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
16afe72d
Commit
16afe72d
authored
May 03, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
merge in latest cython-devel
parents
0e14b4b5
defbb401
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
181 additions
and
26 deletions
+181
-26
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+3
-2
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+22
-1
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+9
-6
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+1
-5
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+9
-7
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+3
-1
Cython/Compiler/Scanning.py
Cython/Compiler/Scanning.py
+1
-1
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+3
-2
runtests.py
runtests.py
+1
-1
tests/errors/e2_packedstruct_T290.pyx
tests/errors/e2_packedstruct_T290.pyx
+6
-0
tests/errors/e_packedstruct_T290.pyx
tests/errors/e_packedstruct_T290.pyx
+7
-0
tests/run/always_allow_keywords_T295.pyx
tests/run/always_allow_keywords_T295.pyx
+60
-0
tests/run/numpy_bufacc_T155.pyx
tests/run/numpy_bufacc_T155.pyx
+15
-0
tests/run/packedstruct_T290.pyx
tests/run/packedstruct_T290.pyx
+16
-0
tests/run/tupleunpack_T298.pyx
tests/run/tupleunpack_T298.pyx
+25
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
16afe72d
...
...
@@ -1586,8 +1586,6 @@ class IndexNode(ExprNode):
if
self
.
indices
:
indices
=
self
.
indices
else
:
# On cloning, indices is cloned. Otherwise, unpack index into indices
assert
not
isinstance
(
self
.
index
,
CloneNode
)
if
isinstance
(
self
.
index
,
TupleNode
):
indices
=
self
.
index
.
args
else
:
...
...
@@ -1600,6 +1598,9 @@ class IndexNode(ExprNode):
if
not
x
.
type
.
is_int
:
buffer_access
=
False
# On cloning, indices is cloned. Otherwise, unpack index into indices
assert
not
(
buffer_access
and
isinstance
(
self
.
index
,
CloneNode
))
if
buffer_access
:
self
.
indices
=
indices
self
.
index
=
None
...
...
Cython/Compiler/ModuleNode.py
View file @
16afe72d
...
...
@@ -640,9 +640,18 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
type
=
entry
.
type
scope
=
type
.
scope
if
scope
:
kind
=
type
.
kind
packed
=
type
.
is_struct
and
type
.
packed
if
packed
:
kind
=
"%s %s"
%
(
type
.
kind
,
"__Pyx_PACKED"
)
code
.
globalstate
.
use_utility_code
(
packed_struct_utility_code
)
header
,
footer
=
\
self
.
sue_header_footer
(
type
,
type
.
kind
,
type
.
cname
)
self
.
sue_header_footer
(
type
,
kind
,
type
.
cname
)
code
.
putln
(
""
)
if
packed
:
code
.
putln
(
"#if !defined(__GNUC__)"
)
code
.
putln
(
"#pragma pack(push, 1)"
)
code
.
putln
(
"#endif"
)
code
.
putln
(
header
)
var_entries
=
scope
.
var_entries
if
not
var_entries
:
...
...
@@ -654,6 +663,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
"%s;"
%
attr
.
type
.
declaration_code
(
attr
.
cname
))
code
.
putln
(
footer
)
if
packed
:
code
.
putln
(
"#if !defined(__GNUC__)"
)
code
.
putln
(
"#pragma pack(pop)"
)
code
.
putln
(
"#endif"
)
def
generate_enum_definition
(
self
,
entry
,
code
):
code
.
mark_pos
(
entry
.
pos
)
...
...
@@ -2468,3 +2481,11 @@ int main(int argc, char** argv) {
return r;
}
"""
)
packed_struct_utility_code
=
UtilityCode
(
proto
=
"""
#if defined(__GNUC__)
#define __Pyx_PACKED __attribute__((__packed__))
#else
#define __Pyx_PACKED
#endif
"""
,
impl
=
""
)
Cython/Compiler/Nodes.py
View file @
16afe72d
...
...
@@ -816,16 +816,19 @@ class CStructOrUnionDefNode(StatNode):
# in_pxd boolean
# attributes [CVarDefNode] or None
# entry Entry
# packed boolean
child_attrs
=
[
"attributes"
]
def
analyse_declarations
(
self
,
env
):
scope
=
None
if
self
.
visibility
==
'extern'
and
self
.
packed
:
error
(
self
.
pos
,
"Cannot declare extern struct as 'packed'"
)
if
self
.
attributes
is
not
None
:
scope
=
StructOrUnionScope
(
self
.
name
)
self
.
entry
=
env
.
declare_struct_or_union
(
self
.
name
,
self
.
kind
,
scope
,
self
.
typedef_flag
,
self
.
pos
,
self
.
cname
,
visibility
=
self
.
visibility
)
self
.
cname
,
visibility
=
self
.
visibility
,
packed
=
self
.
packed
)
if
self
.
attributes
is
not
None
:
if
self
.
in_pxd
and
not
env
.
in_cinclude
:
self
.
entry
.
defined_in_pxd
=
1
...
...
@@ -1644,9 +1647,11 @@ class DefNode(FuncDefNode):
def
analyse_signature
(
self
,
env
):
any_type_tests_needed
=
0
# Use the simpler calling signature for zero- and one-argument functions.
if
not
self
.
entry
.
is_special
and
not
self
.
star_arg
and
not
self
.
starstar_arg
:
if
self
.
entry
.
signature
is
TypeSlots
.
pyfunction_signature
and
Options
.
optimize_simple_methods
:
if
self
.
entry
.
is_special
:
self
.
entry
.
trivial_signature
=
len
(
self
.
args
)
==
1
and
not
(
self
.
star_arg
or
self
.
starstar_arg
)
elif
not
env
.
directives
[
'always_allow_keywords'
]
and
not
(
self
.
star_arg
or
self
.
starstar_arg
):
# Use the simpler calling signature for zero- and one-argument functions.
if
self
.
entry
.
signature
is
TypeSlots
.
pyfunction_signature
:
if
len
(
self
.
args
)
==
0
:
self
.
entry
.
signature
=
TypeSlots
.
pyfunction_noargs
elif
len
(
self
.
args
)
==
1
:
...
...
@@ -1658,8 +1663,6 @@ class DefNode(FuncDefNode):
elif
len
(
self
.
args
)
==
2
:
if
self
.
args
[
1
].
default
is
None
and
not
self
.
args
[
1
].
kw_only
:
self
.
entry
.
signature
=
TypeSlots
.
ibinaryfunc
elif
self
.
entry
.
is_special
:
self
.
entry
.
trivial_signature
=
len
(
self
.
args
)
==
1
and
not
(
self
.
star_arg
or
self
.
starstar_arg
)
sig
=
self
.
entry
.
signature
nfixed
=
sig
.
num_fixed_args
()
for
i
in
range
(
nfixed
):
...
...
Cython/Compiler/Options.py
View file @
16afe72d
...
...
@@ -45,11 +45,6 @@ lookup_module_cpdef = 0
# WARNING: This is a work in progress, may currently segfault.
init_local_none
=
1
# Optimize no argument and one argument methods by using the METH_O and METH_NOARGS
# calling conventions. These are faster calling conventions, but disallow the use of
# keywords (which, admittedly, are of little use in these cases).
optimize_simple_methods
=
1
# Append the c file and line number to the traceback for exceptions.
c_line_in_traceback
=
1
...
...
@@ -68,6 +63,7 @@ option_defaults = {
'auto_cpdef'
:
False
,
'cdivision'
:
True
,
# Will be False in 0.12
'cdivision_warnings'
:
False
,
'always_allow_keywords'
:
False
,
}
# Override types possibilities above, if needed
...
...
Cython/Compiler/Parsing.py
View file @
16afe72d
...
...
@@ -2156,7 +2156,7 @@ def p_cdef_statement(s, ctx):
#if ctx.api:
# error(pos, "'api' not allowed with extension class")
return
p_c_class_definition
(
s
,
pos
,
ctx
)
elif
s
.
sy
==
'IDENT'
and
s
.
systring
in
struct_union_or_enum
:
elif
s
.
sy
==
'IDENT'
and
s
.
systring
in
(
"struct"
,
"union"
,
"enum"
,
"packed"
)
:
if
ctx
.
level
not
in
(
'module'
,
'module_pxd'
):
error
(
pos
,
"C struct/union/enum definition not allowed here"
)
#if ctx.visibility == 'public':
...
...
@@ -2192,10 +2192,6 @@ def p_cdef_extern_block(s, pos, ctx):
include_file
=
include_file
,
body
=
body
)
struct_union_or_enum
=
(
"struct"
,
"union"
,
"enum"
)
def
p_c_enum_definition
(
s
,
pos
,
ctx
):
# s.sy == ident 'enum'
s
.
next
()
...
...
@@ -2246,6 +2242,12 @@ def p_c_enum_item(s, items):
name
=
name
,
cname
=
cname
,
value
=
value
))
def
p_c_struct_or_union_definition
(
s
,
pos
,
ctx
):
packed
=
False
if
s
.
systring
==
'packed'
:
packed
=
True
s
.
next
()
if
s
.
sy
!=
'IDENT'
or
s
.
systring
!=
'struct'
:
s
.
expected
(
'struct'
)
# s.sy == ident 'struct' or 'union'
kind
=
s
.
systring
s
.
next
()
...
...
@@ -2271,7 +2273,7 @@ def p_c_struct_or_union_definition(s, pos, ctx):
return
Nodes
.
CStructOrUnionDefNode
(
pos
,
name
=
name
,
cname
=
cname
,
kind
=
kind
,
attributes
=
attributes
,
typedef_flag
=
ctx
.
typedef_flag
,
visibility
=
ctx
.
visibility
,
in_pxd
=
ctx
.
level
==
'module_pxd'
)
in_pxd
=
ctx
.
level
==
'module_pxd'
,
packed
=
packed
)
def
p_visibility
(
s
,
prev_visibility
):
pos
=
s
.
position
()
...
...
@@ -2343,7 +2345,7 @@ def p_ctypedef_statement(s, ctx):
ctx
.
api
=
1
if
s
.
sy
==
'class'
:
return
p_c_class_definition
(
s
,
pos
,
ctx
)
elif
s
.
sy
==
'IDENT'
and
s
.
systring
in
(
'struct'
,
'union'
,
'enum'
):
elif
s
.
sy
==
'IDENT'
and
s
.
systring
in
(
'
packed'
,
'
struct'
,
'union'
,
'enum'
):
if
s
.
systring
==
'enum'
:
return
p_c_enum_definition
(
s
,
pos
,
ctx
)
else
:
...
...
Cython/Compiler/PyrexTypes.py
View file @
16afe72d
...
...
@@ -1024,11 +1024,12 @@ class CStructOrUnionType(CType):
# kind string "struct" or "union"
# scope StructOrUnionScope, or None if incomplete
# typedef_flag boolean
# packed boolean
is_struct_or_union
=
1
has_attributes
=
1
def
__init__
(
self
,
name
,
kind
,
scope
,
typedef_flag
,
cname
):
def
__init__
(
self
,
name
,
kind
,
scope
,
typedef_flag
,
cname
,
packed
=
False
):
self
.
name
=
name
self
.
cname
=
cname
self
.
kind
=
kind
...
...
@@ -1039,6 +1040,7 @@ class CStructOrUnionType(CType):
self
.
to_py_function
=
"%s_to_py_%s"
%
(
Naming
.
convert_func_prefix
,
self
.
cname
)
self
.
exception_check
=
True
self
.
_convert_code
=
None
self
.
packed
=
packed
def
create_convert_utility_code
(
self
,
env
):
if
env
.
outer_scope
is
None
:
...
...
Cython/Compiler/Scanning.py
View file @
16afe72d
...
...
@@ -490,7 +490,7 @@ class PyrexScanner(Scanner):
else
:
self
.
expected
(
what
,
message
)
def
expected
(
self
,
what
,
message
):
def
expected
(
self
,
what
,
message
=
None
):
if
message
:
self
.
error
(
message
)
else
:
...
...
Cython/Compiler/Symtab.py
View file @
16afe72d
...
...
@@ -341,7 +341,8 @@ class Scope(object):
return entry
def declare_struct_or_union(self, name, kind, scope,
typedef_flag, pos, cname = None, visibility = 'private'):
typedef_flag, pos, cname = None, visibility = 'private',
packed = False):
# Add an entry for a struct or union definition.
if not cname:
if self.in_cinclude or visibility == 'public':
...
...
@@ -351,7 +352,7 @@ class Scope(object):
entry = self.lookup_here(name)
if not entry:
type = PyrexTypes.CStructOrUnionType(
name, kind, scope, typedef_flag, cname)
name, kind, scope, typedef_flag, cname
, packed
)
entry = self.declare_type(name, type, pos, cname,
visibility = visibility, defining = scope is not None)
self.sue_entries.append(entry)
...
...
runtests.py
View file @
16afe72d
...
...
@@ -642,7 +642,7 @@ if __name__ == '__main__':
filetests
=
TestBuilder
(
ROOTDIR
,
WORKDIR
,
selectors
,
exclude_selectors
,
options
.
annotate_source
,
options
.
cleanup_workdir
,
options
.
cleanup_sharedlibs
,
True
,
options
.
cython_only
,
languages
)
options
.
cython_only
,
languages
,
test_bugs
)
test_suite
.
addTest
(
filetests
.
handle_directory
(
os
.
path
.
join
(
sys
.
prefix
,
'lib'
,
'python'
+
sys
.
version
[:
3
],
'test'
),
...
...
tests/errors/e2_packedstruct_T290.pyx
0 → 100644
View file @
16afe72d
cdef
packed
foo
:
pass
_ERRORS
=
u"""
1:12: Expected 'struct'
"""
tests/errors/e_packedstruct_T290.pyx
0 → 100644
View file @
16afe72d
cdef
extern
:
cdef
packed
struct
MyStruct
:
char
a
_ERRORS
=
u"""
2:9: Cannot declare extern struct as 'packed'
"""
tests/run/always_allow_keywords_T295.pyx
0 → 100644
View file @
16afe72d
__doc__
=
"""
>>> func1(None)
>>> func1(*[None])
>>> func1(arg=None)
Traceback (most recent call last):
...
TypeError: func1() takes no keyword arguments
>>> func2(None)
>>> func2(*[None])
>>> func2(arg=None)
Traceback (most recent call last):
...
TypeError: func2() takes no keyword arguments
>>> func3(None)
>>> func3(*[None])
>>> func3(arg=None)
>>> A().meth1(None)
>>> A().meth1(*[None])
>>> A().meth1(arg=None)
Traceback (most recent call last):
...
TypeError: meth1() takes no keyword arguments
>>> A().meth2(None)
>>> A().meth2(*[None])
>>> A().meth2(arg=None)
Traceback (most recent call last):
...
TypeError: meth2() takes no keyword arguments
>>> A().meth3(None)
>>> A().meth3(*[None])
>>> A().meth3(arg=None)
"""
cimport
cython
def
func1
(
arg
):
pass
@
cython
.
always_allow_keywords
(
False
)
def
func2
(
arg
):
pass
@
cython
.
always_allow_keywords
(
True
)
def
func3
(
arg
):
pass
cdef
class
A
:
def
meth1
(
self
,
arg
):
pass
@
cython
.
always_allow_keywords
(
False
)
def
meth2
(
self
,
arg
):
pass
@
cython
.
always_allow_keywords
(
True
)
def
meth3
(
self
,
arg
):
pass
tests/run/numpy_bufacc_T155.pyx
0 → 100644
View file @
16afe72d
"""
>>> myfunc()
0.5
"""
cimport
numpy
as
np
import
numpy
as
np
def
myfunc
():
cdef
np
.
ndarray
[
float
,
ndim
=
2
]
A
=
np
.
ones
((
1
,
1
),
dtype
=
np
.
float32
)
cdef
int
i
for
i
from
0
<=
i
<
A
.
shape
[
0
]:
A
[
i
,
:]
/=
2
return
A
[
0
,
0
]
tests/run/packedstruct_T290.pyx
0 → 100644
View file @
16afe72d
"""
>>> f()
(9, 9)
"""
cdef
packed
struct
MyCdefStruct
:
char
a
double
b
ctypedef
packed
struct
MyCTypeDefStruct
:
char
a
double
b
def
f
():
return
(
sizeof
(
MyCdefStruct
),
sizeof
(
MyCTypeDefStruct
))
tests/run/tupleunpack_T298.pyx
0 → 100644
View file @
16afe72d
"""
>>> func()
0 0
0
0
1 1
1
1
2 2
2
2
>>> func2()
"""
def
g
():
return
((
3
,
2
),
1
,
0
)
def
func2
():
(
a
,
b
),
c
,
d
=
g
()
def
func
():
for
(
a
,
b
),
c
,
d
in
zip
(
zip
(
range
(
3
),
range
(
3
)),
range
(
3
),
range
(
3
)):
print
a
,
b
print
c
print
d
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