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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
d6a7a3d5
Commit
d6a7a3d5
authored
Feb 24, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
externalise module/type importing utility code
parent
5a31a3d8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
86 deletions
+86
-86
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+2
-86
Cython/Utility/ModuleSetupCode.c
Cython/Utility/ModuleSetupCode.c
+84
-0
No files found.
Cython/Compiler/ModuleNode.py
View file @
d6a7a3d5
...
@@ -2353,92 +2353,8 @@ static CYTHON_INLINE int __Pyx_StrEq(const char *s1, const char *s2) {
...
@@ -2353,92 +2353,8 @@ static CYTHON_INLINE int __Pyx_StrEq(const char *s1, const char *s2) {
#------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------
import_module_utility_code
=
UtilityCode
(
import_module_utility_code
=
UtilityCode
.
load_cached
(
"ModuleImport"
,
"ModuleSetupCode.c"
)
proto
=
"""
type_import_utility_code
=
UtilityCode
.
load_cached
(
"TypeImport"
,
"ModuleSetupCode.c"
)
static PyObject *__Pyx_ImportModule(const char *name); /*proto*/
"""
,
impl
=
"""
#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
"""
,
requires
=
[
UtilityCode
.
load_cached
(
"PyIdentifierFromString"
,
"ModuleSetupCode.c"
)])
#------------------------------------------------------------------------------------
type_import_utility_code
=
UtilityCode
(
proto
=
"""
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict); /*proto*/
"""
,
impl
=
"""
#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 && ((PyTypeObject *)result)->tp_basicsize > (Py_ssize_t)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 (((PyTypeObject *)result)->tp_basicsize != (Py_ssize_t)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
"""
,
requires
=
[
UtilityCode
.
load_cached
(
"PyIdentifierFromString"
,
"ModuleSetupCode.c"
)])
#------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------
...
...
Cython/Utility/ModuleSetupCode.c
View file @
d6a7a3d5
...
@@ -378,3 +378,87 @@ static int __Pyx_check_binary_version(void) {
...
@@ -378,3 +378,87 @@ static int __Pyx_check_binary_version(void) {
#endif
#endif
#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
&&
((
PyTypeObject
*
)
result
)
->
tp_basicsize
>
(
Py_ssize_t
)
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
(((
PyTypeObject
*
)
result
)
->
tp_basicsize
!=
(
Py_ssize_t
)
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
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