From 2dc08fb15953ec3521823ba6dcbce5d89b6abe7d Mon Sep 17 00:00:00 2001 From: Lisandro Dalcin Date: Tue, 3 Feb 2009 12:40:49 -0200 Subject: [PATCH] build and install "Cython.Runtime.refnanny", use it as a fallback if a bare "refnanny" module is not available for import --- Cython/Compiler/ModuleNode.py | 11 +++++++++-- Makefile | 1 + setup.py | 20 +++++++++++++------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 190ad987..c5ec83ee 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -1587,8 +1587,13 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln("#ifdef CYTHON_REFNANNY") code.putln("void* __pyx_refchk = NULL;") - code.putln("__Pyx_Refnanny = (__Pyx_RefnannyAPIStruct*) PyCObject_Import((char *)\"refnanny\", (char *)\"RefnannyAPI\");") - code.putln("if (!__Pyx_Refnanny) Py_FatalError(\"failed to import refnanny module\");") + code.putln("__Pyx_Refnanny = __Pyx_ImportRefcountAPI(\"refnanny\");") + code.putln("if (!__Pyx_Refnanny) {") + code.putln(" PyErr_Clear();") + code.putln(" __Pyx_Refnanny = __Pyx_ImportRefcountAPI(\"Cython.Runtime.refnanny\");") + code.putln(" if (!__Pyx_Refnanny)") + code.putln(" Py_FatalError(\"failed to import refnanny module\");") + code.putln("}") code.putln("__pyx_refchk = __Pyx_Refnanny->NewContext(\"%s\", __LINE__);"% header3) code.putln("#endif") @@ -2337,6 +2342,8 @@ typedef struct { int (*FinishContext)(void*); } __Pyx_RefnannyAPIStruct; static __Pyx_RefnannyAPIStruct* __Pyx_Refnanny = NULL; +#define __Pyx_ImportRefcountAPI(name) \ + (__Pyx_RefnannyAPIStruct*) PyCObject_Import((char *)name, (char *)\"RefnannyAPI\") #define __Pyx_INCREF(r) __Pyx_Refnanny->INCREF(__pyx_refchk, (r), __LINE__) #define __Pyx_DECREF(r) __Pyx_Refnanny->DECREF(__pyx_refchk, (r), __LINE__) #define __Pyx_XDECREF(r) if((r) == NULL) ; else __Pyx_DECREF(r) diff --git a/Makefile b/Makefile index d6aa5601..6fdb6f96 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,7 @@ clean: @rm -f Cython/Compiler/Parsing.{c,so,pyd} @rm -f Cython/Compiler/Scanning.{c,so,pyd} @rm -f Cython/Compiler/Visitor.{c,so,pyd} + @rm -f Cython/Runtime/refnanny.{c,so,pyd} @rm -f Cython/Plex/Scanners.{c,so,pyd} @(cd Demos; $(MAKE) clean) diff --git a/setup.py b/setup.py index 3cc72b13..b3068691 100644 --- a/setup.py +++ b/setup.py @@ -41,12 +41,17 @@ except ValueError: compiled_modules = ["Cython.Plex.Scanners", "Cython.Compiler.Scanning", "Cython.Compiler.Parsing", - "Cython.Compiler.Visitor"] + "Cython.Compiler.Visitor", + "Cython.Runtime.refnanny"] extensions = [] for module in compiled_modules: source_file = os.path.join(source_root, *module.split('.')) + if os.path.exists(source_file + ".py"): + source_file = source_file + ".py" + else: + source_file = source_file + ".pyx" print("Compiling module %s ..." % module) - result = compile(source_file + ".py") + result = compile(source_file) if result.c_file: extensions.append( Extension(module, sources = [result.c_file]) @@ -62,7 +67,7 @@ except ValueError: setup( - name = 'Cython', + name = 'Cython', version = version, url = 'http://www.cython.org', author = 'Greg Ewing, Robert Bradshaw, Stefan Behnel, Dag Seljebotn, et al.', @@ -101,6 +106,7 @@ setup( packages=[ 'Cython', 'Cython.Compiler', + 'Cython.Runtime', 'Cython.Distutils', 'Cython.Mac', 'Cython.Unix', @@ -109,13 +115,13 @@ setup( 'Cython.Tests', 'Cython.Compiler.Tests', ], - + # pyximport py_modules = ["pyximport/__init__", "pyximport/pyximport", - "pyximport/pyxbuild", - + "pyximport/pyxbuild", + "cython"], - + **setup_args ) -- 2.26.2