]>
Commit | Line | Data |
---|---|---|
5a0fc37a JB |
1 | From 039ef7c6242b3b6a18363ff22ead04f4e7cce676 Mon Sep 17 00:00:00 2001 |
2 | From: Stefan Behnel <stefan_ml@behnel.de> | |
3 | Date: Fri, 14 Jul 2023 21:46:56 +0200 | |
4 | Subject: [PATCH] In Py2, the extension type might get cleaned up before the | |
5 | objects at system exit, so we need an extra NULL check for the type pointer. | |
6 | ||
7 | --- | |
8 | Cython/Compiler/ModuleNode.py | 6 ++++++ | |
9 | 1 file changed, 6 insertions(+) | |
10 | ||
11 | diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py | |
12 | index f98a0c15054..bf2cc63e1e1 100644 | |
13 | --- a/Cython/Compiler/ModuleNode.py | |
14 | +++ b/Cython/Compiler/ModuleNode.py | |
15 | @@ -1509,7 +1509,13 @@ class ModuleNode(Nodes.Node, Nodes.Block | |
16 | if base_type.scope and base_type.scope.needs_gc(): | |
17 | code.putln("PyObject_GC_Track(o);") | |
18 | else: | |
19 | + code.putln("#if PY_MAJOR_VERSION < 3") | |
20 | + # Py2 lacks guarantees that the type pointer is still valid if we dealloc the object | |
21 | + # at system exit time. Thus, we need an extra NULL check. | |
22 | + code.putln("if (!(%s) || PyType_IS_GC(%s)) PyObject_GC_Track(o);" % (base_cname, base_cname)) | |
23 | + code.putln("#else") | |
24 | code.putln("if (PyType_IS_GC(%s)) PyObject_GC_Track(o);" % base_cname) | |
25 | + code.putln("#endif") | |
26 | ||
27 | tp_dealloc = TypeSlots.get_base_slot_function(scope, tp_slot) | |
28 | if tp_dealloc is not None: |