I'm using Cython to wrap a C++ library, where I use (uintptr_t)(void *) cast to pass pointers to python callers and getback as a handle. In one such scenario - I pass a casted pointer as a Python Integer to another Cython function. In the original function where the pointer is declared the reverse cast to (Class *)(void *) succcessfully generates the original pointer value [Verified within C++]. Whereas in the other Cython function which uses the handle, the reverse cast gives some other pointer value leading to a crash [Verified within C++]. Does the change in size of the object affect reverse cast from uintptr_t to (Class *)(void *)? Or is there any other requirement on such casts and reverse casts.
Class A:
@property
def cppobj(self):
"""
- return pointer to C++ Object
"""
cdef uintptr_t ptr = <uintptr_t><void *> self._obj
# call to printptr C++ method
# argument - <cpp.A *><void *> ptr
# prints: 0x8805508
return <uintptr_t><void *> self._obj
class B:
def useA(self):
# call to printptr C++ method
# argument - <cpp.A *><void *> A.cppobj
# prints: 0x880b718