[Python-Dev] ctypes: is it intentional that id() is the only way to get the address of an object?

Antoine Pitrou solipsis at pitrou.net
Thu Jan 17 05:37:13 EST 2019

On Thu, 17 Jan 2019 21:26:06 +1100
Steven D'Aprano <steve at pearwood.info> wrote:
> Disclaimer: I'm not a ctypes expert, so I might have this completely 
> wrong. If so, I apologise for the noise.
> The id() function is documented as returning an abstract ID number. In 
> CPython, that happens to have been implemented as the address of the 
> object.
> I understand that the only way to pass the address of an object to 
> ctypes is to use that id. Is that intentional?

Can you explain in detail what you're doing?
If you're calling a C API taking a PyObject*, it seems like you should
be using ctypes.py_object as argument type specifier.  Various examples
can be found with Google.



More information about the Python-Dev mailing list