New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increment/decrement don't work with cython.operator.dereference on C++ smart pointers #2058

wrongu opened this Issue Jan 2, 2018 · 0 comments


None yet
1 participant

wrongu commented Jan 2, 2018

Here is a small script showing the problem:

from libcpp.memory cimport shared_ptr
from cython.operator cimport dereference as d

cdef cppclass MyClass:
    int x

cdef MyClass* m = new MyClass()
cdef shared_ptr[MyClass] m_p = shared_ptr[MyClass](m)

m.x = 0
print("Initially, m.x = %d" % m.x)

d(m_p).x = 10
print("Dereference result: m.x = %d" % m.x)
d(m_p).x += 1
print("Dereference increment result: m.x = %d" % m.x)

m_p.get().x = 20
print("get() result: m.x = %d" % m.x)
m_p.get().x += 1
print("get() increment result: m.x = %d" % m.x)

Output is:

Initially, m.x = 0
Dereference result: m.x = 10
Dereference increment result: m.x = 10
get() result: m.x = 20
get() increment result: m.x = 21

The problem is: although assigning a value to a dereferenced smart pointer works fine, incrementing the same value with += does not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment