From bbf073c4edfcbf199961af7a76e286544379eaad Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 3 Aug 2023 19:58:30 +1000 Subject: [PATCH] Cleanup: use POINTER_FROM_INT for PyGetSetDef definitions This makes it clear '(void *)0' represents a zero index instead of a value that's typically nullptr when ignored. --- .../python/mathutils/mathutils_Color.cc | 26 ++++++++++++++----- .../python/mathutils/mathutils_Euler.cc | 8 +++--- .../python/mathutils/mathutils_Quaternion.cc | 8 +++--- .../python/mathutils/mathutils_Vector.cc | 24 ++++++++++++++--- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/source/blender/python/mathutils/mathutils_Color.cc b/source/blender/python/mathutils/mathutils_Color.cc index ace03d82536..e313893e105 100644 --- a/source/blender/python/mathutils/mathutils_Color.cc +++ b/source/blender/python/mathutils/mathutils_Color.cc @@ -1006,27 +1006,39 @@ static int Color_hsv_set(ColorObject *self, PyObject *value, void * /*closure*/) * \{ */ static PyGetSetDef Color_getseters[] = { - {"r", (getter)Color_channel_get, (setter)Color_channel_set, Color_channel_r_doc, (void *)0}, - {"g", (getter)Color_channel_get, (setter)Color_channel_set, Color_channel_g_doc, (void *)1}, - {"b", (getter)Color_channel_get, (setter)Color_channel_set, Color_channel_b_doc, (void *)2}, + {"r", + (getter)Color_channel_get, + (setter)Color_channel_set, + Color_channel_r_doc, + POINTER_FROM_INT(0)}, + {"g", + (getter)Color_channel_get, + (setter)Color_channel_set, + Color_channel_g_doc, + POINTER_FROM_INT(1)}, + {"b", + (getter)Color_channel_get, + (setter)Color_channel_set, + Color_channel_b_doc, + POINTER_FROM_INT(2)}, {"h", (getter)Color_channel_hsv_get, (setter)Color_channel_hsv_set, Color_channel_hsv_h_doc, - (void *)0}, + POINTER_FROM_INT(0)}, {"s", (getter)Color_channel_hsv_get, (setter)Color_channel_hsv_set, Color_channel_hsv_s_doc, - (void *)1}, + POINTER_FROM_INT(1)}, {"v", (getter)Color_channel_hsv_get, (setter)Color_channel_hsv_set, Color_channel_hsv_v_doc, - (void *)2}, + POINTER_FROM_INT(2)}, - {"hsv", (getter)Color_hsv_get, (setter)Color_hsv_set, Color_hsv_doc, (void *)0}, + {"hsv", (getter)Color_hsv_get, (setter)Color_hsv_set, Color_hsv_doc, nullptr}, {"is_wrapped", (getter)BaseMathObject_is_wrapped_get, diff --git a/source/blender/python/mathutils/mathutils_Euler.cc b/source/blender/python/mathutils/mathutils_Euler.cc index 37dffa8b463..67770395c2b 100644 --- a/source/blender/python/mathutils/mathutils_Euler.cc +++ b/source/blender/python/mathutils/mathutils_Euler.cc @@ -719,10 +719,10 @@ static int Euler_order_set(EulerObject *self, PyObject *value, void * /*closure* * \{ */ static PyGetSetDef Euler_getseters[] = { - {"x", (getter)Euler_axis_get, (setter)Euler_axis_set, Euler_axis_doc, (void *)0}, - {"y", (getter)Euler_axis_get, (setter)Euler_axis_set, Euler_axis_doc, (void *)1}, - {"z", (getter)Euler_axis_get, (setter)Euler_axis_set, Euler_axis_doc, (void *)2}, - {"order", (getter)Euler_order_get, (setter)Euler_order_set, Euler_order_doc, (void *)nullptr}, + {"x", (getter)Euler_axis_get, (setter)Euler_axis_set, Euler_axis_doc, POINTER_FROM_INT(0)}, + {"y", (getter)Euler_axis_get, (setter)Euler_axis_set, Euler_axis_doc, POINTER_FROM_INT(1)}, + {"z", (getter)Euler_axis_get, (setter)Euler_axis_set, Euler_axis_doc, POINTER_FROM_INT(2)}, + {"order", (getter)Euler_order_get, (setter)Euler_order_set, Euler_order_doc, nullptr}, {"is_wrapped", (getter)BaseMathObject_is_wrapped_get, diff --git a/source/blender/python/mathutils/mathutils_Quaternion.cc b/source/blender/python/mathutils/mathutils_Quaternion.cc index 22943c4d1ea..cdc505bf977 100644 --- a/source/blender/python/mathutils/mathutils_Quaternion.cc +++ b/source/blender/python/mathutils/mathutils_Quaternion.cc @@ -1551,22 +1551,22 @@ static PyGetSetDef Quaternion_getseters[] = { (getter)Quaternion_axis_get, (setter)Quaternion_axis_set, Quaternion_axis_doc, - (void *)0}, + POINTER_FROM_INT(0)}, {"x", (getter)Quaternion_axis_get, (setter)Quaternion_axis_set, Quaternion_axis_doc, - (void *)1}, + POINTER_FROM_INT(1)}, {"y", (getter)Quaternion_axis_get, (setter)Quaternion_axis_set, Quaternion_axis_doc, - (void *)2}, + POINTER_FROM_INT(2)}, {"z", (getter)Quaternion_axis_get, (setter)Quaternion_axis_set, Quaternion_axis_doc, - (void *)3}, + POINTER_FROM_INT(3)}, {"magnitude", (getter)Quaternion_magnitude_get, (setter) nullptr, diff --git a/source/blender/python/mathutils/mathutils_Vector.cc b/source/blender/python/mathutils/mathutils_Vector.cc index 097f0ac7114..e5126e3fba9 100644 --- a/source/blender/python/mathutils/mathutils_Vector.cc +++ b/source/blender/python/mathutils/mathutils_Vector.cc @@ -2755,10 +2755,26 @@ static int Vector_swizzle_set(VectorObject *self, PyObject *value, void *closure #endif static PyGetSetDef Vector_getseters[] = { - {"x", (getter)Vector_axis_get, (setter)Vector_axis_set, Vector_axis_x_doc, (void *)0}, - {"y", (getter)Vector_axis_get, (setter)Vector_axis_set, Vector_axis_y_doc, (void *)1}, - {"z", (getter)Vector_axis_get, (setter)Vector_axis_set, Vector_axis_z_doc, (void *)2}, - {"w", (getter)Vector_axis_get, (setter)Vector_axis_set, Vector_axis_w_doc, (void *)3}, + {"x", + (getter)Vector_axis_get, + (setter)Vector_axis_set, + Vector_axis_x_doc, + POINTER_FROM_INT(0)}, + {"y", + (getter)Vector_axis_get, + (setter)Vector_axis_set, + Vector_axis_y_doc, + POINTER_FROM_INT(1)}, + {"z", + (getter)Vector_axis_get, + (setter)Vector_axis_set, + Vector_axis_z_doc, + POINTER_FROM_INT(2)}, + {"w", + (getter)Vector_axis_get, + (setter)Vector_axis_set, + Vector_axis_w_doc, + POINTER_FROM_INT(3)}, {"length", (getter)Vector_length_get, (setter)Vector_length_set, Vector_length_doc, nullptr}, {"length_squared", (getter)Vector_length_squared_get,