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
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
Expand all
Show 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
This diff is collapsed.
Click to expand it.
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) {
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 ///////////////
#ifndef CYTHON_REFNANNY
...
...
@@ -580,7 +485,7 @@ static PyObject* ${cleanup_cname}(PyObject *self, PyObject *unused); /*proto*/
/////////////// RegisterModuleCleanup ///////////////
//@substitute: naming
//@requires: ModuleImport
//@requires:
ImportExport.c::
ModuleImport
#if PY_MAJOR_VERSION < 3
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