Cleanup: remove unnecessary PyErr_Fetch/Restore use in bpy_rna
srna_from_self had logic to replace the exception unless there was already an exception set. This logic isn't needed, except in some disabled code which has been updated. If srna_from_self ran with an exception set it would leak memory in Python 3.12.
This commit is contained in:
@@ -4513,15 +4513,20 @@ static PyObject *pyrna_struct_meta_idprop_getattro(PyObject *cls, PyObject *attr
|
||||
* this is faking internal behavior in a way that's too tricky to maintain well. */
|
||||
# if 0
|
||||
if ((ret == nullptr) /* || BPy_PropDeferred_CheckTypeExact(ret) */) {
|
||||
PyErr_Clear(); /* Clear error from tp_getattro. */
|
||||
StructRNA *srna = srna_from_self(cls, "StructRNA.__getattr__");
|
||||
if (srna) {
|
||||
PropertyRNA *prop = RNA_struct_type_find_property_no_base(srna, PyUnicode_AsUTF8(attr));
|
||||
if (prop) {
|
||||
PyErr_Clear(); /* Clear error from tp_getattro. */
|
||||
PointerRNA tptr = RNA_pointer_create(nullptr, &RNA_Property, prop);
|
||||
ret = pyrna_struct_CreatePyObject(&tptr);
|
||||
}
|
||||
}
|
||||
if (ret == nullptr) {
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"StructRNA.__getattr__: attribute \"%.200s\" not found",
|
||||
PyUnicode_AsUTF8(attr));
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
@@ -7949,7 +7954,6 @@ int pyrna_struct_as_ptr_or_null_parse(PyObject *o, void *p)
|
||||
|
||||
StructRNA *srna_from_self(PyObject *self, const char *error_prefix)
|
||||
{
|
||||
|
||||
if (self == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -7961,19 +7965,8 @@ StructRNA *srna_from_self(PyObject *self, const char *error_prefix)
|
||||
}
|
||||
|
||||
/* These cases above not errors, they just mean the type was not compatible
|
||||
* After this any errors will be raised in the script */
|
||||
|
||||
PyObject *error_type, *error_value, *error_traceback;
|
||||
StructRNA *srna;
|
||||
|
||||
PyErr_Fetch(&error_type, &error_value, &error_traceback);
|
||||
srna = pyrna_struct_as_srna(self, false, error_prefix);
|
||||
|
||||
if (!PyErr_Occurred()) {
|
||||
PyErr_Restore(error_type, error_value, error_traceback);
|
||||
}
|
||||
|
||||
return srna;
|
||||
* After this any errors will be raised in the script. */
|
||||
return pyrna_struct_as_srna(self, false, error_prefix);
|
||||
}
|
||||
|
||||
static int deferred_register_prop(StructRNA *srna, PyObject *key, PyObject *item)
|
||||
|
||||
Reference in New Issue
Block a user