tbodt/v8py

Context creation with global object issue

buffer opened this issue · 5 comments

While porting a project of mine from PyV8 to v8py I experienced an issue with passing the Context a global object (in my case this is the global object https://github.com/buffer/thug/blob/master/thug/DOM/Window.py#L66).

The code which causes the crash is as simple as

_ctxt = v8py.Context(self)

(the context initialization is performed within the same global object).

Following the crash dump I get on Mac OS X but I got a similar trace on Linux as well.


Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 _v8py.so 0x000000010e8194d5 v8::internal::(anonymous namespace)::ProbeInstantiationsCache(v8::internal::Isolate*, int) + 37 (atomicops_internals_portable.h:161)
1 _v8py.so 0x000000010e816d36 v8::internal::(anonymous namespace)::InstantiateFunction(v8::internal::Isolate*, v8::internal::Handlev8::internal::FunctionTemplateInfo, v8::internal::Handlev8::internal::Name) + 70 (handles.h:220)
2 _v8py.so 0x000000010e816cab v8::internal::ApiNatives::InstantiateFunction(v8::internal::Handlev8::internal::FunctionTemplateInfo) + 75 (api-natives.cc:23)
3 _v8py.so 0x000000010e7fbab2 v8::FunctionTemplate::GetFunction(v8::Localv8::Context) + 322 (handles.h:200)
4 _v8py.so 0x000000010e72231b py_class_get_constructor(py_class*, v8::Localv8::Context) + 76 (pyclass.cpp:257)
5 _v8py.so 0x000000010e71f63d js_from_py(_object*, v8::Localv8::Context) + 1115 (v8.h:915)
6 _v8py.so 0x000000010e722249 add_to_template(_object*, _object*, _object*, v8::Localv8::FunctionTemplate) + 705 (pyclass.cpp:241)
7 _v8py.so 0x000000010e721f53 add_class_to_template(_object*, v8::Localv8::FunctionTemplate) + 155 (pyclass.cpp:179)
8 _v8py.so 0x000000010e721afa py_class_new(_object*) + 230 (pyclass.cpp:88)
9 _v8py.so 0x000000010e7219e7 py_class_to_template(_object*) + 68 (pyclass.cpp:38)
10 _v8py.so 0x000000010e71e7c3 context_new(_typeobject*, _object*, _object*) + 287 (context.cpp:80)

tbodt commented

This works fine for me:

import v8py
class Glob:
    def __init__(self, foo='bar'):
        self.ctx = v8py.Context(self)
    def foo(self):
        return 2
Glob()

Can you please create a minimal repo case?

Your example works fine here too. Still trying to figure out what's the reason behind that misbehaviour. I will be traveling in the next days but I'll try to create a a case as soon as I can.

tbodt commented

The bug appears to happen when a class has another class as a member. Minimal repro:

import v8py
class Global:
    class Inner:
        pass
v8py.context(Global())
tbodt commented

The easiest workaround would be to put @v8py.hidden on the inner class.