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
Xavier Thompson
cython
Commits
9a6bcfc1
Commit
9a6bcfc1
authored
Mar 09, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
merged in latest cython-devel
parents
e5223c09
d4262734
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
131 additions
and
51 deletions
+131
-51
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+64
-27
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+10
-3
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+8
-13
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+2
-1
tests/errors/e_excvalfunctype.pyx
tests/errors/e_excvalfunctype.pyx
+2
-2
tests/run/bufaccess.pyx
tests/run/bufaccess.pyx
+5
-5
tests/run/embedsignatures.pyx
tests/run/embedsignatures.pyx
+14
-0
tests/run/print.pyx
tests/run/print.pyx
+26
-0
No files found.
Cython/Compiler/Nodes.py
View file @
9a6bcfc1
...
...
@@ -3564,11 +3564,15 @@ class PrintStatNode(StatNode):
# print statement
#
# arg_tuple TupleNode
# stream ExprNode or None (stdout)
# append_newline boolean
child_attrs
=
[
"arg_tuple"
]
child_attrs
=
[
"arg_tuple"
,
"stream"
]
def
analyse_expressions
(
self
,
env
):
if
self
.
stream
:
self
.
stream
.
analyse_expressions
(
env
)
self
.
stream
=
self
.
stream
.
coerce_to_pyobject
(
env
)
self
.
arg_tuple
.
analyse_expressions
(
env
)
self
.
arg_tuple
=
self
.
arg_tuple
.
coerce_to_pyobject
(
env
)
env
.
use_utility_code
(
printing_utility_code
)
...
...
@@ -3579,12 +3583,18 @@ class PrintStatNode(StatNode):
gil_message
=
"Python print statement"
def
generate_execution_code
(
self
,
code
):
if
self
.
stream
:
self
.
stream
.
generate_evaluation_code
(
code
)
stream_result
=
self
.
stream
.
py_result
()
else
:
stream_result
=
'0'
if
len
(
self
.
arg_tuple
.
args
)
==
1
and
self
.
append_newline
:
arg
=
self
.
arg_tuple
.
args
[
0
]
arg
.
generate_evaluation_code
(
code
)
code
.
putln
(
"if (__Pyx_PrintOne(%s) < 0) %s"
%
(
"if (__Pyx_PrintOne(%s, %s) < 0) %s"
%
(
stream_result
,
arg
.
py_result
(),
code
.
error_goto
(
self
.
pos
)))
arg
.
generate_disposal_code
(
code
)
...
...
@@ -3592,17 +3602,26 @@ class PrintStatNode(StatNode):
else
:
self
.
arg_tuple
.
generate_evaluation_code
(
code
)
code
.
putln
(
"if (__Pyx_Print(%s, %d) < 0) %s"
%
(
"if (__Pyx_Print(%s, %s, %d) < 0) %s"
%
(
stream_result
,
self
.
arg_tuple
.
py_result
(),
self
.
append_newline
,
code
.
error_goto
(
self
.
pos
)))
self
.
arg_tuple
.
generate_disposal_code
(
code
)
self
.
arg_tuple
.
free_temps
(
code
)
if
self
.
stream
:
self
.
stream
.
generate_disposal_code
(
code
)
self
.
stream
.
free_temps
(
code
)
def
generate_function_definitions
(
self
,
env
,
code
):
if
self
.
stream
:
self
.
stream
.
generate_function_definitions
(
env
,
code
)
self
.
arg_tuple
.
generate_function_definitions
(
env
,
code
)
def
annotate
(
self
,
code
):
if
self
.
stream
:
self
.
stream
.
annotate
(
code
)
self
.
arg_tuple
.
annotate
(
code
)
...
...
@@ -5226,7 +5245,7 @@ else:
printing_utility_code
=
UtilityCode
(
proto
=
"""
static int __Pyx_Print(PyObject *, int); /*proto*/
static int __Pyx_Print(PyObject
*, PyObject
*, int); /*proto*/
#if PY_MAJOR_VERSION >= 3
static PyObject* %s = 0;
static PyObject* %s = 0;
...
...
@@ -5242,13 +5261,14 @@ static PyObject *__Pyx_GetStdout(void) {
return f;
}
static int __Pyx_Print(PyObject *arg_tuple, int newline) {
PyObject *f;
static int __Pyx_Print(PyObject* f, PyObject *arg_tuple, int newline) {
PyObject* v;
int i;
if (!(f = __Pyx_GetStdout()))
return -1;
if (!f) {
if (!(f = __Pyx_GetStdout()))
return -1;
}
for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) {
if (PyFile_SoftSpace(f, 1)) {
if (PyFile_WriteString(" ", f) < 0)
...
...
@@ -5276,7 +5296,7 @@ static int __Pyx_Print(PyObject *arg_tuple, int newline) {
#else /* Python 3 has a print function */
static int __Pyx_Print(PyObject *arg_tuple, int newline) {
static int __Pyx_Print(PyObject
* stream, PyObject
*arg_tuple, int newline) {
PyObject* kwargs = 0;
PyObject* result = 0;
PyObject* end_string;
...
...
@@ -5285,27 +5305,43 @@ static int __Pyx_Print(PyObject *arg_tuple, int newline) {
if (!%(PRINT_FUNCTION)s)
return -1;
}
if (stream) {
kwargs = PyDict_New();
if (unlikely(!kwargs))
return -1;
if (unlikely(PyDict_SetItemString(kwargs, "file", stream) < 0))
goto bad;
}
}
if (!newline) {
if (!%(PRINT_KWARGS)s) {
if (!kwargs)
kwargs = %(PRINT_KWARGS)s;
if (!kwargs) {
%(PRINT_KWARGS)s = PyDict_New();
if (!%(PRINT_KWARGS)s)
return -1;
end_string = PyUnicode_FromStringAndSize(" ", 1);
if (!end_string)
if unlikely((!%(PRINT_KWARGS)s))
return -1;
if (PyDict_SetItemString(%(PRINT_KWARGS)s, "end", end_string) < 0) {
Py_DECREF(end_string);
return -1;
}
kwargs = %(PRINT_KWARGS)s;
}
end_string = PyUnicode_FromStringAndSize(" ", 1);
if (unlikely(!end_string))
goto bad;
if (PyDict_SetItemString(%(PRINT_KWARGS)s, "end", end_string) < 0) {
Py_DECREF(end_string);
goto bad;
}
kwargs = %(PRINT_KWARGS)s
;
Py_DECREF(end_string)
;
}
result = PyObject_Call(%(PRINT_FUNCTION)s, arg_tuple, kwargs);
if (unlikely(kwargs) && (kwargs != %(PRINT_FUNCTION)s))
Py_DECREF(kwargs);
if (!result)
return -1;
Py_DECREF(result);
return 0;
bad:
if (kwargs != %(PRINT_FUNCTION)s)
Py_XDECREF(kwargs);
return -1;
}
#endif
...
...
@@ -5317,15 +5353,16 @@ static int __Pyx_Print(PyObject *arg_tuple, int newline) {
printing_one_utility_code
=
UtilityCode
(
proto
=
"""
static int __Pyx_PrintOne(PyObject *o); /*proto*/
static int __Pyx_PrintOne(PyObject
* stream, PyObject
*o); /*proto*/
"""
,
impl
=
r"""
#if PY_MAJOR_VERSION < 3
static int __Pyx_PrintOne(PyObject *o) {
PyObject *f;
if (!(f = __Pyx_GetStdout()))
return -1;
static int __Pyx_PrintOne(PyObject* f, PyObject *o) {
if (!f) {
if (!(f = __Pyx_GetStdout()))
return -1;
}
if (PyFile_SoftSpace(f, 0)) {
if (PyFile_WriteString(" ", f) < 0)
return -1;
...
...
@@ -5337,19 +5374,19 @@ static int __Pyx_PrintOne(PyObject *o) {
return 0;
/* the line below is just to avoid compiler
* compiler warnings about unused functions */
return __Pyx_Print(NULL, 0);
return __Pyx_Print(
f,
NULL, 0);
}
#else /* Python 3 has a print function */
static int __Pyx_PrintOne(PyObject *o) {
static int __Pyx_PrintOne(PyObject
* stream, PyObject
*o) {
int res;
PyObject* arg_tuple = PyTuple_New(1);
if (unlikely(!arg_tuple))
return -1;
Py_INCREF(o);
PyTuple_SET_ITEM(arg_tuple, 0, o);
res = __Pyx_Print(arg_tuple, 1);
res = __Pyx_Print(
stream,
arg_tuple, 1);
Py_DECREF(arg_tuple);
return res;
}
...
...
Cython/Compiler/Parsing.py
View file @
9a6bcfc1
...
...
@@ -975,11 +975,17 @@ def p_expression_or_assignment(s):
def
p_print_statement
(
s
):
# s.sy == 'print'
pos
=
s
.
position
()
ends_with_comma
=
0
s
.
next
()
if
s
.
sy
==
'>>'
:
s
.
error
(
"'print >>' not yet implemented"
)
s
.
next
()
stream
=
p_simple_expr
(
s
)
if
s
.
sy
==
','
:
s
.
next
()
ends_with_comma
=
s
.
sy
in
(
'NEWLINE'
,
'EOF'
)
else
:
stream
=
None
args
=
[]
ends_with_comma
=
0
if
s
.
sy
not
in
(
'NEWLINE'
,
'EOF'
):
args
.
append
(
p_simple_expr
(
s
))
while
s
.
sy
==
','
:
...
...
@@ -990,7 +996,8 @@ def p_print_statement(s):
args
.
append
(
p_simple_expr
(
s
))
arg_tuple
=
ExprNodes
.
TupleNode
(
pos
,
args
=
args
)
return
Nodes
.
PrintStatNode
(
pos
,
arg_tuple
=
arg_tuple
,
append_newline
=
not
ends_with_comma
)
arg_tuple
=
arg_tuple
,
stream
=
stream
,
append_newline
=
not
ends_with_comma
)
def
p_exec_statement
(
s
):
# s.sy == 'exec'
...
...
Cython/Compiler/PyrexTypes.py
View file @
9a6bcfc1
...
...
@@ -164,13 +164,13 @@ class PyrexType(BaseType):
return
1
def
create_typedef_type
(
cname
,
base_typ
e
,
is_external
=
0
):
def
create_typedef_type
(
name
,
base_type
,
cnam
e
,
is_external
=
0
):
if
base_type
.
is_complex
:
if
is_external
:
raise
ValueError
(
"Complex external typedefs not supported"
)
return
base_type
else
:
return
CTypedefType
(
cname
,
base_typ
e
,
is_external
)
return
CTypedefType
(
name
,
base_type
,
cnam
e
,
is_external
)
class
CTypedefType
(
BaseType
):
#
...
...
@@ -180,6 +180,7 @@ class CTypedefType(BaseType):
# HERE IS DELEGATED!
#
# qualified_name string
# typedef_name string
# typedef_cname string
# typedef_base_type PyrexType
# typedef_is_external bool
...
...
@@ -191,8 +192,9 @@ class CTypedefType(BaseType):
from_py_utility_code
=
None
def
__init__
(
self
,
cname
,
base_typ
e
,
is_external
=
0
):
def
__init__
(
self
,
name
,
base_type
,
cnam
e
,
is_external
=
0
):
assert
not
base_type
.
is_complex
self
.
typedef_name
=
name
self
.
typedef_cname
=
cname
self
.
typedef_base_type
=
base_type
self
.
typedef_is_external
=
is_external
...
...
@@ -214,19 +216,12 @@ class CTypedefType(BaseType):
def
declaration_code
(
self
,
entity_code
,
for_display
=
0
,
dll_linkage
=
None
,
pyrex
=
0
):
name
=
self
.
declaration_name
(
for_display
,
pyrex
)
if
pyrex
or
for_display
:
base_code
=
name
base_code
=
self
.
typedef_
name
else
:
base_code
=
public_decl
(
name
,
dll_linkage
)
base_code
=
public_decl
(
self
.
typedef_c
name
,
dll_linkage
)
return
self
.
base_declaration_code
(
base_code
,
entity_code
)
def
declaration_name
(
self
,
for_display
=
0
,
pyrex
=
0
):
if
pyrex
or
for_display
:
return
self
.
qualified_name
else
:
return
self
.
typedef_cname
def
as_argument_type
(
self
):
return
self
...
...
@@ -242,7 +237,7 @@ class CTypedefType(BaseType):
return
"<CTypedefType %s>"
%
self
.
typedef_cname
def
__str__
(
self
):
return
self
.
declaration_name
(
for_display
=
1
)
return
self
.
typedef_name
def
_create_utility_code
(
self
,
template_utility_code
,
template_function_name
):
...
...
Cython/Compiler/Symtab.py
View file @
9a6bcfc1
...
...
@@ -366,7 +366,8 @@ class Scope(object):
else:
cname = self.mangle(Naming.type_prefix, name)
try:
type = PyrexTypes.create_typedef_type(cname, base_type, (visibility == 'extern'))
type = PyrexTypes.create_typedef_type(name, base_type, cname,
(visibility == 'extern'))
except ValueError, e:
error(pos, e.message)
type = PyrexTypes.error_type
...
...
tests/errors/e_excvalfunctype.pyx
View file @
9a6bcfc1
...
...
@@ -7,6 +7,6 @@ cdef spamfunc spam
grail
=
spam
# type mismatch
spam
=
grail
# type mismatch
_ERRORS
=
u"""
7:28: Cannot assign type '
e_excvalfunctype.spamfunc' to 'e_excvalfunctype.
grailfunc'
8:28: Cannot assign type '
e_excvalfunctype.grailfunc' to 'e_excvalfunctype.
spamfunc'
7:28: Cannot assign type '
spamfunc' to '
grailfunc'
8:28: Cannot assign type '
grailfunc' to '
spamfunc'
"""
tests/run/bufaccess.pyx
View file @
9a6bcfc1
...
...
@@ -798,7 +798,7 @@ def printbuf_td_cy_int(object[td_cy_int] buf, shape):
>>> printbuf_td_cy_int(ShortMockBuffer(None, range(3)), (3,))
Traceback (most recent call last):
...
ValueError: Buffer dtype mismatch, expected '
bufaccess.
td_cy_int' but got 'short'
ValueError: Buffer dtype mismatch, expected 'td_cy_int' but got 'short'
"""
cdef
int
i
for
i
in
range
(
shape
[
0
]):
...
...
@@ -813,7 +813,7 @@ def printbuf_td_h_short(object[td_h_short] buf, shape):
>>> printbuf_td_h_short(IntMockBuffer(None, range(3)), (3,))
Traceback (most recent call last):
...
ValueError: Buffer dtype mismatch, expected '
bufaccess.
td_h_short' but got 'int'
ValueError: Buffer dtype mismatch, expected 'td_h_short' but got 'int'
"""
cdef
int
i
for
i
in
range
(
shape
[
0
]):
...
...
@@ -828,7 +828,7 @@ def printbuf_td_h_cy_short(object[td_h_cy_short] buf, shape):
>>> printbuf_td_h_cy_short(IntMockBuffer(None, range(3)), (3,))
Traceback (most recent call last):
...
ValueError: Buffer dtype mismatch, expected '
bufaccess.
td_h_cy_short' but got 'int'
ValueError: Buffer dtype mismatch, expected 'td_h_cy_short' but got 'int'
"""
cdef
int
i
for
i
in
range
(
shape
[
0
]):
...
...
@@ -843,7 +843,7 @@ def printbuf_td_h_ushort(object[td_h_ushort] buf, shape):
>>> printbuf_td_h_ushort(ShortMockBuffer(None, range(3)), (3,))
Traceback (most recent call last):
...
ValueError: Buffer dtype mismatch, expected '
bufaccess.
td_h_ushort' but got 'short'
ValueError: Buffer dtype mismatch, expected 'td_h_ushort' but got 'short'
"""
cdef
int
i
for
i
in
range
(
shape
[
0
]):
...
...
@@ -858,7 +858,7 @@ def printbuf_td_h_double(object[td_h_double] buf, shape):
>>> printbuf_td_h_double(FloatMockBuffer(None, [0.25, 1, 3.125]), (3,))
Traceback (most recent call last):
...
ValueError: Buffer dtype mismatch, expected '
bufaccess.
td_h_double' but got 'float'
ValueError: Buffer dtype mismatch, expected 'td_h_double' but got 'float'
"""
cdef
int
i
for
i
in
range
(
shape
[
0
]):
...
...
tests/run/embedsignatures.pyx
View file @
9a6bcfc1
...
...
@@ -135,6 +135,12 @@ __doc__ = ur"""
>>> print (f_D.__doc__)
f_D(long double D) -> long double
>>> print (f_my_i.__doc__)
f_my_i(MyInt i) -> MyInt
>>> print (f_my_f.__doc__)
f_my_f(MyFloat f) -> MyFloat
"""
cdef
class
Ext
:
...
...
@@ -279,3 +285,11 @@ cpdef double f_d(double d):
cpdef
long
double
f_D
(
long
double
D
):
return
D
ctypedef
int
MyInt
cpdef
MyInt
f_my_i
(
MyInt
i
):
return
i
ctypedef
float
MyFloat
cpdef
MyFloat
f_my_f
(
MyFloat
f
):
return
f
tests/run/print.pyx
View file @
9a6bcfc1
...
...
@@ -14,3 +14,29 @@ def f(a, b):
print
a
,
b
print
a
,
b
,
print
42
,
u"spam"
try
:
from
StringIO
import
StringIO
except
ImportError
:
from
io
import
StringIO
def
s
(
stream
,
a
,
b
):
"""
>>> stream = StringIO()
>>> s(stream, 1, 'test')
>>> print(stream.getvalue())
<BLANKLINE>
1
1 test
1 test
1 test 42 spam
<BLANKLINE>
"""
print
>>
stream
print
>>
stream
,
a
print
>>
stream
,
a
,
print
>>
stream
,
b
print
>>
stream
,
a
,
b
print
>>
stream
,
a
,
b
,
print
>>
stream
,
42
,
u"spam"
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