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
6b1c2ef1
Commit
6b1c2ef1
authored
Apr 05, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify import-from code a little by moving the name lookup into a utility function
parent
95553775
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
30 deletions
+32
-30
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+6
-30
Cython/Utility/ImportExport.c
Cython/Utility/ImportExport.c
+26
-0
No files found.
Cython/Compiler/Nodes.py
View file @
6b1c2ef1
...
...
@@ -6764,8 +6764,6 @@ class FromImportStatNode(StatNode):
else
:
coerced_item
=
self
.
item
.
coerce_to
(
target
.
type
,
env
)
self
.
interned_items
.
append
((
name
,
target
,
coerced_item
))
if
self
.
interned_items
:
env
.
use_utility_code
(
raise_import_error_utility_code
)
return
self
def
generate_execution_code
(
self
,
code
):
...
...
@@ -6778,21 +6776,16 @@ class FromImportStatNode(StatNode):
code
.
error_goto
(
self
.
pos
)))
item_temp
=
code
.
funcstate
.
allocate_temp
(
py_object_type
,
manage_ref
=
True
)
self
.
item
.
set_cname
(
item_temp
)
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
"PyObjectGetAttrStr"
,
"ObjectHandling.c"
))
if
self
.
interned_items
:
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
"ImportFrom"
,
"ImportExport.c"
))
for
name
,
target
,
coerced_item
in
self
.
interned_items
:
cname
=
code
.
intern_identifier
(
name
)
code
.
putln
(
'%s = __Pyx_
PyObject_GetAttrStr(%s, %s);
'
%
(
'%s = __Pyx_
ImportFrom(%s, %s); %s
'
%
(
item_temp
,
self
.
module
.
py_result
(),
cname
))
code
.
putln
(
'if (%s == NULL) {'
%
item_temp
)
code
.
putln
(
'if (PyErr_ExceptionMatches(PyExc_AttributeError)) '
'__Pyx_RaiseImportError(%s);'
%
cname
)
code
.
putln
(
code
.
error_goto_if_null
(
item_temp
,
self
.
pos
))
code
.
putln
(
'}'
)
code
.
intern_identifier
(
name
),
code
.
error_goto_if_null
(
item_temp
,
self
.
pos
)))
code
.
put_gotref
(
item_temp
)
if
coerced_item
is
None
:
target
.
generate_assignment_code
(
self
.
item
,
code
)
...
...
@@ -8325,20 +8318,3 @@ init="""
a quiet NaN. */
memset(&%(PYX_NAN)s, 0xFF, sizeof(%(PYX_NAN)s));
"""
%
vars
(
Naming
))
#------------------------------------------------------------------------------------
raise_import_error_utility_code
=
UtilityCode
(
proto
=
'''
static CYTHON_INLINE void __Pyx_RaiseImportError(PyObject *name);
'''
,
impl
=
'''
static CYTHON_INLINE void __Pyx_RaiseImportError(PyObject *name) {
#if PY_MAJOR_VERSION < 3
PyErr_Format(PyExc_ImportError, "cannot import name %.230s",
PyString_AsString(name));
#else
PyErr_Format(PyExc_ImportError, "cannot import name %S", name);
#endif
}
'''
)
Cython/Utility/ImportExport.c
View file @
6b1c2ef1
...
...
@@ -100,6 +100,32 @@ bad:
return
module
;
}
/////////////// ImportFrom.proto ///////////////
static
PyObject
*
__Pyx_ImportFrom
(
PyObject
*
module
,
PyObject
*
name
);
/*proto*/
/////////////// ImportFrom ///////////////
//@requires: ObjectHandling.c::PyObjectGetAttrStr
static
PyObject
*
__Pyx_ImportFrom
(
PyObject
*
module
,
PyObject
*
name
)
{
PyObject
*
value
=
__Pyx_PyObject_GetAttrStr
(
module
,
name
);
if
(
unlikely
(
!
value
)
&&
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
{
PyErr_Format
(
PyExc_ImportError
,
#if PY_MAJOR_VERSION < 3
"cannot import name %.230s"
,
PyString_AS_STRING
(
name
));
#else
"cannot import name %S"
,
name
);
#endif
}
return
value
;
}
static
CYTHON_INLINE
void
__Pyx_RaiseImportError
(
PyObject
*
name
)
{
}
/////////////// 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