build and install "Cython.Runtime.refnanny", use it as a fallback if a bare "refnanny...
authorLisandro Dalcin <dalcinl@gmail.com>
Tue, 3 Feb 2009 14:40:49 +0000 (12:40 -0200)
committerLisandro Dalcin <dalcinl@gmail.com>
Tue, 3 Feb 2009 14:40:49 +0000 (12:40 -0200)
Cython/Compiler/ModuleNode.py
Makefile
setup.py

index 190ad98776f713d001c4e41de0fc7de36c698895..c5ec83ee9963d688db00a1487e2297079c9ece12 100644 (file)
@@ -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)
index d6aa5601c9ed254c799d003cf5e4312dc0b1cb77..6fdb6f96256d4e541723e5a6a4ae79a194b487b8 100644 (file)
--- 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)
 
index 3cc72b1389cd16cdad98db8641ed9fe66636dbb3..b30686918344fff8b643bbad6b86c72011c0e1c7 100644 (file)
--- 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
   )