mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 18:31:55 -04:00
fix leaks, parameter checking in interrogate
This commit is contained in:
parent
9cf428352d
commit
59ceb897ed
@ -82,7 +82,6 @@ InterfaceMaker::Object::
|
|||||||
Object(const InterrogateType &itype) :
|
Object(const InterrogateType &itype) :
|
||||||
_itype(itype)
|
_itype(itype)
|
||||||
{
|
{
|
||||||
_destructor = (Function *)NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -161,13 +160,11 @@ generate_wrappers() {
|
|||||||
// printf(" New Type %d\n",ti);
|
// printf(" New Type %d\n",ti);
|
||||||
}
|
}
|
||||||
|
|
||||||
int gi = 0;
|
int num_global_elements = idb->get_num_global_elements();
|
||||||
while( gi = idb->get_num_global_elements())
|
for (int gi = 0; gi < num_global_elements; ++gi) {
|
||||||
{
|
|
||||||
printf(" Global Type = %d",gi);
|
printf(" Global Type = %d",gi);
|
||||||
TypeIndex type_index = idb->get_global_element(gi);
|
TypeIndex type_index = idb->get_global_element(gi);
|
||||||
record_object(type_index);
|
record_object(type_index);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int num_functions = idb->get_num_global_functions();
|
int num_functions = idb->get_num_global_functions();
|
||||||
@ -610,18 +607,11 @@ record_object(TypeIndex type_index) {
|
|||||||
|
|
||||||
Function *function;
|
Function *function;
|
||||||
|
|
||||||
int num_constructors = itype.number_of_constructors();
|
int num_constructors = itype.number_of_constructors();
|
||||||
for (int ci = 0; ci < num_constructors; ci++)
|
for (int ci = 0; ci < num_constructors; ci++) {
|
||||||
{
|
function = record_function(itype, itype.get_constructor(ci));
|
||||||
function = record_function(itype, itype.get_constructor(ci));
|
object->_constructors.push_back(function);
|
||||||
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_methods = itype.number_of_methods();
|
int num_methods = itype.number_of_methods();
|
||||||
int mi;
|
int mi;
|
||||||
|
@ -99,7 +99,6 @@ public:
|
|||||||
const InterrogateType &_itype;
|
const InterrogateType &_itype;
|
||||||
Functions _constructors;
|
Functions _constructors;
|
||||||
Functions _methods;
|
Functions _methods;
|
||||||
Function *_destructor;
|
|
||||||
};
|
};
|
||||||
typedef map<TypeIndex, Object *> Objects;
|
typedef map<TypeIndex, Object *> Objects;
|
||||||
Objects _objects;
|
Objects _objects;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -59,20 +59,47 @@ void DTOOL_Call_ExtractThisPointerForType(PyObject *self, Dtool_PyTypedObject *
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void * DTOOL_Call_GetPointerThisClass(PyObject *self, Dtool_PyTypedObject *classdef)
|
void *
|
||||||
{
|
DTOOL_Call_GetPointerThisClass(PyObject *self, Dtool_PyTypedObject *classdef) {
|
||||||
if(self != NULL)
|
return DTOOL_Call_GetPointerThisClass(self, classdef, 0, "unknown");
|
||||||
{
|
}
|
||||||
if(DtoolCanThisBeAPandaInstance(self))
|
|
||||||
return ((Dtool_PyInstDef *)self)->_My_Type->_Dtool_UpcastInterface(self,classdef);
|
void *
|
||||||
else
|
DTOOL_Call_GetPointerThisClass(PyObject *self, Dtool_PyTypedObject *classdef,
|
||||||
PyErr_SetString(PyExc_TypeError, "Failed Dtool Type Check ..");
|
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;
|
return NULL;
|
||||||
};
|
}
|
||||||
|
|
||||||
void * DTOOL_Call_GetPointerThis(PyObject *self)
|
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_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)
|
if(self != NULL)
|
||||||
{
|
{
|
||||||
self->_ptr_to_object = local_this;
|
self->_ptr_to_object = local_this;
|
||||||
|
@ -251,10 +251,23 @@ PyObject *Dtool_new_##CLASS_NAME(PyTypeObject *type, PyObject *args, PyObject *k
|
|||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
/// Delete functions..
|
/// Delete functions..
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
#ifdef NDEBUG
|
||||||
#define Define_Dtool_FreeInstance_Private(CLASS_NAME,CNAME)\
|
#define Define_Dtool_FreeInstance_Private(CLASS_NAME,CNAME)\
|
||||||
static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self)\
|
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)\
|
#define Define_Dtool_FreeInstance(CLASS_NAME,CNAME)\
|
||||||
static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self)\
|
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);\
|
delete ((CNAME *)((Dtool_PyInstDef *)self)->_ptr_to_object);\
|
||||||
}\
|
}\
|
||||||
}\
|
}
|
||||||
|
|
||||||
#define Define_Dtool_FreeInstanceRef(CLASS_NAME,CNAME)\
|
#define Define_Dtool_FreeInstanceRef(CLASS_NAME,CNAME)\
|
||||||
static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self)\
|
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);\
|
unref_delete((CNAME *)((Dtool_PyInstDef *)self)->_ptr_to_object);\
|
||||||
}\
|
}\
|
||||||
}\
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
/// Simple Recognition Functions..
|
/// 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);
|
||||||
|
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);
|
EXPCL_DTOOLCONFIG void * DTOOL_Call_GetPointerThis(PyObject *self);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user