[Bf-blender-cvs] [ff2dd59d4a1] master: PyAPI: use _PyObject_LookupAttr

Campbell Barton noreply at git.blender.org
Mon Feb 4 13:49:05 CET 2019


Commit: ff2dd59d4a12a118eda5dc73ad692dae39cd702c
Author: Campbell Barton
Date:   Mon Feb 4 23:35:23 2019 +1100
Branches: master
https://developer.blender.org/rBff2dd59d4a12a118eda5dc73ad692dae39cd702c

PyAPI: use _PyObject_LookupAttr

Unlike PyObject_GetAttr, this avoids setting the attribute error
only to clear it - under some conditions.

===================================================================

M	source/blender/python/intern/bpy_rna.c

===================================================================

diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index e257aa26d33..e8fcb62ba91 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -8253,16 +8253,20 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class
 		return NULL;
 
 	/* call classed register method () */
-	py_cls_meth = PyObject_GetAttr(py_class, bpy_intern_str_register);
-	if (py_cls_meth == NULL) {
-		PyErr_Clear();
-	}
-	else {
-		PyObject *ret = PyObject_CallObject(py_cls_meth, NULL);
-		if (ret) {
-			Py_DECREF(ret);
+	switch (_PyObject_LookupAttr(py_class, bpy_intern_str_register, &py_cls_meth)) {
+		case 1:
+		{
+			PyObject *ret = PyObject_CallObject(py_cls_meth, NULL);
+			if (ret) {
+				Py_DECREF(ret);
+			}
+			else {
+				return NULL;
+			}
+			break;
 		}
-		else {
+		case -1:
+		{
 			return NULL;
 		}
 	}
@@ -8353,16 +8357,20 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla
 	}
 
 	/* call classed unregister method */
-	py_cls_meth = PyObject_GetAttr(py_class, bpy_intern_str_unregister);
-	if (py_cls_meth == NULL) {
-		PyErr_Clear();
-	}
-	else {
-		PyObject *ret = PyObject_CallObject(py_cls_meth, NULL);
-		if (ret) {
-			Py_DECREF(ret);
+	switch (_PyObject_LookupAttr(py_class, bpy_intern_str_unregister, &py_cls_meth)) {
+		case 1:
+		{
+			PyObject *ret = PyObject_CallObject(py_cls_meth, NULL);
+			if (ret) {
+				Py_DECREF(ret);
+			}
+			else {
+				return NULL;
+			}
+			break;
 		}
-		else {
+		case -1:
+		{
 			return NULL;
 		}
 	}



More information about the Bf-blender-cvs mailing list