Error compiling - "Assignment to reference" - in Cython 0.18

812 views
Skip to first unread message

Czarek Tomczak

unread,
Mar 13, 2013, 12:21:27 PM3/13/13
to cython...@googlegroups.com
Hi there,

I've upgraded to from Cython 0.17.4 to Cython 0.18 and I'm getting this
error message while compiling:

    request_handler.pyx:147:32: Assignment to reference 'cefAllowOSExecution'

The code is as follows:

    from libcpp cimport bool as cpp_bool
    cdef public cpp_bool RequestHandler_OnProtocolExecution(
            CefRefPtr[CefBrowser] cefBrowser,
            CefString& cefUrl,
            cpp_bool& cefAllowOSExecution
            ) except * with gil:
        cefAllowOSExecution = bool(pyAllowOSExecution[0])

It worked fine in Cython 0.17, how do I make it work in Cython 0.18? I've tried 
google but no luck.

Thanks for help,
Czarek

Gerald Dalley

unread,
Apr 25, 2013, 2:49:38 PM4/25/13
to cython...@googlegroups.com
I'm seeing this problem in Cython 0.19 too.

Robert Bradshaw

unread,
Apr 25, 2013, 3:47:50 PM4/25/13
to cython...@googlegroups.com
I'm curious how this ever worked. In any case, there's no reason to
pass a bool as a ref, and certainly not if you're going to re-assign
it before even looking at it (which I assume is an artifact of being a
trimmed-down example).

- Robert
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "cython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cython-users...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Czarek Tomczak

unread,
Apr 25, 2013, 3:54:45 PM4/25/13
to cython...@googlegroups.com
I'm depending on a library that uses this style of references, I'm not
sure how to go around this, I'm stuck with Cython 0.17.4 it seems.
Yes, that was a trimmed-down example.

Regards,
Czarek

Gerald Dalley

unread,
Apr 25, 2013, 4:08:06 PM4/25/13
to cython...@googlegroups.com
In my case, I have a pure Cython cdef function that works like this:

    cdef int memo_key = 0
    cdef map[int,int] memoized_result
    
    cdef foo(int key, map[int,int]& result):
        # NOT threadsafe or re-entrant
        if key != memo_key:
            memoized_result.clear()
            ...populate memoized_result...
            memo_key = key
        result = memoized_result

The function works fine with Cython 0.17.4: it properly causes map's assignment operator to be invoked.  

With Cython 0.19, the Cython compiler fails with an "Assignment to reference" error.

Nikita Nemkin

unread,
Apr 25, 2013, 4:15:02 PM4/25/13
to cython...@googlegroups.com
On Fri, 26 Apr 2013 02:08:06 +0600, Gerald Dalley
<gerald...@gmail.com> wrote:

> On Thursday, April 25, 2013 3:54:45 PM UTC-4, Czarek Tomczak wrote:
>>
>> I'm depending on a library that uses this style of references, I'm not
>> sure how to go around this, I'm stuck with Cython 0.17.4 it seems.
>> Yes, that was a trimmed-down example.

A simple (and ugly) workaround for reference assignment:

cdef void test(int& out):
(&out)[0] = 123


>> On Thursday, April 25, 2013 9:47:50 PM UTC+2, Robert Bradshaw wrote:
>>> I'm curious how this ever worked. In any case, there's no reason to
>>> pass a bool as a ref, and certainly not if you're going to re-assign
>>> it before even looking at it (which I assume is an artifact of being a
>>> trimmed-down example).

Using references for output parameters is relatively common in C++,
there is nothing unusual in Czarek's example.


Best regards,
Nikita Nemkin

Robert Bradshaw

unread,
Apr 25, 2013, 4:29:38 PM4/25/13
to cython...@googlegroups.com
Oh, yes, of course. Good old C++, where local T& x is unassignable but
assigning to an argument T& x is a common idiom. This is a bug in
Cython.
> --
>
> ---You received this message because you are subscribed to the Google Groups

Czarek Tomczak

unread,
May 22, 2013, 2:36:34 PM5/22/13
to cython...@googlegroups.com
Using the "(&out)[0] = " fix for referenced arguments works great.
Thank you so much Nikita for this fix, I can use latest version of
Cython again (it's still not fixed in Cython 0.19.1).

Best regards,
Czarek

Matthias Kümmerer

unread,
Nov 23, 2015, 2:01:57 PM11/23/15
to cython-users
I just stumbled across this bug and noticed that it is still present in Cython 0.23.4. Are there any plans to fix this?

Best regards,
  Matthias

mahesh ravishankar

unread,
Feb 12, 2016, 4:49:52 PM2/12/16
to cython-users
I see this too, and would really like a fix for it. My use case is to be able to pass a reference to a empty memoryview object which is assigned to within the function so that the caller can use the memoryview object
Reply all
Reply to author
Forward
0 new messages