Virtual member functions cause exception in get_derived_class_object

I have a couple of really simple classes: class MyBase { public: int x; virtual int foo(int new_x) { }; // our derived classes may or may not override this function. Coders choice. }; class MyDerived: public MyBase { public: int y; MyDerived() { y = 0; }; int Get(void) { return y; }; void Set(int val) { y = val; }; }; My main goal in life is to create an instance of MyDerived class in C++: MyDerived my_derived = new MyDerived(); and then pass the pointer to a Python script where the Python script can call any of the public member functions. Yes, I am careful to keep the pointer around in the C++ code while the Python script uses it. So I expose the class (this may or may not be the source of my problems, need help): BOOST_PYTHON_MODULE(test) { using namespace boost::python; class_<MyDerived>("MyDerived") .def("Get", &MyDerived::Get) .def("Set", &MyDerived::Set) ; } /* test*/ My impasse is that the virtual function seems to really give Boost hell when Im trying to pass the pointer to the class over to the python script. Heres the code snippet for that. Its the conversion thats just KILLING me. If I comment out the virtual function, everything works perfectly! I can pass the pointer over to my script, it calls the public member functions, and Im happy. HOWEVER, if I put the virtual function back in, the following line of code just EXPLODES! // It crashes and burns in make_ptr_instance.cpp, function get_derived_class_object() boost::python::object my_arg(boost::ref(my_derived)); // pass the pointer over to the script now. int rval = callPython("myTestFunc", "Test String argument from c++", my_arg); Im completely frustrated by this. I need some psychological help! Thanks in advance! Dave

Hi David, First of all, please bring Boost.Python questions to the C++-sig: http://www.boost.org/more/mailing_lists.htm#cplussig "David Rostowsky" <davros1@covad.net> writes:
I have a couple of really simple classes:
class MyBase { public: int x; virtual int foo(int new_x) { }; // our derived classes may or may not override this function. Coders choice. };
class MyDerived: public MyBase { public: int y; MyDerived() { y = 0; }; int Get(void) { return y; }; void Set(int val) { y = val; }; };
My main goal in life is to create an instance of MyDerived class in C++: MyDerived my_derived = new MyDerived();
and then pass the pointer to a Python script where the Python script can call any of the public member functions. Yes, I am careful to keep the pointer around in the C++ code while the Python script uses it. So I expose the class (this may or may not be the source of my problems, need help):
BOOST_PYTHON_MODULE(test) { using namespace boost::python;
class_<MyDerived>("MyDerived") .def("Get", &MyDerived::Get) .def("Set", &MyDerived::Set) ; } /* test*/
My impasse is that the virtual function seems to really give Boost hell when Im trying to pass the pointer to the class over to the python script. Heres the code snippet for that.
Please post a complete, minimal, reproducible example.
Its the conversion thats just KILLING me.
Chill, dude. You're still alive. At least someone's sending email on your behalf ;-)
If I comment out the virtual function, everything works perfectly! I can pass the pointer over to my script, it calls the public member functions, and Im happy. HOWEVER, if I put the virtual function back in, the following line of code
Well you've posted several lines there; can you be specific about which one you're having problems with?
just EXPLODES!
What does "EXPLODES" mean? Do you get a compilation error, a runtime error, or something else?
// It crashes and burns in make_ptr_instance.cpp, function get_derived_class_object() boost::python::object my_arg(boost::ref(my_derived));
// pass the pointer over to the script now. int rval = callPython("myTestFunc", "Test String argument from c++", my_arg);
-- Dave Abrahams Boost Consulting www.boost-consulting.com

Attached are the files in question. Thanks for the direction. Im a newbie to these lists. In my original post I was trying to post the minimal that failed, so hence I wanted to give everything in the follow-up. Ill try to find a happier middle ground for future posts. "David Abrahams" <dave@boost-consulting.com> wrote in message news:uwu4zvpit.fsf@boost-consulting.com...
Hi David,
First of all, please bring Boost.Python questions to the C++-sig: http://www.boost.org/more/mailing_lists.htm#cplussig
"David Rostowsky" <davros1@covad.net> writes:
I have a couple of really simple classes:
class MyBase { public: int x; virtual int foo(int new_x) { }; // our derived classes may or may not override this function. Coders choice. };
class MyDerived: public MyBase { public: int y; MyDerived() { y = 0; }; int Get(void) { return y; }; void Set(int val) { y = val; }; };
My main goal in life is to create an instance of MyDerived class in C++: MyDerived my_derived = new MyDerived();
and then pass the pointer to a Python script where the Python script can call any of the public member functions. Yes, I am careful to keep the pointer around in the C++ code while the Python script uses it. So I expose the class (this may or may not be the source of my problems, need help):
BOOST_PYTHON_MODULE(test) { using namespace boost::python;
class_<MyDerived>("MyDerived") .def("Get", &MyDerived::Get) .def("Set", &MyDerived::Set) ; } /* test*/
My impasse is that the virtual function seems to really give Boost hell when Im trying to pass the pointer to the class over to the python script. Heres the code snippet for that.
Please post a complete, minimal, reproducible example.
Its the conversion thats just KILLING me.
Chill, dude. You're still alive. At least someone's sending email on your behalf ;-)
If I comment out the virtual function, everything works perfectly! I can pass the pointer over to my script, it calls the public member functions, and Im happy. HOWEVER, if I put the virtual function back in, the following line of code
Well you've posted several lines there; can you be specific about which one you're having problems with?
just EXPLODES!
What does "EXPLODES" mean? Do you get a compilation error, a runtime error, or something else?
// It crashes and burns in make_ptr_instance.cpp, function get_derived_class_object() boost::python::object my_arg(boost::ref(my_derived));
// pass the pointer over to the script now. int rval = callPython("myTestFunc", "Test String argument from c++", my_arg);
-- Dave Abrahams Boost Consulting www.boost-consulting.com
_______________________________________________ Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
begin 666 test_script.py M=')Y.@T*(" @("!I;7!O<G0@9W)U;7-H#0H@(" @('!R:6YT(")0>71H;VXZ M($EM<&]R="!354-#145$140A(2$B#0IE>&-E<'0Z#0H@(" @('!R:6YT(")0 M>71H;VXZ($EM<&]R="!&04E,140N+BXB#0H-"B -"B,C(R,C(R,C(R,C(R,C M(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C M(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,-"B,@5&5S="!M;V1U;&4-"B,C M(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C M(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,-"F1E9B!M M>51E<W1&=6YC*&US9RP@8W!P3V)J*3H-"@T*(" @(" C(%1E<W0@=&AE(&]B M:F5C="!E>'!O<V5D(&9R;VT@8RLK("A087-S960@87,@82!F;W)M86P@<&%R M86UE=&5R*0T*(" @(" C(%-H;W<@:61E;G1I9GD@;V8@8W!P3V)J#0H@(" @ M('!R:6YT(")0>71H;VXZ($ED96YT:71Y(&]F(&5X<&]S960@8W!P3V)J.B B M+ T*(" @("!C<'!/8FHN<')I;G10='(H*0T*(" @("!P<FEN= T*#0H@(" @ M(",@4VAO=R!S=&%T92!O9B!C<'!/8FH-"B @(" @<')I;G0@(E!Y=&AO;CH@ M8W!P3V)J+D=E="@I(&]N(&5N=')Y.B(L(&-P<$]B:BY'970H*0T*#0H@(" @ M(",@0VAA;F=E('-T871E(&]F(&]B:F5C= T*(" @("!C<'!/8FHN4V5T*#DI M#0H-"B @(" @(R!3:&]W('-T871E(&]F(&]B:F5C= T*(" @("!P<FEN=" B M4'ET:&]N.B!C<'!/8FHN1V5T*"D@;VX@97AI=" Z(BP@8W!P3V)J+D=E="@I 6#0H-"B @(" @<F5T=7)N(#DY.2 -"@`` ` end begin 666 code2.cpp M#0HO+R!';&]B86P@;6]D=6QE('!O:6YT97(-"F)O;W-T.CIP>71H;VXZ.FAA M;F1L93P^(&UY7VUO9'5L93L-"@T*8VQA<W,@0F%S93$-"GL-"G!U8FQI8SH- M"@EI;G0@>CL-"@E"87-E,2@I('L@>CT@,3L@?3L-"@EV:7)T=6%L('9O:60@ M3VY+97E5<"AU;G-I9VYE9"!S:&]R="!V:7)T=6%L7VME>2D@>R!].PT*#0I] M.PT*#0IC;&%S<R!497-T0R Z('!U8FQI8R!"87-E,0T*>PT*<')O=&5C=&5D M.@T*"6EN="!X.PT*#0IP=6)L:6,Z#0H-"@E497-T0R@I('L@>" ](# [('T[ M#0H)=F]I9"!3970H:6YT('9A;"D@>R!X(#T@=F%L.R!].PT*"6EN="!'970H M=F]I9"D@>R!R971U<FX@>#L@?3L-"B @("!V;VED('!R:6YT4'1R*"D@>R!P M<FEN=&8H(D,K*R @(#H@4'1R/3!X)7 B+"!T:&ES*3L@?0T*?3L-"@T*+R\@ M4'ET:&]N('=R87!P97(@9F]R($UY0VQA<W,-"D)/3U-47U!95$A/3E]-3T15 M3$4H9W)U;7-H*0T*>PT*(" @('5S:6YG(&YA;65S<&%C92!B;V]S=#HZ<'ET M:&]N.PT*#0H@("!O8FIE8W0@=&5S=$-L87-S(#T@8VQA<W-?/%1E<W1#+"!B M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@(&UY7VUO9'5L92 ](&EM<&]R=%]M;V1U;&4H M8V]N<W1?8V%S=#QC:&%R*CXH<V-R:7!T3F%M92YC7W-T<B@I*2D[#0H-"B @ M("!R971U<FX@4W5C8V5S<SL-"GT-"@T*:6YT(&UA:6XH*0T*>PT*:6YT(')V M86P[#0H-"E1E<W1#("H@=&5S=" ](&YE=R!497-T0R@I.PT*8F]O<W0Z.G-H M87)E9%]P='(\5&5S=$,^('1E<W0Q<'1R*'1E<W0I.PT*#0H@(" @:6YT(')E M='8@/2!I;FET4'ET:&]N*")T97-T7W-C<FEP="(I.PT*(" @(&EF*"!R971V M(#T](%-U8V-E<W,@*0T*(" @('L-"@T*"2\J(%1H:7,@:7,@=VAE<F4@22!G M970@=&AE(')U;BUT:6UE(&5X8V5P=&EO;B!I9B!)(&AA=F4@=&AE('9I<G1U M86P@;65M8F5R(&9U;F-T:6]N(&EN($)A<V4Q+B -"@DJ*B!#;VUM96YT(&]U M="!T:&4@=FER='5A;"!M96UB97(@9G5N8W1I;VXL(&%N9"!E=F5R>6]N92!I M<R!H87!P>2$@#0H)*B\@(" @(" @( T*(" @(" @("!O8FIE8W0@87)G,BAT M97-T,7!T<BD[#0H-"B @(" @(" @:6YT(')E='8@/2!C86QL4'ET:&]N*")M M>51E<W1&=6YC(BP@(E1E<W0@4W1R:6YG(&%R9W5M96YT(&9R;VT@8RLK(BP@ M87)G,BD[#0H-"B @("!]#0H-"B @("!R971U<FX@,#L-"@T*?2 O*B!M86EN %("HO#0H` ` end

"David Rostowsky" <drostowsky@radioframenetworks.com> writes:
Attached are the files in question. Thanks for the direction. Im a newbie to these lists. In my original post I was trying to post the minimal that failed, so hence I wanted to give everything in the follow-up. Ill try to find a happier middle ground for future posts.
Can you try to answer the other questions I asked in my reply? -- Dave Abrahams Boost Consulting www.boost-consulting.com

Please see my replies on the C++-sig. Cheers! -- Dave Abrahams Boost Consulting www.boost-consulting.com

I figured out my problem now that I saw the code works in your environment. That clued me right off the bat that if it works in your environment and not mine, that my compiler options arent set up to make Python/Boost happy. I was using the default options for a Console App in VS7.Net. Well, the default option entails disabling RTTI. Once I turned RTTI on, everything worked perfect! Thanks for your help! Boost and Python rule! Dave "David Abrahams" <dave@boost-consulting.com> wrote in message news:u65cjqun1.fsf@boost-consulting.com...
Please see my replies on the C++-sig.
Cheers! -- Dave Abrahams Boost Consulting www.boost-consulting.com
_______________________________________________ Unsubscribe & other changes:

"David Rostowsky" <drostowsky@radioframenetworks.com> writes:
Attached are the files in question. Thanks for the direction. Im a newbie to these lists. In my original post I was trying to post the minimal that failed, so hence I wanted to give everything in the follow-up. Ill try to find a happier middle ground for future posts.
Can you try to answer the other questions I asked in my reply? -- Dave Abrahams Boost Consulting www.boost-consulting.com

David Rostowsky wrote:
virtual int foo(int new_x) { };
Maybe not related, but the implementation misses "return ...;". Regards, Daniel -- Daniel Frey aixigo AG - financial solutions & technology Schloß-Rahe-Straße 15, 52072 Aachen, Germany fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99 eMail: daniel.frey@aixigo.de, web: http://www.aixigo.de

Thanks for the feedback! Yes I am glad someone is posting me message! :) Heres my full.cpp file that will hopefully shed some light on my Boost bumbling. Below that is my python script too. I was just typing the code snippets from memory and I noticed I misled on my virtual function return value. In fact, its a void return value. It does throw a runtime exception. Ive commented the line of code in main() where it throws the exception. Thanks for all the help! If I can get these passing C++ pointers to Python issues hammered out, Ill forever proclaim Boost's greatness, and Ill never look at Lua (or Perl) again ;) -Dave #include <windows.h> #include <iostream> #include <string> #include <cstdio> #include <conio.h> #undef _DEBUG // just forcing the non-debug library by doing this #include <Python.h> #define _DEBUG // just forcing the non-debug library by doing this #include <boost/python/class.hpp> #include <boost/python/def.hpp> #include <boost/python/str.hpp> #include <boost/python/extract.hpp> #include <boost/python/module.hpp> #include <boost/python/call_method.hpp> #include <boost/python/handle.hpp> #include <boost/python.hpp> using namespace boost::python; // Error codes #define Success 0 #define PY_InitError -100 #define PY_ConvertError -101 #define PY_CallError -102 // Global module pointer boost::python::handle<> my_module; //////////////////////////////////////////////////////////////////////////// ////////// //////////////////////////////////////////////////////////////////////////// ////////// class Base1 { public: int z; Base1() { z= 1; }; /* ** I dont want Python to even care about this function! My other C++ code classes may (or may not) ** override this function. No Python script should ever override this. The default behavior is ** to do nothing. I figured if I dont expose it to the BOOST_PYTHON_MODULE, why would it need ** to care about this function? Again, if I comment this out, everything works perfectly. Otherwise, ** I get a runtime exception about non_rtti_object. */ virtual void OnKeyUp(unsigned short virtual_key) { }; }; //////////////////////////////////////////////////////////////////////////// ////////// //////////////////////////////////////////////////////////////////////////// ////////// class TestC : public Base1 { protected: int x; public: TestC() { x = 0; }; void Set(int val) { x = val; }; int Get(void) { return x; }; void printPtr() { printf("C++ : Ptr=0x%p", this); } }; //////////////////////////////////////////////////////////////////////////// ////////// // Python wrapper for TestC //////////////////////////////////////////////////////////////////////////// ////////// BOOST_PYTHON_MODULE(grumsh) { using namespace boost::python; object testClass = class_<TestC, boost::shared_ptr<TestC> >( "TestC", init<>()) .def("Get", &TestC::Get) .def("Set", &TestC::Set) .def("printPtr", &TestC::printPtr) ; } /* grumsh */ //////////////////////////////////////////////////////////////////////////// ////////// // Function prototypes //////////////////////////////////////////////////////////////////////////// ////////// int initPython(std::string scriptName); int callPython(std::string func, std::string msg, boost::python::object& obj); //////////////////////////////////////////////////////////////////////////// ////////// // Convenience functions //////////////////////////////////////////////////////////////////////////// ////////// boost::python::handle<> import_module(std::string module_name) { using namespace boost::python; PyObject *module_ptr = PyImport_ImportModule(const_cast<char*>(module_name.c_str())); if (module_ptr == NULL) { OutputDebugString("import_module, NULL\n"); exit(1); } return handle<>(module_ptr); } /* import_module */ //////////////////////////////////////////////////////////////////////////// ////////// //////////////////////////////////////////////////////////////////////////// ////////// boost::python::object get_function(const char * func_name) { // Borrowed reference PyObject * dict = PyModule_GetDict(my_module.get()); boost::python::str funcName(func_name); return boost::python::object(boost::python::handle<>(PyDict_GetItem(dict, funcName.ptr()))); } /* get_function */ //////////////////////////////////////////////////////////////////////////// ////////// // Call a function in module (ptrPyModule) with two arguments // func: Name of python function // msg: Message string // obj: Boost.Python object (an instance of a wrapped class) //////////////////////////////////////////////////////////////////////////// ////////// int callPython(const std::string funcStr, std::string msg, boost::python::object& obj) { int rval; boost::python::object func = get_function(const_cast<char*>(funcStr.c_str())); rval = boost::python::extract<int>(func(msg, obj)); return rval; } /* callPython */ //////////////////////////////////////////////////////////////////////////// ////////// // Initialize Python interpreter // Initialize Extension module that expose C++ classes/objects to Python script // Set up sys.path to include script path (Where the python scripts can be found) //////////////////////////////////////////////////////////////////////////// ////////// int initPython(std::string scriptName) { if(scriptName.length() == 0) return PY_InitError; // Register the extension module PyImport_AppendInittab("grumsh", initgrumsh); // Initialize the Python interpreter Py_Initialize(); PySys_SetPath(strcat(Py_GetPath(), ";.\\scripts\\;\\code\\cpp\\python\\scripts\\")); char * oldpath = Py_GetPath(); // Import the module, storing the pointer in a handle<> my_module = import_module(const_cast<char*>(scriptName.c_str())); return Success; } int main() { int rval; /* Create a new Test class instance. */ TestC * test = new TestC(); /* ** Try any way to wrap it such that I can pass a pointer to my Python script so it can call ** my exposed member functions. */ boost::shared_ptr<TestC> test1ptr(test); std::cout << "C++ : Initializing Python and loading script" << std::endl; int retv = initPython("test_script"); if( retv == Success ) { test1ptr->printPtr(); std::cout << std::endl; std::cout << "C++ : test1ptr->Get() in C++ before Python call: " << test1ptr->Get() << std::endl; /* ** This is where I get a RUNTIME exception (non_rtti_object). If I comment out the virtual ** member function out of the class Base1, this works perfectly! */ object arg2(test1ptr); /* This works great too as long as I dont have the virtual member function. */ int retv = callPython("myTestFunc", "Test String argument from c++", arg2); std::cout << "C++ : callPython() returned: " << retv << std::endl; std::cout << "C++ : test1ptr->Get() after Python call: " << test1ptr->Get() << std::endl; std::cout << "C++ : Press any key to quit" << std::endl; getch(); } return 0; } /* main */ Ok, and heres the full test_script.py file: ========================== try: import grumsh print "Python: Import SUCCEEDED!!!" except: print "Python: Import FAILED..." ############################################################################ ######### ############################################################################ ######### def my_test(ptr): return 0; ############################################################################ ######### # Test module # Illustrate both instatiation and use of already instantiated C++ objects ############################################################################ ######### def myTestFunc(msg, cppObj): # Print message from C++ print "Python: msg = ", msg # Instantiate a MyClass object a = grumsh.TestC() # Show identity print "Python: Identity of 'local' MyClass object: ", a.printPtr() print # Change state of object print "Python: Current state:", a.Get() a.Set(1234) print "Python: New state :", a.Get() # Delete object del a # Test the object exposed from c++ (Passed as a formal parameter) # Show identify of cppObj print "Python: Identity of exposed cppObj: ", cppObj.printPtr() print # Show state of cppObj print "Python: cppObj.Get() on entry:", cppObj.Get() # Change state of object cppObj.Set(9) # Show state of object print "Python: cppObj.Get() on exit :", cppObj.Get() return 999

"David Rostowsky" <drostowsky@radioframenetworks.com> writes:
Thanks for the feedback! Yes I am glad someone is posting me message! :) Heres my full.cpp file that will hopefully shed some light on my Boost bumbling. Below that is my python script too.
I was just typing the code snippets from memory and I noticed I misled on my virtual function return value. In fact, its a void return value.
It does throw a runtime exception. Ive commented the line of code in main() where it throws the exception.
I think we can help you eventually, but: 1. Please post to the appropriate list: http://www.boost.org/more/mailing_lists.htm#cplussig 2. Please reduce your code to a *minimal* example that fails. I'm sure you'll find your error that way, but if perchance you don't, at least we'll stand a chance of figuring out the problem. 3. Please post your example as an attachment so that line wrapping doesn't make it syntactically invalid. Thanks, -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (4)
-
Daniel Frey
-
David Abrahams
-
David Rostowsky
-
David Rostowsky