pypy / lib_pypy / _ctypes / keepalive.txt

Few rules about ctypes keepalives:

* Ownership: the memory is freed when owner of this memory is deleted.
  Owner is the one who allocated the memory. So if we have:

  a = c_int(3)
  b = c_int.from_address(a._buffer.buffer) # pypy notion of address access

  only a frees memory.

* _objects: each ctypes object has (eventually) _objects dictionary in which
  it simply keeps objects to be kept alive.

* there are (some) rules about when to put stuff in it's objects when
  accessing the fields etc. need to list them here.

  * each object has _objects dictionary. In this dict stuff is stored per
    key, which should be a tuple of indices of storages.

places storing stuff in _objects:

* array item assignement, if we share the storage

* pointer item assignement, if we share the storage

* getitem on CDLL stores function pointer

* CFuncPtr.__new__ (assuming that it's a ctypes callable), stores itself

* set contents on pointer

* set value on primitive or __init__ on primitive
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.