Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2021-07-27 15:26:33 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-07-27 15:36:01 +0300
commit58eacb8e7c7ae95bf34896d9cdd868e7a11e044e (patch)
tree7e62d569d7196bbfc20be0b4a5cb3e822eaa8bc4 /source/blender/python/generic
parentb1a2abd6b2ba92c0b9134ae72b502a375556a417 (diff)
Cleanup: pass sizeof array element to PyC_AsArray
Replace the is_double argument which was only used for single/double precision floats. This allows supporting different sized int types more easily.
Diffstat (limited to 'source/blender/python/generic')
-rw-r--r--source/blender/python/generic/idprop_py_api.c2
-rw-r--r--source/blender/python/generic/imbuf_py_api.c2
-rw-r--r--source/blender/python/generic/py_capi_utils.c63
-rw-r--r--source/blender/python/generic/py_capi_utils.h4
4 files changed, 48 insertions, 23 deletions
diff --git a/source/blender/python/generic/idprop_py_api.c b/source/blender/python/generic/idprop_py_api.c
index bfdc763e4df..024900db691 100644
--- a/source/blender/python/generic/idprop_py_api.c
+++ b/source/blender/python/generic/idprop_py_api.c
@@ -1836,7 +1836,7 @@ static int BPy_IDArray_ass_slice(BPy_IDArray *self, int begin, int end, PyObject
/* NOTE: we count on int/float being the same size here */
vec = MEM_mallocN(alloc_len, "array assignment");
- if (PyC_AsArray(vec, seq, size, py_type, is_double, "slice assignment: ") == -1) {
+ if (PyC_AsArray(vec, elem_size, seq, size, py_type, "slice assignment: ") == -1) {
MEM_freeN(vec);
return -1;
}
diff --git a/source/blender/python/generic/imbuf_py_api.c b/source/blender/python/generic/imbuf_py_api.c
index 08ddef992a3..87afc40330c 100644
--- a/source/blender/python/generic/imbuf_py_api.c
+++ b/source/blender/python/generic/imbuf_py_api.c
@@ -242,7 +242,7 @@ static int py_imbuf_ppm_set(Py_ImBuf *self, PyObject *value, void *UNUSED(closur
PY_IMBUF_CHECK_INT(self);
double ppm[2];
- if (PyC_AsArray(ppm, value, 2, &PyFloat_Type, true, "ppm") == -1) {
+ if (PyC_AsArray(ppm, sizeof(*ppm), value, 2, &PyFloat_Type, "ppm") == -1) {
return -1;
}
diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c
index 68fefee4a61..37b2849aa94 100644
--- a/source/blender/python/generic/py_capi_utils.c
+++ b/source/blender/python/generic/py_capi_utils.c
@@ -57,10 +57,10 @@
/* array utility function */
int PyC_AsArray_FAST(void *array,
+ const size_t array_item_size,
PyObject *value_fast,
const Py_ssize_t length,
const PyTypeObject *type,
- const bool is_double,
const char *error_prefix)
{
const Py_ssize_t value_len = PySequence_Fast_GET_SIZE(value_fast);
@@ -80,30 +80,55 @@ int PyC_AsArray_FAST(void *array,
/* for each type */
if (type == &PyFloat_Type) {
- if (is_double) {
- double *array_double = array;
- for (i = 0; i < length; i++) {
- array_double[i] = PyFloat_AsDouble(value_fast_items[i]);
+ switch (array_item_size) {
+ case sizeof(double): {
+ double *array_double = array;
+ for (i = 0; i < length; i++) {
+ array_double[i] = PyFloat_AsDouble(value_fast_items[i]);
+ }
+ break;
}
- }
- else {
- float *array_float = array;
- for (i = 0; i < length; i++) {
- array_float[i] = PyFloat_AsDouble(value_fast_items[i]);
+ case sizeof(float): {
+ float *array_float = array;
+ for (i = 0; i < length; i++) {
+ array_float[i] = PyFloat_AsDouble(value_fast_items[i]);
+ }
+ break;
+ }
+ default: {
+ /* Internal error. */
+ BLI_assert_unreachable();
}
}
}
else if (type == &PyLong_Type) {
- /* could use is_double for 'long int' but no use now */
- int *array_int = array;
- for (i = 0; i < length; i++) {
- array_int[i] = PyC_Long_AsI32(value_fast_items[i]);
+ switch (array_item_size) {
+ case sizeof(int32_t): {
+ int32_t *array_int = array;
+ for (i = 0; i < length; i++) {
+ array_int[i] = PyC_Long_AsI32(value_fast_items[i]);
+ }
+ break;
+ }
+ default: {
+ /* Internal error. */
+ BLI_assert_unreachable();
+ }
}
}
else if (type == &PyBool_Type) {
- bool *array_bool = array;
- for (i = 0; i < length; i++) {
- array_bool[i] = (PyLong_AsLong(value_fast_items[i]) != 0);
+ switch (array_item_size) {
+ case sizeof(bool): {
+ bool *array_bool = array;
+ for (i = 0; i < length; i++) {
+ array_bool[i] = (PyLong_AsLong(value_fast_items[i]) != 0);
+ }
+ break;
+ }
+ default: {
+ /* Internal error. */
+ BLI_assert_unreachable();
+ }
}
}
else {
@@ -123,10 +148,10 @@ int PyC_AsArray_FAST(void *array,
}
int PyC_AsArray(void *array,
+ const size_t array_item_size,
PyObject *value,
const Py_ssize_t length,
const PyTypeObject *type,
- const bool is_double,
const char *error_prefix)
{
PyObject *value_fast;
@@ -136,7 +161,7 @@ int PyC_AsArray(void *array,
return -1;
}
- ret = PyC_AsArray_FAST(array, value_fast, length, type, is_double, error_prefix);
+ ret = PyC_AsArray_FAST(array, array_item_size, value_fast, length, type, error_prefix);
Py_DECREF(value_fast);
return ret;
}
diff --git a/source/blender/python/generic/py_capi_utils.h b/source/blender/python/generic/py_capi_utils.h
index 842e1482c06..5e0f60956f0 100644
--- a/source/blender/python/generic/py_capi_utils.h
+++ b/source/blender/python/generic/py_capi_utils.h
@@ -42,16 +42,16 @@ void PyC_Err_PrintWithFunc(PyObject *py_func);
void PyC_FileAndNum(const char **r_filename, int *r_lineno);
void PyC_FileAndNum_Safe(const char **r_filename, int *r_lineno); /* checks python is running */
int PyC_AsArray_FAST(void *array,
+ const size_t array_elem_size,
PyObject *value_fast,
const Py_ssize_t length,
const PyTypeObject *type,
- const bool is_double,
const char *error_prefix);
int PyC_AsArray(void *array,
+ const size_t array_elem_size,
PyObject *value,
const Py_ssize_t length,
const PyTypeObject *type,
- const bool is_double,
const char *error_prefix);
PyObject *PyC_Tuple_PackArray_F32(const float *array, uint len);