some question about tp_basicsize

D

Dmitry Belous

Hi, All

I use C++ to create new types(inherited from PyTypeObject)
and objects(inherited from PyObject) and virtual
destructor to destroy objects. sizeof() is different
for different objects and therefore i don't know what i must do
with tp_basicsize.

Will the following source code work?
Must i set tp_basicsize to right size? (Can I use zero
for tp_basicsize?)

static void do_instance_dealloc(PyObject* obj) {
if(obj->ob_type == &mytype_base)
delete static_cast<myobject_base*>(obj);
}

PyTypeObject mytype_base = {
....
0, /*tp_basicsize*/ /*i don't know size of object*/
....
&do_instance_dealloc, /*tp_dealloc*/
....
};

class myobject_base : public PyObject {
public:
myobject_base() : ob_type(mytype_base) {}
virtual ~myobject_base() {}
};

class myobject_specific : public myobject_base {
public:
std::string name;
myobject_specific() : myobject_base() {}
};
 

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
474,219
Messages
2,571,118
Members
47,733
Latest member
BlairMeado

Latest Threads

Top