Debian Codegraph @

lib_pypy/_ctypes/keepalive.txt

raw
1
2 Few rules about ctypes keepalives:
3
4 * Ownership: the memory is freed when owner of this memory is deleted.
5 Owner is the one who allocated the memory. So if we have:
6
7 a = c_int(3)
8 b = c_int.from_address(a._buffer.buffer) # pypy notion of address access
9
10 only a frees memory.
11
12 * _objects: each ctypes object has (eventually) _objects dictionary in which
13 it simply keeps objects to be kept alive.
14
15 * there are (some) rules about when to put stuff in it's objects when
16 accessing the fields etc. need to list them here.
17
18 * each object has _objects dictionary. In this dict stuff is stored per
19 key, which should be a tuple of indices of storages.
20
21 places storing stuff in _objects:
22
23 * array item assignement, if we share the storage
24
25 * pointer item assignement, if we share the storage
26
27 * getitem on CDLL stores function pointer
28
29 * CFuncPtr.__new__ (assuming that it's a ctypes callable), stores itself
30 (XXX???)
31
32 * set contents on pointer
33
34 * set value on primitive or __init__ on primitive