Problem in Accessing C++ Class Instance Global Variable (near success, help please!!)

Martin v. Löwis martin at v.loewis.de
Fri Apr 18 04:56:45 EDT 2003


alanpong at hkstar.com (Alan Pong) writes:

> I has one global c++ class instance variable.  I want to call its
> member
> function through wrapper function which is accessed by python.
> However, as seen in wrapper.cpp, it give me another new variable copy
> so that phython actually accessing another instance.
> 
> Does anybody has idea to fix it?

No, but I have an idea how to further investigate.

>From the code you have shown, it appears that getInstance is not used
at all. So I recommend to delete the functions

> extern "C" CTest * getInstance()
> {
> 	return >est;  //***Question is here: a new variable!!! why?***
> }

This one: it isn't used, so your question should be irrelevant.

> static PyObject *
> import_getInstance( PyObject *self, PyObject *args )
> {
>   char *obj = getInstance();
>   return Py_BuildValue("i", obj);
> }

and this one. It uses above function, but, in turn, isn't used,
either. So your program should continue to work without visible
changes if you remove those functions.

If that isn't the case, you have concealed some detail from us that
might be important in understanding the mystery.

Regards,
Martin




More information about the Python-list mailing list