Missing PyObject definition

J

James Whetstone

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?

Thanks!
James
 
D

Diez B. Roggisch

James said:
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?

This is a problem-description pretty far on the vague side, so the answer
can be as vague only: in Python.h, which should be part of your
python-installation.

Better answers can be provided when you give more information - platform,
python-version, source-code, tracebacks...

Diez
 
J

Jeff Schwab

James said:
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.
 
J

James Whetstone

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top