Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitchell Stokes <mogurijin@gmail.com>2011-07-29 10:32:30 +0400
committerMitchell Stokes <mogurijin@gmail.com>2011-07-29 10:32:30 +0400
commitb46d8955509e805f06b76a6fd800ecb4edee113b (patch)
tree7ed0b1a3b5d04ab48d3e9062ff02ce54961ecb06 /source/blender/python/intern/bpy_rna.c
parent6960127d2609620d52620539388ada5cb466bab2 (diff)
parent26589497529ca3c8da85391d4976d286a371e258 (diff)
Merging r36529-38806bge_components
Diffstat (limited to 'source/blender/python/intern/bpy_rna.c')
-rw-r--r--source/blender/python/intern/bpy_rna.c250
1 files changed, 147 insertions, 103 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 8af0db6ee13..6e1b9c807f3 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -39,6 +39,7 @@
#include "bpy_props.h"
#include "bpy_util.h"
#include "bpy_rna_callback.h"
+#include "bpy_intern_string.h"
#ifdef USE_PYRNA_INVALIDATE_WEAKREF
#include "MEM_guardedalloc.h"
@@ -323,11 +324,20 @@ int pyrna_write_check(void)
{
return !rna_disallow_writes;
}
+
+void pyrna_write_set(int val)
+{
+ rna_disallow_writes= !val;
+}
#else // USE_PEDANTIC_WRITE
int pyrna_write_check(void)
{
return TRUE;
}
+void pyrna_write_set(int UNUSED(val))
+{
+ /* nothing */
+}
#endif // USE_PEDANTIC_WRITE
static Py_ssize_t pyrna_prop_collection_length(BPy_PropertyRNA *self);
@@ -336,7 +346,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
static int deferred_register_prop(StructRNA *srna, PyObject *key, PyObject *item);
#ifdef USE_MATHUTILS
-#include "../generic/mathutils.h" /* so we can have mathutils callbacks */
+#include "../mathutils/mathutils.h" /* so we can have mathutils callbacks */
static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyArrayRNA *self, PointerRNA *ptr, PropertyRNA *prop, Py_ssize_t start, Py_ssize_t stop, Py_ssize_t length);
static short pyrna_rotation_euler_order_get(PointerRNA *ptr, PropertyRNA **prop_eul_order, short order_fallback);
@@ -1200,7 +1210,7 @@ static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val)
return ret;
}
-PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
+PyObject *pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
{
PyObject *ret;
int type= RNA_property_type(prop);
@@ -1334,7 +1344,7 @@ int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const cha
return error_val;
}
-static PyObject * pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw);
+static PyObject *pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw);
static PyObject *pyrna_func_to_py(BPy_DummyPointerRNA *pyrna, FunctionRNA *func)
{
@@ -1371,12 +1381,8 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
if (RNA_property_array_check(ptr, prop)) {
- int ok= 1;
-
/* done getting the length */
- ok= pyrna_py_to_array(ptr, prop, data, value, error_prefix);
-
- if (!ok) {
+ if(pyrna_py_to_array(ptr, prop, data, value, error_prefix) == -1) {
return -1;
}
}
@@ -1467,7 +1473,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
param= _PyUnicode_AsString(value);
}
#else // USE_STRING_COERCE
- param= _PyUnicode_AsStringSize(value);
+ param= _PyUnicode_AsString(value);
#endif // USE_STRING_COERCE
if (param==NULL) {
@@ -1758,8 +1764,8 @@ static int pyrna_py_to_prop_array_index(BPy_PropertyArrayRNA *self, int index, P
if (totdim > 1) {
/* char error_str[512]; */
- if (!pyrna_py_to_array_index(&self->ptr, self->prop, self->arraydim, self->arrayoffset, index, value, "")) {
- /* PyErr_SetString(PyExc_AttributeError, error_str); */
+ if (pyrna_py_to_array_index(&self->ptr, self->prop, self->arraydim, self->arrayoffset, index, value, "") == -1) {
+ /* error is set */
ret= -1;
}
}
@@ -2527,16 +2533,18 @@ static PyMappingMethods pyrna_struct_as_mapping= {
(objobjargproc) pyrna_struct_ass_subscript, /* mp_ass_subscript */
};
-static char pyrna_struct_keys_doc[] =
+PyDoc_STRVAR(pyrna_struct_keys_doc,
".. method:: keys()\n"
"\n"
-" Returns the keys of this objects custom properties (matches pythons dictionary function of the same name).\n"
+" Returns the keys of this objects custom properties (matches pythons\n"
+" dictionary function of the same name).\n"
"\n"
" :return: custom property keys.\n"
" :rtype: list of strings\n"
"\n"
-" .. note:: Only :class:`ID`, :class:`Bone` and :class:`PoseBone` classes support custom properties.\n";
-
+" .. note:: Only :class:`ID`, :class:`Bone` and :class:`PoseBone` classes\n"
+" support custom properties.\n"
+);
static PyObject *pyrna_struct_keys(BPy_PropertyRNA *self)
{
IDProperty *group;
@@ -2554,16 +2562,18 @@ static PyObject *pyrna_struct_keys(BPy_PropertyRNA *self)
return BPy_Wrap_GetKeys(group);
}
-static char pyrna_struct_items_doc[] =
+PyDoc_STRVAR(pyrna_struct_items_doc,
".. method:: items()\n"
"\n"
-" Returns the items of this objects custom properties (matches pythons dictionary function of the same name).\n"
+" Returns the items of this objects custom properties (matches pythons\n"
+" dictionary function of the same name).\n"
"\n"
" :return: custom property key, value pairs.\n"
" :rtype: list of key, value tuples\n"
"\n"
-" .. note:: Only :class:`ID`, :class:`Bone` and :class:`PoseBone` classes support custom properties.\n";
-
+" .. note:: Only :class:`ID`, :class:`Bone` and :class:`PoseBone`\n"
+" classes support custom properties.\n"
+);
static PyObject *pyrna_struct_items(BPy_PropertyRNA *self)
{
IDProperty *group;
@@ -2581,16 +2591,18 @@ static PyObject *pyrna_struct_items(BPy_PropertyRNA *self)
return BPy_Wrap_GetItems(self->ptr.id.data, group);
}
-static char pyrna_struct_values_doc[] =
+PyDoc_STRVAR(pyrna_struct_values_doc,
".. method:: values()\n"
"\n"
-" Returns the values of this objects custom properties (matches pythons dictionary function of the same name).\n"
+" Returns the values of this objects custom properties (matches pythons\n"
+" dictionary function of the same name).\n"
"\n"
" :return: custom property values.\n"
" :rtype: list\n"
"\n"
-" .. note:: Only :class:`ID`, :class:`Bone` and :class:`PoseBone` classes support custom properties.\n";
-
+" .. note:: Only :class:`ID`, :class:`Bone` and :class:`PoseBone`\n"
+" classes support custom properties.\n"
+);
static PyObject *pyrna_struct_values(BPy_PropertyRNA *self)
{
IDProperty *group;
@@ -2609,14 +2621,14 @@ static PyObject *pyrna_struct_values(BPy_PropertyRNA *self)
}
-static char pyrna_struct_is_property_set_doc[] =
+PyDoc_STRVAR(pyrna_struct_is_property_set_doc,
".. method:: is_property_set(property)\n"
"\n"
" Check if a property is set, use for testing operator properties.\n"
"\n"
" :return: True when the property has been set.\n"
" :rtype: boolean\n"
-;
+);
static PyObject *pyrna_struct_is_property_set(BPy_StructRNA *self, PyObject *args)
{
PropertyRNA *prop;
@@ -2653,14 +2665,14 @@ static PyObject *pyrna_struct_is_property_set(BPy_StructRNA *self, PyObject *arg
return PyBool_FromLong(ret);
}
-static char pyrna_struct_is_property_hidden_doc[] =
+PyDoc_STRVAR(pyrna_struct_is_property_hidden_doc,
".. method:: is_property_hidden(property)\n"
"\n"
" Check if a property is hidden.\n"
"\n"
" :return: True when the property is hidden.\n"
" :rtype: boolean\n"
-;
+);
static PyObject *pyrna_struct_is_property_hidden(BPy_StructRNA *self, PyObject *args)
{
PropertyRNA *prop;
@@ -2681,16 +2693,17 @@ static PyObject *pyrna_struct_is_property_hidden(BPy_StructRNA *self, PyObject *
return PyBool_FromLong(RNA_property_flag(prop) & PROP_HIDDEN);
}
-static char pyrna_struct_path_resolve_doc[] =
+PyDoc_STRVAR(pyrna_struct_path_resolve_doc,
".. method:: path_resolve(path, coerce=True)\n"
"\n"
" Returns the property from the path, raise an exception when not found.\n"
"\n"
" :arg path: path which this property resolves.\n"
" :type path: string\n"
-" :arg coerce: optional argument, when True, the property will be converted into its python representation.\n"
+" :arg coerce: optional argument, when True, the property will be converted\n"
+" into its python representation.\n"
" :type coerce: boolean\n"
-;
+);
static PyObject *pyrna_struct_path_resolve(BPy_StructRNA *self, PyObject *args)
{
const char *path;
@@ -2738,16 +2751,18 @@ static PyObject *pyrna_struct_path_resolve(BPy_StructRNA *self, PyObject *args)
}
}
-static char pyrna_struct_path_from_id_doc[] =
+PyDoc_STRVAR(pyrna_struct_path_from_id_doc,
".. method:: path_from_id(property=\"\")\n"
"\n"
" Returns the data path from the ID to this object (string).\n"
"\n"
-" :arg property: Optional property name which can be used if the path is to a property of this object.\n"
+" :arg property: Optional property name which can be used if the path is\n"
+" to a property of this object.\n"
" :type property: string\n"
-" :return: The path from :class:`bpy_struct.id_data` to this struct and property (when given).\n"
+" :return: The path from :class:`bpy_struct.id_data`\n"
+" to this struct and property (when given).\n"
" :rtype: str\n"
-;
+);
static PyObject *pyrna_struct_path_from_id(BPy_StructRNA *self, PyObject *args)
{
const char *name= NULL;
@@ -2795,14 +2810,14 @@ static PyObject *pyrna_struct_path_from_id(BPy_StructRNA *self, PyObject *args)
return ret;
}
-static char pyrna_prop_path_from_id_doc[] =
+PyDoc_STRVAR(pyrna_prop_path_from_id_doc,
".. method:: path_from_id()\n"
"\n"
" Returns the data path from the ID to this property (string).\n"
"\n"
" :return: The path from :class:`bpy_struct.id_data` to this property.\n"
" :rtype: str\n"
-;
+);
static PyObject *pyrna_prop_path_from_id(BPy_PropertyRNA *self)
{
const char *path;
@@ -2824,14 +2839,15 @@ static PyObject *pyrna_prop_path_from_id(BPy_PropertyRNA *self)
return ret;
}
-static char pyrna_struct_type_recast_doc[] =
+PyDoc_STRVAR(pyrna_struct_type_recast_doc,
".. method:: type_recast()\n"
"\n"
-" Return a new instance, this is needed because types such as textures can be changed at runtime.\n"
+" Return a new instance, this is needed because types\n"
+" such as textures can be changed at runtime.\n"
"\n"
" :return: a new instance of this object with the type initialized again.\n"
" :rtype: subclass of :class:`bpy_struct`\n"
-;
+);
static PyObject *pyrna_struct_type_recast(BPy_StructRNA *self)
{
PointerRNA r_ptr;
@@ -3091,7 +3107,7 @@ static PyObject *pyrna_struct_meta_idprop_getattro(PyObject *cls, PyObject *attr
* >>> bpy.types.Scene.foo= BoolProperty()
* >>> bpy.types.Scene.foo
* <bpy_struct, BooleanProperty("foo")>
- * ...rather then returning the deferred class register tuple as checked by pyrna_is_deferred_prop()
+ * ...rather than returning the deferred class register tuple as checked by pyrna_is_deferred_prop()
*
* Disable for now, this is faking internal behavior in a way thats too tricky to maintain well. */
#if 0
@@ -3434,14 +3450,15 @@ static PyGetSetDef pyrna_struct_getseters[]= {
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
-static char pyrna_prop_collection_keys_doc[] =
+PyDoc_STRVAR(pyrna_prop_collection_keys_doc,
".. method:: keys()\n"
"\n"
-" Return the identifiers of collection members (matching pythons dict.keys() functionality).\n"
+" Return the identifiers of collection members\n"
+" (matching pythons dict.keys() functionality).\n"
"\n"
" :return: the identifiers for each member of this collection.\n"
" :rtype: list of stings\n"
-;
+);
static PyObject *pyrna_prop_collection_keys(BPy_PropertyRNA *self)
{
PyObject *ret= PyList_New(0);
@@ -3467,14 +3484,15 @@ static PyObject *pyrna_prop_collection_keys(BPy_PropertyRNA *self)
return ret;
}
-static char pyrna_prop_collection_items_doc[] =
+PyDoc_STRVAR(pyrna_prop_collection_items_doc,
".. method:: items()\n"
"\n"
-" Return the identifiers of collection members (matching pythons dict.items() functionality).\n"
+" Return the identifiers of collection members\n"
+" (matching pythons dict.items() functionality).\n"
"\n"
" :return: (key, value) pairs for each member of this collection.\n"
" :rtype: list of tuples\n"
-;
+);
static PyObject *pyrna_prop_collection_items(BPy_PropertyRNA *self)
{
PyObject *ret= PyList_New(0);
@@ -3508,32 +3526,36 @@ static PyObject *pyrna_prop_collection_items(BPy_PropertyRNA *self)
return ret;
}
-static char pyrna_prop_collection_values_doc[] =
+PyDoc_STRVAR(pyrna_prop_collection_values_doc,
".. method:: values()\n"
"\n"
-" Return the values of collection (matching pythons dict.values() functionality).\n"
+" Return the values of collection\n"
+" (matching pythons dict.values() functionality).\n"
"\n"
" :return: the members of this collection.\n"
" :rtype: list\n"
-;
+);
static PyObject *pyrna_prop_collection_values(BPy_PropertyRNA *self)
{
/* re-use slice*/
return pyrna_prop_collection_subscript_slice(self, 0, PY_SSIZE_T_MAX);
}
-static char pyrna_struct_get_doc[] =
+PyDoc_STRVAR(pyrna_struct_get_doc,
".. method:: get(key, default=None)\n"
"\n"
-" Returns the value of the custom property assigned to key or default when not found (matches pythons dictionary function of the same name).\n"
+" Returns the value of the custom property assigned to key or default\n"
+" when not found (matches pythons dictionary function of the same name).\n"
"\n"
" :arg key: The key assosiated with the custom property.\n"
" :type key: string\n"
-" :arg default: Optional argument for the value to return if *key* is not found.\n"
+" :arg default: Optional argument for the value to return if\n"
+" *key* is not found.\n"
" :type default: Undefined\n"
"\n"
-" .. note:: Only :class:`ID`, :class:`Bone` and :class:`PoseBone` classes support custom properties.\n"
-;
+" .. note:: Only :class:`ID`, :class:`Bone` and :class:`PoseBone`\n"
+" classes support custom properties.\n"
+);
static PyObject *pyrna_struct_get(BPy_StructRNA *self, PyObject *args)
{
IDProperty *group, *idprop;
@@ -3563,7 +3585,7 @@ static PyObject *pyrna_struct_get(BPy_StructRNA *self, PyObject *args)
return Py_INCREF(def), def;
}
-static char pyrna_struct_as_pointer_doc[] =
+PyDoc_STRVAR(pyrna_struct_as_pointer_doc,
".. method:: as_pointer()\n"
"\n"
" Returns the memory address which holds a pointer to blenders internal data\n"
@@ -3571,23 +3593,26 @@ static char pyrna_struct_as_pointer_doc[] =
" :return: int (memory address).\n"
" :rtype: int\n"
"\n"
-" .. note:: This is intended only for advanced script writers who need to pass blender data to their own C/Python modules.\n"
-;
+" .. note:: This is intended only for advanced script writers who need to\n"
+" pass blender data to their own C/Python modules.\n"
+);
static PyObject *pyrna_struct_as_pointer(BPy_StructRNA *self)
{
return PyLong_FromVoidPtr(self->ptr.data);
}
-static char pyrna_prop_collection_get_doc[] =
+PyDoc_STRVAR(pyrna_prop_collection_get_doc,
".. method:: get(key, default=None)\n"
"\n"
-" Returns the value of the item assigned to key or default when not found (matches pythons dictionary function of the same name).\n"
+" Returns the value of the item assigned to key or default when not found\n"
+" (matches pythons dictionary function of the same name).\n"
"\n"
" :arg key: The identifier for the collection member.\n"
" :type key: string\n"
-" :arg default: Optional argument for the value to return if *key* is not found.\n"
+" :arg default: Optional argument for the value to return if\n"
+" *key* is not found.\n"
" :type default: Undefined\n"
-;
+);
static PyObject *pyrna_prop_collection_get(BPy_PropertyRNA *self, PyObject *args)
{
PointerRNA newptr;
@@ -3822,9 +3847,11 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set)
case PROP_RAW_DOUBLE:
item= PyFloat_FromDouble((double) ((double *)array)[i]);
break;
- case PROP_RAW_UNSET:
+ default: /* PROP_RAW_UNSET */
/* should never happen */
BLI_assert(!"Invalid array type - get");
+ item= Py_None;
+ Py_INCREF(item);
break;
}
@@ -3851,7 +3878,7 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set)
Py_RETURN_NONE;
}
-static char pyrna_prop_collection_foreach_get_doc[] =
+PyDoc_STRVAR(pyrna_prop_collection_foreach_get_doc,
".. method:: foreach_get(attr, seq)\n"
"\n"
" This is a function to give fast access to attributes within a collection.\n"
@@ -3863,7 +3890,7 @@ static char pyrna_prop_collection_foreach_get_doc[] =
" # Python equivalent\n"
" for i in range(len(seq)): someseq[i]= getattr(collection, attr)\n"
"\n"
-;
+);
static PyObject *pyrna_prop_collection_foreach_get(BPy_PropertyRNA *self, PyObject *args)
{
PYRNA_PROP_CHECK_OBJ(self)
@@ -3871,7 +3898,7 @@ static PyObject *pyrna_prop_collection_foreach_get(BPy_PropertyRNA *self, PyObje
return foreach_getset(self, args, 0);
}
-static char pyrna_prop_collection_foreach_set_doc[] =
+PyDoc_STRVAR(pyrna_prop_collection_foreach_set_doc,
".. method:: foreach_set(attr, seq)\n"
"\n"
" This is a function to give fast access to attributes within a collection.\n"
@@ -3883,7 +3910,7 @@ static char pyrna_prop_collection_foreach_set_doc[] =
" # Python equivalent\n"
" for i in range(len(seq)): setattr(collection[i], attr, seq[i])\n"
"\n"
-;
+);
static PyObject *pyrna_prop_collection_foreach_set(BPy_PropertyRNA *self, PyObject *args)
{
PYRNA_PROP_CHECK_OBJ(self)
@@ -4521,7 +4548,7 @@ PyTypeObject pyrna_struct_meta_idprop_Type= {
NULL, /* printfunc tp_print; */
NULL, /* getattrfunc tp_getattr; */
NULL, /* setattrfunc tp_setattr; */
- NULL, /* tp_compare */ /* DEPRECATED in python 3.0! */
+ NULL, /* tp_compare */ /* deprecated in python 3.0! */
NULL, /* tp_repr */
/* Method suites for standard classes */
@@ -5193,7 +5220,7 @@ static void pyrna_subtype_set_rna(PyObject *newclass, StructRNA *srna)
item= pyrna_struct_CreatePyObject(&ptr);
/* note, must set the class not the __dict__ else the internal slots are not updated correctly */
- PyObject_SetAttrString(newclass, "bl_rna", item);
+ PyObject_SetAttr(newclass, bpy_intern_str_bl_rna, item);
Py_DECREF(item);
/* done with rna instance */
@@ -5255,7 +5282,7 @@ static PyObject* pyrna_srna_ExternalType(StructRNA *srna)
//PyObject *slots= PyObject_GetAttrString(newclass, "__slots__"); // cant do this because it gets superclasses values!
//PyObject *bases= PyObject_GetAttrString(newclass, "__bases__"); // can do this but faster not to.
PyObject *bases= ((PyTypeObject *)newclass)->tp_bases;
- PyObject *slots= PyDict_GetItemString(((PyTypeObject *)newclass)->tp_dict, "__slots__");
+ PyObject *slots= PyDict_GetItem(((PyTypeObject *)newclass)->tp_dict, bpy_intern_str___slots__);
if(slots==NULL) {
fprintf(stderr, "pyrna_srna_ExternalType: expected class '%s' to have __slots__ defined\n\nSee bpy_types.py\n", idname);
@@ -5498,7 +5525,7 @@ PyObject *BPY_rna_module(void)
BPy_StructRNA *pyrna;
PointerRNA ptr;
- /* for now, return the base RNA type rather then a real module */
+ /* for now, return the base RNA type rather than a real module */
RNA_main_pointer_create(G.main, &ptr);
pyrna= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr);
@@ -5518,7 +5545,7 @@ PyObject *BPY_rna_doc(void)
{
PointerRNA ptr;
- /* for now, return the base RNA type rather then a real module */
+ /* for now, return the base RNA type rather than a real module */
RNA_blender_rna_pointer_create(&ptr);
return pyrna_struct_CreatePyObject(&ptr);
@@ -5625,7 +5652,7 @@ StructRNA *pyrna_struct_as_srna(PyObject *self, int parent, const char *error_pr
/* ack, PyObject_GetAttrString wont look up this types tp_dict first :/ */
if(PyType_Check(self)) {
- py_srna= (BPy_StructRNA *)PyDict_GetItemString(((PyTypeObject *)self)->tp_dict, "bl_rna");
+ py_srna= (BPy_StructRNA *)PyDict_GetItem(((PyTypeObject *)self)->tp_dict, bpy_intern_str_bl_rna);
Py_XINCREF(py_srna);
}
@@ -5633,7 +5660,7 @@ StructRNA *pyrna_struct_as_srna(PyObject *self, int parent, const char *error_pr
/* be very careful with this since it will return a parent classes srna.
* modifying this will do confusing stuff! */
if(py_srna==NULL)
- py_srna= (BPy_StructRNA*)PyObject_GetAttrString(self, "bl_rna");
+ py_srna= (BPy_StructRNA*)PyObject_GetAttr(self, bpy_intern_str_bl_rna);
}
if(py_srna==NULL) {
@@ -5723,7 +5750,7 @@ static int deferred_register_prop(StructRNA *srna, PyObject *key, PyObject *item
py_srna_cobject= PyCapsule_New(srna, NULL, NULL);
/* not 100% nice :/, modifies the dict passed, should be ok */
- PyDict_SetItemString(py_kw, "attr", key);
+ PyDict_SetItem(py_kw, bpy_intern_str_attr, key);
args_fake= PyTuple_New(1);
PyTuple_SET_ITEM(args_fake, 0, py_srna_cobject);
@@ -5770,7 +5797,7 @@ static int pyrna_deferred_register_props(StructRNA *srna, PyObject *class_dict)
/* in both cases PyDict_CheckExact(class_dict) will be true even
* though Operators have a metaclass dict namespace */
- if((order= PyDict_GetItemString(class_dict, "order")) && PyList_CheckExact(order)) {
+ if((order= PyDict_GetItem(class_dict, bpy_intern_str_order)) && PyList_CheckExact(order)) {
for(pos= 0; pos<PyList_GET_SIZE(order); pos++) {
key= PyList_GET_ITEM(order, pos);
item= PyDict_GetItem(class_dict, key);
@@ -5863,7 +5890,6 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
PyObject *py_class= (PyObject*)py_data;
PyObject *base_class= RNA_struct_py_type_get(srna);
PyObject *item;
- PyObject *py_arg_count;
int i, flag, arg_count, func_arg_count;
const char *py_class_name= ((PyTypeObject *)py_class)->tp_name; // __name__
@@ -5926,9 +5952,7 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
func_arg_count= rna_function_arg_count(func);
if (func_arg_count >= 0) { /* -1 if we dont care*/
- py_arg_count= PyObject_GetAttrString(PyFunction_GET_CODE(item), "co_argcount");
- arg_count= PyLong_AsLong(py_arg_count);
- Py_DECREF(py_arg_count);
+ arg_count= ((PyCodeObject *)PyFunction_GET_CODE(item))->co_argcount;
/* note, the number of args we check for and the number of args we give to
* @classmethods are different (quirk of python), this is why rna_function_arg_count() doesn't return the value -1*/
@@ -6019,9 +6043,10 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
PyGILState_STATE gilstate;
#ifdef USE_PEDANTIC_WRITE
+ const int is_operator= RNA_struct_is_a(ptr->type, &RNA_Operator);
const char *func_id= RNA_function_identifier(func);
/* testing, for correctness, not operator and not draw function */
- const short is_readonly= strstr("draw", func_id) || /*strstr("render", func_id) ||*/ !RNA_struct_is_a(ptr->type, &RNA_Operator);
+ const short is_readonly= strstr("draw", func_id) || /*strstr("render", func_id) ||*/ !is_operator;
#endif
py_class= RNA_struct_py_type_get(ptr->type);
@@ -6040,17 +6065,18 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
bpy_context_set(C, &gilstate);
if (!is_static) {
- /* exception, operators store their PyObjects for re-use */
+ /* some datatypes (operator, render engine) can store PyObjects for re-use */
if(ptr->data) {
- if(RNA_struct_is_a(ptr->type, &RNA_Operator)) {
- wmOperator *op= ptr->data;
- if(op->py_instance) {
- py_class_instance= op->py_instance;
+ void **instance = RNA_struct_instance(ptr);
+
+ if(instance) {
+ if(*instance) {
+ py_class_instance= *instance;
Py_INCREF(py_class_instance);
}
else {
/* store the instance here once its created */
- py_class_instance_store= &op->py_instance;
+ py_class_instance_store= instance;
}
}
}
@@ -6076,6 +6102,11 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
* Although this is annoying to have to impliment a part of pythons typeobject.c:type_call().
*/
if(py_class->tp_init) {
+#ifdef USE_PEDANTIC_WRITE
+ const int prev_write= rna_disallow_writes;
+ rna_disallow_writes= is_operator ? FALSE : TRUE; /* only operators can write on __init__ */
+#endif
+
/* true in most cases even when the class its self doesn't define an __init__ function. */
args= PyTuple_New(0);
if (py_class->tp_init(py_srna, args, NULL) < 0) {
@@ -6084,11 +6115,16 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
/* err set below */
}
Py_DECREF(args);
+#ifdef USE_PEDANTIC_WRITE
+ rna_disallow_writes= prev_write;
+#endif
}
-
py_class_instance= py_srna;
#else
+ const int prev_write= rna_disallow_writes;
+ rna_disallow_writes= TRUE;
+
/* 'almost' all the time calling the class isn't needed.
* We could just do...
py_class_instance= py_srna;
@@ -6102,7 +6138,10 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
py_class_instance= PyObject_Call(py_class, args, NULL);
Py_DECREF(args);
+ rna_disallow_writes= prev_write;
+
#endif
+
if(py_class_instance == NULL) {
err= -1; /* so the error is not overridden below */
}
@@ -6277,7 +6316,7 @@ static void bpy_class_free(void *pyob_ptr)
// PyDict_Clear(((PyTypeObject*)self)->tp_dict);
//
// remove the rna attribute instead.
- PyDict_DelItemString(((PyTypeObject *)self)->tp_dict, "bl_rna");
+ PyDict_DelItem(((PyTypeObject *)self)->tp_dict, bpy_intern_str_bl_rna);
if(PyErr_Occurred())
PyErr_Clear();
@@ -6358,16 +6397,20 @@ void pyrna_free_types(void)
* the decref. This is not so bad because the leak only happens when re-registering (hold F8)
* - Should still be fixed - Campbell
* */
-static char pyrna_register_class_doc[] =
+PyDoc_STRVAR(pyrna_register_class_doc,
".. method:: register_class(cls)\n"
"\n"
-" Register a subclass of a blender type in (:class:`Panel`, :class:`Menu`, :class:`Header`, :class:`Operator`, :class:`KeyingSetInfo`, :class:`RenderEngine`).\n"
+" Register a subclass of a blender type in (:class:`Panel`,\n"
+" :class:`Menu`, :class:`Header`, :class:`Operator`,\n"
+" :class:`KeyingSetInfo`, :class:`RenderEngine`).\n"
"\n"
-" If the class has a *register* class method it will be called before registration.\n"
+" If the class has a *register* class method it will be called\n"
+" before registration.\n"
"\n"
-" .. note:: :exc:`ValueError` exception is raised if the class is not a subclass of a registerable blender class.\n"
+" .. note:: :exc:`ValueError` exception is raised if the class is not a\n"
+" subclass of a registerable blender class.\n"
"\n"
-;
+);
PyMethodDef meth_bpy_register_class= {"register_class", pyrna_register_class, METH_O, pyrna_register_class_doc};
static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class)
{
@@ -6379,7 +6422,7 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class
const char *identifier;
PyObject *py_cls_meth;
- if(PyDict_GetItemString(((PyTypeObject*)py_class)->tp_dict, "bl_rna")) {
+ if(PyDict_GetItem(((PyTypeObject*)py_class)->tp_dict, bpy_intern_str_bl_rna)) {
PyErr_SetString(PyExc_AttributeError, "register_class(...): already registered as a subclass");
return NULL;
}
@@ -6418,7 +6461,7 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class
identifier= ((PyTypeObject*)py_class)->tp_name;
- srna_new= reg(C, &reports, py_class, identifier, bpy_class_validate, bpy_class_call, bpy_class_free);
+ srna_new= reg(CTX_data_main(C), &reports, py_class, identifier, bpy_class_validate, bpy_class_call, bpy_class_free);
if(BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE) == -1)
return NULL;
@@ -6444,7 +6487,7 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class
return NULL;
/* call classed register method () */
- py_cls_meth= PyObject_GetAttrString(py_class, "register");
+ py_cls_meth= PyObject_GetAttr(py_class, bpy_intern_str_register);
if(py_cls_meth == NULL) {
PyErr_Clear();
}
@@ -6486,13 +6529,14 @@ static int pyrna_srna_contains_pointer_prop_srna(StructRNA *srna_props, StructRN
return 0;
}
-static char pyrna_unregister_class_doc[] =
+PyDoc_STRVAR(pyrna_unregister_class_doc,
".. method:: unregister_class(cls)\n"
"\n"
" Unload the python class from blender.\n"
"\n"
-" If the class has an *unregister* class method it will be called before unregistering.\n"
-;
+" If the class has an *unregister* class method it will be called\n"
+" before unregistering.\n"
+);
PyMethodDef meth_bpy_unregister_class= {"unregister_class", pyrna_unregister_class, METH_O, pyrna_unregister_class_doc};
static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_class)
{
@@ -6501,7 +6545,7 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla
StructRNA *srna;
PyObject *py_cls_meth;
- /*if(PyDict_GetItemString(((PyTypeObject*)py_class)->tp_dict, "bl_rna")==NULL) {
+ /*if(PyDict_GetItem(((PyTypeObject*)py_class)->tp_dict, bpy_intern_str_bl_rna)==NULL) {
PWM_cursor_wait(0);
PyErr_SetString(PyExc_ValueError, "unregister_class(): not a registered as a subclass");
return NULL;
@@ -6520,7 +6564,7 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla
}
/* call classed unregister method */
- py_cls_meth= PyObject_GetAttrString(py_class, "unregister");
+ py_cls_meth= PyObject_GetAttr(py_class, bpy_intern_str_unregister);
if(py_cls_meth == NULL) {
PyErr_Clear();
}
@@ -6568,9 +6612,9 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla
C= BPy_GetContext();
/* call unregister */
- unreg(C, srna); /* calls bpy_class_free, this decref's py_class */
+ unreg(CTX_data_main(C), srna); /* calls bpy_class_free, this decref's py_class */
- PyDict_DelItemString(((PyTypeObject *)py_class)->tp_dict, "bl_rna");
+ PyDict_DelItem(((PyTypeObject *)py_class)->tp_dict, bpy_intern_str_bl_rna);
if(PyErr_Occurred())
PyErr_Clear(); //return NULL;