[C++-sig] Get parameter info of function or method
Hi, I'm currently generating doc for my live boost.python classes, instances and function. But I can't find any way to retrieve the parameter info of functions and its signature because it has no __code__ attribute due to it's written I C++. Any solution to this? ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] TypeError: No to_python (by-value) converter found for C++ type: class std::basic_ostream >
And I forgot to tell you, the python class in an extension of a c++ class. Hence I have the serialise and deserialise function defined in python. // Simon On 29 sep 2010, at 16.02, Jakub Zytka wrote: On 09/29/10 14:11, Simon W wrote: Thank you for the answer. Is there any way I can prevent it from copying the stream object even though std::ostream::write() returns a std::ostream& ? You can use other return policy, or define one on your own. http://www.boost.org/doc/libs/1_44_0/libs/python/doc/tutorial/doc/html/python/functions.html#python.call_policies But honestly, I do not think it is the correct way to go. Read below. > I'm trying to serialise some data. I have a c++ class: > class ostream > { > ... > could to the c++ way and add a integer before the byte stream that reveal how > big it is. But How can i serialise an int from python that takes up constant > "byte-size" for an integer between lets say 0-1!? Everything can be done, but I have a different question: I haven't followed all your previous emails, but do you *really* need to implement serialization code in python? Somehow I feel it is very weird that on one hand you want to have serialization code in python, and yet use ostream. What would be wrong with coding serialization purely in C++, and then providing appropriate pickle suite to python: struct MyPickleSuite { // ... boost::python::tuple MyPickleSuite::getstate(MyClass & object) { std::ostringstream oStream(ios_base::binary); serialize(oStream, object); return boost::python::make_tuple(oStream.str()); } void MyPickleSuite::setstate(MyClass & object, boost::python::tuple state) { // verify tuple correctness etc. std::string serializedData = extract(state[0]); std::istringstream iStream(serializedData, ios_base::binary); serialize(iStream, object); // NOTE: you can use the same code for serialization and deserialization. stream type should determine actual behavior } } That way you do not have to expose ostream to python at all. In fact if you wanted to switch to another type of stream (imagine that you have a custom stream implementation, which provides eg. type checking) it is cheap. You only change a few functions in your pickle suite, nothing more. Even if you do really need to define serialization in python I see no reason to play with streams. I'd rather had a wrapper which hides underlying implementation (eg. std::streams) and operates on strings. Please reconsider your design. ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Abstract class instances to-python conversion
You could use the reload() function in python 2.7 or imp.reload() in python 3. It takes a module object as argument. // Simon On 1 aug 2011, at 12:00, Valentin Perrelle wrote: > >> All of that sounds sounds. But at what point were you trying to register a >> to-python converter? It sounded like you were trying to do that before >> importing the module, and since a to-python converter is by definition C++, >> I didn't understand how you could do it in a Python script before importing >> the module. > > I'm registering the converter by calling the boost::python::import function > in C++ code. I don't know any other way to do that. > > Now, this give me another error. I'm trying to implement a "reload script" > feature. I thought that all i had to do was to call Py_Finalize, then > Py_Initialize again, and to remove any references i was holding to wrapping > classes. But whenever i'm importing my extension again, i get the runtime > error: > > Assertion failed: slot->m_to_python == 0, file > libs\python\src\converter\registry.cpp, line 212 > > which means my to_python converter have been registered once again. Is there > a way to unregister them ? should i find a to not initialize the extension > again ? > > ___ > Cplusplus-sig mailing list > Cplusplus-sig@python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Abstract class instances to-python conversion
In My program I need to unload modules as well. What I do is remove all references to the particular module and it will be unloaded. Are you using boost python for python 2 or 3? If it's the latter it is safe to use Py_Finalize()! I use it myself! // Simon On 1 aug 2011, at 12:58, Valentin Perrelle wrote: > >> You could use the reload() function in python 2.7 or imp.reload() in python >> 3. It takes a module object as argument. > Thanks. However it wouldn't reset to the initial state in the general case. > All modules needs to be unloaded. I don't know a safe way to it yet. I'm just > sure i want to do it in c++ not in Python. > > I've just found that the call of Py_Finalize with Boost.Python is a known > issue, already discussed on this mailing list and that the manual says not to > call it : > http://www.boost.org/doc/libs/1_47_0/libs/python/doc/tutorial/doc/html/python/embedding.html > > ___ > Cplusplus-sig mailing list > Cplusplus-sig@python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Abstract class instances to-python conversion
You can remove one reference from the sys module: Import sys del sys.modules['mymodule'] In cpp it would be like: import('sys').attr('modules')['mymodule'].del() I can give you my code later. Don't have it here! // Simon On 1 aug 2011, at 13:38, Valentin Perrelle wrote: > Le 01/08/2011 13:19, Simon Warg a écrit : >> In My program I need to unload modules as well. What I do is remove all >> references to the particular module and it will be unloaded. > It seems i didn't achieve to do that. There should be some references i can't > remove, i don't know why yet. > >> >> Are you using boost python for python 2 or 3? If it's the latter it is safe >> to use Py_Finalize()! I use it myself! > I'm using Python 3. But the problem of unregistered converters is still > there. See > http://mail.python.org/pipermail/cplusplus-sig/2009-August/014736.html > > > ___ > Cplusplus-sig mailing list > Cplusplus-sig@python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig