Mercurial > hg > cc > cirrus_work
changeset 255:0c5b05d62eda
value from memory view working
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Sat, 18 Jan 2025 23:00:30 +0000 |
parents | aeb755b72a7d |
children | cbcdabf6819d |
files | lib/python/cc/lmh/db.pyx |
diffstat | 1 files changed, 7 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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 = <char[:cdb.cdb_msize():1]>(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')