diff options
| author | Stefan Behnel <stefan_ml@behnel.de> | 2020-04-11 21:32:13 +0200 |
|---|---|---|
| committer | Stefan Behnel <stefan_ml@behnel.de> | 2020-04-11 21:32:34 +0200 |
| commit | fcb44032968d8893ead5c63c7554d293d370ec1b (patch) | |
| tree | 9c748622896d035429a2cc84bc0af29783a7cdc5 | |
| parent | 017075a115314d39982dea493fc139ac1e4c5925 (diff) | |
| download | cython-fcb44032968d8893ead5c63c7554d293d370ec1b.tar.gz | |
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*.
| -rw-r--r-- | Cython/Compiler/ModuleNode.py | 4 | ||||
| -rw-r--r-- | Cython/Utility/CommonStructures.c | 16 |
2 files changed, 10 insertions, 10 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 19e28a8ba..c1bc84787 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -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): diff --git a/Cython/Utility/CommonStructures.c b/Cython/Utility/CommonStructures.c index 127fa5148..e2bf227fd 100644 --- a/Cython/Utility/CommonStructures.c +++ b/Cython/Utility/CommonStructures.c @@ -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); |
