osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


On Fri, 18 Jan 2019 20:49:26 +1100
Steven D'Aprano <steve at pearwood.info> wrote:
> 
> Language-wise, I'm trying to get a definitive answer of whether or not 
> id() returning the address of the object should be a guaranteed feature 
> or not.

For me, the definitive answer is "yes, it's a CPython feature".

However, it's obviously not a PyPy feature, and I'm not sure about other
implementations.  Anything with an object model that can eliminate
in-memory objects in favour of in-register values (for example using
tagged pointers or type specialization + lifetime analysis) is obviously
not able to hold the promise that id() returns the /address/ of the
"object".

That doesn't mean the CPython feature has to live forever.  We may want
to deprecate it at some point (though it's not obvious how to warn the
user: just because you're using id() doesn't mean you're interested in
the actual /address/, rather than some arbitrary unique id).

> According to this claim, using id() to get the address for use in ctypes 
> is the correct and only way to do it

I don't know why you keep repeating that.  You were already explained
that it's /not/ the correct and only way to get the address for use in
ctypes.

Regards

Antoine.