Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error positions of undefined builtins and constants #3030

Merged
merged 1 commit into from Jul 5, 2019

Conversation

orivej
Copy link
Contributor

@orivej orivej commented Jul 4, 2019

Currently Cython generates code like this:

 int __Pyx_InitCachedBuiltins(void) {
     __pyx_builtin_NAME = __Pyx_GetBuiltinName(...);
     if (!__pyx_builtin_NAME) __PYX_ERR(1, 44, __pyx_L1_error)
 }

 int __pyx_pymod_exec_MODULE(PyObject *__pyx_pyinit_module) {
     if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
 }

When InitCachedBuiltins and InitCachedConstants call __PYX_ERR, they
pass the file and line where a builtin is used, but then pymod_exec
overwrites it with 1 and 1, and the error message looks like this:

   File "FILE", line 1, in init MODULE.
     import os
 NameError: name 'NAME' is not defined

After this change Cython generates:

 int __pyx_pymod_exec_MODULE(PyObject *__pyx_pyinit_module) {
     if (__Pyx_InitCachedBuiltins() < 0) goto __pyx_L1_error;
 }

and prints:

   File "FILE", line 44, in init MODULE.
     print(NAME)
 NameError: name 'NAME' is not defined

Currently Cython generates code like this:

     int __Pyx_InitCachedBuiltins(void) {
         __pyx_builtin_NAME = __Pyx_GetBuiltinName(...);
         if (!__pyx_builtin_NAME) __PYX_ERR(1, 44, __pyx_L1_error)
     }

     int __pyx_pymod_exec_MODULE(PyObject *__pyx_pyinit_module) {
         if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
     }

When InitCachedBuiltins and InitCachedConstants call __PYX_ERR, they
pass the file and line where a builtin is used, but then pymod_exec
overwrites it with 1 and 1, and the error message looks like this:

       File "FILE", line 1, in init MODULE.
         import os
     NameError: name 'NAME' is not defined

After this change Cython generates:

     int __pyx_pymod_exec_MODULE(PyObject *__pyx_pyinit_module) {
         if (__Pyx_InitCachedBuiltins() < 0) goto __pyx_L1_error;
     }

and prints:

       File "FILE", line 44, in init MODULE.
         print(NAME)
     NameError: name 'NAME' is not defined
@scoder
Copy link
Contributor

scoder commented Jul 5, 2019

Thanks

scoder pushed a commit that referenced this pull request Jul 5, 2019
Currently Cython generates code like this:

     int __Pyx_InitCachedBuiltins(void) {
         __pyx_builtin_NAME = __Pyx_GetBuiltinName(...);
         if (!__pyx_builtin_NAME) __PYX_ERR(1, 44, __pyx_L1_error)
     }

     int __pyx_pymod_exec_MODULE(PyObject *__pyx_pyinit_module) {
         if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(1, 1, __pyx_L1_error)
     }

When InitCachedBuiltins and InitCachedConstants call __PYX_ERR, they
pass the file and line where a builtin is used, but then pymod_exec
overwrites it with 1 and 1, and the error message looks like this:

       File "FILE", line 1, in init MODULE.
         import os
     NameError: name 'NAME' is not defined

After this change Cython generates:

     int __pyx_pymod_exec_MODULE(PyObject *__pyx_pyinit_module) {
         if (__Pyx_InitCachedBuiltins() < 0) goto __pyx_L1_error;
     }

and prints:

       File "FILE", line 44, in init MODULE.
         print(NAME)
     NameError: name 'NAME' is not defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants