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
bdcc37cd
Commit
bdcc37cd
authored
May 30, 2017
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Shared pointer fixes.
Coersion to subclasses prefered in overload resolution to coersion to nullptr_t.
parent
1b7a91a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
3 deletions
+52
-3
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+16
-1
tests/run/cpp_smart_ptr.pyx
tests/run/cpp_smart_ptr.pyx
+36
-2
No files found.
Cython/Compiler/PyrexTypes.py
View file @
bdcc37cd
...
@@ -3572,6 +3572,14 @@ class CppClassType(CType):
...
@@ -3572,6 +3572,14 @@ class CppClassType(CType):
return
1
return
1
return
0
return
0
def
subclass_dist
(
self
,
super_type
):
if
self
.
same_as_resolved_type
(
super_type
):
return
0
elif
not
self
.
base_classes
:
return
float
(
'inf'
)
else
:
return
1
+
min
(
b
.
subclass_dist
(
super_type
)
for
b
in
self
.
base_classes
)
def
same_as_resolved_type
(
self
,
other_type
):
def
same_as_resolved_type
(
self
,
other_type
):
if
other_type
.
is_cpp_class
:
if
other_type
.
is_cpp_class
:
if
self
==
other_type
:
if
self
==
other_type
:
...
@@ -4135,7 +4143,7 @@ def best_match(arg_types, functions, pos=None, env=None, args=None):
...
@@ -4135,7 +4143,7 @@ def best_match(arg_types, functions, pos=None, env=None, args=None):
needed_coercions
=
{}
needed_coercions
=
{}
for
index
,
(
func
,
func_type
)
in
enumerate
(
candidates
):
for
index
,
(
func
,
func_type
)
in
enumerate
(
candidates
):
score
=
[
0
,
0
,
0
,
0
]
score
=
[
0
,
0
,
0
,
0
,
0
,
0
,
0
]
for
i
in
range
(
min
(
actual_nargs
,
len
(
func_type
.
args
))):
for
i
in
range
(
min
(
actual_nargs
,
len
(
func_type
.
args
))):
src_type
=
arg_types
[
i
]
src_type
=
arg_types
[
i
]
dst_type
=
func_type
.
args
[
i
].
type
dst_type
=
func_type
.
args
[
i
].
type
...
@@ -4169,6 +4177,13 @@ def best_match(arg_types, functions, pos=None, env=None, args=None):
...
@@ -4169,6 +4177,13 @@ def best_match(arg_types, functions, pos=None, env=None, args=None):
(
src_type
.
is_float
and
dst_type
.
is_float
)):
(
src_type
.
is_float
and
dst_type
.
is_float
)):
score
[
2
]
+=
abs
(
dst_type
.
rank
+
(
not
dst_type
.
signed
)
-
score
[
2
]
+=
abs
(
dst_type
.
rank
+
(
not
dst_type
.
signed
)
-
(
src_type
.
rank
+
(
not
src_type
.
signed
)))
+
1
(
src_type
.
rank
+
(
not
src_type
.
signed
)))
+
1
elif
dst_type
.
is_ptr
and
src_type
.
is_ptr
:
if
dst_type
.
base_type
==
c_void_type
:
score
[
4
]
+=
1
elif
src_type
.
base_type
.
is_cpp_class
and
src_type
.
base_type
.
is_subclass
(
dst_type
.
base_type
):
score
[
6
]
+=
src_type
.
base_type
.
subclass_dist
(
dst_type
.
base_type
)
else
:
score
[
5
]
+=
1
elif
not
src_type
.
is_pyobject
:
elif
not
src_type
.
is_pyobject
:
score
[
1
]
+=
1
score
[
1
]
+=
1
else
:
else
:
...
...
tests/run/cpp_smart_ptr.pyx
View file @
bdcc37cd
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
# mode: run
# mode: run
# tag: cpp, werror
# tag: cpp, werror
from
libcpp.memory
cimport
unique_ptr
,
shared_ptr
,
default_delete
from
libcpp.memory
cimport
unique_ptr
,
shared_ptr
,
default_delete
from
libcpp
cimport
nullptr
from
libcpp
cimport
nullptr
cdef
extern
from
"cpp_smart_ptr_helper.h"
:
cdef
extern
from
"cpp_smart_ptr_helper.h"
:
...
@@ -33,7 +33,7 @@ def test_unique_ptr():
...
@@ -33,7 +33,7 @@ def test_unique_ptr():
x_ptr2
.
reset
()
x_ptr2
.
reset
()
assert
alloc_count
==
1
assert
alloc_count
==
1
assert
dealloc_count
==
1
assert
dealloc_count
==
1
alloc_count
=
0
alloc_count
=
0
dealloc_count
=
0
dealloc_count
=
0
cdef
unique_ptr
[
CountAllocDealloc
,
FreePtr
[
CountAllocDealloc
]]
x_ptr3
cdef
unique_ptr
[
CountAllocDealloc
,
FreePtr
[
CountAllocDealloc
]]
x_ptr3
...
@@ -41,3 +41,37 @@ def test_unique_ptr():
...
@@ -41,3 +41,37 @@ def test_unique_ptr():
assert
x_ptr3
.
get
()
!=
nullptr
;
assert
x_ptr3
.
get
()
!=
nullptr
;
x_ptr3
.
reset
()
x_ptr3
.
reset
()
assert
x_ptr3
.
get
()
==
nullptr
;
assert
x_ptr3
.
get
()
==
nullptr
;
def
test_shared_ptr
():
"""
>>> test_shared_ptr()
"""
cdef
int
alloc_count
=
0
,
dealloc_count
=
0
cdef
shared_ptr
[
CountAllocDealloc
]
ptr
=
shared_ptr
[
CountAllocDealloc
](
new
CountAllocDealloc
(
&
alloc_count
,
&
dealloc_count
))
assert
alloc_count
==
1
assert
dealloc_count
==
0
cdef
shared_ptr
[
CountAllocDealloc
]
ptr2
=
ptr
assert
alloc_count
==
1
assert
dealloc_count
==
0
ptr
.
reset
()
assert
alloc_count
==
1
assert
dealloc_count
==
0
ptr2
.
reset
()
assert
alloc_count
==
1
assert
dealloc_count
==
1
cdef
cppclass
A
:
pass
cdef
cppclass
B
(
A
):
pass
cdef
cppclass
C
(
B
):
pass
cdef
shared_ptr
[
A
]
holding_subclass
=
shared_ptr
[
A
](
new
C
())
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