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
1e92f37a
Commit
1e92f37a
authored
Jun 27, 2012
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow no-arg constructor C++ classes as extension class members.
parent
456149b5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
2 deletions
+13
-2
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+8
-0
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+5
-2
No files found.
Cython/Compiler/ModuleNode.py
View file @
1e92f37a
...
...
@@ -1036,6 +1036,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
type
.
vtabslot_cname
,
struct_type_cast
,
type
.
vtabptr_cname
))
for
entry
in
scope
.
var_entries
:
if
entry
.
type
.
is_cpp_class
:
code
.
putln
(
"new(&(p->%s)) %s();"
%
(
entry
.
cname
,
entry
.
type
.
cname
));
for
entry
in
py_attrs
:
if
scope
.
is_internal
or
entry
.
name
==
"__weakref__"
:
# internal classes do not need None inits
...
...
@@ -1091,6 +1095,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if
weakref_slot
in
scope
.
var_entries
:
code
.
putln
(
"if (p->__weakref__) PyObject_ClearWeakRefs(o);"
)
for
entry
in
scope
.
var_entries
:
if
entry
.
type
.
is_cpp_class
:
code
.
putln
(
"p->%s.~%s();"
%
(
entry
.
cname
,
entry
.
type
.
cname
));
for
entry
in
py_attrs
:
code
.
put_xdecref
(
"p->%s"
%
entry
.
cname
,
entry
.
type
,
nanny
=
False
)
...
...
Cython/Compiler/Symtab.py
View file @
1e92f37a
...
...
@@ -571,7 +571,7 @@ class Scope(object):
if type.is_cpp_class and visibility != 'extern':
constructor = type.scope.lookup(u'<init>')
if constructor is not None and PyrexTypes.best_match([], constructor.all_alternatives()) is None:
error(pos, "
C
++
class
must
have
a
default
constructor
to
be
stack
allocated
")
error(pos, "
C
++
class
must
have
a
no
-
arg
constructor
to
be
stack
allocated
")
entry = self.declare(name, cname, type, pos, visibility)
entry.is_variable = 1
if in_pxd and visibility != 'extern':
...
...
@@ -1770,7 +1770,10 @@ class CClassScope(ClassScope):
if
visibility
==
'private'
:
cname
=
c_safe_identifier
(
cname
)
if
type
.
is_cpp_class
and
visibility
!=
'extern'
:
error
(
pos
,
"C++ classes not allowed as members of an extension type, use a pointer or reference instead"
)
constructor
=
type
.
scope
.
lookup
(
u'<init>'
)
if
constructor
is
not
None
and
\
PyrexTypes
.
best_match
([],
constructor
.
all_alternatives
())
is
None
:
error
(
pos
,
"C++ class must have a no-arg constructor to be a member of an extension type; use a pointer instead"
)
entry
=
self
.
declare
(
name
,
cname
,
type
,
pos
,
visibility
)
entry
.
is_variable
=
1
self
.
var_entries
.
append
(
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