Skip to content

Commit 5a79d2a

Browse files
authored
Revert "gh-46376: Return existing pointer when possible in ctypes (#1… (#108688)
This reverts commit 08447b5. Revert also _ctypes.c changes of the PyDict_ContainsString() change, commit 6726626.
1 parent 44fc378 commit 5a79d2a

File tree

3 files changed

+0
-63
lines changed

3 files changed

+0
-63
lines changed

Lib/test/test_ctypes/test_keeprefs.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -98,33 +98,6 @@ def test_p_cint(self):
9898
x = pointer(i)
9999
self.assertEqual(x._objects, {'1': i})
100100

101-
def test_pp_ownership(self):
102-
d = c_int(123)
103-
n = c_int(456)
104-
105-
p = pointer(d)
106-
pp = pointer(p)
107-
108-
self.assertIs(pp._objects['1'], p)
109-
self.assertIs(pp._objects['0']['1'], d)
110-
111-
pp.contents.contents = n
112-
113-
self.assertIs(pp._objects['1'], p)
114-
self.assertIs(pp._objects['0']['1'], n)
115-
116-
self.assertIs(p._objects['1'], n)
117-
self.assertEqual(len(p._objects), 1)
118-
119-
del d
120-
del p
121-
122-
self.assertIs(pp._objects['0']['1'], n)
123-
self.assertEqual(len(pp._objects), 2)
124-
125-
del n
126-
127-
self.assertEqual(len(pp._objects), 2)
128101

129102
class PointerToStructure(unittest.TestCase):
130103
def test(self):

Misc/NEWS.d/next/Library/2023-07-24-01-21-16.gh-issue-46376.w-xuDL.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.

Modules/_ctypes/_ctypes.c

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5148,41 +5148,6 @@ Pointer_get_contents(CDataObject *self, void *closure)
51485148

51495149
stgdict = PyObject_stgdict((PyObject *)self);
51505150
assert(stgdict); /* Cannot be NULL for pointer instances */
5151-
5152-
PyObject *keep = GetKeepedObjects(self);
5153-
if (keep != NULL) {
5154-
// check if it's a pointer to a pointer:
5155-
// pointers will have '0' key in the _objects
5156-
int ptr_probe = PyDict_ContainsString(keep, "0");
5157-
if (ptr_probe < 0) {
5158-
return NULL;
5159-
}
5160-
if (ptr_probe) {
5161-
PyObject *item;
5162-
if (PyDict_GetItemStringRef(keep, "1", &item) < 0) {
5163-
return NULL;
5164-
}
5165-
if (item == NULL) {
5166-
PyErr_SetString(PyExc_ValueError,
5167-
"Unexpected NULL pointer in _objects");
5168-
return NULL;
5169-
}
5170-
#ifndef NDEBUG
5171-
CDataObject *ptr2ptr = (CDataObject *)item;
5172-
// Don't construct a new object,
5173-
// return existing one instead to preserve refcount.
5174-
// Double-check that we are returning the same thing.
5175-
assert(
5176-
*(void**) self->b_ptr == ptr2ptr->b_ptr ||
5177-
*(void**) self->b_value.c == ptr2ptr->b_ptr ||
5178-
*(void**) self->b_ptr == ptr2ptr->b_value.c ||
5179-
*(void**) self->b_value.c == ptr2ptr->b_value.c
5180-
);
5181-
#endif
5182-
return item;
5183-
}
5184-
}
5185-
51865151
return PyCData_FromBaseObj(stgdict->proto,
51875152
(PyObject *)self, 0,
51885153
*(void **)self->b_ptr);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy