
Hi there! Since I read much documentation, and talked to many people on IRC regarding my Problem, I now post it here, because no one can help me. Here is the Source of my C++ App : #include <boost/python.hpp> #include <iostream> using namespace boost::python; void test() { std::cout << "Hello World!" << std::endl; } BOOST_PYTHON_MODULE(test) { def("test", &test); } int main() { Py_Initialize(); std::cout << "INITIALIZED" << std::endl; init_module_test(); std::cout << "MODULE LOADED" << std::endl; FILE * fp; fp = fopen ("test.py","r"); std::cout << "created fp" << std::endl; PyRun_AnyFile(fp, "test.py"); Py_Finalize(); std::cout << "Called PyRun" << std::endl; fclose(fp); } Running this code results in 'Aborted' on init_module_test() ; here's the GDB Output : GNU gdb 6.3 Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i686-pc-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1". (gdb) run Starting program: /home/spellbreaker/c++/test [Thread debugging using libthread_db enabled] [New Thread 16384 (LWP 13445)] Program received signal SIGABRT, Aborted. [Switching to Thread 16384 (LWP 13445)] 0xb7cc02b1 in kill () from /lib/libc.so.6 (gdb) bt #0 0xb7cc02b1 in kill () from /lib/libc.so.6 #1 0xb7c4d8b8 in pthread_kill () from /lib/libpthread.so.0 #2 0x00003485 in ?? () #3 0x00000006 in ?? () #4 0xb7c52ff4 in ?? () from /lib/libpthread.so.0 #5 0x00000006 in ?? () #6 0xbfffec40 in ?? () #7 0xb7c4dc21 in raise () from /lib/libpthread.so.0 #8 0x00004000 in ?? () #9 0x00000006 in ?? () #10 0xb7da6ff4 in ?? () from /lib/libc.so.6 #11 0xb7cc0052 in raise () from /lib/libc.so.6 #12 0x00000006 in ?? () #13 0xb7da710c in __fpu_control () from /lib/libc.so.6 #14 0xb7da6ff4 in ?? () from /lib/libc.so.6 #15 0x00000000 in ?? () #16 0xb7cc158a in abort () from /lib/libc.so.6 #17 0x00000020 in ?? () #18 0x00000000 in ?? () #19 0x00000000 in ?? () #20 0x00000000 in ?? () #21 0x00000000 in ?? () #22 0x00000000 in ?? () #23 0x00000000 in ?? () #24 0x00000000 in ?? () #25 0x00000000 in ?? () #26 0x00000000 in ?? () #27 0x00000000 in ?? () #28 0x00000000 in ?? () #29 0x00000000 in ?? () #30 0x00000000 in ?? () #31 0x00000000 in ?? () #32 0x00000000 in ?? () #33 0x00000000 in ?? () #34 0x00000000 in ?? () #35 0x00000000 in ?? () #36 0x00000000 in ?? () #37 0x00000000 in ?? () #38 0x00000000 in ?? () #39 0x00000000 in ?? () #40 0x00000000 in ?? () #41 0x00000000 in ?? () #42 0x00000000 in ?? () #43 0x00000000 in ?? () #44 0x00000000 in ?? () #45 0x00000000 in ?? () #46 0x00000000 in ?? () #47 0x00000000 in ?? () #48 0x00000000 in ?? () #49 0x00000000 in ?? () #50 0x00000000 in ?? () #51 0x00000000 in ?? () #52 0x00000000 in ?? () #53 0x00000000 in ?? () #54 0x00000000 in ?? () #55 0x00000000 in ?? () #56 0x09844246 in ?? () #57 0xbfffece0 in ?? () #58 0xb7fce568 in ?? () #59 0x0804a10c in ?? () #60 0x08048f88 in init_module_test () #61 0xb7e780f4 in std::terminate () from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/libstdc++.so.5 #62 0xb7e78296 in __cxa_throw () from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/libstdc++.so.5 #63 0xb7fbdb67 in boost::python::throw_error_already_set () from /usr/lib/libboost_python.so.1.32.0 #64 0xb7fb496b in boost::python::objects::function::add_to_namespace () from /usr/lib/libboost_python.so.1.32.0 #65 0xb7fb4a93 in boost::python::objects::function::add_to_namespace () from /usr/lib/libboost_python.so.1.32.0 #66 0xb7fb4c04 in boost::python::objects::add_to_namespace () from /usr/lib/libboost_python.so.1.32.0 #67 0xb7fbe170 in boost::python::detail::scope_setattr_doc () from /usr/lib/libboost_python.so.1.32.0 #68 0x08049165 in boost::python::def<void (*)()> () #69 0x08048f86 in init_module_test () #70 0x08048fa2 in main () I hope someone can help me to solve this problem, since I don't see what I did wrong. Best regards, Nico Blanke

Nico Blanke <n.blanke@gmx.net> writes:
Hi there!
Since I read much documentation, and talked to many people on IRC regarding my Problem, I now post it here, because no one can help me.
Nico, The best place for Boost.Python questions is the C++-sig: http://www.boost.org/more/mailing_lists.htm#cplussig
Here is the Source of my C++ App :
#include <boost/python.hpp> #include <iostream> using namespace boost::python;
void test() { std::cout << "Hello World!" << std::endl; }
BOOST_PYTHON_MODULE(test) { def("test", &test); }
int main() { Py_Initialize(); std::cout << "INITIALIZED" << std::endl; init_module_test(); std::cout << "MODULE LOADED" << std::endl; FILE * fp; fp = fopen ("test.py","r"); std::cout << "created fp" << std::endl; PyRun_AnyFile(fp, "test.py"); Py_Finalize(); std::cout << "Called PyRun" << std::endl; fclose(fp); }
Running this code results in 'Aborted' on init_module_test() ;
Boost.Python doesn't support Py_Finalize, but that's not your problem. Your problem is that Boost.Python is throwing an exception at you but you have no try/catch block and no way to report it:
here's the GDB Output :
<snip>
#58 0xb7fce568 in ?? () #59 0x0804a10c in ?? () #60 0x08048f88 in init_module_test () #61 0xb7e780f4 in std::terminate () from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/libstdc++.so.5 #62 0xb7e78296 in __cxa_throw () ^^^^^^^^^^^^^^------- here from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/libstdc++.so.5 #63 0xb7fbdb67 in boost::python::throw_error_already_set () from /usr/lib/libboost_python.so.1.32.0 #64 0xb7fb496b in boost::python::objects::function::add_to_namespace () from /usr/lib/libboost_python.so.1.32.0 #65 0xb7fb4a93 in boost::python::objects::function::add_to_namespace () from /usr/lib/libboost_python.so.1.32.0 #66 0xb7fb4c04 in boost::python::objects::add_to_namespace () from /usr/lib/libboost_python.so.1.32.0 #67 0xb7fbe170 in boost::python::detail::scope_setattr_doc () from /usr/lib/libboost_python.so.1.32.0 #68 0x08049165 in boost::python::def<void (*)()> () #69 0x08048f86 in init_module_test () #70 0x08048fa2 in main ()
I hope someone can help me to solve this problem, since I don't see what I did wrong.
Take your example from libs/python/test/embedding.cpp in your Boost distro. There you will find, e.g.: if (python::handle_exception(test)) { if (PyErr_Occurred()) PyErr_Print(); return 1; } If you put all the code in your main function (except the Py_Initialize call; do that first) inside void test() { .... } you'll be able to see what the error is. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
Nico Blanke