diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-03-29 22:12:48 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-03-29 23:14:28 +0300 |
commit | 25ec4b437fe927205a810470cdc23efd7282c85b (patch) | |
tree | 6d7ba2fe73703915b4b94d3f2dab03fb731e9544 /source/blender/python/generic | |
parent | 18d06e8d21ed8c9a19df4205abcd7ed17eb9af00 (diff) |
Cleanup: style, use braces for the Python API
Diffstat (limited to 'source/blender/python/generic')
-rw-r--r-- | source/blender/python/generic/bgl.c | 77 | ||||
-rw-r--r-- | source/blender/python/generic/blf_py_api.c | 42 | ||||
-rw-r--r-- | source/blender/python/generic/bpy_internal_import.c | 24 | ||||
-rw-r--r-- | source/blender/python/generic/idprop_py_api.c | 68 | ||||
-rw-r--r-- | source/blender/python/generic/py_capi_utils.c | 24 |
5 files changed, 163 insertions, 72 deletions
diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c index 13342b7dac8..b52326ed7a4 100644 --- a/source/blender/python/generic/bgl.c +++ b/source/blender/python/generic/bgl.c @@ -476,15 +476,25 @@ static int gl_buffer_type_from_py_buffer(Py_buffer *pybuffer) Py_ssize_t itemsize = pybuffer->itemsize; if (PyC_StructFmt_type_is_float_any(format)) { - if (itemsize == 4) return GL_FLOAT; - if (itemsize == 8) return GL_DOUBLE; + if (itemsize == 4) { + return GL_FLOAT; + } + if (itemsize == 8) { + return GL_DOUBLE; + } } if (PyC_StructFmt_type_is_byte(format) || PyC_StructFmt_type_is_int_any(format)) { - if (itemsize == 1) return GL_BYTE; - if (itemsize == 2) return GL_SHORT; - if (itemsize == 4) return GL_INT; + if (itemsize == 1) { + return GL_BYTE; + } + if (itemsize == 2) { + return GL_SHORT; + } + if (itemsize == 4) { + return GL_INT; + } } return -1; /* UNKNOWN */ @@ -769,10 +779,12 @@ static PyObject *Buffer_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject for (i = 0; i < ndimensions; i++) { PyObject *ob = PySequence_GetItem(length_ob, i); - if (!PyLong_Check(ob)) + if (!PyLong_Check(ob)) { dimensions[i] = 1; - else + } + else { dimensions[i] = PyLong_AsLong(ob); + } Py_DECREF(ob); if (dimensions[i] < 1) { @@ -868,9 +880,15 @@ static PyObject *Buffer_slice(Buffer *self, int begin, int end) PyObject *list; int count; - if (begin < 0) begin = 0; - if (end > self->dimensions[0]) end = self->dimensions[0]; - if (begin > end) begin = end; + if (begin < 0) { + begin = 0; + } + if (end > self->dimensions[0]) { + end = self->dimensions[0]; + } + if (begin > end) { + begin = end; + } list = PyList_New(end - begin); @@ -916,9 +934,15 @@ static int Buffer_ass_slice(Buffer *self, int begin, int end, PyObject *seq) PyObject *item; int count, err = 0; - if (begin < 0) begin = 0; - if (end > self->dimensions[0]) end = self->dimensions[0]; - if (begin > end) begin = end; + if (begin < 0) { + begin = 0; + } + if (end > self->dimensions[0]) { + end = self->dimensions[0]; + } + if (begin > end) { + begin = end; + } if (!PySequence_Check(seq)) { PyErr_Format(PyExc_TypeError, @@ -957,17 +981,20 @@ static PyObject *Buffer_subscript(Buffer *self, PyObject *item) if (PyIndex_Check(item)) { Py_ssize_t i; i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) + if (i == -1 && PyErr_Occurred()) { return NULL; - if (i < 0) + } + if (i < 0) { i += self->dimensions[0]; + } return Buffer_item(self, i); } else if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; - if (PySlice_GetIndicesEx(item, self->dimensions[0], &start, &stop, &step, &slicelength) < 0) + if (PySlice_GetIndicesEx(item, self->dimensions[0], &start, &stop, &step, &slicelength) < 0) { return NULL; + } if (slicelength <= 0) { return PyTuple_New(0); @@ -993,20 +1020,24 @@ static int Buffer_ass_subscript(Buffer *self, PyObject *item, PyObject *value) { if (PyIndex_Check(item)) { Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) + if (i == -1 && PyErr_Occurred()) { return -1; - if (i < 0) + } + if (i < 0) { i += self->dimensions[0]; + } return Buffer_ass_item(self, i, value); } else if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; - if (PySlice_GetIndicesEx(item, self->dimensions[0], &start, &stop, &step, &slicelength) < 0) + if (PySlice_GetIndicesEx(item, self->dimensions[0], &start, &stop, &step, &slicelength) < 0) { return -1; + } - if (step == 1) + if (step == 1) { return Buffer_ass_slice(self, start, stop, value); + } else { PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors"); @@ -1390,8 +1421,9 @@ PyObject *BPyInit_bgl(void) submodule = PyModule_Create(&BGL_module_def); dict = PyModule_GetDict(submodule); - if (PyType_Ready(&BGL_bufferType) < 0) + if (PyType_Ready(&BGL_bufferType) < 0) { return NULL; /* should never happen */ + } PyModule_AddObject(submodule, "Buffer", (PyObject *)&BGL_bufferType); Py_INCREF((PyObject *)&BGL_bufferType); @@ -2554,8 +2586,9 @@ static PyObject *Method_ShaderSource(PyObject *UNUSED(self), PyObject *args) unsigned int shader; const char *source; - if (!PyArg_ParseTuple(args, "Is", &shader, &source)) + if (!PyArg_ParseTuple(args, "Is", &shader, &source)) { return NULL; + } glShaderSource(shader, 1, (const char **)&source, NULL); diff --git a/source/blender/python/generic/blf_py_api.c b/source/blender/python/generic/blf_py_api.c index 79ffb9aa892..9161e5d979b 100644 --- a/source/blender/python/generic/blf_py_api.c +++ b/source/blender/python/generic/blf_py_api.c @@ -50,8 +50,9 @@ static PyObject *py_blf_position(PyObject *UNUSED(self), PyObject *args) int fontid; float x, y, z; - if (!PyArg_ParseTuple(args, "ifff:blf.position", &fontid, &x, &y, &z)) + if (!PyArg_ParseTuple(args, "ifff:blf.position", &fontid, &x, &y, &z)) { return NULL; + } BLF_position(fontid, x, y, z); @@ -75,8 +76,9 @@ static PyObject *py_blf_size(PyObject *UNUSED(self), PyObject *args) { int fontid, size, dpi; - if (!PyArg_ParseTuple(args, "iii:blf.size", &fontid, &size, &dpi)) + if (!PyArg_ParseTuple(args, "iii:blf.size", &fontid, &size, &dpi)) { return NULL; + } BLF_size(fontid, size, dpi); @@ -99,8 +101,9 @@ static PyObject *py_blf_aspect(PyObject *UNUSED(self), PyObject *args) float aspect; int fontid; - if (!PyArg_ParseTuple(args, "if:blf.aspect", &fontid, &aspect)) + if (!PyArg_ParseTuple(args, "if:blf.aspect", &fontid, &aspect)) { return NULL; + } BLF_aspect(fontid, aspect, aspect, 1.0); @@ -157,8 +160,9 @@ static PyObject *py_blf_blur(PyObject *UNUSED(self), PyObject *args) { int blur, fontid; - if (!PyArg_ParseTuple(args, "ii:blf.blur", &fontid, &blur)) + if (!PyArg_ParseTuple(args, "ii:blf.blur", &fontid, &blur)) { return NULL; + } BLF_blur(fontid, blur); @@ -183,8 +187,9 @@ static PyObject *py_blf_draw(PyObject *UNUSED(self), PyObject *args) int text_length; int fontid; - if (!PyArg_ParseTuple(args, "is#:blf.draw", &fontid, &text, &text_length)) + if (!PyArg_ParseTuple(args, "is#:blf.draw", &fontid, &text, &text_length)) { return NULL; + } BLF_draw(fontid, text, (unsigned int)text_length); @@ -210,8 +215,9 @@ static PyObject *py_blf_dimensions(PyObject *UNUSED(self), PyObject *args) PyObject *ret; int fontid; - if (!PyArg_ParseTuple(args, "is:blf.dimensions", &fontid, &text)) + if (!PyArg_ParseTuple(args, "is:blf.dimensions", &fontid, &text)) { return NULL; + } BLF_width_and_height(fontid, text, INT_MAX, &r_width, &r_height); @@ -243,8 +249,9 @@ static PyObject *py_blf_clipping(PyObject *UNUSED(self), PyObject *args) float xmin, ymin, xmax, ymax; int fontid; - if (!PyArg_ParseTuple(args, "iffff:blf.clipping", &fontid, &xmin, &ymin, &xmax, &ymax)) + if (!PyArg_ParseTuple(args, "iffff:blf.clipping", &fontid, &xmin, &ymin, &xmax, &ymax)) { return NULL; + } BLF_clipping(fontid, xmin, ymin, xmax, ymax); @@ -266,8 +273,9 @@ static PyObject *py_blf_word_wrap(PyObject *UNUSED(self), PyObject *args) int wrap_width; int fontid; - if (!PyArg_ParseTuple(args, "ii:blf.word_wrap", &fontid, &wrap_width)) + if (!PyArg_ParseTuple(args, "ii:blf.word_wrap", &fontid, &wrap_width)) { return NULL; + } BLF_wordwrap(fontid, wrap_width); @@ -288,8 +296,9 @@ static PyObject *py_blf_disable(PyObject *UNUSED(self), PyObject *args) { int option, fontid; - if (!PyArg_ParseTuple(args, "ii:blf.disable", &fontid, &option)) + if (!PyArg_ParseTuple(args, "ii:blf.disable", &fontid, &option)) { return NULL; + } BLF_disable(fontid, option); @@ -310,8 +319,9 @@ static PyObject *py_blf_enable(PyObject *UNUSED(self), PyObject *args) { int option, fontid; - if (!PyArg_ParseTuple(args, "ii:blf.enable", &fontid, &option)) + if (!PyArg_ParseTuple(args, "ii:blf.enable", &fontid, &option)) { return NULL; + } BLF_enable(fontid, option); @@ -333,8 +343,9 @@ static PyObject *py_blf_rotation(PyObject *UNUSED(self), PyObject *args) float angle; int fontid; - if (!PyArg_ParseTuple(args, "if:blf.rotation", &fontid, &angle)) + if (!PyArg_ParseTuple(args, "if:blf.rotation", &fontid, &angle)) { return NULL; + } BLF_rotation(fontid, angle); @@ -397,8 +408,9 @@ static PyObject *py_blf_shadow_offset(PyObject *UNUSED(self), PyObject *args) { int x, y, fontid; - if (!PyArg_ParseTuple(args, "iii:blf.shadow_offset", &fontid, &x, &y)) + if (!PyArg_ParseTuple(args, "iii:blf.shadow_offset", &fontid, &x, &y)) { return NULL; + } BLF_shadow_offset(fontid, x, y); @@ -419,8 +431,9 @@ static PyObject *py_blf_load(PyObject *UNUSED(self), PyObject *args) { const char *filename; - if (!PyArg_ParseTuple(args, "s:blf.load", &filename)) + if (!PyArg_ParseTuple(args, "s:blf.load", &filename)) { return NULL; + } return PyLong_FromLong(BLF_load(filename)); } @@ -437,8 +450,9 @@ static PyObject *py_blf_unload(PyObject *UNUSED(self), PyObject *args) { const char *filename; - if (!PyArg_ParseTuple(args, "s:blf.unload", &filename)) + if (!PyArg_ParseTuple(args, "s:blf.unload", &filename)) { return NULL; + } BLF_unload(filename); diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c index 96b5645f0e7..0baa4008f2d 100644 --- a/source/blender/python/generic/bpy_internal_import.c +++ b/source/blender/python/generic/bpy_internal_import.c @@ -180,8 +180,9 @@ PyObject *bpy_text_import_name(const char *name, int *found) } /* we know this cant be importable, the name is too long for blender! */ - if (namelen >= (MAX_ID_NAME - 2) - 3) + if (namelen >= (MAX_ID_NAME - 2) - 3) { return NULL; + } memcpy(txtname, name, namelen); memcpy(&txtname[namelen], ".py", 4); @@ -200,10 +201,12 @@ PyObject *bpy_text_import_name(const char *name, int *found) maggie = maggie->next; } - if (!text) + if (!text) { return NULL; - else + } + else { *found = 1; + } return bpy_text_import(text); } @@ -229,8 +232,9 @@ PyObject *bpy_text_reimport(PyObject *module, int *found) *found = 0; /* get name, filename from the module itself */ - if ((name = PyModule_GetName(module)) == NULL) + if ((name = PyModule_GetName(module)) == NULL) { return NULL; + } { PyObject *module_file = PyModule_GetFilenameObject(module); @@ -248,10 +252,12 @@ PyObject *bpy_text_reimport(PyObject *module, int *found) text = BLI_findstring(&maggie->texts, BLI_path_basename(filepath), offsetof(ID, name) + 2); /* uh-oh.... didn't find it */ - if (!text) + if (!text) { return NULL; - else + } + else { *found = 1; + } if (bpy_text_compile(text) == false) { return NULL; @@ -283,8 +289,9 @@ static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject /* import existing builtin modules or modules that have been imported already */ newmodule = PyImport_ImportModuleLevel(name, globals, locals, fromlist, level); - if (newmodule) + if (newmodule) { return newmodule; + } PyErr_Fetch(&exception, &err, &tb); /* get the python error in case we cant import as blender text either */ @@ -330,8 +337,9 @@ static PyObject *blender_reload(PyObject *UNUSED(self), PyObject *module) newmodule = PyObject_CallFunctionObjArgs(imp_reload_orig, module, NULL); - if (newmodule) + if (newmodule) { return newmodule; + } /* no file, try importing from memory */ PyErr_Fetch(&exception, &err, &tb); /*restore for probable later use */ diff --git a/source/blender/python/generic/idprop_py_api.c b/source/blender/python/generic/idprop_py_api.c index 6c5177d4759..f18d02a4405 100644 --- a/source/blender/python/generic/idprop_py_api.c +++ b/source/blender/python/generic/idprop_py_api.c @@ -419,11 +419,17 @@ static int idp_array_type_from_formatstr_and_size(const char *typestr, Py_ssize_ char format = PyC_StructFmt_type_from_str(typestr); if (PyC_StructFmt_type_is_float_any(format)) { - if (itemsize == 4) return IDP_FLOAT; - if (itemsize == 8) return IDP_DOUBLE; + if (itemsize == 4) { + return IDP_FLOAT; + } + if (itemsize == 8) { + return IDP_DOUBLE; + } } if (PyC_StructFmt_type_is_int_any(format)) { - if (itemsize == 4) return IDP_INT; + if (itemsize == 4) { + return IDP_INT; + } } return -1; @@ -431,9 +437,15 @@ static int idp_array_type_from_formatstr_and_size(const char *typestr, Py_ssize_ static const char *idp_format_from_array_type(int type) { - if (type == IDP_INT) return "i"; - if (type == IDP_FLOAT) return "f"; - if (type == IDP_DOUBLE) return "d"; + if (type == IDP_INT) { + return "i"; + } + if (type == IDP_FLOAT) { + return "f"; + } + if (type == IDP_DOUBLE) { + return "d"; + } return NULL; } @@ -936,8 +948,9 @@ PyObject *BPy_Wrap_GetKeys(IDProperty *prop) IDProperty *loop; int i; - for (i = 0, loop = prop->data.group.first; loop && (i < prop->len); loop = loop->next, i++) + for (i = 0, loop = prop->data.group.first; loop && (i < prop->len); loop = loop->next, i++) { PyList_SET_ITEM(list, i, PyUnicode_FromString(loop->name)); + } /* if the id prop is corrupt, count the remaining */ for ( ; loop; loop = loop->next, i++) { @@ -1067,7 +1080,9 @@ static PyObject *BPy_IDGroup_update(BPy_IDProperty *self, PyObject *value) else if (PyDict_Check(value)) { while (PyDict_Next(value, &i, &pkey, &pval)) { BPy_IDGroup_Map_SetItem(self, pkey, pval); - if (PyErr_Occurred()) return NULL; + if (PyErr_Occurred()) { + return NULL; + } } } else { @@ -1113,14 +1128,16 @@ static PyObject *BPy_IDGroup_get(BPy_IDProperty *self, PyObject *args) const char *key; PyObject *def = Py_None; - if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) + if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) { return NULL; + } idprop = IDP_GetPropertyFromGroup(self->prop, key); if (idprop) { PyObject *pyobj = BPy_IDGroup_WrapData(self->id, idprop, self->prop); - if (pyobj) + if (pyobj) { return pyobj; + } } Py_INCREF(def); @@ -1376,7 +1393,9 @@ static PyObject *BPy_IDArray_slice(BPy_IDArray *self, int begin, int end) int count; CLAMP(begin, 0, prop->len); - if (end < 0) end = prop->len + end + 1; + if (end < 0) { + end = prop->len + end + 1; + } CLAMP(end, 0, prop->len); begin = MIN2(begin, end); @@ -1446,17 +1465,20 @@ static PyObject *BPy_IDArray_subscript(BPy_IDArray *self, PyObject *item) if (PyIndex_Check(item)) { Py_ssize_t i; i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) + if (i == -1 && PyErr_Occurred()) { return NULL; - if (i < 0) + } + if (i < 0) { i += self->prop->len; + } return BPy_IDArray_GetItem(self, i); } else if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; - if (PySlice_GetIndicesEx(item, self->prop->len, &start, &stop, &step, &slicelength) < 0) + if (PySlice_GetIndicesEx(item, self->prop->len, &start, &stop, &step, &slicelength) < 0) { return NULL; + } if (slicelength <= 0) { return PyTuple_New(0); @@ -1481,20 +1503,24 @@ static int BPy_IDArray_ass_subscript(BPy_IDArray *self, PyObject *item, PyObject { if (PyIndex_Check(item)) { Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); - if (i == -1 && PyErr_Occurred()) + if (i == -1 && PyErr_Occurred()) { return -1; - if (i < 0) + } + if (i < 0) { i += self->prop->len; + } return BPy_IDArray_SetItem(self, i, value); } else if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; - if (PySlice_GetIndicesEx(item, self->prop->len, &start, &stop, &step, &slicelength) < 0) + if (PySlice_GetIndicesEx(item, self->prop->len, &start, &stop, &step, &slicelength) < 0) { return -1; + } - if (step == 1) + if (step == 1) { return BPy_IDArray_ass_slice(self, start, stop, value); + } else { PyErr_SetString(PyExc_TypeError, "slice steps not supported with vectors"); return -1; @@ -1516,9 +1542,9 @@ static PyMappingMethods BPy_IDArray_AsMapping = { static int itemsize_by_idarray_type(int array_type) { - if (array_type == IDP_INT) return sizeof(int); - if (array_type == IDP_FLOAT) return sizeof(float); - if (array_type == IDP_DOUBLE) return sizeof(double); + if (array_type == IDP_INT) { return sizeof(int); } + if (array_type == IDP_FLOAT) { return sizeof(float); } + if (array_type == IDP_DOUBLE) { return sizeof(double); } return -1; /* should never happen */ } diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c index f18e794ead3..0c10737609c 100644 --- a/source/blender/python/generic/py_capi_utils.c +++ b/source/blender/python/generic/py_capi_utils.c @@ -319,8 +319,12 @@ void PyC_FileAndNum(const char **filename, int *lineno) { PyFrameObject *frame; - if (filename) *filename = NULL; - if (lineno) *lineno = -1; + if (filename) { + *filename = NULL; + } + if (lineno) { + *lineno = -1; + } if (!(frame = PyThreadState_GET()->frame)) { return; @@ -384,10 +388,13 @@ PyObject *PyC_Object_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...) attr = va_arg(vargs, char *); item = PyObject_GetAttrString(item, attr); - if (item) + if (item) { Py_DECREF(item); - else /* python will set the error value here */ + } + else { + /* python will set the error value here */ break; + } } va_end(vargs); @@ -527,8 +534,9 @@ PyObject *PyC_ExceptionBuffer(void) PyObject *error_type, *error_value, *error_traceback; - if (!PyErr_Occurred()) + if (!PyErr_Occurred()) { return NULL; + } PyErr_Fetch(&error_type, &error_value, &error_traceback); @@ -593,8 +601,9 @@ PyObject *PyC_ExceptionBuffer_Simple(void) PyObject *error_type, *error_value, *error_traceback; - if (!PyErr_Occurred()) + if (!PyErr_Occurred()) { return NULL; + } PyErr_Fetch(&error_type, &error_value, &error_traceback); @@ -775,9 +784,10 @@ void PyC_SetHomePath(const char *py_path_bundle) #ifdef __APPLE__ /* OSX allow file/directory names to contain : character (represented as / in the Finder) * but current Python lib (release 3.1.1) doesn't handle these correctly */ - if (strchr(py_path_bundle, ':')) + if (strchr(py_path_bundle, ':')) { printf("Warning : Blender application is located in a path containing : or / chars\ \nThis may make python import function fail\n"); + } #endif |