|
@@ -94,10 +94,24 @@ attempt_coercion(PyObject *self, Dtool_PyTypedObject *classdef,
|
|
|
// temporary object. Weird.
|
|
// temporary object. Weird.
|
|
|
Py_DECREF(obj);
|
|
Py_DECREF(obj);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // Clear the error returned by the coercion constructor. It's not
|
|
|
|
|
+ // the error message we want to report.
|
|
|
|
|
+ PyErr_Clear();
|
|
|
}
|
|
}
|
|
|
return NULL;
|
|
return NULL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// Temporary function to preserve backward compatibility.
|
|
|
|
|
+void *
|
|
|
|
|
+DTOOL_Call_GetPointerThisClass(PyObject *self, Dtool_PyTypedObject *classdef,
|
|
|
|
|
+ int param, const string &function_name, bool const_ok,
|
|
|
|
|
+ PyObject **coerced) {
|
|
|
|
|
+ return DTOOL_Call_GetPointerThisClass(self, classdef,
|
|
|
|
|
+ param, function_name, const_ok,
|
|
|
|
|
+ coerced, true);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: DTOOL_Call_GetPointerThisClass
|
|
// Function: DTOOL_Call_GetPointerThisClass
|
|
|
// Description: Extracts the C++ pointer for an object, given its
|
|
// Description: Extracts the C++ pointer for an object, given its
|
|
@@ -140,7 +154,10 @@ attempt_coercion(PyObject *self, Dtool_PyTypedObject *classdef,
|
|
|
void *
|
|
void *
|
|
|
DTOOL_Call_GetPointerThisClass(PyObject *self, Dtool_PyTypedObject *classdef,
|
|
DTOOL_Call_GetPointerThisClass(PyObject *self, Dtool_PyTypedObject *classdef,
|
|
|
int param, const string &function_name, bool const_ok,
|
|
int param, const string &function_name, bool const_ok,
|
|
|
- PyObject **coerced) {
|
|
|
|
|
|
|
+ PyObject **coerced, bool report_errors) {
|
|
|
|
|
+ if (PyErr_Occurred()) {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
if (self != NULL) {
|
|
if (self != NULL) {
|
|
|
if (DtoolCanThisBeAPandaInstance(self)) {
|
|
if (DtoolCanThisBeAPandaInstance(self)) {
|
|
|
Dtool_PyTypedObject *my_type = ((Dtool_PyInstDef *)self)->_My_Type;
|
|
Dtool_PyTypedObject *my_type = ((Dtool_PyInstDef *)self)->_My_Type;
|
|
@@ -150,16 +167,53 @@ DTOOL_Call_GetPointerThisClass(PyObject *self, Dtool_PyTypedObject *classdef,
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ostringstream str;
|
|
|
|
|
- str << function_name << "() argument " << param << " may not be const";
|
|
|
|
|
- string msg = str.str();
|
|
|
|
|
- PyErr_SetString(PyExc_TypeError, msg.c_str());
|
|
|
|
|
|
|
+ if (report_errors) {
|
|
|
|
|
+ ostringstream str;
|
|
|
|
|
+ str << function_name << "() argument " << param << " may not be const";
|
|
|
|
|
+ string msg = str.str();
|
|
|
|
|
+ PyErr_SetString(PyExc_TypeError, msg.c_str());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
- ostringstream str;
|
|
|
|
|
- str << function_name << "() argument " << param << " must be ";
|
|
|
|
|
|
|
+ if (report_errors) {
|
|
|
|
|
+ ostringstream str;
|
|
|
|
|
+ str << function_name << "() argument " << param << " must be ";
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ PyObject *fname = PyObject_GetAttrString((PyObject *)classdef, "__name__");
|
|
|
|
|
+ if (fname != (PyObject *)NULL) {
|
|
|
|
|
+ str << PyString_AsString(fname);
|
|
|
|
|
+ Py_DECREF(fname);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ str << classdef->_name;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ PyObject *tname = PyObject_GetAttrString((PyObject *)self->ob_type, "__name__");
|
|
|
|
|
+ if (tname != (PyObject *)NULL) {
|
|
|
|
|
+ str << ", not " << PyString_AsString(tname);
|
|
|
|
|
+ Py_DECREF(tname);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ str << ", not " << my_type->_name;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ string msg = str.str();
|
|
|
|
|
+ PyErr_SetString(PyExc_TypeError, msg.c_str());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // The parameter was not a Panda type. Can we coerce it to the
|
|
|
|
|
+ // appropriate type, by creating a temporary object?
|
|
|
|
|
+ void *result = attempt_coercion(self, classdef, coerced);
|
|
|
|
|
+ if (result != NULL) {
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ // Coercion failed.
|
|
|
|
|
+ if (report_errors) {
|
|
|
|
|
+ ostringstream str;
|
|
|
|
|
+ str << function_name << "() argument " << param << " must be ";
|
|
|
|
|
+
|
|
|
PyObject *fname = PyObject_GetAttrString((PyObject *)classdef, "__name__");
|
|
PyObject *fname = PyObject_GetAttrString((PyObject *)classdef, "__name__");
|
|
|
if (fname != (PyObject *)NULL) {
|
|
if (fname != (PyObject *)NULL) {
|
|
|
str << PyString_AsString(fname);
|
|
str << PyString_AsString(fname);
|
|
@@ -167,50 +221,21 @@ DTOOL_Call_GetPointerThisClass(PyObject *self, Dtool_PyTypedObject *classdef,
|
|
|
} else {
|
|
} else {
|
|
|
str << classdef->_name;
|
|
str << classdef->_name;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
PyObject *tname = PyObject_GetAttrString((PyObject *)self->ob_type, "__name__");
|
|
PyObject *tname = PyObject_GetAttrString((PyObject *)self->ob_type, "__name__");
|
|
|
if (tname != (PyObject *)NULL) {
|
|
if (tname != (PyObject *)NULL) {
|
|
|
str << ", not " << PyString_AsString(tname);
|
|
str << ", not " << PyString_AsString(tname);
|
|
|
Py_DECREF(tname);
|
|
Py_DECREF(tname);
|
|
|
- } else {
|
|
|
|
|
- str << ", not " << my_type->_name;
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
string msg = str.str();
|
|
string msg = str.str();
|
|
|
PyErr_SetString(PyExc_TypeError, msg.c_str());
|
|
PyErr_SetString(PyExc_TypeError, msg.c_str());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- // The parameter was not a Panda type. Can we coerce it to the
|
|
|
|
|
- // appropriate type, by creating a temporary object?
|
|
|
|
|
- void *result = attempt_coercion(self, classdef, coerced);
|
|
|
|
|
- if (result != NULL) {
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Coercion failed.
|
|
|
|
|
- ostringstream str;
|
|
|
|
|
- str << function_name << "() argument " << param << " must be ";
|
|
|
|
|
-
|
|
|
|
|
- PyObject *fname = PyObject_GetAttrString((PyObject *)classdef, "__name__");
|
|
|
|
|
- if (fname != (PyObject *)NULL) {
|
|
|
|
|
- str << PyString_AsString(fname);
|
|
|
|
|
- Py_DECREF(fname);
|
|
|
|
|
- } else {
|
|
|
|
|
- str << 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 {
|
|
} else {
|
|
|
- PyErr_SetString(PyExc_TypeError, "Self Is Null");
|
|
|
|
|
|
|
+ if (report_errors) {
|
|
|
|
|
+ PyErr_SetString(PyExc_TypeError, "Self Is Null");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
return NULL;
|