Blender  V2.93
bpy_props.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
25 /* Future-proof, See https://docs.python.org/3/c-api/arg.html#strings-and-buffers */
26 #define PY_SSIZE_T_CLEAN
27 
28 #include <Python.h>
29 
30 #include "RNA_types.h"
31 
32 #include "BLI_listbase.h"
33 #include "BLI_utildefines.h"
34 
35 #include "bpy_capi_utils.h"
36 #include "bpy_props.h"
37 #include "bpy_rna.h"
38 
39 #include "BKE_idprop.h"
40 
41 #include "RNA_access.h"
42 #include "RNA_define.h" /* for defining our own rna */
43 #include "RNA_enum_types.h"
44 
45 #include "MEM_guardedalloc.h"
46 
47 #include "DNA_ID.h" /* MAX_IDPROP_NAME */
48 
49 #include "../generic/py_capi_utils.h"
50 
51 /* -------------------------------------------------------------------- */
56  {PROP_HIDDEN, "HIDDEN", 0, "Hidden", ""},
57  {PROP_SKIP_SAVE, "SKIP_SAVE", 0, "Skip Save", ""},
58  {PROP_ANIMATABLE, "ANIMATABLE", 0, "Animatable", ""},
59  {PROP_LIB_EXCEPTION, "LIBRARY_EDITABLE", 0, "Library Editable", ""},
60  {PROP_PROPORTIONAL, "PROPORTIONAL", 0, "Adjust values proportionally to eachother", ""},
62  "TEXTEDIT_UPDATE",
63  0,
64  "Update on every keystroke in textedit 'mode'",
65  ""},
66  {0, NULL, 0, NULL, NULL},
67 };
68 
69 #define BPY_PROPDEF_OPTIONS_DOC \
70  " :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE', 'LIBRARY_EDITABLE', " \
71  "'PROPORTIONAL'," \
72  "'TEXTEDIT_UPDATE'].\n" \
73  " :type options: set\n"
74 
76  {PROP_HIDDEN, "HIDDEN", 0, "Hidden", ""},
77  {PROP_SKIP_SAVE, "SKIP_SAVE", 0, "Skip Save", ""},
78  {PROP_ANIMATABLE, "ANIMATABLE", 0, "Animatable", ""},
79  {PROP_LIB_EXCEPTION, "LIBRARY_EDITABLE", 0, "Library Editable", ""},
80  {PROP_ENUM_FLAG, "ENUM_FLAG", 0, "Enum Flag", ""},
81  {0, NULL, 0, NULL, NULL},
82 };
83 
84 #define BPY_PROPDEF_OPTIONS_ENUM_DOC \
85  " :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE', 'ENUM_FLAG', " \
86  "'LIBRARY_EDITABLE'].\n" \
87  " :type options: set\n"
88 
91  "LIBRARY_OVERRIDABLE",
92  0,
93  "Library Overridable",
94  "Make that property editable in library overrides of linked data-blocks"},
95  {0, NULL, 0, NULL, NULL},
96 };
97 
98 #define BPY_PROPDEF_OPTIONS_OVERRIDE_DOC \
99  " :arg override: Enumerator in ['LIBRARY_OVERRIDABLE'].\n" \
100  " :type override: set\n"
101 
104  "LIBRARY_OVERRIDABLE",
105  0,
106  "Library Overridable",
107  "Make that property editable in library overrides of linked data-blocks"},
109  "NO_PROPERTY_NAME",
110  0,
111  "No Name",
112  "Do not use the names of the items, only their indices in the collection"},
114  "USE_INSERTION",
115  0,
116  "Use Insertion",
117  "Allow users to add new items in that collection in library overrides"},
118  {0, NULL, 0, NULL, NULL},
119 };
120 
121 #define BPY_PROPDEF_OPTIONS_OVERRIDE_COLLECTION_DOC \
122  " :arg override: Enumerator in ['LIBRARY_OVERRIDABLE', 'NO_PROPERTY_NAME', " \
123  "'USE_INSERTION'].\n" \
124  " :type override: set\n"
125 
126 /* subtypes */
127 /* Keep in sync with RNA_types.h PropertySubType and rna_rna.c's rna_enum_property_subtype_items */
129  {PROP_FILEPATH, "FILE_PATH", 0, "File Path", ""},
130  {PROP_DIRPATH, "DIR_PATH", 0, "Directory Path", ""},
131  {PROP_FILENAME, "FILE_NAME", 0, "Filename", ""},
132  {PROP_BYTESTRING, "BYTE_STRING", 0, "Byte String", ""},
133  {PROP_PASSWORD, "PASSWORD", 0, "Password", "A string that is displayed hidden ('********')"},
134 
135  {PROP_NONE, "NONE", 0, "None", ""},
136  {0, NULL, 0, NULL, NULL},
137 };
138 
139 #define BPY_PROPDEF_SUBTYPE_STRING_DOC \
140  " :arg subtype: Enumerator in ['FILE_PATH', 'DIR_PATH', 'FILE_NAME', 'BYTE_STRING', " \
141  "'PASSWORD', 'NONE'].\n" \
142  " :type subtype: string\n"
143 
145  {PROP_PIXEL, "PIXEL", 0, "Pixel", ""},
146  {PROP_UNSIGNED, "UNSIGNED", 0, "Unsigned", ""},
147  {PROP_PERCENTAGE, "PERCENTAGE", 0, "Percentage", ""},
148  {PROP_FACTOR, "FACTOR", 0, "Factor", ""},
149  {PROP_ANGLE, "ANGLE", 0, "Angle", ""},
150  {PROP_TIME, "TIME", 0, "Time", ""},
151  {PROP_DISTANCE, "DISTANCE", 0, "Distance", ""},
152  {PROP_DISTANCE_CAMERA, "DISTANCE_CAMERA", 0, "Camera Distance", ""},
153  {PROP_POWER, "POWER", 0, "Power", ""},
154  {PROP_TEMPERATURE, "TEMPERATURE", 0, "Temperature", ""},
155 
156  {PROP_NONE, "NONE", 0, "None", ""},
157  {0, NULL, 0, NULL, NULL},
158 };
159 
160 #define BPY_PROPDEF_SUBTYPE_NUMBER_DOC \
161  " :arg subtype: Enumerator in ['PIXEL', 'UNSIGNED', 'PERCENTAGE', 'FACTOR', 'ANGLE', " \
162  "'TIME', 'DISTANCE', 'DISTANCE_CAMERA', 'POWER', 'TEMPERATURE', 'NONE'].\n" \
163  " :type subtype: string\n"
164 
166  {PROP_COLOR, "COLOR", 0, "Color", ""},
167  {PROP_TRANSLATION, "TRANSLATION", 0, "Translation", ""},
168  {PROP_DIRECTION, "DIRECTION", 0, "Direction", ""},
169  {PROP_VELOCITY, "VELOCITY", 0, "Velocity", ""},
170  {PROP_ACCELERATION, "ACCELERATION", 0, "Acceleration", ""},
171  {PROP_MATRIX, "MATRIX", 0, "Matrix", ""},
172  {PROP_EULER, "EULER", 0, "Euler", ""},
173  {PROP_QUATERNION, "QUATERNION", 0, "Quaternion", ""},
174  {PROP_AXISANGLE, "AXISANGLE", 0, "Axis Angle", ""},
175  {PROP_XYZ, "XYZ", 0, "XYZ", ""},
176  {PROP_XYZ_LENGTH, "XYZ_LENGTH", 0, "XYZ Length", ""},
177  {PROP_COLOR_GAMMA, "COLOR_GAMMA", 0, "Color Gamma", ""},
178  {PROP_COORDS, "COORDINATES", 0, "Vector Coordinates", ""},
179  {PROP_LAYER, "LAYER", 0, "Layer", ""},
180  {PROP_LAYER_MEMBER, "LAYER_MEMBER", 0, "Layer Member", ""},
181 
182  {PROP_NONE, "NONE", 0, "None", ""},
183  {0, NULL, 0, NULL, NULL},
184 };
185 
186 #define BPY_PROPDEF_SUBTYPE_ARRAY_DOC \
187  " :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', " \
188  "'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', " \
189  "'XYZ', 'XYZ_LENGTH', 'COLOR_GAMMA', 'COORDINATES', 'LAYER', 'LAYER_MEMBER', 'NONE'].\n" \
190  " :type subtype: string\n"
191 
194 /* -------------------------------------------------------------------- */
232 struct BPyPropStore {
233  struct BPyPropStore *next, *prev;
234 
239  struct {
241  PyObject *get_fn;
242  PyObject *set_fn;
244  PyObject *update_fn;
245 
247  union {
249  struct {
251  PyObject *itemf_fn;
254  struct {
256  PyObject *poll_fn;
258  };
260 };
261 
262 #define BPY_PROP_STORE_PY_DATA_SIZE \
263  (sizeof(((struct BPyPropStore *)NULL)->py_data) / sizeof(PyObject *))
264 
265 #define ASSIGN_PYOBJECT_INCREF(a, b) \
266  { \
267  BLI_assert((a) == NULL); \
268  Py_INCREF(b); \
269  a = b; \
270  } \
271  ((void)0)
272 
278 
280 {
281  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
282  if (prop_store == NULL) {
283  prop_store = MEM_callocN(sizeof(*prop_store), __func__);
284  RNA_def_py_data(prop, prop_store);
285  BLI_addtail(&g_bpy_prop_store_list, prop_store);
286  }
287  return prop_store;
288 }
289 
294 {
295  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
296  if (prop_store == NULL) {
297  return;
298  }
299 
300  PyObject **py_data = (PyObject **)&prop_store->py_data;
301  for (int i = 0; i < BPY_PROP_STORE_PY_DATA_SIZE; i++) {
302  Py_XDECREF(py_data[i]);
303  }
304  BLI_remlink(&g_bpy_prop_store_list, prop_store);
305 }
306 
309 /* -------------------------------------------------------------------- */
318 {
319  PyObject_GC_UnTrack(self);
320  Py_CLEAR(self->kw);
321  PyObject_GC_Del(self);
322 }
323 
324 static int bpy_prop_deferred_traverse(BPy_PropDeferred *self, visitproc visit, void *arg)
325 {
326  Py_VISIT(self->kw);
327  return 0;
328 }
329 
331 {
332  Py_CLEAR(self->kw);
333  return 0;
334 }
335 
337 {
338  return PyUnicode_FromFormat("<%.200s, %R, %R>", Py_TYPE(self)->tp_name, self->fn, self->kw);
339 }
340 
348  PyObject *UNUSED(args),
349  PyObject *UNUSED(kw))
350 {
351  /* Dummy value. */
352  Py_RETURN_NONE;
353 }
354 
355 /* Get/Set Items. */
356 
361 static PyObject *bpy_prop_deferred_function_get(BPy_PropDeferred *self, void *UNUSED(closure))
362 {
363  PyObject *ret = self->fn;
364  Py_IncRef(ret);
365  return ret;
366 }
367 
372 static PyObject *bpy_prop_deferred_keywords_get(BPy_PropDeferred *self, void *UNUSED(closure))
373 {
374  PyObject *ret = self->kw;
375  Py_IncRef(ret);
376  return ret;
377 }
378 
379 static PyGetSetDef bpy_prop_deferred_getset[] = {
380  {"function", (getter)bpy_prop_deferred_function_get, (setter)NULL, NULL, NULL},
381  {"keywords", (getter)bpy_prop_deferred_keywords_get, (setter)NULL, NULL, NULL},
382  {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
383 };
384 
385 PyDoc_STRVAR(bpy_prop_deferred_doc,
386  "Intermediate storage for properties before registration.\n"
387  "\n"
388  ".. note::\n"
389  "\n"
390  " This is not part of the stable API and may change between releases.");
391 
392 PyTypeObject bpy_prop_deferred_Type = {
393  PyVarObject_HEAD_INIT(NULL, 0)
394 
395  .tp_name = "_PropertyDeferred",
396  .tp_basicsize = sizeof(BPy_PropDeferred),
397  .tp_dealloc = (destructor)bpy_prop_deferred_dealloc,
398  .tp_repr = (reprfunc)bpy_prop_deferred_repr,
399  .tp_call = (ternaryfunc)bpy_prop_deferred_call,
400 
401  .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
402 
403  .tp_doc = bpy_prop_deferred_doc,
404  .tp_traverse = (traverseproc)bpy_prop_deferred_traverse,
405  .tp_clear = (inquiry)bpy_prop_deferred_clear,
406 
407  .tp_getset = bpy_prop_deferred_getset,
408 };
409 
410 static PyObject *bpy_prop_deferred_data_CreatePyObject(PyObject *fn, PyObject *kw)
411 {
412  BPy_PropDeferred *self = PyObject_GC_New(BPy_PropDeferred, &bpy_prop_deferred_Type);
413  self->fn = fn;
414  if (kw == NULL) {
415  kw = PyDict_New();
416  }
417  else {
418  Py_INCREF(kw);
419  }
420  self->kw = kw;
421  PyObject_GC_Track(self);
422  return (PyObject *)self;
423 }
424 
427 /* PyObject's */
428 static PyObject *pymeth_BoolProperty = NULL;
429 static PyObject *pymeth_BoolVectorProperty = NULL;
430 static PyObject *pymeth_IntProperty = NULL;
431 static PyObject *pymeth_IntVectorProperty = NULL;
432 static PyObject *pymeth_FloatProperty = NULL;
433 static PyObject *pymeth_FloatVectorProperty = NULL;
434 static PyObject *pymeth_StringProperty = NULL;
435 static PyObject *pymeth_EnumProperty = NULL;
436 static PyObject *pymeth_PointerProperty = NULL;
437 static PyObject *pymeth_CollectionProperty = NULL;
438 static PyObject *pymeth_RemoveProperty = NULL;
439 
441 {
442  PyObject *self = NULL;
443  /* first get self */
444  /* operators can store their own instance for later use */
445  if (ptr->data) {
446  void **instance = RNA_struct_instance(ptr);
447 
448  if (instance) {
449  if (*instance) {
450  self = *instance;
451  Py_INCREF(self);
452  }
453  }
454  }
455 
456  /* in most cases this will run */
457  if (self == NULL) {
459  }
460 
461  return self;
462 }
463 
464 static void bpy_prop_assign_flag(PropertyRNA *prop, const int flag)
465 {
466  const int flag_mask = ((PROP_ANIMATABLE) & ~flag);
467 
468  if (flag) {
469  RNA_def_property_flag(prop, flag);
470  }
471 
472  if (flag_mask) {
473  RNA_def_property_clear_flag(prop, flag_mask);
474  }
475 }
476 
477 static void bpy_prop_assign_flag_override(PropertyRNA *prop, const int flag_override)
478 {
479  RNA_def_property_override_flag(prop, flag_override);
480 }
481 
484 /* -------------------------------------------------------------------- */
490 /* callbacks */
491 static void bpy_prop_update_fn(struct bContext *C,
492  struct PointerRNA *ptr,
493  struct PropertyRNA *prop)
494 {
495  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
496  PyGILState_STATE gilstate;
497  PyObject *py_func;
498  PyObject *args;
499  PyObject *self;
500  PyObject *ret;
501  const bool is_write_ok = pyrna_write_check();
502 
503  BLI_assert(prop_store != NULL);
504 
505  if (!is_write_ok) {
506  pyrna_write_set(true);
507  }
508 
509  bpy_context_set(C, &gilstate);
510 
511  py_func = prop_store->py_data.update_fn;
512 
513  args = PyTuple_New(2);
515  PyTuple_SET_ITEM(args, 0, self);
516 
517  PyTuple_SET_ITEM(args, 1, (PyObject *)bpy_context_module);
518  Py_INCREF(bpy_context_module);
519 
520  ret = PyObject_CallObject(py_func, args);
521 
522  Py_DECREF(args);
523 
524  if (ret == NULL) {
525  PyC_Err_PrintWithFunc(py_func);
526  }
527  else {
528  if (ret != Py_None) {
529  PyErr_SetString(PyExc_ValueError, "the return value must be None");
530  PyC_Err_PrintWithFunc(py_func);
531  }
532 
533  Py_DECREF(ret);
534  }
535 
536  bpy_context_clear(C, &gilstate);
537 
538  if (!is_write_ok) {
539  pyrna_write_set(false);
540  }
541 }
542 
545 /* -------------------------------------------------------------------- */
549 static bool bpy_prop_boolean_get_fn(struct PointerRNA *ptr, struct PropertyRNA *prop)
550 {
551  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
552  PyObject *py_func;
553  PyObject *args;
554  PyObject *self;
555  PyObject *ret;
556  PyGILState_STATE gilstate;
557  bool use_gil;
558  const bool is_write_ok = pyrna_write_check();
559  bool value;
560 
561  BLI_assert(prop_store != NULL);
562 
563  if (!is_write_ok) {
564  pyrna_write_set(true);
565  }
566 
567  use_gil = true; /* !PyC_IsInterpreterActive(); */
568 
569  if (use_gil) {
570  gilstate = PyGILState_Ensure();
571  }
572 
573  py_func = prop_store->py_data.get_fn;
574 
575  args = PyTuple_New(1);
577  PyTuple_SET_ITEM(args, 0, self);
578 
579  ret = PyObject_CallObject(py_func, args);
580 
581  Py_DECREF(args);
582 
583  if (ret == NULL) {
584  PyC_Err_PrintWithFunc(py_func);
585  value = false;
586  }
587  else {
588  const int value_i = PyC_Long_AsBool(ret);
589 
590  if (value_i == -1 && PyErr_Occurred()) {
591  PyC_Err_PrintWithFunc(py_func);
592  value = false;
593  }
594  else {
595  value = (bool)value_i;
596  }
597 
598  Py_DECREF(ret);
599  }
600 
601  if (use_gil) {
602  PyGILState_Release(gilstate);
603  }
604 
605  if (!is_write_ok) {
606  pyrna_write_set(false);
607  }
608 
609  return value;
610 }
611 
612 static void bpy_prop_boolean_set_fn(struct PointerRNA *ptr, struct PropertyRNA *prop, bool value)
613 {
614  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
615  PyObject *py_func;
616  PyObject *args;
617  PyObject *self;
618  PyObject *ret;
619  PyGILState_STATE gilstate;
620  bool use_gil;
621  const bool is_write_ok = pyrna_write_check();
622 
623  BLI_assert(prop_store != NULL);
624 
625  if (!is_write_ok) {
626  pyrna_write_set(true);
627  }
628 
629  use_gil = true; /* !PyC_IsInterpreterActive(); */
630 
631  if (use_gil) {
632  gilstate = PyGILState_Ensure();
633  }
634 
635  py_func = prop_store->py_data.set_fn;
636 
637  args = PyTuple_New(2);
639  PyTuple_SET_ITEM(args, 0, self);
640 
641  PyTuple_SET_ITEM(args, 1, PyBool_FromLong(value));
642 
643  ret = PyObject_CallObject(py_func, args);
644 
645  Py_DECREF(args);
646 
647  if (ret == NULL) {
648  PyC_Err_PrintWithFunc(py_func);
649  }
650  else {
651  if (ret != Py_None) {
652  PyErr_SetString(PyExc_ValueError, "the return value must be None");
653  PyC_Err_PrintWithFunc(py_func);
654  }
655 
656  Py_DECREF(ret);
657  }
658 
659  if (use_gil) {
660  PyGILState_Release(gilstate);
661  }
662 
663  if (!is_write_ok) {
664  pyrna_write_set(false);
665  }
666 }
667 
669  struct PropertyRNA *prop,
670  bool *values)
671 {
672  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
673  PyObject *py_func;
674  PyObject *args;
675  PyObject *self;
676  PyObject *ret;
677  PyGILState_STATE gilstate;
678  bool use_gil;
679  const bool is_write_ok = pyrna_write_check();
680  int i, len = RNA_property_array_length(ptr, prop);
681 
682  BLI_assert(prop_store != NULL);
683 
684  if (!is_write_ok) {
685  pyrna_write_set(true);
686  }
687 
688  use_gil = true; /* !PyC_IsInterpreterActive(); */
689 
690  if (use_gil) {
691  gilstate = PyGILState_Ensure();
692  }
693 
694  py_func = prop_store->py_data.get_fn;
695 
696  args = PyTuple_New(1);
698  PyTuple_SET_ITEM(args, 0, self);
699 
700  ret = PyObject_CallObject(py_func, args);
701 
702  Py_DECREF(args);
703 
704  if (ret == NULL) {
705  PyC_Err_PrintWithFunc(py_func);
706 
707  for (i = 0; i < len; i++) {
708  values[i] = false;
709  }
710  }
711  else {
712  if (PyC_AsArray(values, ret, len, &PyBool_Type, false, "BoolVectorProperty get") == -1) {
713  PyC_Err_PrintWithFunc(py_func);
714 
715  for (i = 0; i < len; i++) {
716  values[i] = false;
717  }
718  }
719  Py_DECREF(ret);
720  }
721 
722  if (use_gil) {
723  PyGILState_Release(gilstate);
724  }
725 
726  if (!is_write_ok) {
727  pyrna_write_set(false);
728  }
729 }
730 
732  struct PropertyRNA *prop,
733  const bool *values)
734 {
735  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
736  PyObject *py_func;
737  PyObject *args;
738  PyObject *self;
739  PyObject *ret;
740  PyObject *py_values;
741  PyGILState_STATE gilstate;
742  bool use_gil;
743  const bool is_write_ok = pyrna_write_check();
744  const int len = RNA_property_array_length(ptr, prop);
745 
746  BLI_assert(prop_store != NULL);
747 
748  if (!is_write_ok) {
749  pyrna_write_set(true);
750  }
751 
752  use_gil = true; /* !PyC_IsInterpreterActive(); */
753 
754  if (use_gil) {
755  gilstate = PyGILState_Ensure();
756  }
757 
758  py_func = prop_store->py_data.set_fn;
759 
760  args = PyTuple_New(2);
762  PyTuple_SET_ITEM(args, 0, self);
763 
764  py_values = PyC_Tuple_PackArray_Bool(values, len);
765  PyTuple_SET_ITEM(args, 1, py_values);
766 
767  ret = PyObject_CallObject(py_func, args);
768 
769  Py_DECREF(args);
770 
771  if (ret == NULL) {
772  PyC_Err_PrintWithFunc(py_func);
773  }
774  else {
775  if (ret != Py_None) {
776  PyErr_SetString(PyExc_ValueError, "the return value must be None");
777  PyC_Err_PrintWithFunc(py_func);
778  }
779 
780  Py_DECREF(ret);
781  }
782 
783  if (use_gil) {
784  PyGILState_Release(gilstate);
785  }
786 
787  if (!is_write_ok) {
788  pyrna_write_set(false);
789  }
790 }
791 
794 /* -------------------------------------------------------------------- */
798 static int bpy_prop_int_get_fn(struct PointerRNA *ptr, struct PropertyRNA *prop)
799 {
800  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
801  PyObject *py_func;
802  PyObject *args;
803  PyObject *self;
804  PyObject *ret;
805  PyGILState_STATE gilstate;
806  bool use_gil;
807  const bool is_write_ok = pyrna_write_check();
808  int value;
809 
810  BLI_assert(prop_store != NULL);
811 
812  if (!is_write_ok) {
813  pyrna_write_set(true);
814  }
815 
816  use_gil = true; /* !PyC_IsInterpreterActive(); */
817 
818  if (use_gil) {
819  gilstate = PyGILState_Ensure();
820  }
821 
822  py_func = prop_store->py_data.get_fn;
823 
824  args = PyTuple_New(1);
826  PyTuple_SET_ITEM(args, 0, self);
827 
828  ret = PyObject_CallObject(py_func, args);
829 
830  Py_DECREF(args);
831 
832  if (ret == NULL) {
833  PyC_Err_PrintWithFunc(py_func);
834  value = 0.0f;
835  }
836  else {
837  value = PyC_Long_AsI32(ret);
838 
839  if (value == -1 && PyErr_Occurred()) {
840  PyC_Err_PrintWithFunc(py_func);
841  value = 0;
842  }
843 
844  Py_DECREF(ret);
845  }
846 
847  if (use_gil) {
848  PyGILState_Release(gilstate);
849  }
850 
851  if (!is_write_ok) {
852  pyrna_write_set(false);
853  }
854 
855  return value;
856 }
857 
858 static void bpy_prop_int_set_fn(struct PointerRNA *ptr, struct PropertyRNA *prop, int value)
859 {
860  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
861  PyObject *py_func;
862  PyObject *args;
863  PyObject *self;
864  PyObject *ret;
865  PyGILState_STATE gilstate;
866  bool use_gil;
867  const bool is_write_ok = pyrna_write_check();
868 
869  BLI_assert(prop_store != NULL);
870 
871  if (!is_write_ok) {
872  pyrna_write_set(true);
873  }
874 
875  use_gil = true; /* !PyC_IsInterpreterActive(); */
876 
877  if (use_gil) {
878  gilstate = PyGILState_Ensure();
879  }
880 
881  py_func = prop_store->py_data.set_fn;
882 
883  args = PyTuple_New(2);
885  PyTuple_SET_ITEM(args, 0, self);
886 
887  PyTuple_SET_ITEM(args, 1, PyLong_FromLong(value));
888 
889  ret = PyObject_CallObject(py_func, args);
890 
891  Py_DECREF(args);
892 
893  if (ret == NULL) {
894  PyC_Err_PrintWithFunc(py_func);
895  }
896  else {
897  if (ret != Py_None) {
898  PyErr_SetString(PyExc_ValueError, "the return value must be None");
899  PyC_Err_PrintWithFunc(py_func);
900  }
901 
902  Py_DECREF(ret);
903  }
904 
905  if (use_gil) {
906  PyGILState_Release(gilstate);
907  }
908 
909  if (!is_write_ok) {
910  pyrna_write_set(false);
911  }
912 }
913 
915  struct PropertyRNA *prop,
916  int *values)
917 {
918  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
919  PyObject *py_func;
920  PyObject *args;
921  PyObject *self;
922  PyObject *ret;
923  PyGILState_STATE gilstate;
924  bool use_gil;
925  const bool is_write_ok = pyrna_write_check();
926  int i, len = RNA_property_array_length(ptr, prop);
927 
928  BLI_assert(prop_store != NULL);
929 
930  if (!is_write_ok) {
931  pyrna_write_set(true);
932  }
933 
934  use_gil = true; /* !PyC_IsInterpreterActive(); */
935 
936  if (use_gil) {
937  gilstate = PyGILState_Ensure();
938  }
939 
940  py_func = prop_store->py_data.get_fn;
941 
942  args = PyTuple_New(1);
944  PyTuple_SET_ITEM(args, 0, self);
945 
946  ret = PyObject_CallObject(py_func, args);
947 
948  Py_DECREF(args);
949 
950  if (ret == NULL) {
951  PyC_Err_PrintWithFunc(py_func);
952 
953  for (i = 0; i < len; i++) {
954  values[i] = 0;
955  }
956  }
957  else {
958  if (PyC_AsArray(values, ret, len, &PyLong_Type, false, "IntVectorProperty get") == -1) {
959  PyC_Err_PrintWithFunc(py_func);
960 
961  for (i = 0; i < len; i++) {
962  values[i] = 0;
963  }
964  }
965  Py_DECREF(ret);
966  }
967 
968  if (use_gil) {
969  PyGILState_Release(gilstate);
970  }
971 
972  if (!is_write_ok) {
973  pyrna_write_set(false);
974  }
975 }
976 
978  struct PropertyRNA *prop,
979  const int *values)
980 {
981  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
982  PyObject *py_func;
983  PyObject *args;
984  PyObject *self;
985  PyObject *ret;
986  PyObject *py_values;
987  PyGILState_STATE gilstate;
988  bool use_gil;
989  const bool is_write_ok = pyrna_write_check();
990  const int len = RNA_property_array_length(ptr, prop);
991 
992  BLI_assert(prop_store != NULL);
993 
994  if (!is_write_ok) {
995  pyrna_write_set(true);
996  }
997 
998  use_gil = true; /* !PyC_IsInterpreterActive(); */
999 
1000  if (use_gil) {
1001  gilstate = PyGILState_Ensure();
1002  }
1003 
1004  py_func = prop_store->py_data.set_fn;
1005 
1006  args = PyTuple_New(2);
1007  self = pyrna_struct_as_instance(ptr);
1008  PyTuple_SET_ITEM(args, 0, self);
1009 
1010  py_values = PyC_Tuple_PackArray_I32(values, len);
1011  PyTuple_SET_ITEM(args, 1, py_values);
1012 
1013  ret = PyObject_CallObject(py_func, args);
1014 
1015  Py_DECREF(args);
1016 
1017  if (ret == NULL) {
1018  PyC_Err_PrintWithFunc(py_func);
1019  }
1020  else {
1021  if (ret != Py_None) {
1022  PyErr_SetString(PyExc_ValueError, "the return value must be None");
1023  PyC_Err_PrintWithFunc(py_func);
1024  }
1025 
1026  Py_DECREF(ret);
1027  }
1028 
1029  if (use_gil) {
1030  PyGILState_Release(gilstate);
1031  }
1032 
1033  if (!is_write_ok) {
1034  pyrna_write_set(false);
1035  }
1036 }
1037 
1040 /* -------------------------------------------------------------------- */
1044 static float bpy_prop_float_get_fn(struct PointerRNA *ptr, struct PropertyRNA *prop)
1045 {
1046  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
1047  PyObject *py_func;
1048  PyObject *args;
1049  PyObject *self;
1050  PyObject *ret;
1051  PyGILState_STATE gilstate;
1052  bool use_gil;
1053  const bool is_write_ok = pyrna_write_check();
1054  float value;
1055 
1056  BLI_assert(prop_store != NULL);
1057 
1058  if (!is_write_ok) {
1059  pyrna_write_set(true);
1060  }
1061 
1062  use_gil = true; /* !PyC_IsInterpreterActive(); */
1063 
1064  if (use_gil) {
1065  gilstate = PyGILState_Ensure();
1066  }
1067 
1068  py_func = prop_store->py_data.get_fn;
1069 
1070  args = PyTuple_New(1);
1071  self = pyrna_struct_as_instance(ptr);
1072  PyTuple_SET_ITEM(args, 0, self);
1073 
1074  ret = PyObject_CallObject(py_func, args);
1075 
1076  Py_DECREF(args);
1077 
1078  if (ret == NULL) {
1079  PyC_Err_PrintWithFunc(py_func);
1080  value = 0.0f;
1081  }
1082  else {
1083  value = PyFloat_AsDouble(ret);
1084 
1085  if (value == -1.0f && PyErr_Occurred()) {
1086  PyC_Err_PrintWithFunc(py_func);
1087  value = 0.0f;
1088  }
1089 
1090  Py_DECREF(ret);
1091  }
1092 
1093  if (use_gil) {
1094  PyGILState_Release(gilstate);
1095  }
1096 
1097  if (!is_write_ok) {
1098  pyrna_write_set(false);
1099  }
1100 
1101  return value;
1102 }
1103 
1104 static void bpy_prop_float_set_fn(struct PointerRNA *ptr, struct PropertyRNA *prop, float value)
1105 {
1106  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
1107  PyObject *py_func;
1108  PyObject *args;
1109  PyObject *self;
1110  PyObject *ret;
1111  PyGILState_STATE gilstate;
1112  bool use_gil;
1113  const bool is_write_ok = pyrna_write_check();
1114 
1115  BLI_assert(prop_store != NULL);
1116 
1117  if (!is_write_ok) {
1118  pyrna_write_set(true);
1119  }
1120 
1121  use_gil = true; /* !PyC_IsInterpreterActive(); */
1122 
1123  if (use_gil) {
1124  gilstate = PyGILState_Ensure();
1125  }
1126 
1127  py_func = prop_store->py_data.set_fn;
1128 
1129  args = PyTuple_New(2);
1130  self = pyrna_struct_as_instance(ptr);
1131  PyTuple_SET_ITEM(args, 0, self);
1132 
1133  PyTuple_SET_ITEM(args, 1, PyFloat_FromDouble(value));
1134 
1135  ret = PyObject_CallObject(py_func, args);
1136 
1137  Py_DECREF(args);
1138 
1139  if (ret == NULL) {
1140  PyC_Err_PrintWithFunc(py_func);
1141  }
1142  else {
1143  if (ret != Py_None) {
1144  PyErr_SetString(PyExc_ValueError, "the return value must be None");
1145  PyC_Err_PrintWithFunc(py_func);
1146  }
1147 
1148  Py_DECREF(ret);
1149  }
1150 
1151  if (use_gil) {
1152  PyGILState_Release(gilstate);
1153  }
1154 
1155  if (!is_write_ok) {
1156  pyrna_write_set(false);
1157  }
1158 }
1159 
1161  struct PropertyRNA *prop,
1162  float *values)
1163 {
1164  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
1165  PyObject *py_func;
1166  PyObject *args;
1167  PyObject *self;
1168  PyObject *ret;
1169  PyGILState_STATE gilstate;
1170  bool use_gil;
1171  const bool is_write_ok = pyrna_write_check();
1172  int i, len = RNA_property_array_length(ptr, prop);
1173 
1174  BLI_assert(prop_store != NULL);
1175 
1176  if (!is_write_ok) {
1177  pyrna_write_set(true);
1178  }
1179 
1180  use_gil = true; /* !PyC_IsInterpreterActive(); */
1181 
1182  if (use_gil) {
1183  gilstate = PyGILState_Ensure();
1184  }
1185 
1186  py_func = prop_store->py_data.get_fn;
1187 
1188  args = PyTuple_New(1);
1189  self = pyrna_struct_as_instance(ptr);
1190  PyTuple_SET_ITEM(args, 0, self);
1191 
1192  ret = PyObject_CallObject(py_func, args);
1193 
1194  Py_DECREF(args);
1195 
1196  if (ret == NULL) {
1197  PyC_Err_PrintWithFunc(py_func);
1198 
1199  for (i = 0; i < len; i++) {
1200  values[i] = 0.0f;
1201  }
1202  }
1203  else {
1204  if (PyC_AsArray(values, ret, len, &PyFloat_Type, false, "FloatVectorProperty get") == -1) {
1205  PyC_Err_PrintWithFunc(py_func);
1206 
1207  for (i = 0; i < len; i++) {
1208  values[i] = 0.0f;
1209  }
1210  }
1211  Py_DECREF(ret);
1212  }
1213 
1214  if (use_gil) {
1215  PyGILState_Release(gilstate);
1216  }
1217 
1218  if (!is_write_ok) {
1219  pyrna_write_set(false);
1220  }
1221 }
1222 
1224  struct PropertyRNA *prop,
1225  const float *values)
1226 {
1227  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
1228  PyObject *py_func;
1229  PyObject *args;
1230  PyObject *self;
1231  PyObject *ret;
1232  PyObject *py_values;
1233  PyGILState_STATE gilstate;
1234  bool use_gil;
1235  const bool is_write_ok = pyrna_write_check();
1236  const int len = RNA_property_array_length(ptr, prop);
1237 
1238  BLI_assert(prop_store != NULL);
1239 
1240  if (!is_write_ok) {
1241  pyrna_write_set(true);
1242  }
1243 
1244  use_gil = true; /* !PyC_IsInterpreterActive(); */
1245 
1246  if (use_gil) {
1247  gilstate = PyGILState_Ensure();
1248  }
1249 
1250  py_func = prop_store->py_data.set_fn;
1251 
1252  args = PyTuple_New(2);
1253  self = pyrna_struct_as_instance(ptr);
1254  PyTuple_SET_ITEM(args, 0, self);
1255 
1256  py_values = PyC_Tuple_PackArray_F32(values, len);
1257  PyTuple_SET_ITEM(args, 1, py_values);
1258 
1259  ret = PyObject_CallObject(py_func, args);
1260 
1261  Py_DECREF(args);
1262 
1263  if (ret == NULL) {
1264  PyC_Err_PrintWithFunc(py_func);
1265  }
1266  else {
1267  if (ret != Py_None) {
1268  PyErr_SetString(PyExc_ValueError, "the return value must be None");
1269  PyC_Err_PrintWithFunc(py_func);
1270  }
1271 
1272  Py_DECREF(ret);
1273  }
1274 
1275  if (use_gil) {
1276  PyGILState_Release(gilstate);
1277  }
1278 
1279  if (!is_write_ok) {
1280  pyrna_write_set(false);
1281  }
1282 }
1283 
1286 /* -------------------------------------------------------------------- */
1290 static void bpy_prop_string_get_fn(struct PointerRNA *ptr, struct PropertyRNA *prop, char *value)
1291 {
1292  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
1293  PyObject *py_func;
1294  PyObject *args;
1295  PyObject *self;
1296  PyObject *ret;
1297  PyGILState_STATE gilstate;
1298  bool use_gil;
1299  const bool is_write_ok = pyrna_write_check();
1300 
1301  BLI_assert(prop_store != NULL);
1302 
1303  if (!is_write_ok) {
1304  pyrna_write_set(true);
1305  }
1306 
1307  use_gil = true; /* !PyC_IsInterpreterActive(); */
1308 
1309  if (use_gil) {
1310  gilstate = PyGILState_Ensure();
1311  }
1312 
1313  py_func = prop_store->py_data.get_fn;
1314 
1315  args = PyTuple_New(1);
1316  self = pyrna_struct_as_instance(ptr);
1317  PyTuple_SET_ITEM(args, 0, self);
1318 
1319  ret = PyObject_CallObject(py_func, args);
1320 
1321  Py_DECREF(args);
1322 
1323  if (ret == NULL) {
1324  PyC_Err_PrintWithFunc(py_func);
1325  value[0] = '\0';
1326  }
1327  else if (!PyUnicode_Check(ret)) {
1328  PyErr_Format(
1329  PyExc_TypeError, "return value must be a string, not %.200s", Py_TYPE(ret)->tp_name);
1330  PyC_Err_PrintWithFunc(py_func);
1331  value[0] = '\0';
1332  Py_DECREF(ret);
1333  }
1334  else {
1335  Py_ssize_t length;
1336  const char *buffer = PyUnicode_AsUTF8AndSize(ret, &length);
1337  memcpy(value, buffer, length + 1);
1338  Py_DECREF(ret);
1339  }
1340 
1341  if (use_gil) {
1342  PyGILState_Release(gilstate);
1343  }
1344 
1345  if (!is_write_ok) {
1346  pyrna_write_set(false);
1347  }
1348 }
1349 
1350 static int bpy_prop_string_length_fn(struct PointerRNA *ptr, struct PropertyRNA *prop)
1351 {
1352  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
1353  PyObject *py_func;
1354  PyObject *args;
1355  PyObject *self;
1356  PyObject *ret;
1357  PyGILState_STATE gilstate;
1358  bool use_gil;
1359  const bool is_write_ok = pyrna_write_check();
1360  int length;
1361 
1362  BLI_assert(prop_store != NULL);
1363 
1364  if (!is_write_ok) {
1365  pyrna_write_set(true);
1366  }
1367 
1368  use_gil = true; /* !PyC_IsInterpreterActive(); */
1369 
1370  if (use_gil) {
1371  gilstate = PyGILState_Ensure();
1372  }
1373 
1374  py_func = prop_store->py_data.get_fn;
1375 
1376  args = PyTuple_New(1);
1377  self = pyrna_struct_as_instance(ptr);
1378  PyTuple_SET_ITEM(args, 0, self);
1379 
1380  ret = PyObject_CallObject(py_func, args);
1381 
1382  Py_DECREF(args);
1383 
1384  if (ret == NULL) {
1385  PyC_Err_PrintWithFunc(py_func);
1386  length = 0;
1387  }
1388  else if (!PyUnicode_Check(ret)) {
1389  PyErr_Format(
1390  PyExc_TypeError, "return value must be a string, not %.200s", Py_TYPE(ret)->tp_name);
1391  PyC_Err_PrintWithFunc(py_func);
1392  length = 0;
1393  Py_DECREF(ret);
1394  }
1395  else {
1396  Py_ssize_t length_ssize_t = 0;
1397  PyUnicode_AsUTF8AndSize(ret, &length_ssize_t);
1398  length = length_ssize_t;
1399  Py_DECREF(ret);
1400  }
1401 
1402  if (use_gil) {
1403  PyGILState_Release(gilstate);
1404  }
1405 
1406  if (!is_write_ok) {
1407  pyrna_write_set(false);
1408  }
1409 
1410  return length;
1411 }
1412 
1414  struct PropertyRNA *prop,
1415  const char *value)
1416 {
1417  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
1418  PyObject *py_func;
1419  PyObject *args;
1420  PyObject *self;
1421  PyObject *ret;
1422  PyGILState_STATE gilstate;
1423  bool use_gil;
1424  const bool is_write_ok = pyrna_write_check();
1425  PyObject *py_value;
1426 
1427  BLI_assert(prop_store != NULL);
1428 
1429  if (!is_write_ok) {
1430  pyrna_write_set(true);
1431  }
1432 
1433  use_gil = true; /* !PyC_IsInterpreterActive(); */
1434 
1435  if (use_gil) {
1436  gilstate = PyGILState_Ensure();
1437  }
1438 
1439  py_func = prop_store->py_data.set_fn;
1440 
1441  args = PyTuple_New(2);
1442  self = pyrna_struct_as_instance(ptr);
1443  PyTuple_SET_ITEM(args, 0, self);
1444 
1445  py_value = PyUnicode_FromString(value);
1446  if (!py_value) {
1447  PyErr_SetString(PyExc_ValueError, "the return value must be a string");
1448  PyC_Err_PrintWithFunc(py_func);
1449  }
1450  else {
1451  PyTuple_SET_ITEM(args, 1, py_value);
1452  }
1453 
1454  ret = PyObject_CallObject(py_func, args);
1455 
1456  Py_DECREF(args);
1457 
1458  if (ret == NULL) {
1459  PyC_Err_PrintWithFunc(py_func);
1460  }
1461  else {
1462  if (ret != Py_None) {
1463  PyErr_SetString(PyExc_ValueError, "the return value must be None");
1464  PyC_Err_PrintWithFunc(py_func);
1465  }
1466 
1467  Py_DECREF(ret);
1468  }
1469 
1470  if (use_gil) {
1471  PyGILState_Release(gilstate);
1472  }
1473 
1474  if (!is_write_ok) {
1475  pyrna_write_set(false);
1476  }
1477 }
1478 
1481 /* -------------------------------------------------------------------- */
1485 static bool bpy_prop_pointer_poll_fn(struct PointerRNA *self,
1486  PointerRNA candidate,
1487  struct PropertyRNA *prop)
1488 {
1489  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
1490  PyObject *py_self;
1491  PyObject *py_candidate;
1492  PyObject *py_func;
1493  PyObject *args;
1494  PyObject *ret;
1495  bool result;
1496  const int is_write_ok = pyrna_write_check();
1497  const PyGILState_STATE gilstate = PyGILState_Ensure();
1498 
1499  BLI_assert(self != NULL);
1500 
1501  py_self = pyrna_struct_as_instance(self);
1502  py_candidate = pyrna_struct_as_instance(&candidate);
1503  py_func = prop_store->py_data.pointer_data.poll_fn;
1504 
1505  if (!is_write_ok) {
1506  pyrna_write_set(true);
1507  }
1508 
1509  args = PyTuple_New(2);
1510  PyTuple_SET_ITEM(args, 0, py_self);
1511  PyTuple_SET_ITEM(args, 1, py_candidate);
1512 
1513  ret = PyObject_CallObject(py_func, args);
1514 
1515  Py_DECREF(args);
1516 
1517  if (ret == NULL) {
1518  PyC_Err_PrintWithFunc(py_func);
1519  result = false;
1520  }
1521  else {
1522  result = PyObject_IsTrue(ret);
1523  Py_DECREF(ret);
1524  }
1525 
1526  PyGILState_Release(gilstate);
1527  if (!is_write_ok) {
1528  pyrna_write_set(false);
1529  }
1530 
1531  return result;
1532 }
1533 
1536 /* -------------------------------------------------------------------- */
1540 static int bpy_prop_enum_get_fn(struct PointerRNA *ptr, struct PropertyRNA *prop)
1541 {
1542  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
1543  PyObject *py_func;
1544  PyObject *args;
1545  PyObject *self;
1546  PyObject *ret;
1547  PyGILState_STATE gilstate;
1548  bool use_gil;
1549  const bool is_write_ok = pyrna_write_check();
1550  int value;
1551 
1552  BLI_assert(prop_store != NULL);
1553 
1554  if (!is_write_ok) {
1555  pyrna_write_set(true);
1556  }
1557 
1558  use_gil = true; /* !PyC_IsInterpreterActive(); */
1559 
1560  if (use_gil) {
1561  gilstate = PyGILState_Ensure();
1562  }
1563 
1564  py_func = prop_store->py_data.get_fn;
1565 
1566  args = PyTuple_New(1);
1567  self = pyrna_struct_as_instance(ptr);
1568  PyTuple_SET_ITEM(args, 0, self);
1569 
1570  ret = PyObject_CallObject(py_func, args);
1571 
1572  Py_DECREF(args);
1573 
1574  if (ret == NULL) {
1575  PyC_Err_PrintWithFunc(py_func);
1576  value = RNA_property_enum_get_default(ptr, prop);
1577  }
1578  else {
1579  value = PyC_Long_AsI32(ret);
1580 
1581  if (value == -1 && PyErr_Occurred()) {
1582  PyC_Err_PrintWithFunc(py_func);
1583  value = RNA_property_enum_get_default(ptr, prop);
1584  }
1585 
1586  Py_DECREF(ret);
1587  }
1588 
1589  if (use_gil) {
1590  PyGILState_Release(gilstate);
1591  }
1592 
1593  if (!is_write_ok) {
1594  pyrna_write_set(false);
1595  }
1596 
1597  return value;
1598 }
1599 
1600 static void bpy_prop_enum_set_fn(struct PointerRNA *ptr, struct PropertyRNA *prop, int value)
1601 {
1602  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
1603  PyObject *py_func;
1604  PyObject *args;
1605  PyObject *self;
1606  PyObject *ret;
1607  PyGILState_STATE gilstate;
1608  bool use_gil;
1609  const bool is_write_ok = pyrna_write_check();
1610 
1611  BLI_assert(prop_store != NULL);
1612 
1613  if (!is_write_ok) {
1614  pyrna_write_set(true);
1615  }
1616 
1617  use_gil = true; /* !PyC_IsInterpreterActive(); */
1618 
1619  if (use_gil) {
1620  gilstate = PyGILState_Ensure();
1621  }
1622 
1623  py_func = prop_store->py_data.set_fn;
1624 
1625  args = PyTuple_New(2);
1626  self = pyrna_struct_as_instance(ptr);
1627  PyTuple_SET_ITEM(args, 0, self);
1628 
1629  PyTuple_SET_ITEM(args, 1, PyLong_FromLong(value));
1630 
1631  ret = PyObject_CallObject(py_func, args);
1632 
1633  Py_DECREF(args);
1634 
1635  if (ret == NULL) {
1636  PyC_Err_PrintWithFunc(py_func);
1637  }
1638  else {
1639  if (ret != Py_None) {
1640  PyErr_SetString(PyExc_ValueError, "the return value must be None");
1641  PyC_Err_PrintWithFunc(py_func);
1642  }
1643 
1644  Py_DECREF(ret);
1645  }
1646 
1647  if (use_gil) {
1648  PyGILState_Release(gilstate);
1649  }
1650 
1651  if (!is_write_ok) {
1652  pyrna_write_set(false);
1653  }
1654 }
1655 
1656 /* utility function we need for parsing int's in an if statement */
1657 static bool py_long_as_int(PyObject *py_long, int *r_int)
1658 {
1659  if (PyLong_CheckExact(py_long)) {
1660  *r_int = (int)PyLong_AS_LONG(py_long);
1661  return true;
1662  }
1663 
1664  return false;
1665 }
1666 
1667 #if 0
1668 /* copies orig to buf, then sets orig to buf, returns copy length */
1669 static size_t strswapbufcpy(char *buf, const char **orig)
1670 {
1671  const char *src = *orig;
1672  char *dst = buf;
1673  size_t i = 0;
1674  *orig = buf;
1675  while ((*dst = *src)) {
1676  dst++;
1677  src++;
1678  i++;
1679  }
1680  return i + 1; /* include '\0' */
1681 }
1682 #endif
1683 
1684 static int icon_id_from_name(const char *name)
1685 {
1686  const EnumPropertyItem *item;
1687  int id;
1688 
1689  if (name[0]) {
1690  for (item = rna_enum_icon_items, id = 0; item->identifier; item++, id++) {
1691  if (STREQ(item->name, name)) {
1692  return item->value;
1693  }
1694  }
1695  }
1696 
1697  return 0;
1698 }
1699 
1700 static const EnumPropertyItem *enum_items_from_py(PyObject *seq_fast,
1701  PyObject *def,
1702  int *defvalue,
1703  const bool is_enum_flag)
1704 {
1705  EnumPropertyItem *items;
1706  PyObject *item;
1707  const Py_ssize_t seq_len = PySequence_Fast_GET_SIZE(seq_fast);
1708  PyObject **seq_fast_items = PySequence_Fast_ITEMS(seq_fast);
1709  Py_ssize_t totbuf = 0;
1710  int i;
1711  short def_used = 0;
1712  const char *def_string_cmp = NULL;
1713  int def_int_cmp = 0;
1714 
1715  if (is_enum_flag) {
1716  if (seq_len > RNA_ENUM_BITFLAG_SIZE) {
1717  PyErr_SetString(PyExc_TypeError,
1718  "EnumProperty(...): maximum " STRINGIFY(
1719  RNA_ENUM_BITFLAG_SIZE) " members for a ENUM_FLAG type property");
1720  return NULL;
1721  }
1722  if (def && !PySet_Check(def)) {
1723  PyErr_Format(PyExc_TypeError,
1724  "EnumProperty(...): default option must be a 'set' "
1725  "type when ENUM_FLAG is enabled, not a '%.200s'",
1726  Py_TYPE(def)->tp_name);
1727  return NULL;
1728  }
1729  }
1730  else {
1731  if (def) {
1732  if (!py_long_as_int(def, &def_int_cmp)) {
1733  def_string_cmp = PyUnicode_AsUTF8(def);
1734  if (def_string_cmp == NULL) {
1735  PyErr_Format(PyExc_TypeError,
1736  "EnumProperty(...): default option must be a 'str' or 'int' "
1737  "type when ENUM_FLAG is disabled, not a '%.200s'",
1738  Py_TYPE(def)->tp_name);
1739  return NULL;
1740  }
1741  }
1742  }
1743  }
1744 
1745  /* blank value */
1746  *defvalue = 0;
1747 
1748  items = MEM_callocN(sizeof(EnumPropertyItem) * (seq_len + 1), "enum_items_from_py1");
1749 
1750  for (i = 0; i < seq_len; i++) {
1751  EnumPropertyItem tmp = {0, "", 0, "", ""};
1752  const char *tmp_icon = NULL;
1753  Py_ssize_t item_size;
1754  Py_ssize_t id_str_size;
1755  Py_ssize_t name_str_size;
1756  Py_ssize_t desc_str_size;
1757 
1758  item = seq_fast_items[i];
1759 
1760  if ((PyTuple_CheckExact(item)) && (item_size = PyTuple_GET_SIZE(item)) &&
1761  (item_size >= 3 && item_size <= 5) &&
1762  (tmp.identifier = PyUnicode_AsUTF8AndSize(PyTuple_GET_ITEM(item, 0), &id_str_size)) &&
1763  (tmp.name = PyUnicode_AsUTF8AndSize(PyTuple_GET_ITEM(item, 1), &name_str_size)) &&
1764  (tmp.description = PyUnicode_AsUTF8AndSize(PyTuple_GET_ITEM(item, 2), &desc_str_size)) &&
1765  /* TODO, number isn't ensured to be unique from the script author */
1766  (item_size != 4 || py_long_as_int(PyTuple_GET_ITEM(item, 3), &tmp.value)) &&
1767  (item_size != 5 || ((py_long_as_int(PyTuple_GET_ITEM(item, 3), &tmp.icon) ||
1768  (tmp_icon = PyUnicode_AsUTF8(PyTuple_GET_ITEM(item, 3)))) &&
1769  py_long_as_int(PyTuple_GET_ITEM(item, 4), &tmp.value)))) {
1770  if (is_enum_flag) {
1771  if (item_size < 4) {
1772  tmp.value = 1 << i;
1773  }
1774 
1775  if (def && PySet_Contains(def, PyTuple_GET_ITEM(item, 0))) {
1776  *defvalue |= tmp.value;
1777  def_used++;
1778  }
1779  }
1780  else {
1781  if (item_size < 4) {
1782  tmp.value = i;
1783  }
1784 
1785  if (def && def_used == 0) {
1786  if ((def_string_cmp != NULL && STREQ(def_string_cmp, tmp.identifier)) ||
1787  (def_string_cmp == NULL && def_int_cmp == tmp.value)) {
1788  *defvalue = tmp.value;
1789  def_used++; /* only ever 1 */
1790  }
1791  }
1792  }
1793 
1794  if (tmp_icon) {
1795  tmp.icon = icon_id_from_name(tmp_icon);
1796  }
1797 
1798  items[i] = tmp;
1799 
1800  /* calculate combine string length */
1801  totbuf += id_str_size + name_str_size + desc_str_size + 3; /* 3 is for '\0's */
1802  }
1803  else if (item == Py_None) {
1804  /* Only set since the rest is cleared. */
1805  items[i].identifier = "";
1806  }
1807  else {
1808  MEM_freeN(items);
1809  PyErr_SetString(PyExc_TypeError,
1810  "EnumProperty(...): expected a tuple containing "
1811  "(identifier, name, description) and optionally an "
1812  "icon name and unique number");
1813  return NULL;
1814  }
1815  }
1816 
1817  if (is_enum_flag) {
1818  /* strict check that all set members were used */
1819  if (def && def_used != PySet_GET_SIZE(def)) {
1820  MEM_freeN(items);
1821 
1822  PyErr_Format(PyExc_TypeError,
1823  "EnumProperty(..., default={...}): set has %d unused member(s)",
1824  PySet_GET_SIZE(def) - def_used);
1825  return NULL;
1826  }
1827  }
1828  else {
1829  if (def && def_used == 0) {
1830  MEM_freeN(items);
1831 
1832  if (def_string_cmp) {
1833  PyErr_Format(PyExc_TypeError,
1834  "EnumProperty(..., default=\'%s\'): not found in enum members",
1835  def_string_cmp);
1836  }
1837  else {
1838  PyErr_Format(PyExc_TypeError,
1839  "EnumProperty(..., default=%d): not found in enum members",
1840  def_int_cmp);
1841  }
1842  return NULL;
1843  }
1844  }
1845 
1846  /* disabled duplicating strings because the array can still be freed and
1847  * the strings from it referenced, for now we can't support dynamically
1848  * created strings from python. */
1849 #if 0
1850  /* this would all work perfectly _but_ the python strings may be freed
1851  * immediately after use, so we need to duplicate them, ugh.
1852  * annoying because it works most of the time without this. */
1853  {
1854  EnumPropertyItem *items_dup = MEM_mallocN((sizeof(EnumPropertyItem) * (seq_len + 1)) +
1855  (sizeof(char) * totbuf),
1856  "enum_items_from_py2");
1857  EnumPropertyItem *items_ptr = items_dup;
1858  char *buf = ((char *)items_dup) + (sizeof(EnumPropertyItem) * (seq_len + 1));
1859  memcpy(items_dup, items, sizeof(EnumPropertyItem) * (seq_len + 1));
1860  for (i = 0; i < seq_len; i++, items_ptr++) {
1861  buf += strswapbufcpy(buf, &items_ptr->identifier);
1862  buf += strswapbufcpy(buf, &items_ptr->name);
1863  buf += strswapbufcpy(buf, &items_ptr->description);
1864  }
1865  MEM_freeN(items);
1866  items = items_dup;
1867  }
1868  /* end string duplication */
1869 #endif
1870 
1871  return items;
1872 }
1873 
1875  PointerRNA *ptr,
1876  PropertyRNA *prop,
1877  bool *r_free)
1878 {
1879  PyGILState_STATE gilstate;
1880  struct BPyPropStore *prop_store = RNA_property_py_data_get(prop);
1881  PyObject *py_func = prop_store->py_data.enum_data.itemf_fn;
1882  PyObject *self = NULL;
1883  PyObject *args;
1884  PyObject *items; /* returned from the function call */
1885 
1886  const EnumPropertyItem *eitems = NULL;
1887  int err = 0;
1888 
1889  if (C) {
1890  bpy_context_set(C, &gilstate);
1891  }
1892  else {
1893  gilstate = PyGILState_Ensure();
1894  }
1895 
1896  args = PyTuple_New(2);
1897  self = pyrna_struct_as_instance(ptr);
1898  PyTuple_SET_ITEM(args, 0, self);
1899 
1900  /* now get the context */
1901  if (C) {
1902  PyTuple_SET_ITEM(args, 1, (PyObject *)bpy_context_module);
1903  Py_INCREF(bpy_context_module);
1904  }
1905  else {
1906  PyTuple_SET_ITEM(args, 1, Py_None);
1907  Py_INCREF(Py_None);
1908  }
1909 
1910  items = PyObject_CallObject(py_func, args);
1911 
1912  Py_DECREF(args);
1913 
1914  if (items == NULL) {
1915  err = -1;
1916  }
1917  else {
1918  PyObject *items_fast;
1919  int defvalue_dummy = 0;
1920 
1921  if (!(items_fast = PySequence_Fast(items,
1922  "EnumProperty(...): "
1923  "return value from the callback was not a sequence"))) {
1924  err = -1;
1925  }
1926  else {
1927  eitems = enum_items_from_py(
1928  items_fast, NULL, &defvalue_dummy, (RNA_property_flag(prop) & PROP_ENUM_FLAG) != 0);
1929 
1930  Py_DECREF(items_fast);
1931 
1932  if (!eitems) {
1933  err = -1;
1934  }
1935  }
1936 
1937  Py_DECREF(items);
1938  }
1939 
1940  if (err != -1) { /* worked */
1941  *r_free = true;
1942  }
1943  else {
1944  PyC_Err_PrintWithFunc(py_func);
1945 
1946  eitems = DummyRNA_NULL_items;
1947  }
1948 
1949  if (C) {
1950  bpy_context_clear(C, &gilstate);
1951  }
1952  else {
1953  PyGILState_Release(gilstate);
1954  }
1955 
1956  return eitems;
1957 }
1958 
1959 static int bpy_prop_callback_check(PyObject *py_func, const char *keyword, int argcount)
1960 {
1961  if (py_func && py_func != Py_None) {
1962  if (!PyFunction_Check(py_func)) {
1963  PyErr_Format(PyExc_TypeError,
1964  "%s keyword: expected a function type, not a %.200s",
1965  keyword,
1966  Py_TYPE(py_func)->tp_name);
1967  return -1;
1968  }
1969 
1970  PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(py_func);
1971  if (f_code->co_argcount != argcount) {
1972  PyErr_Format(PyExc_TypeError,
1973  "%s keyword: expected a function taking %d arguments, not %d",
1974  keyword,
1975  argcount,
1976  f_code->co_argcount);
1977  return -1;
1978  }
1979  }
1980 
1981  return 0;
1982 }
1983 
1986 /* -------------------------------------------------------------------- */
1990 static void bpy_prop_callback_assign_update(struct PropertyRNA *prop, PyObject *update_fn)
1991 {
1992  /* assume this is already checked for type and arg length */
1993  if (update_fn && update_fn != Py_None) {
1994  struct BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
1995 
1998 
2000  }
2001 }
2002 
2003 static void bpy_prop_callback_assign_pointer(struct PropertyRNA *prop, PyObject *poll_fn)
2004 {
2005  if (poll_fn && poll_fn != Py_None) {
2006  struct BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2007 
2009  ASSIGN_PYOBJECT_INCREF(prop_store->py_data.pointer_data.poll_fn, poll_fn);
2010  }
2011 }
2012 
2014  PyObject *get_fn,
2015  PyObject *set_fn)
2016 {
2017  BooleanPropertyGetFunc rna_get_fn = NULL;
2018  BooleanPropertySetFunc rna_set_fn = NULL;
2019 
2020  if (get_fn && get_fn != Py_None) {
2021  struct BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2022 
2023  rna_get_fn = bpy_prop_boolean_get_fn;
2025  }
2026 
2027  if (set_fn && set_fn != Py_None) {
2028  struct BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2029 
2030  rna_set_fn = bpy_prop_boolean_set_fn;
2032  }
2033 
2034  RNA_def_property_boolean_funcs_runtime(prop, rna_get_fn, rna_set_fn);
2035 }
2036 
2038  PyObject *get_fn,
2039  PyObject *set_fn)
2040 {
2041  BooleanArrayPropertyGetFunc rna_get_fn = NULL;
2042  BooleanArrayPropertySetFunc rna_set_fn = NULL;
2043 
2044  if (get_fn && get_fn != Py_None) {
2045  struct BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2046 
2047  rna_get_fn = bpy_prop_boolean_array_get_fn;
2049  }
2050 
2051  if (set_fn && set_fn != Py_None) {
2052  struct BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2053 
2054  rna_set_fn = bpy_prop_boolean_array_set_fn;
2056  }
2057 
2058  RNA_def_property_boolean_array_funcs_runtime(prop, rna_get_fn, rna_set_fn);
2059 }
2060 
2062  PyObject *get_fn,
2063  PyObject *set_fn)
2064 {
2065  IntPropertyGetFunc rna_get_fn = NULL;
2066  IntPropertySetFunc rna_set_fn = NULL;
2067 
2068  if (get_fn && get_fn != Py_None) {
2069  struct BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2070 
2071  rna_get_fn = bpy_prop_int_get_fn;
2073  }
2074 
2075  if (set_fn && set_fn != Py_None) {
2076  struct BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2077 
2078  rna_set_fn = bpy_prop_int_set_fn;
2080  }
2081 
2082  RNA_def_property_int_funcs_runtime(prop, rna_get_fn, rna_set_fn, NULL);
2083 }
2084 
2086  PyObject *get_fn,
2087  PyObject *set_fn)
2088 {
2089  IntArrayPropertyGetFunc rna_get_fn = NULL;
2090  IntArrayPropertySetFunc rna_set_fn = NULL;
2091 
2092  if (get_fn && get_fn != Py_None) {
2093  struct BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2094 
2095  rna_get_fn = bpy_prop_int_array_get_fn;
2097  }
2098 
2099  if (set_fn && set_fn != Py_None) {
2100  struct BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2101 
2102  rna_set_fn = bpy_prop_int_array_set_fn;
2104  }
2105 
2106  RNA_def_property_int_array_funcs_runtime(prop, rna_get_fn, rna_set_fn, NULL);
2107 }
2108 
2110  PyObject *get_fn,
2111  PyObject *set_fn)
2112 {
2113  FloatPropertyGetFunc rna_get_fn = NULL;
2114  FloatPropertySetFunc rna_set_fn = NULL;
2115 
2116  if (get_fn && get_fn != Py_None) {
2117  struct BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2118 
2119  rna_get_fn = bpy_prop_float_get_fn;
2121  }
2122 
2123  if (set_fn && set_fn != Py_None) {
2124  struct BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2125 
2126  rna_set_fn = bpy_prop_float_set_fn;
2128  }
2129 
2130  RNA_def_property_float_funcs_runtime(prop, rna_get_fn, rna_set_fn, NULL);
2131 }
2132 
2134  PyObject *get_fn,
2135  PyObject *set_fn)
2136 {
2137  FloatArrayPropertyGetFunc rna_get_fn = NULL;
2138  FloatArrayPropertySetFunc rna_set_fn = NULL;
2139 
2140  if (get_fn && get_fn != Py_None) {
2141  struct BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2142 
2143  rna_get_fn = bpy_prop_float_array_get_fn;
2145  }
2146 
2147  if (set_fn && set_fn != Py_None) {
2148  struct BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2149 
2150  rna_set_fn = bpy_prop_float_array_set_fn;
2152  }
2153 
2154  RNA_def_property_float_array_funcs_runtime(prop, rna_get_fn, rna_set_fn, NULL);
2155 }
2156 
2158  PyObject *get_fn,
2159  PyObject *set_fn)
2160 {
2161  StringPropertyGetFunc rna_get_fn = NULL;
2162  StringPropertyLengthFunc rna_length_fn = NULL;
2163  StringPropertySetFunc rna_set_fn = NULL;
2164 
2165  if (get_fn && get_fn != Py_None) {
2166  struct BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2167 
2168  rna_get_fn = bpy_prop_string_get_fn;
2169  rna_length_fn = bpy_prop_string_length_fn;
2171  }
2172 
2173  if (set_fn && set_fn != Py_None) {
2174  struct BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2175 
2176  rna_set_fn = bpy_prop_string_set_fn;
2178  }
2179 
2180  RNA_def_property_string_funcs_runtime(prop, rna_get_fn, rna_length_fn, rna_set_fn);
2181 }
2182 
2184  PyObject *get_fn,
2185  PyObject *set_fn,
2186  PyObject *itemf_fn)
2187 {
2188  EnumPropertyGetFunc rna_get_fn = NULL;
2189  EnumPropertyItemFunc rna_itemf_fn = NULL;
2190  EnumPropertySetFunc rna_set_fn = NULL;
2191 
2192  if (get_fn && get_fn != Py_None) {
2193  struct BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2194 
2195  rna_get_fn = bpy_prop_enum_get_fn;
2197  }
2198 
2199  if (set_fn && set_fn != Py_None) {
2200  struct BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2201 
2202  rna_set_fn = bpy_prop_enum_set_fn;
2204  }
2205 
2206  if (itemf_fn && itemf_fn != Py_None) {
2207  struct BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop);
2208  rna_itemf_fn = bpy_prop_enum_itemf_fn;
2209  ASSIGN_PYOBJECT_INCREF(prop_store->py_data.enum_data.itemf_fn, itemf_fn);
2210  }
2211 
2212  RNA_def_property_enum_funcs_runtime(prop, rna_get_fn, rna_set_fn, rna_itemf_fn);
2213 }
2214 
2217 /* -------------------------------------------------------------------- */
2221 /* this define runs at the start of each function and deals with
2222  * returning a deferred property (to be registered later) */
2223 #define BPY_PROPDEF_HEAD(_func) \
2224  if (PyTuple_GET_SIZE(args) == 1) { \
2225  PyObject *ret; \
2226  self = PyTuple_GET_ITEM(args, 0); \
2227  args = PyTuple_New(0); \
2228  ret = BPy_##_func(self, args, kw); \
2229  Py_DECREF(args); \
2230  return ret; \
2231  } \
2232  if (PyTuple_GET_SIZE(args) > 1) { \
2233  PyErr_SetString(PyExc_ValueError, "all args must be keywords"); \
2234  return NULL; \
2235  } \
2236  srna = srna_from_self(self, #_func "(...):"); \
2237  if (srna == NULL) { \
2238  if (PyErr_Occurred()) { \
2239  return NULL; \
2240  } \
2241  return bpy_prop_deferred_data_CreatePyObject(pymeth_##_func, kw); \
2242  } \
2243  (void)0
2244 
2245 /* terse macros for error checks shared between all funcs cant use function
2246  * calls because of static strings passed to pyrna_set_to_enum_bitfield */
2247 #define BPY_PROPDEF_CHECK(_func, _property_flag_items, _property_flag_override_items) \
2248  if (UNLIKELY(id_len >= MAX_IDPROP_NAME)) { \
2249  PyErr_Format(PyExc_TypeError, \
2250  #_func "(): '%.200s' too long, max length is %d", \
2251  id, \
2252  MAX_IDPROP_NAME - 1); \
2253  return NULL; \
2254  } \
2255  if (UNLIKELY(RNA_def_property_free_identifier(srna, id) == -1)) { \
2256  PyErr_Format(PyExc_TypeError, #_func "(): '%s' is defined as a non-dynamic type", id); \
2257  return NULL; \
2258  } \
2259  if (UNLIKELY(pyopts && pyrna_set_to_enum_bitfield( \
2260  _property_flag_items, pyopts, &opts, #_func "(options={ ...}):"))) { \
2261  return NULL; \
2262  } \
2263  if (UNLIKELY(pyopts_override && pyrna_set_to_enum_bitfield(_property_flag_override_items, \
2264  pyopts_override, \
2265  &opts_override, \
2266  #_func "(override={ ...}):"))) { \
2267  return NULL; \
2268  } \
2269  { \
2270  const EnumPropertyItem *tag_defines = RNA_struct_property_tag_defines(srna); \
2271  if (py_tags && !tag_defines) { \
2272  PyErr_Format(PyExc_TypeError, \
2273  #_func "(): property-tags not available for '%s'", \
2274  RNA_struct_identifier(srna)); \
2275  return NULL; \
2276  } \
2277  if (UNLIKELY(py_tags && pyrna_set_to_enum_bitfield( \
2278  tag_defines, py_tags, &prop_tags, #_func "(tags={ ...}):"))) { \
2279  return NULL; \
2280  } \
2281  } \
2282  (void)0
2283 
2284 #define BPY_PROPDEF_SUBTYPE_CHECK( \
2285  _func, _property_flag_items, _property_flag_override_items, _subtype) \
2286  BPY_PROPDEF_CHECK(_func, _property_flag_items, _property_flag_override_items); \
2287  if (UNLIKELY(pysubtype && RNA_enum_value_from_id(_subtype, pysubtype, &subtype) == 0)) { \
2288  const char *enum_str = BPy_enum_as_string(_subtype); \
2289  PyErr_Format(PyExc_TypeError, \
2290  #_func \
2291  "(subtype='%s'): " \
2292  "subtype not found in (%s)", \
2293  pysubtype, \
2294  enum_str); \
2295  MEM_freeN((void *)enum_str); \
2296  return NULL; \
2297  } \
2298  (void)0
2299 
2302 /* -------------------------------------------------------------------- */
2306 #define BPY_PROPDEF_NAME_DOC \
2307  " :arg name: Name used in the user interface.\n" \
2308  " :type name: string\n"
2309 
2310 #define BPY_PROPDEF_DESC_DOC \
2311  " :arg description: Text used for the tooltip and api documentation.\n" \
2312  " :type description: string\n"
2313 
2314 #define BPY_PROPDEF_UNIT_DOC \
2315  " :arg unit: Enumerator in ['NONE', 'LENGTH', 'AREA', 'VOLUME', 'ROTATION', 'TIME', " \
2316  "'VELOCITY', 'ACCELERATION', 'MASS', 'CAMERA', 'POWER'].\n" \
2317  " :type unit: string\n"
2318 
2319 #define BPY_PROPDEF_NUM_MIN_DOC \
2320  " :arg min: Hard minimum, trying to assign a value below will silently assign this minimum " \
2321  "instead.\n"
2322 
2323 #define BPY_PROPDEF_NUM_MAX_DOC \
2324  " :arg max: Hard maximum, trying to assign a value above will silently assign this maximum " \
2325  "instead.\n"
2326 
2327 #define BPY_PROPDEF_NUM_SOFTMIN_DOC \
2328  " :arg soft_min: Soft minimum (>= *min*), user won't be able to drag the widget below this " \
2329  "value in the UI.\n"
2330 
2331 #define BPY_PROPDEF_NUM_SOFTMAX_DOC \
2332  " :arg soft_max: Soft maximum (<= *max*), user won't be able to drag the widget above this " \
2333  "value in the UI.\n"
2334 
2335 #define BPY_PROPDEF_VECSIZE_DOC \
2336  " :arg size: Vector dimensions in [1, " STRINGIFY(PYRNA_STACK_ARRAY) "].\n" \
2337 " :type size: int\n"
2338 
2339 #define BPY_PROPDEF_INT_STEP_DOC \
2340  " :arg step: Step of increment/decrement in UI, in [1, 100], defaults to 1 (WARNING: unused " \
2341  "currently!).\n" \
2342  " :type step: int\n"
2343 
2344 #define BPY_PROPDEF_FLOAT_STEP_DOC \
2345  " :arg step: Step of increment/decrement in UI, in [1, 100], defaults to 3 (WARNING: actual " \
2346  "value is /100).\n" \
2347  " :type step: int\n"
2348 
2349 #define BPY_PROPDEF_FLOAT_PREC_DOC \
2350  " :arg precision: Maximum number of decimal digits to display, in [0, 6].\n" \
2351  " :type precision: int\n"
2352 
2353 #define BPY_PROPDEF_UPDATE_DOC \
2354  " :arg update: Function to be called when this value is modified,\n" \
2355  " This function must take 2 values (self, context) and return None.\n" \
2356  " *Warning* there are no safety checks to avoid infinite recursion.\n" \
2357  " :type update: function\n"
2358 
2359 #define BPY_PROPDEF_POLL_DOC \
2360  " :arg poll: function to be called to determine whether an item is valid for this " \
2361  "property.\n" \
2362  " The function must take 2 values (self, object) and return Bool.\n" \
2363  " :type poll: function\n"
2364 
2365 #define BPY_PROPDEF_GET_DOC \
2366  " :arg get: Function to be called when this value is 'read',\n" \
2367  " This function must take 1 value (self) and return the value of the property.\n" \
2368  " :type get: function\n"
2369 
2370 #define BPY_PROPDEF_SET_DOC \
2371  " :arg set: Function to be called when this value is 'written',\n" \
2372  " This function must take 2 values (self, value) and return None.\n" \
2373  " :type set: function\n"
2374 
2375 #define BPY_PROPDEF_TYPE_DOC \
2376  " :arg type: A subclass of :class:`bpy.types.PropertyGroup` or :class:`bpy.types.ID`.\n" \
2377  " :type type: class\n"
2378 
2379 #define BPY_PROPDEF_TAGS_DOC \
2380  " :arg tags: Enumerator of tags that are defined by parent class.\n" \
2381  " :type tags: set\n"
2382 
2383 #if 0
2384 static int bpy_struct_id_used(StructRNA *srna, char *identifier)
2385 {
2386  PointerRNA ptr;
2387  RNA_pointer_create(NULL, srna, NULL, &ptr);
2388  return (RNA_struct_find_property(&ptr, identifier) != NULL);
2389 }
2390 #endif
2391 
2394 /* -------------------------------------------------------------------- */
2398 /* Function that sets RNA, NOTE - self is NULL when called from python,
2399  * but being abused from C so we can pass the srna along.
2400  * This isn't incorrect since its a python object - but be careful */
2401 PyDoc_STRVAR(BPy_BoolProperty_doc,
2402  ".. function:: BoolProperty(name=\"\", "
2403  "description=\"\", "
2404  "default=False, "
2405  "options={'ANIMATABLE'}, "
2406  "override=set(), "
2407  "tags=set(), "
2408  "subtype='NONE', "
2409  "update=None, "
2410  "get=None, "
2411  "set=None)\n"
2412  "\n"
2413  " Returns a new boolean property definition.\n"
2418 static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
2419 {
2420  StructRNA *srna;
2421 
2422  BPY_PROPDEF_HEAD(BoolProperty);
2423 
2424  if (srna) {
2425  const char *id = NULL, *name = NULL, *description = "";
2426  Py_ssize_t id_len;
2427  bool def = false;
2428  PropertyRNA *prop;
2429  PyObject *pyopts = NULL;
2430  PyObject *pyopts_override = NULL;
2431  int opts = 0;
2432  int opts_override = 0;
2433  int prop_tags = 0;
2434  const char *pysubtype = NULL;
2435  int subtype = PROP_NONE;
2436  PyObject *update_fn = NULL;
2437  PyObject *get_fn = NULL;
2438  PyObject *set_fn = NULL;
2439  PyObject *py_tags = NULL;
2440 
2441  static const char *_keywords[] = {
2442  "attr",
2443  "name",
2444  "description",
2445  "default",
2446  "options",
2447  "override",
2448  "tags",
2449  "subtype",
2450  "update",
2451  "get",
2452  "set",
2453  NULL,
2454  };
2455  static _PyArg_Parser _parser = {"s#|ssO&O!O!O!sOOO:BoolProperty", _keywords, 0};
2456  if (!_PyArg_ParseTupleAndKeywordsFast(args,
2457  kw,
2458  &_parser,
2459  &id,
2460  &id_len,
2461  &name,
2462  &description,
2463  PyC_ParseBool,
2464  &def,
2465  &PySet_Type,
2466  &pyopts,
2467  &PySet_Type,
2468  &pyopts_override,
2469  &PySet_Type,
2470  &py_tags,
2471  &pysubtype,
2472  &update_fn,
2473  &get_fn,
2474  &set_fn)) {
2475  return NULL;
2476  }
2477 
2478  BPY_PROPDEF_SUBTYPE_CHECK(BoolProperty,
2482 
2483  if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
2484  return NULL;
2485  }
2486  if (bpy_prop_callback_check(get_fn, "get", 1) == -1) {
2487  return NULL;
2488  }
2489  if (bpy_prop_callback_check(set_fn, "set", 2) == -1) {
2490  return NULL;
2491  }
2492 
2493  prop = RNA_def_property(srna, id, PROP_BOOLEAN, subtype);
2495  RNA_def_property_ui_text(prop, name ? name : id, description);
2496 
2497  if (py_tags) {
2498  RNA_def_property_tags(prop, prop_tags);
2499  }
2500  if (pyopts) {
2501  bpy_prop_assign_flag(prop, opts);
2502  }
2503  if (pyopts_override) {
2504  bpy_prop_assign_flag_override(prop, opts_override);
2505  }
2509  }
2510 
2511  Py_RETURN_NONE;
2512 }
2513 
2515  BPy_BoolVectorProperty_doc,
2516  ".. function:: BoolVectorProperty(name=\"\", "
2517  "description=\"\", "
2518  "default=(False, False, False), "
2519  "options={'ANIMATABLE'}, "
2520  "override=set(), "
2521  "tags=set(), "
2522  "subtype='NONE', "
2523  "size=3, "
2524  "update=None, "
2525  "get=None, "
2526  "set=None)\n"
2527  "\n"
2528  " Returns a new vector boolean property definition.\n"
2530  " :arg default: sequence of booleans the length of *size*.\n"
2531  " :type default: sequence\n" BPY_PROPDEF_OPTIONS_DOC BPY_PROPDEF_OPTIONS_OVERRIDE_DOC
2534 static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
2535 {
2536  StructRNA *srna;
2537 
2538  BPY_PROPDEF_HEAD(BoolVectorProperty);
2539 
2540  if (srna) {
2541  const char *id = NULL, *name = NULL, *description = "";
2542  Py_ssize_t id_len;
2543  bool def[PYRNA_STACK_ARRAY] = {0};
2544  int size = 3;
2545  PropertyRNA *prop;
2546  PyObject *pydef = NULL;
2547  PyObject *pyopts = NULL;
2548  PyObject *pyopts_override = NULL;
2549  int opts = 0;
2550  int opts_override = 0;
2551  int prop_tags = 0;
2552  const char *pysubtype = NULL;
2553  int subtype = PROP_NONE;
2554  PyObject *update_fn = NULL;
2555  PyObject *get_fn = NULL;
2556  PyObject *set_fn = NULL;
2557  PyObject *py_tags = NULL;
2558 
2559  static const char *_keywords[] = {
2560  "attr",
2561  "name",
2562  "description",
2563  "default",
2564  "options",
2565  "override",
2566  "tags",
2567  "subtype",
2568  "size",
2569  "update",
2570  "get",
2571  "set",
2572  NULL,
2573  };
2574  static _PyArg_Parser _parser = {"s#|ssOO!O!O!siOOO:BoolVectorProperty", _keywords, 0};
2575  if (!_PyArg_ParseTupleAndKeywordsFast(args,
2576  kw,
2577  &_parser,
2578  &id,
2579  &id_len,
2580  &name,
2581  &description,
2582  &pydef,
2583  &PySet_Type,
2584  &pyopts,
2585  &PySet_Type,
2586  &pyopts_override,
2587  &PySet_Type,
2588  &py_tags,
2589  &pysubtype,
2590  &size,
2591  &update_fn,
2592  &get_fn,
2593  &set_fn)) {
2594  return NULL;
2595  }
2596 
2597  BPY_PROPDEF_SUBTYPE_CHECK(BoolVectorProperty,
2601 
2602  if (size < 1 || size > PYRNA_STACK_ARRAY) {
2603  PyErr_Format(
2604  PyExc_TypeError,
2605  "BoolVectorProperty(size=%d): size must be between 0 and " STRINGIFY(PYRNA_STACK_ARRAY),
2606  size);
2607  return NULL;
2608  }
2609 
2610  if (pydef &&
2611  PyC_AsArray(
2612  def, pydef, size, &PyBool_Type, false, "BoolVectorProperty(default=sequence)") == -1) {
2613  return NULL;
2614  }
2615 
2616  if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
2617  return NULL;
2618  }
2619  if (bpy_prop_callback_check(get_fn, "get", 1) == -1) {
2620  return NULL;
2621  }
2622  if (bpy_prop_callback_check(set_fn, "set", 2) == -1) {
2623  return NULL;
2624  }
2625 
2626 #if 0
2627  prop = RNA_def_boolean_array(
2628  srna, id, size, pydef ? def : NULL, name ? name : id, description);
2629 #endif
2630  prop = RNA_def_property(srna, id, PROP_BOOLEAN, subtype);
2632  if (pydef) {
2634  }
2635  RNA_def_property_ui_text(prop, name ? name : id, description);
2636 
2637  if (py_tags) {
2638  RNA_def_property_tags(prop, prop_tags);
2639  }
2640  if (pyopts) {
2641  bpy_prop_assign_flag(prop, opts);
2642  }
2643  if (pyopts_override) {
2644  bpy_prop_assign_flag_override(prop, opts_override);
2645  }
2649  }
2650 
2651  Py_RETURN_NONE;
2652 }
2653 
2655  BPy_IntProperty_doc,
2656  ".. function:: IntProperty(name=\"\", "
2657  "description=\"\", "
2658  "default=0, "
2659  "min=-2**31, max=2**31-1, "
2660  "soft_min=-2**31, soft_max=2**31-1, "
2661  "step=1, "
2662  "options={'ANIMATABLE'}, "
2663  "override=set(), "
2664  "tags=set(), "
2665  "subtype='NONE', "
2666  "update=None, "
2667  "get=None, "
2668  "set=None)\n"
2669  "\n"
2670  " Returns a new int property definition.\n"
2672  " :type min: int\n" BPY_PROPDEF_NUM_MAX_DOC " :type max: int\n" BPY_PROPDEF_NUM_SOFTMAX_DOC
2673  " :type soft_min: int\n" BPY_PROPDEF_NUM_SOFTMIN_DOC
2674  " :type soft_max: int\n" BPY_PROPDEF_INT_STEP_DOC BPY_PROPDEF_OPTIONS_DOC
2677 static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
2678 {
2679  StructRNA *srna;
2680 
2681  BPY_PROPDEF_HEAD(IntProperty);
2682 
2683  if (srna) {
2684  const char *id = NULL, *name = NULL, *description = "";
2685  Py_ssize_t id_len;
2686  int min = INT_MIN, max = INT_MAX, soft_min = INT_MIN, soft_max = INT_MAX, step = 1, def = 0;
2687  PropertyRNA *prop;
2688  PyObject *pyopts = NULL;
2689  int opts = 0;
2690  PyObject *pyopts_override = NULL;
2691  int opts_override = 0;
2692  int prop_tags = 0;
2693  const char *pysubtype = NULL;
2694  int subtype = PROP_NONE;
2695  PyObject *update_fn = NULL;
2696  PyObject *get_fn = NULL;
2697  PyObject *set_fn = NULL;
2698  PyObject *py_tags = NULL;
2699 
2700  static const char *_keywords[] = {
2701  "attr",
2702  "name",
2703  "description",
2704  "default",
2705  "min",
2706  "max",
2707  "soft_min",
2708  "soft_max",
2709  "step",
2710  "options",
2711  "override",
2712  "tags",
2713  "subtype",
2714  "update",
2715  "get",
2716  "set",
2717  NULL,
2718  };
2719  static _PyArg_Parser _parser = {"s#|ssiiiiiiO!O!O!sOOO:IntProperty", _keywords, 0};
2720  if (!_PyArg_ParseTupleAndKeywordsFast(args,
2721  kw,
2722  &_parser,
2723  &id,
2724  &id_len,
2725  &name,
2726  &description,
2727  &def,
2728  &min,
2729  &max,
2730  &soft_min,
2731  &soft_max,
2732  &step,
2733  &PySet_Type,
2734  &pyopts,
2735  &PySet_Type,
2736  &pyopts_override,
2737  &PySet_Type,
2738  &py_tags,
2739  &pysubtype,
2740  &update_fn,
2741  &get_fn,
2742  &set_fn)) {
2743  return NULL;
2744  }
2745 
2746  BPY_PROPDEF_SUBTYPE_CHECK(IntProperty,
2750 
2751  if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
2752  return NULL;
2753  }
2754  if (bpy_prop_callback_check(get_fn, "get", 1) == -1) {
2755  return NULL;
2756  }
2757  if (bpy_prop_callback_check(set_fn, "set", 2) == -1) {
2758  return NULL;
2759  }
2760 
2761  prop = RNA_def_property(srna, id, PROP_INT, subtype);
2762  RNA_def_property_int_default(prop, def);
2763  RNA_def_property_ui_text(prop, name ? name : id, description);
2764  RNA_def_property_range(prop, min, max);
2765  RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, 3);
2766 
2767  if (py_tags) {
2768  RNA_def_property_tags(prop, prop_tags);
2769  }
2770  if (pyopts) {
2771  bpy_prop_assign_flag(prop, opts);
2772  }
2773  if (pyopts_override) {
2774  bpy_prop_assign_flag_override(prop, opts_override);
2775  }
2779  }
2780  Py_RETURN_NONE;
2781 }
2782 
2783 PyDoc_STRVAR(BPy_IntVectorProperty_doc,
2784  ".. function:: IntVectorProperty(name=\"\", "
2785  "description=\"\", "
2786  "default=(0, 0, 0), min=-2**31, max=2**31-1, "
2787  "soft_min=-2**31, "
2788  "soft_max=2**31-1, "
2789  "step=1, "
2790  "options={'ANIMATABLE'}, "
2791  "override=set(), "
2792  "tags=set(), "
2793  "subtype='NONE', "
2794  "size=3, "
2795  "update=None, "
2796  "get=None, "
2797  "set=None)\n"
2798  "\n"
2799  " Returns a new vector int property definition.\n"
2801  " :arg default: sequence of ints the length of *size*.\n"
2802  " :type default: sequence\n" BPY_PROPDEF_NUM_MIN_DOC
2803  " :type min: int\n" BPY_PROPDEF_NUM_MAX_DOC
2804  " :type max: int\n" BPY_PROPDEF_NUM_SOFTMIN_DOC
2805  " :type soft_min: int\n" BPY_PROPDEF_NUM_SOFTMAX_DOC
2806  " :type soft_max: int\n" BPY_PROPDEF_INT_STEP_DOC BPY_PROPDEF_OPTIONS_DOC
2810 static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
2811 {
2812  StructRNA *srna;
2813 
2814  BPY_PROPDEF_HEAD(IntVectorProperty);
2815 
2816  if (srna) {
2817  const char *id = NULL, *name = NULL, *description = "";
2818  Py_ssize_t id_len;
2819  int min = INT_MIN, max = INT_MAX, soft_min = INT_MIN, soft_max = INT_MAX, step = 1;
2820  int def[PYRNA_STACK_ARRAY] = {0};
2821  int size = 3;
2822  PropertyRNA *prop;
2823  PyObject *pydef = NULL;
2824  PyObject *pyopts = NULL;
2825  int opts = 0;
2826  PyObject *pyopts_override = NULL;
2827  int opts_override = 0;
2828  int prop_tags = 0;
2829  const char *pysubtype = NULL;
2830  int subtype = PROP_NONE;
2831  PyObject *update_fn = NULL;
2832  PyObject *get_fn = NULL;
2833  PyObject *set_fn = NULL;
2834  PyObject *py_tags = NULL;
2835 
2836  static const char *_keywords[] = {
2837  "attr",
2838  "name",
2839  "description",
2840  "default",
2841  "min",
2842  "max",
2843  "soft_min",
2844  "soft_max",
2845  "step",
2846  "options",
2847  "override",
2848  "tags",
2849  "subtype",
2850  "size",
2851  "update",
2852  "get",
2853  "set",
2854  NULL,
2855  };
2856  static _PyArg_Parser _parser = {"s#|ssOiiiiiO!O!O!siOOO:IntVectorProperty", _keywords, 0};
2857  if (!_PyArg_ParseTupleAndKeywordsFast(args,
2858  kw,
2859  &_parser,
2860  &id,
2861  &id_len,
2862  &name,
2863  &description,
2864  &pydef,
2865  &min,
2866  &max,
2867  &soft_min,
2868  &soft_max,
2869  &step,
2870  &PySet_Type,
2871  &pyopts,
2872  &PySet_Type,
2873  &pyopts_override,
2874  &PySet_Type,
2875  &py_tags,
2876  &pysubtype,
2877  &size,
2878  &update_fn,
2879  &get_fn,
2880  &set_fn)) {
2881  return NULL;
2882  }
2883 
2884  BPY_PROPDEF_SUBTYPE_CHECK(IntVectorProperty,
2888 
2889  if (size < 1 || size > PYRNA_STACK_ARRAY) {
2890  PyErr_Format(
2891  PyExc_TypeError,
2892  "IntVectorProperty(size=%d): size must be between 0 and " STRINGIFY(PYRNA_STACK_ARRAY),
2893  size);
2894  return NULL;
2895  }
2896 
2897  if (pydef &&
2898  PyC_AsArray(
2899  def, pydef, size, &PyLong_Type, false, "IntVectorProperty(default=sequence)") == -1) {
2900  return NULL;
2901  }
2902 
2903  if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
2904  return NULL;
2905  }
2906  if (bpy_prop_callback_check(get_fn, "get", 1) == -1) {
2907  return NULL;
2908  }
2909  if (bpy_prop_callback_check(set_fn, "set", 2) == -1) {
2910  return NULL;
2911  }
2912 
2913  prop = RNA_def_property(srna, id, PROP_INT, subtype);
2915  if (pydef) {
2917  }
2918  RNA_def_property_range(prop, min, max);
2919  RNA_def_property_ui_text(prop, name ? name : id, description);
2920  RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, 3);
2921 
2922  if (py_tags) {
2923  RNA_def_property_tags(prop, prop_tags);
2924  }
2925  if (pyopts) {
2926  bpy_prop_assign_flag(prop, opts);
2927  }
2928  if (pyopts_override) {
2929  bpy_prop_assign_flag_override(prop, opts_override);
2930  }
2934  }
2935  Py_RETURN_NONE;
2936 }
2937 
2938 PyDoc_STRVAR(BPy_FloatProperty_doc,
2939  ".. function:: FloatProperty(name=\"\", "
2940  "description=\"\", "
2941  "default=0.0, "
2942  "min=-3.402823e+38, max=3.402823e+38, "
2943  "soft_min=-3.402823e+38, soft_max=3.402823e+38, "
2944  "step=3, "
2945  "precision=2, "
2946  "options={'ANIMATABLE'}, "
2947  "override=set(), "
2948  "tags=set(), "
2949  "subtype='NONE', "
2950  "unit='NONE', "
2951  "update=None, "
2952  "get=None, "
2953  "set=None)\n"
2954  "\n"
2955  " Returns a new float (single precision) property definition.\n"
2957  " :type min: float\n" BPY_PROPDEF_NUM_MAX_DOC
2958  " :type max: float\n" BPY_PROPDEF_NUM_SOFTMIN_DOC
2959  " :type soft_min: float\n" BPY_PROPDEF_NUM_SOFTMAX_DOC
2960  " :type soft_max: float\n" BPY_PROPDEF_FLOAT_STEP_DOC BPY_PROPDEF_FLOAT_PREC_DOC
2964 static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
2965 {
2966  StructRNA *srna;
2967 
2968  BPY_PROPDEF_HEAD(FloatProperty);
2969 
2970  if (srna) {
2971  const char *id = NULL, *name = NULL, *description = "";
2972  Py_ssize_t id_len;
2973  float min = -FLT_MAX, max = FLT_MAX, soft_min = -FLT_MAX, soft_max = FLT_MAX, step = 3,
2974  def = 0.0f;
2975  int precision = 2;
2976  PropertyRNA *prop;
2977  PyObject *pyopts = NULL;
2978  int opts = 0;
2979  PyObject *pyopts_override = NULL;
2980  int opts_override = 0;
2981  int prop_tags = 0;
2982  const char *pysubtype = NULL;
2983  int subtype = PROP_NONE;
2984  const char *pyunit = NULL;
2985  int unit = PROP_UNIT_NONE;
2986  PyObject *update_fn = NULL;
2987  PyObject *get_fn = NULL;
2988  PyObject *set_fn = NULL;
2989  PyObject *py_tags = NULL;
2990 
2991  static const char *_keywords[] = {
2992  "attr", "name", "description", "default", "min", "max", "soft_min",
2993  "soft_max", "step", "precision", "options", "override", "tags", "subtype",
2994  "unit", "update", "get", "set", NULL,
2995  };
2996  static _PyArg_Parser _parser = {"s#|ssffffffiO!O!O!ssOOO:FloatProperty", _keywords, 0};
2997  if (!_PyArg_ParseTupleAndKeywordsFast(args,
2998  kw,
2999  &_parser,
3000  &id,
3001  &id_len,
3002  &name,
3003  &description,
3004  &def,
3005  &min,
3006  &max,
3007  &soft_min,
3008  &soft_max,
3009  &step,
3010  &precision,
3011  &PySet_Type,
3012  &pyopts,
3013  &PySet_Type,
3014  &pyopts_override,
3015  &PySet_Type,
3016  &py_tags,
3017  &pysubtype,
3018  &pyunit,
3019  &update_fn,
3020  &get_fn,
3021  &set_fn)) {
3022  return NULL;
3023  }
3024 
3025  BPY_PROPDEF_SUBTYPE_CHECK(FloatProperty,
3029 
3030  if (pyunit && RNA_enum_value_from_id(rna_enum_property_unit_items, pyunit, &unit) == 0) {
3031  PyErr_Format(PyExc_TypeError, "FloatProperty(unit='%s'): invalid unit", pyunit);
3032  return NULL;
3033  }
3034 
3035  if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
3036  return NULL;
3037  }
3038  if (bpy_prop_callback_check(get_fn, "get", 1) == -1) {
3039  return NULL;
3040  }
3041  if (bpy_prop_callback_check(set_fn, "set", 2) == -1) {
3042  return NULL;
3043  }
3044 
3045  prop = RNA_def_property(srna, id, PROP_FLOAT, subtype | unit);
3046  RNA_def_property_float_default(prop, def);
3047  RNA_def_property_range(prop, min, max);
3048  RNA_def_property_ui_text(prop, name ? name : id, description);
3049  RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, precision);
3050 
3051  if (py_tags) {
3052  RNA_def_property_tags(prop, prop_tags);
3053  }
3054  if (pyopts) {
3055  bpy_prop_assign_flag(prop, opts);
3056  }
3057  if (pyopts_override) {
3058  bpy_prop_assign_flag_override(prop, opts_override);
3059  }
3063  }
3064  Py_RETURN_NONE;
3065 }
3066 
3067 PyDoc_STRVAR(BPy_FloatVectorProperty_doc,
3068  ".. function:: FloatVectorProperty(name=\"\", "
3069  "description=\"\", "
3070  "default=(0.0, 0.0, 0.0), "
3071  "min=sys.float_info.min, max=sys.float_info.max, "
3072  "soft_min=sys.float_info.min, soft_max=sys.float_info.max, "
3073  "step=3, "
3074  "precision=2, "
3075  "options={'ANIMATABLE'}, "
3076  "override=set(), "
3077  "tags=set(), "
3078  "subtype='NONE', "
3079  "unit='NONE', "
3080  "size=3, "
3081  "update=None, "
3082  "get=None, "
3083  "set=None)\n"
3084  "\n"
3085  " Returns a new vector float property definition.\n"
3087  " :arg default: sequence of floats the length of *size*.\n"
3088  " :type default: sequence\n" BPY_PROPDEF_NUM_MIN_DOC
3089  " :type min: float\n" BPY_PROPDEF_NUM_MAX_DOC
3090  " :type max: float\n" BPY_PROPDEF_NUM_SOFTMIN_DOC
3091  " :type soft_min: float\n" BPY_PROPDEF_NUM_SOFTMAX_DOC
3096 static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
3097 {
3098  StructRNA *srna;
3099 
3100  BPY_PROPDEF_HEAD(FloatVectorProperty);
3101 
3102  if (srna) {
3103  const char *id = NULL, *name = NULL, *description = "";
3104  Py_ssize_t id_len;
3105  float min = -FLT_MAX, max = FLT_MAX, soft_min = -FLT_MAX, soft_max = FLT_MAX, step = 3;
3106  float def[PYRNA_STACK_ARRAY] = {0.0f};
3107  int precision = 2, size = 3;
3108  PropertyRNA *prop;
3109  PyObject *pydef = NULL;
3110  PyObject *pyopts = NULL;
3111  int opts = 0;
3112  PyObject *pyopts_override = NULL;
3113  int opts_override = 0;
3114  int prop_tags = 0;
3115  const char *pysubtype = NULL;
3116  int subtype = PROP_NONE;
3117  const char *pyunit = NULL;
3118  int unit = PROP_UNIT_NONE;
3119  PyObject *update_fn = NULL;
3120  PyObject *get_fn = NULL;
3121  PyObject *set_fn = NULL;
3122  PyObject *py_tags = NULL;
3123 
3124  static const char *_keywords[] = {
3125  "attr", "name", "description", "default", "min", "max", "soft_min",
3126  "soft_max", "step", "precision", "options", "override", "tags", "subtype",
3127  "unit", "size", "update", "get", "set", NULL,
3128  };
3129  static _PyArg_Parser _parser = {"s#|ssOfffffiO!O!O!ssiOOO:FloatVectorProperty", _keywords, 0};
3130  if (!_PyArg_ParseTupleAndKeywordsFast(args,
3131  kw,
3132  &_parser,
3133  &id,
3134  &id_len,
3135  &name,
3136  &description,
3137  &pydef,
3138  &min,
3139  &max,
3140  &soft_min,
3141  &soft_max,
3142  &step,
3143  &precision,
3144  &PySet_Type,
3145  &pyopts,
3146  &PySet_Type,
3147  &pyopts_override,
3148  &PySet_Type,
3149  &py_tags,
3150  &pysubtype,
3151  &pyunit,
3152  &size,
3153  &update_fn,
3154  &get_fn,
3155  &set_fn)) {
3156  return NULL;
3157  }
3158 
3159  BPY_PROPDEF_SUBTYPE_CHECK(FloatVectorProperty,
3163 
3164  if (pyunit && RNA_enum_value_from_id(rna_enum_property_unit_items, pyunit, &unit) == 0) {
3165  PyErr_Format(PyExc_TypeError, "FloatVectorProperty(unit='%s'): invalid unit", pyunit);
3166  return NULL;
3167  }
3168 
3169  if (size < 1 || size > PYRNA_STACK_ARRAY) {
3170  PyErr_Format(
3171  PyExc_TypeError,
3172  "FloatVectorProperty(size=%d): size must be between 0 and " STRINGIFY(PYRNA_STACK_ARRAY),
3173  size);
3174  return NULL;
3175  }
3176 
3177  if (pydef &&
3178  PyC_AsArray(
3179  def, pydef, size, &PyFloat_Type, false, "FloatVectorProperty(default=sequence)") ==
3180  -1) {
3181  return NULL;
3182  }
3183 
3184  if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
3185  return NULL;
3186  }
3187  if (bpy_prop_callback_check(get_fn, "get", 1) == -1) {
3188  return NULL;
3189  }
3190  if (bpy_prop_callback_check(set_fn, "set", 2) == -1) {
3191  return NULL;
3192  }
3193 
3194  prop = RNA_def_property(srna, id, PROP_FLOAT, subtype | unit);
3196  if (pydef) {
3198  }
3199  RNA_def_property_range(prop, min, max);
3200  RNA_def_property_ui_text(prop, name ? name : id, description);
3201  RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, precision);
3202 
3203  if (py_tags) {
3204  RNA_def_property_tags(prop, prop_tags);
3205  }
3206  if (pyopts) {
3207  bpy_prop_assign_flag(prop, opts);
3208  }
3209  if (pyopts_override) {
3210  bpy_prop_assign_flag_override(prop, opts_override);
3211  }
3215  }
3216  Py_RETURN_NONE;
3217 }
3218 
3219 PyDoc_STRVAR(BPy_StringProperty_doc,
3220  ".. function:: StringProperty(name=\"\", "
3221  "description=\"\", "
3222  "default=\"\", "
3223  "maxlen=0, "
3224  "options={'ANIMATABLE'}, "
3225  "override=set(), "
3226  "tags=set(), "
3227  "subtype='NONE', "
3228  "update=None, "
3229  "get=None, "
3230  "set=None)\n"
3231  "\n"
3232  " Returns a new string property definition.\n"
3234  " :arg default: initializer string.\n"
3235  " :type default: string\n"
3236  " :arg maxlen: maximum length of the string.\n"
3240 static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw)
3241 {
3242  StructRNA *srna;
3243 
3244  BPY_PROPDEF_HEAD(StringProperty);
3245 
3246  if (srna) {
3247  const char *id = NULL, *name = NULL, *description = "", *def = "";
3248  Py_ssize_t id_len;
3249  int maxlen = 0;
3250  PropertyRNA *prop;
3251  PyObject *pyopts = NULL;
3252  int opts = 0;
3253  PyObject *pyopts_override = NULL;
3254  int opts_override = 0;
3255  int prop_tags = 0;
3256  const char *pysubtype = NULL;
3257  int subtype = PROP_NONE;
3258  PyObject *update_fn = NULL;
3259  PyObject *get_fn = NULL;
3260  PyObject *set_fn = NULL;
3261  PyObject *py_tags = NULL;
3262 
3263  static const char *_keywords[] = {
3264  "attr",
3265  "name",
3266  "description",
3267  "default",
3268  "maxlen",
3269  "options",
3270  "override",
3271  "tags",
3272  "subtype",
3273  "update",
3274  "get",
3275  "set",
3276  NULL,
3277  };
3278  static _PyArg_Parser _parser = {"s#|sssiO!O!O!sOOO:StringProperty", _keywords, 0};
3279  if (!_PyArg_ParseTupleAndKeywordsFast(args,
3280  kw,
3281  &_parser,
3282  &id,
3283  &id_len,
3284  &name,
3285  &description,
3286  &def,
3287  &maxlen,
3288  &PySet_Type,
3289  &pyopts,
3290  &PySet_Type,
3291  &pyopts_override,
3292  &PySet_Type,
3293  &py_tags,
3294  &pysubtype,
3295  &update_fn,
3296  &get_fn,
3297  &set_fn)) {
3298  return NULL;
3299  }
3300 
3301  BPY_PROPDEF_SUBTYPE_CHECK(StringProperty,
3305 
3306  if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
3307  return NULL;
3308  }
3309  if (bpy_prop_callback_check(get_fn, "get", 1) == -1) {
3310  return NULL;
3311  }
3312  if (bpy_prop_callback_check(set_fn, "set", 2) == -1) {
3313  return NULL;
3314  }
3315 
3316  prop = RNA_def_property(srna, id, PROP_STRING, subtype);
3317  if (maxlen != 0) {
3318  /* +1 since it includes null terminator. */
3319  RNA_def_property_string_maxlength(prop, maxlen + 1);
3320  }
3321  if (def && def[0]) {
3323  }
3324  RNA_def_property_ui_text(prop, name ? name : id, description);
3325 
3326  if (py_tags) {
3327  RNA_def_property_tags(prop, prop_tags);
3328  }
3329  if (pyopts) {
3330  bpy_prop_assign_flag(prop, opts);
3331  }
3332  if (pyopts_override) {
3333  bpy_prop_assign_flag_override(prop, opts_override);
3334  }
3338  }
3339  Py_RETURN_NONE;
3340 }
3341 
3343  BPy_EnumProperty_doc,
3344  ".. function:: EnumProperty(items, "
3345  "name=\"\", "
3346  "description=\"\", "
3347  "default=None, "
3348  "options={'ANIMATABLE'}, "
3349  "override=set(), "
3350  "tags=set(), "
3351  "update=None, "
3352  "get=None, "
3353  "set=None)\n"
3354  "\n"
3355  " Returns a new enumerator property definition.\n"
3356  "\n"
3357  " :arg items: sequence of enum items formatted:\n"
3358  " ``[(identifier, name, description, icon, number), ...]``.\n"
3359  "\n"
3360  " The first three elements of the tuples are mandatory.\n"
3361  "\n"
3362  " :identifier: The identifier is used for Python access.\n"
3363  " :name: Name for the interface.\n"
3364  " :description: Used for documentation and tooltips.\n"
3365  " :icon: An icon string identifier or integer icon value\n"
3366  " (e.g. returned by :class:`bpy.types.UILayout.icon`)\n"
3367  " :number: Unique value used as the identifier for this item (stored in file data).\n"
3368  " Use when the identifier may need to change. If the *ENUM_FLAG* option is used,\n"
3369  " the values are bitmasks and should be powers of two.\n"
3370  "\n"
3371  " When an item only contains 4 items they define ``(identifier, name, description, "
3372  "number)``.\n"
3373  "\n"
3374  " Separators may be added using None instead of a tuple."
3375  "\n"
3376  " For dynamic values a callback can be passed which returns a list in\n"
3377  " the same format as the static list.\n"
3378  " This function must take 2 arguments ``(self, context)``, **context may be None**.\n"
3379  "\n"
3380  " .. warning::\n"
3381  "\n"
3382  " There is a known bug with using a callback,\n"
3383  " Python must keep a reference to the strings returned by the callback or Blender\n"
3384  " will misbehave or even crash."
3385  "\n"
3386  " :type items: sequence of string tuples or a function\n" BPY_PROPDEF_NAME_DOC
3388  " :arg default: The default value for this enum, a string from the identifiers used in "
3389  "*items*, or integer matching an item number.\n"
3390  " If the *ENUM_FLAG* option is used this must be a set of such string identifiers "
3391  "instead.\n"
3392  " WARNING: Strings can not be specified for dynamic enums\n"
3393  " (i.e. if a callback function is given as *items* parameter).\n"
3394  " :type default: string, integer or set\n" BPY_PROPDEF_OPTIONS_ENUM_DOC
3397 static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
3398 {
3399  StructRNA *srna;
3400 
3401  BPY_PROPDEF_HEAD(EnumProperty);
3402 
3403  if (srna) {
3404  const char *id = NULL, *name = NULL, *description = "";
3405  PyObject *def = NULL;
3406  Py_ssize_t id_len;
3407  int defvalue = 0;
3408  PyObject *items, *items_fast;
3409  const EnumPropertyItem *eitems;
3410  PropertyRNA *prop;
3411  PyObject *pyopts = NULL;
3412  int opts = 0;
3413  PyObject *pyopts_override = NULL;
3414  int opts_override = 0;
3415  int prop_tags = 0;
3416  bool is_itemf = false;
3417  PyObject *update_fn = NULL;
3418  PyObject *get_fn = NULL;
3419  PyObject *set_fn = NULL;
3420  PyObject *py_tags = NULL;
3421 
3422  static const char *_keywords[] = {
3423  "attr",
3424  "items",
3425  "name",
3426  "description",
3427  "default",
3428  "options",
3429  "override",
3430  "tags",
3431  "update",
3432  "get",
3433  "set",
3434  NULL,
3435  };
3436  static _PyArg_Parser _parser = {"s#O|ssOO!O!O!OOO:EnumProperty", _keywords, 0};
3437  if (!_PyArg_ParseTupleAndKeywordsFast(args,
3438  kw,
3439  &_parser,
3440  &id,
3441  &id_len,
3442  &items,
3443  &name,
3444  &description,
3445  &def,
3446  &PySet_Type,
3447  &pyopts,
3448  &PySet_Type,
3449  &pyopts_override,
3450  &PySet_Type,
3451  &py_tags,
3452  &update_fn,
3453  &get_fn,
3454  &set_fn)) {
3455  return NULL;
3456  }
3457 
3459 
3460  if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
3461  return NULL;
3462  }
3463  if (bpy_prop_callback_check(get_fn, "get", 1) == -1) {
3464  return NULL;
3465  }
3466  if (bpy_prop_callback_check(set_fn, "set", 2) == -1) {
3467  return NULL;
3468  }
3469 
3470  if (def == Py_None) {
3471  /* This allows to get same behavior when explicitly passing None as default value,
3472  * and not defining a default value at all! */
3473  def = NULL;
3474  }
3475 
3476  /* items can be a list or a callable */
3477  if (PyFunction_Check(
3478  items)) { /* don't use PyCallable_Check because we need the function code for errors */
3479  PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(items);
3480  if (f_code->co_argcount != 2) {
3481  PyErr_Format(PyExc_ValueError,
3482  "EnumProperty(...): expected 'items' function to take 2 arguments, not %d",
3483  f_code->co_argcount);
3484  return NULL;
3485  }
3486 
3487  if (def) {
3488  /* Only support getting integer default values here. */
3489  if (!py_long_as_int(def, &defvalue)) {
3490  /* note, using type error here is odd but python does this for invalid arguments */
3491  PyErr_SetString(
3492  PyExc_TypeError,
3493  "EnumProperty(...): 'default' can only be an integer when 'items' is a function");
3494  return NULL;
3495  }
3496  }
3497 
3498  is_itemf = true;
3499  eitems = DummyRNA_NULL_items;
3500  }
3501  else {
3502  if (!(items_fast = PySequence_Fast(
3503  items,
3504  "EnumProperty(...): "
3505  "expected a sequence of tuples for the enum items or a function"))) {
3506  return NULL;
3507  }
3508 
3509  eitems = enum_items_from_py(items_fast, def, &defvalue, (opts & PROP_ENUM_FLAG) != 0);
3510 
3511  if (!eitems) {
3512  Py_DECREF(items_fast);
3513  return NULL;
3514  }
3515  }
3516 
3517  if (opts & PROP_ENUM_FLAG) {
3518  prop = RNA_def_enum_flag(srna, id, eitems, defvalue, name ? name : id, description);
3519  }
3520  else {
3521  prop = RNA_def_enum(srna, id, eitems, defvalue, name ? name : id, description);
3522  }
3523 
3524  if (py_tags) {
3525  RNA_def_property_tags(prop, prop_tags);
3526  }
3527  if (pyopts) {
3528  bpy_prop_assign_flag(prop, opts);
3529  }
3530  if (pyopts_override) {
3531  bpy_prop_assign_flag_override(prop, opts_override);
3532  }
3534  bpy_prop_callback_assign_enum(prop, get_fn, set_fn, (is_itemf ? items : NULL));
3536 
3537  if (is_itemf == false) {
3538  /* note: this must be postponed until after #RNA_def_property_duplicate_pointers
3539  * otherwise if this is a generator it may free the strings before we copy them */
3540  Py_DECREF(items_fast);
3541 
3542  MEM_freeN((void *)eitems);
3543  }
3544  }
3545  Py_RETURN_NONE;
3546 }
3547 
3548 StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix)
3549 {
3550  StructRNA *srna;
3551 
3552  srna = srna_from_self(value, "");
3553  if (!srna) {
3554  if (PyErr_Occurred()) {
3555  PyObject *msg = PyC_ExceptionBuffer();
3556  const char *msg_char = PyUnicode_AsUTF8(msg);
3557  PyErr_Format(
3558  PyExc_TypeError, "%.200s expected an RNA type, failed with: %s", error_prefix, msg_char);
3559  Py_DECREF(msg);
3560  }
3561  else {
3562  PyErr_Format(PyExc_TypeError,
3563  "%.200s expected an RNA type, failed with type '%s'",
3564  error_prefix,
3565  Py_TYPE(value)->tp_name);
3566  }
3567  return NULL;
3568  }
3569 
3570  return srna;
3571 }
3572 
3573 PyDoc_STRVAR(BPy_PointerProperty_doc,
3574  ".. function:: PointerProperty(type=None, "
3575  "name=\"\", "
3576  "description=\"\", "
3577  "options={'ANIMATABLE'}, "
3578  "override=set(), "
3579  "tags=set(), "
3580  "poll=None, "
3581  "update=None)\n"
3582  "\n"
3583  " Returns a new pointer property definition.\n"
3587 PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
3588 {
3589  StructRNA *srna;
3590 
3591  BPY_PROPDEF_HEAD(PointerProperty);
3592 
3593  if (srna) {
3594  const char *id = NULL, *name = NULL, *description = "";
3595  Py_ssize_t id_len;
3596  PropertyRNA *prop;
3597  StructRNA *ptype;
3598  PyObject *type = Py_None;
3599  PyObject *pyopts = NULL;
3600  PyObject *pyopts_override = NULL;
3601  PyObject *py_tags = NULL;
3602  int opts = 0;
3603  int opts_override = 0;
3604  int prop_tags = 0;
3605  PyObject *update_fn = NULL, *poll_fn = NULL;
3606 
3607  static const char *_keywords[] = {
3608  "attr",
3609  "type",
3610  "name",
3611  "description",
3612  "options",
3613  "override",
3614  "tags",
3615  "poll",
3616  "update",
3617  NULL,
3618  };
3619  static _PyArg_Parser _parser = {"s#O|ssO!O!O!OO:PointerProperty", _keywords, 0};
3620  if (!_PyArg_ParseTupleAndKeywordsFast(args,
3621  kw,
3622  &_parser,
3623  &id,
3624  &id_len,
3625  &type,
3626  &name,
3627  &description,
3628  &PySet_Type,
3629  &pyopts,
3630  &PySet_Type,
3631  &pyopts_override,
3632  &PySet_Type,
3633  &py_tags,
3634  &poll_fn,
3635  &update_fn)) {
3636  return NULL;
3637  }
3638 
3640 
3641  ptype = pointer_type_from_py(type, "PointerProperty(...)");
3642  if (!ptype) {
3643  return NULL;
3644  }
3645  if (!RNA_struct_is_a(ptype, &RNA_PropertyGroup) && !RNA_struct_is_ID(ptype)) {
3646  PyErr_Format(PyExc_TypeError,
3647  "PointerProperty(...) expected an RNA type derived from %.200s or %.200s",
3650  return NULL;
3651  }
3652  if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
3653  return NULL;
3654  }
3655  if (bpy_prop_callback_check(poll_fn, "poll", 2) == -1) {
3656  return NULL;
3657  }
3658  prop = RNA_def_pointer_runtime(srna, id, ptype, name ? name : id, description);
3659  if (py_tags) {
3660  RNA_def_property_tags(prop, prop_tags);
3661  }
3662  if (pyopts) {
3663  bpy_prop_assign_flag(prop, opts);
3664  }
3665  if (pyopts_override) {
3666  bpy_prop_assign_flag_override(prop, opts_override);
3667  }
3668 
3670  if (RNA_struct_is_a(srna, &RNA_PropertyGroup)) {
3672  }
3673  }
3677  }
3678  Py_RETURN_NONE;
3679 }
3680 
3681 PyDoc_STRVAR(BPy_CollectionProperty_doc,
3682  ".. function:: CollectionProperty(type=None, "
3683  "name=\"\", "
3684  "description=\"\", "
3685  "options={'ANIMATABLE'}, "
3686  "override=set(), "
3687  "tags=set())\n"
3688  "\n"
3689  " Returns a new collection property definition.\n"
3693 PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
3694 {
3695  StructRNA *srna;
3696 
3697  BPY_PROPDEF_HEAD(CollectionProperty);
3698 
3699  if (srna) {
3700  Py_ssize_t id_len;
3701  const char *id = NULL, *name = NULL, *description = "";
3702  PropertyRNA *prop;
3703  StructRNA *ptype;
3704  PyObject *type = Py_None;
3705  PyObject *pyopts = NULL;
3706  PyObject *pyopts_override = NULL;
3707  PyObject *py_tags = NULL;
3708  int opts = 0;
3709  int opts_override = 0;
3710  int prop_tags = 0;
3711 
3712  static const char *_keywords[] = {
3713  "attr",
3714  "type",
3715  "name",
3716  "description",
3717  "options",
3718  "override",
3719  "tags",
3720  NULL,
3721  };
3722  static _PyArg_Parser _parser = {"s#O|ssO!O!O!:CollectionProperty", _keywords, 0};
3723  if (!_PyArg_ParseTupleAndKeywordsFast(args,
3724  kw,
3725  &_parser,
3726  &id,
3727  &id_len,
3728  &type,
3729  &name,
3730  &description,
3731  &PySet_Type,
3732  &pyopts,
3733  &PySet_Type,
3734  &pyopts_override,
3735  &PySet_Type,
3736  &py_tags)) {
3737  return NULL;
3738  }
3739 
3742 
3743  ptype = pointer_type_from_py(type, "CollectionProperty(...):");
3744  if (!ptype) {
3745  return NULL;
3746  }
3747 
3748  if (!RNA_struct_is_a(ptype, &RNA_PropertyGroup)) {
3749  PyErr_Format(PyExc_TypeError,
3750  "CollectionProperty(...) expected an RNA type derived from %.200s",
3752  return NULL;
3753  }
3754 
3755  prop = RNA_def_collection_runtime(srna, id, ptype, name ? name : id, description);
3756  if (py_tags) {
3757  RNA_def_property_tags(prop, prop_tags);
3758  }
3759  if (pyopts) {
3760  bpy_prop_assign_flag(prop, opts);
3761  }
3762  if (pyopts_override) {
3763  bpy_prop_assign_flag_override(prop, opts_override);
3764  }
3765 
3767  if (RNA_struct_is_a(srna, &RNA_PropertyGroup)) {
3769  }
3770  }
3772  }
3773  Py_RETURN_NONE;
3774 }
3775 
3776 PyDoc_STRVAR(BPy_RemoveProperty_doc,
3777  ".. function:: RemoveProperty(cls, attr)\n"
3778  "\n"
3779  " Removes a dynamically defined property.\n"
3780  "\n"
3781  " :arg cls: The class containing the property (must be a positional argument).\n"
3782  " :type cls: type\n"
3783  " :arg attr: Property name (must be passed as a keyword).\n"
3784  " :type attr: string\n"
3785  "\n"
3786  ".. note:: Typically this function doesn't need to be accessed directly.\n"
3787  " Instead use ``del cls.attr``\n");
3788 static PyObject *BPy_RemoveProperty(PyObject *self, PyObject *args, PyObject *kw)
3789 {
3790  StructRNA *srna;
3791 
3792  if (PyTuple_GET_SIZE(args) == 1) {
3793  PyObject *ret;
3794  self = PyTuple_GET_ITEM(args, 0);
3795  args = PyTuple_New(0);
3796  ret = BPy_RemoveProperty(self, args, kw);
3797  Py_DECREF(args);
3798  return ret;
3799  }
3800  if (PyTuple_GET_SIZE(args) > 1) {
3801  PyErr_SetString(PyExc_ValueError, "expected one positional arg, one keyword arg");
3802  return NULL;
3803  }
3804 
3805  srna = srna_from_self(self, "RemoveProperty(...):");
3806  if (srna == NULL && PyErr_Occurred()) {
3807  return NULL; /* self's type was compatible but error getting the srna */
3808  }
3809  if (srna == NULL) {
3810  PyErr_SetString(PyExc_TypeError, "RemoveProperty(): struct rna not available for this type");
3811  return NULL;
3812  }
3813 
3814  const char *id = NULL;
3815 
3816  static const char *_keywords[] = {
3817  "attr",
3818  NULL,
3819  };
3820  static _PyArg_Parser _parser = {"s:RemoveProperty", _keywords, 0};
3821  if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &id)) {
3822  return NULL;
3823  }
3824 
3825  if (RNA_def_property_free_identifier(srna, id) != 1) {
3826  PyErr_Format(PyExc_TypeError, "RemoveProperty(): '%s' not a defined dynamic property", id);
3827  return NULL;
3828  }
3829 
3830  Py_RETURN_NONE;
3831 }
3832 
3835 /* -------------------------------------------------------------------- */
3839 static struct PyMethodDef props_methods[] = {
3840  {"BoolProperty",
3841  (PyCFunction)BPy_BoolProperty,
3842  METH_VARARGS | METH_KEYWORDS,
3843  BPy_BoolProperty_doc},
3844  {"BoolVectorProperty",
3845  (PyCFunction)BPy_BoolVectorProperty,
3846  METH_VARARGS | METH_KEYWORDS,
3847  BPy_BoolVectorProperty_doc},
3848  {"IntProperty",
3849  (PyCFunction)BPy_IntProperty,
3850  METH_VARARGS | METH_KEYWORDS,
3851  BPy_IntProperty_doc},
3852  {"IntVectorProperty",
3853  (PyCFunction)BPy_IntVectorProperty,
3854  METH_VARARGS | METH_KEYWORDS,
3855  BPy_IntVectorProperty_doc},
3856  {"FloatProperty",
3857  (PyCFunction)BPy_FloatProperty,
3858  METH_VARARGS | METH_KEYWORDS,
3859  BPy_FloatProperty_doc},
3860  {"FloatVectorProperty",
3861  (PyCFunction)BPy_FloatVectorProperty,
3862  METH_VARARGS | METH_KEYWORDS,
3863  BPy_FloatVectorProperty_doc},
3864  {"StringProperty",
3865  (PyCFunction)BPy_StringProperty,
3866  METH_VARARGS | METH_KEYWORDS,
3867  BPy_StringProperty_doc},
3868  {"EnumProperty",
3869  (PyCFunction)BPy_EnumProperty,
3870  METH_VARARGS | METH_KEYWORDS,
3871  BPy_EnumProperty_doc},
3872  {"PointerProperty",
3873  (PyCFunction)BPy_PointerProperty,
3874  METH_VARARGS | METH_KEYWORDS,
3875  BPy_PointerProperty_doc},
3876  {"CollectionProperty",
3877  (PyCFunction)BPy_CollectionProperty,
3878  METH_VARARGS | METH_KEYWORDS,
3879  BPy_CollectionProperty_doc},
3880 
3881  {"RemoveProperty",
3882  (PyCFunction)BPy_RemoveProperty,
3883  METH_VARARGS | METH_KEYWORDS,
3884  BPy_RemoveProperty_doc},
3885  {NULL, NULL, 0, NULL},
3886 };
3887 
3888 static int props_visit(PyObject *UNUSED(self), visitproc visit, void *arg)
3889 {
3890  LISTBASE_FOREACH (struct BPyPropStore *, prop_store, &g_bpy_prop_store_list) {
3891  PyObject **py_data = (PyObject **)&prop_store->py_data;
3892  for (int i = 0; i < BPY_PROP_STORE_PY_DATA_SIZE; i++) {
3893  Py_VISIT(py_data[i]);
3894  }
3895  }
3896  return 0;
3897 }
3898 
3899 static int props_clear(PyObject *UNUSED(self))
3900 {
3901  LISTBASE_FOREACH (struct BPyPropStore *, prop_store, &g_bpy_prop_store_list) {
3902  PyObject **py_data = (PyObject **)&prop_store->py_data;
3903  for (int i = 0; i < BPY_PROP_STORE_PY_DATA_SIZE; i++) {
3904  Py_CLEAR(py_data[i]);
3905  }
3906  }
3907  return 0;
3908 }
3909 
3910 static struct PyModuleDef props_module = {
3911  PyModuleDef_HEAD_INIT,
3912  "bpy.props",
3913  "This module defines properties to extend Blender's internal data. The result of these "
3914  "functions"
3915  " is used to assign properties to classes registered with Blender and can't be used "
3916  "directly.\n"
3917  "\n"
3918  ".. note:: All parameters to these functions must be passed as keywords.\n",
3919  -1, /* multiple "initialization" just copies the module dict. */
3920  props_methods,
3921  NULL,
3922  props_visit,
3923  props_clear,
3924  NULL,
3925 };
3926 
3927 PyObject *BPY_rna_props(void)
3928 {
3929  PyObject *submodule;
3930  PyObject *submodule_dict;
3931 
3932  submodule = PyModule_Create(&props_module);
3933  PyDict_SetItemString(PyImport_GetModuleDict(), props_module.m_name, submodule);
3934 
3935  /* api needs the PyObjects internally */
3936  submodule_dict = PyModule_GetDict(submodule);
3937 
3938 #define ASSIGN_STATIC(_name) pymeth_##_name = PyDict_GetItemString(submodule_dict, #_name)
3939 
3940  ASSIGN_STATIC(BoolProperty);
3941  ASSIGN_STATIC(BoolVectorProperty);
3942  ASSIGN_STATIC(IntProperty);
3943  ASSIGN_STATIC(IntVectorProperty);
3944  ASSIGN_STATIC(FloatProperty);
3945  ASSIGN_STATIC(FloatVectorProperty);
3946  ASSIGN_STATIC(StringProperty);
3947  ASSIGN_STATIC(EnumProperty);
3948  ASSIGN_STATIC(PointerProperty);
3949  ASSIGN_STATIC(CollectionProperty);
3950  ASSIGN_STATIC(RemoveProperty);
3951 
3952  if (PyType_Ready(&bpy_prop_deferred_Type) < 0) {
3953  return NULL;
3954  }
3955  PyModule_AddType(submodule, &bpy_prop_deferred_Type);
3956 
3957  /* Run this when properties are freed. */
3959 
3960  return submodule;
3961 }
3962 
3968 {
3969  /* Remove all user counts, so this isn't considered a leak from Python's perspective. */
3970  props_clear(NULL);
3971 
3972  /* Running is harmless, but redundant. */
3974 
3975  /* Include as it's correct, in practice this should never be used again. */
3977 }
3978 
#define BLI_assert(a)
Definition: BLI_assert.h:58
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
Definition: BLI_listbase.h:128
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:133
#define STRINGIFY(x)
#define UNUSED(x)
#define MAX2(a, b)
#define MIN2(a, b)
#define STREQ(a, b)
ID and Library types, which are fundamental for sdna.
_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.
StructRNA RNA_ID
int RNA_def_property_free_identifier(StructOrFunctionRNA *cont_, const char *identifier)
void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA *prop)
void RNA_def_property_free_pointers_set_py_data_callback(void(*py_data_clear_fn)(PropertyRNA *prop))
int(* EnumPropertyGetFunc)(struct PointerRNA *ptr, struct PropertyRNA *prop)
Definition: RNA_types.h:503
float(* FloatPropertyGetFunc)(struct PointerRNA *ptr, struct PropertyRNA *prop)
Definition: RNA_types.h:480
@ STRUCT_CONTAINS_DATABLOCK_IDPROPERTIES
Definition: RNA_types.h:634
void(* IntPropertySetFunc)(struct PointerRNA *ptr, struct PropertyRNA *prop, int value)
Definition: RNA_types.h:467
void(* EnumPropertySetFunc)(struct PointerRNA *ptr, struct PropertyRNA *prop, int value)
Definition: RNA_types.h:504
#define RNA_ENUM_BITFLAG_SIZE
Definition: RNA_types.h:102
void(* IntArrayPropertyGetFunc)(struct PointerRNA *ptr, struct PropertyRNA *prop, int *values)
Definition: RNA_types.h:468
void(* FloatPropertySetFunc)(struct PointerRNA *ptr, struct PropertyRNA *prop, float value)
Definition: RNA_types.h:481
@ PROP_FLOAT
Definition: RNA_types.h:75
@ PROP_BOOLEAN
Definition: RNA_types.h:73
@ PROP_INT
Definition: RNA_types.h:74
@ PROP_STRING
Definition: RNA_types.h:76
@ PROP_UNIT_NONE
Definition: RNA_types.h:84
struct EnumPropertyItem EnumPropertyItem
void(* BooleanArrayPropertySetFunc)(struct PointerRNA *ptr, struct PropertyRNA *prop, const bool *values)
Definition: RNA_types.h:463
void(* FloatArrayPropertySetFunc)(struct PointerRNA *ptr, struct PropertyRNA *prop, const float *values)
Definition: RNA_types.h:487
bool(* BooleanPropertyGetFunc)(struct PointerRNA *ptr, struct PropertyRNA *prop)
Definition: RNA_types.h:456
void(* BooleanArrayPropertyGetFunc)(struct PointerRNA *ptr, struct PropertyRNA *prop, bool *values)
Definition: RNA_types.h:460
void(* StringPropertyGetFunc)(struct PointerRNA *ptr, struct PropertyRNA *prop, char *value)
Definition: RNA_types.h:496
void(* StringPropertySetFunc)(struct PointerRNA *ptr, struct PropertyRNA *prop, const char *value)
Definition: RNA_types.h:500
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition: RNA_types.h:297
@ PROPOVERRIDE_LIBRARY_INSERTION
Definition: RNA_types.h:322
@ PROPOVERRIDE_NO_PROP_NAME
Definition: RNA_types.h:329
void(* IntArrayPropertySetFunc)(struct PointerRNA *ptr, struct PropertyRNA *prop, const int *values)
Definition: RNA_types.h:471
int(* StringPropertyLengthFunc)(struct PointerRNA *ptr, struct PropertyRNA *prop)
Definition: RNA_types.h:499
int(* IntPropertyGetFunc)(struct PointerRNA *ptr, struct PropertyRNA *prop)
Definition: RNA_types.h:466
const EnumPropertyItem *(* EnumPropertyItemFunc)(struct bContext *C, PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free)
Definition: RNA_types.h:506
@ PROP_ANIMATABLE
Definition: RNA_types.h:188
@ PROP_PROPORTIONAL
Definition: RNA_types.h:209
@ PROP_ENUM_FLAG
Definition: RNA_types.h:251
@ PROP_LIB_EXCEPTION
Definition: RNA_types.h:181
@ PROP_CONTEXT_PROPERTY_UPDATE
Definition: RNA_types.h:255
@ PROP_SKIP_SAVE
Definition: RNA_types.h:204
@ PROP_TEXTEDIT_UPDATE
Definition: RNA_types.h:195
@ PROP_HIDDEN
Definition: RNA_types.h:202
void(* FloatArrayPropertyGetFunc)(struct PointerRNA *ptr, struct PropertyRNA *prop, float *values)
Definition: RNA_types.h:484
void(* BooleanPropertySetFunc)(struct PointerRNA *ptr, struct PropertyRNA *prop, bool value)
Definition: RNA_types.h:457
@ PROP_TIME
Definition: RNA_types.h:133
@ PROP_MATRIX
Definition: RNA_types.h:144
@ PROP_DIRECTION
Definition: RNA_types.h:141
@ PROP_XYZ
Definition: RNA_types.h:148
@ PROP_DISTANCE
Definition: RNA_types.h:135
@ PROP_ACCELERATION
Definition: RNA_types.h:143
@ PROP_TEMPERATURE
Definition: RNA_types.h:163
@ PROP_BYTESTRING
Definition: RNA_types.h:120
@ PROP_POWER
Definition: RNA_types.h:160
@ PROP_LAYER_MEMBER
Definition: RNA_types.h:157
@ PROP_FILENAME
Definition: RNA_types.h:118
@ PROP_PASSWORD
Definition: RNA_types.h:123
@ PROP_COLOR
Definition: RNA_types.h:139
@ PROP_PIXEL
Definition: RNA_types.h:128
@ PROP_ANGLE
Definition: RNA_types.h:132
@ PROP_DISTANCE_CAMERA
Definition: RNA_types.h:136
@ PROP_AXISANGLE
Definition: RNA_types.h:147
@ PROP_EULER
Definition: RNA_types.h:145
@ PROP_COORDS
Definition: RNA_types.h:153
@ PROP_NONE
Definition: RNA_types.h:113
@ PROP_DIRPATH
Definition: RNA_types.h:117
@ PROP_PERCENTAGE
Definition: RNA_types.h:130
@ PROP_FACTOR
Definition: RNA_types.h:131
@ PROP_COLOR_GAMMA
Definition: RNA_types.h:151
@ PROP_TRANSLATION
Definition: RNA_types.h:140
@ PROP_XYZ_LENGTH
Definition: RNA_types.h:149
@ PROP_UNSIGNED
Definition: RNA_types.h:129
@ PROP_LAYER
Definition: RNA_types.h:156
@ PROP_QUATERNION
Definition: RNA_types.h:146
@ PROP_FILEPATH
Definition: RNA_types.h:116
@ PROP_VELOCITY
Definition: RNA_types.h:142
#define C
Definition: RandGen.cpp:39
void bpy_context_clear(struct bContext *C, const PyGILState_STATE *gilstate)
void bpy_context_set(struct bContext *C, PyGILState_STATE *gilstate)
PyObject * self
Definition: bpy_driver.c:185
#define BPY_PROPDEF_SUBTYPE_STRING_DOC
Definition: bpy_props.c:139
void BPY_rna_props_clear_all(void)
Definition: bpy_props.c:3967
static bool bpy_prop_boolean_get_fn(struct PointerRNA *ptr, struct PropertyRNA *prop)
Definition: bpy_props.c:549
static PyObject * pymeth_FloatProperty
Definition: bpy_props.c:432
static const EnumPropertyItem property_subtype_array_items[]
Definition: bpy_props.c:165
#define BPY_PROPDEF_NUM_MIN_DOC
Definition: bpy_props.c:2319
#define ASSIGN_PYOBJECT_INCREF(a, b)
Definition: bpy_props.c:265
static int bpy_prop_enum_get_fn(struct PointerRNA *ptr, struct PropertyRNA *prop)
Definition: bpy_props.c:1540
static void bpy_prop_callback_assign_string(struct PropertyRNA *prop, PyObject *get_fn, PyObject *set_fn)
Definition: bpy_props.c:2157
static const EnumPropertyItem property_flag_override_items[]
Definition: bpy_props.c:89
static PyObject * BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
Definition: bpy_props.c:2964
#define BPY_PROPDEF_OPTIONS_OVERRIDE_COLLECTION_DOC
Definition: bpy_props.c:121
static void bpy_prop_callback_assign_pointer(struct PropertyRNA *prop, PyObject *poll_fn)
Definition: bpy_props.c:2003
static bool py_long_as_int(PyObject *py_long, int *r_int)
Definition: bpy_props.c:1657
static struct PyModuleDef props_module
Definition: bpy_props.c:3910
static const EnumPropertyItem property_flag_enum_items[]
Definition: bpy_props.c:75
static void bpy_prop_float_set_fn(struct PointerRNA *ptr, struct PropertyRNA *prop, float value)
Definition: bpy_props.c:1104
PyObject * BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
Definition: bpy_props.c:3693
static PyObject * BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
Definition: bpy_props.c:2418
#define BPY_PROPDEF_NAME_DOC
Definition: bpy_props.c:2306
#define BPY_PROPDEF_HEAD(_func)
Definition: bpy_props.c:2223
static PyGetSetDef bpy_prop_deferred_getset[]
Definition: bpy_props.c:379
PyObject * BPY_rna_props(void)
Definition: bpy_props.c:3927
static void bpy_prop_int_array_get_fn(struct PointerRNA *ptr, struct PropertyRNA *prop, int *values)
Definition: bpy_props.c:914
static void bpy_prop_string_set_fn(struct PointerRNA *ptr, struct PropertyRNA *prop, const char *value)
Definition: bpy_props.c:1413
#define BPY_PROPDEF_FLOAT_STEP_DOC
Definition: bpy_props.c:2344
static PyObject * pymeth_IntVectorProperty
Definition: bpy_props.c:431
PyDoc_STRVAR(bpy_prop_deferred_doc, "Intermediate storage for properties before registration.\n" "\n" ".. note::\n" "\n" " This is not part of the stable API and may change between releases.")
#define BPY_PROPDEF_UPDATE_DOC
Definition: bpy_props.c:2353
static PyObject * pymeth_EnumProperty
Definition: bpy_props.c:435
#define BPY_PROPDEF_GET_DOC
Definition: bpy_props.c:2365
static struct BPyPropStore * bpy_prop_py_data_ensure(struct PropertyRNA *prop)
Definition: bpy_props.c:279
static void bpy_prop_callback_assign_update(struct PropertyRNA *prop, PyObject *update_fn)
Definition: bpy_props.c:1990
static PyObject * bpy_prop_deferred_function_get(BPy_PropDeferred *self, void *UNUSED(closure))
Definition: bpy_props.c:361
static void bpy_prop_callback_assign_float(struct PropertyRNA *prop, PyObject *get_fn, PyObject *set_fn)
Definition: bpy_props.c:2109
static void bpy_prop_enum_set_fn(struct PointerRNA *ptr, struct PropertyRNA *prop, int value)
Definition: bpy_props.c:1600
static int bpy_prop_deferred_clear(BPy_PropDeferred *self)
Definition: bpy_props.c:330
static const EnumPropertyItem property_flag_items[]
Definition: bpy_props.c:55
static void bpy_prop_py_data_remove(PropertyRNA *prop)
Definition: bpy_props.c:293
static void bpy_prop_boolean_set_fn(struct PointerRNA *ptr, struct PropertyRNA *prop, bool value)
Definition: bpy_props.c:612
#define BPY_PROPDEF_NUM_SOFTMIN_DOC
Definition: bpy_props.c:2327
static void bpy_prop_boolean_array_set_fn(struct PointerRNA *ptr, struct PropertyRNA *prop, const bool *values)
Definition: bpy_props.c:731
static int props_visit(PyObject *UNUSED(self), visitproc visit, void *arg)
Definition: bpy_props.c:3888
#define BPY_PROPDEF_FLOAT_PREC_DOC
Definition: bpy_props.c:2349
#define BPY_PROPDEF_POLL_DOC
Definition: bpy_props.c:2359
static PyObject * pymeth_FloatVectorProperty
Definition: bpy_props.c:433
static bool bpy_prop_pointer_poll_fn(struct PointerRNA *self, PointerRNA candidate, struct PropertyRNA *prop)
Definition: bpy_props.c:1485
static PyObject * pymeth_IntProperty
Definition: bpy_props.c:430
static const EnumPropertyItem property_flag_override_collection_items[]
Definition: bpy_props.c:102
static int props_clear(PyObject *UNUSED(self))
Definition: bpy_props.c:3899
static const EnumPropertyItem * bpy_prop_enum_itemf_fn(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
Definition: bpy_props.c:1874
static PyObject * bpy_prop_deferred_data_CreatePyObject(PyObject *fn, PyObject *kw)
Definition: bpy_props.c:410
static PyObject * BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw)
Definition: bpy_props.c:3240
static const EnumPropertyItem property_subtype_number_items[]
Definition: bpy_props.c:144
StructRNA * pointer_type_from_py(PyObject *value, const char *error_prefix)
Definition: bpy_props.c:3548
static void bpy_prop_callback_assign_boolean(struct PropertyRNA *prop, PyObject *get_fn, PyObject *set_fn)
Definition: bpy_props.c:2013
static PyObject * BPy_RemoveProperty(PyObject *self, PyObject *args, PyObject *kw)
Definition: bpy_props.c:3788
static void bpy_prop_deferred_dealloc(BPy_PropDeferred *self)
Definition: bpy_props.c:317
#define BPY_PROPDEF_CHECK(_func, _property_flag_items, _property_flag_override_items)
Definition: bpy_props.c:2247
static void bpy_prop_update_fn(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop)
Definition: bpy_props.c:491
static PyObject * pymeth_RemoveProperty
Definition: bpy_props.c:438
static PyObject * BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
Definition: bpy_props.c:2534
static int icon_id_from_name(const char *name)
Definition: bpy_props.c:1684
PyObject * BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
Definition: bpy_props.c:3587
static PyObject * pymeth_CollectionProperty
Definition: bpy_props.c:437
static int bpy_prop_int_get_fn(struct PointerRNA *ptr, struct PropertyRNA *prop)
Definition: bpy_props.c:798
static void bpy_prop_assign_flag(PropertyRNA *prop, const int flag)
Definition: bpy_props.c:464
#define BPY_PROPDEF_TAGS_DOC
Definition: bpy_props.c:2379
static void bpy_prop_float_array_get_fn(struct PointerRNA *ptr, struct PropertyRNA *prop, float *values)
Definition: bpy_props.c:1160
static int bpy_prop_deferred_traverse(BPy_PropDeferred *self, visitproc visit, void *arg)
Definition: bpy_props.c:324
#define BPY_PROP_STORE_PY_DATA_SIZE
Definition: bpy_props.c:262
static void bpy_prop_string_get_fn(struct PointerRNA *ptr, struct PropertyRNA *prop, char *value)
Definition: bpy_props.c:1290
static void bpy_prop_int_array_set_fn(struct PointerRNA *ptr, struct PropertyRNA *prop, const int *values)
Definition: bpy_props.c:977
static PyObject * pymeth_PointerProperty
Definition: bpy_props.c:436
static void bpy_prop_callback_assign_int_array(struct PropertyRNA *prop, PyObject *get_fn, PyObject *set_fn)
Definition: bpy_props.c:2085
#define BPY_PROPDEF_OPTIONS_DOC
Definition: bpy_props.c:69
static void bpy_prop_callback_assign_enum(struct PropertyRNA *prop, PyObject *get_fn, PyObject *set_fn, PyObject *itemf_fn)
Definition: bpy_props.c:2183
static PyObject * pyrna_struct_as_instance(PointerRNA *ptr)
Definition: bpy_props.c:440
static void bpy_prop_callback_assign_int(struct PropertyRNA *prop, PyObject *get_fn, PyObject *set_fn)
Definition: bpy_props.c:2061
static const EnumPropertyItem * enum_items_from_py(PyObject *seq_fast, PyObject *def, int *defvalue, const bool is_enum_flag)
Definition: bpy_props.c:1700
#define BPY_PROPDEF_NUM_SOFTMAX_DOC
Definition: bpy_props.c:2331
static void bpy_prop_int_set_fn(struct PointerRNA *ptr, struct PropertyRNA *prop, int value)
Definition: bpy_props.c:858
static void bpy_prop_boolean_array_get_fn(struct PointerRNA *ptr, struct PropertyRNA *prop, bool *values)
Definition: bpy_props.c:668
static struct PyMethodDef props_methods[]
Definition: bpy_props.c:3839
static void bpy_prop_callback_assign_float_array(struct PropertyRNA *prop, PyObject *get_fn, PyObject *set_fn)
Definition: bpy_props.c:2133
static PyObject * BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
Definition: bpy_props.c:3096
static PyObject * pymeth_BoolProperty
Definition: bpy_props.c:428
static const EnumPropertyItem property_subtype_string_items[]
Definition: bpy_props.c:128
#define BPY_PROPDEF_OPTIONS_ENUM_DOC
Definition: bpy_props.c:84
#define BPY_PROPDEF_SUBTYPE_CHECK(_func, _property_flag_items, _property_flag_override_items, _subtype)
Definition: bpy_props.c:2284
#define BPY_PROPDEF_UNIT_DOC
Definition: bpy_props.c:2314
#define BPY_PROPDEF_NUM_MAX_DOC
Definition: bpy_props.c:2323
#define BPY_PROPDEF_SUBTYPE_NUMBER_DOC
Definition: bpy_props.c:160
static PyObject * bpy_prop_deferred_keywords_get(BPy_PropDeferred *self, void *UNUSED(closure))
Definition: bpy_props.c:372
static float bpy_prop_float_get_fn(struct PointerRNA *ptr, struct PropertyRNA *prop)
Definition: bpy_props.c:1044
static int bpy_prop_callback_check(PyObject *py_func, const char *keyword, int argcount)
Definition: bpy_props.c:1959
static void bpy_prop_callback_assign_boolean_array(struct PropertyRNA *prop, PyObject *get_fn, PyObject *set_fn)
Definition: bpy_props.c:2037
#define ASSIGN_STATIC(_name)
static int bpy_prop_string_length_fn(struct PointerRNA *ptr, struct PropertyRNA *prop)
Definition: bpy_props.c:1350
#define BPY_PROPDEF_VECSIZE_DOC
Definition: bpy_props.c:2335
#define BPY_PROPDEF_TYPE_DOC
Definition: bpy_props.c:2375
static void bpy_prop_float_array_set_fn(struct PointerRNA *ptr, struct PropertyRNA *prop, const float *values)
Definition: bpy_props.c:1223
static PyObject * bpy_prop_deferred_call(BPy_PropDeferred *UNUSED(self), PyObject *UNUSED(args), PyObject *UNUSED(kw))
Definition: bpy_props.c:347
#define BPY_PROPDEF_SUBTYPE_ARRAY_DOC
Definition: bpy_props.c:186
#define BPY_PROPDEF_INT_STEP_DOC
Definition: bpy_props.c:2339
#define BPY_PROPDEF_DESC_DOC
Definition: bpy_props.c:2310
PyTypeObject bpy_prop_deferred_Type
Definition: bpy_props.c:392
static PyObject * pymeth_BoolVectorProperty
Definition: bpy_props.c:429
static PyObject * BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
Definition: bpy_props.c:2810
static PyObject * BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
Definition: bpy_props.c:3397
static ListBase g_bpy_prop_store_list
Definition: bpy_props.c:277
static void bpy_prop_assign_flag_override(PropertyRNA *prop, const int flag_override)
Definition: bpy_props.c:477
#define BPY_PROPDEF_OPTIONS_OVERRIDE_DOC
Definition: bpy_props.c:98
static PyObject * pymeth_StringProperty
Definition: bpy_props.c:434
static PyObject * bpy_prop_deferred_repr(BPy_PropDeferred *self)
Definition: bpy_props.c:336
static PyObject * BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
Definition: bpy_props.c:2677
#define BPY_PROPDEF_SET_DOC
Definition: bpy_props.c:2370
#define PYRNA_STACK_ARRAY
Definition: bpy_props.h:44
bool pyrna_write_check(void)
Definition: bpy_rna.c:362
PyObject * pyrna_struct_CreatePyObject(PointerRNA *ptr)
Definition: bpy_rna.c:7469
StructRNA * srna_from_self(PyObject *self, const char *error_prefix)
Definition: bpy_rna.c:7906
void pyrna_write_set(bool val)
Definition: bpy_rna.c:367
BPy_StructRNA * bpy_context_module
Definition: bpy_rna.c:97
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
SIMD_FORCE_INLINE btScalar length(const btQuaternion &q)
Return the length of a quaternion.
Definition: btQuaternion.h:895
static FT_Error err
Definition: freetypefont.c:52
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
PyObject * PyC_Tuple_PackArray_Bool(const bool *array, uint len)
PyObject * PyC_ExceptionBuffer(void)
int PyC_Long_AsBool(PyObject *value)
PyObject * PyC_Tuple_PackArray_F32(const float *array, uint len)
PyObject * PyC_Tuple_PackArray_I32(const int *array, uint len)
void PyC_Err_PrintWithFunc(PyObject *py_func)
int PyC_ParseBool(PyObject *o, void *p)
int PyC_AsArray(void *array, PyObject *value, const Py_ssize_t length, const PyTypeObject *type, const bool is_double, const char *error_prefix)
return ret
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
Definition: rna_access.c:844
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:146
void ** RNA_struct_instance(PointerRNA *ptr)
Definition: rna_access.c:1016
bool RNA_struct_is_ID(const StructRNA *type)
Definition: rna_access.c:797
bool RNA_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value)
Definition: rna_access.c:6474
const char * RNA_struct_ui_name(const StructRNA *type)
Definition: rna_access.c:728
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:866
bool RNA_struct_idprops_contains_datablock(const StructRNA *type)
Definition: rna_access.c:823
int RNA_property_enum_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
Definition: rna_access.c:3592
int RNA_property_flag(PropertyRNA *prop)
Definition: rna_access.c:1192
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:1218
void * RNA_property_py_data_get(PropertyRNA *prop)
Definition: rna_access.c:1213
PropertyRNA * RNA_def_enum_flag(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3795
void RNA_def_struct_flag(StructRNA *srna, int flag)
Definition: rna_define.c:1152
void RNA_def_property_float_default(PropertyRNA *prop, float value)
Definition: rna_define.c:2042
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1676
void RNA_def_property_int_funcs_runtime(PropertyRNA *prop, IntPropertyGetFunc getfunc, IntPropertySetFunc setfunc, IntPropertyRangeFunc rangefunc)
Definition: rna_define.c:3099
void RNA_def_property_boolean_default(PropertyRNA *prop, bool value)
Definition: rna_define.c:1957
PropertyRNA * RNA_def_collection_runtime(StructOrFunctionRNA *cont_, const char *identifier, StructRNA *type, const char *ui_name, const char *ui_description)
Definition: rna_define.c:4210
void RNA_def_property_enum_funcs_runtime(PropertyRNA *prop, EnumPropertyGetFunc getfunc, EnumPropertySetFunc setfunc, EnumPropertyItemFunc itemfunc)
Definition: rna_define.c:3285
void RNA_def_property_boolean_array_funcs_runtime(PropertyRNA *prop, BooleanArrayPropertyGetFunc getfunc, BooleanArrayPropertySetFunc setfunc)
Definition: rna_define.c:3032
void RNA_def_property_int_default(PropertyRNA *prop, int value)
Definition: rna_define.c:1998
void RNA_def_py_data(PropertyRNA *prop, void *py_data)
Definition: rna_define.c:3474
void RNA_def_property_array(PropertyRNA *prop, int length)
Definition: rna_define.c:1568
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
Definition: rna_define.c:1757
void RNA_def_property_poll_runtime(PropertyRNA *prop, const void *func)
Definition: rna_define.c:2943
void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
Definition: rna_define.c:1940
void RNA_def_property_float_funcs_runtime(PropertyRNA *prop, FloatPropertyGetFunc getfunc, FloatPropertySetFunc setfunc, FloatPropertyRangeFunc rangefunc)
Definition: rna_define.c:3197
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1279
void RNA_def_property_int_array_default(PropertyRNA *prop, const int *array)
Definition: rna_define.c:2020
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1517
PropertyRNA * RNA_def_pointer_runtime(StructOrFunctionRNA *cont_, const char *identifier, StructRNA *type, const char *ui_name, const char *ui_description)
Definition: rna_define.c:4175
void RNA_def_property_string_default(PropertyRNA *prop, const char *value)
Definition: rna_define.c:2086
void RNA_def_property_int_array_funcs_runtime(PropertyRNA *prop, IntArrayPropertyGetFunc getfunc, IntArrayPropertySetFunc setfunc, IntPropertyRangeFunc rangefunc)
Definition: rna_define.c:3126
void RNA_def_property_float_array_funcs_runtime(PropertyRNA *prop, FloatArrayPropertyGetFunc getfunc, FloatArrayPropertySetFunc setfunc, FloatPropertyRangeFunc rangefunc)
Definition: rna_define.c:3224
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
void RNA_def_property_update_runtime(PropertyRNA *prop, const void *func)
Definition: rna_define.c:2938
void RNA_def_property_boolean_array_default(PropertyRNA *prop, const bool *array)
Definition: rna_define.c:1981
void RNA_def_property_boolean_funcs_runtime(PropertyRNA *prop, BooleanPropertyGetFunc getfunc, BooleanPropertySetFunc setfunc)
Definition: rna_define.c:3009
PropertyRNA * RNA_def_boolean_array(StructOrFunctionRNA *cont_, const char *identifier, int len, bool *default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3497
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
Definition: rna_define.c:1706
void RNA_def_property_tags(PropertyRNA *prop, int tags)
Definition: rna_define.c:1542
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3771
void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array)
Definition: rna_define.c:2064
void RNA_def_property_string_funcs_runtime(PropertyRNA *prop, StringPropertyGetFunc getfunc, StringPropertyLengthFunc lengthfunc, StringPropertySetFunc setfunc)
Definition: rna_define.c:3346
void RNA_def_property_override_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
Definition: rna_define.c:1525
StructRNA RNA_PropertyGroup
const EnumPropertyItem rna_enum_property_unit_items[]
Definition: rna_rna.c:111
const EnumPropertyItem DummyRNA_NULL_items[]
Definition: rna_rna.c:40
const EnumPropertyItem rna_enum_icon_items[]
Definition: rna_ui_api.c:46
#define min(a, b)
Definition: sort.c:51
PyObject * get_fn
Definition: bpy_props.c:241
PyObject * update_fn
Definition: bpy_props.c:244
struct BPyPropStore::@1122::@1123::@1126 pointer_data
struct BPyPropStore::@1122 py_data
PyObject * itemf_fn
Definition: bpy_props.c:251
PyObject * poll_fn
Definition: bpy_props.c:256
struct BPyPropStore * prev
Definition: bpy_props.c:233
struct BPyPropStore::@1122::@1123::@1125 enum_data
PyObject * set_fn
Definition: bpy_props.c:242
struct BPyPropStore * next
Definition: bpy_props.c:233
const char * identifier
Definition: RNA_types.h:446
const char * name
Definition: RNA_types.h:450
const char * description
Definition: RNA_types.h:452
void * data
Definition: RNA_types.h:52
float max
uint len
PointerRNA * ptr
Definition: wm_files.c:3157