From e555ede626dade2c9b6449ec7dcdda22b2585fd4 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 7 Nov 2022 22:34:35 +1100 Subject: Cleanup: unify struct declaration style for Python types, update names Use struct identifiers in comments before the value. This has some advantages: - The struct identifiers didn't mix well with other code-comments, where other comments were wrapped onto the next line. - Minor changes could re-align all other comments in the struct. - PyVarObject_HEAD_INIT & tp_name are no longer placed on the same line. Remove overly verbose comments copied from PyTypeObject (Python v2.x), these aren't especially helpful and get outdated. Also corrected some outdated names: - PyTypeObject.tp_print -> tp_vectorcall_offset - PyTypeObject.tp_reserved -> tp_as_async --- source/blender/python/bmesh/bmesh_py_types.c | 35 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'source/blender/python/bmesh/bmesh_py_types.c') diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index 364adb5458b..cf20e1349ee 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -3313,31 +3313,30 @@ static int bpy_bmelem_ass_subscript(BPy_BMElem *self, BPy_BMLayerItem *key, PyOb } static PySequenceMethods bpy_bmelemseq_as_sequence = { - (lenfunc)bpy_bmelemseq_length, /* sq_length */ - NULL, /* sq_concat */ - NULL, /* sq_repeat */ - (ssizeargfunc)bpy_bmelemseq_subscript_int, - /* sq_item */ /* Only set this so PySequence_Check() returns True */ - NULL, /* sq_slice */ - (ssizeobjargproc)NULL, /* sq_ass_item */ - NULL, /* *was* sq_ass_slice */ - (objobjproc)bpy_bmelemseq_contains, /* sq_contains */ - (binaryfunc)NULL, /* sq_inplace_concat */ - (ssizeargfunc)NULL, /* sq_inplace_repeat */ + /*sq_length*/ (lenfunc)bpy_bmelemseq_length, + /*sq_concat*/ NULL, + /*sq_repeat*/ NULL, + /* Only set this so `PySequence_Check()` returns True. */ + /*sq_item*/ (ssizeargfunc)bpy_bmelemseq_subscript_int, + /*was_sq_slice*/ NULL, + /*sq_ass_item*/ NULL, + /*was_sq_ass_slice*/ NULL, + /*sq_contains*/ (objobjproc)bpy_bmelemseq_contains, + /*sq_inplace_concat*/ NULL, + /*sq_inplace_repeat*/ NULL, }; static PyMappingMethods bpy_bmelemseq_as_mapping = { - (lenfunc)bpy_bmelemseq_length, /* mp_length */ - (binaryfunc)bpy_bmelemseq_subscript, /* mp_subscript */ - (objobjargproc)NULL, /* mp_ass_subscript */ + /*mp_len*/ (lenfunc)bpy_bmelemseq_length, + /*mp_subscript*/ (binaryfunc)bpy_bmelemseq_subscript, + /*mp_ass_subscript*/ (objobjargproc)NULL, }; /* for customdata access */ static PyMappingMethods bpy_bm_elem_as_mapping = { - (lenfunc)NULL, - /* mp_length */ /* keep this empty, messes up 'if elem: ...' test */ - (binaryfunc)bpy_bmelem_subscript, /* mp_subscript */ - (objobjargproc)bpy_bmelem_ass_subscript, /* mp_ass_subscript */ + /*mp_len*/ (lenfunc)NULL, /* Keep this empty, messes up `if elem: ...` test. */ + /*mp_subscript*/ (binaryfunc)bpy_bmelem_subscript, + /*mp_ass_subscript*/ (objobjargproc)bpy_bmelem_ass_subscript, }; /* Iterator -- cgit v1.2.3 From 4eb9322edae4ded7caba1b12379a0194225d87cd Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 8 Nov 2022 11:13:58 +1100 Subject: Cleanup: PyMethodDef formatting Missed these changes in [0]. Also replace designated initializers in some C code, as it's not used often and would need to be removed when converting to C++. [0] e555ede626dade2c9b6449ec7dcdda22b2585fd4 --- source/blender/python/bmesh/bmesh_py_types.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source/blender/python/bmesh/bmesh_py_types.c') diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index cf20e1349ee..fab23d06ab3 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -3735,14 +3735,14 @@ void BPy_BM_init_types(void) static struct PyModuleDef BPy_BM_types_module_def = { PyModuleDef_HEAD_INIT, - "bmesh.types", /* m_name */ - NULL, /* m_doc */ - 0, /* m_size */ - NULL, /* m_methods */ - NULL, /* m_slots */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL, /* m_free */ + /*m_name*/ "bmesh.types", + /*m_doc*/ NULL, + /*m_size*/ 0, + /*m_methods*/ NULL, + /*m_slots*/ NULL, + /*m_traverse*/ NULL, + /*m_clear*/ NULL, + /*m_free*/ NULL, }; PyObject *BPyInit_bmesh_types(void) -- cgit v1.2.3 From 8f439bdc2de1f964c8037448796a3f03a9cce4fe Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 8 Nov 2022 12:03:38 +1100 Subject: Fix invalid function signatures for PySequenceMethods callbacks Function casts hid casting between potentially incompatible type signatures (using int instead of Py_ssize_t). As it happens this seems not to have caused any bugs on supported platforms so this change is mainly for correctness and to avoid problems in the future. --- source/blender/python/bmesh/bmesh_py_types.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/python/bmesh/bmesh_py_types.c') diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index 364adb5458b..5c9c83f2e6e 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -3118,7 +3118,7 @@ static Py_ssize_t bpy_bmelemseq_length(BPy_BMElemSeq *self) } } -static PyObject *bpy_bmelemseq_subscript_int(BPy_BMElemSeq *self, int keynum) +static PyObject *bpy_bmelemseq_subscript_int(BPy_BMElemSeq *self, Py_ssize_t keynum) { BPY_BM_CHECK_OBJ(self); -- cgit v1.2.3 From 0d945fe20e87ac7ada2d565f751146c2e8fa1ed6 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 7 Nov 2022 15:43:20 +0100 Subject: Fix deprecation warnings about printf() on macOS The new Xcode 14.1 brings the new Apple Clang compiler which considers sprintf unsafe and geenrates deprecation warnings suggesting to sue snprintf instead. This only happens for C++ code by default, and C code can still use sprintf without any warning. This changes does the following: - Whenever is trivial replace sprintf() with BLI_snprintf. - For all other cases use the newly introduced BLI_sprintf which is a wrapper around sprintf() but without warning. There is a discouragement note in the BLI_sprintf comment to suggest use of BLI_snprintf when the size is known. Differential Revision: https://developer.blender.org/D16410 --- source/blender/python/bmesh/bmesh_py_types.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'source/blender/python/bmesh/bmesh_py_types.c') diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index 5c9c83f2e6e..1aa20700f31 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -7,6 +7,7 @@ #include "BLI_math.h" #include "BLI_sort.h" +#include "BLI_string.h" #include "DNA_material_types.h" #include "DNA_mesh_types.h" @@ -4247,16 +4248,16 @@ char *BPy_BMElem_StringFromHType_ex(const char htype, char ret[32]) /* zero to ensure string is always NULL terminated */ char *ret_ptr = ret; if (htype & BM_VERT) { - ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMVert_Type.tp_name); + ret_ptr += BLI_sprintf(ret_ptr, "/%s", BPy_BMVert_Type.tp_name); } if (htype & BM_EDGE) { - ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMEdge_Type.tp_name); + ret_ptr += BLI_sprintf(ret_ptr, "/%s", BPy_BMEdge_Type.tp_name); } if (htype & BM_FACE) { - ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMFace_Type.tp_name); + ret_ptr += BLI_sprintf(ret_ptr, "/%s", BPy_BMFace_Type.tp_name); } if (htype & BM_LOOP) { - ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMLoop_Type.tp_name); + ret_ptr += BLI_sprintf(ret_ptr, "/%s", BPy_BMLoop_Type.tp_name); } ret[0] = '('; *ret_ptr++ = ')'; -- cgit v1.2.3