| 193 | } |
| 194 | |
| 195 | int mathutils_array_parse_alloc(float **array, |
| 196 | int array_num_min, |
| 197 | PyObject *value, |
| 198 | const char *error_prefix) |
| 199 | { |
| 200 | int num; |
| 201 | |
| 202 | #if 1 /* approx 6x speedup for mathutils types */ |
| 203 | |
| 204 | if ((num = VectorObject_Check(value) ? (reinterpret_cast<VectorObject *>(value))->vec_num : 0) || |
| 205 | (num = EulerObject_Check(value) ? 3 : 0) || (num = QuaternionObject_Check(value) ? 4 : 0) || |
| 206 | (num = ColorObject_Check(value) ? 3 : 0)) |
| 207 | { |
| 208 | if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) { |
| 209 | return -1; |
| 210 | } |
| 211 | |
| 212 | if (num < array_num_min) { |
| 213 | PyErr_Format(PyExc_ValueError, |
| 214 | "%.200s: sequence size is %d, expected >= %d", |
| 215 | error_prefix, |
| 216 | num, |
| 217 | array_num_min); |
| 218 | return -1; |
| 219 | } |
| 220 | |
| 221 | *array = static_cast<float *>(PyMem_Malloc(num * sizeof(float))); |
| 222 | memcpy(*array, (reinterpret_cast<const BaseMathObject *>(value))->data, num * sizeof(float)); |
| 223 | return num; |
| 224 | } |
| 225 | |
| 226 | #endif |
| 227 | |
| 228 | PyObject *value_fast = nullptr; |
| 229 | // *array = nullptr; |
| 230 | int ret; |
| 231 | |
| 232 | /* non list/tuple cases */ |
| 233 | if (!(value_fast = PySequence_Fast(value, error_prefix))) { |
| 234 | /* PySequence_Fast sets the error */ |
| 235 | return -1; |
| 236 | } |
| 237 | |
| 238 | num = PySequence_Fast_GET_SIZE(value_fast); |
| 239 | |
| 240 | if (num < array_num_min) { |
| 241 | Py_DECREF(value_fast); |
| 242 | PyErr_Format(PyExc_ValueError, |
| 243 | "%.200s: sequence size is %d, expected >= %d", |
| 244 | error_prefix, |
| 245 | num, |
| 246 | array_num_min); |
| 247 | return -1; |
| 248 | } |
| 249 | |
| 250 | *array = static_cast<float *>(PyMem_Malloc(num * sizeof(float))); |
| 251 | |
| 252 | ret = mathutils_array_parse_fast(*array, num, value_fast, error_prefix); |
no test coverage detected