New issue 2798: Creating a global-variable PyObject in a C++ extension crashes 
while dlopening
https://bitbucket.org/pypy/pypy/issues/2798/creating-a-global-variable-pyobject-in-a-c

Hrvoje Nikšić:

The attached module crashes when compiled and imported from pypy 5.10.0.

The crash is apparently triggered by global variable initialization:

```
#!c++

// global variable - crash goes away without it
PyObject *global = PyInt_FromLong(42);
```

This kind of global initialization is frequently used in our in-house CPython 
C++ extensions[1]. It is safe for dynamically loaded extensions because by the 
time the shared object gets dlopen-ed, Python has been initialized and the GIL 
acquired. In PyPy 5.10.0 it consistently crashes before executing the module 
initialization function.

Is this a bug in cpyext, or is the above pattern forbidden? Is there a 
workaround to make it work?

[1]
The example is, of course, simplified - in actual code, the object would be a 
RAII wrapper object whose constructor invokes PyInt_FromLong. It is used in 
many different extensions and cannot be easily replaced with, say, a function 
that lazily constructs and returns an object.


_______________________________________________
pypy-issue mailing list
pypy-issue@python.org
https://mail.python.org/mailman/listinfo/pypy-issue

Reply via email to