[Bf-blender-cvs] [495a7128cb2] blender2.8: Cleanup: use the naming convention in py_capi_utils

mano-wii noreply at git.blender.org
Sat Oct 6 06:18:04 CEST 2018


Commit: 495a7128cb230a26bc72cb735e33be5324bf3baa
Author: mano-wii
Date:   Sat Oct 6 01:15:15 2018 -0300
Branches: blender2.8
https://developer.blender.org/rB495a7128cb230a26bc72cb735e33be5324bf3baa

Cleanup: use the naming convention in py_capi_utils

And use inline functions instead of preprocessor directives.

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

M	source/blender/python/generic/bgl.c
M	source/blender/python/generic/py_capi_utils.h
M	source/blender/python/gpu/gpu_py_element.c

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

diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c
index 58bfea5fab8..a89525d942f 100644
--- a/source/blender/python/generic/bgl.c
+++ b/source/blender/python/generic/bgl.c
@@ -480,14 +480,14 @@ int BGL_typeSize(int type)
 
 static int gl_buffer_type_from_py_buffer(Py_buffer *pybuffer)
 {
-	const char format = FORMAT_STR_GET(pybuffer->format);
+	const char format = PyC_Formatstr_get(pybuffer->format);
 	Py_ssize_t itemsize = pybuffer->itemsize;
 
-	if (FORMAT_STR_IS_FLOAT(format)) {
+	if (PyC_Formatstr_is_float(format)) {
 		if (itemsize == 4) return GL_FLOAT;
 		if (itemsize == 8) return GL_DOUBLE;
 	}
-	if (FORMAT_STR_IS_BYTE(format) || FORMAT_STR_IS_INT(format)) {
+	if (PyC_Formatstr_is_byte(format) || PyC_Formatstr_is_int(format)) {
 		if (itemsize == 1) return GL_BYTE;
 		if (itemsize == 2) return GL_SHORT;
 		if (itemsize == 4) return GL_INT;
diff --git a/source/blender/python/generic/py_capi_utils.h b/source/blender/python/generic/py_capi_utils.h
index 8ceb4a76a53..523712d0cb0 100644
--- a/source/blender/python/generic/py_capi_utils.h
+++ b/source/blender/python/generic/py_capi_utils.h
@@ -132,10 +132,74 @@ Py_LOCAL_INLINE(int64_t)  PyC_Long_AsI64(PyObject *value) { return (int64_t)PyLo
 Py_LOCAL_INLINE(uint64_t) PyC_Long_AsU64(PyObject *value) { return (uint64_t)PyLong_AsUnsignedLongLong(value); }
 
 /* utils for format string in `struct` module style syntax */
-#define FORMAT_STR_GET(typestr) ELEM(typestr[0], '!', '<', '=', '>', '@') ? typestr[1] : typestr[0]
-#define FORMAT_STR_IS_FLOAT(format) ELEM(format, 'f', 'd', 'e')
-#define FORMAT_STR_IS_INT(format) ELEM(format, 'i', 'I', 'l', 'L', 'h', 'H', 'b', 'B', 'q', 'Q', 'n', 'N', 'P')
-#define FORMAT_STR_IS_BYTE(format) ELEM(format, 'c', 's', 'p')
-#define FORMAT_STR_IS_BOOL(format) ELEM(format, '?')
+Py_LOCAL_INLINE(char) PyC_Formatstr_get(char *typestr)
+{
+	switch (typestr[0]) {
+		case '!':
+		case '<':
+		case '=':
+		case '>':
+		case '@':
+			return typestr[1];
+		default:
+			return typestr[0];
+	}
+}
+
+Py_LOCAL_INLINE(bool) PyC_Formatstr_is_float(char format)
+{
+	switch (format) {
+		case 'f':
+		case 'd':
+		case 'e':
+			return true;
+		default:
+			return false;
+	}
+}
+
+Py_LOCAL_INLINE(bool) PyC_Formatstr_is_int(char format)
+{
+	switch (format) {
+		case 'i':
+		case 'I':
+		case 'l':
+		case 'L':
+		case 'h':
+		case 'H':
+		case 'b':
+		case 'B':
+		case 'q':
+		case 'Q':
+		case 'n':
+		case 'N':
+		case 'P':
+			return true;
+		default:
+			return false;
+	}
+}
+
+Py_LOCAL_INLINE(bool) PyC_Formatstr_is_byte(char format)
+{
+	switch (format) {
+		case 'c':
+		case 's':
+		case 'p':
+			return true;
+		default:
+			return false;
+	}
+}
+
+Py_LOCAL_INLINE(bool) PyC_Formatstr_is_bool(char format)
+{
+	switch (format) {
+		case '?':
+			return true;
+		default:
+			return false;
+	}
+}
 
 #endif  /* __PY_CAPI_UTILS_H__ */
diff --git a/source/blender/python/gpu/gpu_py_element.c b/source/blender/python/gpu/gpu_py_element.c
index 0c4cd1d815b..379cd0836ca 100644
--- a/source/blender/python/gpu/gpu_py_element.c
+++ b/source/blender/python/gpu/gpu_py_element.c
@@ -91,17 +91,11 @@ static PyObject *bpygpu_IndexBuf_new(PyTypeObject *UNUSED(type), PyObject *args,
 			return NULL;
 		}
 
-		bool format_error = pybuffer.itemsize != 4;
+		if (pybuffer.itemsize != 4 ||
+		    PyC_Formatstr_is_float(PyC_Formatstr_get(pybuffer.format)))
 		{
-			char format = FORMAT_STR_GET(pybuffer.format);
-			if (FORMAT_STR_IS_FLOAT(format)) {
-				format_error = true;
-			}
-		}
-
-		if (format_error) {
 			PyErr_Format(PyExc_ValueError,
-			        "Each index must be an integer value with 4 bytes in size");
+			             "Each index must be an 4-bytes integer value");
 			return NULL;
 		}



More information about the Bf-blender-cvs mailing list