[Bf-blender-cvs] [1fd1735df0b] blender2.8: CPython: use format char utilities in idprop_py_api

mano-wii noreply at git.blender.org
Sun Oct 7 17:26:07 CEST 2018


Commit: 1fd1735df0bf2aa39b863a372a2e0f0ad91d1545
Author: mano-wii
Date:   Sun Oct 7 12:24:47 2018 -0300
Branches: blender2.8
https://developer.blender.org/rB1fd1735df0bf2aa39b863a372a2e0f0ad91d1545

CPython: use format char utilities in idprop_py_api

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

M	source/blender/python/generic/idprop_py_api.c

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

diff --git a/source/blender/python/generic/idprop_py_api.c b/source/blender/python/generic/idprop_py_api.c
index 918ec8fa018..3eef3a1aa28 100644
--- a/source/blender/python/generic/idprop_py_api.c
+++ b/source/blender/python/generic/idprop_py_api.c
@@ -422,11 +422,18 @@ static IDProperty *idp_from_PyBytes(const char *name, PyObject *ob)
 	return IDP_New(IDP_STRING, &val, name);
 }
 
-static int idp_array_type_from_format_char(char format)
+static int idp_array_type_from_formatstr_and_size(const char *typestr, Py_ssize_t itemsize)
 {
-	if (format == 'i') return IDP_INT;
-	if (format == 'f') return IDP_FLOAT;
-	if (format == 'd') return IDP_DOUBLE;
+	char format = PyC_Formatchar_get(typestr);
+
+	if (PyC_Formatchar_is_floating_type(format)) {
+		if (itemsize == 4) return IDP_FLOAT;
+		if (itemsize == 8) return IDP_DOUBLE;
+	}
+	if (PyC_Formatchar_is_integer_type(format)) {
+		if (itemsize == 4) return IDP_INT;
+	}
+
 	return -1;
 }
 
@@ -443,13 +450,13 @@ static IDProperty *idp_from_PySequence_Buffer(const char *name, Py_buffer *buffe
 	IDProperty *prop;
 	IDPropertyTemplate val = {0};
 
-	int format = idp_array_type_from_format_char(*buffer->format);
-	if (format == -1) {
+	int id_type = idp_array_type_from_formatstr_and_size(buffer->format, buffer->itemsize);
+	if (id_type == -1) {
 		/* should never happen as the type has been checked before */
 		return NULL;
 	}
 	else {
-		val.array.type = format;
+		val.array.type = id_type;
 		val.array.len = buffer->len / buffer->itemsize;
 	}
 	prop = IDP_New(IDP_ARRAY, &val, name);
@@ -533,8 +540,10 @@ static IDProperty *idp_from_PySequence(const char *name, PyObject *ob)
 
 	if (PyObject_CheckBuffer(ob)) {
 		PyObject_GetBuffer(ob, &buffer, PyBUF_SIMPLE | PyBUF_FORMAT);
-		char format = *buffer.format;
-		if (ELEM(format, 'i', 'f', 'd')) {
+		char format = PyC_Formatchar_get(buffer.format);
+		if (PyC_Formatchar_is_floating_type(format) ||
+		    (PyC_Formatchar_is_integer_type(format) && buffer.itemsize == 4))
+		{
 			use_buffer = true;
 		}
 		else {



More information about the Bf-blender-cvs mailing list