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
c960580f
Commit
c960580f
authored
Mar 30, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move "import *" utility code from ModuleNode.py to ImportExport.c file
parent
a3447eb8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
121 additions
and
120 deletions
+121
-120
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+3
-120
Cython/Utility/ImportExport.c
Cython/Utility/ImportExport.c
+118
-0
No files found.
Cython/Compiler/ModuleNode.py
View file @
c960580f
...
...
@@ -2024,8 +2024,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
"bad:"
)
code
.
putln
(
"return -1;"
)
code
.
putln
(
"}"
)
code
.
putln
(
import_star_utility_code
)
code
.
exit_cfunc_scope
()
# done with labels
code
.
putln
(
""
)
code
.
putln
(
UtilityCode
.
load_cached
(
"ImportStar"
,
"ImportExport.c"
).
impl
)
code
.
exit_cfunc_scope
()
# done with labels
def
generate_module_init_func
(
self
,
imported_modules
,
env
,
code
):
code
.
enter_cfunc_scope
()
...
...
@@ -2823,124 +2824,6 @@ static CYTHON_INLINE int __Pyx_StrEq(const char *s1, const char *s2) {
#------------------------------------------------------------------------------------
import_star_utility_code
=
"""
/* import_all_from is an unexposed function from ceval.c */
static int
__Pyx_import_all_from(PyObject *locals, PyObject *v)
{
PyObject *all = PyObject_GetAttrString(v, "__all__");
PyObject *dict, *name, *value;
int skip_leading_underscores = 0;
int pos, err;
if (all == NULL) {
if (!PyErr_ExceptionMatches(PyExc_AttributeError))
return -1; /* Unexpected error */
PyErr_Clear();
dict = PyObject_GetAttrString(v, "__dict__");
if (dict == NULL) {
if (!PyErr_ExceptionMatches(PyExc_AttributeError))
return -1;
PyErr_SetString(PyExc_ImportError,
"from-import-* object has no __dict__ and no __all__");
return -1;
}
#if PY_MAJOR_VERSION < 3
all = PyObject_CallMethod(dict, (char *)"keys", NULL);
#else
all = PyMapping_Keys(dict);
#endif
Py_DECREF(dict);
if (all == NULL)
return -1;
skip_leading_underscores = 1;
}
for (pos = 0, err = 0; ; pos++) {
name = PySequence_GetItem(all, pos);
if (name == NULL) {
if (!PyErr_ExceptionMatches(PyExc_IndexError))
err = -1;
else
PyErr_Clear();
break;
}
if (skip_leading_underscores &&
#if PY_MAJOR_VERSION < 3
PyString_Check(name) &&
PyString_AS_STRING(name)[0] == '_')
#else
PyUnicode_Check(name) &&
PyUnicode_AS_UNICODE(name)[0] == '_')
#endif
{
Py_DECREF(name);
continue;
}
value = PyObject_GetAttr(v, name);
if (value == NULL)
err = -1;
else if (PyDict_CheckExact(locals))
err = PyDict_SetItem(locals, name, value);
else
err = PyObject_SetItem(locals, name, value);
Py_DECREF(name);
Py_XDECREF(value);
if (err != 0)
break;
}
Py_DECREF(all);
return err;
}
static int %(IMPORT_STAR)s(PyObject* m) {
int i;
int ret = -1;
char* s;
PyObject *locals = 0;
PyObject *list = 0;
#if PY_MAJOR_VERSION >= 3
PyObject *utf8_name = 0;
#endif
PyObject *name;
PyObject *item;
locals = PyDict_New(); if (!locals) goto bad;
if (__Pyx_import_all_from(locals, m) < 0) goto bad;
list = PyDict_Items(locals); if (!list) goto bad;
for(i=0; i<PyList_GET_SIZE(list); i++) {
name = PyTuple_GET_ITEM(PyList_GET_ITEM(list, i), 0);
item = PyTuple_GET_ITEM(PyList_GET_ITEM(list, i), 1);
#if PY_MAJOR_VERSION >= 3
utf8_name = PyUnicode_AsUTF8String(name);
if (!utf8_name) goto bad;
s = PyBytes_AS_STRING(utf8_name);
if (%(IMPORT_STAR_SET)s(item, name, s) < 0) goto bad;
Py_DECREF(utf8_name); utf8_name = 0;
#else
s = PyString_AsString(name);
if (!s) goto bad;
if (%(IMPORT_STAR_SET)s(item, name, s) < 0) goto bad;
#endif
}
ret = 0;
bad:
Py_XDECREF(locals);
Py_XDECREF(list);
#if PY_MAJOR_VERSION >= 3
Py_XDECREF(utf8_name);
#endif
return ret;
}
"""
%
{
'IMPORT_STAR'
:
Naming
.
import_star
,
'IMPORT_STAR_SET'
:
Naming
.
import_star_set
}
refnanny_utility_code
=
UtilityCode
.
load
(
"Refnanny"
,
"ModuleSetupCode.c"
)
packed_struct_utility_code
=
UtilityCode
(
proto
=
"""
...
...
Cython/Utility/ImportExport.c
View file @
c960580f
...
...
@@ -113,6 +113,124 @@ static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
}
/////////////// ImportStar ///////////////
//@substitute: naming
/* import_all_from is an unexposed function from ceval.c */
static
int
__Pyx_import_all_from
(
PyObject
*
locals
,
PyObject
*
v
)
{
PyObject
*
all
=
PyObject_GetAttrString
(
v
,
"__all__"
);
PyObject
*
dict
,
*
name
,
*
value
;
int
skip_leading_underscores
=
0
;
int
pos
,
err
;
if
(
all
==
NULL
)
{
if
(
!
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
return
-
1
;
/* Unexpected error */
PyErr_Clear
();
dict
=
PyObject_GetAttrString
(
v
,
"__dict__"
);
if
(
dict
==
NULL
)
{
if
(
!
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
return
-
1
;
PyErr_SetString
(
PyExc_ImportError
,
"from-import-* object has no __dict__ and no __all__"
);
return
-
1
;
}
#if PY_MAJOR_VERSION < 3
all
=
PyObject_CallMethod
(
dict
,
(
char
*
)
"keys"
,
NULL
);
#else
all
=
PyMapping_Keys
(
dict
);
#endif
Py_DECREF
(
dict
);
if
(
all
==
NULL
)
return
-
1
;
skip_leading_underscores
=
1
;
}
for
(
pos
=
0
,
err
=
0
;
;
pos
++
)
{
name
=
PySequence_GetItem
(
all
,
pos
);
if
(
name
==
NULL
)
{
if
(
!
PyErr_ExceptionMatches
(
PyExc_IndexError
))
err
=
-
1
;
else
PyErr_Clear
();
break
;
}
if
(
skip_leading_underscores
&&
#if PY_MAJOR_VERSION < 3
PyString_Check
(
name
)
&&
PyString_AS_STRING
(
name
)[
0
]
==
'_'
)
#else
PyUnicode_Check
(
name
)
&&
PyUnicode_AS_UNICODE
(
name
)[
0
]
==
'_'
)
#endif
{
Py_DECREF
(
name
);
continue
;
}
value
=
PyObject_GetAttr
(
v
,
name
);
if
(
value
==
NULL
)
err
=
-
1
;
else
if
(
PyDict_CheckExact
(
locals
))
err
=
PyDict_SetItem
(
locals
,
name
,
value
);
else
err
=
PyObject_SetItem
(
locals
,
name
,
value
);
Py_DECREF
(
name
);
Py_XDECREF
(
value
);
if
(
err
!=
0
)
break
;
}
Py_DECREF
(
all
);
return
err
;
}
static
int
$
{
import_star
}(
PyObject
*
m
)
{
int
i
;
int
ret
=
-
1
;
char
*
s
;
PyObject
*
locals
=
0
;
PyObject
*
list
=
0
;
#if PY_MAJOR_VERSION >= 3
PyObject
*
utf8_name
=
0
;
#endif
PyObject
*
name
;
PyObject
*
item
;
locals
=
PyDict_New
();
if
(
!
locals
)
goto
bad
;
if
(
__Pyx_import_all_from
(
locals
,
m
)
<
0
)
goto
bad
;
list
=
PyDict_Items
(
locals
);
if
(
!
list
)
goto
bad
;
for
(
i
=
0
;
i
<
PyList_GET_SIZE
(
list
);
i
++
)
{
name
=
PyTuple_GET_ITEM
(
PyList_GET_ITEM
(
list
,
i
),
0
);
item
=
PyTuple_GET_ITEM
(
PyList_GET_ITEM
(
list
,
i
),
1
);
#if PY_MAJOR_VERSION >= 3
utf8_name
=
PyUnicode_AsUTF8String
(
name
);
if
(
!
utf8_name
)
goto
bad
;
s
=
PyBytes_AS_STRING
(
utf8_name
);
if
(
$
{
import_star_set
}(
item
,
name
,
s
)
<
0
)
goto
bad
;
Py_DECREF
(
utf8_name
);
utf8_name
=
0
;
#else
s
=
PyString_AsString
(
name
);
if
(
!
s
)
goto
bad
;
if
(
$
{
import_star_set
}(
item
,
name
,
s
)
<
0
)
goto
bad
;
#endif
}
ret
=
0
;
bad:
Py_XDECREF
(
locals
);
Py_XDECREF
(
list
);
#if PY_MAJOR_VERSION >= 3
Py_XDECREF
(
utf8_name
);
#endif
return
ret
;
}
/////////////// 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