Ticket #670 (closed defect: worksforme)

Opened 4 years ago

Last modified 3 years ago

Bug in closures

Reported by: Ralf Schmitt Owned by: somebody
Priority: major Milestone: 0.15.1
Component: Code Generation Keywords:
Cc:

Description

Hi all,

compiling the following code with cython --cplus and importing it
results in a segfault on my system:

,----
| cdef class graph(object):
|
|     def get_links_to(self, s):
|         return [1,2,3]
|
|     def computePaths(self, node, allowCycles=False):
|         def get(n):
|             return self.get_links_to(node)
|
|         def _computePaths(node, path):
|             return get(node)
|
|         return _computePaths(node, [node])
|
|
| g = graph()
| print g.computePaths(1)
`----

gdb gives me the following stacktrace:

,----
| (gdb) bt
| #0  0x00007ffff7aa57a8 in PyObject_GetAttr () from /usr/lib/libpython2.7.so.1.0
| #1  0x00007ffff6a949b6 in __pyx_pf_2gg_12computePaths_get(_object*, _object*) () from ./gg.so
| #2  0x00007ffff7a6ab53 in PyObject_Call () from /usr/lib/libpython2.7.so.1.0
| #3  0x00007ffff6a94ea9 in __pyx_pf_2gg_12computePaths_1_computePaths(_object*, _object*, _object*)
|     () from ./gg.so
| #4  0x00007ffff7a6ab53 in PyObject_Call () from /usr/lib/libpython2.7.so.1.0
| #5  0x00007ffff6a95247 in __pyx_pf_2gg_5graph_1computePaths(_object*, _object*, _object*) ()
|    from ./gg.so
| #6  0x00007ffff7a6ab53 in PyObject_Call () from /usr/lib/libpython2.7.so.1.0
| #7  0x00007ffff6a95a86 in initgg () from ./gg.so
| ...
`----


If I remove the allowCycles=False argument, g++ complains:
,----
| g++ -Wno-deprecated -O2 -I. -I/usr/include/python2.7 -fPIC -std=gnu++0x -o gg.o -c gg.cc
| gg.cc: In function ‘PyObject* __pyx_pf_2gg_5graph_1computePaths(PyObject*, PyObject*)’:
| gg.cc:701:35: error: cannot convert ‘PyObject*’ to ‘__pyx_obj_2gg_graph*’ in assignment
| make: *** [gg.o] Error 1
`----

Change History

Changed 3 years ago by scoder

  • status changed from new to closed
  • resolution set to worksforme
  • milestone changed from wishlist to 0.15.1

Works for me in latest master branch - assuming that it's been working for a while.

Note: See TracTickets for help on using tickets.