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
Boxiang Sun
cython
Commits
e76ce170
Commit
e76ce170
authored
May 14, 2009
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing up flawed fix for #303
parent
c192ad41
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
17 deletions
+42
-17
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+16
-12
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+13
-3
tests/run/typedfieldbug_T303.pyx
tests/run/typedfieldbug_T303.pyx
+13
-2
No files found.
Cython/Compiler/Nodes.py
View file @
e76ce170
...
@@ -794,21 +794,25 @@ class CVarDefNode(StatNode):
...
@@ -794,21 +794,25 @@ class CVarDefNode(StatNode):
self
.
dest_scope
=
dest_scope
self
.
dest_scope
=
dest_scope
base_type
=
self
.
base_type
.
analyse
(
env
)
base_type
=
self
.
base_type
.
analyse
(
env
)
# If the field is an external typedef, we cannot be sure about the type,
need_property
=
False
# so do conversion ourself rather than rely on the CPython mechanism (through
if
(
dest_scope
.
is_c_class_scope
# a property; made in AnalyseDeclarationsTransform).
and
self
.
visibility
==
'public'
# Also, if the type is an extension type, then the CPython mechanism does
and
base_type
.
is_pyobject
# not do enough type-checking for us.
and
(
base_type
.
is_builtin_type
or
base_type
.
is_extension_type
)):
if
(
dest_scope
.
is_c_class_scope
and
# If the field is settable and extension type, then the CPython mechanism does
((
self
.
visibility
==
'public'
# not do enough type-checking for us.
and
base_type
.
is_pyobject
need_property
=
True
and
(
base_type
.
is_builtin_type
or
base_type
.
is_extension_type
)
elif
(
base_type
.
is_typedef
and
base_type
.
typedef_is_external
or
(
base_type
.
is_typedef
and
base_type
.
typedef_is_external
)))):
and
(
self
.
visibility
in
(
'public'
,
'readonly'
))):
self
.
need_properties
=
[]
# If the field is an external typedef, we cannot be sure about the type,
# so do conversion ourself rather than rely on the CPython mechanism (through
# a property; made in AnalyseDeclarationsTransform).
need_property
=
True
need_property
=
True
if
need_property
:
visibility
=
'private'
visibility
=
'private'
self
.
need_properties
=
[]
else
:
else
:
need_property
=
False
visibility
=
self
.
visibility
visibility
=
self
.
visibility
for
declarator
in
self
.
declarators
:
for
declarator
in
self
.
declarators
:
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
e76ce170
...
@@ -676,6 +676,12 @@ property NAME:
...
@@ -676,6 +676,12 @@ property NAME:
ATTR = value
ATTR = value
"""
,
level
=
'c_class'
)
"""
,
level
=
'c_class'
)
readonly_property
=
TreeFragment
(
u"""
property NAME:
def __get__(self):
return ATTR
"""
,
level
=
'c_class'
)
def
__call__
(
self
,
root
):
def
__call__
(
self
,
root
):
self
.
env_stack
=
[
root
.
scope
]
self
.
env_stack
=
[
root
.
scope
]
# needed to determine if a cdef var is declared after it's used.
# needed to determine if a cdef var is declared after it's used.
...
@@ -752,7 +758,7 @@ property NAME:
...
@@ -752,7 +758,7 @@ property NAME:
# mechanism for them.
# mechanism for them.
stats
=
[]
stats
=
[]
for
entry
in
node
.
need_properties
:
for
entry
in
node
.
need_properties
:
property
=
self
.
create_Property
(
entry
)
property
=
self
.
create_Property
(
entry
,
node
.
visibility
==
'readonly'
)
property
.
analyse_declarations
(
node
.
dest_scope
)
property
.
analyse_declarations
(
node
.
dest_scope
)
self
.
visit
(
property
)
self
.
visit
(
property
)
stats
.
append
(
property
)
stats
.
append
(
property
)
...
@@ -760,8 +766,12 @@ property NAME:
...
@@ -760,8 +766,12 @@ property NAME:
else
:
else
:
return
None
return
None
def
create_Property
(
self
,
entry
):
def
create_Property
(
self
,
entry
,
readonly
):
property
=
self
.
basic_property
.
substitute
({
if
readonly
:
template
=
self
.
readonly_property
else
:
template
=
self
.
basic_property
property
=
template
.
substitute
({
u"ATTR"
:
AttributeNode
(
pos
=
entry
.
pos
,
u"ATTR"
:
AttributeNode
(
pos
=
entry
.
pos
,
obj
=
NameNode
(
pos
=
entry
.
pos
,
name
=
"self"
),
obj
=
NameNode
(
pos
=
entry
.
pos
,
name
=
"self"
),
attribute
=
entry
.
name
),
attribute
=
entry
.
name
),
...
...
tests/run/typedfieldbug_T303.pyx
View file @
e76ce170
"""
"""
>>> f()
>>> f()
42.0 42.0
42.0 42.0 42.0
>>> readonly()
Traceback (most recent call last):
...
AttributeError: attribute 'var_nf' of 'typedfieldbug_T303.MyClass' objects is not writable
"""
"""
cdef
extern
from
"external_defs.h"
:
cdef
extern
from
"external_defs.h"
:
...
@@ -10,11 +14,18 @@ cdef class MyClass:
...
@@ -10,11 +14,18 @@ cdef class MyClass:
cdef
readonly
:
cdef
readonly
:
double
var_d
double
var_d
DoubleTypedef
var_nf
DoubleTypedef
var_nf
cdef
public
:
DoubleTypedef
mutable
def
__init__
(
self
):
def
__init__
(
self
):
self
.
var_d
=
42.0
self
.
var_d
=
42.0
self
.
var_nf
=
42.0
self
.
var_nf
=
42.0
self
.
mutable
=
1
def
f
():
def
f
():
c
=
MyClass
()
c
=
MyClass
()
print
c
.
var_d
,
c
.
var_nf
c
.
mutable
=
42.0
print
c
.
var_d
,
c
.
var_nf
,
c
.
mutable
def
readonly
():
c
=
MyClass
()
c
.
var_nf
=
3
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