Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
f5b3c3a0
Commit
f5b3c3a0
authored
Oct 14, 2009
by
Lisandro Dalcin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RefNanny: renaming of internal stuff and simpler import/export API
parent
db48dbe1
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
51 deletions
+67
-51
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+2
-2
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+55
-39
Cython/Runtime/refnanny.pyx
Cython/Runtime/refnanny.pyx
+9
-9
runtests.py
runtests.py
+1
-1
No files found.
Cython/Compiler/Code.py
View file @
f5b3c3a0
...
...
@@ -1273,10 +1273,10 @@ class CCodeWriter(object):
return
self
.
globalstate
.
lookup_filename
(
filename
)
def
put_setup_refcount_context
(
self
,
name
):
self
.
putln
(
'__Pyx_
SetupRefcount
Context("%s");'
%
name
)
self
.
putln
(
'__Pyx_
RefNannySetup
Context("%s");'
%
name
)
def
put_finish_refcount_context
(
self
):
self
.
putln
(
"__Pyx_
FinishRefcount
Context();"
)
self
.
putln
(
"__Pyx_
RefNannyFinish
Context();"
)
def
put_trace_call
(
self
,
name
,
pos
):
self
.
putln
(
'__Pyx_TraceCall("%s", %s[%s], %s);'
%
(
name
,
Naming
.
filetable_cname
,
self
.
lookup_filename
(
pos
[
0
]),
pos
[
1
]));
...
...
Cython/Compiler/ModuleNode.py
View file @
f5b3c3a0
...
...
@@ -260,7 +260,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
globalstate
.
module_pos
=
self
.
pos
globalstate
.
directives
=
self
.
directives
globalstate
.
use_utility_code
(
ref
count
_utility_code
)
globalstate
.
use_utility_code
(
ref
nanny
_utility_code
)
code
=
globalstate
[
'before_global_var'
]
code
.
putln
(
'#define __Pyx_MODULE_NAME "%s"'
%
self
.
full_module_name
)
...
...
@@ -1634,19 +1634,20 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
"{"
)
tempdecl_code
=
code
.
insertion_point
()
self
.
generate_filename_init_call
(
code
)
code
.
putln
(
"#ifdef CYTHON_REFNANNY"
)
code
.
putln
(
"void* __pyx_refchk = NULL;"
)
code
.
putln
(
"__Pyx_Refnanny = __Pyx_ImportRefcountAPI(
\
"
refnanny
\
"
);"
)
code
.
putln
(
"if (!__Pyx_Refnanny) {"
)
code
.
putln
(
"#if CYTHON_REFNANNY"
)
code
.
putln
(
"void* __pyx_refnanny = NULL;"
)
code
.
putln
(
"__Pyx_RefNanny = __Pyx_RefNannyImportAPI(
\
"
refnanny
\
"
);"
)
code
.
putln
(
"if (!__Pyx_RefNanny) {"
)
code
.
putln
(
" PyErr_Clear();"
)
code
.
putln
(
" __Pyx_Ref
nanny = __Pyx_ImportRefcoun
tAPI(
\
"
Cython.Runtime.refnanny
\
"
);"
)
code
.
putln
(
" if (!__Pyx_Ref
n
anny)"
)
code
.
putln
(
" Py_FatalError(
\
"
failed to import
refnanny
module
\
"
);"
)
code
.
putln
(
" __Pyx_Ref
Nanny = __Pyx_RefNannyImpor
tAPI(
\
"
Cython.Runtime.refnanny
\
"
);"
)
code
.
putln
(
" if (!__Pyx_Ref
N
anny)"
)
code
.
putln
(
" Py_FatalError(
\
"
failed to import
'refnanny'
module
\
"
);"
)
code
.
putln
(
"}"
)
code
.
putln
(
"__pyx_ref
chk = __Pyx_Refnanny->New
Context(
\
"
%s
\
"
, __LINE__, __FILE__);"
%
header3
)
code
.
putln
(
"__pyx_ref
nanny = __Pyx_RefNanny->Setup
Context(
\
"
%s
\
"
, __LINE__, __FILE__);"
%
header3
)
code
.
putln
(
"#endif"
)
self
.
generate_filename_init_call
(
code
)
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
)));
...
...
@@ -2444,36 +2445,51 @@ bad:
"""
%
{
'IMPORT_STAR'
:
Naming
.
import_star
,
'IMPORT_STAR_SET'
:
Naming
.
import_star_set
}
refcount_utility_code
=
UtilityCode
(
proto
=
"""
#ifdef CYTHON_REFNANNY
typedef struct {
refnanny_utility_code
=
UtilityCode
(
proto
=
"""
#ifndef CYTHON_REFNANNY
#define CYTHON_REFNANNY 0
#endif
#if CYTHON_REFNANNY
typedef struct {
void (*INCREF)(void*, PyObject*, int);
void (*DECREF)(void*, PyObject*, int);
void (*GOTREF)(void*, PyObject*, int);
void (*GIVEREF)(void*, PyObject*, int);
void* (*New
Context)(const char*, int, const char*);
void* (*Setup
Context)(const char*, int, const char*);
void (*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, (PyObject *)(r), __LINE__)
#define __Pyx_DECREF(r) __Pyx_Refnanny->DECREF(__pyx_refchk, (PyObject *)(r), __LINE__)
#define __Pyx_GOTREF(r) __Pyx_Refnanny->GOTREF(__pyx_refchk, (PyObject *)(r), __LINE__)
#define __Pyx_GIVEREF(r) __Pyx_Refnanny->GIVEREF(__pyx_refchk, (PyObject *)(r), __LINE__)
#define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r);} } while(0)
#define __Pyx_SetupRefcountContext(name)
\
void* __pyx_refchk = __Pyx_Refnanny->NewContext((name), __LINE__, __FILE__)
#define __Pyx_FinishRefcountContext()
\
__Pyx_Refnanny->FinishContext(&__pyx_refchk)
} __Pyx_RefNannyAPIStruct;
static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
static __Pyx_RefNannyAPIStruct * __Pyx_RefNannyImportAPI(const char *modname) {
PyObject *m = NULL, *p = NULL;
void *r = NULL;
m = PyImport_ImportModule((char *)modname);
if (!m) goto end;
p = PyObject_GetAttrString(m, (char *)
\
"
RefNannyAPI
\
"
);
if (!p) goto end;
r = PyLong_AsVoidPtr(p);
end:
Py_XDECREF(p);
Py_XDECREF(m);
return (__Pyx_RefNannyAPIStruct *)r;
}
#define __Pyx_RefNannySetupContext(name)
\
void *__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
#define __Pyx_RefNannyFinishContext()
\
__Pyx_RefNanny->FinishContext(&__pyx_refnanny)
#define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
#define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
#define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
#define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
#define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r);} } while(0)
#else
#define __Pyx_INCREF(r) Py_INCREF(r
)
#define __Pyx_DECREF(r) Py_DECREF(r
)
#define __Pyx_GOT
REF(r)
#define __Pyx_GIVE
REF(r)
#define __Pyx_XDECREF(r) Py_XDEC
REF(r)
#define __Pyx_SetupRefcountContext(name
)
#define __Pyx_FinishRefcountContext(
)
#define __Pyx_RefNannySetupContext(name
)
#define __Pyx_RefNannyFinishContext(
)
#define __Pyx_INCREF(r) Py_INC
REF(r)
#define __Pyx_DECREF(r) Py_DEC
REF(r)
#define __Pyx_GOT
REF(r)
#define __Pyx_GIVEREF(r
)
#define __Pyx_XDECREF(r) Py_XDECREF(r
)
#endif /* CYTHON_REFNANNY */
#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);} } while(0)
#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r);} } while(0)
...
...
Cython/Runtime/refnanny.pyx
View file @
f5b3c3a0
...
...
@@ -69,7 +69,7 @@ cdef void report_unraisable(object e):
# exception has been fetched, in case we are called from
# exception-handling code.
cdef
PyObject
*
New
Context
(
char
*
funcname
,
int
lineno
,
char
*
filename
)
except
NULL
:
cdef
PyObject
*
Setup
Context
(
char
*
funcname
,
int
lineno
,
char
*
filename
)
except
NULL
:
if
Context
is
None
:
# Context may be None during finalize phase.
# In that case, we don't want to be doing anything fancy
...
...
@@ -143,23 +143,23 @@ cdef void FinishContext(PyObject** ctx):
ctx
[
0
]
=
NULL
PyErr_Restore
(
type
,
value
,
tb
)
cdef
extern
from
"Python.h"
:
object
PyCObject_FromVoidPtr
(
void
*
,
void
(
*
)(
void
*
))
ctypedef
struct
RefnannyAPIStruct
:
ctypedef
struct
RefNannyAPIStruct
:
void
(
*
INCREF
)(
PyObject
*
,
PyObject
*
,
int
)
void
(
*
DECREF
)(
PyObject
*
,
PyObject
*
,
int
)
void
(
*
GOTREF
)(
PyObject
*
,
PyObject
*
,
int
)
void
(
*
GIVEREF
)(
PyObject
*
,
PyObject
*
,
int
)
PyObject
*
(
*
New
Context
)(
char
*
,
int
,
char
*
)
except
NULL
PyObject
*
(
*
Setup
Context
)(
char
*
,
int
,
char
*
)
except
NULL
void
(
*
FinishContext
)(
PyObject
**
)
cdef
Ref
n
annyAPIStruct
api
cdef
Ref
N
annyAPIStruct
api
api
.
INCREF
=
INCREF
api
.
DECREF
=
DECREF
api
.
GOTREF
=
GOTREF
api
.
GIVEREF
=
GIVEREF
api
.
NewContext
=
New
Context
api
.
SetupContext
=
Setup
Context
api
.
FinishContext
=
FinishContext
RefnannyAPI
=
PyCObject_FromVoidPtr
(
<
void
*>&
api
,
NULL
)
cdef
extern
from
"Python.h"
:
object
PyLong_FromVoidPtr
(
void
*
)
RefNannyAPI
=
PyLong_FromVoidPtr
(
<
void
*>&
api
)
runtests.py
View file @
f5b3c3a0
...
...
@@ -735,7 +735,7 @@ if __name__ == '__main__':
build_in_temp
=
True
,
pyxbuild_dir
=
os
.
path
.
join
(
WORKDIR
,
"support"
))
sys
.
path
.
insert
(
0
,
os
.
path
.
split
(
libpath
)[
0
])
CFLAGS
.
append
(
"-DCYTHON_REFNANNY"
)
CFLAGS
.
append
(
"-DCYTHON_REFNANNY
=1
"
)
test_bugs
=
False
if
options
.
tickets
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment