cloudflare / stpyv8

Python 3 and JavaScript interoperability. Successor To PyV8 (https://github.com/flier/pyv8)
Apache License 2.0
440 stars 39 forks source link

Segfault calling eval outside of `with` #108

Closed declann closed 6 months ago

declann commented 6 months ago

Hi,

Thanks for STPyV8, I have a workaround noted below but posting in case there are issues you want to fix.

This works: image

But this causes a segfault: image

I like the latter pattern for notebook/interactive calls to JS.

Heres a workaround that seems to suits my needs:

image

Thanks, Declan

buffer commented 6 months ago

This is not an issue. In the second example you're just creating a JSContext but you have to enter it

>>> import STPyV8
>>> c = STPyV8.JSContext()
>>> c.enter()
>>> print(c.eval("2+2"))
4
>>> c.leave()

Using the with statement just saves you from entering and leaving the context as the context manager takes care of such details for you. Hope this helps.

declann commented 6 months ago

My bad, thanks a lot for the explanation!

On Thu 16 May 2024, 10:47 buffer, @.***> wrote:

This is not an issue. In the second example you're just creating a JSContext but you have to enter it

import STPyV8 c = STPyV8.JSContext() c.enter() print(c.eval("2+2")) 4 c.leave()

Using the with statement just saves you from entering and leaving the context as the context manager takes care of such details for you. Hope this helps.

— Reply to this email directly, view it on GitHub https://github.com/cloudflare/stpyv8/issues/108#issuecomment-2114723752, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACWHPTYV7OXDGJ7BGNEFKLZCR6BZAVCNFSM6AAAAABHQQXSQCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJUG4ZDGNZVGI . You are receiving this because you authored the thread.Message ID: @.***>