Cleanup: use "num" as a suffix in: source/blender/python
See T85728
This commit is contained in:
@@ -92,47 +92,46 @@ Py_hash_t mathutils_array_hash(const float *array, size_t array_len)
|
||||
}
|
||||
|
||||
int mathutils_array_parse(
|
||||
float *array, int array_min, int array_max, PyObject *value, const char *error_prefix)
|
||||
float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
|
||||
{
|
||||
const uint flag = array_max;
|
||||
int size;
|
||||
const uint flag = array_num_max;
|
||||
int num;
|
||||
|
||||
array_max &= ~MU_ARRAY_FLAGS;
|
||||
array_num_max &= ~MU_ARRAY_FLAGS;
|
||||
|
||||
#if 1 /* approx 6x speedup for mathutils types */
|
||||
|
||||
if ((size = VectorObject_Check(value) ? ((VectorObject *)value)->size : 0) ||
|
||||
(size = EulerObject_Check(value) ? 3 : 0) ||
|
||||
(size = QuaternionObject_Check(value) ? 4 : 0) ||
|
||||
(size = ColorObject_Check(value) ? 3 : 0)) {
|
||||
if ((num = VectorObject_Check(value) ? ((VectorObject *)value)->vec_num : 0) ||
|
||||
(num = EulerObject_Check(value) ? 3 : 0) || (num = QuaternionObject_Check(value) ? 4 : 0) ||
|
||||
(num = ColorObject_Check(value) ? 3 : 0)) {
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (flag & MU_ARRAY_SPILL) {
|
||||
CLAMP_MAX(size, array_max);
|
||||
CLAMP_MAX(num, array_num_max);
|
||||
}
|
||||
|
||||
if (size > array_max || size < array_min) {
|
||||
if (array_max == array_min) {
|
||||
if (num > array_num_max || num < array_num_min) {
|
||||
if (array_num_max == array_num_min) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s: sequence size is %d, expected %d",
|
||||
"%.200s: sequence length is %d, expected %d",
|
||||
error_prefix,
|
||||
size,
|
||||
array_max);
|
||||
num,
|
||||
array_num_max);
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s: sequence size is %d, expected [%d - %d]",
|
||||
"%.200s: sequence length is %d, expected [%d - %d]",
|
||||
error_prefix,
|
||||
size,
|
||||
array_min,
|
||||
array_max);
|
||||
num,
|
||||
array_num_min,
|
||||
array_num_max);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(array, ((const BaseMathObject *)value)->data, size * sizeof(float));
|
||||
memcpy(array, ((const BaseMathObject *)value)->data, num * sizeof(float));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@@ -145,77 +144,76 @@ int mathutils_array_parse(
|
||||
return -1;
|
||||
}
|
||||
|
||||
size = PySequence_Fast_GET_SIZE(value_fast);
|
||||
num = PySequence_Fast_GET_SIZE(value_fast);
|
||||
|
||||
if (flag & MU_ARRAY_SPILL) {
|
||||
CLAMP_MAX(size, array_max);
|
||||
CLAMP_MAX(num, array_num_max);
|
||||
}
|
||||
|
||||
if (size > array_max || size < array_min) {
|
||||
if (array_max == array_min) {
|
||||
if (num > array_num_max || num < array_num_min) {
|
||||
if (array_num_max == array_num_min) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s: sequence size is %d, expected %d",
|
||||
"%.200s: sequence length is %d, expected %d",
|
||||
error_prefix,
|
||||
size,
|
||||
array_max);
|
||||
num,
|
||||
array_num_max);
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s: sequence size is %d, expected [%d - %d]",
|
||||
"%.200s: sequence length is %d, expected [%d - %d]",
|
||||
error_prefix,
|
||||
size,
|
||||
array_min,
|
||||
array_max);
|
||||
num,
|
||||
array_num_min,
|
||||
array_num_max);
|
||||
}
|
||||
Py_DECREF(value_fast);
|
||||
return -1;
|
||||
}
|
||||
|
||||
size = mathutils_array_parse_fast(array, size, value_fast, error_prefix);
|
||||
num = mathutils_array_parse_fast(array, num, value_fast, error_prefix);
|
||||
Py_DECREF(value_fast);
|
||||
}
|
||||
|
||||
if (size != -1) {
|
||||
if (num != -1) {
|
||||
if (flag & MU_ARRAY_ZERO) {
|
||||
const int size_left = array_max - size;
|
||||
if (size_left) {
|
||||
memset(&array[size], 0, sizeof(float) * size_left);
|
||||
const int array_num_left = array_num_max - num;
|
||||
if (array_num_left) {
|
||||
memset(&array[num], 0, sizeof(float) * array_num_left);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
return num;
|
||||
}
|
||||
|
||||
int mathutils_array_parse_alloc(float **array,
|
||||
int array_min,
|
||||
int array_num,
|
||||
PyObject *value,
|
||||
const char *error_prefix)
|
||||
{
|
||||
int size;
|
||||
int num;
|
||||
|
||||
#if 1 /* approx 6x speedup for mathutils types */
|
||||
|
||||
if ((size = VectorObject_Check(value) ? ((VectorObject *)value)->size : 0) ||
|
||||
(size = EulerObject_Check(value) ? 3 : 0) ||
|
||||
(size = QuaternionObject_Check(value) ? 4 : 0) ||
|
||||
(size = ColorObject_Check(value) ? 3 : 0)) {
|
||||
if ((num = VectorObject_Check(value) ? ((VectorObject *)value)->vec_num : 0) ||
|
||||
(num = EulerObject_Check(value) ? 3 : 0) || (num = QuaternionObject_Check(value) ? 4 : 0) ||
|
||||
(num = ColorObject_Check(value) ? 3 : 0)) {
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (size < array_min) {
|
||||
if (num < array_num) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s: sequence size is %d, expected > %d",
|
||||
error_prefix,
|
||||
size,
|
||||
array_min);
|
||||
num,
|
||||
array_num);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*array = PyMem_Malloc(size * sizeof(float));
|
||||
memcpy(*array, ((const BaseMathObject *)value)->data, size * sizeof(float));
|
||||
return size;
|
||||
*array = PyMem_Malloc(num * sizeof(float));
|
||||
memcpy(*array, ((const BaseMathObject *)value)->data, num * sizeof(float));
|
||||
return num;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -230,21 +228,21 @@ int mathutils_array_parse_alloc(float **array,
|
||||
return -1;
|
||||
}
|
||||
|
||||
size = PySequence_Fast_GET_SIZE(value_fast);
|
||||
num = PySequence_Fast_GET_SIZE(value_fast);
|
||||
|
||||
if (size < array_min) {
|
||||
if (num < array_num) {
|
||||
Py_DECREF(value_fast);
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s: sequence size is %d, expected > %d",
|
||||
error_prefix,
|
||||
size,
|
||||
array_min);
|
||||
num,
|
||||
array_num);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*array = PyMem_Malloc(size * sizeof(float));
|
||||
*array = PyMem_Malloc(num * sizeof(float));
|
||||
|
||||
ret = mathutils_array_parse_fast(*array, size, value_fast, error_prefix);
|
||||
ret = mathutils_array_parse_fast(*array, num, value_fast, error_prefix);
|
||||
Py_DECREF(value_fast);
|
||||
|
||||
if (ret == -1) {
|
||||
@@ -261,7 +259,7 @@ int mathutils_array_parse_alloc_v(float **array,
|
||||
{
|
||||
PyObject *value_fast;
|
||||
const int array_dim_flag = array_dim;
|
||||
int i, size;
|
||||
int i, num;
|
||||
|
||||
/* non list/tuple cases */
|
||||
if (!(value_fast = PySequence_Fast(value, error_prefix))) {
|
||||
@@ -269,30 +267,30 @@ int mathutils_array_parse_alloc_v(float **array,
|
||||
return -1;
|
||||
}
|
||||
|
||||
size = PySequence_Fast_GET_SIZE(value_fast);
|
||||
num = PySequence_Fast_GET_SIZE(value_fast);
|
||||
|
||||
if (size != 0) {
|
||||
if (num != 0) {
|
||||
PyObject **value_fast_items = PySequence_Fast_ITEMS(value_fast);
|
||||
float *fp;
|
||||
|
||||
array_dim &= ~MU_ARRAY_FLAGS;
|
||||
|
||||
fp = *array = PyMem_Malloc(size * array_dim * sizeof(float));
|
||||
fp = *array = PyMem_Malloc(num * array_dim * sizeof(float));
|
||||
|
||||
for (i = 0; i < size; i++, fp += array_dim) {
|
||||
for (i = 0; i < num; i++, fp += array_dim) {
|
||||
PyObject *item = value_fast_items[i];
|
||||
|
||||
if (mathutils_array_parse(fp, array_dim, array_dim_flag, item, error_prefix) == -1) {
|
||||
PyMem_Free(*array);
|
||||
*array = NULL;
|
||||
size = -1;
|
||||
num = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Py_DECREF(value_fast);
|
||||
return size;
|
||||
return num;
|
||||
}
|
||||
|
||||
int mathutils_int_array_parse(int *array, int array_dim, PyObject *value, const char *error_prefix)
|
||||
@@ -458,7 +456,7 @@ int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (((MatrixObject *)value)->num_row < 3 || ((MatrixObject *)value)->num_col < 3) {
|
||||
if (((MatrixObject *)value)->row_num < 3 || ((MatrixObject *)value)->col_num < 3) {
|
||||
PyErr_Format(
|
||||
PyExc_ValueError, "%.200s: matrix must have minimum 3x3 dimensions", error_prefix);
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user