dumpb/loadb results in non-working database
Opened this issue · 3 comments
I was trying to serialize and then restore database, all I get when trying to call scan on restored database is hyperscan.InvalidError: error code -1
. I'm using python module version 0.7.7 and python 3.11.9.
Here's sample code:
db = hyperscan.Database(mode=hyperscan.HS_MODE_BLOCK)
db.compile(
expressions=[b'bar']
)
def callback(id, start, end, flags, context):
print(f"Matched {id} from {start} to {end}")
db.scan(b'foo bar baz', callback)
data = hyperscan.dumpb(db)
db2 = hyperscan.loadb(data, hyperscan.HS_MODE_BLOCK)
db2.scan(b'foo bar baz', callback)
And results:
data = hyperscan.dumpb(db)
db2 = hyperscan.loadb(data, hyperscan.HS_MODE_BLOCK)
> db2.scan(b'foo bar baz', callback)
E hyperscan.InvalidError: error code -1
I also noticed in debugger that restored db
has no scratch
atribute set (it's None
), but I'm not sure if this is the reason.
sc = hyperscan.Scratch(db2)
db2.scan(b'foo bar baz', callback, scratch=sc)
Thanks, I'm just back on this task and yeah, this works. Also this works even better:
db2 = hyperscan.loadb(data, hyperscan.HS_MODE_BLOCK)
db2.scratch = hyperscan.Scratch(db2)
Although it's still a workaround and it should probably be fixed or at least documented.
yeah unless anyone has a different opinion i don't see a reason why the scratch couldn't be initialized during loadb similar to the db. could possibly even do it in python wrapper space, and make it optional so it can be turned off in the event you want to manually reserve scratch i'd imagine?