# HG changeset patch # User Henry S. Thompson # Date 1737241230 0 # Node ID 0c5b05d62edae5f65f92978d3d0e0c364f845396 # Parent aeb755b72a7ddbc16e0e6b4f75d968c1e537b8bb value from memory view working diff -r aeb755b72a7d -r 0c5b05d62eda lib/python/cc/lmh/db.pyx --- a/lib/python/cc/lmh/db.pyx Sat Jan 18 21:25:17 2025 +0000 +++ b/lib/python/cc/lmh/db.pyx Sat Jan 18 23:00:30 2025 +0000 @@ -8,6 +8,7 @@ cdef class Cdb: cdef cdb.Cdb* _c_cdb + def __cinit__(self): self._c_cdb = cdb.cdb_new() @@ -15,9 +16,10 @@ cdef int find(self: Cdb, p: bytes): return cdb.cdb_find(self._c_cdb, p, len(p)) - cdef void init(self: Cdb, fno: int): + cdef char[::1] init(self: Cdb, fno: int): cdb.cdb_init(self._c_cdb,fno) cdef char[::1] _mview = (cdb.cdb_mmap()) + return _mview probe: bytes = sys.argv[2].encode('utf8') @@ -29,10 +31,12 @@ print('testing...') cd = Cdb() with open(sys.argv[1],'rb') as dbf: - cd.init(dbf.fileno()) + mv = cd.init(dbf.fileno()) cdb.cdb_findstart(cd._c_cdb) if cd.find(probe) > 0: - print(cdb.cdb_pos(), cdb.cdb_len()) + print(o:=cdb.cdb_pos(), l:=cdb.cdb_len()) + sys.stdout.buffer.write(mv[o:o+l]) + sys.stdout.buffer.write(b'\n') else: print(0) print('tested')