Missing PyObject definition

Michael Wieher michael.wieher at gmail.com
Mon Mar 17 14:36:22 EDT 2008


2008/3/17, James Whetstone <jameswhetstone at comcast.net>:
>
> Hi,
>
> Yeah, I've included python.h and object.h but the compiler still complain
> about not finding PyObject.  It's weird.    So I'm developing and App on
> windows using VS 8.0.  I've intalled Python 2.5 and have added the include
> directory to my project's configuration.  I'm also using boost.python in
> another application to wrap my C++ classes.
>
> Here's the C++ class I'm wrapping:
>
> class widget
> {
>
> public:
>
>     widget(const string &name,  unsigned int myint) :
>     {
>
>     }
>
>     static unsigned int __stdcall Callback(void * voidPtr);
>     void startMessageHandler();
>    void stopMessageHandler();
>     virtual void handleMessage(void *message)=0;
>
> };
>
> So the idea here is that the Python user will derive from widget and
> override the virtual method "handleMessage".  A thread is spawned by
> "startMessageHandler()" that does some work and periodically calls
> "handleMessage" passing it a chunk of memory.  This memory is intended to
> be
> zero-copy. Okay, so I've implemeted this class to set up the class for
> Python:
>
> class py_widget : public widget
> {
> public:
>     py_widget(PyObject *p, const string &name, unsigned int myint) :
>                      self(p),
>                      py_widget(name, myint)
>   {
>   }
>
>   void handleMessage(void *message);
>
>   PyObject *self;
>
> };
>
> where handleMessage has the following implementation:
>
> void PyAsyncQueue::handleMessage(void *message)
> {
>      //get the memory block size with a method not shown here
>      int size = getSize(message);
>
>     //create a buffer object so the Python users can access memory block
> directly.
>
>      PyObject *obj = PyBuffer_FromReadWriteMemory( message, size ) ;
>
>     //now what ????
>
>      //I've tried calling the method directly based on some info I found
> some documentation, but this doesn't
>     //compile because the compile can't find PyObject.  Also, I really
> know
> what it looks like anyways.
>      //self->attr("handleMessage")(obj);
>
>      //This boost.python call doesn't work either.
>      //call_method<void>(self, "handleMessage", obj);
> }
>
>
> Thanks for your suggestions on this,
> James
>
>
>
> "Jeff Schwab" <jeff at schwabcenter.com> wrote in message
> news:mvadnfg_hOdmDEPanZ2dnUVZ_u2mnZ2d at comcast.com...
> > James Whetstone wrote:
> >> I'm trying to access a PyObject directly from C++ for the purpose of
> >> calling method on a Python object that is an intance of a derived C++
> >> class. My problem is that the compiler is complaining about not
> PyObject
> >> not being defined.  Has anyone run into the problem?  Where is PyObject
> >> defined?
> >
> > Are you using Python's C API?
> >
> > Did you #include "Python.h" before using PyObject?
> >
> > PyObject is a C-style struct defined in object.h, which is in turn
> > included by Python.h.  Does your compiler know where to look for those
> > headers?  If you are getting messages of the form "error: cannot find
> > Python.h," then add -Iyour_python_root/include/python2.5 (or whatever
> > version) to the CXXFLAGS variable in your makefile, or to your
> compiler's
> > command line.
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

If you're using MS-Visual Studio, be sure you really included the file where
you think you did... I ran into some stupidity of my own, trying to put
include files in the "library" path and vice versa.

If you have "Python.h" included properly, you should be able to compile some
small test-code using PyObject.

If you can't, you haven't got it included correctly.  That's where I'd
start.

If there's other bugs in your code, thats a different issue, but if the
compiler can't find class-X defined in file-Y, then you need to double-check
your include, include-path, and so on and so forth.

Also, don't forget that just because the include directory is on your
project's path, that the actual file itself needs to be included.  When
running in VS 6.0 I had to place my includes in some awfully strange
places.  Redundant includes don't hurt.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080317/ae1d1176/attachment-0001.html>


More information about the Python-list mailing list