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
53324e72
Commit
53324e72
authored
Sep 16, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Detect const-incorrect calls of non-const method from const cypclass object
parent
1a1d49d7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
2 deletions
+26
-2
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+1
-0
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+13
-1
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+12
-1
No files found.
Cython/Compiler/Nodes.py
View file @
53324e72
...
...
@@ -779,6 +779,7 @@ class CFuncDeclaratorNode(CDeclaratorNode):
calling_convention
=
self
.
base
.
calling_convention
,
nogil
=
self
.
nogil
,
with_gil
=
self
.
with_gil
,
is_overridable
=
self
.
overridable
,
is_const_method
=
self
.
is_const_method
,
is_cyp_class_method
=
env
.
is_cyp_class_scope
,
templates
=
self
.
templates
)
if
self
.
optional_arg_count
:
...
...
Cython/Compiler/PyrexTypes.py
View file @
53324e72
...
...
@@ -2941,19 +2941,21 @@ class CFuncType(CType):
# (used for optimisation overrides)
# is_const_method boolean
# is_static_method boolean
# is_cyp_class_method boolean
is_cfunction
=
1
original_sig
=
None
cached_specialized_types
=
None
from_fused
=
False
is_const_method
=
False
is_cyp_class_method
=
False
subtypes
=
[
'return_type'
,
'args'
]
def
__init__
(
self
,
return_type
,
args
,
has_varargs
=
0
,
exception_value
=
None
,
exception_check
=
0
,
calling_convention
=
""
,
nogil
=
0
,
with_gil
=
0
,
is_overridable
=
0
,
optional_arg_count
=
0
,
is_const_method
=
False
,
is_static_method
=
False
,
is_const_method
=
False
,
is_static_method
=
False
,
is_cyp_class_method
=
False
,
templates
=
None
,
is_strict_signature
=
False
):
self
.
return_type
=
return_type
self
.
args
=
args
...
...
@@ -2967,6 +2969,7 @@ class CFuncType(CType):
self
.
is_overridable
=
is_overridable
self
.
is_const_method
=
is_const_method
self
.
is_static_method
=
is_static_method
self
.
is_cyp_class_method
=
is_cyp_class_method
self
.
templates
=
templates
self
.
is_strict_signature
=
is_strict_signature
...
...
@@ -2997,6 +3000,7 @@ class CFuncType(CType):
with_gil
,
self
.
is_overridable
,
self
.
optional_arg_count
,
self
.
is_const_method
,
self
.
is_static_method
,
self
.
is_cyp_class_method
,
self
.
templates
,
self
.
is_strict_signature
)
def
calling_convention_prefix
(
self
):
...
...
@@ -3348,6 +3352,7 @@ class CFuncType(CType):
optional_arg_count
=
self
.
optional_arg_count
,
is_const_method
=
self
.
is_const_method
,
is_static_method
=
self
.
is_static_method
,
is_cyp_class_method
=
self
.
is_cyp_class_method
,
templates
=
self
.
templates
)
result
.
from_fused
=
self
.
is_fused
...
...
@@ -5157,6 +5162,13 @@ def best_match(arg_types, functions, pos=None, env=None, args=None, throw=False)
%
(
expectation
,
actual_nargs
)
errors
.
append
((
func
,
error_mesg
))
continue
# Skip non_const methods called on const object
if
func_type
.
is_const
and
not
func_type
.
is_const_method
:
# Impose const-correctness only on cypclass methods for now
if
func_type
.
is_cyp_class_method
:
error_mesg
=
"Cannot call non-const method on const object"
errors
.
append
((
func
,
error_mesg
))
continue
if
func_type
.
templates
:
deductions
=
reduce
(
merge_template_deductions
,
...
...
Cython/Compiler/Symtab.py
View file @
53324e72
...
...
@@ -3253,10 +3253,21 @@ class CConstOrVolatileScope(Scope):
return
self
.
cached_const_or_volatile_entries
[
name
]
except
KeyError
:
entry
=
self
.
base_type_scope
.
lookup_here
(
name
)
if
entry
is
not
None
:
if
entry
is
not
None
and
not
entry
.
is_type
:
entry
=
copy
.
copy
(
entry
)
entry
.
type
=
PyrexTypes
.
c_const_or_volatile_type
(
entry
.
type
,
self
.
is_const
,
self
.
is_volatile
)
# Copy and adapt all the overloaded alternatives
if
entry
.
is_cfunction
:
# the overloaded entry at index 0 is always the one in the scope dict
overloaded_alternatives
=
[
entry
]
for
alt
in
entry
.
overloaded_alternatives
[
1
:]:
qual_alt
=
copy
.
copy
(
alt
)
qual_alt
.
type
=
PyrexTypes
.
c_const_or_volatile_type
(
alt
.
type
,
self
.
is_const
,
self
.
is_volatile
)
qual_alt
.
overloaded_alternatives
=
overloaded_alternatives
overloaded_alternatives
.
append
(
qual_alt
)
entry
.
overloaded_alternatives
=
overloaded_alternatives
self
.
cached_const_or_volatile_entries
[
name
]
=
entry
return
entry
...
...
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