Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r68893:49c649807414 Date: 2014-01-23 23:14 +0100 http://bitbucket.org/pypy/pypy/changeset/49c649807414/
Log: Bah, another try at 9bfd0a649773. See comment. diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py --- a/pypy/module/cpyext/api.py +++ b/pypy/module/cpyext/api.py @@ -400,16 +400,16 @@ '_PyObject_CallFunction_SizeT', '_PyObject_CallMethod_SizeT', 'PyBuffer_FromMemory', 'PyBuffer_FromReadWriteMemory', 'PyBuffer_FromObject', - 'PyBuffer_FromReadWriteObject', 'PyBuffer_New', 'PyBuffer_Type', '_Py_init_bufferobject', + 'PyBuffer_FromReadWriteObject', 'PyBuffer_New', 'PyBuffer_Type', '_Py_get_buffer_type', 'PyCObject_FromVoidPtr', 'PyCObject_FromVoidPtrAndDesc', 'PyCObject_AsVoidPtr', 'PyCObject_GetDesc', 'PyCObject_Import', 'PyCObject_SetVoidPtr', - 'PyCObject_Type', '_Py_init_pycobject', + 'PyCObject_Type', '_Py_get_cobject_type', 'PyCapsule_New', 'PyCapsule_IsValid', 'PyCapsule_GetPointer', 'PyCapsule_GetName', 'PyCapsule_GetDestructor', 'PyCapsule_GetContext', 'PyCapsule_SetPointer', 'PyCapsule_SetName', 'PyCapsule_SetDestructor', - 'PyCapsule_SetContext', 'PyCapsule_Import', 'PyCapsule_Type', '_Py_init_capsule', + 'PyCapsule_SetContext', 'PyCapsule_Import', 'PyCapsule_Type', '_Py_get_capsule_type', 'PyObject_AsReadBuffer', 'PyObject_AsWriteBuffer', 'PyObject_CheckReadBuffer', @@ -691,17 +691,25 @@ prefix = 'PyPy' else: prefix = 'cpyexttest' - init_buffer = rffi.llexternal('_%s_init_bufferobject' % prefix, [], lltype.Void, - compilation_info=eci, releasegil=False) - init_pycobject = rffi.llexternal('_%s_init_pycobject' % prefix, [], lltype.Void, - compilation_info=eci, releasegil=False) - init_capsule = rffi.llexternal('_%s_init_capsule' % prefix, [], lltype.Void, - compilation_info=eci, releasegil=False) - INIT_FUNCTIONS.extend([ - lambda space: init_buffer(), - lambda space: init_pycobject(), - lambda space: init_capsule(), - ]) + # jump through hoops to avoid releasing the GIL during initialization + # of the cpyext module. The C functions are called with no wrapper, + # but must not do anything like calling back PyType_Ready(). We + # use them just to get a pointer to the PyTypeObjects defined in C. + get_buffer_type = rffi.llexternal('_%s_get_buffer_type' % prefix, + [], PyTypeObjectPtr, + compilation_info=eci, _nowrapper=True) + get_cobject_type = rffi.llexternal('_%s_get_cobject_type' % prefix, + [], PyTypeObjectPtr, + compilation_info=eci, _nowrapper=True) + get_capsule_type = rffi.llexternal('_%s_get_capsule_type' % prefix, + [], PyTypeObjectPtr, + compilation_info=eci, _nowrapper=True) + def init_types(space): + from pypy.module.cpyext.typeobject import py_type_ready + py_type_ready(space, get_buffer_type()) + py_type_ready(space, get_cobject_type()) + py_type_ready(space, get_capsule_type()) + INIT_FUNCTIONS.append(init_types) from pypy.module.posix.interp_posix import add_fork_hook reinit_tls = rffi.llexternal('%sThread_ReInitTLS' % prefix, [], lltype.Void, compilation_info=eci) diff --git a/pypy/module/cpyext/src/bufferobject.c b/pypy/module/cpyext/src/bufferobject.c --- a/pypy/module/cpyext/src/bufferobject.c +++ b/pypy/module/cpyext/src/bufferobject.c @@ -783,9 +783,9 @@ return size; } -void _Py_init_bufferobject(void) +PyTypeObject *_Py_get_buffer_type(void) { - PyType_Ready(&PyBuffer_Type); + return &PyBuffer_Type; } static PySequenceMethods buffer_as_sequence = { diff --git a/pypy/module/cpyext/src/capsule.c b/pypy/module/cpyext/src/capsule.c --- a/pypy/module/cpyext/src/capsule.c +++ b/pypy/module/cpyext/src/capsule.c @@ -321,8 +321,7 @@ PyCapsule_Type__doc__ /*tp_doc*/ }; -void _Py_init_capsule() +PyTypeObject *_Py_get_capsule_type(void) { - PyType_Ready(&PyCapsule_Type); + return &PyCapsule_Type; } - diff --git a/pypy/module/cpyext/src/cobject.c b/pypy/module/cpyext/src/cobject.c --- a/pypy/module/cpyext/src/cobject.c +++ b/pypy/module/cpyext/src/cobject.c @@ -156,7 +156,7 @@ PyCObject_Type__doc__ /*tp_doc*/ }; -void _Py_init_pycobject() +PyTypeObject *_Py_get_cobject_type(void) { - PyType_Ready(&PyCObject_Type); + return &PyCObject_Type; } diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py --- a/pypy/module/cpyext/typeobject.py +++ b/pypy/module/cpyext/typeobject.py @@ -549,11 +549,14 @@ pto.c_tp_flags |= Py_TPFLAGS_READY return pto +def py_type_ready(space, pto): + if pto.c_tp_flags & Py_TPFLAGS_READY: + return + type_realize(space, rffi.cast(PyObject, pto)) + @cpython_api([PyTypeObjectPtr], rffi.INT_real, error=-1) def PyType_Ready(space, pto): - if pto.c_tp_flags & Py_TPFLAGS_READY: - return 0 - type_realize(space, rffi.cast(PyObject, pto)) + py_type_ready(space, pto) return 0 def type_realize(space, py_obj): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit