From alain.miniussi at oca.eu Thu Jun 11 09:28:44 2020 From: alain.miniussi at oca.eu (Alain O' Miniussi) Date: Thu, 11 Jun 2020 15:28:44 +0200 (CEST) Subject: [C++-sig] Boost class to represent PyBytesObject ? Message-ID: <194917008.490962.1591882124641.JavaMail.zimbra@oca.eu> Hi, The pickle API has changed between Python 2 and 3, moving from str (represented by the boost::python::str class) to bytes. For serialization purpose, I need to represent the Python's bytes (PyBytesObject in C) type in C++. What would be the the best type to extract to ? Thank ---- Alain Miniussi DSI, P?les Calcul et Genie Log. Observatoire de la C?te d'Azur T?l. : +33492003009 (Mont-Gros) +33483618544 (Sophia Antipolis) +33609650665 From dcirmirakis at gmail.com Wed Jun 24 05:45:58 2020 From: dcirmirakis at gmail.com (Dominik Cirmirakis) Date: Wed, 24 Jun 2020 10:45:58 +0100 Subject: [C++-sig] Boost Python issue with converters - static linking Message-ID: Hi, I have a question regarding the below code. It's an example how to pass a custom class via shared_ptr to embedded python code and it works when boost is dynamically linked. Unfortunately the same code with statically linked boost doesn't work with the following error message: "No to_python (by-value) converter found for C++ type: class boost::shared_ptr". I don't understand why a different linking can affect type recognition of a registered converter. What am I missing? Can anybody help me out? Thanks, Dominik https://stackoverflow.com/questions/8225934/exposing-a-c-class-instance-to-a-python-embedded-interpreter?noredirect=1&lq=1 #include #include #include #include #include namespace bp = boost::python; struct Foo{ ??? Foo(){} ??? Foo(std::string const& s) : m_string(s){} ??? void doSomething() { ??????? std::cout << "Foo:" << m_string << std::endl; ??? } ??? std::string m_string; }; typedef boost::shared_ptr foo_ptr; BOOST_PYTHON_MODULE(hello) { ??? bp::class_("Foo") ??????? .def("doSomething", &Foo::doSomething) ??? ; }; int main(int argc, char **argv) { ??? Py_Initialize(); ??? try { ??????? PyRun_SimpleString( ??????????? "a_foo = None\n" ??????????? "\n" ??????????? "def setup(a_foo_from_cxx):\n" ??????????? "??? print 'setup called with', a_foo_from_cxx\n" ??????????? "??? global a_foo\n" ??????????? "??? a_foo = a_foo_from_cxx\n" ??????????? "\n" ??????????? "def run():\n" ??????????? "??? a_foo.doSomething()\n" ??????????? "\n" ??????????? "print 'main module loaded'\n" ??????? ); ??????? foo_ptr a_cxx_foo = boost::make_shared("c++"); ??????? inithello(); ??????? bp::object main = bp::object(bp::handle<>(bp::borrowed( ??????????? PyImport_AddModule("__main__") ??????? ))); ??????? // pass the reference to a_cxx_foo into python: ??????? bp::object setup_func = main.attr("setup"); ??????? setup_func(a_cxx_foo); ??????? // now run the python 'main' function ??????? bp::object run_func = main.attr("run"); ??????? run_func(); ??? } ??? catch (bp::error_already_set) { ??????? PyErr_Print(); ??? } ??? Py_Finalize(); ??? return 0; }