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
8bcb7184
Commit
8bcb7184
authored
Sep 25, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disallow the form 'f(self, ...) const' for cypclass methods
parent
bd25a02e
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
48 additions
and
48 deletions
+48
-48
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+2
-2
Cython/Includes/libcythonplus/dict.pxd
Cython/Includes/libcythonplus/dict.pxd
+8
-8
Cython/Includes/libcythonplus/list.pxd
Cython/Includes/libcythonplus/list.pxd
+6
-6
Cython/Includes/libcythonplus/set.pxd
Cython/Includes/libcythonplus/set.pxd
+20
-20
tests/errors/cypclass_lock_error.pyx
tests/errors/cypclass_lock_error.pyx
+1
-1
tests/run/cypclass_acthon.pyx
tests/run/cypclass_acthon.pyx
+9
-9
tests/run/cypclass_lock.pyx
tests/run/cypclass_lock.pyx
+1
-1
tests/run/cypclass_operators_more.pyx
tests/run/cypclass_operators_more.pyx
+1
-1
No files found.
Cython/Compiler/Nodes.py
View file @
8bcb7184
...
...
@@ -651,6 +651,8 @@ class CFuncDeclaratorNode(CDeclaratorNode):
directive_locals
=
{}
if
nonempty
:
nonempty
-=
1
if
self
.
is_const_method
and
env
.
is_cyp_class_scope
:
error
(
self
.
pos
,
"The form 'f(self, ...) const' is not allowed for cypclass methods. Use 'f(const self, ...)' instead"
)
func_type_args
=
[]
for
i
,
arg_node
in
enumerate
(
self
.
args
):
name_declarator
,
type
=
arg_node
.
analyse
(
...
...
@@ -683,8 +685,6 @@ class CFuncDeclaratorNode(CDeclaratorNode):
if
type
.
is_const_cyp_class
:
self
.
is_const_method
=
True
unqualified_type
=
type
.
const_base_type
elif
self
.
is_const_method
:
type
=
PyrexTypes
.
cyp_class_const_type
(
type
)
# check that the type of self is correct:
if
not
unqualified_type
.
same_as
(
env
.
parent_type
):
error
(
self
.
pos
,
"Wrong type for self argument - expected %s, got %s"
%
(
env
.
parent_type
,
type
))
...
...
Cython/Includes/libcythonplus/dict.pxd
View file @
8bcb7184
...
...
@@ -137,7 +137,7 @@ cdef cypclass cypdict[K, V]:
__init__
(
self
):
self
.
_active_iterators
.
store
(
0
)
V
__getitem__
(
self
,
const
key_type
key
)
except
~
const
:
V
__getitem__
(
const
self
,
const
key_type
key
)
except
~
:
it
=
self
.
_indices
.
const_find
(
key
)
if
it
!=
self
.
_indices
.
end
():
return
self
.
_items
[
dereference
(
it
).
second
].
second
...
...
@@ -182,23 +182,23 @@ cdef cypclass cypdict[K, V]:
with
gil
:
raise
RuntimeError
(
"Modifying a dictionary with active iterators"
)
iterator
begin
(
self
)
const
:
iterator
begin
(
const
self
)
:
return
iterator
(
self
.
_items
.
const_begin
(),
self
)
vector
[
item_type
].
const_iterator
end
(
self
)
const
:
vector
[
item_type
].
const_iterator
end
(
const
self
)
:
return
self
.
_items
.
const_end
()
size_type
__len__
(
self
)
const
:
size_type
__len__
(
const
self
)
:
return
self
.
_items
.
size
()
bint
__contains__
(
self
,
const
key_type
key
)
const
:
bint
__contains__
(
const
self
,
const
key_type
key
)
:
return
self
.
_indices
.
count
(
key
)
keys_view
keys
(
self
)
const
:
keys_view
keys
(
const
self
)
:
return
keys_view
(
self
)
values_view
values
(
self
)
const
:
values_view
values
(
const
self
)
:
return
values_view
(
self
)
items_view
items
(
self
)
const
:
items_view
items
(
const
self
)
:
return
items_view
(
self
)
Cython/Includes/libcythonplus/list.pxd
View file @
8bcb7184
...
...
@@ -34,7 +34,7 @@ cdef cypclass cyplist[V]:
__init__
(
self
):
self
.
_active_iterators
.
store
(
0
)
V
__getitem__
(
self
,
const
size_type
index
)
except
~
const
:
V
__getitem__
(
const
self
,
const
size_type
index
)
except
~
:
if
index
<
self
.
_elements
.
size
():
return
self
.
_elements
[
index
]
else
:
...
...
@@ -86,7 +86,7 @@ cdef cypclass cyplist[V]:
with
gil
:
raise
RuntimeError
(
"Modifying a list with active iterators"
)
cyplist
[
V
]
__add__
(
self
,
const
cyplist
[
V
]
other
)
const
:
cyplist
[
V
]
__add__
(
const
self
,
const
cyplist
[
V
]
other
)
:
result
=
cyplist
[
V
]()
result
.
_elements
.
reserve
(
self
.
_elements
.
size
()
+
other
.
_elements
.
size
())
result
.
_elements
.
insert
(
result
.
_elements
.
end
(),
self
.
_elements
.
const_begin
(),
self
.
_elements
.
const_end
())
...
...
@@ -101,7 +101,7 @@ cdef cypclass cyplist[V]:
with
gil
:
raise
RuntimeError
(
"Modifying a list with active iterators"
)
cyplist
[
V
]
__mul__
(
self
,
size_type
n
)
const
:
cyplist
[
V
]
__mul__
(
const
self
,
size_type
n
)
:
result
=
cyplist
[
V
]()
result
.
_elements
.
reserve
(
self
.
_elements
.
size
()
*
n
)
for
i
in
range
(
n
):
...
...
@@ -125,13 +125,13 @@ cdef cypclass cyplist[V]:
with
gil
:
raise
RuntimeError
(
"Modifying a list with active iterators"
)
iterator
begin
(
self
)
const
:
iterator
begin
(
const
self
)
:
return
iterator
(
self
.
_elements
.
const_begin
(),
self
)
vector
[
value_type
].
const_iterator
end
(
self
)
const
:
vector
[
value_type
].
const_iterator
end
(
const
self
)
:
return
self
.
_elements
.
const_end
()
size_type
__len__
(
self
)
const
:
size_type
__len__
(
const
self
)
:
return
self
.
_elements
.
size
()
bint
__contains__
(
self
,
const
value_type
value
):
...
...
Cython/Includes/libcythonplus/set.pxd
View file @
8bcb7184
...
...
@@ -79,13 +79,13 @@ cdef cypclass cypset[V]:
# inspection operations
size_type
__len__
(
self
)
const
:
size_type
__len__
(
const
self
)
:
return
self
.
_elements
.
size
()
bint
__contains__
(
self
,
const
value_type
value
):
return
self
.
_elements
.
count
(
value
)
bint
isdisjoint
(
self
,
const
cypset
[
V
]
other
)
const
:
bint
isdisjoint
(
const
self
,
const
cypset
[
V
]
other
)
:
cdef
const
cypset
[
V
]
smallest
cdef
const
cypset
[
V
]
greatest
if
self
.
_elements
.
size
()
<
other
.
_elements
.
size
():
...
...
@@ -101,7 +101,7 @@ cdef cypclass cypset[V]:
# set comparisons
bint
__eq__
(
self
,
const
cypset
[
V
]
other
)
const
:
bint
__eq__
(
const
self
,
const
cypset
[
V
]
other
)
:
if
self
.
_elements
.
size
()
!=
other
.
_elements
.
size
():
return
0
for
value
in
self
.
_elements
:
...
...
@@ -109,7 +109,7 @@ cdef cypclass cypset[V]:
return
0
return
1
bint
__ne__
(
self
,
const
cypset
[
V
]
other
)
const
:
bint
__ne__
(
const
self
,
const
cypset
[
V
]
other
)
:
if
self
.
_elements
.
size
()
!=
other
.
_elements
.
size
():
return
1
for
value
in
self
.
_elements
:
...
...
@@ -117,7 +117,7 @@ cdef cypclass cypset[V]:
return
1
return
0
bint
__le__
(
self
,
const
cypset
[
V
]
other
)
const
:
bint
__le__
(
const
self
,
const
cypset
[
V
]
other
)
:
if
self
.
_elements
.
size
()
>
other
.
_elements
.
size
():
return
0
for
value
in
self
.
_elements
:
...
...
@@ -125,13 +125,13 @@ cdef cypclass cypset[V]:
return
0
return
1
bint
__lt__
(
self
,
const
cypset
[
V
]
other
)
const
:
bint
__lt__
(
const
self
,
const
cypset
[
V
]
other
)
:
return
self
<=
other
and
self
.
_elements
.
size
()
<
other
.
_elements
.
size
()
bint
issubset
(
self
,
const
cypset
[
V
]
other
)
const
:
bint
issubset
(
const
self
,
const
cypset
[
V
]
other
)
:
return
self
<=
other
bint
__ge__
(
self
,
const
cypset
[
V
]
other
)
const
:
bint
__ge__
(
const
self
,
const
cypset
[
V
]
other
)
:
if
self
.
_elements
.
size
()
<
other
.
_elements
.
size
():
return
0
for
value
in
other
.
_elements
:
...
...
@@ -139,25 +139,25 @@ cdef cypclass cypset[V]:
return
0
return
1
bint
__gt__
(
self
,
const
cypset
[
V
]
other
)
const
:
bint
__gt__
(
const
self
,
const
cypset
[
V
]
other
)
:
return
self
>=
other
and
self
.
_elements
.
size
()
>
other
.
_elements
.
size
()
bint
issuperset
(
self
,
const
cypset
[
V
]
other
)
const
:
bint
issuperset
(
const
self
,
const
cypset
[
V
]
other
)
:
return
self
>=
other
# set non-modifying operations
cypset
[
V
]
__or__
(
self
,
const
cypset
[
V
]
other
)
const
:
cypset
[
V
]
__or__
(
const
self
,
const
cypset
[
V
]
other
)
:
result
=
cypset
[
V
]()
result
.
_elements
.
insert
(
self
.
_elements
.
const_begin
(),
self
.
_elements
.
const_end
())
result
.
_elements
.
insert
(
other
.
_elements
.
const_begin
(),
other
.
_elements
.
const_end
())
return
result
cypset
[
V
]
union
"set_union"
(
self
,
const
cypset
[
V
]
other
)
const
:
cypset
[
V
]
union
"set_union"
(
const
self
,
const
cypset
[
V
]
other
)
:
return
self
|
other
cypset
[
V
]
__and__
(
self
,
const
cypset
[
V
]
other
)
const
:
cypset
[
V
]
__and__
(
const
self
,
const
cypset
[
V
]
other
)
:
cdef
const
cypset
[
V
]
smallest
cdef
const
cypset
[
V
]
greatest
if
self
.
_elements
.
size
()
<
other
.
_elements
.
size
():
...
...
@@ -172,20 +172,20 @@ cdef cypclass cypset[V]:
result
.
_elements
.
insert
(
value
)
return
result
cypset
[
V
]
intersection
(
self
,
const
cypset
[
V
]
other
)
const
:
cypset
[
V
]
intersection
(
const
self
,
const
cypset
[
V
]
other
)
:
return
self
&
other
cypset
[
V
]
__sub__
(
self
,
const
cypset
[
V
]
other
)
const
:
cypset
[
V
]
__sub__
(
const
self
,
const
cypset
[
V
]
other
)
:
result
=
cypset
[
V
]()
for
value
in
self
.
_elements
:
if
other
.
_elements
.
count
(
value
)
==
0
:
result
.
_elements
.
insert
(
value
)
return
result
cypset
[
V
]
difference
(
self
,
const
cypset
[
V
]
other
)
const
:
cypset
[
V
]
difference
(
const
self
,
const
cypset
[
V
]
other
)
:
return
self
-
other
cypset
[
V
]
__xor__
(
self
,
const
cypset
[
V
]
other
)
const
:
cypset
[
V
]
__xor__
(
const
self
,
const
cypset
[
V
]
other
)
:
result
=
cypset
[
V
]()
result
.
_elements
=
other
.
_elements
for
value
in
self
.
_elements
:
...
...
@@ -196,7 +196,7 @@ cdef cypclass cypset[V]:
result
.
_elements
.
insert
(
value
)
return
result
cypset
[
V
]
symmetric_difference
(
self
,
const
cypset
[
V
]
other
)
const
:
cypset
[
V
]
symmetric_difference
(
const
self
,
const
cypset
[
V
]
other
)
:
return
self
^
other
...
...
@@ -261,8 +261,8 @@ cdef cypclass cypset[V]:
# iterators
iterator
begin
(
self
)
const
:
iterator
begin
(
const
self
)
:
return
iterator
(
self
.
_elements
.
const_begin
(),
self
)
unordered_set
[
value_type
].
const_iterator
end
(
self
)
const
:
unordered_set
[
value_type
].
const_iterator
end
(
const
self
)
:
return
self
.
_elements
.
const_end
()
tests/errors/cypclass_lock_error.pyx
View file @
8bcb7184
...
...
@@ -4,7 +4,7 @@
cdef
cypclass
A
checklock
:
int
a
int
getter
(
self
)
const
:
int
getter
(
const
self
)
:
return
self
.
a
void
setter
(
self
,
int
a
):
self
.
a
=
a
...
...
tests/run/cypclass_acthon.pyx
View file @
8bcb7184
...
...
@@ -23,7 +23,7 @@ cdef cypclass BasicQueue(ActhonQueueInterface) checklock:
__dealloc__
(
self
):
del
self
.
_queue
bint
is_empty
(
self
)
const
:
bint
is_empty
(
const
self
)
:
return
self
.
_queue
.
empty
()
void
push
(
self
,
ActhonMessageInterface
message
):
...
...
@@ -58,9 +58,9 @@ cdef cypclass NoneResult(ActhonResultInterface) checklock:
pass
void
pushIntResult
(
self
,
int
result
):
pass
void
*
getVoidStarResult
(
self
)
const
:
void
*
getVoidStarResult
(
const
self
)
:
return
NULL
int
getIntResult
(
self
)
const
:
int
getIntResult
(
const
self
)
:
return
0
cdef
cypclass
WaitResult
(
ActhonResultInterface
)
checklock
:
...
...
@@ -89,18 +89,18 @@ cdef cypclass WaitResult(ActhonResultInterface) checklock:
self
.
result
.
int_val
=
result
sem_post
(
&
self
.
semaphore
)
result_t
_getRawResult
(
self
)
const
:
result_t
_getRawResult
(
const
self
)
:
# We must ensure a result exists, but we can let others access it immediately
# The cast here is a way of const-casting (we're modifying the semaphore in a const method)
sem_wait
(
<
sem_t
*>
&
self
.
semaphore
)
sem_post
(
<
sem_t
*>
&
self
.
semaphore
)
return
self
.
result
void
*
getVoidStarResult
(
self
)
const
:
void
*
getVoidStarResult
(
const
self
)
:
res
=
self
.
_getRawResult
()
return
res
.
ptr
int
getIntResult
(
self
)
const
:
int
getIntResult
(
const
self
)
:
res
=
self
.
_getRawResult
()
return
res
.
int_val
...
...
@@ -118,10 +118,10 @@ cdef cypclass ActivityCounterSync(ActhonSyncInterface) checklock:
void
removeActivity
(
self
,
ActhonMessageInterface
msg
):
self
.
count
-=
1
bint
isCompleted
(
self
)
const
:
bint
isCompleted
(
const
self
)
:
return
self
.
count
==
0
bint
isActivable
(
self
)
const
:
bint
isActivable
(
const
self
)
:
cdef
bint
res
=
True
if
self
.
previous_sync
is
not
NULL
:
prev_sync
=
self
.
previous_sync
...
...
@@ -135,7 +135,7 @@ cdef cypclass A checklock activable:
self
.
a
=
0
self
.
_active_result_class
=
WaitResult
.
construct
self
.
_active_queue_class
=
BasicQueue
()
int
getter
(
self
)
const
:
int
getter
(
const
self
)
:
return
self
.
a
void
setter
(
self
,
int
a
):
self
.
a
=
a
...
...
tests/run/cypclass_lock.pyx
View file @
8bcb7184
...
...
@@ -6,7 +6,7 @@ cdef cypclass A checklock:
int
a
__init__
(
self
):
self
.
a
=
0
int
getter
(
self
)
const
:
int
getter
(
const
self
)
:
return
self
.
a
void
setter
(
self
,
int
a
):
self
.
a
=
a
...
...
tests/run/cypclass_operators_more.pyx
View file @
8bcb7184
...
...
@@ -175,7 +175,7 @@ cdef cypclass Subscript:
self
.
value
=
NULL
self
.
index
=
NULL
Value
__getitem__
(
self
,
Index
index
)
const
:
Value
__getitem__
(
const
self
,
Index
index
)
:
if
self
.
index
is
index
:
return
value
return
NULL
...
...
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