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
Gwenaël Samain
cython
Commits
914dc35d
Commit
914dc35d
authored
Jul 14, 2014
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:cython/cython into cdef_closure
parents
ac8a7d95
1c3855fb
Changes
16
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
402 additions
and
75 deletions
+402
-75
CHANGES.rst
CHANGES.rst
+9
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+180
-39
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+10
-3
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+3
-1
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+3
-0
Cython/Plex/Scanners.pxd
Cython/Plex/Scanners.pxd
+1
-1
Cython/Utils.py
Cython/Utils.py
+13
-0
cythonize.py
cythonize.py
+9
-0
setup.py
setup.py
+3
-2
tests/compile/builtinfuncs.pyx
tests/compile/builtinfuncs.pyx
+4
-2
tests/run/constant_folding.py
tests/run/constant_folding.py
+7
-7
tests/run/cpdef_enums_import.srctree
tests/run/cpdef_enums_import.srctree
+2
-2
tests/run/notinop.pyx
tests/run/notinop.pyx
+14
-14
tests/run/pointers.pyx
tests/run/pointers.pyx
+27
-0
tests/run/py2_super.pyx
tests/run/py2_super.pyx
+97
-0
tests/run/py3k_super.pyx
tests/run/py3k_super.pyx
+20
-4
No files found.
CHANGES.rst
View file @
914dc35d
...
@@ -21,6 +21,13 @@ Features added
...
@@ -21,6 +21,13 @@ Features added
is raised only when such a pointer is assigned to a variable and
is raised only when such a pointer is assigned to a variable and
would thus exceed the lifetime of the string itself.
would thus exceed the lifetime of the string itself.
* The "and"/"or" operators try to avoid unnecessary coercions of their
arguments. They now evaluate the truth value of each argument
independently and only coerce the final result of the whole expression
to the target type (e.g. the type on the left side of an assignment).
This also avoids reference counting overhead for Python values during
evaluation and generally improves the code flow in the generated C code.
* Cascaded assignments (a = b = ...) try to minimise the number of
* Cascaded assignments (a = b = ...) try to minimise the number of
type coercions.
type coercions.
...
@@ -84,6 +91,8 @@ Bugs fixed
...
@@ -84,6 +91,8 @@ Bugs fixed
* Correctly handle ``from cython.submodule cimport name``.
* Correctly handle ``from cython.submodule cimport name``.
* Fix infinite recursion when using super with cpdef methods.
Other changes
Other changes
-------------
-------------
...
...
Cython/Compiler/ExprNodes.py
View file @
914dc35d
This diff is collapsed.
Click to expand it.
Cython/Compiler/Nodes.py
View file @
914dc35d
...
@@ -27,6 +27,7 @@ from .Code import UtilityCode
...
@@ -27,6 +27,7 @@ from .Code import UtilityCode
from
.StringEncoding
import
EncodedString
,
escape_byte_string
,
split_string_literal
from
.StringEncoding
import
EncodedString
,
escape_byte_string
,
split_string_literal
from
.
import
Options
from
.
import
Options
from
.
import
DebugFlags
from
.
import
DebugFlags
from
Cython.Utils
import
LazyStr
absolute_path_length
=
0
absolute_path_length
=
0
...
@@ -2294,10 +2295,16 @@ class CFuncDefNode(FuncDefNode):
...
@@ -2294,10 +2295,16 @@ class CFuncDefNode(FuncDefNode):
if
is_module_scope
:
if
is_module_scope
:
cfunc
=
ExprNodes
.
NameNode
(
self
.
pos
,
name
=
self
.
entry
.
name
)
cfunc
=
ExprNodes
.
NameNode
(
self
.
pos
,
name
=
self
.
entry
.
name
)
else
:
else
:
self_arg
=
ExprNodes
.
NameNode
(
self
.
pos
,
name
=
arg_names
[
0
])
type_entry
=
self
.
type
.
args
[
0
].
type
.
entry
cfunc
=
ExprNodes
.
AttributeNode
(
self
.
pos
,
obj
=
self_arg
,
attribute
=
self
.
entry
.
name
)
type_arg
=
ExprNodes
.
NameNode
(
self
.
pos
,
name
=
type_entry
.
name
)
type_arg
.
entry
=
type_entry
cfunc
=
ExprNodes
.
AttributeNode
(
self
.
pos
,
obj
=
type_arg
,
attribute
=
self
.
entry
.
name
)
skip_dispatch
=
not
is_module_scope
or
Options
.
lookup_module_cpdef
skip_dispatch
=
not
is_module_scope
or
Options
.
lookup_module_cpdef
c_call
=
ExprNodes
.
SimpleCallNode
(
self
.
pos
,
function
=
cfunc
,
args
=
[
ExprNodes
.
NameNode
(
self
.
pos
,
name
=
n
)
for
n
in
arg_names
[
1
-
is_module_scope
:]],
wrapper_call
=
skip_dispatch
)
c_call
=
ExprNodes
.
SimpleCallNode
(
self
.
pos
,
function
=
cfunc
,
args
=
[
ExprNodes
.
NameNode
(
self
.
pos
,
name
=
n
)
for
n
in
arg_names
],
wrapper_call
=
skip_dispatch
)
return
ReturnStatNode
(
pos
=
self
.
pos
,
return_type
=
PyrexTypes
.
py_object_type
,
value
=
c_call
)
return
ReturnStatNode
(
pos
=
self
.
pos
,
return_type
=
PyrexTypes
.
py_object_type
,
value
=
c_call
)
def
declare_arguments
(
self
,
env
):
def
declare_arguments
(
self
,
env
):
...
...
Cython/Compiler/Optimize.py
View file @
914dc35d
...
@@ -816,6 +816,8 @@ class SwitchTransform(Visitor.CythonTransform):
...
@@ -816,6 +816,8 @@ class SwitchTransform(Visitor.CythonTransform):
if
isinstance
(
cond
,
(
ExprNodes
.
CoerceToTempNode
,
if
isinstance
(
cond
,
(
ExprNodes
.
CoerceToTempNode
,
ExprNodes
.
CoerceToBooleanNode
)):
ExprNodes
.
CoerceToBooleanNode
)):
cond
=
cond
.
arg
cond
=
cond
.
arg
elif
isinstance
(
cond
,
ExprNodes
.
BoolBinopResultNode
):
cond
=
cond
.
arg
.
arg
elif
isinstance
(
cond
,
UtilNodes
.
EvalWithTempExprNode
):
elif
isinstance
(
cond
,
UtilNodes
.
EvalWithTempExprNode
):
# this is what we get from the FlattenInListTransform
# this is what we get from the FlattenInListTransform
cond
=
cond
.
subexpression
cond
=
cond
.
subexpression
...
@@ -860,7 +862,7 @@ class SwitchTransform(Visitor.CythonTransform):
...
@@ -860,7 +862,7 @@ class SwitchTransform(Visitor.CythonTransform):
elif
getattr
(
cond
.
operand1
,
'entry'
,
None
)
\
elif
getattr
(
cond
.
operand1
,
'entry'
,
None
)
\
and
cond
.
operand1
.
entry
.
is_const
:
and
cond
.
operand1
.
entry
.
is_const
:
return
not_in
,
cond
.
operand2
,
[
cond
.
operand1
]
return
not_in
,
cond
.
operand2
,
[
cond
.
operand1
]
elif
isinstance
(
cond
,
ExprNodes
.
BoolBinopNode
):
elif
isinstance
(
cond
,
(
ExprNodes
.
BoolBinopNode
,
ExprNodes
.
GenericBoolBinopNode
)
):
if
cond
.
operator
==
'or'
or
(
allow_not_in
and
cond
.
operator
==
'and'
):
if
cond
.
operator
==
'or'
or
(
allow_not_in
and
cond
.
operator
==
'and'
):
allow_not_in
=
(
cond
.
operator
==
'and'
)
allow_not_in
=
(
cond
.
operator
==
'and'
)
not_in_1
,
t1
,
c1
=
self
.
extract_conditions
(
cond
.
operand1
,
allow_not_in
)
not_in_1
,
t1
,
c1
=
self
.
extract_conditions
(
cond
.
operand1
,
allow_not_in
)
...
...
Cython/Compiler/PyrexTypes.py
View file @
914dc35d
...
@@ -3711,6 +3711,9 @@ def independent_spanning_type(type1, type2):
...
@@ -3711,6 +3711,9 @@ def independent_spanning_type(type1, type2):
return
py_object_type
return
py_object_type
span_type
=
_spanning_type
(
type1
,
type2
)
span_type
=
_spanning_type
(
type1
,
type2
)
if
span_type
is
None
:
if
span_type
is
None
:
if
type1
.
is_ptr
and
type2
.
is_ptr
:
# incompatible pointers, void* will do as a result
return
c_void_ptr_type
return
error_type
return
error_type
return
span_type
return
span_type
...
...
Cython/Plex/Scanners.pxd
View file @
914dc35d
...
@@ -24,7 +24,7 @@ cdef class Scanner:
...
@@ -24,7 +24,7 @@ cdef class Scanner:
cdef
public
list
queue
cdef
public
list
queue
cdef
public
bint
trace
cdef
public
bint
trace
cdef
public
cur_char
cdef
public
cur_char
cdef
public
int
input_state
cdef
public
long
input_state
cdef
public
level
cdef
public
level
...
...
Cython/Utils.py
View file @
914dc35d
...
@@ -399,3 +399,16 @@ def print_bytes(s, end=b'\n', file=sys.stdout, flush=True):
...
@@ -399,3 +399,16 @@ def print_bytes(s, end=b'\n', file=sys.stdout, flush=True):
out
.
write
(
end
)
out
.
write
(
end
)
if
flush
:
if
flush
:
out
.
flush
()
out
.
flush
()
class
LazyStr
:
def
__init__
(
self
,
callback
):
self
.
callback
=
callback
def
__str__
(
self
):
return
self
.
callback
()
def
__repr__
(
self
):
return
self
.
callback
()
def
__add__
(
self
,
right
):
return
self
.
callback
()
+
right
def
__radd__
(
self
,
left
):
return
left
+
self
.
callback
()
cythonize.py
0 → 100755
View file @
914dc35d
#!/usr/bin/env python
#
# Cython -- enhanced main program
#
if
__name__
==
'__main__'
:
from
Cython.Build.Cythonize
import
main
main
()
setup.py
View file @
914dc35d
...
@@ -74,14 +74,15 @@ if 'setuptools' in sys.modules:
...
@@ -74,14 +74,15 @@ if 'setuptools' in sys.modules:
setuptools_extra_args
[
'entry_points'
]
=
{
setuptools_extra_args
[
'entry_points'
]
=
{
'console_scripts'
:
[
'console_scripts'
:
[
'cython = Cython.Compiler.Main:setuptools_main'
,
'cython = Cython.Compiler.Main:setuptools_main'
,
'cythonize = Cython.Build.Cythonize:main'
]
]
}
}
scripts
=
[]
scripts
=
[]
else
:
else
:
if
os
.
name
==
"posix"
:
if
os
.
name
==
"posix"
:
scripts
=
[
"bin/cython"
]
scripts
=
[
"bin/cython"
,
'bin/cythonize'
]
else
:
else
:
scripts
=
[
"cython.py"
]
scripts
=
[
"cython.py"
,
"cythonize.py"
]
if
include_debugger
:
if
include_debugger
:
if
'setuptools'
in
sys
.
modules
:
if
'setuptools'
in
sys
.
modules
:
...
...
tests/compile/builtinfuncs.pyx
View file @
914dc35d
...
@@ -5,18 +5,20 @@ cdef int f() except -1:
...
@@ -5,18 +5,20 @@ cdef int f() except -1:
cdef
str
sstring
cdef
str
sstring
cdef
basestring
sustring
cdef
basestring
sustring
cdef
int
i
cdef
int
i
cdef
long
lng
cdef
Py_ssize_t
s
x
=
abs
(
y
)
x
=
abs
(
y
)
delattr
(
x
,
'spam'
)
delattr
(
x
,
'spam'
)
x
=
dir
(
y
)
x
=
dir
(
y
)
x
=
divmod
(
y
,
z
)
x
=
divmod
(
y
,
z
)
x
=
getattr
(
y
,
'spam'
)
x
=
getattr
(
y
,
'spam'
)
i
=
hasattr
(
y
,
'spam'
)
i
=
hasattr
(
y
,
'spam'
)
i
=
hash
(
y
)
lng
=
hash
(
y
)
x
=
intern
(
y
)
x
=
intern
(
y
)
i
=
isinstance
(
y
,
z
)
i
=
isinstance
(
y
,
z
)
i
=
issubclass
(
y
,
z
)
i
=
issubclass
(
y
,
z
)
x
=
iter
(
y
)
x
=
iter
(
y
)
i
=
len
(
x
)
s
=
len
(
x
)
x
=
open
(
y
,
z
)
x
=
open
(
y
,
z
)
x
=
pow
(
y
,
z
,
w
)
x
=
pow
(
y
,
z
,
w
)
x
=
pow
(
y
,
z
)
x
=
pow
(
y
,
z
)
...
...
tests/run/constant_folding.py
View file @
914dc35d
...
@@ -390,8 +390,8 @@ def combined():
...
@@ -390,8 +390,8 @@ def combined():
'//IntNode[@value = "4"]'
,
'//IntNode[@value = "4"]'
,
'//IntNode[@value = "5"]'
,
'//IntNode[@value = "5"]'
,
'//IntNode[@value = "7"]'
,
'//IntNode[@value = "7"]'
,
'//BoolBinopNode//PrimaryCmpNode'
,
'//
Generic
BoolBinopNode//PrimaryCmpNode'
,
'//BoolBinopNode[.//PrimaryCmpNode//IntNode[@value = "4"] and .//PrimaryCmpNode//IntNode[@value = "5"]]'
,
'//
Generic
BoolBinopNode[.//PrimaryCmpNode//IntNode[@value = "4"] and .//PrimaryCmpNode//IntNode[@value = "5"]]'
,
'//PrimaryCmpNode[.//IntNode[@value = "2"] and .//IntNode[@value = "4"]]'
,
'//PrimaryCmpNode[.//IntNode[@value = "2"] and .//IntNode[@value = "4"]]'
,
'//PrimaryCmpNode[.//IntNode[@value = "5"] and .//IntNode[@value = "7"]]'
,
'//PrimaryCmpNode[.//IntNode[@value = "5"] and .//IntNode[@value = "7"]]'
,
)
)
...
@@ -423,11 +423,11 @@ def cascaded_cmp_with_partial_constants(a, b):
...
@@ -423,11 +423,11 @@ def cascaded_cmp_with_partial_constants(a, b):
'//IntNode[@value = "4"]'
,
'//IntNode[@value = "4"]'
,
'//IntNode[@value = "5"]'
,
'//IntNode[@value = "5"]'
,
'//IntNode[@value = "7"]'
,
'//IntNode[@value = "7"]'
,
'//BoolBinopNode'
,
'//
Generic
BoolBinopNode'
,
'//SingleAssignmentNode//BoolBinopNode'
,
'//SingleAssignmentNode//
Generic
BoolBinopNode'
,
'//SingleAssignmentNode//BoolBinopNode//NameNode[@name = "a"]'
,
'//SingleAssignmentNode//
Generic
BoolBinopNode//NameNode[@name = "a"]'
,
'//SingleAssignmentNode//BoolBinopNode//NameNode[@name = "b"]'
,
'//SingleAssignmentNode//
Generic
BoolBinopNode//NameNode[@name = "b"]'
,
'//BoolBinopNode[.//PrimaryCmpNode//IntNode[@value = "4"] and .//PrimaryCmpNode//IntNode[@value = "5"]]'
,
'//
Generic
BoolBinopNode[.//PrimaryCmpNode//IntNode[@value = "4"] and .//PrimaryCmpNode//IntNode[@value = "5"]]'
,
'//BoolNode[@value = False]'
,
'//BoolNode[@value = False]'
,
)
)
@
cython
.
test_fail_if_path_exists
(
@
cython
.
test_fail_if_path_exists
(
...
...
tests/run/cpdef_enums_import.srctree
View file @
914dc35d
...
@@ -34,12 +34,12 @@ from enums cimport *
...
@@ -34,12 +34,12 @@ from enums cimport *
# We can import enums with a star import.
# We can import enums with a star import.
from enums import *
from enums import *
print
dir(
)
print
(dir()
)
assert 'BAR' in dir() and 'FOO' in dir()
assert 'BAR' in dir() and 'FOO' in dir()
# enums not generated in the wrong module
# enums not generated in the wrong module
import no_enums
import no_enums
print
dir(no_enums
)
print
(dir(no_enums)
)
assert 'FOO' not in dir(no_enums)
assert 'FOO' not in dir(no_enums)
assert 'foo' not in dir(no_enums)
assert 'foo' not in dir(no_enums)
tests/run/notinop.pyx
View file @
914dc35d
...
@@ -83,7 +83,7 @@ def m_tuple(int a):
...
@@ -83,7 +83,7 @@ def m_tuple(int a):
return
result
return
result
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
)
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
)
@
cython
.
test_fail_if_path_exists
(
"//BoolBinopNode"
,
"//PrimaryCmpNode"
)
@
cython
.
test_fail_if_path_exists
(
"//BoolBinopNode"
,
"//
GenericBoolBinopNode"
,
"//
PrimaryCmpNode"
)
def
m_set
(
int
a
):
def
m_set
(
int
a
):
"""
"""
>>> m_set(2)
>>> m_set(2)
...
@@ -97,7 +97,7 @@ def m_set(int a):
...
@@ -97,7 +97,7 @@ def m_set(int a):
cdef
bytes
bytes_string
=
b'abcdefg'
cdef
bytes
bytes_string
=
b'abcdefg'
@
cython
.
test_assert_path_exists
(
"//PrimaryCmpNode"
)
@
cython
.
test_assert_path_exists
(
"//PrimaryCmpNode"
)
@
cython
.
test_fail_if_path_exists
(
"//SwitchStatNode"
,
"//BoolBinopNode"
)
@
cython
.
test_fail_if_path_exists
(
"//SwitchStatNode"
,
"//BoolBinopNode"
,
"//GenericBoolBinopNode"
)
def
m_bytes
(
char
a
):
def
m_bytes
(
char
a
):
"""
"""
>>> m_bytes(ord('f'))
>>> m_bytes(ord('f'))
...
@@ -109,7 +109,7 @@ def m_bytes(char a):
...
@@ -109,7 +109,7 @@ def m_bytes(char a):
return
result
return
result
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
)
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
)
@
cython
.
test_fail_if_path_exists
(
"//BoolBinopNode"
,
"//PrimaryCmpNode"
)
@
cython
.
test_fail_if_path_exists
(
"//BoolBinopNode"
,
"//
GenericBoolBinopNode"
,
"//
PrimaryCmpNode"
)
def
m_bytes_literal
(
char
a
):
def
m_bytes_literal
(
char
a
):
"""
"""
>>> m_bytes_literal(ord('f'))
>>> m_bytes_literal(ord('f'))
...
@@ -127,7 +127,7 @@ cdef unicode klingon_character = u'\uF8D2'
...
@@ -127,7 +127,7 @@ cdef unicode klingon_character = u'\uF8D2'
py_klingon_character
=
klingon_character
py_klingon_character
=
klingon_character
@
cython
.
test_assert_path_exists
(
"//PrimaryCmpNode"
)
@
cython
.
test_assert_path_exists
(
"//PrimaryCmpNode"
)
@
cython
.
test_fail_if_path_exists
(
"//SwitchStatNode"
,
"//BoolBinopNode"
)
@
cython
.
test_fail_if_path_exists
(
"//SwitchStatNode"
,
"//
GenericBoolBinopNode"
,
"//
BoolBinopNode"
)
def
m_unicode
(
Py_UNICODE
a
,
unicode
unicode_string
):
def
m_unicode
(
Py_UNICODE
a
,
unicode
unicode_string
):
"""
"""
>>> m_unicode(ord('f'), py_unicode_string)
>>> m_unicode(ord('f'), py_unicode_string)
...
@@ -147,7 +147,7 @@ def m_unicode(Py_UNICODE a, unicode unicode_string):
...
@@ -147,7 +147,7 @@ def m_unicode(Py_UNICODE a, unicode unicode_string):
return
result
return
result
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
)
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
)
@
cython
.
test_fail_if_path_exists
(
"//BoolBinopNode"
,
"//PrimaryCmpNode"
)
@
cython
.
test_fail_if_path_exists
(
"//
GenericBoolBinopNode"
,
"//
BoolBinopNode"
,
"//PrimaryCmpNode"
)
def
m_unicode_literal
(
Py_UNICODE
a
):
def
m_unicode_literal
(
Py_UNICODE
a
):
"""
"""
>>> m_unicode_literal(ord('f'))
>>> m_unicode_literal(ord('f'))
...
@@ -160,7 +160,7 @@ def m_unicode_literal(Py_UNICODE a):
...
@@ -160,7 +160,7 @@ def m_unicode_literal(Py_UNICODE a):
cdef
int
result
=
a
not
in
u'abcdefg
\
u1234
\
uF8D2
'
cdef
int
result
=
a
not
in
u'abcdefg
\
u1234
\
uF8D2
'
return
result
return
result
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
,
"//BoolBinopNode"
)
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
,
"//
Generic
BoolBinopNode"
)
@
cython
.
test_fail_if_path_exists
(
"//PrimaryCmpNode"
)
@
cython
.
test_fail_if_path_exists
(
"//PrimaryCmpNode"
)
def
m_tuple_in_or_notin
(
int
a
):
def
m_tuple_in_or_notin
(
int
a
):
"""
"""
...
@@ -174,7 +174,7 @@ def m_tuple_in_or_notin(int a):
...
@@ -174,7 +174,7 @@ def m_tuple_in_or_notin(int a):
cdef
int
result
=
a
not
in
(
1
,
2
,
3
,
4
)
or
a
in
(
3
,
4
)
cdef
int
result
=
a
not
in
(
1
,
2
,
3
,
4
)
or
a
in
(
3
,
4
)
return
result
return
result
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
,
"//BoolBinopNode"
)
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
,
"//
Generic
BoolBinopNode"
)
@
cython
.
test_fail_if_path_exists
(
"//PrimaryCmpNode"
)
@
cython
.
test_fail_if_path_exists
(
"//PrimaryCmpNode"
)
def
m_tuple_notin_or_notin
(
int
a
):
def
m_tuple_notin_or_notin
(
int
a
):
"""
"""
...
@@ -189,7 +189,7 @@ def m_tuple_notin_or_notin(int a):
...
@@ -189,7 +189,7 @@ def m_tuple_notin_or_notin(int a):
return
result
return
result
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
)
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
)
@
cython
.
test_fail_if_path_exists
(
"//BoolBinopNode"
,
"//PrimaryCmpNode"
)
@
cython
.
test_fail_if_path_exists
(
"//
GenericBoolBinopNode"
,
"//
BoolBinopNode"
,
"//PrimaryCmpNode"
)
def
m_tuple_notin_and_notin
(
int
a
):
def
m_tuple_notin_and_notin
(
int
a
):
"""
"""
>>> m_tuple_notin_and_notin(2)
>>> m_tuple_notin_and_notin(2)
...
@@ -202,7 +202,7 @@ def m_tuple_notin_and_notin(int a):
...
@@ -202,7 +202,7 @@ def m_tuple_notin_and_notin(int a):
cdef
int
result
=
a
not
in
(
1
,
2
,
3
,
4
)
and
a
not
in
(
6
,
7
)
cdef
int
result
=
a
not
in
(
1
,
2
,
3
,
4
)
and
a
not
in
(
6
,
7
)
return
result
return
result
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
,
"//BoolBinopNode"
)
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
,
"//
Generic
BoolBinopNode"
)
@
cython
.
test_fail_if_path_exists
(
"//PrimaryCmpNode"
)
@
cython
.
test_fail_if_path_exists
(
"//PrimaryCmpNode"
)
def
m_tuple_notin_and_notin_overlap
(
int
a
):
def
m_tuple_notin_and_notin_overlap
(
int
a
):
"""
"""
...
@@ -217,7 +217,7 @@ def m_tuple_notin_and_notin_overlap(int a):
...
@@ -217,7 +217,7 @@ def m_tuple_notin_and_notin_overlap(int a):
return
result
return
result
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
)
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
)
@
cython
.
test_fail_if_path_exists
(
"//BoolBinopNode"
,
"//PrimaryCmpNode"
)
@
cython
.
test_fail_if_path_exists
(
"//
GenericBoolBinopNode"
,
"//
BoolBinopNode"
,
"//PrimaryCmpNode"
)
def
conditional_int
(
int
a
):
def
conditional_int
(
int
a
):
"""
"""
>>> conditional_int(1)
>>> conditional_int(1)
...
@@ -230,7 +230,7 @@ def conditional_int(int a):
...
@@ -230,7 +230,7 @@ def conditional_int(int a):
return
1
if
a
not
in
(
1
,
2
,
3
,
4
)
else
2
return
1
if
a
not
in
(
1
,
2
,
3
,
4
)
else
2
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
)
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
)
@
cython
.
test_fail_if_path_exists
(
"//BoolBinopNode"
,
"//PrimaryCmpNode"
)
@
cython
.
test_fail_if_path_exists
(
"//
GenericBoolBinopNode"
,
"//
BoolBinopNode"
,
"//PrimaryCmpNode"
)
def
conditional_object
(
int
a
):
def
conditional_object
(
int
a
):
"""
"""
>>> conditional_object(1)
>>> conditional_object(1)
...
@@ -243,7 +243,7 @@ def conditional_object(int a):
...
@@ -243,7 +243,7 @@ def conditional_object(int a):
return
1
if
a
not
in
(
1
,
2
,
3
,
4
)
else
'2'
return
1
if
a
not
in
(
1
,
2
,
3
,
4
)
else
'2'
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
)
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
)
@
cython
.
test_fail_if_path_exists
(
"//BoolBinopNode"
,
"//PrimaryCmpNode"
)
@
cython
.
test_fail_if_path_exists
(
"//
GenericBoolBinopNode"
,
"//
BoolBinopNode"
,
"//PrimaryCmpNode"
)
def
conditional_bytes
(
char
a
):
def
conditional_bytes
(
char
a
):
"""
"""
>>> conditional_bytes(ord('a'))
>>> conditional_bytes(ord('a'))
...
@@ -256,7 +256,7 @@ def conditional_bytes(char a):
...
@@ -256,7 +256,7 @@ def conditional_bytes(char a):
return
1
if
a
not
in
b'abc'
else
'2'
return
1
if
a
not
in
b'abc'
else
'2'
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
)
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
)
@
cython
.
test_fail_if_path_exists
(
"//BoolBinopNode"
,
"//PrimaryCmpNode"
)
@
cython
.
test_fail_if_path_exists
(
"//
GenericBoolBinopNode"
,
"//
BoolBinopNode"
,
"//PrimaryCmpNode"
)
def
conditional_unicode
(
Py_UNICODE
a
):
def
conditional_unicode
(
Py_UNICODE
a
):
"""
"""
>>> conditional_unicode(ord('a'))
>>> conditional_unicode(ord('a'))
...
@@ -269,7 +269,7 @@ def conditional_unicode(Py_UNICODE a):
...
@@ -269,7 +269,7 @@ def conditional_unicode(Py_UNICODE a):
return
1
if
a
not
in
u'abc'
else
'2'
return
1
if
a
not
in
u'abc'
else
'2'
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
)
@
cython
.
test_assert_path_exists
(
"//SwitchStatNode"
)
@
cython
.
test_fail_if_path_exists
(
"//BoolBinopNode"
,
"//PrimaryCmpNode"
)
@
cython
.
test_fail_if_path_exists
(
"//
GenericBoolBinopNode"
,
"//
BoolBinopNode"
,
"//PrimaryCmpNode"
)
def
conditional_none
(
int
a
):
def
conditional_none
(
int
a
):
"""
"""
>>> conditional_none(1)
>>> conditional_none(1)
...
...
tests/run/pointers.pyx
View file @
914dc35d
cimport
cython
cdef
char
*
c_string
=
b'abcdefg'
cdef
char
*
c_string
=
b'abcdefg'
cdef
void
*
void_ptr
=
c_string
cdef
void
*
void_ptr
=
c_string
...
@@ -60,3 +61,29 @@ def bool_binop_truth(int x):
...
@@ -60,3 +61,29 @@ def bool_binop_truth(int x):
print
True
print
True
if
c_string
and
x
or
not
(
void_ptr
or
int_ptr
and
float_ptr
)
or
x
:
if
c_string
and
x
or
not
(
void_ptr
or
int_ptr
and
float_ptr
)
or
x
:
print
True
print
True
def
binop_voidptr
(
int
x
,
long
y
,
char
*
z
):
"""
>>> binop_voidptr(1, 3, b'abc')
'void *'
"""
result
=
&
x
and
&
y
and
z
return
cython
.
typeof
(
result
)
def
cond_expr_voidptr
(
int
x
,
long
y
,
char
*
z
):
"""
>>> cond_expr_voidptr(0, -1, b'abc')
('void *', 0)
>>> cond_expr_voidptr(-1, 0, b'abc')
('void *', -1)
>>> cond_expr_voidptr(-1, 0, b'')
('void *', 0)
>>> cond_expr_voidptr(0, -1, b'')
('void *', -1)
"""
result
=
&
x
if
len
(
z
)
else
&
y
assert
sizeof
(
long
)
>=
sizeof
(
int
)
assert
-
1
==
<
int
>
(
-
1L
)
return
cython
.
typeof
(
result
),
(
<
int
*>
result
)[
0
]
tests/run/py2_super.pyx
0 → 100644
View file @
914dc35d
# mode: run
# tag: py3k_super
class
A
(
object
):
def
method
(
self
):
return
1
@
classmethod
def
class_method
(
cls
):
return
2
@
staticmethod
def
static_method
():
return
3
def
generator_test
(
self
):
return
[
1
,
2
,
3
]
class
B
(
A
):
"""
>>> obj = B()
>>> obj.method()
1
>>> B.class_method()
2
>>> B.static_method(obj)
3
>>> list(obj.generator_test())
[1, 2, 3]
"""
def
method
(
self
):
return
super
(
B
,
self
).
method
()
@
classmethod
def
class_method
(
cls
):
return
super
(
B
,
cls
).
class_method
()
@
staticmethod
def
static_method
(
instance
):
return
super
(
B
,
instance
).
static_method
()
def
generator_test
(
self
):
for
i
in
super
(
B
,
self
).
generator_test
():
yield
i
cdef
class
CClassBase
(
object
):
def
method
(
self
):
return
'def'
cpdef
method_cp
(
self
):
return
'cpdef'
# cdef method_c(self):
# return 'cdef'
# def call_method_c(self):
# return self.method_c()
cdef
class
CClassSub
(
CClassBase
):
"""
>>> CClassSub().method()
'def'
>>> CClassSub().method_cp()
'cpdef'
"""
# >>> CClassSub().call_method_c()
# 'cdef'
def
method
(
self
):
return
super
(
CClassSub
,
self
).
method
()
cpdef
method_cp
(
self
):
return
super
(
CClassSub
,
self
).
method_cp
()
# cdef method_c(self):
# return super(CClassSub, self).method_c()
cdef
class
Base
(
object
):
"""
>>> Base().method()
'Base'
>>> Base.method(Base())
'Base'
"""
cpdef
method
(
self
):
return
"Base"
cdef
class
Sub
(
Base
):
"""
>>> Sub().method()
'Sub'
>>> Sub.method(Sub())
'Sub'
>>> Base.method(Sub())
'Base'
"""
cpdef
method
(
self
):
return
"Sub"
tests/run/py3k_super.pyx
View file @
914dc35d
...
@@ -63,13 +63,29 @@ def test_class_cell_empty():
...
@@ -63,13 +63,29 @@ def test_class_cell_empty():
cdef
class
CClassBase
(
object
):
cdef
class
CClassBase
(
object
):
def
method
(
self
):
def
method
(
self
):
return
1
return
'def'
# cpdef method_cp(self):
# return 'cpdef'
# cdef method_c(self):
# return 'cdef'
# def call_method_c(self):
# return self.method_c()
cdef
class
CClassSu
per
(
CClassBase
):
cdef
class
CClassSu
b
(
CClassBase
):
"""
"""
>>> CClassSu
per
().method()
>>> CClassSu
b
().method()
1
'def'
"""
"""
# >>> CClassSub().method_cp()
# 'cpdef'
# >>> CClassSub().call_method_c()
# 'cdef'
def
method
(
self
):
def
method
(
self
):
return
super
().
method
()
return
super
().
method
()
# cpdef method_cp(self):
# return super().method_cp()
# cdef method_c(self):
# return super().method_c()
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