From b7efaf8c3fc2d04e1c86bd6d1e627b303281f470 Mon Sep 17 00:00:00 2001 From: Duy-Nguyen Ta Date: Wed, 8 Mar 2017 15:22:16 -0500 Subject: [PATCH] special ctor signature to be used with cyCreateFromShared so that calling the default ctor by mistake on a class without the default ctor will respond nicely with an exception instead of a seg-fault --- wrap/Class.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wrap/Class.cpp b/wrap/Class.cpp index 7aa4cd72a..9336dc9dc 100644 --- a/wrap/Class.cpp +++ b/wrap/Class.cpp @@ -827,13 +827,13 @@ void Class::emit_cython_pyx(FileWriter& pyxFile, const std::vector& allCl " self." << shared_pxd_obj_in_pyx() << " = " << shared_pxd_class_in_pyx() << "()\n"; + pyxFile.oss << " if len(args)==0 and len(kwargs)==1 and kwargs.has_key('cyCreateFromShared'):\n return\n"; for (size_t i = 0; i0) { - pyxFile.oss << " elif len(args)+len(kwargs)==0:\n return\n"; pyxFile.oss << " else:\n raise TypeError('" << pyxClassName() << " construction failed!')\n"; } @@ -849,7 +849,7 @@ void Class::emit_cython_pyx(FileWriter& pyxFile, const std::vector& allCl pyxFile.oss << " @staticmethod\n"; pyxFile.oss << " cdef " << pyxClassName() << " cyCreateFromShared(const " << shared_pxd_class_in_pyx() << "& other):\n" - << " cdef " << pyxClassName() << " ret = " << pyxClassName() << "()\n" + << " cdef " << pyxClassName() << " ret = " << pyxClassName() << "(cyCreateFromShared=True)\n" << " ret." << shared_pxd_obj_in_pyx() << " = other\n"; pyxInitParentObj(pyxFile, " ret", "other", allClasses); pyxFile.oss << " return ret" << "\n";