From ef315905a0bfdadd7bd38bbbec41dd440a60e2b7 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Thu, 16 Jul 2009 02:32:52 -0700 Subject: [PATCH] empty bytes global --- Cython/Compiler/ModuleNode.py | 6 ++++++ Cython/Compiler/Naming.py | 1 + Cython/Compiler/Nodes.py | 13 +++---------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index c400499f..28afe203 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -573,6 +573,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln('static PyObject *%s;' % env.module_cname) code.putln('static PyObject *%s;' % Naming.builtins_cname) code.putln('static PyObject *%s;' % Naming.empty_tuple) + code.putln('static PyObject *%s;' % Naming.empty_bytes) if Options.pre_import is not None: code.putln('static PyObject *%s;' % Naming.preimport_cname) code.putln('static int %s;' % Naming.lineno_cname) @@ -1647,6 +1648,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln("#endif") code.putln("%s = PyTuple_New(0); %s" % (Naming.empty_tuple, code.error_goto_if_null(Naming.empty_tuple, self.pos))); + code.putln("#if PY_MAJOR_VERSION < 3"); + code.putln("%s = PyString_FromStringAndSize(\"\", 0); %s" % (Naming.empty_bytes, code.error_goto_if_null(Naming.empty_bytes, self.pos))); + code.putln("#else"); + code.putln("%s = PyBytes_FromStringAndSize(\"\", 0); %s" % (Naming.empty_bytes, code.error_goto_if_null(Naming.empty_bytes, self.pos))); + code.putln("#endif"); code.putln("/*--- Library function declarations ---*/") env.generate_library_function_declarations(code) diff --git a/Cython/Compiler/Naming.py b/Cython/Compiler/Naming.py index e12a4048..4f43f827 100644 --- a/Cython/Compiler/Naming.py +++ b/Cython/Compiler/Naming.py @@ -74,6 +74,7 @@ c_api_tab_cname = pyrex_prefix + "c_api_tab" gilstate_cname = pyrex_prefix + "state" skip_dispatch_cname = pyrex_prefix + "skip_dispatch" empty_tuple = pyrex_prefix + "empty_tuple" +empty_bytes = pyrex_prefix + "empty_bytes" print_function = pyrex_prefix + "print" print_function_kwargs = pyrex_prefix + "print_kwargs" cleanup_cname = pyrex_prefix + "module_cleanup" diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index ef2e841b..e4191d71 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -5412,7 +5412,6 @@ static void __Pyx_AddTraceback(const char *funcname) { PyObject *py_srcfile = 0; PyObject *py_funcname = 0; PyObject *py_globals = 0; - PyObject *empty_string = 0; PyCodeObject *py_code = 0; PyFrameObject *py_frame = 0; @@ -5439,12 +5438,6 @@ static void __Pyx_AddTraceback(const char *funcname) { if (!py_funcname) goto bad; py_globals = PyModule_GetDict(%(GLOBALS)s); if (!py_globals) goto bad; - #if PY_MAJOR_VERSION < 3 - empty_string = PyString_FromStringAndSize("", 0); - #else - empty_string = PyBytes_FromStringAndSize("", 0); - #endif - if (!empty_string) goto bad; py_code = PyCode_New( 0, /*int argcount,*/ #if PY_MAJOR_VERSION >= 3 @@ -5453,7 +5446,7 @@ static void __Pyx_AddTraceback(const char *funcname) { 0, /*int nlocals,*/ 0, /*int stacksize,*/ 0, /*int flags,*/ - empty_string, /*PyObject *code,*/ + %(EMPTY_BYTES)s, /*PyObject *code,*/ %(EMPTY_TUPLE)s, /*PyObject *consts,*/ %(EMPTY_TUPLE)s, /*PyObject *names,*/ %(EMPTY_TUPLE)s, /*PyObject *varnames,*/ @@ -5462,7 +5455,7 @@ static void __Pyx_AddTraceback(const char *funcname) { py_srcfile, /*PyObject *filename,*/ py_funcname, /*PyObject *name,*/ %(LINENO)s, /*int firstlineno,*/ - empty_string /*PyObject *lnotab*/ + %(EMPTY_BYTES)s /*PyObject *lnotab*/ ); if (!py_code) goto bad; py_frame = PyFrame_New( @@ -5477,7 +5470,6 @@ static void __Pyx_AddTraceback(const char *funcname) { bad: Py_XDECREF(py_srcfile); Py_XDECREF(py_funcname); - Py_XDECREF(empty_string); Py_XDECREF(py_code); Py_XDECREF(py_frame); } @@ -5488,6 +5480,7 @@ bad: 'CLINENO': Naming.clineno_cname, 'GLOBALS': Naming.module_cname, 'EMPTY_TUPLE' : Naming.empty_tuple, + 'EMPTY_BYTES' : Naming.empty_bytes, }) restore_exception_utility_code = UtilityCode( -- 2.26.2