summaryrefslogtreecommitdiff
path: root/tests/run
diff options
context:
space:
mode:
authorscoder <stefan_ml@behnel.de>2023-05-15 20:18:47 +0200
committerStefan Behnel <stefan_ml@behnel.de>2023-05-15 20:24:02 +0200
commit38f6a5670c7004172502fee41d990519e2163666 (patch)
tree2b053fc2b58caae0ad9c07d4d6bfde1fcd04b0c2 /tests/run
parenta2db6deb18a64ca08da2f1298808fe5e1d460415 (diff)
downloadcython-38f6a5670c7004172502fee41d990519e2163666.tar.gz
Prevent calling the dealloc slot of a non-GC base class with GC tracking enabled. (GH-5432)
This shows warnings in CPython (3.12) debug builds and can lead to crashes when GC triggers on an object while deallocating it.
Diffstat (limited to 'tests/run')
-rw-r--r--tests/run/exttype_gc.pyx38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/run/exttype_gc.pyx b/tests/run/exttype_gc.pyx
new file mode 100644
index 000000000..db8ae2cc9
--- /dev/null
+++ b/tests/run/exttype_gc.pyx
@@ -0,0 +1,38 @@
+# mode: run
+# tag: gc
+
+
+def create_obj(cls):
+ cls() # create and discard
+
+
+cdef class BaseTypeNoGC:
+ pass
+
+
+cdef class ExtTypeGC(BaseTypeNoGC):
+ """
+ >>> create_obj(ExtTypeGC)
+ >>> create_obj(ExtTypeGC)
+ >>> create_obj(ExtTypeGC)
+
+ >>> class PyExtTypeGC(ExtTypeGC): pass
+ >>> create_obj(PyExtTypeGC)
+ >>> create_obj(PyExtTypeGC)
+ >>> create_obj(PyExtTypeGC)
+ """
+ cdef object attr
+
+
+cdef class ExtTypeNoGC(BaseTypeNoGC):
+ """
+ >>> create_obj(ExtTypeNoGC)
+ >>> create_obj(ExtTypeNoGC)
+ >>> create_obj(ExtTypeNoGC)
+
+ >>> class PyExtTypeNoGC(ExtTypeNoGC): pass
+ >>> create_obj(PyExtTypeNoGC)
+ >>> create_obj(PyExtTypeNoGC)
+ >>> create_obj(PyExtTypeNoGC)
+ """
+ cdef int x