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
Boxiang Sun
cython
Commits
2a9ab506
Commit
2a9ab506
authored
Aug 27, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement 1-arg exec()
parent
e1ca469b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
11 deletions
+42
-11
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+5
-2
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+1
-1
Cython/Utility/Builtins.c
Cython/Utility/Builtins.c
+24
-6
tests/run/cython3.pyx
tests/run/cython3.pyx
+12
-2
No files found.
Cython/Compiler/Builtin.py
View file @
2a9ab506
...
@@ -55,6 +55,7 @@ bad:
...
@@ -55,6 +55,7 @@ bad:
globals_utility_code
=
UtilityCode
.
load_cached
(
"Globals"
,
"Builtins.c"
)
globals_utility_code
=
UtilityCode
.
load_cached
(
"Globals"
,
"Builtins.c"
)
pyexec_utility_code
=
UtilityCode
.
load_cached
(
"PyExec"
,
"Builtins.c"
)
pyexec_utility_code
=
UtilityCode
.
load_cached
(
"PyExec"
,
"Builtins.c"
)
pyexec_globals_utility_code
=
UtilityCode
.
load_cached
(
"PyExecGlobals"
,
"Builtins.c"
)
intern_utility_code
=
UtilityCode
(
intern_utility_code
=
UtilityCode
(
proto
=
"""
proto
=
"""
...
@@ -215,10 +216,12 @@ builtin_function_table = [
...
@@ -215,10 +216,12 @@ builtin_function_table = [
BuiltinFunction
(
'delattr'
,
"OO"
,
"r"
,
"PyObject_DelAttr"
),
BuiltinFunction
(
'delattr'
,
"OO"
,
"r"
,
"PyObject_DelAttr"
),
BuiltinFunction
(
'dir'
,
"O"
,
"O"
,
"PyObject_Dir"
),
BuiltinFunction
(
'dir'
,
"O"
,
"O"
,
"PyObject_Dir"
),
BuiltinFunction
(
'divmod'
,
"OO"
,
"O"
,
"PyNumber_Divmod"
),
BuiltinFunction
(
'divmod'
,
"OO"
,
"O"
,
"PyNumber_Divmod"
),
BuiltinFunction
(
'exec'
,
"OOO"
,
"O"
,
"__Pyx_Py
Run
3"
,
BuiltinFunction
(
'exec'
,
"OOO"
,
"O"
,
"__Pyx_Py
Exec
3"
,
utility_code
=
pyexec_utility_code
),
utility_code
=
pyexec_utility_code
),
BuiltinFunction
(
'exec'
,
"OO"
,
"O"
,
"__Pyx_Py
Run
2"
,
BuiltinFunction
(
'exec'
,
"OO"
,
"O"
,
"__Pyx_Py
Exec
2"
,
utility_code
=
pyexec_utility_code
),
utility_code
=
pyexec_utility_code
),
BuiltinFunction
(
'exec'
,
"O"
,
"O"
,
"__Pyx_PyExecGlobals"
,
utility_code
=
pyexec_globals_utility_code
),
#('eval', "", "", ""),
#('eval', "", "", ""),
#('execfile', "", "", ""),
#('execfile', "", "", ""),
#('filter', "", "", ""),
#('filter', "", "", ""),
...
...
Cython/Compiler/Nodes.py
View file @
2a9ab506
...
@@ -4685,7 +4685,7 @@ class ExecStatNode(StatNode):
...
@@ -4685,7 +4685,7 @@ class ExecStatNode(StatNode):
args
.
append
(
arg
.
py_result
()
)
args
.
append
(
arg
.
py_result
()
)
args
=
tuple
(
args
+
[
'0'
,
'0'
][:
3
-
len
(
args
)])
args
=
tuple
(
args
+
[
'0'
,
'0'
][:
3
-
len
(
args
)])
temp_result
=
code
.
funcstate
.
allocate_temp
(
PyrexTypes
.
py_object_type
,
manage_ref
=
True
)
temp_result
=
code
.
funcstate
.
allocate_temp
(
PyrexTypes
.
py_object_type
,
manage_ref
=
True
)
code
.
putln
(
"%s = __Pyx_Py
Run
3(%s, %s, %s);"
%
(
code
.
putln
(
"%s = __Pyx_Py
Exec
3(%s, %s, %s);"
%
(
(
temp_result
,)
+
args
))
(
temp_result
,)
+
args
))
for
arg
in
self
.
args
:
for
arg
in
self
.
args
:
arg
.
generate_disposal_code
(
code
)
arg
.
generate_disposal_code
(
code
)
...
...
Cython/Utility/Builtins.c
View file @
2a9ab506
...
@@ -11,7 +11,7 @@ static PyObject* __Pyx_Globals(void); /*proto*/
...
@@ -11,7 +11,7 @@ static PyObject* __Pyx_Globals(void); /*proto*/
// of Python names. Supporting cdef names in the module and write
// of Python names. Supporting cdef names in the module and write
// access requires a rewrite as a dedicated class.
// access requires a rewrite as a dedicated class.
static
PyObject
*
__Pyx_Globals
()
{
static
PyObject
*
__Pyx_Globals
(
void
)
{
Py_ssize_t
i
;
Py_ssize_t
i
;
/*PyObject *d;*/
/*PyObject *d;*/
PyObject
*
names
=
NULL
;
PyObject
*
names
=
NULL
;
...
@@ -47,19 +47,37 @@ bad:
...
@@ -47,19 +47,37 @@ bad:
return
NULL
;
return
NULL
;
}
}
//////////////////// PyExecGlobals.proto ////////////////////
static
PyObject
*
__Pyx_PyExecGlobals
(
PyObject
*
);
//////////////////// PyExecGlobals ////////////////////
//@requires: Globals
//@requires: PyExec
static
PyObject
*
__Pyx_PyExecGlobals
(
PyObject
*
code
)
{
PyObject
*
result
;
PyObject
*
globals
=
__Pyx_Globals
();
if
(
unlikely
(
!
globals
))
return
NULL
;
result
=
__Pyx_PyExec2
(
code
,
globals
);
Py_DECREF
(
globals
);
return
result
;
}
//////////////////// PyExec.proto ////////////////////
//////////////////// PyExec.proto ////////////////////
static
PyObject
*
__Pyx_Py
Run
3
(
PyObject
*
,
PyObject
*
,
PyObject
*
);
static
PyObject
*
__Pyx_Py
Exec
3
(
PyObject
*
,
PyObject
*
,
PyObject
*
);
static
CYTHON_INLINE
PyObject
*
__Pyx_Py
Run
2
(
PyObject
*
,
PyObject
*
);
static
CYTHON_INLINE
PyObject
*
__Pyx_Py
Exec
2
(
PyObject
*
,
PyObject
*
);
//////////////////// PyExec ////////////////////
//////////////////// PyExec ////////////////////
//@substitute: naming
//@substitute: naming
static
CYTHON_INLINE
PyObject
*
__Pyx_Py
Run
2
(
PyObject
*
o
,
PyObject
*
globals
)
{
static
CYTHON_INLINE
PyObject
*
__Pyx_Py
Exec
2
(
PyObject
*
o
,
PyObject
*
globals
)
{
return
__Pyx_Py
Run
3
(
o
,
globals
,
NULL
);
return
__Pyx_Py
Exec
3
(
o
,
globals
,
NULL
);
}
}
static
PyObject
*
__Pyx_Py
Run
3
(
PyObject
*
o
,
PyObject
*
globals
,
PyObject
*
locals
)
{
static
PyObject
*
__Pyx_Py
Exec
3
(
PyObject
*
o
,
PyObject
*
globals
,
PyObject
*
locals
)
{
PyObject
*
result
;
PyObject
*
result
;
PyObject
*
s
=
0
;
PyObject
*
s
=
0
;
char
*
code
=
0
;
char
*
code
=
0
;
...
...
tests/run/cython3.pyx
View file @
2a9ab506
...
@@ -5,8 +5,7 @@
...
@@ -5,8 +5,7 @@
cimport
cython
cimport
cython
__doc__
=
"""
__doc__
=
"""
>>> items = list(locals_function(1).items())
>>> items = sorted(locals_function(1).items())
>>> items.sort()
>>> for item in items:
>>> for item in items:
... print('%s = %r' % item)
... print('%s = %r' % item)
a = 1
a = 1
...
@@ -49,6 +48,17 @@ def exec2_function(cmd):
...
@@ -49,6 +48,17 @@ def exec2_function(cmd):
exec
(
cmd
,
g
)
exec
(
cmd
,
g
)
return
g
return
g
EXEC_GLOBAL
=
[
5
]
def
exec1_function
(
cmd
):
"""
>>> exec1_function('EXEC_GLOBAL.append(1)')
[1]
"""
old
=
len
(
EXEC_GLOBAL
)
exec
(
cmd
)
return
EXEC_GLOBAL
[
old
:]
ustring
=
"abcdefg"
ustring
=
"abcdefg"
def
unicode_literals
():
def
unicode_literals
():
...
...
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