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
Gwenaël Samain
cython
Commits
3fceadcd
Commit
3fceadcd
authored
Nov 03, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved helper function __Pyx_Import() into ImportExport.c utility code file
parent
c8019db7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
82 deletions
+79
-82
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+1
-81
Cython/Compiler/FusedNode.py
Cython/Compiler/FusedNode.py
+1
-1
Cython/Utility/ImportExport.c
Cython/Utility/ImportExport.c
+77
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
3fceadcd
...
...
@@ -1948,7 +1948,7 @@ class ImportNode(ExprNode):
self
.
name_list
.
analyse_types
(
env
)
self
.
name_list
.
coerce_to_pyobject
(
env
)
self
.
is_temp
=
1
env
.
use_utility_code
(
import_utility_code
)
env
.
use_utility_code
(
UtilityCode
.
load_cached
(
"Import"
,
"ImportExport.c"
)
)
gil_message
=
"Python import"
...
...
@@ -9901,86 +9901,6 @@ static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
#------------------------------------------------------------------------------------
import_utility_code
=
UtilityCode
(
proto
=
"""
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/
"""
,
impl
=
"""
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) {
PyObject *py_import = 0;
PyObject *empty_list = 0;
PyObject *module = 0;
PyObject *global_dict = 0;
PyObject *empty_dict = 0;
PyObject *list;
py_import = __Pyx_GetAttrString(%(BUILTINS)s, "__import__");
if (!py_import)
goto bad;
if (from_list)
list = from_list;
else {
empty_list = PyList_New(0);
if (!empty_list)
goto bad;
list = empty_list;
}
global_dict = PyModule_GetDict(%(GLOBALS)s);
if (!global_dict)
goto bad;
empty_dict = PyDict_New();
if (!empty_dict)
goto bad;
#if PY_VERSION_HEX >= 0x02050000
{
#if PY_MAJOR_VERSION >= 3
if (level == -1) {
if (strchr(__Pyx_MODULE_NAME, '.')) {
/* try package relative import first */
PyObject *py_level = PyInt_FromLong(1);
if (!py_level)
goto bad;
module = PyObject_CallFunctionObjArgs(py_import,
name, global_dict, empty_dict, list, py_level, NULL);
Py_DECREF(py_level);
if (!module) {
if (!PyErr_ExceptionMatches(PyExc_ImportError))
goto bad;
PyErr_Clear();
}
}
level = 0; /* try absolute import on failure */
}
#endif
if (!module) {
PyObject *py_level = PyInt_FromLong(level);
if (!py_level)
goto bad;
module = PyObject_CallFunctionObjArgs(py_import,
name, global_dict, empty_dict, list, py_level, NULL);
Py_DECREF(py_level);
}
}
#else
if (level>0) {
PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4.");
goto bad;
}
module = PyObject_CallFunctionObjArgs(py_import,
name, global_dict, empty_dict, list, NULL);
#endif
bad:
Py_XDECREF(empty_list);
Py_XDECREF(py_import);
Py_XDECREF(empty_dict);
return module;
}
"""
%
{
"BUILTINS"
:
Naming
.
builtins_cname
,
"GLOBALS"
:
Naming
.
module_cname
,
})
#------------------------------------------------------------------------------------
pyerr_occurred_withgil_utility_code
=
UtilityCode
(
proto
=
"""
static CYTHON_INLINE int __Pyx_ErrOccurredWithGIL(void); /* proto */
...
...
Cython/Compiler/FusedNode.py
View file @
3fceadcd
...
...
@@ -580,7 +580,7 @@ class FusedCFuncDefNode(StatListNode):
if
all_buffer_types
:
self
.
_buffer_declarations
(
pyx_code
,
decl_code
,
all_buffer_types
)
env
.
use_utility_code
(
ExprNodes
.
import_utility_code
)
env
.
use_utility_code
(
Code
.
UtilityCode
.
load_cached
(
"Import"
,
"ImportExport.c"
)
)
pyx_code
.
put_chunk
(
u"""
...
...
Cython/Utility/ImportExport.c
View file @
3fceadcd
...
...
@@ -8,6 +8,83 @@
#endif
#endif
/////////////// Import.proto ///////////////
static
PyObject
*
__Pyx_Import
(
PyObject
*
name
,
PyObject
*
from_list
,
long
level
);
/*proto*/
/////////////// Import ///////////////
//@substitute: naming
static
PyObject
*
__Pyx_Import
(
PyObject
*
name
,
PyObject
*
from_list
,
long
level
)
{
PyObject
*
py_import
=
0
;
PyObject
*
empty_list
=
0
;
PyObject
*
module
=
0
;
PyObject
*
global_dict
=
0
;
PyObject
*
empty_dict
=
0
;
PyObject
*
list
;
py_import
=
__Pyx_GetAttrString
(
$
builtins_cname
,
"__import__"
);
if
(
!
py_import
)
goto
bad
;
if
(
from_list
)
list
=
from_list
;
else
{
empty_list
=
PyList_New
(
0
);
if
(
!
empty_list
)
goto
bad
;
list
=
empty_list
;
}
global_dict
=
PyModule_GetDict
(
$
module_cname
);
if
(
!
global_dict
)
goto
bad
;
empty_dict
=
PyDict_New
();
if
(
!
empty_dict
)
goto
bad
;
#if PY_VERSION_HEX >= 0x02050000
{
#if PY_MAJOR_VERSION >= 3
if
(
level
==
-
1
)
{
if
(
strchr
(
__Pyx_MODULE_NAME
,
'.'
))
{
/* try package relative import first */
PyObject
*
py_level
=
PyInt_FromLong
(
1
);
if
(
!
py_level
)
goto
bad
;
module
=
PyObject_CallFunctionObjArgs
(
py_import
,
name
,
global_dict
,
empty_dict
,
list
,
py_level
,
NULL
);
Py_DECREF
(
py_level
);
if
(
!
module
)
{
if
(
!
PyErr_ExceptionMatches
(
PyExc_ImportError
))
goto
bad
;
PyErr_Clear
();
}
}
level
=
0
;
/* try absolute import on failure */
}
#endif
if
(
!
module
)
{
PyObject
*
py_level
=
PyInt_FromLong
(
level
);
if
(
!
py_level
)
goto
bad
;
module
=
PyObject_CallFunctionObjArgs
(
py_import
,
name
,
global_dict
,
empty_dict
,
list
,
py_level
,
NULL
);
Py_DECREF
(
py_level
);
}
}
#else
if
(
level
>
0
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
"Relative import is not supported for Python <=2.4."
);
goto
bad
;
}
module
=
PyObject_CallFunctionObjArgs
(
py_import
,
name
,
global_dict
,
empty_dict
,
list
,
NULL
);
#endif
bad:
Py_XDECREF
(
empty_list
);
Py_XDECREF
(
py_import
);
Py_XDECREF
(
empty_dict
);
return
module
;
}
/////////////// ModuleImport.proto ///////////////
static
PyObject
*
__Pyx_ImportModule
(
const
char
*
name
);
/*proto*/
...
...
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