Commit fcb44032 authored by Stefan Behnel's avatar Stefan Behnel

Fix refleak in limited-api case for cross-module shared extension types and...

Fix refleak in limited-api case for cross-module shared extension types and store them correctly as PyTypeObject* instead of a generic (and unusable) PyObject*.
parent 017075a1
......@@ -2460,10 +2460,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln('int %s;' % Naming.clineno_cname)
code.putln('const char *%s;' % Naming.filename_cname)
code.putln('#ifdef __Pyx_CyFunction_USED')
code.putln('PyObject *%s;' % Naming.cyfunction_type_cname)
code.putln('PyTypeObject *%s;' % Naming.cyfunction_type_cname)
code.putln('#endif')
code.putln('#ifdef __Pyx_FusedFunction_USED')
code.putln('PyObject *%s;' % Naming.fusedfunction_type_cname)
code.putln('PyTypeObject *%s;' % Naming.fusedfunction_type_cname)
code.putln('#endif')
def generate_module_state_end(self, env, modules, globalstate):
......
......@@ -2,7 +2,7 @@
static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);
#if CYTHON_COMPILING_IN_LIMITED_API
static PyObject* __Pyx_FetchCommonTypeFromSpec(PyType_Spec *spec, PyObject *bases);
static PyTypeObject* __Pyx_FetchCommonTypeFromSpec(PyType_Spec *spec, PyObject *bases);
#endif
/////////////// FetchCommonType ///////////////
......@@ -70,8 +70,8 @@ bad:
}
#if CYTHON_COMPILING_IN_LIMITED_API
static PyObject *__Pyx_FetchCommonTypeFromSpec(PyType_Spec *spec, PyObject *bases) {
PyObject *abi_module, *py_basicsize, *type, *cached_type = NULL;
static PyTypeObject *__Pyx_FetchCommonTypeFromSpec(PyType_Spec *spec, PyObject *bases) {
PyObject *abi_module, *py_basicsize, *cached_type = NULL;
Py_ssize_t basicsize;
abi_module = __Pyx_FetchSharedCythonABIModule();
......@@ -96,15 +96,15 @@ static PyObject *__Pyx_FetchCommonTypeFromSpec(PyType_Spec *spec, PyObject *base
if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
PyErr_Clear();
type = PyType_FromSpecWithBases(spec, bases);
if (unlikely(!type)) goto bad;
if (PyObject_SetAttrString(abi_module, spec->name, type) < 0) goto bad;
cached_type = type;
cached_type = PyType_FromSpecWithBases(spec, bases);
if (unlikely(!cached_type)) goto bad;
if (PyObject_SetAttrString(abi_module, spec->name, cached_type) < 0) goto bad;
done:
Py_DECREF(abi_module);
// NOTE: always returns owned reference, or NULL on error
return cached_type;
assert(cached_type == NULL || PyType_Check(cached_type));
return (PyTypeObject *) cached_type;
bad:
Py_XDECREF(cached_type);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment