|
|
@@ -273,6 +273,29 @@ PyObject *Dtool_Raise_ArgTypeError(PyObject *obj, int param, const char *functio
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: Dtool_Raise_AttributeError
|
|
|
+// Description: Raises an AttributeError of the form:
|
|
|
+// 'type' has no attribute 'attr'
|
|
|
+//
|
|
|
+// Always returns NULL so that it can be conveniently
|
|
|
+// used as a return expression for wrapper functions
|
|
|
+// that return a PyObject pointer.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+PyObject *Dtool_Raise_AttributeError(PyObject *obj, const char *attribute) {
|
|
|
+#if PY_MAJOR_VERSION >= 3
|
|
|
+ PyObject *message = PyUnicode_FromFormat(
|
|
|
+#else
|
|
|
+ PyObject *message = PyString_FromFormat(
|
|
|
+#endif
|
|
|
+ "'%.100s' object has no attribute '%.200s'",
|
|
|
+ Py_TYPE(obj)->tp_name, attribute);
|
|
|
+
|
|
|
+ Py_INCREF(PyExc_TypeError);
|
|
|
+ PyErr_Restore(PyExc_TypeError, message, (PyObject *)NULL);
|
|
|
+ return NULL;
|
|
|
+}
|
|
|
+
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: Dtool_Raise_BadArgumentsError
|
|
|
// Description: Raises a TypeError of the form:
|
|
|
@@ -330,6 +353,24 @@ PyObject *Dtool_Return_Bool(bool value) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: Dtool_Return
|
|
|
+// Description: Convenience method that checks for exceptions, and
|
|
|
+// if one occurred, returns NULL, otherwise the given
|
|
|
+// return value. Its reference count is not increased.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+PyObject *_Dtool_Return(PyObject *value) {
|
|
|
+ if (_PyErr_OCCURRED()) {
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+#ifndef NDEBUG
|
|
|
+ if (Notify::ptr()->has_assert_failed()) {
|
|
|
+ return Dtool_Raise_AssertionError();
|
|
|
+ }
|
|
|
+#endif
|
|
|
+ return value;
|
|
|
+}
|
|
|
+
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
// Function : DTool_CreatePyInstanceTyped
|
|
|
//
|