1from cpython.ref cimport PyObject
2
3cdef extern from *:
4    ctypedef Py_ssize_t Py_intptr_t
5
6python_string = "foo"
7
8cdef void* ptr = <void*>python_string
9cdef Py_intptr_t adress_in_c = <Py_intptr_t>ptr
10address_from_void = adress_in_c        # address_from_void is a python int
11
12cdef PyObject* ptr2 = <PyObject*>python_string
13cdef Py_intptr_t address_in_c2 = <Py_intptr_t>ptr2
14address_from_PyObject = address_in_c2  # address_from_PyObject is a python int
15
16assert address_from_void == address_from_PyObject == id(python_string)
17
18print(<object>ptr)                     # Prints "foo"
19print(<object>ptr2)                    # prints "foo"
20