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
b13d9a8e
Commit
b13d9a8e
authored
Apr 09, 2009
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
f62ca61f
08971cba
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
71 additions
and
41 deletions
+71
-41
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+4
-4
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+4
-3
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+19
-3
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+1
-1
Cython/Includes/stdio.pxd
Cython/Includes/stdio.pxd
+7
-7
Cython/Includes/stdlib.pxd
Cython/Includes/stdlib.pxd
+6
-6
tests/run/exectest.pyx
tests/run/exectest.pyx
+17
-17
tests/run/range_optimisation_T203.pyx
tests/run/range_optimisation_T203.pyx
+13
-0
No files found.
Cython/Compiler/Builtin.py
View file @
b13d9a8e
...
...
@@ -168,6 +168,7 @@ impl = """
static PyObject* __Pyx_PyRun(PyObject* o, PyObject* globals, PyObject* locals) {
PyObject* result;
PyObject* s = 0;
char *code = 0;
if (!locals && !globals) {
globals = PyModule_GetDict(%s);"""
%
Naming
.
module_cname
+
"""
...
...
@@ -195,13 +196,12 @@ static PyObject* __Pyx_PyRun(PyObject* o, PyObject* globals, PyObject* locals) {
goto bad;
}
result = PyRun_String(
#if PY_MAJOR_VERSION >= 3
PyBytes_AS_STRING(o),
code = PyBytes_AS_STRING(o);
#else
PyString_AS_STRING(o),
code = PyString_AS_STRING(o);
#endif
Py_file_input, globals, locals);
result = PyRun_String(code,
Py_file_input, globals, locals);
Py_XDECREF(s);
return result;
...
...
Cython/Compiler/ExprNodes.py
View file @
b13d9a8e
...
...
@@ -2067,7 +2067,8 @@ class SliceIndexNode(ExprNode):
array_length
=
rhs
.
type
.
size
self
.
generate_slice_guard_code
(
code
,
array_length
)
else
:
error
(
"Slice assignments from pointers are not yet supported."
)
error
(
self
.
pos
,
"Slice assignments from pointers are not yet supported."
)
# FIXME: fix the array size according to start/stop
array_length
=
self
.
base
.
type
.
size
for
i
in
range
(
array_length
):
...
...
@@ -2657,8 +2658,8 @@ class AttributeNode(NewTempExprNode):
def
compile_time_value
(
self
,
denv
):
attr
=
self
.
attribute
if
attr
.
startswith
(
"__"
)
and
attr
.
endswith
(
"__"
):
self
.
error
(
"Invalid attribute name '%s' in compile-time expression"
%
attr
)
error
(
self
.
pos
,
"Invalid attribute name '%s' in compile-time expression"
%
attr
)
return
None
obj
=
self
.
obj
.
compile_time_value
(
denv
)
try
:
...
...
Cython/Compiler/Nodes.py
View file @
b13d9a8e
...
...
@@ -4003,12 +4003,28 @@ class ForFromStatNode(LoopNode, StatNode):
self
.
body
.
generate_execution_code
(
code
)
code
.
put_label
(
code
.
continue_label
)
if
self
.
py_loopvar_node
:
# Reassign py variable to loop var here.
# (For consistancy, should rarely come up in practice.)
# This mess is to make for..from loops with python targets behave
# exactly like those with C targets with regards to re-assignment
# of the loop variable.
import
ExprNodes
from_py_node
=
ExprNodes
.
CoerceFromPyTypeNode
(
self
.
loopvar_node
.
type
,
self
.
target
,
None
)
if
self
.
target
.
entry
.
is_pyglobal
:
# We know target is a NameNode, this is the only ugly case.
target_node
=
ExprNodes
.
PyTempNode
(
self
.
target
.
pos
,
None
)
target_node
.
result_code
=
code
.
funcstate
.
allocate_temp
(
py_object_type
,
False
)
code
.
putln
(
"%s = __Pyx_GetName(%s, %s); %s"
%
(
target_node
.
result_code
,
Naming
.
module_cname
,
self
.
target
.
entry
.
interned_cname
,
code
.
error_goto_if_null
(
target_node
.
result_code
,
self
.
target
.
pos
)))
code
.
put_gotref
(
target_node
.
result_code
)
else
:
target_node
=
self
.
target
from_py_node
=
ExprNodes
.
CoerceFromPyTypeNode
(
self
.
loopvar_node
.
type
,
target_node
,
None
)
from_py_node
.
temp_code
=
loopvar_name
from_py_node
.
generate_result_code
(
code
)
if
self
.
target
.
entry
.
is_pyglobal
:
code
.
put_decref_clear
(
target_node
.
result_code
,
py_object_type
)
code
.
funcstate
.
release_temp
(
target_node
.
result_code
)
code
.
putln
(
"}"
)
if
self
.
py_loopvar_node
:
# This is potentially wasteful, but we don't want the semantics to
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
b13d9a8e
...
...
@@ -730,7 +730,7 @@ property NAME:
if
node
.
name
in
self
.
seen_vars_stack
[
-
1
]:
entry
=
self
.
env_stack
[
-
1
].
lookup
(
node
.
name
)
if
entry
is
None
or
entry
.
visibility
!=
'extern'
:
error
(
node
.
pos
,
"cdef variable '%s' declared after it is used"
%
node
.
name
)
warning
(
node
.
pos
,
"cdef variable '%s' declared after it is used"
%
node
.
name
,
2
)
self
.
visitchildren
(
node
)
return
node
...
...
Cython/Includes/stdio.pxd
View file @
b13d9a8e
cdef
extern
from
"stdio.h"
:
cdef
extern
from
"stdio.h"
nogil
:
ctypedef
struct
FILE
int
printf
(
char
*
format
,
...)
nogil
int
fprintf
(
FILE
*
stream
,
char
*
format
,
...)
nogil
int
sprintf
(
char
*
str
,
char
*
format
,
...)
nogil
FILE
*
fopen
(
char
*
path
,
char
*
mode
)
nogil
int
fclose
(
FILE
*
strea
)
nogil
int
printf
(
char
*
format
,
...)
int
fprintf
(
FILE
*
stream
,
char
*
format
,
...)
int
sprintf
(
char
*
str
,
char
*
format
,
...)
FILE
*
fopen
(
char
*
path
,
char
*
mode
)
int
fclose
(
FILE
*
strea
)
cdef
FILE
*
stdout
int
scanf
(
char
*
format
,
...)
nogil
int
scanf
(
char
*
format
,
...)
Cython/Includes/stdlib.pxd
View file @
b13d9a8e
cdef
extern
from
"stdlib.h"
:
void
free
(
void
*
ptr
)
nogil
void
*
malloc
(
size_t
size
)
nogil
void
*
realloc
(
void
*
ptr
,
size_t
size
)
nogil
size_t
strlen
(
char
*
s
)
nogil
char
*
strcpy
(
char
*
dest
,
char
*
src
)
nogil
cdef
extern
from
"stdlib.h"
nogil
:
void
free
(
void
*
ptr
)
void
*
malloc
(
size_t
size
)
void
*
realloc
(
void
*
ptr
,
size_t
size
)
size_t
strlen
(
char
*
s
)
char
*
strcpy
(
char
*
dest
,
char
*
src
)
tests/run/exectest.pyx
View file @
b13d9a8e
__doc__
=
"""# no unicode string, not tested in Python3!
__doc__
=
u"""
#>>> a
#Traceback (most recent call last):
#NameError: name 'a' is not defined
...
...
@@ -10,32 +10,32 @@ __doc__ = """# no unicode string, not tested in Python3!
>>> d = {}
>>> test_dict_scope2(d)
>>> print
d['b']
>>> print
(d['b'])
2
>>> d1 = {}
>>> test_dict_scope3(d1, d1)
>>> print
d1['b']
>>> print
(d1['b'])
2
>>> d1, d2 = {}, {}
>>> test_dict_scope3(d1, d2)
>>> print
d1.get('b'), d2.get('b'
)
None 2
>>> print
((d1.get('b'), d2.get('b'))
)
(None, 2)
>>> d1, d2 = {}, {}
>>> test_dict_scope3(d1, d2)
>>> print
d1.get('b'), d2.get('b'
)
None 2
>>> print
((d1.get('b'), d2.get('b'))
)
(None, 2)
>>> d1, d2 = dict(a=11), dict(c=5)
>>> test_dict_scope_ref(d1, d2)
>>> print
d1.get('b'), d2.get('b'
)
None 16
>>> print
((d1.get('b'), d2.get('b'))
)
(None, 16)
>>> d = dict(a=11, c=5)
>>> test_dict_scope_ref(d, d)
>>> print
d['b']
>>> print
(d['b'])
16
>>> d = dict(seq = [1,2,3,4])
...
...
@@ -57,22 +57,22 @@ NameError: name 'a' is not defined
def
test_dict_scope1
():
cdef
dict
d
=
{}
exec
"b=1+1"
in
d
return
d
[
'b'
]
exec
u
"b=1+1"
in
d
return
d
[
u
'b'
]
def
test_dict_scope2
(
d
):
exec
"b=1+1"
in
d
exec
u
"b=1+1"
in
d
def
test_dict_scope3
(
d1
,
d2
):
exec
"b=1+1"
in
d1
,
d2
exec
u
"b=1+1"
in
d1
,
d2
def
test_dict_scope_ref
(
d1
,
d2
):
exec
"b=a+c"
in
d1
,
d2
exec
u
"b=a+c"
in
d1
,
d2
def
test_def
(
d
,
varref
):
exec
"""
exec
u
"""
def test():
for x in %s:
yield x+1
"""
%
varref
in
d
return
d
[
'test'
]
return
d
[
u
'test'
]
tests/run/range_optimisation_T203.pyx
View file @
b13d9a8e
...
...
@@ -46,6 +46,12 @@ at 1
at 3
at 7
15
>>> for_from_py_global_target_reassignment(10, 2)
at 0
at 1
at 3
at 7
15
>>> for_in_target_reassignment(10, 2)
at 0
at 1
...
...
@@ -112,6 +118,13 @@ def for_from_py_target_reassignment(int bound, int factor):
i
*=
factor
return
i
def
for_from_py_global_target_reassignment
(
int
bound
,
int
factor
):
global
g_var
for
g_var
from
0
<=
g_var
<
bound
:
print
"at"
,
g_var
g_var
*=
factor
return
g_var
def
for_in_target_reassignment
(
int
bound
,
int
factor
):
cdef
int
i
=
100
for
i
in
range
(
bound
):
...
...
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