Boost logo

Boost :

From: topdog_at_[hidden]
Date: 2001-10-26 06:35:26


Hi,

I have a really strange problem, I will try to explain it with a small example.

class base
{
public:

        base(void);
        virtual ~base(void);
        
        virtual void doit(void) { printf("doit base!\n"); }
        void b(void) { printf("base!\n"); }
};

class derived : public base
{
public:

        derived(void);
        virtual ~derived(void);
        
        virtual void doit(void) { printf("doit derived!\n"); }
        void call_doit(void) { doit(); }
        
        void d(void) { printf("derived!\n"); }
};

// Create an object representing this extension module.
python::module_builder this_module("Module");

// Create the Python type object for our extension class.
python::class_builder<base> base_class(this_module, "base");
base_class.def(python::constructor<>());
base_class.def(&base::doit, "doit");
base_class.def(&base::b, "b");
        
python::class_builder<derived> derived_class(this_module, "derived");
derived_class.def(python::constructor<>());
// Establish the inheritance relationship between Base and Derived
derived_class.declare_base(base_class);

derived_class.def(&derived::call_doit, "call_doit");
derived_class.def(&derived::d, "d");

                
                
Now a small python test script

a = derived()
a.d()
a.call_doit()
a.doit()
a.b()
                
Should give the output:

derived!
doit derived!
doit derived!
base!

Ok this works perfect. Now I destroy the python interpreter and create a new one.

Py_EndInterpreter(PyThreadState_Get());
Py_NewInterpreter();

This destroys all instances and the destructors are also called correctly.

Now I need do initialize the module again.

initModule();
PyRun_SimpleString("from Module import *");
        

Starting the same script now gives this error:

Traceback(most recent call last):
File "", line 4, in ?
RuntimeError:unidentifiable C++ exception

Line 4 is "a.doit()"

The same error apears in line 5. Looks like he forgot the
inheritance relationship between derived and base?

I also tried Py_Finalize(); Py_Initialize(); but this didn't help.
Any ideas what's going wrong here?

Andreas

________________________________________________________________
Lotto online tippen! Egal zu welcher Zeit, egal von welchem Ort.
Mit dem WEB.DE Lottoservice. http://tippen2.web.de/?x=13


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk