26#define USE_STRING_COERCE
28#ifdef USE_STRING_COERCE
64#ifdef USE_STRING_COERCE
97 return reinterpret_cast<PyObject *
>(group);
110 return reinterpret_cast<PyObject *
>(
array);
115 PyObject *
seq = PyList_New(prop->
len);
121 PyExc_RuntimeError,
"%s: IDP_IDPARRAY: PyList_New(%d) failed", __func__, prop->
len);
125 for (i = 0; i < prop->
len; i++) {
129 if (
wrap ==
nullptr) [[unlikely]] {
154 return PyUnicode_FromFormat(
"<bpy id prop: owner=\"%s\", name=\"%s\", address=%p>",
162 switch (prop->
type) {
188static int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject *value)
190 switch (prop->type) {
193 if (!PyUnicode_Check(value)) {
194 PyErr_SetString(PyExc_TypeError,
"expected a string!");
198# ifdef USE_STRING_COERCE
201 PyObject *value_coerce =
nullptr;
204 alloc_len = strlen(st) + 1;
206 st = PyUnicode_AsUTF8(value);
209 Py_XDECREF(value_coerce);
212 length_ssize_t st_len;
213 st = PyUnicode_AsUTF8AndSize(value, &st_len);
222 int ivalue = PyLong_AsSsize_t(value);
223 if (ivalue == -1 && PyErr_Occurred()) {
224 PyErr_SetString(PyExc_TypeError,
"expected an int type");
231 float fvalue =
float(PyFloat_AsDouble(value));
232 if (fvalue == -1 && PyErr_Occurred()) {
233 PyErr_SetString(PyExc_TypeError,
"expected a float");
240 double dvalue = PyFloat_AsDouble(value);
241 if (dvalue == -1 && PyErr_Occurred()) {
242 PyErr_SetString(PyExc_TypeError,
"expected a float");
249 PyErr_SetString(PyExc_AttributeError,
"attempt to set read-only attribute!");
258 BPy_IDGroup_GetName_doc,
259 "The name of this Group.\n"
264 return PyUnicode_FromString(self->
prop->
name);
272 if (!PyUnicode_Check(value)) {
273 PyErr_SetString(PyExc_TypeError,
"expected a string!");
277 name = PyUnicode_AsUTF8AndSize(value, &name_len);
280 PyErr_SetString(PyExc_TypeError,
"string length cannot exceed 63 characters!");
288 PyErr_SetString(PyExc_NameError,
"property name already exists in parent group");
293 memcpy(self->
prop->
name, name, name_len + 1);
298static PyObject *BPy_IDGroup_GetType(BPy_IDProperty *self)
300 return PyLong_FromLong(self->prop->type);
308 BPy_IDGroup_GetName_doc,
310 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr},
316 PyErr_SetString(PyExc_TypeError,
"len() of unsized object");
329 PyErr_SetString(PyExc_TypeError,
"unsubscriptable object");
333 name = PyUnicode_AsUTF8(item);
335 if (name ==
nullptr) {
336 PyErr_SetString(PyExc_TypeError,
"only strings are allowed as keys of ID properties");
343 PyErr_SetString(PyExc_KeyError,
"key not in subgroup dict");
354 PyObject **seq_fast_items = PySequence_Fast_ITEMS(seq_fast);
358 Py_ssize_t i,
len = PySequence_Fast_GET_SIZE(seq_fast);
360 for (i = 0; i <
len; i++) {
361 item = seq_fast_items[i];
362 if (PyFloat_Check(item)) {
370 else if (PyBool_Check(item)) {
377 else if (PyLong_Check(item)) {
384 else if (PyMapping_Check(item)) {
401 const char *name =
nullptr;
404 name = PyUnicode_AsUTF8AndSize(name_obj, &name_len);
406 if (name ==
nullptr) {
407 PyErr_Format(PyExc_KeyError,
408 "invalid id-property key, expected a string, not a %.200s",
409 Py_TYPE(name_obj)->tp_name);
414 PyErr_SetString(PyExc_KeyError,
415 "the length of IDProperty names is limited to 63 characters");
453 const bool do_conversion,
454 const bool can_create)
457 const double value = PyFloat_AsDouble(ob);
463 else if (do_conversion) {
464 switch (prop_exist->
type) {
481 if (!prop && can_create) {
490 const bool do_conversion,
491 const bool can_create)
500 else if (do_conversion) {
501 switch (prop_exist->
type) {
518 if (!prop && can_create) {
527 const bool do_conversion,
528 const bool can_create)
533 const int value = PyC_Long_AsI32(ob);
534 if (value == -1 && PyErr_Occurred()) {
540 else if (do_conversion) {
541 const int64_t value = PyC_Long_AsI64(ob);
542 if (value == -1 && PyErr_Occurred()) {
545 switch (prop_exist->
type) {
565 if (!prop && can_create) {
566 const int value = PyC_Long_AsI32(ob);
567 if (value == -1 && PyErr_Occurred()) {
579 const bool can_create)
582 Py_ssize_t value_len = 0;
583 const char *value =
nullptr;
585#ifdef USE_STRING_COERCE
586 PyObject *value_coerce =
nullptr;
589 value = PyUnicode_AsUTF8AndSize(ob, &value_len);
600 if (!prop && can_create) {
603 val.
string.len = int(value_len) + 1;
608#ifdef USE_STRING_COERCE
609 Py_XDECREF(value_coerce);
619 const bool can_create)
622 Py_ssize_t value_len = PyBytes_GET_SIZE(ob);
623 const char *value = PyBytes_AS_STRING(ob);
633 if (!prop && can_create) {
636 val.
string.len = int(value_len);
685 const Py_buffer &buffer,
688 const bool can_create)
701 if (!prop && can_create) {
703 val.
array.type = idp_type;
704 val.
array.len = buffer.len / buffer.itemsize;
714 const bool do_conversion,
715 const bool can_create)
720 PyObject **ob_seq_fast_items;
724 ob_seq_fast_items = PySequence_Fast_ITEMS(ob);
729 if (val.
array.type ==
char(-1)) {
730 PyErr_SetString(PyExc_TypeError,
731 "only floats, ints, booleans and dicts are allowed in ID property arrays");
736 PyErr_SetString(PyExc_RuntimeError,
"internal error with idp array.type");
741 val.
array.len = PySequence_Fast_GET_SIZE(ob);
748 if (prop_exist && prop_exist->
len == val.
array.len) {
749 switch (val.
array.type) {
759 for (i = 0; i < val.
array.len; i++) {
760 item = ob_seq_fast_items[i];
761 const double value = PyFloat_AsDouble(item);
762 if ((value == -1.0) && PyErr_Occurred()) {
766 static_cast<float *
>(prop_data)[i] =
float(value);
769 static_cast<double *
>(prop_data)[i] = value;
784 for (i = 0; i < val.
array.len; i++) {
785 item = ob_seq_fast_items[i];
787 const int64_t value = PyC_Long_AsI64(item);
788 if ((value == -1) && PyErr_Occurred()) {
792 static_cast<float *
>(prop_data)[i] =
float(value);
795 static_cast<double *
>(prop_data)[i] =
double(value);
799 const int value = PyC_Long_AsI32(item);
800 if ((value == -1) && PyErr_Occurred()) {
803 static_cast<int *
>(prop_data)[i] = value;
817 for (i = 0; i < val.
array.len; i++) {
818 item = ob_seq_fast_items[i];
820 if ((value == -1) && PyErr_Occurred()) {
824 static_cast<int *
>(prop_data)[i] = value;
827 static_cast<bool *
>(prop_data)[i] =
bool(value);
839 if (prop || !can_create) {
843 switch (val.
array.type) {
848 for (i = 0; i < val.
array.len; i++) {
849 item = ob_seq_fast_items[i];
850 if (((prop_data[i] = PyFloat_AsDouble(item)) == -1.0) && PyErr_Occurred()) {
861 for (i = 0; i < val.
array.len; i++) {
862 item = ob_seq_fast_items[i];
863 if (((prop_data[i] = PyC_Long_AsI32(item)) == -1) && PyErr_Occurred()) {
872 for (i = 0; i < val.
array.len; i++) {
873 item = ob_seq_fast_items[i];
884 for (i = 0; i < val.
array.len; i++) {
885 item = ob_seq_fast_items[i];
887 if ((value == -1) && PyErr_Occurred()) {
891 prop_data[i] = (value != 0);
902 const bool do_conversion,
903 const bool can_create)
906 bool use_buffer =
false;
907 int idp_buffer_type = -1;
909 if (PyObject_CheckBuffer(ob)) {
910 if (PyObject_GetBuffer(ob, &buffer, PyBUF_ND | PyBUF_FORMAT) == -1) {
917 if (idp_buffer_type != -1) {
920 if (!can_create && (!prop_exist || (prop_exist->
type != idp_buffer_type) ||
921 (prop_exist->
len != buffer.len)))
923 PyBuffer_Release(&buffer);
930 PyBuffer_Release(&buffer);
937 prop_exist, name, buffer, idp_buffer_type, do_conversion, can_create);
938 PyBuffer_Release(&buffer);
942 PyObject *ob_seq_fast = PySequence_Fast(ob,
"py -> idprop");
943 if (ob_seq_fast !=
nullptr) {
945 prop_exist, name, ob_seq_fast, do_conversion, can_create);
946 Py_DECREF(ob_seq_fast);
963 PyObject *keys, *vals, *key, *pval;
966 len = PyMapping_Length(ob);
970 keys = PyMapping_Keys(ob);
971 if (keys ==
nullptr) {
974 vals = PyMapping_Values(ob);
975 if (vals ==
nullptr) {
983 for (i = 0; i <
len; i++) {
984 key = PySequence_GetItem(keys, i);
985 pval = PySequence_GetItem(vals, i);
1007 const bool can_create)
1010 ID *value =
nullptr;
1014 PyErr_SetString(PyExc_ValueError,
"Cannot assign an embedded ID pointer to an id-property");
1025 if (!prop && can_create) {
1034 const bool do_conversion,
1035 const bool can_create)
1037 if (name ==
nullptr) {
1041 if (PyFloat_Check(ob)) {
1044 if (PyBool_Check(ob)) {
1045 return idp_from_PyBool(prop_exist, name, ob, do_conversion, can_create);
1047 if (PyLong_Check(ob)) {
1048 return idp_from_PyLong(prop_exist, name, ob, do_conversion, can_create);
1050 if (PyUnicode_Check(ob)) {
1053 if (PyBytes_Check(ob)) {
1056 if (PySequence_Check(ob)) {
1062 if (PyMapping_Check(ob)) {
1067 PyExc_TypeError,
"invalid id-property type %.200s not supported", Py_TYPE(ob)->tp_name);
1087 if (new_prop ==
nullptr) {
1093 MEM_delete(new_prop);
1105 if (prop != prop_exist) {
1106 PyErr_Format(PyExc_TypeError,
1107 "Cannot assign a '%.200s' value to the existing '%s' %s IDProperty",
1108 Py_TYPE(ob)->tp_name,
1119 if (new_prop ==
nullptr) {
1122 if (new_prop == prop_exist) {
1137 prop_exist->
ui_data =
nullptr;
1151 PyErr_SetString(PyExc_TypeError,
"unsubscriptable object");
1155 if (val ==
nullptr) {
1157 const char *name = PyUnicode_AsUTF8(key);
1159 if (name ==
nullptr) {
1160 PyErr_Format(PyExc_KeyError,
"expected a string, not %.200s", Py_TYPE(key)->tp_name);
1170 PyErr_SetString(PyExc_KeyError,
"property not found in group");
1194 ret = PyObject_GetIter(iterable);
1195 Py_DECREF(iterable);
1205 switch (prop->
type) {
1219 PyObject *
seq = PyList_New(prop->
len);
1224 PyExc_RuntimeError,
"%s: IDP_ARRAY: PyList_New(%d) failed", __func__, prop->
len);
1231 for (i = 0; i < prop->
len; i++) {
1232 PyList_SET_ITEM(
seq, i, PyFloat_FromDouble(
array[i]));
1238 for (i = 0; i < prop->
len; i++) {
1239 PyList_SET_ITEM(
seq, i, PyFloat_FromDouble(
array[i]));
1245 for (i = 0; i < prop->
len; i++) {
1246 PyList_SET_ITEM(
seq, i, PyLong_FromLong(
array[i]));
1252 for (i = 0; i < prop->
len; i++) {
1253 PyList_SET_ITEM(
seq, i, PyBool_FromLong(
array[i]));
1259 PyExc_RuntimeError,
"%s: invalid/corrupt array type '%d'!", __func__, prop->
subtype);
1267 PyObject *
seq = PyList_New(prop->
len);
1273 PyExc_RuntimeError,
"%s: IDP_IDPARRAY: PyList_New(%d) failed", __func__, prop->
len);
1277 for (i = 0; i < prop->
len; i++) {
1281 if (
wrap ==
nullptr) [[unlikely]] {
1286 PyList_SET_ITEM(
seq, i,
wrap);
1291 PyObject *dict = _PyDict_NewPresized(prop->
len);
1294 for (loop = prop->
data.
group.first(); loop; loop = loop->
next) {
1298 if (
wrap ==
nullptr) [[unlikely]] {
1303 PyDict_SetItemString(dict, loop->
name,
wrap);
1310 PyErr_Format(PyExc_RuntimeError,
1311 "%s ERROR: '%s' property exists with a bad type code '%d'!",
1326 if (self->
group ==
nullptr) {
1327 return PyUnicode_FromFormat(
"<%s>", Py_TYPE(self)->tp_name);
1329 return PyUnicode_FromFormat(
"<%s \"%s\">", Py_TYPE(self)->tp_name, self->
group->
prop->
name);
1334 if (self->
group !=
nullptr) {
1335 PyObject_GC_UnTrack(self);
1337 Py_CLEAR(self->
group);
1338 PyObject_GC_Del(self);
1343 Py_VISIT(self->
group);
1349 Py_CLEAR(self->
group);
1355 return (self->
group !=
nullptr);
1363 PyErr_SetString(PyExc_RuntimeError,
"IDPropertyGroup changed size during iteration");
1369 if (self->
cur !=
nullptr) {
1376 return PyUnicode_FromString(cur->
name);
1378 PyErr_SetNone(PyExc_StopIteration);
1384 if (self->
cur !=
nullptr) {
1393 PyErr_SetNone(PyExc_StopIteration);
1399 if (self->
cur !=
nullptr) {
1406 PyObject *
ret = PyTuple_New(2);
1408 PyUnicode_FromString(cur->
name),
1412 PyErr_SetNone(PyExc_StopIteration);
1416PyDoc_STRVAR(BPy_IDGroup_IterKeys_doc,
"Iterator over :class:`IDPropertyGroup` keys.");
1417PyDoc_STRVAR(BPy_IDGroup_IterValues_doc,
"Iterator over :class:`IDPropertyGroup` values.");
1419 "Iterator over :class:`IDPropertyGroup` items (key/value pairs).");
1428#define SHARED_MEMBER_SET(member, value) \
1430 k_ty->member = v_ty->member = i_ty->member = value; \
1439 k_ty->tp_name =
"IDPropertyGroupIterKeys";
1440 v_ty->tp_name =
"IDPropertyGroupIterValues";
1441 i_ty->tp_name =
"IDPropertyGroupIterItems";
1443 k_ty->tp_doc = BPy_IDGroup_IterKeys_doc;
1444 v_ty->tp_doc = BPy_IDGroup_IterValues_doc;
1445 i_ty->tp_doc = BPy_IDGroup_IterItems_doc;
1461#undef SHARED_MEMBER_SET
1465 const bool reversed,
1471 iter->
group = group;
1472 if (group !=
nullptr) {
1474 BLI_assert(!PyObject_GC_IsTracked((PyObject *)iter));
1475 PyObject_GC_Track(iter);
1478 iter->len_init = group->
prop->
len;
1481 iter->
cur =
nullptr;
1484 return reinterpret_cast<PyObject *
>(iter);
1520 if (self->
group ==
nullptr) {
1521 return PyUnicode_FromFormat(
"<%s>", Py_TYPE(self)->tp_name);
1523 return PyUnicode_FromFormat(
"<%s \"%s\">", Py_TYPE(self)->tp_name, self->
group->
prop->
name);
1528 if (self->
group !=
nullptr) {
1529 PyObject_GC_UnTrack(self);
1531 Py_CLEAR(self->
group);
1532 PyObject_GC_Del(self);
1537 Py_VISIT(self->
group);
1543 Py_CLEAR(self->
group);
1549 return (self->
group !=
nullptr);
1571 if (self->
group ==
nullptr) {
1579 if (self->
group ==
nullptr) {
1587 if (self->
group ==
nullptr) {
1591 PyObject *
list = PySequence_List(
reinterpret_cast<PyObject *
>(self));
1592 const int result = PySequence_Contains(
list, value);
1599 if (self->
group ==
nullptr) {
1603 PyObject *
list = PySequence_List(
reinterpret_cast<PyObject *
>(self));
1604 const int result = PySequence_Contains(
list, value);
1646 BPy_IDGroup_View_reversed_doc,
1647 "Return a reverse iterator over the ID Property keys values or items.");
1652 return reinterpret_cast<PyObject *
>(
result);
1659 BPy_IDGroup_View_reversed_doc},
1665 BPy_IDGroup_ViewKeys_doc,
1666 "A view of :class:`IDPropertyGroup` keys "
1667 "(supports ``len()``, ``in``, iteration, and ``reversed()``).");
1670 BPy_IDGroup_ViewValues_doc,
1671 "A view of :class:`IDPropertyGroup` values "
1672 "(supports ``len()``, ``in``, iteration, and ``reversed()``).");
1675 BPy_IDGroup_ViewItems_doc,
1676 "A view of :class:`IDPropertyGroup` items as key/value pairs "
1677 "(supports ``len()``, ``in``, iteration, and ``reversed()``).");
1691 k_ty->tp_name =
"IDPropertyGroupViewKeys";
1692 v_ty->tp_name =
"IDPropertyGroupViewValues";
1693 i_ty->tp_name =
"IDPropertyGroupViewItems";
1695 k_ty->tp_doc = BPy_IDGroup_ViewKeys_doc;
1696 v_ty->tp_doc = BPy_IDGroup_ViewValues_doc;
1697 i_ty->tp_doc = BPy_IDGroup_ViewItems_doc;
1708#define SHARED_MEMBER_SET(member, value) \
1710 k_ty->member = v_ty->member = i_ty->member = value; \
1723#undef SHARED_MEMBER_SET
1734 BPy_IDGroup_pop_doc,
1735 ".. method:: pop(key, default)\n"
1737 " Remove an item from the group, returning a Python representation.\n"
1739 " :raises KeyError: When the item doesn't exist and no *default* is given.\n"
1741 " :param key: Name of item to remove.\n"
1743 " :param default: Value to return when *key* isn't found "
1744 "(optional, a :exc:`KeyError` is raised when omitted and the key is not found).\n"
1745 " :type default: Any\n"
1746 " :return: A Python representation of the removed item, or *default*.\n"
1754 PyObject *def =
nullptr;
1756 if (!PyArg_ParseTuple(args,
1769 if (def ==
nullptr) {
1770 PyErr_SetString(PyExc_KeyError,
"item not in group");
1773 return Py_NewRef(def);
1777 if (pyform ==
nullptr) {
1792 printf(
"%s: ID Property Error found and corrected!\n", func);
1795 for (j =
len; j < prop->
len; j++) {
1796 PyList_SET_ITEM(
seq, j, Py_NewRef(Py_None));
1805 PyObject *
list = PyList_New(prop->
len);
1809 for (i = 0, loop = prop->
data.
group.first(); loop && (i < prop->
len); loop = loop->
next, i++) {
1810 PyList_SET_ITEM(
list, i, PyUnicode_FromString(loop->
name));
1814 for (; loop; loop = loop->
next, i++) {
1818 if (i != prop->
len) {
1830 PyObject *
list = PyList_New(prop->
len);
1834 for (i = 0, loop = prop->
data.
group.first(); loop; loop = loop->
next, i++) {
1838 if (i != prop->
len) {
1850 PyObject *
seq = PyList_New(prop->
len);
1854 for (i = 0, loop = prop->
data.
group.first(); loop; loop = loop->
next, i++) {
1855 PyObject *item = PyTuple_New(2);
1858 PyList_SET_ITEM(
seq, i, item);
1861 if (i != prop->
len) {
1897 BPy_IDGroup_keys_doc,
1898 ".. method:: keys()\n"
1900 " Return a view of the keys in the group.\n"
1902 " :return: A view of the keys.\n"
1903 " :rtype: :class:`IDPropertyGroupViewKeys`\n");
1911 BPy_IDGroup_values_doc,
1912 ".. method:: values()\n"
1914 " Return the values associated with this group.\n"
1916 " :return: A view of the values.\n"
1917 " :rtype: :class:`IDPropertyGroupViewValues`\n");
1925 BPy_IDGroup_items_doc,
1926 ".. method:: items()\n"
1928 " Return a view of the items in the group, behaves like dictionary method items.\n"
1930 " :return: A view of the items.\n"
1931 " :rtype: :class:`IDPropertyGroupViewItems`\n");
1939 const char *name = PyUnicode_AsUTF8(value);
1942 PyErr_Format(PyExc_TypeError,
"expected a string, not a %.200s", Py_TYPE(value)->tp_name);
1951 BPy_IDGroup_update_doc,
1952 ".. method:: update(other)\n"
1954 " Update key-value pairs from *other*, overwriting existing keys.\n"
1958 " Unlike :meth:`dict.update`, keyword arguments are not supported.\n"
1960 " :param other: Updates the values in the group with this.\n"
1962 " :type other: :class:`IDPropertyGroup` | dict[str, Any]\n");
1965 PyObject *pkey, *pval;
1970 if (self->
prop == other->
prop) [[unlikely]] {
1977 else if (PyDict_Check(value)) {
1978 while (PyDict_Next(value, &i, &pkey, &pval)) {
1980 if (PyErr_Occurred()) {
1986 PyErr_Format(PyExc_TypeError,
1987 "expected a dict or an IDPropertyGroup type, not a %.200s",
1988 Py_TYPE(value)->tp_name);
1997 BPy_IDGroup_to_dict_doc,
1998 ".. method:: to_dict()\n"
2000 " Return a purely Python version of the group.\n"
2002 " :return: A dictionary representation of the group.\n"
2003 " :rtype: dict[str, Any]\n");
2011 BPy_IDGroup_clear_doc,
2012 ".. method:: clear()\n"
2014 " Clear all members from this group.\n");
2023 BPy_IDGroup_get_doc,
2024 ".. method:: get(key, default=None)\n"
2026 " Return the value for key, if it exists, else default.\n"
2028 " :param key: The key to look up.\n"
2030 " :param default: Value to return if *key* is not found.\n"
2031 " :type default: Any\n"
2032 " :return: The value for the key, or *default* if not found.\n"
2038 PyObject *def = Py_None;
2040 if (!PyArg_ParseTuple(args,
2065# pragma clang diagnostic push
2066# pragma clang diagnostic ignored "-Wcast-function-type"
2068# pragma GCC diagnostic push
2069# pragma GCC diagnostic ignored "-Wcast-function-type"
2074 {
"pop",
reinterpret_cast<PyCFunction
>(
BPy_IDGroup_pop), METH_VARARGS, BPy_IDGroup_pop_doc},
2075 {
"keys",
reinterpret_cast<PyCFunction
>(
BPy_IDGroup_keys), METH_NOARGS, BPy_IDGroup_keys_doc},
2079 BPy_IDGroup_values_doc},
2083 BPy_IDGroup_items_doc},
2084 {
"update",
reinterpret_cast<PyCFunction
>(
BPy_IDGroup_update), METH_O, BPy_IDGroup_update_doc},
2085 {
"get",
reinterpret_cast<PyCFunction
>(
BPy_IDGroup_get), METH_VARARGS, BPy_IDGroup_get_doc},
2089 BPy_IDGroup_to_dict_doc},
2093 BPy_IDGroup_clear_doc},
2094 {
nullptr,
nullptr, 0,
nullptr},
2099# pragma clang diagnostic pop
2101# pragma GCC diagnostic pop
2133 BPy_IDGroup_Type_doc,
2134 "A dictionary-like group of ID properties, "
2135 "supporting key access, iteration, and membership testing.\n"
2139 " Only supports a maximum of 1024 levels of nesting.");
2142 PyVarObject_HEAD_INIT(
nullptr, 0)
2163 BPy_IDGroup_Type_doc,
2204 *elem_size =
sizeof(
float);
2205 return &PyFloat_Type;
2207 *elem_size =
sizeof(double);
2208 return &PyFloat_Type;
2210 *elem_size =
sizeof(
int8_t);
2211 return &PyBool_Type;
2213 *elem_size =
sizeof(int);
2214 return &PyLong_Type;
2223 return PyUnicode_FromFormat(
"<bpy id property array [%d]>", self->
prop->
len);
2228 BPy_IDArray_get_typecode_doc,
2229 "The type of the data in the array "
2230 "{'f': float (32-bit), 'd': double (64-bit), 'i': int, 'b': bool}. "
2231 "Both 'f' and 'd' use Python's :class:`float` type but differ in storage precision.\n"
2233 ":type: Literal['f', 'd', 'i', 'b']\n");
2236 const char *typecode;
2251 PyErr_Format(PyExc_RuntimeError,
2252 "%s: invalid/corrupt array type '%d'!",
2259 return PyUnicode_FromString(typecode);
2266 static_cast<setter
>(
nullptr),
2267 BPy_IDArray_get_typecode_doc,
2269 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr},
2274 BPy_IDArray_to_list_doc,
2275 ".. method:: to_list()\n"
2277 " Return the array as a list.\n"
2279 " :return: The array as a list.\n"
2280 " :rtype: list[int] | list[float] | list[bool]\n");
2288# pragma clang diagnostic push
2289# pragma clang diagnostic ignored "-Wcast-function-type"
2291# pragma GCC diagnostic push
2292# pragma GCC diagnostic ignored "-Wcast-function-type"
2300 BPy_IDArray_to_list_doc},
2301 {
nullptr,
nullptr, 0,
nullptr},
2306# pragma clang diagnostic pop
2308# pragma GCC diagnostic pop
2319 if (index < 0 || index >= self->
prop->
len) {
2320 PyErr_SetString(PyExc_IndexError,
"index out of range!");
2336 PyExc_RuntimeError,
"%s: invalid/corrupt array type '%d'!", __func__, self->
prop->
subtype);
2343 if (index < 0 || index >= self->
prop->
len) {
2344 PyErr_SetString(PyExc_RuntimeError,
"index out of range!");
2350 const float f =
float(PyFloat_AsDouble(value));
2351 if (f == -1 && PyErr_Occurred()) {
2358 const double d = PyFloat_AsDouble(value);
2359 if (d == -1 && PyErr_Occurred()) {
2366 const int i = PyC_Long_AsI32(value);
2367 if (i == -1 && PyErr_Occurred()) {
2376 if (i == -1 && PyErr_Occurred()) {
2409 end = prop->
len + end + 1;
2414 tuple = PyTuple_New(end -
begin);
2419 for (count =
begin; count < end; count++) {
2420 PyTuple_SET_ITEM(tuple, count -
begin, PyFloat_FromDouble(
array[count]));
2426 for (count =
begin; count < end; count++) {
2427 PyTuple_SET_ITEM(tuple, count -
begin, PyFloat_FromDouble(
array[count]));
2433 for (count =
begin; count < end; count++) {
2434 PyTuple_SET_ITEM(tuple, count -
begin, PyLong_FromLong(
array[count]));
2440 for (count =
begin; count < end; count++) {
2441 PyTuple_SET_ITEM(tuple, count -
begin, PyBool_FromLong(
long(
array[count])));
2463 size = (end -
begin);
2464 alloc_len = size * elem_size;
2469 if (
PyC_AsArray(vec, elem_size,
seq, size, py_type,
"slice assignment: ") == -1) {
2485 if (PyIndex_Check(item)) {
2487 i = PyNumber_AsSsize_t(item, PyExc_IndexError);
2488 if (i == -1 && PyErr_Occurred()) {
2496 if (PySlice_Check(item)) {
2497 Py_ssize_t start, stop,
step, slicelength;
2499 if (PySlice_GetIndicesEx(item, self->
prop->
len, &start, &stop, &
step, &slicelength) < 0) {
2503 if (slicelength <= 0) {
2504 return PyTuple_New(0);
2510 PyErr_SetString(PyExc_TypeError,
"slice steps not supported with vectors");
2514 PyErr_Format(PyExc_TypeError,
2515 "vector indices must be integers, not %.200s",
2517 Py_TYPE(item)->tp_name);
2523 if (PyIndex_Check(item)) {
2524 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
2525 if (i == -1 && PyErr_Occurred()) {
2533 if (PySlice_Check(item)) {
2534 Py_ssize_t start, stop,
step, slicelength;
2536 if (PySlice_GetIndicesEx(item, self->
prop->
len, &start, &stop, &
step, &slicelength) < 0) {
2544 PyErr_SetString(PyExc_TypeError,
"slice steps not supported with vectors");
2549 PyExc_TypeError,
"vector indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
2565 return sizeof(
float);
2568 return sizeof(double);
2571 return sizeof(bool);
2580 const int length = itemsize * prop->
len;
2582 if (PyBuffer_FillInfo(view,
2583 reinterpret_cast<PyObject *
>(self),
2592 view->itemsize = itemsize;
2596 shape[0] = prop->
len;
2597 view->shape = shape;
2604 MEM_delete(view->shape);
2620 BPy_IDArray_Type_doc,
2621 "An array of values with a fixed type, "
2622 "supporting indexing and slicing.");
2625 PyVarObject_HEAD_INIT(
nullptr, 0)
2646 BPy_IDArray_Type_doc,
2712 iter->
group = group;
2713 if (group !=
nullptr) {
2715 BLI_assert(!PyObject_GC_IsTracked((PyObject *)iter));
2716 PyObject_GC_Track(iter);
2723 return reinterpret_cast<PyObject *
>(
2729 return reinterpret_cast<PyObject *
>(
2735 return reinterpret_cast<PyObject *
>(
2759 PyObject *submodule;
2791 {
nullptr,
nullptr, 0,
nullptr},
2797 "This module provides access to ID property types, used for\n"
2798 "custom properties on data-blocks, accessed via ``[\"key\"]`` syntax.\n"
2800 "- See :ref:`info_quickstart-custom_properties` for example usage.\n"
2801 "- See :ref:`bpy_types-custom_properties` for types that support custom properties.\n");
2817 PyObject *submodule;
2818 PyObject *sys_modules = PyImport_GetModuleDict();
#define IDP_float_get(prop)
#define IDP_array_voidp_get(prop)
#define IDP_bool_set(prop, value)
#define IDP_int_get(prop)
#define IDP_array_double_get(prop)
#define IDP_int_set(prop, value)
#define IDP_string_get(prop)
#define IDP_double_get(prop)
#define IDP_array_bool_get(prop)
#define IDP_array_int_get(prop)
#define IDP_property_array_get(prop)
#define IDP_float_set(prop, value)
#define IDP_double_set(prop, value)
#define IDP_array_float_get(prop)
#define IDP_bool_get(prop)
ID and Library types, which are fundamental for SDNA.
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
VecBase< float, D > constexpr mod(VecOp< float, D >, VecOp< float, D >) RET
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
float length(VecOp< float, D >) RET
#define SHARED_MEMBER_SET(member, value)
#define BPy_IDGroup_Check(v)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
std::unique_ptr< IDProperty, IDPropertyDeleter > create_bool(StringRef prop_name, bool value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_BOOLEAN, set its name and value.
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRef prop_name, int32_t value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_INT, set its name and value.
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRef prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
BLI_INLINE ColorTheme4f to_float(const ColorTheme4b &theme4b)
BLI_INLINE Texture * wrap(MTLTexture *texture)
static PyObject * BPy_IDArray_GetItem(BPy_IDArray *self, Py_ssize_t index)
bool BPy_IDProperty_Map_ValidateAndCreate(PyObject *key, IDProperty *group, PyObject *ob)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
PyObject * BPyInit_idprop()
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bool pyrna_id_CheckPyObject(PyObject *obj)
void IDP_FreeFromGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
static const char * idp_try_read_name(PyObject *name_obj)
static PyObject * BPy_IDGroup_IterItems_CreatePyObject(BPy_IDProperty *group, const bool reversed)
static PyMappingMethods BPy_IDArray_AsMapping
static PyObject * idprop_py_from_idp_group(ID *id, IDProperty *prop, IDProperty *parent)
static PyObject * BPy_Group_ViewValues_iter(BPy_IDGroup_View *self)
static char idp_sequence_type(PyObject *seq_fast)
static PyMethodDef IDProp_methods[]
static void BPy_IDGroup_View_dealloc(BPy_IDGroup_View *self)
static PyObject * BPy_Group_IterValues_next(BPy_IDGroup_Iter *self)
static PyObject * BPy_Group_ViewKeys_iter(BPy_IDGroup_View *self)
static int BPy_IDGroup_Iter_is_gc(BPy_IDGroup_Iter *self)
void IDPropertyUIData_Init_Types()
PyObject * pyrna_id_CreatePyObject(ID *id)
PyTypeObject BPy_IDGroup_IterValues_Type
static PyGetSetDef BPy_IDArray_getseters[]
static PyObject * BPy_IDGroup_get(BPy_IDProperty *self, PyObject *args)
char PyC_StructFmt_type_from_str(const char *typestr)
static PyMethodDef BPy_IDGroup_View_methods[]
static PyObject * BPy_IDGroup_ViewKeys_CreatePyObject(BPy_IDProperty *group)
static PyObject * BPy_IDArray_get_typecode(BPy_IDArray *self, void *)
static int BPy_IDArray_SetItem(BPy_IDArray *self, Py_ssize_t index, PyObject *value)
static PyObject * BPy_IDGroup_repr(BPy_IDProperty *self)
static PyObject * idprop_py_from_idp_idparray(ID *id, IDProperty *prop)
IDProperty * IDP_GetPropertyFromGroup(const IDProperty *prop, StringRef name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
PyDoc_STRVAR(bpy_bm_new_doc, ".. function:: new(*, use_operators=True)\n" "\n" " :param use_operators: Support calling operators in :mod:`bmesh.ops` (uses some " "extra memory per vert/edge/face).\n" " :type use_operators: bool\n" " :return: Return a new, empty BMesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n")
static PyObject * BPy_Group_ViewItems_iter(BPy_IDGroup_View *self)
static PyObject * BPy_IDGroup_pop(BPy_IDProperty *self, PyObject *args)
static int BPy_Group_ViewValues_Contains(BPy_IDGroup_View *self, PyObject *value)
static Py_ssize_t BPy_Group_View_len(BPy_IDGroup_View *self)
static PyBufferProcs BPy_IDArray_Buffer
int PyC_AsArray(void *array, const size_t array_item_size, PyObject *value, const Py_ssize_t length, const PyTypeObject *type, const char *error_prefix)
static int BPy_Group_ViewItems_Contains(BPy_IDGroup_View *self, PyObject *value)
static PyMappingMethods BPy_IDGroup_Mapping
static PyObject * BPy_IDGroup_iter(BPy_IDProperty *self)
PyObject * BPy_IDGroup_MapDataToPy(IDProperty *prop)
PyTypeObject BPy_IDArray_Type
static PyMethodDef BPy_IDGroup_methods[]
PyObject * BPy_Wrap_GetItems_View_WithID(ID *id, IDProperty *prop)
PyTypeObject BPy_IDGroup_ViewValues_Type
static PySequenceMethods BPy_IDGroup_ViewValues_as_sequence
static PyObject * BPy_IDArray_subscript(BPy_IDArray *self, PyObject *item)
static PyObject * BPy_IDGroup_Map_GetItem(BPy_IDProperty *self, PyObject *item)
static int BPy_IDArray_ass_subscript(BPy_IDArray *self, PyObject *item, PyObject *value)
static int BPy_Group_ViewKeys_Contains(BPy_IDGroup_View *self, PyObject *value)
static PyObject * BPy_IDGroup_ViewItems_CreatePyObject(BPy_IDProperty *group)
eIDPropertyUIDataType IDP_ui_data_type(const IDProperty *prop)
static PyMethodDef BPy_IDArray_methods[]
static PyObject * IDGroup_Iter_New_WithType(BPy_IDProperty *group, const bool reversed, PyTypeObject *type)
void IDP_AssignID(IDProperty *prop, ID *id, int flag)
void MEM_delete_void(void *vmemh)
PyObject * BPy_Wrap_GetKeys_View_WithID(ID *id, IDProperty *prop)
static PyObject * BPy_IDArray_repr(BPy_IDArray *self)
void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, bool do_overwrite) ATTR_NONNULL()
static PyObject * BPy_IDGroup_GetName(BPy_IDProperty *self, void *)
PyTypeObject BPy_IDGroup_IterItems_Type
PyObject * BPy_Wrap_GetItems(ID *id, IDProperty *prop)
static IDProperty * idp_from_PyMapping(IDProperty *, const char *name, PyObject *ob, const bool, const bool)
static int BPy_IDGroup_Iter_clear(BPy_IDGroup_Iter *self)
static PyObject * BPy_IDArray_to_list(BPy_IDArray *self)
static PyObject * idprop_py_from_idp_id(IDProperty *prop)
void IDP_ReplaceInGroup_ex(IDProperty *group, IDProperty *prop, IDProperty *prop_exist, int flag)
static const char * idp_format_from_array_type(int type)
static PyObject * idprop_py_from_idp_string(const IDProperty *prop)
static IDProperty * idp_from_PySequence(IDProperty *prop_exist, const char *name, PyObject *ob, const bool do_conversion, const bool can_create)
static void BPy_IDArray_releasebuffer(BPy_IDArray *, Py_buffer *view)
PyObject * BPy_Wrap_GetKeys(IDProperty *prop)
static PyTypeObject * idp_array_py_type(BPy_IDArray *self, size_t *elem_size)
static int itemsize_by_idarray_type(int array_type)
static int BPy_IDGroup_SetName(BPy_IDProperty *self, PyObject *value, void *)
static Py_ssize_t BPy_IDGroup_Map_Len(BPy_IDProperty *self)
void IDP_ClearProperty(IDProperty *prop)
static PyObject * idprop_py_from_idp_int(const IDProperty *prop)
IDPropertyUIData * IDP_TryConvertUIData(IDPropertyUIData *src, eIDPropertyUIDataType src_type, eIDPropertyUIDataType dst_type)
static PyObject * BPy_IDGroup_to_dict(BPy_IDProperty *self)
static PyObject * BPy_IDGroup_View_reversed(BPy_IDGroup_View *self, PyObject *)
static PyObject * idprop_py_from_idp_double(const IDProperty *prop)
static IDProperty * idp_from_PyLong(IDProperty *prop_exist, const char *name, PyObject *ob, const bool do_conversion, const bool can_create)
@ IDP_FLAG_OVERRIDABLE_LIBRARY
static PyObject * idprop_py_from_idp_bool(const IDProperty *prop)
PyTypeObject BPy_IDGroup_IterKeys_Type
static IDProperty * idp_from_PyFloat(IDProperty *prop_exist, const char *name, PyObject *ob, const bool do_conversion, const bool can_create)
static int BPy_IDGroup_View_traverse(BPy_IDGroup_View *self, visitproc visit, void *arg)
static IDProperty * idp_from_PyUnicode(IDProperty *prop_exist, const char *name, PyObject *ob, const bool, const bool can_create)
PyTypeObject BPy_IDGroup_Type
static PyModuleDef IDProp_types_module_def
static PyModuleDef IDProp_module_def
bool pyrna_id_FromPyObject(PyObject *obj, ID **id)
static int BPy_IDGroup_Map_SetItem(BPy_IDProperty *self, PyObject *key, PyObject *val)
static int BPy_IDGroup_View_clear(BPy_IDGroup_View *self)
static int idp_array_type_from_formatstr_and_size(const char *typestr, Py_ssize_t itemsize)
static PyObject * BPy_IDGroup_ViewValues_CreatePyObject(BPy_IDProperty *group)
static BPy_IDGroup_View * IDGroup_View_New_WithType(BPy_IDProperty *group, PyTypeObject *type)
PyObject * BPy_IDGroup_WrapData(ID *id, IDProperty *prop, IDProperty *parent)
static PyObject * BPy_IDGroup_items(BPy_IDProperty *self)
static Py_ssize_t BPy_IDArray_Len(BPy_IDArray *self)
static PyObject * BPy_IDGroup_keys(BPy_IDProperty *self)
static bool BPy_Group_Iter_same_size_or_raise_error(BPy_IDGroup_Iter *self)
void IDP_ResizeArray(IDProperty *prop, int newlen)
const char * IDP_type_str(eIDPropertyType type, short sub_type)
static PySequenceMethods BPy_IDGroup_Seq
static PyObject * BPyInit_idprop_types()
const char * PyC_UnicodeAsBytes(PyObject *py_str, PyObject **r_coerce)
static PyObject * BPy_IDGroup_clear(BPy_IDProperty *self)
int PyC_Long_AsBool(PyObject *value)
void IDP_AppendArray(IDProperty *prop, IDProperty *item)
PyObject * BPy_Wrap_GetValues_View_WithID(ID *id, IDProperty *prop)
static int BPy_IDGroup_View_is_gc(BPy_IDGroup_View *self)
static PyObject * idprop_py_from_idp_float(const IDProperty *prop)
static PyObject * BPy_IDGroup_Iter_repr(BPy_IDGroup_Iter *self)
static IDProperty * idp_from_PyBytes(IDProperty *prop_exist, const char *name, PyObject *ob, const bool, const bool can_create)
static void BPy_IDGroup_Iter_dealloc(BPy_IDGroup_Iter *self)
static int BPy_IDGroup_Contains(BPy_IDProperty *self, PyObject *value)
static void BPy_IDGroup_CorrectListLen(IDProperty *prop, PyObject *seq, int len, const char *func)
PyTypeObject BPy_IDPropertyUIManager_Type
static IDProperty * idp_from_PySequence_Fast(IDProperty *prop_exist, const char *name, PyObject *ob, const bool do_conversion, const bool can_create)
void IDP_FreeProperty(IDProperty *prop)
static IDProperty * idp_from_PySequence_Buffer(IDProperty *prop_exist, const char *name, const Py_buffer &buffer, const int idp_type, const bool, const bool can_create)
bool PyC_StructFmt_type_is_float_any(char format)
int PyC_Module_AddToSysModules(PyObject *sys_modules, PyObject *module)
static PyObject * BPy_IDGroup_IterKeys_CreatePyObject(BPy_IDProperty *group, const bool reversed)
static int BPy_IDArray_ass_slice(BPy_IDArray *self, int begin, int end, PyObject *seq)
static PyObject * BPy_IDGroup_update(BPy_IDProperty *self, PyObject *value)
static void IDGroup_Iter_init_type()
static PySequenceMethods BPy_IDGroup_ViewKeys_as_sequence
IDProperty * IDP_New(char type, const IDPropertyTemplate *val, StringRef name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
static PyObject * BPy_Group_IterItems_next(BPy_IDGroup_Iter *self)
PyTypeObject BPy_IDGroup_ViewItems_Type
static int BPy_IDGroup_Iter_traverse(BPy_IDGroup_Iter *self, visitproc visit, void *arg)
static PyObject * BPy_IDGroup_IterValues_CreatePyObject(BPy_IDProperty *group, const bool reversed)
static void IDGroup_View_init_type()
static IDProperty * idp_from_DatablockPointer(IDProperty *prop_exist, const char *name, PyObject *ob, const bool, const bool can_create)
IDProperty * BPy_IDProperty_FromPyObject(IDProperty *prop_exist, const char *name, PyObject *ob, const bool do_conversion, const bool can_create)
PyObject * PyC_UnicodeFromBytesAndSize(const char *str, Py_ssize_t size)
bool PyC_StructFmt_type_is_int_any(char format)
static PyObject * BPy_Group_IterKeys_next(BPy_IDGroup_Iter *self)
static PySequenceMethods BPy_IDGroup_ViewItems_as_sequence
static PyGetSetDef BPy_IDGroup_getseters[]
PyObject * BPy_Wrap_GetValues(ID *id, IDProperty *prop)
PyTypeObject BPy_IDGroup_ViewKeys_Type
static int BPy_IDArray_getbuffer(BPy_IDArray *self, Py_buffer *view, int flags)
static PyObject * idprop_py_from_idp_array(ID *id, IDProperty *prop)
static PyObject * BPy_IDGroup_View_repr(BPy_IDGroup_View *self)
static Py_hash_t BPy_IDGroup_hash(BPy_IDProperty *self)
IDProperty * IDP_NewIDPArray(StringRef name) ATTR_WARN_UNUSED_RESULT
static PyObject * BPy_IDArray_slice(BPy_IDArray *self, int begin, int end)
void IDP_AssignStringMaxSize(IDProperty *prop, const char *st, size_t st_maxncpy) ATTR_NONNULL()
static PyObject * BPy_IDGroup_values(BPy_IDProperty *self)
static PySequenceMethods BPy_IDArray_Seq
int BPy_Wrap_SetMapItem(IDProperty *prop, PyObject *key, PyObject *val)
const char * PyC_UnicodeAsBytesAndSize(PyObject *py_str, Py_ssize_t *r_size, PyObject **r_coerce)
static IDProperty * idp_from_PyBool(IDProperty *prop_exist, const char *name, PyObject *ob, const bool do_conversion, const bool can_create)
header-only compatibility defines.
#define PyTuple_SET_ITEMS(op_arg,...)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
PyObject_HEAD BPy_IDProperty * group
PyObject_HEAD BPy_IDProperty * group
struct IDProperty * parent
PyObject_HEAD struct ID * owner_id
ListBaseT< struct IDProperty > group
IDPropertyUIData * ui_data
struct blender::IDPropertyTemplate::@100215251242210352227251277016155305041022127377 array
struct blender::IDPropertyTemplate::@116303142222164257205355242364302075230051143265 string