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
Boxiang Sun
cython
Commits
7ce4db08
Commit
7ce4db08
authored
Aug 25, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
factored import/export utility code out into separate utility code file ImportExport.c
parent
ce91fb6e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
313 additions
and
319 deletions
+313
-319
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+17
-223
Cython/Utility/ImportExport.c
Cython/Utility/ImportExport.c
+295
-0
Cython/Utility/ModuleSetupCode.c
Cython/Utility/ModuleSetupCode.c
+1
-96
No files found.
Cython/Compiler/ModuleNode.py
View file @
7ce4db08
...
@@ -237,14 +237,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -237,14 +237,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
cname
=
env
.
mangle
(
Naming
.
varptr_prefix
,
entry
.
name
)
cname
=
env
.
mangle
(
Naming
.
varptr_prefix
,
entry
.
name
)
h_code
.
putln
(
"static %s = 0;"
%
type
.
declaration_code
(
cname
))
h_code
.
putln
(
"static %s = 0;"
%
type
.
declaration_code
(
cname
))
h_code
.
putln
(
"#define %s (*%s)"
%
(
entry
.
name
,
cname
))
h_code
.
putln
(
"#define %s (*%s)"
%
(
entry
.
name
,
cname
))
h_code
.
put
(
UtilityCode
.
load_cached
(
"PyIdentifierFromString"
,
"
ModuleSetupCode
.c"
).
proto
)
h_code
.
put
(
UtilityCode
.
load_cached
(
"PyIdentifierFromString"
,
"
ImportExport
.c"
).
proto
)
h_code
.
put
(
import_module_utility_code
.
impl
)
h_code
.
put
(
UtilityCode
.
load_cached
(
"ModuleImport"
,
"ImportExport.c"
)
.
impl
)
if
api_vars
:
if
api_vars
:
h_code
.
put
(
voidptr_import_utility_code
.
impl
)
h_code
.
put
(
UtilityCode
.
load_cached
(
"VoidPtrImport"
,
"ImportExport.c"
)
.
impl
)
if
api_funcs
:
if
api_funcs
:
h_code
.
put
(
function_import_utility_code
.
impl
)
h_code
.
put
(
UtilityCode
.
load_cached
(
"FunctionImport"
,
"ImportExport.c"
)
.
impl
)
if
api_extension_types
:
if
api_extension_types
:
h_code
.
put
(
type_import_utility_code
.
impl
)
h_code
.
put
(
UtilityCode
.
load_cached
(
"TypeImport"
,
"ImportExport.c"
)
.
impl
)
h_code
.
putln
(
""
)
h_code
.
putln
(
""
)
h_code
.
putln
(
"static int import_%s(void) {"
%
self
.
api_name
(
env
))
h_code
.
putln
(
"static int import_%s(void) {"
%
self
.
api_name
(
env
))
h_code
.
putln
(
"PyObject *module = 0;"
)
h_code
.
putln
(
"PyObject *module = 0;"
)
...
@@ -2139,7 +2139,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -2139,7 +2139,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
or
(
Options
.
cimport_from_pyx
and
not
entry
.
visibility
==
'extern'
)):
or
(
Options
.
cimport_from_pyx
and
not
entry
.
visibility
==
'extern'
)):
entries
.
append
(
entry
)
entries
.
append
(
entry
)
if
entries
:
if
entries
:
env
.
use_utility_code
(
voidptr_export_utility_code
)
env
.
use_utility_code
(
UtilityCode
.
load_cached
(
"VoidPtrExport"
,
"ImportExport.c"
)
)
for
entry
in
entries
:
for
entry
in
entries
:
signature
=
entry
.
type
.
declaration_code
(
""
)
signature
=
entry
.
type
.
declaration_code
(
""
)
code
.
putln
(
'if (__Pyx_ExportVoidPtr("%s", (void *)&%s, "%s") < 0) %s'
%
(
code
.
putln
(
'if (__Pyx_ExportVoidPtr("%s", (void *)&%s, "%s") < 0) %s'
%
(
...
@@ -2155,7 +2155,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -2155,7 +2155,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
or
(
Options
.
cimport_from_pyx
and
not
entry
.
visibility
==
'extern'
)):
or
(
Options
.
cimport_from_pyx
and
not
entry
.
visibility
==
'extern'
)):
entries
.
append
(
entry
)
entries
.
append
(
entry
)
if
entries
:
if
entries
:
env
.
use_utility_code
(
function_export_utility_code
)
env
.
use_utility_code
(
UtilityCode
.
load_cached
(
"FunctionExport"
,
"ImportExport.c"
))
for
entry
in
entries
:
for
entry
in
entries
:
signature
=
entry
.
type
.
signature_string
()
signature
=
entry
.
type
.
signature_string
()
code
.
putln
(
'if (__Pyx_ExportFunction("%s", (void (*)(void))%s, "%s") < 0) %s'
%
(
code
.
putln
(
'if (__Pyx_ExportFunction("%s", (void (*)(void))%s, "%s") < 0) %s'
%
(
...
@@ -2191,8 +2192,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -2191,8 +2192,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if
entry
.
defined_in_pxd
:
if
entry
.
defined_in_pxd
:
entries
.
append
(
entry
)
entries
.
append
(
entry
)
if
entries
:
if
entries
:
env
.
use_utility_code
(
import_module_utility_code
)
env
.
use_utility_code
(
env
.
use_utility_code
(
voidptr_import_utility_code
)
UtilityCode
.
load_cached
(
"ModuleImport"
,
"ImportExport.c"
))
env
.
use_utility_code
(
UtilityCode
.
load_cached
(
"VoidPtrImport"
,
"ImportExport.c"
))
temp
=
code
.
funcstate
.
allocate_temp
(
py_object_type
,
manage_ref
=
True
)
temp
=
code
.
funcstate
.
allocate_temp
(
py_object_type
,
manage_ref
=
True
)
code
.
putln
(
code
.
putln
(
'%s = __Pyx_ImportModule("%s"); if (!%s) %s'
%
(
'%s = __Pyx_ImportModule("%s"); if (!%s) %s'
%
(
...
@@ -2219,8 +2222,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -2219,8 +2222,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if
entry
.
defined_in_pxd
and
entry
.
used
:
if
entry
.
defined_in_pxd
and
entry
.
used
:
entries
.
append
(
entry
)
entries
.
append
(
entry
)
if
entries
:
if
entries
:
env
.
use_utility_code
(
import_module_utility_code
)
env
.
use_utility_code
(
env
.
use_utility_code
(
function_import_utility_code
)
UtilityCode
.
load_cached
(
"ModuleImport"
,
"ImportExport.c"
))
env
.
use_utility_code
(
UtilityCode
.
load_cached
(
"FunctionImport"
,
"ImportExport.c"
))
temp
=
code
.
funcstate
.
allocate_temp
(
py_object_type
,
manage_ref
=
True
)
temp
=
code
.
funcstate
.
allocate_temp
(
py_object_type
,
manage_ref
=
True
)
code
.
putln
(
code
.
putln
(
'%s = __Pyx_ImportModule("%s"); if (!%s) %s'
%
(
'%s = __Pyx_ImportModule("%s"); if (!%s) %s'
%
(
...
@@ -2256,19 +2261,15 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -2256,19 +2261,15 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
base_type
.
is_builtin_type
and
not
entry
.
utility_code_definition
):
base_type
.
is_builtin_type
and
not
entry
.
utility_code_definition
):
self
.
generate_type_import_code
(
env
,
base_type
,
self
.
pos
,
code
)
self
.
generate_type_import_code
(
env
,
base_type
,
self
.
pos
,
code
)
def
use_type_import_utility_code
(
self
,
env
):
env
.
use_utility_code
(
type_import_utility_code
)
env
.
use_utility_code
(
import_module_utility_code
)
def
generate_type_import_code
(
self
,
env
,
type
,
pos
,
code
):
def
generate_type_import_code
(
self
,
env
,
type
,
pos
,
code
):
# If not already done, generate code to import the typeobject of an
# If not already done, generate code to import the typeobject of an
# extension type defined in another module, and extract its C method
# extension type defined in another module, and extract its C method
# table pointer if any.
# table pointer if any.
if
type
in
env
.
types_imported
:
if
type
in
env
.
types_imported
:
return
return
env
.
use_utility_code
(
UtilityCode
.
load_cached
(
"TypeImport"
,
"ImportExport.c"
))
self
.
generate_type_import_call
(
type
,
code
,
self
.
generate_type_import_call
(
type
,
code
,
code
.
error_goto_if_null
(
type
.
typeptr_cname
,
pos
))
code
.
error_goto_if_null
(
type
.
typeptr_cname
,
pos
))
self
.
use_type_import_utility_code
(
env
)
if
type
.
vtabptr_cname
:
if
type
.
vtabptr_cname
:
env
.
use_utility_code
(
Nodes
.
get_vtable_utility_code
)
env
.
use_utility_code
(
Nodes
.
get_vtable_utility_code
)
code
.
putln
(
"%s = (struct %s*)__Pyx_GetVtable(%s->tp_dict); %s"
%
(
code
.
putln
(
"%s = (struct %s*)__Pyx_GetVtable(%s->tp_dict); %s"
%
(
...
@@ -2488,213 +2489,6 @@ static CYTHON_INLINE int __Pyx_StrEq(const char *s1, const char *s2) {
...
@@ -2488,213 +2489,6 @@ static CYTHON_INLINE int __Pyx_StrEq(const char *s1, const char *s2) {
#------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------
import_module_utility_code
=
UtilityCode
.
load_cached
(
"ModuleImport"
,
"ModuleSetupCode.c"
)
type_import_utility_code
=
UtilityCode
.
load_cached
(
"TypeImport"
,
"ModuleSetupCode.c"
)
#------------------------------------------------------------------------------------
voidptr_export_utility_code
=
UtilityCode
(
proto
=
"""
static int __Pyx_ExportVoidPtr(const char *name, void *p, const char *sig); /*proto*/
"""
,
impl
=
r"""
static int __Pyx_ExportVoidPtr(const char *name, void *p, const char *sig) {
PyObject *d = 0;
PyObject *cobj = 0;
d = PyObject_GetAttrString(%(MODULE)s, (char *)"%(API)s");
if (!d) {
PyErr_Clear();
d = PyDict_New();
if (!d)
goto bad;
Py_INCREF(d);
if (PyModule_AddObject(%(MODULE)s, (char *)"%(API)s", d) < 0)
goto bad;
}
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
cobj = PyCapsule_New(p, sig, 0);
#else
cobj = PyCObject_FromVoidPtrAndDesc(p, (void *)sig, 0);
#endif
if (!cobj)
goto bad;
if (PyDict_SetItemString(d, name, cobj) < 0)
goto bad;
Py_DECREF(cobj);
Py_DECREF(d);
return 0;
bad:
Py_XDECREF(cobj);
Py_XDECREF(d);
return -1;
}
"""
%
{
'MODULE'
:
Naming
.
module_cname
,
'API'
:
Naming
.
api_name
}
)
function_export_utility_code
=
UtilityCode
(
proto
=
"""
static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig); /*proto*/
"""
,
impl
=
r"""
static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig) {
PyObject *d = 0;
PyObject *cobj = 0;
union {
void (*fp)(void);
void *p;
} tmp;
d = PyObject_GetAttrString(%(MODULE)s, (char *)"%(API)s");
if (!d) {
PyErr_Clear();
d = PyDict_New();
if (!d)
goto bad;
Py_INCREF(d);
if (PyModule_AddObject(%(MODULE)s, (char *)"%(API)s", d) < 0)
goto bad;
}
tmp.fp = f;
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
cobj = PyCapsule_New(tmp.p, sig, 0);
#else
cobj = PyCObject_FromVoidPtrAndDesc(tmp.p, (void *)sig, 0);
#endif
if (!cobj)
goto bad;
if (PyDict_SetItemString(d, name, cobj) < 0)
goto bad;
Py_DECREF(cobj);
Py_DECREF(d);
return 0;
bad:
Py_XDECREF(cobj);
Py_XDECREF(d);
return -1;
}
"""
%
{
'MODULE'
:
Naming
.
module_cname
,
'API'
:
Naming
.
api_name
}
)
voidptr_import_utility_code
=
UtilityCode
(
proto
=
"""
static int __Pyx_ImportVoidPtr(PyObject *module, const char *name, void **p, const char *sig); /*proto*/
"""
,
impl
=
"""
#ifndef __PYX_HAVE_RT_ImportVoidPtr
#define __PYX_HAVE_RT_ImportVoidPtr
static int __Pyx_ImportVoidPtr(PyObject *module, const char *name, void **p, const char *sig) {
PyObject *d = 0;
PyObject *cobj = 0;
d = PyObject_GetAttrString(module, (char *)"%(API)s");
if (!d)
goto bad;
cobj = PyDict_GetItemString(d, name);
if (!cobj) {
PyErr_Format(PyExc_ImportError,
"%%s does not export expected C variable %%s",
PyModule_GetName(module), name);
goto bad;
}
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
if (!PyCapsule_IsValid(cobj, sig)) {
PyErr_Format(PyExc_TypeError,
"C variable %%s.%%s has wrong signature (expected %%s, got %%s)",
PyModule_GetName(module), name, sig, PyCapsule_GetName(cobj));
goto bad;
}
*p = PyCapsule_GetPointer(cobj, sig);
#else
{const char *desc, *s1, *s2;
desc = (const char *)PyCObject_GetDesc(cobj);
if (!desc)
goto bad;
s1 = desc; s2 = sig;
while (*s1 != '
\
\
0' && *s1 == *s2) { s1++; s2++; }
if (*s1 != *s2) {
PyErr_Format(PyExc_TypeError,
"C variable %%s.%%s has wrong signature (expected %%s, got %%s)",
PyModule_GetName(module), name, sig, desc);
goto bad;
}
*p = PyCObject_AsVoidPtr(cobj);}
#endif
if (!(*p))
goto bad;
Py_DECREF(d);
return 0;
bad:
Py_XDECREF(d);
return -1;
}
#endif
"""
%
dict
(
API
=
Naming
.
api_name
)
)
function_import_utility_code
=
UtilityCode
(
proto
=
"""
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig); /*proto*/
"""
,
impl
=
"""
#ifndef __PYX_HAVE_RT_ImportFunction
#define __PYX_HAVE_RT_ImportFunction
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig) {
PyObject *d = 0;
PyObject *cobj = 0;
union {
void (*fp)(void);
void *p;
} tmp;
d = PyObject_GetAttrString(module, (char *)"%(API)s");
if (!d)
goto bad;
cobj = PyDict_GetItemString(d, funcname);
if (!cobj) {
PyErr_Format(PyExc_ImportError,
"%%s does not export expected C function %%s",
PyModule_GetName(module), funcname);
goto bad;
}
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
if (!PyCapsule_IsValid(cobj, sig)) {
PyErr_Format(PyExc_TypeError,
"C function %%s.%%s has wrong signature (expected %%s, got %%s)",
PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
goto bad;
}
tmp.p = PyCapsule_GetPointer(cobj, sig);
#else
{const char *desc, *s1, *s2;
desc = (const char *)PyCObject_GetDesc(cobj);
if (!desc)
goto bad;
s1 = desc; s2 = sig;
while (*s1 != '
\
\
0' && *s1 == *s2) { s1++; s2++; }
if (*s1 != *s2) {
PyErr_Format(PyExc_TypeError,
"C function %%s.%%s has wrong signature (expected %%s, got %%s)",
PyModule_GetName(module), funcname, sig, desc);
goto bad;
}
tmp.p = PyCObject_AsVoidPtr(cobj);}
#endif
*f = tmp.fp;
if (!(*f))
goto bad;
Py_DECREF(d);
return 0;
bad:
Py_XDECREF(d);
return -1;
}
#endif
"""
%
dict
(
API
=
Naming
.
api_name
)
)
#------------------------------------------------------------------------------------
import_star_utility_code
=
"""
import_star_utility_code
=
"""
/* import_all_from is an unexposed function from ceval.c */
/* import_all_from is an unexposed function from ceval.c */
...
...
Cython/Utility/ImportExport.c
0 → 100644
View file @
7ce4db08
/////////////// PyIdentifierFromString.proto ///////////////
#if !defined(__Pyx_PyIdentifier_FromString)
#if PY_MAJOR_VERSION < 3
#define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
#else
#define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
#endif
#endif
/////////////// ModuleImport.proto ///////////////
static
PyObject
*
__Pyx_ImportModule
(
const
char
*
name
);
/*proto*/
/////////////// ModuleImport ///////////////
//@requires: PyIdentifierFromString
#ifndef __PYX_HAVE_RT_ImportModule
#define __PYX_HAVE_RT_ImportModule
static
PyObject
*
__Pyx_ImportModule
(
const
char
*
name
)
{
PyObject
*
py_name
=
0
;
PyObject
*
py_module
=
0
;
py_name
=
__Pyx_PyIdentifier_FromString
(
name
);
if
(
!
py_name
)
goto
bad
;
py_module
=
PyImport_Import
(
py_name
);
Py_DECREF
(
py_name
);
return
py_module
;
bad:
Py_XDECREF
(
py_name
);
return
0
;
}
#endif
/////////////// TypeImport.proto ///////////////
static
PyTypeObject
*
__Pyx_ImportType
(
const
char
*
module_name
,
const
char
*
class_name
,
size_t
size
,
int
strict
);
/*proto*/
/////////////// TypeImport ///////////////
//@requires: PyIdentifierFromString
//@requires: ModuleImport
#ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
static
PyTypeObject
*
__Pyx_ImportType
(
const
char
*
module_name
,
const
char
*
class_name
,
size_t
size
,
int
strict
)
{
PyObject
*
py_module
=
0
;
PyObject
*
result
=
0
;
PyObject
*
py_name
=
0
;
char
warning
[
200
];
py_module
=
__Pyx_ImportModule
(
module_name
);
if
(
!
py_module
)
goto
bad
;
py_name
=
__Pyx_PyIdentifier_FromString
(
class_name
);
if
(
!
py_name
)
goto
bad
;
result
=
PyObject_GetAttr
(
py_module
,
py_name
);
Py_DECREF
(
py_name
);
py_name
=
0
;
Py_DECREF
(
py_module
);
py_module
=
0
;
if
(
!
result
)
goto
bad
;
if
(
!
PyType_Check
(
result
))
{
PyErr_Format
(
PyExc_TypeError
,
"%s.%s is not a type object"
,
module_name
,
class_name
);
goto
bad
;
}
if
(
!
strict
&&
(
size_t
)((
PyTypeObject
*
)
result
)
->
tp_basicsize
>
size
)
{
PyOS_snprintf
(
warning
,
sizeof
(
warning
),
"%s.%s size changed, may indicate binary incompatibility"
,
module_name
,
class_name
);
#if PY_VERSION_HEX < 0x02050000
if
(
PyErr_Warn
(
NULL
,
warning
)
<
0
)
goto
bad
;
#else
if
(
PyErr_WarnEx
(
NULL
,
warning
,
0
)
<
0
)
goto
bad
;
#endif
}
else
if
((
size_t
)((
PyTypeObject
*
)
result
)
->
tp_basicsize
!=
size
)
{
PyErr_Format
(
PyExc_ValueError
,
"%s.%s has the wrong size, try recompiling"
,
module_name
,
class_name
);
goto
bad
;
}
return
(
PyTypeObject
*
)
result
;
bad:
Py_XDECREF
(
py_module
);
Py_XDECREF
(
result
);
return
NULL
;
}
#endif
/////////////// FunctionImport.proto ///////////////
static
int
__Pyx_ImportFunction
(
PyObject
*
module
,
const
char
*
funcname
,
void
(
**
f
)(
void
),
const
char
*
sig
);
/*proto*/
/////////////// FunctionImport ///////////////
//@substitute: naming
#ifndef __PYX_HAVE_RT_ImportFunction
#define __PYX_HAVE_RT_ImportFunction
static
int
__Pyx_ImportFunction
(
PyObject
*
module
,
const
char
*
funcname
,
void
(
**
f
)(
void
),
const
char
*
sig
)
{
PyObject
*
d
=
0
;
PyObject
*
cobj
=
0
;
union
{
void
(
*
fp
)(
void
);
void
*
p
;
}
tmp
;
d
=
PyObject_GetAttrString
(
module
,
(
char
*
)
"$api_name"
);
if
(
!
d
)
goto
bad
;
cobj
=
PyDict_GetItemString
(
d
,
funcname
);
if
(
!
cobj
)
{
PyErr_Format
(
PyExc_ImportError
,
"%s does not export expected C function %s"
,
PyModule_GetName
(
module
),
funcname
);
goto
bad
;
}
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3 && PY_MINOR_VERSION==0)
if
(
!
PyCapsule_IsValid
(
cobj
,
sig
))
{
PyErr_Format
(
PyExc_TypeError
,
"C function %s.%s has wrong signature (expected %s, got %s)"
,
PyModule_GetName
(
module
),
funcname
,
sig
,
PyCapsule_GetName
(
cobj
));
goto
bad
;
}
tmp
.
p
=
PyCapsule_GetPointer
(
cobj
,
sig
);
#else
{
const
char
*
desc
,
*
s1
,
*
s2
;
desc
=
(
const
char
*
)
PyCObject_GetDesc
(
cobj
);
if
(
!
desc
)
goto
bad
;
s1
=
desc
;
s2
=
sig
;
while
(
*
s1
!=
'\0'
&&
*
s1
==
*
s2
)
{
s1
++
;
s2
++
;
}
if
(
*
s1
!=
*
s2
)
{
PyErr_Format
(
PyExc_TypeError
,
"C function %s.%s has wrong signature (expected %s, got %s)"
,
PyModule_GetName
(
module
),
funcname
,
sig
,
desc
);
goto
bad
;
}
tmp
.
p
=
PyCObject_AsVoidPtr
(
cobj
);}
#endif
*
f
=
tmp
.
fp
;
if
(
!
(
*
f
))
goto
bad
;
Py_DECREF
(
d
);
return
0
;
bad:
Py_XDECREF
(
d
);
return
-
1
;
}
#endif
/////////////// FunctionExport.proto ///////////////
static
int
__Pyx_ExportFunction
(
const
char
*
name
,
void
(
*
f
)(
void
),
const
char
*
sig
);
/*proto*/
/////////////// FunctionExport ///////////////
//@substitute: naming
static
int
__Pyx_ExportFunction
(
const
char
*
name
,
void
(
*
f
)(
void
),
const
char
*
sig
)
{
PyObject
*
d
=
0
;
PyObject
*
cobj
=
0
;
union
{
void
(
*
fp
)(
void
);
void
*
p
;
}
tmp
;
d
=
PyObject_GetAttrString
(
$
module_cname
,
(
char
*
)
"$api_name"
);
if
(
!
d
)
{
PyErr_Clear
();
d
=
PyDict_New
();
if
(
!
d
)
goto
bad
;
Py_INCREF
(
d
);
if
(
PyModule_AddObject
(
$
module_cname
,
(
char
*
)
"$api_name"
,
d
)
<
0
)
goto
bad
;
}
tmp
.
fp
=
f
;
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
cobj
=
PyCapsule_New
(
tmp
.
p
,
sig
,
0
);
#else
cobj
=
PyCObject_FromVoidPtrAndDesc
(
tmp
.
p
,
(
void
*
)
sig
,
0
);
#endif
if
(
!
cobj
)
goto
bad
;
if
(
PyDict_SetItemString
(
d
,
name
,
cobj
)
<
0
)
goto
bad
;
Py_DECREF
(
cobj
);
Py_DECREF
(
d
);
return
0
;
bad:
Py_XDECREF
(
cobj
);
Py_XDECREF
(
d
);
return
-
1
;
}
/////////////// VoidPtrImport.proto ///////////////
static
int
__Pyx_ImportVoidPtr
(
PyObject
*
module
,
const
char
*
name
,
void
**
p
,
const
char
*
sig
);
/*proto*/
/////////////// VoidPtrImport ///////////////
//@substitute: naming
#ifndef __PYX_HAVE_RT_ImportVoidPtr
#define __PYX_HAVE_RT_ImportVoidPtr
static
int
__Pyx_ImportVoidPtr
(
PyObject
*
module
,
const
char
*
name
,
void
**
p
,
const
char
*
sig
)
{
PyObject
*
d
=
0
;
PyObject
*
cobj
=
0
;
d
=
PyObject_GetAttrString
(
module
,
(
char
*
)
"$api_name"
);
if
(
!
d
)
goto
bad
;
cobj
=
PyDict_GetItemString
(
d
,
name
);
if
(
!
cobj
)
{
PyErr_Format
(
PyExc_ImportError
,
"%s does not export expected C variable %s"
,
PyModule_GetName
(
module
),
name
);
goto
bad
;
}
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3 && PY_MINOR_VERSION==0)
if
(
!
PyCapsule_IsValid
(
cobj
,
sig
))
{
PyErr_Format
(
PyExc_TypeError
,
"C variable %s.%s has wrong signature (expected %s, got %s)"
,
PyModule_GetName
(
module
),
name
,
sig
,
PyCapsule_GetName
(
cobj
));
goto
bad
;
}
*
p
=
PyCapsule_GetPointer
(
cobj
,
sig
);
#else
{
const
char
*
desc
,
*
s1
,
*
s2
;
desc
=
(
const
char
*
)
PyCObject_GetDesc
(
cobj
);
if
(
!
desc
)
goto
bad
;
s1
=
desc
;
s2
=
sig
;
while
(
*
s1
!=
'\0'
&&
*
s1
==
*
s2
)
{
s1
++
;
s2
++
;
}
if
(
*
s1
!=
*
s2
)
{
PyErr_Format
(
PyExc_TypeError
,
"C variable %s.%s has wrong signature (expected %s, got %s)"
,
PyModule_GetName
(
module
),
name
,
sig
,
desc
);
goto
bad
;
}
*
p
=
PyCObject_AsVoidPtr
(
cobj
);}
#endif
if
(
!
(
*
p
))
goto
bad
;
Py_DECREF
(
d
);
return
0
;
bad:
Py_XDECREF
(
d
);
return
-
1
;
}
#endif
/////////////// VoidPtrExport.proto ///////////////
static
int
__Pyx_ExportVoidPtr
(
const
char
*
name
,
void
*
p
,
const
char
*
sig
);
/*proto*/
/////////////// VoidPtrExport ///////////////
//@substitute: naming
static
int
__Pyx_ExportVoidPtr
(
const
char
*
name
,
void
*
p
,
const
char
*
sig
)
{
PyObject
*
d
=
0
;
PyObject
*
cobj
=
0
;
d
=
PyObject_GetAttrString
(
$
module_cname
,
(
char
*
)
"$api_name"
);
if
(
!
d
)
{
PyErr_Clear
();
d
=
PyDict_New
();
if
(
!
d
)
goto
bad
;
Py_INCREF
(
d
);
if
(
PyModule_AddObject
(
$
module_cname
,
(
char
*
)
"$api_name"
,
d
)
<
0
)
goto
bad
;
}
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3 && PY_MINOR_VERSION==0)
cobj
=
PyCapsule_New
(
p
,
sig
,
0
);
#else
cobj
=
PyCObject_FromVoidPtrAndDesc
(
p
,
(
void
*
)
sig
,
0
);
#endif
if
(
!
cobj
)
goto
bad
;
if
(
PyDict_SetItemString
(
d
,
name
,
cobj
)
<
0
)
goto
bad
;
Py_DECREF
(
cobj
);
Py_DECREF
(
d
);
return
0
;
bad:
Py_XDECREF
(
cobj
);
Py_XDECREF
(
d
);
return
-
1
;
}
Cython/Utility/ModuleSetupCode.c
View file @
7ce4db08
...
@@ -399,101 +399,6 @@ static int __Pyx_check_binary_version(void) {
...
@@ -399,101 +399,6 @@ static int __Pyx_check_binary_version(void) {
return
0
;
return
0
;
}
}
/////////////// PyIdentifierFromString.proto ///////////////
#if !defined(__Pyx_PyIdentifier_FromString)
#if PY_MAJOR_VERSION < 3
#define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
#else
#define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
#endif
#endif
/////////////// TypeImport.proto ///////////////
static
PyTypeObject
*
__Pyx_ImportType
(
const
char
*
module_name
,
const
char
*
class_name
,
size_t
size
,
int
strict
);
/*proto*/
/////////////// TypeImport ///////////////
//@requires: PyIdentifierFromString
#ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
static
PyTypeObject
*
__Pyx_ImportType
(
const
char
*
module_name
,
const
char
*
class_name
,
size_t
size
,
int
strict
)
{
PyObject
*
py_module
=
0
;
PyObject
*
result
=
0
;
PyObject
*
py_name
=
0
;
char
warning
[
200
];
py_module
=
__Pyx_ImportModule
(
module_name
);
if
(
!
py_module
)
goto
bad
;
py_name
=
__Pyx_PyIdentifier_FromString
(
class_name
);
if
(
!
py_name
)
goto
bad
;
result
=
PyObject_GetAttr
(
py_module
,
py_name
);
Py_DECREF
(
py_name
);
py_name
=
0
;
Py_DECREF
(
py_module
);
py_module
=
0
;
if
(
!
result
)
goto
bad
;
if
(
!
PyType_Check
(
result
))
{
PyErr_Format
(
PyExc_TypeError
,
"%s.%s is not a type object"
,
module_name
,
class_name
);
goto
bad
;
}
if
(
!
strict
&&
(
size_t
)((
PyTypeObject
*
)
result
)
->
tp_basicsize
>
size
)
{
PyOS_snprintf
(
warning
,
sizeof
(
warning
),
"%s.%s size changed, may indicate binary incompatibility"
,
module_name
,
class_name
);
#if PY_VERSION_HEX < 0x02050000
if
(
PyErr_Warn
(
NULL
,
warning
)
<
0
)
goto
bad
;
#else
if
(
PyErr_WarnEx
(
NULL
,
warning
,
0
)
<
0
)
goto
bad
;
#endif
}
else
if
((
size_t
)((
PyTypeObject
*
)
result
)
->
tp_basicsize
!=
size
)
{
PyErr_Format
(
PyExc_ValueError
,
"%s.%s has the wrong size, try recompiling"
,
module_name
,
class_name
);
goto
bad
;
}
return
(
PyTypeObject
*
)
result
;
bad:
Py_XDECREF
(
py_module
);
Py_XDECREF
(
result
);
return
NULL
;
}
#endif
/////////////// ModuleImport.proto ///////////////
static
PyObject
*
__Pyx_ImportModule
(
const
char
*
name
);
/*proto*/
/////////////// ModuleImport ///////////////
//@requires: PyIdentifierFromString
#ifndef __PYX_HAVE_RT_ImportModule
#define __PYX_HAVE_RT_ImportModule
static
PyObject
*
__Pyx_ImportModule
(
const
char
*
name
)
{
PyObject
*
py_name
=
0
;
PyObject
*
py_module
=
0
;
py_name
=
__Pyx_PyIdentifier_FromString
(
name
);
if
(
!
py_name
)
goto
bad
;
py_module
=
PyImport_Import
(
py_name
);
Py_DECREF
(
py_name
);
return
py_module
;
bad:
Py_XDECREF
(
py_name
);
return
0
;
}
#endif
/////////////// Refnanny.proto ///////////////
/////////////// Refnanny.proto ///////////////
#ifndef CYTHON_REFNANNY
#ifndef CYTHON_REFNANNY
...
@@ -580,7 +485,7 @@ static PyObject* ${cleanup_cname}(PyObject *self, PyObject *unused); /*proto*/
...
@@ -580,7 +485,7 @@ static PyObject* ${cleanup_cname}(PyObject *self, PyObject *unused); /*proto*/
/////////////// RegisterModuleCleanup ///////////////
/////////////// RegisterModuleCleanup ///////////////
//@substitute: naming
//@substitute: naming
//@requires: ModuleImport
//@requires:
ImportExport.c::
ModuleImport
#if PY_MAJOR_VERSION < 3
#if PY_MAJOR_VERSION < 3
static
int
__Pyx_RegisterCleanup
(
void
)
{
static
int
__Pyx_RegisterCleanup
(
void
)
{
...
...
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