39 #include "../generic/py_capi_utils.h"
44 # include "../mathutils/mathutils.h"
47 #define MAX_ARRAY_DIMENSION 10
95 const bool is_dynamic,
97 const char *item_type_str,
98 const char *error_prefix)
103 if (dim + 1 < totdim) {
105 const int seq_size = PySequence_Size(seq);
106 if (seq_size == -1) {
107 PyErr_Format(PyExc_ValueError,
108 "%s sequence expected at dimension %d, not '%s'",
111 Py_TYPE(seq)->tp_name);
114 for (i = 0; i < seq_size; i++) {
115 Py_ssize_t item_seq_size;
118 item = PySequence_GetItem(seq, i);
121 PyErr_Format(PyExc_TypeError,
122 "%s sequence type '%s' failed to retrieve index %d",
124 Py_TYPE(seq)->tp_name,
128 else if ((item_seq_size = PySequence_Size(item)) == -1) {
130 PyErr_Format(PyExc_TypeError,
131 "%s expected a sequence of %s, not %s",
134 Py_TYPE(item)->tp_name);
142 else if (item_seq_size != dimsize[dim + 1]) {
146 PyErr_Format(PyExc_ValueError,
147 "%s sequences of dimension %d should contain %d items, not %d",
161 error_prefix) == -1) {
174 const int seq_size = PySequence_Size(seq);
175 if (seq_size == -1) {
176 PyErr_Format(PyExc_ValueError,
177 "%s sequence expected at dimension %d, not '%s'",
180 Py_TYPE(seq)->tp_name);
183 if ((seq_size != dimsize[dim]) && (is_dynamic ==
false)) {
184 PyErr_Format(PyExc_ValueError,
185 "%s sequences of dimension %d should contain %d items, not %d",
193 for (i = 0; i < seq_size; i++) {
194 PyObject *item = PySequence_GetItem(seq, i);
197 PyErr_Format(PyExc_TypeError,
198 "%s sequence type '%s' failed to retrieve index %d",
200 Py_TYPE(seq)->tp_name,
204 if (!check_item_type(item)) {
209 error_str, error_str_size,
"sequence items should be of type %s", item_type_str);
211 PyErr_Format(PyExc_TypeError,
212 "%s expected sequence items of type %s, not %s",
215 Py_TYPE(item)->tp_name);
232 const Py_ssize_t seq_size = PySequence_Size(seq);
234 for (i = 0; i < seq_size; i++) {
235 PyObject *item = PySequence_GetItem(seq, i);
254 totitem = PySequence_Size(seq);
266 const char *error_prefix)
269 int tot, totdim,
len;
275 PyErr_Format(PyExc_ValueError,
276 "%s %.200s.%.200s, error validating the sequence length",
286 if (!RNA_property_dynamic_array_set_length(
ptr, prop, tot)) {
290 PyErr_Format(PyExc_ValueError,
291 "%s %s.%s: array length cannot be changed to %d",
331 for (i = lvalue_dim; i < totdim; i++) {
338 PyErr_Format(PyExc_ValueError,
339 "%s %.200s.%.200s, sequence must have %d items total, not %d",
359 const char *item_type_str,
361 const char *error_prefix)
369 if (lvalue_dim == 0) {
378 PyErr_Format(PyExc_ValueError,
379 "%s %.200s.%.200s, matrix assign to non float array",
386 PyErr_Format(PyExc_ValueError,
387 "%s %.200s.%.200s, matrix assign array with %d dimensions",
394 if (pymat->
num_col != dimsize[0] || pymat->
num_row != dimsize[1]) {
395 PyErr_Format(PyExc_ValueError,
396 "%s %.200s.%.200s, matrix assign dimension size mismatch, "
397 "is %dx%d, expected be %dx%d",
408 *r_totitem = dimsize[0] * dimsize[1];
423 error_prefix) == -1) {
445 char *value = (
void *)&value_buf;
447 convert_item->
func(&convert_item->
arg, item, value);
448 rna_set_index(
ptr, prop, *index, value);
452 convert_item->
func(&convert_item->
arg, item,
data);
470 const Py_ssize_t seq_size = PySequence_Size(seq);
482 if (seq_size == -1) {
494 memcpy(
data, pymat->matrix, allocsize);
504 for (i = 0; i < seq_size; i++) {
505 PyObject *item = PySequence_GetItem(seq, i);
507 if (dim + 1 < totdim) {
509 item,
ptr, prop, dim + 1,
data, item_size, index, convert_item, rna_set_index);
513 item,
ptr, prop,
data, item_size, index, convert_item, rna_set_index);
533 const char *item_type_str,
537 const char *error_prefix)
545 if (
validate_array(seq,
ptr, prop, 0, check_item_type, item_type_str, &totitem, error_prefix) ==
562 else if (param_data) {
566 data = PyMem_MALLOC(item_size * totitem);
572 if (param_data ==
NULL) {
574 rna_set_array(
ptr, prop,
data);
579 if (param_data ==
NULL) {
583 PyErr_Format(PyExc_TypeError,
584 "%s internal error parsing sequence of type '%s' after successful validation",
586 Py_TYPE(seq)->tp_name);
601 const char *item_type_str,
604 const char *error_prefix)
623 for (i = lvalue_dim; i < totdim; i++) {
627 index += arrayoffset;
629 if (lvalue_dim == totdim) {
630 if (!check_item_type(py)) {
631 PyErr_Format(PyExc_TypeError,
632 "%s %.200s.%.200s, expected a %s type, not %s",
637 Py_TYPE(py)->tp_name);
644 py,
ptr, prop, lvalue_dim, check_item_type, item_type_str, &totitem, error_prefix) ==
659 float value = (
float)PyFloat_AsDouble(py);
660 CLAMP(value, range[0], range[1]);
661 *(
float *)
data = value;
666 const int *range = arg->
int_data.range;
667 int value = PyC_Long_AsI32(py);
668 CLAMP(value, range[0], range[1]);
669 *(
int *)
data = value;
674 *(
bool *)
data = (
bool)PyObject_IsTrue(py);
680 return PyNumber_Check(py);
686 return PyLong_Check(py);
691 return PyBool_Check(py);
788 PyErr_SetString(PyExc_TypeError,
"not an array type");
803 const char *error_prefix)
859 PyErr_SetString(PyExc_TypeError,
"not an array type");
883 PyErr_SetString(PyExc_TypeError,
"not an array type");
894 static PyObject *pyrna_py_from_array_internal(
PointerRNA *
ptr,
905 tuple = PyTuple_New(
len);
907 for (i = 0; i <
len; i++) {
910 if (dim + 1 < totdim) {
911 item = pyrna_py_from_array_internal(
ptr, prop, dim + 1, index);
923 PyTuple_SET_ITEM(tuple, i, item);
938 arraydim =
self ?
self->arraydim : 0;
939 arrayoffset =
self ?
self->arrayoffset : 0;
943 if (index >=
len || index < 0) {
947 PyErr_SetString(PyExc_IndexError,
"out of range");
953 if (arraydim + 1 < totdim) {
955 ret->arraydim = arraydim + 1;
965 for (i = arraydim + 1; i < totdim; i++) {
969 ret->arrayoffset = arrayoffset + index;
972 index = arrayoffset + index;
976 return (PyObject *)
ret;
1006 PyErr_SetString(PyExc_TypeError,
"PropertyRNA - multi dimensional arrays not supported yet");
1014 const float value_f = PyFloat_AsDouble(value);
1015 if (value_f == -1 && PyErr_Occurred()) {
1023 if (
len *
sizeof(
float) >
sizeof(tmp)) {
1024 tmp_arr = PyMem_MALLOC(
len *
sizeof(
float));
1032 for (i = 0; i <
len; i++) {
1033 if (tmp_arr[i] == value_f) {
1038 if (tmp_arr != tmp) {
1039 PyMem_FREE(tmp_arr);
1042 return i <
len ? 1 : 0;
1047 const int value_i = PyC_Long_AsI32(value);
1048 if (value_i == -1 && PyErr_Occurred()) {
1056 if (
len *
sizeof(
int) >
sizeof(tmp)) {
1057 tmp_arr = PyMem_MALLOC(
len *
sizeof(
int));
1065 for (i = 0; i <
len; i++) {
1066 if (tmp_arr[i] == value_i) {
1071 if (tmp_arr != tmp) {
1072 PyMem_FREE(tmp_arr);
1075 return i <
len ? 1 : 0;
1081 if (value_i == -1 && PyErr_Occurred()) {
1089 if (
len *
sizeof(
bool) >
sizeof(tmp)) {
1090 tmp_arr = PyMem_MALLOC(
len *
sizeof(
bool));
1098 for (i = 0; i <
len; i++) {
1099 if (tmp_arr[i] == value_i) {
1104 if (tmp_arr != tmp) {
1105 PyMem_FREE(tmp_arr);
1108 return i <
len ? 1 : 0;
1115 PyErr_SetString(PyExc_TypeError,
"PropertyRNA - type not in float/bool/int");
typedef float(TangentPoint)[2]
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
struct CLG_LogRef * BPY_LOG_RNA
#define CLOG_WARN(clg_ref,...)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
Group RGB to Bright Vector Camera CLAMP
PyObject * pyrna_prop_CreatePyObject(PointerRNA *ptr, PropertyRNA *prop)
PyObject * pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop)
int pyrna_py_to_array(PointerRNA *ptr, PropertyRNA *prop, char *param_data, PyObject *py, const char *error_prefix)
static void py_to_int(const struct ItemConvertArgData *arg, PyObject *py, char *data)
static void int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, void *value)
#define MAX_ARRAY_DIMENSION
static int validate_array_length(PyObject *rvalue, PointerRNA *ptr, PropertyRNA *prop, int lvalue_dim, int *r_totitem, const char *error_prefix)
static void convert_item_init_int(PointerRNA *ptr, PropertyRNA *prop, ItemConvert_FuncArg *convert_item)
static int validate_array_type(PyObject *seq, int dim, int totdim, int dimsize[], const bool is_dynamic, ItemTypeCheckFunc check_item_type, const char *item_type_str, const char *error_prefix)
static int py_float_check(PyObject *py)
static void convert_item_init_bool(PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), ItemConvert_FuncArg *convert_item)
static int py_int_check(PyObject *py)
int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
static void bool_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, void *value)
void(* ItemConvertFunc)(const struct ItemConvertArgData *arg, PyObject *, char *)
int pyrna_py_to_array_index(PointerRNA *ptr, PropertyRNA *prop, int arraydim, int arrayoffset, int index, PyObject *py, const char *error_prefix)
static int validate_array(PyObject *rvalue, PointerRNA *ptr, PropertyRNA *prop, int lvalue_dim, ItemTypeCheckFunc check_item_type, const char *item_type_str, int *r_totitem, const char *error_prefix)
PyObject * pyrna_array_index(PointerRNA *ptr, PropertyRNA *prop, int index)
static char * copy_values(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop, int dim, char *data, uint item_size, int *index, const ItemConvert_FuncArg *convert_item, RNA_SetIndexFunc rna_set_index)
static void float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, void *value)
static int count_items(PyObject *seq, int dim)
static void py_to_float(const struct ItemConvertArgData *arg, PyObject *py, char *data)
static void convert_item_init_float(PointerRNA *ptr, PropertyRNA *prop, ItemConvert_FuncArg *convert_item)
void(* RNA_SetIndexFunc)(PointerRNA *, PropertyRNA *, int index, void *)
PyObject * pyrna_py_from_array(PointerRNA *ptr, PropertyRNA *prop)
static void py_to_bool(const struct ItemConvertArgData *UNUSED(arg), PyObject *py, char *data)
struct ItemConvert_FuncArg ItemConvert_FuncArg
PyObject * pyrna_py_from_array_index(BPy_PropertyArrayRNA *self, PointerRNA *ptr, PropertyRNA *prop, int index)
static int py_to_array(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop, char *param_data, ItemTypeCheckFunc check_item_type, const char *item_type_str, int item_size, const ItemConvert_FuncArg *convert_item, RNA_SetArrayFunc rna_set_array, const char *error_prefix)
static char * copy_value_single(PyObject *item, PointerRNA *ptr, PropertyRNA *prop, char *data, uint item_size, int *index, const ItemConvert_FuncArg *convert_item, RNA_SetIndexFunc rna_set_index)
static int py_to_array_index(PyObject *py, PointerRNA *ptr, PropertyRNA *prop, int lvalue_dim, int arrayoffset, int index, ItemTypeCheckFunc check_item_type, const char *item_type_str, const ItemConvert_FuncArg *convert_item, RNA_SetIndexFunc rna_set_index, const char *error_prefix)
void(* RNA_SetArrayFunc)(PointerRNA *, PropertyRNA *, const char *)
int(* ItemTypeCheckFunc)(PyObject *)
static int py_bool_check(PyObject *py)
void *(* MEM_callocN)(size_t len, const char *str)
#define BaseMath_ReadCallback(_self)
#define MatrixObject_Check(v)
int PyC_Long_AsBool(PyObject *value)
const char * RNA_struct_identifier(const StructRNA *type)
void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, bool value)
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
const char * RNA_property_identifier(const PropertyRNA *prop)
void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, float value)
int RNA_property_array_dimension(PointerRNA *ptr, PropertyRNA *prop, int length[])
float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin, float *hardmax)
void RNA_property_boolean_get_array(PointerRNA *ptr, PropertyRNA *prop, bool *values)
PropertyType RNA_property_type(PropertyRNA *prop)
void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value)
int RNA_property_flag(PropertyRNA *prop)
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, int *hardmax)
bool RNA_property_boolean_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
int RNA_property_multi_array_length(PointerRNA *ptr, PropertyRNA *prop, int dim)
void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const bool *values)
struct ItemConvertArgData::@1127::@1129 int_data
struct ItemConvertArgData::@1127::@1130 float_data
struct ItemConvertArgData arg