File: python3.11-untrack

package info (click to toggle)
python-cffi 1.15.1-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,492 kB
  • sloc: python: 28,164; ansic: 14,823; asm: 116; makefile: 96; sh: 14
file content (65 lines) | stat: -rw-r--r-- 2,306 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
From: Stefano Rivera <stefanor@debian.org>
Date: Sun, 4 Dec 2022 18:57:16 -0400
Subject: Issue 553

Two missing calls to PyObject_GC_UnTrack()

Origin: upstream: https://foss.heptapod.net/pypy/cffi/-/commit/2b807ea84d385a95aae5eb78a57c9e3bf911043c
Bug-Upstream: https://foss.heptapod.net/pypy/cffi/-/issues/553
Bug-Upstream: https://foss.heptapod.net/pypy/cffi/-/issues/554
Bug-Debian: https://bugs.debian.org/1024767
Bug-Debian: https://bugs.debian.org/1025027
---
 c/_cffi_backend.c                 |  2 ++
 testing/cffi0/test_ffi_backend.py | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
index b9618bd..d2dc76c 100644
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -1938,6 +1938,7 @@ static void cdataowninggc_dealloc(CDataObject *cd)
 static void cdatafrombuf_dealloc(CDataObject *cd)
 {
     Py_buffer *view = ((CDataObject_frombuf *)cd)->bufferview;
+    PyObject_GC_UnTrack(cd);
     cdata_dealloc(cd);
 
     PyBuffer_Release(view);
@@ -2043,6 +2044,7 @@ static void cdatagcp_dealloc(CDataObject_gcp *cd)
 {
     PyObject *destructor = cd->destructor;
     PyObject *origobj = cd->origobj;
+    PyObject_GC_UnTrack(cd);
     cdata_dealloc((CDataObject *)cd);
 
     gcp_finalize(destructor, origobj);
diff --git a/testing/cffi0/test_ffi_backend.py b/testing/cffi0/test_ffi_backend.py
index 8e29bc4..da13c00 100644
--- a/testing/cffi0/test_ffi_backend.py
+++ b/testing/cffi0/test_ffi_backend.py
@@ -159,6 +159,24 @@ class TestFFI(backend_tests.BackendTests,
         assert p.bcd == 9999999
         assert p.foo.data[3] != 78   # has been overwritten with 9999999
 
+    def test_issue553(self):
+        import gc, warnings
+        ffi = FFI(backend=self.Backend())
+        p = ffi.new("int *", 123)
+        with warnings.catch_warnings(record=True) as w:
+            ffi.gc(p, lambda x: None)
+            gc.collect()
+        assert w == []
+
+    def test_issue553_from_buffer(self):
+        import gc, warnings
+        ffi = FFI(backend=self.Backend())
+        buf = b"123"
+        with warnings.catch_warnings(record=True) as w:
+            ffi.from_buffer(buf)
+            gc.collect()
+        assert w == []
+
 
 class TestBitfield:
     def check(self, source, expected_ofs_y, expected_align, expected_size):