Hi,

I ran into a bug where a python object was deleted in the middle of a function that was using it because a callback decref'd the one and only reference to the object. This doesn't happen with python bytecode because ref counts of the callable and of all args are essentially incref'd before the call and then decref'd after. Doing the same in Cython generated C code might be the way to fix this.

The pure python mode code below reproduces the crash with cython 0.23 when compiled to C and the Crash function called.

Thanks,

John


import cython

@cython.cclass
class Record:
  cython.declare(ref=object)

  def setref(self, ref):
    self.ref = ref

GLOBAL_RECORD = Record()

@cython.cclass
class CrashCls:

  def method(self):

    cython.declare(rec=Record)

    rec = GLOBAL_RECORD

    print id(self)
    rec.ref = None
    assert isinstance(self, CrashCls)  # <-- should crash

def Crash():
  cython.declare(rec=Record)

  rec = GLOBAL_RECORD

  o = CrashCls()
  rec.ref = o.method
  del o

  args = ()
  rec.ref(*args)

_______________________________________________
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel

Reply via email to