Cycles: svn merge -r41467:41531 ^/trunk/blender

This commit is contained in:
2011-11-04 20:21:40 +00:00
188 changed files with 1833 additions and 700 deletions

View File

@@ -38,17 +38,22 @@ void bpy_app_generic_callback(struct Main *main, struct ID *id, void *arg);
static PyTypeObject BlenderAppCbType;
static PyStructSequence_Field app_cb_info_fields[]= {
{(char *)"frame_change_pre", NULL},
{(char *)"frame_change_post", NULL},
{(char *)"render_pre", NULL},
{(char *)"render_post", NULL},
{(char *)"render_stats", NULL},
{(char *)"load_pre", NULL},
{(char *)"load_post", NULL},
{(char *)"save_pre", NULL},
{(char *)"save_post", NULL},
{(char *)"scene_update_pre", NULL},
{(char *)"scene_update_post", NULL},
{(char *)"frame_change_pre", (char *)"Callback list - on frame change for playback and rendering (before)"},
{(char *)"frame_change_post", (char *)"Callback list - on frame change for playback and rendering (after)"},
{(char *)"render_pre", (char *)"Callback list - on render (before)"},
{(char *)"render_post", (char *)"Callback list - on render (after)"},
{(char *)"render_stats", (char *)"Callback list - on printing render statistics"},
{(char *)"load_pre", (char *)"Callback list - on loading a new blend file (before)"},
{(char *)"load_post", (char *)"Callback list - on loading a new blend file (after)"},
{(char *)"save_pre", (char *)"Callback list - on saving a blend file (before)"},
{(char *)"save_post", (char *)"Callback list - on saving a blend file (after)"},
{(char *)"scene_update_pre", (char *)"Callback list - on updating the scenes data (before)"},
{(char *)"scene_update_post", (char *)"Callback list - on updating the scenes data (after)"},
/* sets the permanent tag */
# define APP_CB_OTHER_FIELDS 1
{(char *)"persistent", (char *)"Function decorator for callback functions not to be removed when loading new files"},
{NULL}
};
@@ -65,6 +70,95 @@ static PyStructSequence_Desc app_cb_info_desc= {
#endif
*/
/* --------------------------------------------------------------------------*/
/* permanent tagging code */
#define PERMINENT_CB_ID "_bpy_persistent"
static PyObject *bpy_app_handlers_persistent_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *UNUSED(kwds))
{
PyObject *value;
if(!PyArg_ParseTuple(args, "O:bpy.app.handlers.persistent", &value))
return NULL;
if (PyFunction_Check(value)) {
PyObject **dict_ptr= _PyObject_GetDictPtr(value);
if (dict_ptr == NULL) {
PyErr_SetString(PyExc_ValueError,
"bpy.app.handlers.persistent wasn't able to "
"get the dictionary from the function passed");
return NULL;
}
else {
/* set id */
if (*dict_ptr == NULL) {
*dict_ptr= PyDict_New();
}
PyDict_SetItemString(*dict_ptr, PERMINENT_CB_ID, Py_None);
}
Py_INCREF(value);
return value;
}
else {
PyErr_SetString(PyExc_ValueError,
"bpy.app.handlers.persistent expected a function");
return NULL;
}
}
/* dummy type because decorators can't be PyCFunctions */
static PyTypeObject BPyPersistent_Type = {
#if defined(_MSC_VER) || defined(FREE_WINDOWS)
PyVarObject_HEAD_INIT(NULL, 0)
#else
PyVarObject_HEAD_INIT(&PyType_Type, 0)
#endif
"persistent", /* tp_name */
0, /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
0, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
bpy_app_handlers_persistent_new, /* tp_new */
0, /* tp_free */
};
static PyObject *py_cb_array[BLI_CB_EVT_TOT]= {NULL};
static PyObject *make_app_cb_info(void)
@@ -83,10 +177,13 @@ static PyObject *make_app_cb_info(void)
}
PyStructSequence_SET_ITEM(app_cb_info, pos, (py_cb_array[pos]= PyList_New(0)));
}
if (app_cb_info_fields[pos].name != NULL) {
if (app_cb_info_fields[pos + APP_CB_OTHER_FIELDS].name != NULL) {
Py_FatalError("invalid callback slots 2");
}
/* custom function */
PyStructSequence_SET_ITEM(app_cb_info, pos++, (PyObject *)&BPyPersistent_Type);
return app_cb_info;
}
@@ -94,6 +191,14 @@ PyObject *BPY_app_handlers_struct(void)
{
PyObject *ret;
#if defined(_MSC_VER) || defined(FREE_WINDOWS)
BPyPersistent_Type.ob_base.ob_base.ob_type= &PyType_Type;
#endif
if (PyType_Ready(&BPyPersistent_Type) < 0) {
BLI_assert(!"error initializing 'bpy.app.handlers.persistent'");
}
PyStructSequence_InitType(&BlenderAppCbType, &app_cb_info_desc);
ret= make_app_cb_info();
@@ -120,12 +225,46 @@ PyObject *BPY_app_handlers_struct(void)
return ret;
}
void BPY_app_handlers_reset(void)
void BPY_app_handlers_reset(const short do_all)
{
int pos= 0;
if (do_all) {
for (pos= 0; pos < BLI_CB_EVT_TOT; pos++) {
PyList_SetSlice(py_cb_array[pos], 0, PY_SSIZE_T_MAX, NULL);
/* clear list */
PyList_SetSlice(py_cb_array[pos], 0, PY_SSIZE_T_MAX, NULL);
}
}
else {
/* save string conversion thrashing */
PyObject *perm_id_str= PyUnicode_FromString(PERMINENT_CB_ID);
for (pos= 0; pos < BLI_CB_EVT_TOT; pos++) {
/* clear only items without PERMINENT_CB_ID */
PyObject *ls= py_cb_array[pos];
Py_ssize_t i;
PyObject *item;
PyObject **dict_ptr;
for(i= PyList_GET_SIZE(ls) - 1; i >= 0; i--) {
if ( (PyFunction_Check((item= PyList_GET_ITEM(ls, i)))) &&
(dict_ptr= _PyObject_GetDictPtr(item)) &&
(*dict_ptr) &&
(PyDict_GetItem(*dict_ptr, perm_id_str) != NULL))
{
/* keep */
}
else {
/* remove */
/* PySequence_DelItem(ls, i); */ /* more obvious buw slower */
PyList_SetSlice(ls, i, i + 1, NULL);
}
}
}
Py_DECREF(perm_id_str);
}
}

View File

@@ -380,7 +380,7 @@ static PyObject *pyop_getrna(PyObject *UNUSED(self), PyObject *value)
{
wmOperatorType *ot;
PointerRNA ptr;
char *opname= _PyUnicode_AsString(value);
const char *opname= _PyUnicode_AsString(value);
BPy_StructRNA *pyrna= NULL;
if (opname==NULL) {
@@ -413,7 +413,7 @@ static PyObject *pyop_getinstance(PyObject *UNUSED(self), PyObject *value)
wmOperatorType *ot;
wmOperator *op;
PointerRNA ptr;
char *opname= _PyUnicode_AsString(value);
const char *opname= _PyUnicode_AsString(value);
BPy_StructRNA *pyrna= NULL;
if (opname==NULL) {

View File

@@ -1211,7 +1211,7 @@ static StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix
if (!srna) {
if (PyErr_Occurred()) {
PyObject *msg= PyC_ExceptionBuffer();
char *msg_char= _PyUnicode_AsString(msg);
const char *msg_char= _PyUnicode_AsString(msg);
PyErr_Format(PyExc_TypeError,
"%.200s expected an RNA type derived from PropertyGroup, failed with: %s",
error_prefix, msg_char);