fix leaks, parameter checking in interrogate

This commit is contained in:
David Rose 2005-09-09 16:26:52 +00:00
parent 9cf428352d
commit 59ceb897ed
5 changed files with 468 additions and 447 deletions

View File

@ -82,7 +82,6 @@ InterfaceMaker::Object::
Object(const InterrogateType &itype) :
_itype(itype)
{
_destructor = (Function *)NULL;
}
////////////////////////////////////////////////////////////////////
@ -161,13 +160,11 @@ generate_wrappers() {
// printf(" New Type %d\n",ti);
}
int gi = 0;
while( gi = idb->get_num_global_elements())
{
int num_global_elements = idb->get_num_global_elements();
for (int gi = 0; gi < num_global_elements; ++gi) {
printf(" Global Type = %d",gi);
TypeIndex type_index = idb->get_global_element(gi);
record_object(type_index);
}
int num_functions = idb->get_num_global_functions();
@ -610,18 +607,11 @@ record_object(TypeIndex type_index) {
Function *function;
int num_constructors = itype.number_of_constructors();
for (int ci = 0; ci < num_constructors; ci++)
{
function = record_function(itype, itype.get_constructor(ci));
object->_constructors.push_back(function);
}
if (itype.has_destructor() && !itype.destructor_is_inherited())
{
function = record_function(itype, itype.get_destructor());
object->_destructor = function;
}
int num_constructors = itype.number_of_constructors();
for (int ci = 0; ci < num_constructors; ci++) {
function = record_function(itype, itype.get_constructor(ci));
object->_constructors.push_back(function);
}
int num_methods = itype.number_of_methods();
int mi;

View File

@ -99,7 +99,6 @@ public:
const InterrogateType &_itype;
Functions _constructors;
Functions _methods;
Function *_destructor;
};
typedef map<TypeIndex, Object *> Objects;
Objects _objects;

File diff suppressed because it is too large Load Diff

View File

@ -59,20 +59,47 @@ void DTOOL_Call_ExtractThisPointerForType(PyObject *self, Dtool_PyTypedObject *
};
void * DTOOL_Call_GetPointerThisClass(PyObject *self, Dtool_PyTypedObject *classdef)
{
if(self != NULL)
{
if(DtoolCanThisBeAPandaInstance(self))
return ((Dtool_PyInstDef *)self)->_My_Type->_Dtool_UpcastInterface(self,classdef);
else
PyErr_SetString(PyExc_TypeError, "Failed Dtool Type Check ..");
void *
DTOOL_Call_GetPointerThisClass(PyObject *self, Dtool_PyTypedObject *classdef) {
return DTOOL_Call_GetPointerThisClass(self, classdef, 0, "unknown");
}
void *
DTOOL_Call_GetPointerThisClass(PyObject *self, Dtool_PyTypedObject *classdef,
int param, const string &function_name) {
if (self != NULL) {
if (DtoolCanThisBeAPandaInstance(self)) {
Dtool_PyTypedObject *my_type = ((Dtool_PyInstDef *)self)->_My_Type;
void *result = my_type->_Dtool_UpcastInterface(self, classdef);
if (result != NULL) {
return result;
}
ostringstream str;
str << function_name << "() argument " << param << " must be "
<< classdef->_name << ", not " << my_type->_name;
string msg = str.str();
PyErr_SetString(PyExc_TypeError, msg.c_str());
} else {
ostringstream str;
str << function_name << "() argument " << param << " must be "
<< classdef->_name;
PyObject *tname = PyObject_GetAttrString((PyObject *)self->ob_type, "__name__");
if (tname != (PyObject *)NULL) {
str << ", not " << PyString_AsString(tname);
Py_DECREF(tname);
}
string msg = str.str();
PyErr_SetString(PyExc_TypeError, msg.c_str());
}
} else {
PyErr_SetString(PyExc_TypeError, "Self Is Null");
}
else
PyErr_SetString(PyExc_TypeError, "Self Is Null");
return NULL;
};
}
void * DTOOL_Call_GetPointerThis(PyObject *self)
{
@ -163,7 +190,7 @@ PyObject * DTool_CreatePyInstance(void * local_this, Dtool_PyTypedObject & in_cl
}
Dtool_PyTypedObject * classdef = &in_classdef;
Dtool_PyInstDef * self = (Dtool_PyInstDef *) classdef->As_PyTypeObject().tp_new(&classdef->As_PyTypeObject(), NULL,NULL);
Dtool_PyInstDef * self = (Dtool_PyInstDef *) classdef->As_PyTypeObject().tp_new(&classdef->As_PyTypeObject(), NULL,NULL);
if(self != NULL)
{
self->_ptr_to_object = local_this;

View File

@ -251,10 +251,23 @@ PyObject *Dtool_new_##CLASS_NAME(PyTypeObject *type, PyObject *args, PyObject *k
////////////////////////////////////////////////////////////////////////
/// Delete functions..
////////////////////////////////////////////////////////////////////////
#ifdef NDEBUG
#define Define_Dtool_FreeInstance_Private(CLASS_NAME,CNAME)\
static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self)\
{\
}\
}
#else // NDEBUG
#define Define_Dtool_FreeInstance_Private(CLASS_NAME,CNAME)\
static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self)\
{\
if(((Dtool_PyInstDef *)self)->_ptr_to_object != NULL)\
if(((Dtool_PyInstDef *)self)->_memory_rules)\
{\
cerr << "Detected leak for " << #CLASS_NAME \
<< " which interrogate cannot delete.\n"; \
}\
}
#endif // NDEBUG
#define Define_Dtool_FreeInstance(CLASS_NAME,CNAME)\
static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self)\
@ -264,7 +277,7 @@ static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self)\
{\
delete ((CNAME *)((Dtool_PyInstDef *)self)->_ptr_to_object);\
}\
}\
}
#define Define_Dtool_FreeInstanceRef(CLASS_NAME,CNAME)\
static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self)\
@ -274,7 +287,7 @@ static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self)\
{\
unref_delete((CNAME *)((Dtool_PyInstDef *)self)->_ptr_to_object);\
}\
}\
}
////////////////////////////////////////////////////////////////////////
/// Simple Recognition Functions..
@ -292,6 +305,7 @@ EXPCL_DTOOLCONFIG void DTOOL_Call_ExtractThisPointerForType(PyObject *self, Dtoo
EXPCL_DTOOLCONFIG void * DTOOL_Call_GetPointerThisClass(PyObject *self, Dtool_PyTypedObject *classdef);
EXPCL_DTOOLCONFIG void * DTOOL_Call_GetPointerThisClass(PyObject *self, Dtool_PyTypedObject *classdef, int param, const string &function_name);
EXPCL_DTOOLCONFIG void * DTOOL_Call_GetPointerThis(PyObject *self);