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
cf38d155
Commit
cf38d155
authored
Jan 07, 2009
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
fd6fcfbe
a1572260
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
72 additions
and
52 deletions
+72
-52
.hgtags
.hgtags
+1
-0
Cython/Compiler/Buffer.py
Cython/Compiler/Buffer.py
+6
-5
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+7
-0
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+25
-32
Cython/Compiler/Version.py
Cython/Compiler/Version.py
+1
-1
Cython/Compiler/Visitor.py
Cython/Compiler/Visitor.py
+21
-14
tests/run/bufaccess.pyx
tests/run/bufaccess.pyx
+11
-0
No files found.
.hgtags
View file @
cf38d155
...
@@ -6,3 +6,4 @@ a09347d7b470290076b983aef98707921445a038 0.9.8.1
...
@@ -6,3 +6,4 @@ a09347d7b470290076b983aef98707921445a038 0.9.8.1
a89b05b78236a27a654f3004bdffc7b8a56311a7 0.10
a89b05b78236a27a654f3004bdffc7b8a56311a7 0.10
ef9d2c680684d0df7d81f529cda29e9e1741f575 cython-0.10.1
ef9d2c680684d0df7d81f529cda29e9e1741f575 cython-0.10.1
92baafe0edf3cea00deb7ce1e31e337bb485af1a 0.10.2
92baafe0edf3cea00deb7ce1e31e337bb485af1a 0.10.2
cdf889c30e7a7053de20bae3a578dad09ebcbdf5 0.10.3
Cython/Compiler/Buffer.py
View file @
cf38d155
...
@@ -64,6 +64,9 @@ class IntroduceBufferAuxiliaryVars(CythonTransform):
...
@@ -64,6 +64,9 @@ class IntroduceBufferAuxiliaryVars(CythonTransform):
# for now...note that pos is wrong
# for now...note that pos is wrong
raise
CompileError
(
node
.
pos
,
"Buffer vars not allowed in module scope"
)
raise
CompileError
(
node
.
pos
,
"Buffer vars not allowed in module scope"
)
for
entry
in
bufvars
:
for
entry
in
bufvars
:
if
entry
.
type
.
dtype
.
is_ptr
:
raise
CompileError
(
node
.
pos
,
"Buffers with pointer types not yet supported."
)
name
=
entry
.
name
name
=
entry
.
name
buftype
=
entry
.
type
buftype
=
entry
.
type
if
buftype
.
ndim
>
self
.
max_ndim
:
if
buftype
.
ndim
>
self
.
max_ndim
:
...
@@ -500,7 +503,7 @@ def mangle_dtype_name(dtype):
...
@@ -500,7 +503,7 @@ def mangle_dtype_name(dtype):
elif
dtype
.
is_ptr
:
elif
dtype
.
is_ptr
:
return
"ptr"
return
"ptr"
else
:
else
:
if
dtype
.
typestring
is
None
:
if
dtype
.
is_typedef
or
dtype
.
is_struct_or_union
:
prefix
=
"nn_"
prefix
=
"nn_"
else
:
else
:
prefix
=
""
prefix
=
""
...
@@ -552,10 +555,8 @@ def create_typestringchecker(protocode, defcode, name, dtype):
...
@@ -552,10 +555,8 @@ def create_typestringchecker(protocode, defcode, name, dtype):
defcode
.
putln
(
"int ok;"
)
defcode
.
putln
(
"int ok;"
)
defcode
.
putln
(
"ts = __Pyx_ConsumeWhitespace(ts); if (!ts) return NULL;"
)
defcode
.
putln
(
"ts = __Pyx_ConsumeWhitespace(ts); if (!ts) return NULL;"
)
defcode
.
putln
(
"if (*ts == '1') ++ts;"
)
defcode
.
putln
(
"if (*ts == '1') ++ts;"
)
if
dtype
.
typestring
is
not
None
:
if
dtype
.
is_pyobject
:
assert
len
(
dtype
.
typestring
)
==
1
defcode
.
putln
(
"ok = (*ts == 'O');"
)
# Can use direct comparison
defcode
.
putln
(
"ok = (*ts == '%s');"
%
dtype
.
typestring
)
else
:
else
:
# Cannot trust declared size; but rely on int vs float and
# Cannot trust declared size; but rely on int vs float and
# signed/unsigned to be correctly declared. Use a switch statement
# signed/unsigned to be correctly declared. Use a switch statement
...
...
Cython/Compiler/Nodes.py
View file @
cf38d155
...
@@ -3905,6 +3905,7 @@ class TryExceptStatNode(StatNode):
...
@@ -3905,6 +3905,7 @@ class TryExceptStatNode(StatNode):
except_end_label
=
code
.
new_label
(
'exception_handled'
)
except_end_label
=
code
.
new_label
(
'exception_handled'
)
except_error_label
=
code
.
new_label
(
'except_error'
)
except_error_label
=
code
.
new_label
(
'except_error'
)
except_return_label
=
code
.
new_label
(
'except_return'
)
except_return_label
=
code
.
new_label
(
'except_return'
)
try_return_label
=
code
.
new_label
(
'try_return'
)
try_end_label
=
code
.
new_label
(
'try'
)
try_end_label
=
code
.
new_label
(
'try'
)
code
.
putln
(
"{"
)
code
.
putln
(
"{"
)
...
@@ -3914,6 +3915,7 @@ class TryExceptStatNode(StatNode):
...
@@ -3914,6 +3915,7 @@ class TryExceptStatNode(StatNode):
', '
.
join
([
'&%s'
%
var
for
var
in
Naming
.
exc_save_vars
]))
', '
.
join
([
'&%s'
%
var
for
var
in
Naming
.
exc_save_vars
]))
code
.
putln
(
code
.
putln
(
"/*try:*/ {"
)
"/*try:*/ {"
)
code
.
return_label
=
try_return_label
self
.
body
.
generate_execution_code
(
code
)
self
.
body
.
generate_execution_code
(
code
)
code
.
putln
(
code
.
putln
(
"}"
)
"}"
)
...
@@ -3928,6 +3930,11 @@ class TryExceptStatNode(StatNode):
...
@@ -3928,6 +3930,11 @@ class TryExceptStatNode(StatNode):
for
var
in
Naming
.
exc_save_vars
:
for
var
in
Naming
.
exc_save_vars
:
code
.
put_xdecref_clear
(
var
,
py_object_type
)
code
.
put_xdecref_clear
(
var
,
py_object_type
)
code
.
put_goto
(
try_end_label
)
code
.
put_goto
(
try_end_label
)
if
code
.
label_used
(
try_return_label
):
code
.
put_label
(
try_return_label
)
for
var
in
Naming
.
exc_save_vars
:
code
.
put_xdecref_clear
(
var
,
py_object_type
)
code
.
put_goto
(
old_return_label
)
code
.
put_label
(
our_error_label
)
code
.
put_label
(
our_error_label
)
code
.
put_var_xdecrefs_clear
(
self
.
cleanup_list
)
code
.
put_var_xdecrefs_clear
(
self
.
cleanup_list
)
for
except_clause
in
self
.
except_clauses
:
for
except_clause
in
self
.
except_clauses
:
...
...
Cython/Compiler/PyrexTypes.py
View file @
cf38d155
...
@@ -49,7 +49,6 @@ class PyrexType(BaseType):
...
@@ -49,7 +49,6 @@ class PyrexType(BaseType):
# default_value string Initial value
# default_value string Initial value
# parsetuple_format string Format char for PyArg_ParseTuple
# parsetuple_format string Format char for PyArg_ParseTuple
# pymemberdef_typecode string Type code for PyMemberDef struct
# pymemberdef_typecode string Type code for PyMemberDef struct
# typestring string String char defining the type (see Python struct module)
#
#
# declaration_code(entity_code,
# declaration_code(entity_code,
# for_display = 0, dll_linkage = None, pyrex = 0)
# for_display = 0, dll_linkage = None, pyrex = 0)
...
@@ -101,7 +100,6 @@ class PyrexType(BaseType):
...
@@ -101,7 +100,6 @@ class PyrexType(BaseType):
default_value
=
""
default_value
=
""
parsetuple_format
=
""
parsetuple_format
=
""
pymemberdef_typecode
=
None
pymemberdef_typecode
=
None
typestring
=
None
def
resolve
(
self
):
def
resolve
(
self
):
# If a typedef, returns the base type.
# If a typedef, returns the base type.
...
@@ -157,7 +155,6 @@ class CTypedefType(BaseType):
...
@@ -157,7 +155,6 @@ class CTypedefType(BaseType):
# typedef_base_type PyrexType
# typedef_base_type PyrexType
is_typedef
=
1
is_typedef
=
1
typestring
=
None
# Because typedefs are not known exactly
def
__init__
(
self
,
cname
,
base_type
):
def
__init__
(
self
,
cname
,
base_type
):
self
.
typedef_cname
=
cname
self
.
typedef_cname
=
cname
...
@@ -243,7 +240,6 @@ class PyObjectType(PyrexType):
...
@@ -243,7 +240,6 @@ class PyObjectType(PyrexType):
parsetuple_format
=
"O"
parsetuple_format
=
"O"
pymemberdef_typecode
=
"T_OBJECT"
pymemberdef_typecode
=
"T_OBJECT"
buffer_defaults
=
None
buffer_defaults
=
None
typestring
=
"O"
def
__str__
(
self
):
def
__str__
(
self
):
return
"Python object"
return
"Python object"
...
@@ -469,10 +465,9 @@ class CNumericType(CType):
...
@@ -469,10 +465,9 @@ class CNumericType(CType):
sign_words
=
(
"unsigned "
,
""
,
"signed "
)
sign_words
=
(
"unsigned "
,
""
,
"signed "
)
def
__init__
(
self
,
rank
,
signed
=
1
,
pymemberdef_typecode
=
None
,
typestring
=
None
):
def
__init__
(
self
,
rank
,
signed
=
1
,
pymemberdef_typecode
=
None
):
self
.
rank
=
rank
self
.
rank
=
rank
self
.
signed
=
signed
self
.
signed
=
signed
self
.
typestring
=
typestring
ptf
=
self
.
parsetuple_formats
[
signed
][
rank
]
ptf
=
self
.
parsetuple_formats
[
signed
][
rank
]
if
ptf
==
'?'
:
if
ptf
==
'?'
:
ptf
=
None
ptf
=
None
...
@@ -507,9 +502,8 @@ class CIntType(CNumericType):
...
@@ -507,9 +502,8 @@ class CIntType(CNumericType):
from_py_function
=
"__pyx_PyInt_AsLong"
from_py_function
=
"__pyx_PyInt_AsLong"
exception_value
=
-
1
exception_value
=
-
1
def
__init__
(
self
,
rank
,
signed
,
pymemberdef_typecode
=
None
,
is_returncode
=
0
,
def
__init__
(
self
,
rank
,
signed
,
pymemberdef_typecode
=
None
,
is_returncode
=
0
):
typestring
=
None
):
CNumericType
.
__init__
(
self
,
rank
,
signed
,
pymemberdef_typecode
)
CNumericType
.
__init__
(
self
,
rank
,
signed
,
pymemberdef_typecode
,
typestring
=
typestring
)
self
.
is_returncode
=
is_returncode
self
.
is_returncode
=
is_returncode
if
self
.
from_py_function
==
'__pyx_PyInt_AsLong'
:
if
self
.
from_py_function
==
'__pyx_PyInt_AsLong'
:
self
.
from_py_function
=
self
.
get_type_conversion
()
self
.
from_py_function
=
self
.
get_type_conversion
()
...
@@ -602,8 +596,8 @@ class CFloatType(CNumericType):
...
@@ -602,8 +596,8 @@ class CFloatType(CNumericType):
to_py_function
=
"PyFloat_FromDouble"
to_py_function
=
"PyFloat_FromDouble"
from_py_function
=
"__pyx_PyFloat_AsDouble"
from_py_function
=
"__pyx_PyFloat_AsDouble"
def
__init__
(
self
,
rank
,
pymemberdef_typecode
=
None
,
typestring
=
None
):
def
__init__
(
self
,
rank
,
pymemberdef_typecode
=
None
):
CNumericType
.
__init__
(
self
,
rank
,
1
,
pymemberdef_typecode
,
typestring
=
typestring
)
CNumericType
.
__init__
(
self
,
rank
,
1
,
pymemberdef_typecode
)
def
assignable_from_resolved_type
(
self
,
src_type
):
def
assignable_from_resolved_type
(
self
,
src_type
):
return
src_type
.
is_numeric
or
src_type
is
error_type
return
src_type
.
is_numeric
or
src_type
is
error_type
...
@@ -1133,7 +1127,6 @@ class ErrorType(PyrexType):
...
@@ -1133,7 +1127,6 @@ class ErrorType(PyrexType):
exception_check
=
0
exception_check
=
0
to_py_function
=
"dummy"
to_py_function
=
"dummy"
from_py_function
=
"dummy"
from_py_function
=
"dummy"
typestring
=
None
def
create_convert_utility_code
(
self
,
env
):
def
create_convert_utility_code
(
self
,
env
):
return
True
return
True
...
@@ -1167,29 +1160,29 @@ c_void_type = CVoidType()
...
@@ -1167,29 +1160,29 @@ c_void_type = CVoidType()
c_void_ptr_type
=
CPtrType
(
c_void_type
)
c_void_ptr_type
=
CPtrType
(
c_void_type
)
c_void_ptr_ptr_type
=
CPtrType
(
c_void_ptr_type
)
c_void_ptr_ptr_type
=
CPtrType
(
c_void_ptr_type
)
c_uchar_type
=
CIntType
(
0
,
0
,
"T_UBYTE"
,
typestring
=
"B"
)
c_uchar_type
=
CIntType
(
0
,
0
,
"T_UBYTE"
)
c_ushort_type
=
CIntType
(
1
,
0
,
"T_USHORT"
,
typestring
=
"H"
)
c_ushort_type
=
CIntType
(
1
,
0
,
"T_USHORT"
)
c_uint_type
=
CUIntType
(
2
,
0
,
"T_UINT"
,
typestring
=
"I"
)
c_uint_type
=
CUIntType
(
2
,
0
,
"T_UINT"
)
c_ulong_type
=
CULongType
(
3
,
0
,
"T_ULONG"
,
typestring
=
"L"
)
c_ulong_type
=
CULongType
(
3
,
0
,
"T_ULONG"
)
c_ulonglong_type
=
CULongLongType
(
4
,
0
,
"T_ULONGLONG"
,
typestring
=
"Q"
)
c_ulonglong_type
=
CULongLongType
(
4
,
0
,
"T_ULONGLONG"
)
c_char_type
=
CIntType
(
0
,
1
,
"T_CHAR"
,
typestring
=
"b"
)
c_char_type
=
CIntType
(
0
,
1
,
"T_CHAR"
)
c_short_type
=
CIntType
(
1
,
1
,
"T_SHORT"
,
typestring
=
"h"
)
c_short_type
=
CIntType
(
1
,
1
,
"T_SHORT"
)
c_int_type
=
CIntType
(
2
,
1
,
"T_INT"
,
typestring
=
"i"
)
c_int_type
=
CIntType
(
2
,
1
,
"T_INT"
)
c_long_type
=
CIntType
(
3
,
1
,
"T_LONG"
,
typestring
=
"l"
)
c_long_type
=
CIntType
(
3
,
1
,
"T_LONG"
)
c_longlong_type
=
CLongLongType
(
4
,
1
,
"T_LONGLONG"
,
typestring
=
"q"
)
c_longlong_type
=
CLongLongType
(
4
,
1
,
"T_LONGLONG"
)
c_py_ssize_t_type
=
CPySSizeTType
(
5
,
1
)
c_py_ssize_t_type
=
CPySSizeTType
(
5
,
1
)
c_bint_type
=
CBIntType
(
2
,
1
,
"T_INT"
,
typestring
=
"i"
)
c_bint_type
=
CBIntType
(
2
,
1
,
"T_INT"
)
c_schar_type
=
CIntType
(
0
,
2
,
"T_CHAR"
,
typestring
=
"b"
)
c_schar_type
=
CIntType
(
0
,
2
,
"T_CHAR"
)
c_sshort_type
=
CIntType
(
1
,
2
,
"T_SHORT"
,
typestring
=
"h"
)
c_sshort_type
=
CIntType
(
1
,
2
,
"T_SHORT"
)
c_sint_type
=
CIntType
(
2
,
2
,
"T_INT"
,
typestring
=
"i"
)
c_sint_type
=
CIntType
(
2
,
2
,
"T_INT"
)
c_slong_type
=
CIntType
(
3
,
2
,
"T_LONG"
,
typestring
=
"l"
)
c_slong_type
=
CIntType
(
3
,
2
,
"T_LONG"
)
c_slonglong_type
=
CLongLongType
(
4
,
2
,
"T_LONGLONG"
,
typestring
=
"q"
)
c_slonglong_type
=
CLongLongType
(
4
,
2
,
"T_LONGLONG"
)
c_float_type
=
CFloatType
(
6
,
"T_FLOAT"
,
typestring
=
"f"
)
c_float_type
=
CFloatType
(
6
,
"T_FLOAT"
)
c_double_type
=
CFloatType
(
7
,
"T_DOUBLE"
,
typestring
=
"d"
)
c_double_type
=
CFloatType
(
7
,
"T_DOUBLE"
)
c_longdouble_type
=
CFloatType
(
8
,
typestring
=
"g"
)
c_longdouble_type
=
CFloatType
(
8
)
c_null_ptr_type
=
CNullPtrType
(
c_void_type
)
c_null_ptr_type
=
CNullPtrType
(
c_void_type
)
c_char_array_type
=
CCharArrayType
(
None
)
c_char_array_type
=
CCharArrayType
(
None
)
...
...
Cython/Compiler/Version.py
View file @
cf38d155
version
=
'0.10.
2
'
version
=
'0.10.
3
'
Cython/Compiler/Visitor.py
View file @
cf38d155
...
@@ -16,24 +16,31 @@ class BasicVisitor(object):
...
@@ -16,24 +16,31 @@ class BasicVisitor(object):
self
.
dispatch_table
=
{}
self
.
dispatch_table
=
{}
def
visit
(
self
,
obj
):
def
visit
(
self
,
obj
):
cls
=
obj
.
__class__
cls
=
type
(
obj
)
m
=
self
.
dispatch_table
.
get
(
cls
.
__name__
)
try
:
if
m
is
None
:
handler_method
=
self
.
dispatch_table
[
cls
]
except
KeyError
:
#print "Cache miss for class %s in visitor %s" % (
# cls.__name__, type(self).__name__)
# Must resolve, try entire hierarchy
# Must resolve, try entire hierarchy
pattern
=
"visit_%s"
pattern
=
"visit_%s"
mro
=
inspect
.
getmro
(
cls
)
mro
=
inspect
.
getmro
(
cls
)
for
cls
in
mro
:
handler_method
=
None
m
=
getattr
(
self
,
pattern
%
cls
.
__name__
,
None
)
for
mro_cls
in
mro
:
if
m
is
not
None
:
if
hasattr
(
self
,
pattern
%
mro_cls
.
__name__
):
handler_method
=
getattr
(
self
,
pattern
%
mro_cls
.
__name__
)
break
break
els
e
:
if
handler_method
is
Non
e
:
print
type
(
self
),
type
(
obj
)
print
type
(
self
),
type
(
obj
)
if
hasattr
(
self
,
'access_path'
):
print
self
.
access_path
print
self
.
access_path
if
self
.
access_path
:
print
self
.
access_path
[
-
1
][
0
].
pos
print
self
.
access_path
[
-
1
][
0
].
pos
print
self
.
access_path
[
-
1
][
0
].
__dict__
print
self
.
access_path
[
-
1
][
0
].
__dict__
raise
RuntimeError
(
"Visitor does not accept object: %s"
%
obj
)
raise
RuntimeError
(
"Visitor does not accept object: %s"
%
obj
)
self
.
dispatch_table
[
cls
.
__name__
]
=
m
#print "Caching " + cls.__name__
return
m
(
obj
)
self
.
dispatch_table
[
cls
]
=
handler_method
return
handler_method
(
obj
)
class
TreeVisitor
(
BasicVisitor
):
class
TreeVisitor
(
BasicVisitor
):
"""
"""
...
@@ -53,7 +60,7 @@ class TreeVisitor(BasicVisitor):
...
@@ -53,7 +60,7 @@ class TreeVisitor(BasicVisitor):
Example:
Example:
>>> class SampleNode:
>>> class SampleNode
(object)
:
... child_attrs = ["head", "body"]
... child_attrs = ["head", "body"]
... def __init__(self, value, head=None, body=None):
... def __init__(self, value, head=None, body=None):
... self.value = value
... self.value = value
...
...
tests/run/bufaccess.pyx
View file @
cf38d155
...
@@ -384,6 +384,17 @@ def wrong_string(object[int] buf):
...
@@ -384,6 +384,17 @@ def wrong_string(object[int] buf):
"""
"""
print
buf
[
1
]
print
buf
[
1
]
@
testcase
def
int_and_long_are_same
():
"""
>>> int_and_long_are_same()
"""
cdef
object
[
int
]
intarr
cdef
object
[
long
]
longarr
if
sizeof
(
int
)
==
sizeof
(
long
):
intarr
=
IntMockBuffer
(
None
,
[
1
,
2
],
format
=
'l'
)
longarr
=
IntMockBuffer
(
None
,
[
1
,
2
])
#
#
# Getting items and index bounds checking
# Getting items and index bounds checking
#
#
...
...
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