Permalink
Browse files

Clang-compatible C++ nested destructor call.

  • Loading branch information...
robertwb committed Feb 18, 2014
1 parent 5fbe131 commit d360c927d8c2c7027e54b5e600d337f936b3d155
Showing with 9 additions and 8 deletions.
  1. +1 −8 Cython/Compiler/ModuleNode.py
  2. +8 −0 Cython/Utility/ModuleSetupCode.c
@@ -1296,14 +1296,7 @@ def generate_dealloc_function(self, scope, code):
code.putln("if (p->__weakref__) PyObject_ClearWeakRefs(o);")

for entry in cpp_class_attrs:
split_cname = entry.type.cname.split('::')
destructor_name = split_cname.pop()
# Make sure the namespace delimiter was not in a template arg.
while destructor_name.count('<') != destructor_name.count('>'):
destructor_name = split_cname.pop() + '::' + destructor_name
destructor_name = destructor_name.split('<', 1)[0]
code.putln("p->%s.%s::~%s();" % (
entry.cname, entry.type.declaration_code(""), destructor_name))
code.putln("__Pyx_call_destructor(&p->%s);" % entry.cname)

for entry in py_attrs:
code.put_xdecref_clear("p->%s" % entry.cname, entry.type, nanny=False,
@@ -336,6 +336,14 @@ static CYTHON_INLINE float __PYX_NAN() {
}
#endif

// Work around clang bug http://stackoverflow.com/questions/21847816/c-invoke-nested-template-class-destructor
#ifdef __cplusplus
template<typename T>
void __Pyx_call_destructor(T* x) {
x->~T();
}
#endif

/////////////// UtilityFunctionPredeclarations.proto ///////////////

/* unused attribute */

1 comment on commit d360c92

@sturlamolden

This comment has been minimized.

Copy link
Contributor

sturlamolden commented on d360c92 Feb 18, 2014

__Pyx_call_destructor could very well need this comment line:

// C++ lacks placement delete, shame on you Bjarne.

Please sign in to comment.