Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dumpb/loadb results in non-working database #153

Open
piotr-piatkowski opened this issue Jun 6, 2024 · 3 comments
Open

dumpb/loadb results in non-working database #153

piotr-piatkowski opened this issue Jun 6, 2024 · 3 comments

Comments

@piotr-piatkowski
Copy link

piotr-piatkowski commented Jun 6, 2024

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.

@betterlch
Copy link

betterlch commented Jun 19, 2024

sc = hyperscan.Scratch(db2)
db2.scan(b'foo bar baz', callback, scratch=sc)

@piotr-piatkowski
Copy link
Author

piotr-piatkowski commented Sep 18, 2024

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.

@darvid
Copy link
Owner

darvid commented Sep 24, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants