[C++-sig] Re: calling a python-callback-function - switching to python 2.3

Lars Kunert lkunert at mpi-sb.mpg.de
Sun Sep 28 01:09:09 CEST 2003


Hi!

Thanks for pointing me to the pep 311 documents. This patch seem to be the 
solution to problems.
Anyway it also opens up a bunch of new ones.

I have just installed python 2.3.1 (to get the pep 311 stuff) and the 
current boost-cvs-snapshot to get a boost.python version wich works 
together with pyhton 2.3.
Then I tried to recompile my program. I got the following error message:

>In file included from /usr/local/include/python2.3/Python.h:69,
>                from 
/usr/local/include/boost/python/detail/wrap_python.hpp:121,
>                 from 
/usr/local/include/boost/python/detail/prefix.hpp:13,
>                from /usr/local/include/boost/python/args.hpp:9,
>                 from /usr/local/include/boost/python.hpp:12,
>                 from QtApp.h:21,
>                 from Thread.cxx:2:
>/usr/local/include/python2.3/object.h:343: error: parse error before `;' 
token

in the file Python.h line 69 I find the the following code:

>typedef struct _heaptypeobject {
>       /* Note: there's a dependency on the order of these members
>          in slotptr() in typeobject.c . */
>       PyTypeObject type;
>       PyNumberMethods as_number;
>       PyMappingMethods as_mapping;
>       PySequenceMethods as_sequence; /* as_sequence comes after 
as_mapping,
>                                         so that the mapping wins when 
both
>                                         the mapping and the sequence 
define
>                                         a given operator (e.g. 
__getitem__).
>                                         see add_operators() in 
typeobject.c . */
>       PyBufferProcs as_buffer;
>       PyObject *name, *slots;   <---LINE 69
>       /* here are optional user slots, followed by the members. */
>} PyHeapTypeObject;

I have not changed anything else in my code yet. But I think, what I have 
to do, is to wrap the callback into a PyGILState_Ensure/Release pair

>void  QtApp::callback() 
>{
>   PyGILState_STATE state = PyGILState_Ensure();
>    {
>        boost::python::call<void>( _callback );
> 
>    }; PyGILState_Release( state );
>};

I do not feel quite comfortable with this approch for two reasons:
- I have to use a cvs (non-release) library and
- The python IDLE I have to use is linked the application, my Qt-program 
wants to interact with. And I am not sure if the developer of that 
application give me the opportunity to exchange the python version they 
are linking to...

Do you see any other way to call the callback with the facilities python 
2.2 and boost-1.30.2 are offering to me?

I enclose a complete set of files, which are cooked down to the 
essentials...


Thanks for your help,

Lars



-------------- next part --------------
A non-text attachment was scrubbed...
Name: PyApp.h
Type: application/octet-stream
Size: 950 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030928/0e99bacc/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PyApp.cxx
Type: application/octet-stream
Size: 1364 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030928/0e99bacc/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Thread.h
Type: application/octet-stream
Size: 257 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030928/0e99bacc/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Thread.cxx
Type: application/octet-stream
Size: 343 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030928/0e99bacc/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PyApp.pyste
Type: application/octet-stream
Size: 57 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030928/0e99bacc/attachment-0004.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: QtApp.h
Type: application/octet-stream
Size: 1090 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030928/0e99bacc/attachment-0005.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: QtApp.cxx
Type: application/octet-stream
Size: 1101 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030928/0e99bacc/attachment-0006.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Makefile.am
Type: application/octet-stream
Size: 731 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030928/0e99bacc/attachment-0007.obj>


More information about the Cplusplus-sig mailing list