MCPcopy Create free account
hub / github.com/blender/blender / mathutils_array_parse_alloc

Function mathutils_array_parse_alloc

source/blender/python/mathutils/mathutils.cc:195–260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

193}
194
195int 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);

Callers 6

Vector_vectorcallFunction · 0.85
C_Vector_RepeatFunction · 0.85
Vector_dotFunction · 0.85
Vector_projectFunction · 0.85
Vector_lerpFunction · 0.85
Vector_ass_sliceFunction · 0.85

Calls 1

Tested by

no test coverage detected