diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-09-02 16:33:29 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-09-02 16:33:29 +0400 |
commit | b56ffd2cdb51021d1a3456af9e8f4b5451407c61 (patch) | |
tree | f51e4af01e685d779ff498b69496f9ff3a0eada1 /source/blender/python | |
parent | fefbdc4376b6bacdaba0ad50da3c706289301b3d (diff) | |
parent | 15afd240e04ef3f220b6133cc920d964dbcfcf85 (diff) |
Cycles: svn merge -r39669:39870 https://svn.blender.org/svnroot/bf-blender/trunk/blender
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/generic/bgl.c | 6 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_app_handlers.c | 5 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_intern_string.c | 5 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_operator.c | 3 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_props.c | 4 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 77 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_traceback.c | 11 |
7 files changed, 64 insertions, 47 deletions
diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c index 09432e0b316..ae8069cf3c5 100644 --- a/source/blender/python/generic/bgl.c +++ b/source/blender/python/generic/bgl.c @@ -52,11 +52,9 @@ static int Buffer_len(Buffer *self); static PyObject *Buffer_item(Buffer *self, int i); static PyObject *Buffer_slice(Buffer *self, int begin, int end); static int Buffer_ass_item(Buffer *self, int i, PyObject *v); -static int Buffer_ass_slice(Buffer *self, int begin, int end, - PyObject *seq); +static int Buffer_ass_slice(Buffer *self, int begin, int end, PyObject *seq); static PyObject *Buffer_subscript(Buffer *self, PyObject *item); -static int Buffer_ass_subscript(Buffer *self, PyObject *item, - PyObject *value); +static int Buffer_ass_subscript(Buffer *self, PyObject *item, PyObject *value); static PySequenceMethods Buffer_SeqMethods = { (lenfunc) Buffer_len, /*sq_length */ diff --git a/source/blender/python/intern/bpy_app_handlers.c b/source/blender/python/intern/bpy_app_handlers.c index 26d9ca76e3f..e7e46160199 100644 --- a/source/blender/python/intern/bpy_app_handlers.c +++ b/source/blender/python/intern/bpy_app_handlers.c @@ -42,9 +42,10 @@ static PyTypeObject BlenderAppCbType; static PyStructSequence_Field app_cb_info_fields[]= { {(char *)"render_pre", NULL}, {(char *)"render_post", NULL}, - {(char *)"load_pre", NULL}, + {(char *)"render_stats", NULL}, + {(char *)"load_pre", NULL}, {(char *)"load_post", NULL}, - {(char *)"save_pre", NULL}, + {(char *)"save_pre", NULL}, {(char *)"save_post", NULL}, {NULL} }; diff --git a/source/blender/python/intern/bpy_intern_string.c b/source/blender/python/intern/bpy_intern_string.c index c6629007532..7c80653496f 100644 --- a/source/blender/python/intern/bpy_intern_string.c +++ b/source/blender/python/intern/bpy_intern_string.c @@ -28,18 +28,19 @@ #include <Python.h> +#include "bpy_intern_string.h" + PyObject *bpy_intern_str_register; PyObject *bpy_intern_str_unregister; PyObject *bpy_intern_str_bl_rna; PyObject *bpy_intern_str_order; PyObject *bpy_intern_str_attr; PyObject *bpy_intern_str___slots__; -PyObject *bpy_intern_str___bases__; void bpy_intern_string_init(void) { bpy_intern_str_register= PyUnicode_FromString("register"); - bpy_intern_str_unregister= PyUnicode_FromString("unregister");; + bpy_intern_str_unregister= PyUnicode_FromString("unregister"); bpy_intern_str_bl_rna= PyUnicode_FromString("bl_rna"); bpy_intern_str_order= PyUnicode_FromString("order"); bpy_intern_str_attr= PyUnicode_FromString("attr"); diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index 7310878f661..7327679cc7e 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -117,7 +117,6 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args) } context_dict_back= CTX_py_dict_get(C); - CTX_py_dict_set(C, (void *)context_dict); Py_XINCREF(context_dict); /* so we done loose it */ @@ -293,7 +292,7 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args) * function corrects bpy.data (internal Main pointer) */ BPY_modules_update(C); - /* needed for when WM_OT_read_factory_settings us called fro within a script */ + /* needed for when WM_OT_read_factory_settings us called from within a script */ bpy_import_main_set(CTX_data_main(C)); /* return operator_ret as a bpy enum */ diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c index a0ad1ff7850..5da142aeea7 100644 --- a/source/blender/python/intern/bpy_props.c +++ b/source/blender/python/intern/bpy_props.c @@ -117,7 +117,7 @@ static PyObject *pymeth_PointerProperty= NULL; static PyObject *pymeth_CollectionProperty= NULL; static PyObject *pymeth_RemoveProperty= NULL; -PyObject *pyrna_struct_as_instance(PointerRNA *ptr) +static PyObject *pyrna_struct_as_instance(PointerRNA *ptr) { PyObject *self= NULL; /* first get self */ @@ -177,7 +177,7 @@ static PyObject *bpy_prop_deferred_return(PyObject *func, PyObject *kw) } /* callbacks */ -void bpy_prop_update_cb(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop) +static void bpy_prop_update_cb(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop) { PyGILState_STATE gilstate; PyObject **py_data= (PyObject **)RNA_property_py_data_get(prop); diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 72553872057..6de3c040c18 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1117,6 +1117,7 @@ static int pyrna_string_to_enum(PyObject *item, PointerRNA *ptr, PropertyRNA *pr return 1; } +/* 'value' _must_ be a set type, error check before calling */ int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int *r_value, const char *error_prefix) { /* set of enum items, concatenate all values with OR */ @@ -1138,8 +1139,10 @@ int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int *r_ error_prefix, Py_TYPE(key)->tp_name); return -1; } - if(pyrna_enum_value_from_id(items, param, &ret, error_prefix) < 0) + + if(pyrna_enum_value_from_id(items, param, &ret, error_prefix) < 0) { return -1; + } flag |= ret; } @@ -1156,6 +1159,14 @@ static int pyrna_prop_to_enum_bitfield(PointerRNA *ptr, PropertyRNA *prop, PyObj *r_value= 0; + if (!PyAnySet_Check(value)) { + PyErr_Format(PyExc_TypeError, + "%.200s, %.200s.%.200s expected a set, not a %.200s", + error_prefix, RNA_struct_identifier(ptr->type), + RNA_property_identifier(prop), Py_TYPE(value)->tp_name); + return -1; + } + RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free); if(item) { @@ -1240,7 +1251,7 @@ static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val) #if 0 // gives python decoding errors while generating docs :( char error_str[256]; - snprintf(error_str, sizeof(error_str), "RNA Warning: Current value \"%d\" matches no enum in '%s', '%s', '%s'", val, RNA_struct_identifier(ptr->type), ptr_name, RNA_property_identifier(prop)); + BLI_snprintf(error_str, sizeof(error_str), "RNA Warning: Current value \"%d\" matches no enum in '%s', '%s', '%s'", val, RNA_struct_identifier(ptr->type), ptr_name, RNA_property_identifier(prop)); PyErr_Warn(PyExc_RuntimeWarning, error_str); #endif @@ -1287,7 +1298,9 @@ PyObject *pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop) { int subtype= RNA_property_subtype(prop); const char *buf; - buf= RNA_property_string_get_alloc(ptr, prop, NULL, -1); + char buf_fixed[32]; + + buf= RNA_property_string_get_alloc(ptr, prop, buf_fixed, sizeof(buf_fixed)); #ifdef USE_STRING_COERCE /* only file paths get special treatment, they may contain non utf-8 chars */ if(ELEM3(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME)) { @@ -1299,7 +1312,9 @@ PyObject *pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop) #else // USE_STRING_COERCE ret= PyUnicode_FromString(buf); #endif // USE_STRING_COERCE - MEM_freeN((void *)buf); + if(buf_fixed != buf) { + MEM_freeN((void *)buf); + } break; } case PROP_ENUM: @@ -1529,33 +1544,18 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb { int val= 0; - if (PyUnicode_Check(value)) { - if (!pyrna_string_to_enum(value, ptr, prop, &val, error_prefix)) - return -1; - } - else if (PyAnySet_Check(value)) { - if(RNA_property_flag(prop) & PROP_ENUM_FLAG) { - /* set of enum items, concatenate all values with OR */ - if(pyrna_prop_to_enum_bitfield(ptr, prop, value, &val, error_prefix) < 0) - return -1; - } - else { - PyErr_Format(PyExc_TypeError, - "%.200s, %.200s.%.200s is not a bitflag enum type", - error_prefix, RNA_struct_identifier(ptr->type), - RNA_property_identifier(prop)); + /* type checkins is done by each function */ + if(RNA_property_flag(prop) & PROP_ENUM_FLAG) { + /* set of enum items, concatenate all values with OR */ + if(pyrna_prop_to_enum_bitfield(ptr, prop, value, &val, error_prefix) < 0) { return -1; } } else { - const char *enum_str= pyrna_enum_as_string(ptr, prop); - PyErr_Format(PyExc_TypeError, - "%.200s %.200s.%.200s expected a string enum or a set of strings in (%.2000s), not %.200s", - error_prefix, RNA_struct_identifier(ptr->type), - RNA_property_identifier(prop), enum_str, - Py_TYPE(value)->tp_name); - MEM_freeN((void *)enum_str); - return -1; + /* simple enum string */ + if (!pyrna_string_to_enum(value, ptr, prop, &val, error_prefix) < 0) { + return -1; + } } if(data) *((int*)data)= val; @@ -4320,7 +4320,6 @@ static PyObject *small_dict_get_item_string(PyObject *dict, const char *key_look Py_ssize_t pos = 0; PyObject *value = NULL; - /* case not, search for it in the script's global dictionary */ while (PyDict_Next(dict, &pos, &key, &value)) { if(PyUnicode_Check(key)) { if(strcmp(key_lookup, _PyUnicode_AsString(key))==0) { @@ -6422,7 +6421,21 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param err= -1; } else if(ret_len==1) { - err= pyrna_py_to_prop(&funcptr, pret_single, retdata_single, ret, "calling class function:"); + err= pyrna_py_to_prop(&funcptr, pret_single, retdata_single, ret, ""); + + /* when calling operator funcs only gives Function.result with + * no line number since the func has finished calling on error, + * re-raise the exception with more info since it would be slow to + * create prefix on every call (when there are no errors) */ + if(err == -1 && PyErr_Occurred()) { + PyObject *error_type, *error_value, *error_traceback; + PyErr_Fetch(&error_type, &error_value, &error_traceback); + + PyErr_Format(error_type, + "class %.200s, function %.200s: incompatible return value%S", + RNA_struct_identifier(ptr->type), RNA_function_identifier(func), + error_value); + } } else if (ret_len > 1) { @@ -6582,9 +6595,9 @@ void pyrna_free_types(void) PyDoc_STRVAR(pyrna_register_class_doc, ".. method:: register_class(cls)\n" "\n" -" Register a subclass of a blender type in (:class:`Panel`,\n" -" :class:`Menu`, :class:`Header`, :class:`Operator`,\n" -" :class:`KeyingSetInfo`, :class:`RenderEngine`).\n" +" Register a subclass of a blender type in (:class:`bpy.types.Panel`,\n" +" :class:`bpy.types.Menu`, :class:`bpy.types.Header`, :class:`bpy.types.Operator`,\n" +" :class:`bpy.types.KeyingSetInfo`, :class:`bpy.types.RenderEngine`).\n" "\n" " If the class has a *register* class method it will be called\n" " before registration.\n" diff --git a/source/blender/python/intern/bpy_traceback.c b/source/blender/python/intern/bpy_traceback.c index 17f082b79dc..747a876d6df 100644 --- a/source/blender/python/intern/bpy_traceback.c +++ b/source/blender/python/intern/bpy_traceback.c @@ -30,9 +30,9 @@ #include "bpy_traceback.h" -static const char *traceback_filepath(PyTracebackObject *tb) +static const char *traceback_filepath(PyTracebackObject *tb, PyObject **coerce) { - return _PyUnicode_AsString(tb->tb_frame->f_code->co_filename); + return PyBytes_AS_STRING((*coerce= PyUnicode_EncodeFSDefault(tb->tb_frame->f_code->co_filename))); } /* copied from pythonrun.c, 3.2.0 */ @@ -146,7 +146,12 @@ void python_script_error_jump(const char *filepath, int *lineno, int *offset) PyErr_Print(); for(tb= (PyTracebackObject *)PySys_GetObject("last_traceback"); tb && (PyObject *)tb != Py_None; tb= tb->tb_next) { - if(strcmp(traceback_filepath(tb), filepath) != 0) { + PyObject *coerce; + const char *tb_filepath= traceback_filepath(tb, &coerce); + const int match= strcmp(tb_filepath, filepath) != 0; + Py_DECREF(coerce); + + if(match) { *lineno= tb->tb_lineno; break; } |