changeset 275:5439c4c7777e

trivial test, suitable for gdb
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Wed, 19 Feb 2025 17:46:24 +0000
parents 5c013fd18ea0
children 76fb260e893b
files lib/python/cc/lmh/dbt.pyx lib/python/cc/lmh/setup_t.py
diffstat 2 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/python/cc/lmh/dbt.pyx	Wed Feb 19 17:46:24 2025 +0000
@@ -0,0 +1,44 @@
+#!/usr/bin/python3
+# # distutils: sources = [cdb_min/cdb.c, cdb_min/error.c, cdb_min/open_read.c, cdb_min/seek_cur.c, cdb_min/open_trunc.c, cdb_min/seek_set.c, cdb_min/byte_copy.c, cdb_min/byte_diff.c, cdb_min/error_str.c, cdb_min/uint32_unpack.c, cdb_min/cdb_hash.c]
+# distutils: extra_objects = cdb/libcdb.a
+# distutils: include_dirs = cdb
+
+# Usage: testc cdb-path probe nreps
+
+# E.g. python3 -c 'import db' ~/results/CC-MAIN-2019-35/warc_lmhx/ks_0.cdb 20190825142846http://71.43.189.10/dermorph/ 10000000
+
+import sys, timeit
+
+cimport cdb
+cimport db
+
+cdef db.CCdb CC
+
+cdef db.CCdb testMe(bytes probe):
+  res: int = -1
+  print('testing... %s %s x %s'%(sys.argv[1],probe,int(sys.argv[3])))
+  cdef db.CCdb cd = db.CCdb()
+  with open(sys.argv[1],'rb') as dbf:
+    cd.init(dbf.fileno())
+    cdb.cdb_findstart(cd._c_cdb)
+    if (res:=cdb.cdb_find(cd._c_cdb,probe,len(probe))) == 1:
+      cdb.cdb_write(cd._c_cdb,1)
+      sys.stdout.buffer.write(b'\n')
+    else:
+      print(0)
+      print(probe,len(probe),cdb.cdb_find(cd._c_cdb,probe,len(probe)))
+      print(res,o:=cdb.cdb_pos(cd._c_cdb), l:=cdb.cdb_len(cd._c_cdb))
+      sys.stdout.buffer.write(b'\n')
+  print('tested')
+  return cd
+
+def cfind(p: bytes) -> int:
+  global CC
+  return cdb.cdb_find(CC._c_cdb, p, len(p))
+
+CC = testMe(sys.argv[2].encode('utf8'))
+
+exit()
+
+print(timeit.timeit('cfind(sys.argv[2].encode("utf8"))',
+               number=int(sys.argv[3]), globals=globals()))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/python/cc/lmh/setup_t.py	Wed Feb 19 17:46:24 2025 +0000
@@ -0,0 +1,6 @@
+from setuptools import Extension, setup
+from Cython.Build import cythonize
+
+setup(
+    ext_modules = cythonize([Extension("dbt", ["dbt.pyx"])])
+)