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

Accessing results outside of scope where parser was referenced leads to segfault? #50

Open
ctheune opened this issue Oct 22, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@ctheune
Copy link

ctheune commented Oct 22, 2023

I found this experimentally: is it assumed that access to the results are only valid as long as the parser object lives / is in scope?

I noticed that when I have a function that instantiates the parser and returns the result of the parse output I will regularly get segfaults. This isn't very Python and might need a bigger warning and/or some utilities to assist managing the lifecycle ...

@ctheune
Copy link
Author

ctheune commented Oct 22, 2023

My workaround for this situation:

class CysimdResult(object):
    def __init__(self, parser, result):
        self.parser = parser
        self.result = result

async def rgwadmin(*args):
    proc = await asyncio.create_subprocess_exec(
        "radosgw-admin",
        *args,
        stdout=asyncio.subprocess.PIPE,
        stderr=asyncio.subprocess.PIPE,
    )

    parser = cysimdjson.JSONParser()
    stdout, stderr = await proc.communicate()
    return CysimdResult(parser, parser.parse(stdout))

I could make the Result object a bit smarter by proxying the underlying attributes to the result ... but for understanding the issue, this should suffice.

@ateska
Copy link
Contributor

ateska commented Mar 22, 2024

This is correct. It is actually the SIMDJSON requirement.
But I agree, this is not safe in a Python typical way.

@ateska ateska added the enhancement New feature or request label Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants