merge with trunk r39216

This commit is contained in:
Xiao Xiangquan
2011-08-10 14:32:03 +00:00
210 changed files with 6222 additions and 3313 deletions

View File

@@ -41,8 +41,6 @@
#include "bpy_driver.h"
#include "../generic/py_capi_utils.h"
/* for pydrivers (drivers using one-line Python expressions to express relationships between targets) */
PyObject *bpy_pydriver_Dict= NULL;
@@ -89,7 +87,7 @@ int bpy_pydriver_create_dict(void)
void BPY_driver_reset(void)
{
PyGILState_STATE gilstate;
int use_gil= !PYC_INTERPRETER_ACTIVE;
int use_gil= 1; /* !PYC_INTERPRETER_ACTIVE; */
if(use_gil)
gilstate= PyGILState_Ensure();
@@ -120,9 +118,14 @@ static void pydriver_error(ChannelDriver *driver)
/* This evals py driver expressions, 'expr' is a Python expression that
* should evaluate to a float number, which is returned.
*
* note: PyGILState_Ensure() isnt always called because python can call the
* bake operator which intern starts a thread which calls scene update which
* does a driver update. to avoid a deadlock check PYC_INTERPRETER_ACTIVE if PyGILState_Ensure() is needed.
* (old)note: PyGILState_Ensure() isnt always called because python can call
* the bake operator which intern starts a thread which calls scene update
* which does a driver update. to avoid a deadlock check PYC_INTERPRETER_ACTIVE
* if PyGILState_Ensure() is needed - see [#27683]
*
* (new)note: checking if python is running is not threadsafe [#28114]
* now release the GIL on python operator execution instead, using
* PyEval_SaveThread() / PyEval_RestoreThread() so we dont lock up blender.
*/
float BPY_driver_exec(ChannelDriver *driver)
{
@@ -149,7 +152,7 @@ float BPY_driver_exec(ChannelDriver *driver)
return 0.0f;
}
use_gil= !PYC_INTERPRETER_ACTIVE;
use_gil= 1; /* !PYC_INTERPRETER_ACTIVE; */
if(use_gil)
gilstate= PyGILState_Ensure();

View File

@@ -39,6 +39,7 @@
#include "BKE_library.h"
#include "BKE_idcode.h"
#include "BKE_report.h"
#include "BKE_context.h"
#include "BLI_utildefines.h"
#include "BLI_string.h"
@@ -317,7 +318,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
flag_all_listbases_ids(LIB_PRE_EXISTING, 1);
/* here appending/linking starts */
mainl= BLO_library_append_begin(BPy_GetContext(), &(self->blo_handle), self->relpath);
mainl= BLO_library_append_begin(CTX_data_main(BPy_GetContext()), &(self->blo_handle), self->relpath);
{
int i= 0, code;

View File

@@ -55,6 +55,10 @@
#include "BKE_report.h"
#include "BKE_context.h"
/* so operators called can spawn threads which aquire the GIL */
#define BPY_RELEASE_GIL
static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
{
wmOperatorType *ot;
@@ -219,7 +223,22 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
reports= MEM_mallocN(sizeof(ReportList), "wmOperatorReportList");
BKE_reports_init(reports, RPT_STORE | RPT_OP_HOLD); /* own so these dont move into global reports */
operator_ret= WM_operator_call_py(C, ot, context, &ptr, reports);
#ifdef BPY_RELEASE_GIL
/* release GIL, since a thread could be started from an operator
* that updates a driver */
/* note: I havve not seen any examples of code that does this
* so it may not be officially supported but seems to work ok. */
{
PyThreadState *ts= PyEval_SaveThread();
#endif
operator_ret= WM_operator_call_py(C, ot, context, &ptr, reports);
#ifdef BPY_RELEASE_GIL
/* regain GIL */
PyEval_RestoreThread(ts);
}
#endif
error_val= BPy_reports_to_error(reports, PyExc_RuntimeError, FALSE);
@@ -378,7 +397,9 @@ static PyObject *pyop_getrna(PyObject *UNUSED(self), PyObject *value)
pyrna= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr);
#ifdef PYRNA_FREE_SUPPORT
pyrna->freeptr= TRUE;
#endif
return (PyObject *)pyrna;
}

View File

@@ -326,6 +326,11 @@ static int bpy_prop_callback_assign(struct PropertyRNA *prop, PyObject *update_c
" :type description: string\n" \
#define BPY_PROPDEF_UNIT_DOC \
" :arg unit: Enumerator in ['NONE', 'LENGTH', 'AREA', 'VOLUME', 'ROTATION', 'TIME', 'VELOCITY', 'ACCELERATION'].\n" \
" :type unit: string\n" \
#define BPY_PROPDEF_UPDATE_DOC \
" :arg update: function to be called when this value is modified,\n" \
" This function must take 2 values (self, context) and return None.\n" \
@@ -639,8 +644,7 @@ BPY_PROPDEF_DESC_DOC
" :type options: set\n"
" :arg subtype: Enumerator in ['UNSIGNED', 'PERCENTAGE', 'FACTOR', 'ANGLE', 'TIME', 'DISTANCE', 'NONE'].\n"
" :type subtype: string\n"
" :arg unit: Enumerator in ['NONE', 'LENGTH', 'AREA', 'VOLUME', 'ROTATION', 'TIME', 'VELOCITY', 'ACCELERATION'].\n"
" :type unit: string\n"
BPY_PROPDEF_UNIT_DOC
BPY_PROPDEF_UPDATE_DOC
);
static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
@@ -679,7 +683,7 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
BPY_PROPDEF_SUBTYPE_CHECK(FloatProperty, property_flag_items, property_subtype_number_items)
if(pyunit && RNA_enum_value_from_id(property_unit_items, pyunit, &unit)==0) {
PyErr_Format(PyExc_TypeError, "FloatProperty(unit='%s'): invalid unit");
PyErr_Format(PyExc_TypeError, "FloatProperty(unit='%s'): invalid unit", pyunit);
return NULL;
}
@@ -716,6 +720,7 @@ BPY_PROPDEF_DESC_DOC
" :type options: set\n"
" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
" :type subtype: string\n"
BPY_PROPDEF_UNIT_DOC
" :arg size: Vector dimensions in [1, and " STRINGIFY(PYRNA_STACK_ARRAY) "].\n"
" :type size: int\n"
BPY_PROPDEF_UPDATE_DOC
@@ -727,7 +732,7 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
BPY_PROPDEF_HEAD(FloatVectorProperty)
if(srna) {
static const char *kwlist[]= {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "options", "subtype", "size", "update", NULL};
static const char *kwlist[]= {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "options", "subtype", "unit", "size", "update", NULL};
const char *id=NULL, *name="", *description="";
int id_len;
float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, step=3, def[PYRNA_STACK_ARRAY]={0.0f};
@@ -738,15 +743,17 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
int opts=0;
char *pysubtype= NULL;
int subtype= PROP_NONE;
char *pyunit= NULL;
int unit= PROP_UNIT_NONE;
PyObject *update_cb= NULL;
if (!PyArg_ParseTupleAndKeywords(args, kw,
"s#|ssOfffffiO!siO:FloatVectorProperty",
"s#|ssOfffffiO!ssiO:FloatVectorProperty",
(char **)kwlist, &id, &id_len,
&name, &description, &pydef,
&min, &max, &soft_min, &soft_max,
&step, &precision, &PySet_Type,
&pyopts, &pysubtype, &size,
&pyopts, &pysubtype, &pyunit, &size,
&update_cb))
{
return NULL;
@@ -754,6 +761,11 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
BPY_PROPDEF_SUBTYPE_CHECK(FloatVectorProperty, property_flag_items, property_subtype_array_items)
if(pyunit && RNA_enum_value_from_id(property_unit_items, pyunit, &unit)==0) {
PyErr_Format(PyExc_TypeError, "FloatVectorProperty(unit='%s'): invalid unit", pyunit);
return NULL;
}
if(size < 1 || size > PYRNA_STACK_ARRAY) {
PyErr_Format(PyExc_TypeError, "FloatVectorProperty(size=%d): size must be between 0 and " STRINGIFY(PYRNA_STACK_ARRAY), size);
return NULL;
@@ -766,7 +778,7 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
return NULL;
}
prop= RNA_def_property(srna, id, PROP_FLOAT, subtype);
prop= RNA_def_property(srna, id, PROP_FLOAT, subtype | unit);
RNA_def_property_array(prop, size);
if(pydef) RNA_def_property_float_array_default(prop, def);
RNA_def_property_range(prop, min, max);

View File

@@ -908,6 +908,13 @@ static PyObject *pyrna_prop_repr(BPy_PropertyRNA *self)
return ret;
}
static PyObject *pyrna_func_repr(BPy_FunctionRNA *self)
{
return PyUnicode_FromFormat("<%.200s %.200s.%.200s()>", Py_TYPE(self)->tp_name, RNA_struct_identifier(self->ptr.type), RNA_function_identifier(self->func));
}
static long pyrna_struct_hash(BPy_StructRNA *self)
{
return _Py_HashPointer(self->ptr.data);
@@ -950,11 +957,13 @@ static int pyrna_struct_clear(BPy_StructRNA *self)
/* use our own dealloc so we can free a property if we use one */
static void pyrna_struct_dealloc(BPy_StructRNA *self)
{
#ifdef PYRNA_FREE_SUPPORT
if (self->freeptr && self->ptr.data) {
IDP_FreeProperty(self->ptr.data);
MEM_freeN(self->ptr.data);
self->ptr.data= NULL;
}
#endif /* PYRNA_FREE_SUPPORT */
#ifdef USE_WEAKREFS
if (self->in_weakreflist != NULL) {
@@ -1344,36 +1353,16 @@ 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_to_py(BPy_DummyPointerRNA *pyrna, FunctionRNA *func)
static PyObject *pyrna_func_to_py(PointerRNA *ptr, FunctionRNA *func)
{
static PyMethodDef func_meth= {"<generic rna function>", (PyCFunction)pyrna_func_call, METH_VARARGS|METH_KEYWORDS, "python rna function"};
PyObject *self;
PyObject *ret;
if(func==NULL) {
PyErr_Format(PyExc_RuntimeError,
"%.200s: type attempted to get NULL function",
RNA_struct_identifier(pyrna->ptr.type));
return NULL;
}
self= PyTuple_New(2);
PyTuple_SET_ITEM(self, 0, (PyObject *)pyrna);
Py_INCREF(pyrna);
PyTuple_SET_ITEM(self, 1, PyCapsule_New((void *)func, NULL, NULL));
ret= PyCFunction_New(&func_meth, self);
Py_DECREF(self);
return ret;
BPy_FunctionRNA* pyfunc= (BPy_FunctionRNA *) PyObject_NEW(BPy_FunctionRNA, &pyrna_func_Type);
pyfunc->ptr= *ptr;
pyfunc->func= func;
return (PyObject *)pyfunc;
}
static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *value, const char *error_prefix)
{
/* XXX hard limits should be checked here */
@@ -3001,7 +2990,7 @@ static PyObject *pyrna_struct_getattro(BPy_StructRNA *self, PyObject *pyname)
}
/* RNA function only if callback is declared (no optional functions) */
else if ((func= RNA_struct_find_function(&self->ptr, name)) && RNA_function_defined(func)) {
ret= pyrna_func_to_py((BPy_DummyPointerRNA *)self, func);
ret= pyrna_func_to_py(&self->ptr, func);
}
else if (self->ptr.type == &RNA_Context) {
bContext *C= self->ptr.data;
@@ -3262,11 +3251,15 @@ static PyObject *pyrna_prop_dir(BPy_PropertyRNA *self)
* */
ret= PyList_New(0);
if (!BPy_PropertyRNA_CheckExact(self))
if (!BPy_PropertyRNA_CheckExact(self)) {
pyrna_dir_members_py(ret, (PyObject *)self);
}
if(RNA_property_collection_type_get(&self->ptr, self->prop, &r_ptr))
pyrna_dir_members_rna(ret, &r_ptr);
if(RNA_property_type(self->prop) == PROP_COLLECTION) {
if(RNA_property_collection_type_get(&self->ptr, self->prop, &r_ptr)) {
pyrna_dir_members_rna(ret, &r_ptr);
}
}
return ret;
}
@@ -3299,7 +3292,7 @@ static PyObject *pyrna_prop_collection_getattro(BPy_PropertyRNA *self, PyObject
}
else if ((func= RNA_struct_find_function(&r_ptr, name))) {
PyObject *self_collection= pyrna_struct_CreatePyObject(&r_ptr);
ret= pyrna_func_to_py((BPy_DummyPointerRNA *)self_collection, func);
ret= pyrna_func_to_py(&((BPy_DummyPointerRNA *)self_collection)->ptr, func);
Py_DECREF(self_collection);
return ret;
@@ -4253,11 +4246,11 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat
return ret;
}
static PyObject *pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw)
static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject *kw)
{
/* Note, both BPy_StructRNA and BPy_PropertyRNA can be used here */
PointerRNA *self_ptr= &(((BPy_DummyPointerRNA *)PyTuple_GET_ITEM(self, 0))->ptr);
FunctionRNA *self_func= PyCapsule_GetPointer(PyTuple_GET_ITEM(self, 1), NULL);
PointerRNA *self_ptr= &self->ptr;
FunctionRNA *self_func= self->func;
PointerRNA funcptr;
ParameterList parms;
@@ -5041,6 +5034,91 @@ static PyTypeObject pyrna_prop_collection_idprop_Type= {
NULL
};
/*-----------------------BPy_PropertyRNA method def------------------------------*/
PyTypeObject pyrna_func_Type= {
PyVarObject_HEAD_INIT(NULL, 0)
"bpy_func", /* tp_name */
sizeof(BPy_FunctionRNA), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
NULL, /* tp_dealloc */
NULL, /* printfunc tp_print; */
NULL, /* getattrfunc tp_getattr; */
NULL, /* setattrfunc tp_setattr; */
NULL, /* tp_compare */ /* DEPRECATED in python 3.0! */
(reprfunc) pyrna_func_repr, /* tp_repr */
/* Method suites for standard classes */
NULL, /* PyNumberMethods *tp_as_number; */
NULL, /* PySequenceMethods *tp_as_sequence; */
NULL, /* PyMappingMethods *tp_as_mapping; */
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
(ternaryfunc)pyrna_func_call, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
/* will only use these if this is a subtype of a py class */
NULL, /* getattrofunc tp_getattro; */
NULL, /* setattrofunc tp_setattro; */
/* Functions to access object as input/output buffer */
NULL, /* PyBufferProcs *tp_as_buffer; */
/*** Flags to define presence of optional/expanded features ***/
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
NULL, /* char *tp_doc; Documentation string */
/*** Assigned meaning in release 2.0 ***/
/* call function for all accessible objects */
NULL, /* traverseproc tp_traverse; */
/* delete references to contained objects */
NULL, /* inquiry tp_clear; */
/*** Assigned meaning in release 2.1 ***/
/*** rich comparisons ***/
NULL, /* richcmpfunc tp_richcompare; */
/*** weak reference enabler ***/
#ifdef USE_WEAKREFS
offsetof(BPy_PropertyRNA, in_weakreflist), /* long tp_weaklistoffset; */
#else
0,
#endif
/*** Added in release 2.2 ***/
/* Iterators */
NULL, /* getiterfunc tp_iter; */
NULL, /* iternextfunc tp_iternext; */
/*** Attribute descriptor and subclassing stuff ***/
NULL, /* struct PyMethodDef *tp_methods; */
NULL, /* struct PyMemberDef *tp_members; */
NULL, /* struct PyGetSetDef *tp_getset; */
NULL, /* struct _typeobject *tp_base; */
NULL, /* PyObject *tp_dict; */
NULL, /* descrgetfunc tp_descr_get; */
NULL, /* descrsetfunc tp_descr_set; */
0, /* long tp_dictoffset; */
NULL, /* initproc tp_init; */
NULL, /* allocfunc tp_alloc; */
NULL, /* newfunc tp_new; */
/* Low-level free-memory routine */
NULL, /* freefunc tp_free; */
/* For PyObject_IS_GC */
NULL, /* inquiry tp_is_gc; */
NULL, /* PyObject *tp_bases; */
/* method resolution order */
NULL, /* PyObject *tp_mro; */
NULL, /* PyObject *tp_cache; */
NULL, /* PyObject *tp_subclasses; */
NULL, /* PyObject *tp_weaklist; */
NULL
};
#ifdef USE_PYRNA_ITER
/* --- collection iterator: start --- */
/* wrap rna collection iterator functions */
@@ -5419,7 +5497,9 @@ PyObject *pyrna_struct_CreatePyObject(PointerRNA *ptr)
}
pyrna->ptr= *ptr;
#ifdef PYRNA_FREE_SUPPORT
pyrna->freeptr= FALSE;
#endif
#ifdef USE_PYRNA_STRUCT_REFERENCE
pyrna->reference= NULL;
@@ -5512,6 +5592,9 @@ void BPY_rna_init(void)
if(PyType_Ready(&pyrna_prop_collection_idprop_Type) < 0)
return;
if(PyType_Ready(&pyrna_func_Type) < 0)
return;
#ifdef USE_PYRNA_ITER
if(PyType_Ready(&pyrna_prop_collection_iter_Type) < 0)
return;
@@ -6407,7 +6490,9 @@ PyDoc_STRVAR(pyrna_register_class_doc,
" 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\n"
" .. note::\n"
"\n"
" :exc:`ValueError` exception is raised if the class is not a\n"
" subclass of a registerable blender class.\n"
"\n"
);

View File

@@ -62,6 +62,11 @@
#if defined(USE_PYRNA_INVALIDATE_GC) && defined(USE_PYRNA_INVALIDATE_WEAKREF)
#error "Only 1 reference check method at a time!"
#endif
/* only used by operator introspection get_rna(), this is only used for doc gen
* so prefer the leak to the memory bloat for now. */
// #define PYRNA_FREE_SUPPORT
/* --- end bpy build options --- */
struct ID;
@@ -71,6 +76,7 @@ extern PyTypeObject pyrna_struct_Type;
extern PyTypeObject pyrna_prop_Type;
extern PyTypeObject pyrna_prop_array_Type;
extern PyTypeObject pyrna_prop_collection_Type;
extern PyTypeObject pyrna_func_Type;
#define BPy_StructRNA_Check(v) (PyObject_TypeCheck(v, &pyrna_struct_Type))
#define BPy_StructRNA_CheckExact(v) (Py_TYPE(v) == &pyrna_struct_Type)
@@ -107,7 +113,10 @@ typedef struct {
* hold onto the collection iterator to prevent it from freeing allocated data we may use */
PyObject *reference;
#endif /* !USE_PYRNA_STRUCT_REFERENCE */
#ifdef PYRNA_FREE_SUPPORT
int freeptr; /* needed in some cases if ptr.data is created on the fly, free when deallocing */
#endif /* PYRNA_FREE_SUPPORT */
} BPy_StructRNA;
typedef struct {
@@ -142,6 +151,15 @@ typedef struct {
CollectionPropertyIterator iter;
} BPy_PropertyCollectionIterRNA;
typedef struct {
PyObject_HEAD /* required python macro */
#ifdef USE_WEAKREFS
PyObject *in_weakreflist;
#endif
PointerRNA ptr;
FunctionRNA *func;
} BPy_FunctionRNA;
/* cheap trick */
#define BPy_BaseTypeRNA BPy_PropertyRNA