diff --git a/wrap/Class.cpp b/wrap/Class.cpp index 784e19062..7177fb121 100644 --- a/wrap/Class.cpp +++ b/wrap/Class.cpp @@ -841,29 +841,19 @@ void Class::emit_cython_pyx(FileWriter& file, const std::vector& allClass if (parentClass) file.oss << "(" << parentClass->pyxClassName() << ")"; file.oss << ":\n"; - // shared variable of the corresponding cython object - // file.oss << " cdef " << shared_pxd_class_in_pyx() << " " << shared_pxd_obj_in_pyx() << "\n"; - - // __cinit___ - file.oss << " def __init__(self, *args, **kwargs):\n" - " self." << shared_pxd_obj_in_pyx() << " = " - << shared_pxd_class_in_pyx() << "()\n"; - + // __init___ + file.oss << " def __init__(self, *args, **kwargs):\n"; + file.oss << " cdef list __params\n"; + file.oss << " self." << shared_pxd_obj_in_pyx() << " = " << shared_pxd_class_in_pyx() << "()\n"; file.oss << " if len(args)==0 and len(kwargs)==1 and kwargs.has_key('cyCreateFromShared'):\n return\n"; - for (size_t i = 0; i0) file.oss << "\n"; + file.oss << " if (self." << shared_pxd_obj_in_pyx() << ".use_count()==0):\n"; + file.oss << " raise TypeError('" << pyxClassName() + << " construction failed!')\n"; + pyxInitParentObj(file, " self", "self." + shared_pxd_obj_in_pyx(), allClasses); + file.oss << "\n"; // cyCreateFromShared file.oss << " @staticmethod\n"; diff --git a/wrap/Constructor.cpp b/wrap/Constructor.cpp index 09746bfdb..ecfc42b39 100644 --- a/wrap/Constructor.cpp +++ b/wrap/Constructor.cpp @@ -129,37 +129,31 @@ bool Constructor::hasDefaultConstructor() const { } /* ************************************************************************* */ -void Constructor::emit_cython_pxd(FileWriter& pxdFile, const Class& cls) const { +void Constructor::emit_cython_pxd(FileWriter& file, const Class& cls) const { for (size_t i = 0; i < nrOverloads(); i++) { ArgumentList args = argumentList(i); // generate the constructor - pxdFile.oss << " " << cls.pxdClassName() << "("; - args.emit_cython_pxd(pxdFile, cls.pxdClassName(), cls.templateArgs); - pxdFile.oss << ") " - << "except +\n"; + file.oss << " " << cls.pxdClassName() << "("; + args.emit_cython_pxd(file, cls.pxdClassName(), cls.templateArgs); + file.oss << ") " << "except +\n"; } } /* ************************************************************************* */ -void Constructor::emit_cython_pyx(FileWriter& pyxFile, const Class& cls) const { +void Constructor::emit_cython_pyx(FileWriter& file, const Class& cls) const { for (size_t i = 0; i < nrOverloads(); i++) { ArgumentList args = argumentList(i); - pyxFile.oss - << " def " + cls.pyxClassName() + "_" + to_string(i) - + "(self, args, kwargs):\n"; - pyxFile.oss << " cdef list __params\n"; - pyxFile.oss << " try:\n"; - pyxFile.oss << pyx_resolveOverloadParams(args, true, 3); - pyxFile.oss + file.oss << " try:\n"; + file.oss << pyx_resolveOverloadParams(args, true, 3); + file.oss << argumentList(i).pyx_convertEigenTypeAndStorageOrder(" "); - pyxFile.oss << " self." << cls.shared_pxd_obj_in_pyx() << " = " + file.oss << " self." << cls.shared_pxd_obj_in_pyx() << " = " << cls.shared_pxd_class_in_pyx() << "(new " << cls.pxd_class_in_pyx() << "(" << args.pyx_asParams() << "))\n"; - pyxFile.oss << " return True\n"; - pyxFile.oss << " except:\n"; - pyxFile.oss << " return False\n\n"; + file.oss << " except:\n"; + file.oss << " pass\n"; } } diff --git a/wrap/Module.cpp b/wrap/Module.cpp index 995d7a52b..6477aabc6 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -348,9 +348,10 @@ void Module::emit_cython_pxd(FileWriter& pxdFile) const { " shared_ptr()\n" " shared_ptr(T*)\n" " T* get()\n" + " long use_count() const\n" " T& operator*()\n\n" " cdef shared_ptr[T] dynamic_pointer_cast[T,U](const shared_ptr[U]& r)\n" - " cdef shared_ptr[T] make_shared[T](const T& r)\n"; + " cdef shared_ptr[T] make_shared[T](const T& r)\n\n"; for(const TypedefPair& types: typedefs) types.emit_cython_pxd(pxdFile); diff --git a/wrap/Qualified.h b/wrap/Qualified.h index 03095eb89..899ac3541 100644 --- a/wrap/Qualified.h +++ b/wrap/Qualified.h @@ -237,7 +237,7 @@ public: /// the internal Cython shared obj in a Python class wrappper std::string shared_pxd_obj_in_pyx() const { - return "shared_" + pxdClassName() + "_"; + return pxdClassName() + "_"; } std::string make_shared_pxd_class_in_pyx() const {