cython producing error-prone code in __pyx_import_star_set with C macros

23 views
Skip to first unread message

Vasilis Stamelos

unread,
Apr 21, 2022, 5:28:36 PM4/21/22
to cython-users
hello, i have been trying to learn vulkan with cython and i have hit a wall cause the C compiler throws this error `error C2106: '=': left operand must be l-value`

this is the actual code that throws the error in the C++ source:
```cpp
else if (__Pyx_StrEq(name, "GLFW_CLIENT_API")) {
     GLFW_CLIENT_API = _Pyx_PyInt_As_int(o); if (unlikely((GLFW_CLIENT_API == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 293, __pyx_L2_error)
}
```
which will expand to
`139265 = _Pyx_PyInt_As_int(o); `

what can i do to fix this error?

da-woods

unread,
Apr 22, 2022, 3:45:10 AM4/22/22
to cython...@googlegroups.com
It'd be useful if you could show the code that generated it rather than just linking to a Github repository (which has quite a few files to look through, and no doubt needs headers to be installed even if we wanted to try compiling it ourselves). The relevant code should be in comments right next to the C++ code that's failing.
--

---
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/cython-users/c24ed9a3-61d1-4adb-af9a-4eb0ace3555dn%40googlegroups.com.


Vasilis Stamelos

unread,
Apr 22, 2022, 8:53:20 AM4/22/22
to cython-users
after i searched the source i could find only one instance of GLFW_CLIENT_API being used
```py
cdef GLFWwindow* create_window(int width, int height, char* windowName):

     glfwInit()

     glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API)

     glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE)

    
return glfwCreateWindow(width, height, windowName, NULL, NULL)
```

the only other place that it was mention was in CyGlfw.pxd inside a `cdef extern from` block with the type of int

i hope this helped but i dont know what i am supposed to look for

da-woods

unread,
Apr 22, 2022, 6:09:43 PM4/22/22
to cython...@googlegroups.com
Right - I can reproduce it with a pxd file:

cdef extern from *:
    int SOME_MACRO

and a pyx file:

from cimportstarpxd cimport *

from somewhere_else import *

def f():
    print(SOME_MACRO)

------------------------

Essentially, it believes SOME_MACRO is a writeable integer. It doesn't know what gets imported from "somewhere_else" but will reassign SOME_MACRO if "somewhere_else" defines that value.

Your options are:
1) avoid "import *" and/or "cimport *"
2) Define "SOME_MACRO" differently - e.g. as a member of an extern enum (it doesn't believe enums can be reassigned):
         cdef enum:
            SOME_MACRO

David
Reply all
Reply to author
Forward
0 new messages