Missing PyObject definition

James Whetstone jameswhetstone at comcast.net
Mon Mar 17 17:40:36 CET 2008


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. 





More information about the Python-list mailing list