Compiler crash in AnalyseExpressionsTransform

129 views
Skip to first unread message

Czarek Tomczak

unread,
May 22, 2013, 1:18:53 PM5/22/13
to cython...@googlegroups.com
Hi,

I'm getting this crash while compiling with Cython:

web_request.pyx:54:19: Compiler crash in AnalyseExpressionsTransform
ModuleNode.body = StatListNode(cefpython.pyx:42:0)
StatListNode.stats[11] = StatListNode(cefpython.pyx:77:4)
StatListNode.stats[4] = StatListNode(web_request.pyx:14:0)
StatListNode.stats[2] = CFuncDefNode(web_request.pyx:49:5,
    args = [...]/2,
    modifiers = [...]/0,
    visibility = u'private')
File 'Nodes.py', line 387, in analyse_expressions: StatListNode(web_request.pyx:51:4)
File 'Nodes.py', line 4403, in analyse_expressions: SingleAssignmentNode(web_request.pyx:54:47)
File 'Nodes.py', line 4509, in analyse_types: SingleAssignmentNode(web_request.pyx:54:47)
File 'ExprNodes.py', line 2750, in analyse_target_types: IndexNode(web_request.pyx:54:19,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 3178, in is_lvalue: IndexNode(web_request.pyx:54:19,
    result_is_used = True,
    use_managed_ref = True)
Compiler crash traceback from this point on:
  File "/usr/local/lib/python2.7/dist-packages/Cython/Compiler/ExprNodes.py", line 3178, in is_lvalue
    return not base_type.base_type.is_array
AttributeError: 'CppClassType' object has no attribute 'base_type'

The code is:

cdef cpp_map[int, void*] g_pyWebRequests
cdef PyWebRequest webRequest = PyWebRequest(request, webRequestClient) 
g_pyWebRequests[1] = <void*>webRequest

PyWebRequest is a cdef class.

What to do?

A side note:
I have to keep PyWebRequests in C++ map as I do not want to increase references
to these objects, I need to access them from C++ and I do not have control over
their lifetime, keeping them in a Python dict would make them live forever and the
memory would never be freed.

Using latest Cython 0.19.1

Thanks for help.

Regards,
Czarek

Nikita Nemkin

unread,
May 22, 2013, 1:50:01 PM5/22/13
to cython...@googlegroups.com
On Wed, 22 May 2013 23:18:53 +0600, Czarek Tomczak
<czarek....@gmail.com> wrote:

> I have to keep PyWebRequests in C++ map as I do not want to increase
> references
> to these objects, I need to access them from C++ and I do not have
> control over their lifetime, keeping them in a Python dict would make
> them live forever and the memory would never be freed.

Weak references exist specifically for this purpose.
They are also much safer, because they are cleared automatically
when the pointed object dies.
Take a look at WeakValueDictionary in the standard lib.

Note: cdef classes need an additional member ("cdef __weakref__")
in order to support weak references.
(http://docs.cython.org/src/reference/extension_types.html#weak-referencing)

Language-level weakref support and weakref optimizations are on my
personal Cython wishlist...

Best regards,
Nikita Nemkin

Czarek Tomczak

unread,
May 22, 2013, 2:07:00 PM5/22/13
to cython...@googlegroups.com
Replacing Cython.Shadow.void* with libc.stdint.uintptr_t in the C++ map 
gets rid of the compiler crash, I will just use this fix.

Regards,
Czarek

Czarek Tomczak

unread,
May 22, 2013, 2:12:35 PM5/22/13
to cython...@googlegroups.com
Nikita, thank you for the guide on weak references, I will take a look at it.
Right now I'm removing objects from a C++ map in the __dealloc__ method
of the cdef class, which is called when object lifetime ends, so it works.

Regards,
Czarek

Czarek Tomczak

unread,
May 26, 2013, 5:04:31 AM5/26/13
to cython...@googlegroups.com
I had further problems with using uintptr_t instead of void*, casting python object
to uintptr_t threw some errors, I ended up using weak references and it works great.

Best regards,
Czarek
Reply all
Reply to author
Forward
0 new messages