diff options
author | Orivej Desh <orivej@gmx.fr> | 2019-07-05 09:31:16 +0000 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2019-07-05 11:31:16 +0200 |
commit | edf66a93595aed45de949ce0239348abb9175538 (patch) | |
tree | 403686a8e49c48dd2c49b52919c79b5678efe6fd /Cython/Compiler/ModuleNode.py | |
parent | 6306793d110fe6a0f31fd296604305fce2809ca4 (diff) | |
download | cython-edf66a93595aed45de949ce0239348abb9175538.tar.gz |
Fix error positions of undefined builtins and constants (GH-3030)
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
Diffstat (limited to 'Cython/Compiler/ModuleNode.py')
-rw-r--r-- | Cython/Compiler/ModuleNode.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 2762c2d5b..5c5ad53aa 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -2448,10 +2448,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): if Options.cache_builtins: code.putln("/*--- Builtin init code ---*/") - code.put_error_if_neg(self.pos, "__Pyx_InitCachedBuiltins()") + code.put_error_if_neg(None, "__Pyx_InitCachedBuiltins()") code.putln("/*--- Constants init code ---*/") - code.put_error_if_neg(self.pos, "__Pyx_InitCachedConstants()") + code.put_error_if_neg(None, "__Pyx_InitCachedConstants()") code.putln("/*--- Global type/function init code ---*/") |