1

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
  • I might be missing something, but `A.cppobj` is a pointer to the `cppojb` method (well property in this case), I think you want `A().cppojb`. – Bi Rico Aug 15 '14 at 23:02
  • In addition to @Bi Rico 's comment, noting that http://stackoverflow.com/questions/24764048/get-the-value-of-a-cython-pointer worked for me with pointers to C structures. – 0 _ Mar 30 '16 at 18:49

0 Answers0