[issue12836] ctypes.cast() creates circular reference in original object

Vinay Sajip report at bugs.python.org
Mon Aug 29 18:15:10 CEST 2011


Vinay Sajip <vinay_sajip at yahoo.co.uk> added the comment:

I can confirm that the same behaviour occur in Python 3.3, and this appears to be by design. There's a specific line in the cast() function in in Modules/_ctypes.c:

rc = PyDict_SetItem(result->b_objects, index, src);

This adds the source object to the _objects of the cast object being returned. However, earlier in the function, the code

CDataObject *obj = (CDataObject *)src;

...

result->b_objects = obj->b_objects;

ensures that result and src are using a single dictionary. Possibly, the result's b_objects needs to be a copy of the src's b_objects; but I don't know enough about ctypes internals to say whether the present code is intentional, or whether an attempt to minimise resource usage (by not copying the dictionary) has led to unwanted consequences.

----------
nosy: +vinay.sajip
versions: +Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12836>
_______________________________________


More information about the Python-bugs-list mailing list