Commit fb7d630d authored by Lisandro Dalcin's avatar Lisandro Dalcin

Avoid the need to load refnanny module using RTLD_GLOBAL

parent 9db97fa5
...@@ -1585,7 +1585,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1585,7 +1585,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("PyObject* %s;" % Naming.retval_cname) code.putln("PyObject* %s;" % Naming.retval_cname)
tempdecl_code = code.insertion_point() tempdecl_code = code.insertion_point()
code.put_setup_refcount_context(header3) 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_refchk = __Pyx_Refnanny->NewContext(\"%s\", __LINE__);"% header3)
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("%s = PyTuple_New(0); %s" % (Naming.empty_tuple, code.error_goto_if_null(Naming.empty_tuple, self.pos)));
...@@ -2323,27 +2328,29 @@ bad: ...@@ -2323,27 +2328,29 @@ bad:
refcount_utility_code = UtilityCode(proto=""" refcount_utility_code = UtilityCode(proto="""
#ifdef CYTHON_REFNANNY #ifdef CYTHON_REFNANNY
__PYX_EXTERN_C void __Pyx_Refnanny_INCREF(void*, PyObject*, int); typedef struct {
__PYX_EXTERN_C void __Pyx_Refnanny_GOTREF(void*, PyObject*, int); void (*INCREF)(void*, PyObject*, int);
__PYX_EXTERN_C void __Pyx_Refnanny_GIVEREF(void*, PyObject*, int); void (*DECREF)(void*, PyObject*, int);
__PYX_EXTERN_C void __Pyx_Refnanny_INCREF(void*, PyObject*, int); void (*GOTREF)(void*, PyObject*, int);
__PYX_EXTERN_C void __Pyx_Refnanny_DECREF(void*, PyObject*, int); void (*GIVEREF)(void*, PyObject*, int);
__PYX_EXTERN_C void* __Pyx_Refnanny_NewContext(char*, int); void* (*NewContext)(const char*, int);
__PYX_EXTERN_C int __Pyx_Refnanny_FinishContext(void*); int (*FinishContext)(void*);
#define __Pyx_INCREF(r) __Pyx_Refnanny_INCREF(__pyx_refchk, r, __LINE__) } __Pyx_RefnannyAPIStruct;
#define __Pyx_GOTREF(r) __Pyx_Refnanny_GOTREF(__pyx_refchk, r, __LINE__) static __Pyx_RefnannyAPIStruct* __Pyx_Refnanny = NULL;
#define __Pyx_GIVEREF(r) __Pyx_Refnanny_GIVEREF(__pyx_refchk, r, __LINE__) #define __Pyx_INCREF(r) __Pyx_Refnanny->INCREF(__pyx_refchk, (r), __LINE__)
#define __Pyx_DECREF(r) __Pyx_Refnanny_DECREF(__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) #define __Pyx_XDECREF(r) if((r) == NULL) ; else __Pyx_DECREF(r)
#define __Pyx_GOTREF(r) __Pyx_Refnanny->GOTREF(__pyx_refchk, (r), __LINE__)
#define __Pyx_GIVEREF(r) __Pyx_Refnanny->GIVEREF(__pyx_refchk, (r), __LINE__)
#define __Pyx_SetupRefcountContext(name) \ #define __Pyx_SetupRefcountContext(name) \
void* __pyx_refchk = __Pyx_Refnanny_NewContext((char*)name, __LINE__) void* __pyx_refchk = __Pyx_Refnanny->NewContext((name), __LINE__)
#define __Pyx_FinishRefcountContext() __Pyx_Refnanny_FinishContext(__pyx_refchk) #define __Pyx_FinishRefcountContext() __Pyx_Refnanny->FinishContext(__pyx_refchk)
#else #else
#define __Pyx_INCREF(r) Py_INCREF(r) #define __Pyx_INCREF(r) Py_INCREF(r)
#define __Pyx_GOTREF(r)
#define __Pyx_GIVEREF(r)
#define __Pyx_DECREF(r) Py_DECREF(r) #define __Pyx_DECREF(r) Py_DECREF(r)
#define __Pyx_XDECREF(r) Py_XDECREF(r) #define __Pyx_XDECREF(r) Py_XDECREF(r)
#define __Pyx_GOTREF(r)
#define __Pyx_GIVEREF(r)
#define __Pyx_SetupRefcountContext(name) #define __Pyx_SetupRefcountContext(name)
#define __Pyx_FinishRefcountContext() 0 #define __Pyx_FinishRefcountContext() 0
#endif /* CYTHON_REFNANNY */ #endif /* CYTHON_REFNANNY */
......
...@@ -54,7 +54,7 @@ class RefnannyContext(object): ...@@ -54,7 +54,7 @@ class RefnannyContext(object):
# print self.errors # print self.errors
raise RefnannyException("\n".join(self.errors)) raise RefnannyException("\n".join(self.errors))
cdef public void* __Pyx_Refnanny_NewContext(char* funcname, int lineno) except NULL: cdef void* Refnanny_NewContext(char* funcname, int lineno) except NULL:
if exc.PyErr_Occurred() != NULL: if exc.PyErr_Occurred() != NULL:
print "error flag set on newcontext?" print "error flag set on newcontext?"
return NULL return NULL
...@@ -62,8 +62,8 @@ cdef public void* __Pyx_Refnanny_NewContext(char* funcname, int lineno) except N ...@@ -62,8 +62,8 @@ cdef public void* __Pyx_Refnanny_NewContext(char* funcname, int lineno) except N
Py_INCREF(ctx) Py_INCREF(ctx)
return <void*>ctx return <void*>ctx
cdef public void __Pyx_Refnanny_GOTREF(void* ctx, void* p_obj, int lineno): cdef public void Refnanny_GOTREF(void* ctx, void* p_obj, int lineno):
cdef exc.PyObject* type, *value, *tb cdef exc.PyObject* type = NULL, *value = NULL, *tb = NULL
if ctx == NULL: return if ctx == NULL: return
exc.PyErr_Fetch(&type, &value, &tb) exc.PyErr_Fetch(&type, &value, &tb)
try: try:
...@@ -78,8 +78,8 @@ cdef public void __Pyx_Refnanny_GOTREF(void* ctx, void* p_obj, int lineno): ...@@ -78,8 +78,8 @@ cdef public void __Pyx_Refnanny_GOTREF(void* ctx, void* p_obj, int lineno):
Py_XDECREF(<object>tb) Py_XDECREF(<object>tb)
raise raise
cdef public void __Pyx_Refnanny_GIVEREF(void* ctx, void* p_obj, int lineno): cdef public void Refnanny_GIVEREF(void* ctx, void* p_obj, int lineno):
cdef exc.PyObject* type, *value, *tb cdef exc.PyObject* type = NULL, *value = NULL, *tb = NULL
if ctx == NULL: return if ctx == NULL: return
exc.PyErr_Fetch(&type, &value, &tb) exc.PyErr_Fetch(&type, &value, &tb)
try: try:
...@@ -94,18 +94,18 @@ cdef public void __Pyx_Refnanny_GIVEREF(void* ctx, void* p_obj, int lineno): ...@@ -94,18 +94,18 @@ cdef public void __Pyx_Refnanny_GIVEREF(void* ctx, void* p_obj, int lineno):
Py_XDECREF(<object>tb) Py_XDECREF(<object>tb)
raise raise
cdef public void __Pyx_Refnanny_INCREF(void* ctx, void* obj, int lineno): cdef public void Refnanny_INCREF(void* ctx, void* obj, int lineno):
if obj is not NULL: Py_INCREF(<object>obj) if obj is not NULL: Py_INCREF(<object>obj)
__Pyx_Refnanny_GOTREF(ctx, obj, lineno) Refnanny_GOTREF(ctx, obj, lineno)
cdef public void __Pyx_Refnanny_DECREF(void* ctx, void* obj, int lineno): cdef public void Refnanny_DECREF(void* ctx, void* obj, int lineno):
# GIVEREF raises exception if we hit 0 # GIVEREF raises exception if we hit 0
# #
__Pyx_Refnanny_GIVEREF(ctx, obj, lineno) Refnanny_GIVEREF(ctx, obj, lineno)
if obj is not NULL: Py_DECREF(<object>obj) if obj is not NULL: Py_DECREF(<object>obj)
cdef public int __Pyx_Refnanny_FinishContext(void* ctx) except -1: cdef public int Refnanny_FinishContext(void* ctx) except -1:
cdef exc.PyObject* type, *value, *tb cdef exc.PyObject* type = NULL, *value = NULL, *tb = NULL
if ctx == NULL: if ctx == NULL:
assert False assert False
exc.PyErr_Fetch(&type, &value, &tb) exc.PyErr_Fetch(&type, &value, &tb)
...@@ -123,3 +123,25 @@ cdef public int __Pyx_Refnanny_FinishContext(void* ctx) except -1: ...@@ -123,3 +123,25 @@ cdef public int __Pyx_Refnanny_FinishContext(void* ctx) except -1:
return 0 return 0
cdef extern from "Python.h":
object PyCObject_FromVoidPtr(void *, void (*)(void*))
ctypedef struct RefnannyAPIStruct:
void (*INCREF)(void*, void*, int)
void (*DECREF)(void*, void*, int)
void (*GOTREF)(void*, void*, int)
void (*GIVEREF)(void*, void*, int)
void* (*NewContext)(char*, int) except NULL
int (*FinishContext)(void*) except -1
cdef RefnannyAPIStruct api
api.INCREF = Refnanny_INCREF
api.DECREF = Refnanny_DECREF
api.GOTREF = Refnanny_GOTREF
api.GIVEREF = Refnanny_GIVEREF
api.NewContext = Refnanny_NewContext
api.FinishContext = Refnanny_FinishContext
RefnannyAPI = PyCObject_FromVoidPtr(&api, NULL)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment