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
db1f0ad5
Commit
db1f0ad5
authored
May 01, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make analyse_const_expression() pass on the return value of its internal call to analyse_types()
parent
6075a3c6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
25 deletions
+39
-25
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+3
-2
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+25
-23
tests/run/carrays.pyx
tests/run/carrays.pyx
+11
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
db1f0ad5
...
...
@@ -372,8 +372,9 @@ class ExprNode(Node):
# constant expression. Analyses the expression's type,
# checks whether it is a legal const expression,
# and determines its value.
self
.
analyse_types
(
env
)
return
self
.
check_const
()
node
=
self
.
analyse_types
(
env
)
node
.
check_const
()
return
node
def
analyse_expressions
(
self
,
env
):
# Convenience routine performing both the Type
...
...
Cython/Compiler/Nodes.py
View file @
db1f0ad5
...
...
@@ -537,7 +537,7 @@ class CArrayDeclaratorNode(CDeclaratorNode):
base_type
=
base_type
.
specialize_here
(
self
.
pos
,
values
)
return
self
.
base
.
analyse
(
base_type
,
env
,
nonempty
=
nonempty
)
if
self
.
dimension
:
self
.
dimension
.
analyse_const_expression
(
env
)
self
.
dimension
=
self
.
dimension
.
analyse_const_expression
(
env
)
if
not
self
.
dimension
.
type
.
is_int
:
error
(
self
.
dimension
.
pos
,
"Array dimension not integer"
)
size
=
self
.
dimension
.
get_constant_c_result_code
()
...
...
@@ -621,33 +621,35 @@ class CFuncDeclaratorNode(CDeclaratorNode):
env
.
add_include_file
(
'new'
)
# for std::bad_alloc
env
.
add_include_file
(
'stdexcept'
)
env
.
add_include_file
(
'typeinfo'
)
# for std::bad_cast
if
return_type
.
is_pyobject
\
and
(
self
.
exception_value
or
self
.
exception_check
)
\
and
self
.
exception_check
!=
'+'
:
error
(
self
.
pos
,
"Exception clause not allowed for function returning Python object"
)
if
(
return_type
.
is_pyobject
and
(
self
.
exception_value
or
self
.
exception_check
)
and
self
.
exception_check
!=
'+'
)
:
error
(
self
.
pos
,
"Exception clause not allowed for function returning Python object"
)
else
:
if
self
.
exception_value
:
self
.
exception_value
.
analyse_const_expression
(
env
)
self
.
exception_value
=
self
.
exception_value
.
analyse_const_expression
(
env
)
if
self
.
exception_check
==
'+'
:
self
.
exception_value
=
self
.
exception_value
.
analyse_types
(
env
)
exc_val_type
=
self
.
exception_value
.
type
if
not
exc_val_type
.
is_error
and
\
not
exc_val_type
.
is_pyobject
and
\
not
(
exc_val_type
.
is_cfunction
and
not
exc_val_type
.
return_type
.
is_pyobject
and
len
(
exc_val_type
.
args
)
==
0
):
if
(
not
exc_val_type
.
is_error
and
not
exc_val_type
.
is_pyobject
and
not
(
exc_val_type
.
is_cfunction
and
not
exc_val_type
.
return_type
.
is_pyobject
and
not
exc_val_type
.
args
)):
error
(
self
.
exception_value
.
pos
,
"Exception value must be a Python exception or cdef function with no arguments."
)
"Exception value must be a Python exception or cdef function with no arguments."
)
exc_val
=
self
.
exception_value
else
:
self
.
exception_value
=
self
.
exception_value
.
coerce_to
(
return_type
,
env
)
if
self
.
exception_value
.
analyse_const_expression
(
env
):
exc_val
=
self
.
exception_value
.
get_constant_c_result_code
()
if
exc_val
is
None
:
raise
InternalError
(
"get_constant_c_result_code not implemented for %s"
%
self
.
exception_value
.
__class__
.
__name__
)
if
not
return_type
.
assignable_from
(
self
.
exception_value
.
type
):
error
(
self
.
exception_value
.
pos
,
"Exception value incompatible with function return type"
)
self
.
exception_value
=
self
.
exception_value
.
coerce_to
(
return_type
,
env
).
analyse_const_expression
(
env
)
exc_val
=
self
.
exception_value
.
get_constant_c_result_code
()
if
exc_val
is
None
:
raise
InternalError
(
"get_constant_c_result_code not implemented for %s"
%
self
.
exception_value
.
__class__
.
__name__
)
if
not
return_type
.
assignable_from
(
self
.
exception_value
.
type
):
error
(
self
.
exception_value
.
pos
,
"Exception value incompatible with function return type"
)
exc_check
=
self
.
exception_check
if
return_type
.
is_cfunction
:
error
(
self
.
pos
,
...
...
@@ -1376,10 +1378,10 @@ class CEnumDefItemNode(StatNode):
def
analyse_declarations
(
self
,
env
,
enum_entry
):
if
self
.
value
:
self
.
value
.
analyse_const_expression
(
env
)
self
.
value
=
self
.
value
.
analyse_const_expression
(
env
)
if
not
self
.
value
.
type
.
is_int
:
self
.
value
=
self
.
value
.
coerce_to
(
PyrexTypes
.
c_int_type
,
env
)
self
.
value
.
analyse_const_expression
(
env
)
self
.
value
=
self
.
value
.
analyse_const_expression
(
env
)
entry
=
env
.
declare_const
(
self
.
name
,
enum_entry
.
type
,
self
.
value
,
self
.
pos
,
cname
=
self
.
cname
,
visibility
=
enum_entry
.
visibility
,
api
=
enum_entry
.
api
)
...
...
tests/run/carrays.pyx
View file @
db1f0ad5
...
...
@@ -35,3 +35,14 @@ def test3():
cdef
int
a
[
MY_SIZE_A
]
cdef
int
b
[
MY_SIZE_B
]
return
sizeof
(
a
)
/
sizeof
(
int
),
sizeof
(
b
)
/
sizeof
(
int
)
from
libc
cimport
limits
def
test_cimported_attribute
():
"""
>>> test_cimported_attribute()
True
"""
cdef
char
a
[
limits
.
CHAR_MAX
]
return
sizeof
(
a
)
>=
127
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