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
Kirill Smelkov
cython
Commits
568bcc0c
Commit
568bcc0c
authored
7 years ago
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix generation of api code for C++ classes with object members.
Fixes Github issue #1886.
parent
9c6af17f
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
40 deletions
+63
-40
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+51
-40
tests/run/cpp_classes_def.pyx
tests/run/cpp_classes_def.pyx
+12
-0
No files found.
Cython/Compiler/ModuleNode.py
View file @
568bcc0c
...
...
@@ -901,6 +901,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
put
(
"virtual "
)
has_virtual_methods
=
True
code
.
putln
(
"%s;"
%
attr
.
type
.
declaration_code
(
attr
.
cname
))
is_implementing
=
'init_module'
in
code
.
globalstate
.
parts
if
constructor
or
py_attrs
:
if
constructor
:
arg_decls
=
[]
...
...
@@ -917,6 +918,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
else
:
arg_decls
=
[
"void"
]
arg_names
=
[]
if
is_implementing
:
code
.
putln
(
"%s(%s) {"
%
(
type
.
cname
,
", "
.
join
(
arg_decls
)))
if
py_attrs
:
code
.
put_ensure_gil
()
...
...
@@ -927,9 +929,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if
py_attrs
:
code
.
put_release_ensured_gil
()
code
.
putln
(
"}"
)
else
:
code
.
putln
(
"%s(%s);"
%
(
type
.
cname
,
", "
.
join
(
arg_decls
)))
if
destructor
or
py_attrs
or
has_virtual_methods
:
if
has_virtual_methods
:
code
.
put
(
"virtual "
)
if
is_implementing
:
code
.
putln
(
"~%s() {"
%
type
.
cname
)
if
py_attrs
:
code
.
put_ensure_gil
()
...
...
@@ -940,8 +945,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
put_var_xdecref
(
attr
,
nanny
=
False
);
code
.
put_release_ensured_gil
()
code
.
putln
(
"}"
)
else
:
code
.
putln
(
"~%s();"
%
type
.
cname
)
if
py_attrs
:
# Also need copy constructor and assignment operators.
if
is_implementing
:
code
.
putln
(
"%s(const %s& __Pyx_other) {"
%
(
type
.
cname
,
type
.
cname
))
code
.
put_ensure_gil
()
for
attr
in
scope
.
var_entries
:
...
...
@@ -962,6 +970,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
"}"
)
code
.
putln
(
"return *this;"
)
code
.
putln
(
"}"
)
else
:
code
.
putln
(
"%s(const %s& __Pyx_other);"
%
(
type
.
cname
,
type
.
cname
))
code
.
putln
(
"%s& operator=(const %s& __Pyx_other);"
%
(
type
.
cname
,
type
.
cname
))
code
.
putln
(
"};"
)
def
generate_enum_definition
(
self
,
entry
,
code
):
...
...
This diff is collapsed.
Click to expand it.
tests/run/cpp_classes_def.pyx
View file @
568bcc0c
...
...
@@ -226,6 +226,18 @@ def test_CppClassWithObjectMemberCopyAssign(name):
print
"Nothing alive."
# Github issue #1886.
cdef
public
cppclass
PublicCppClassWithObjectMember
:
object
o
def
test_PublicCppClassWithObjectMember
():
"""
>>> test_PublicCppClassWithObjectMember()
"""
cdef
PublicCppClassWithObjectMember
c
assert
c
.
o
is
None
cdef
cppclass
UncopyableConstructorArgument
:
unique_ptr
[
vector
[
int
]]
member
__init__
(
unique_ptr
[
vector
[
int
]]
arg
):
...
...
This diff is collapsed.
Click to expand it.
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