From 9d6f05edb810ed06b7d1a48c7c00cd6e62956d5f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 18 Sep 2013 01:22:28 +0000 Subject: fix relating to bug [#36758], When printing operator reports, ommit unset properties. This is needed because in some cases operators check if a value is set or not, so filling in default arguments may change behavior. --- source/blender/makesrna/RNA_access.h | 12 +-- source/blender/makesrna/intern/rna_access.c | 90 ++++++++++------------ source/blender/python/intern/bpy_rna.c | 2 +- .../blender/windowmanager/intern/wm_event_system.c | 6 +- source/blender/windowmanager/intern/wm_operators.c | 10 +-- 5 files changed, 53 insertions(+), 67 deletions(-) (limited to 'source') diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index b6152c4a4bf..d18fe7629fd 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -1035,15 +1035,15 @@ void RNA_struct_property_unset(PointerRNA *ptr, const char *identifier); /* python compatible string representation of this property, (must be freed!) */ char *RNA_property_as_string(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index, int max_prop_length); char *RNA_pointer_as_string(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop_ptr, PointerRNA *ptr_prop); -char *RNA_pointer_as_string_keywords_ex(struct bContext *C, PointerRNA *ptr, PointerRNA *ptr_default, - const short skip_optional_value, const short all_args, +char *RNA_pointer_as_string_keywords_ex(struct bContext *C, PointerRNA *ptr, + const bool skip_optional_value, const bool all_args, const int max_prop_length, PropertyRNA *iterprop); -char *RNA_pointer_as_string_keywords(struct bContext *C, PointerRNA *ptr, PointerRNA *ptr_default, - const short skip_optional_value, const short all_args, +char *RNA_pointer_as_string_keywords(struct bContext *C, PointerRNA *ptr, + const bool skip_optional_value, const bool all_args, const int max_prop_length); -char *RNA_function_as_string_keywords(struct bContext *C, FunctionRNA *func, PointerRNA *ptr_default, - const short as_function, const short all_args, +char *RNA_function_as_string_keywords(struct bContext *C, FunctionRNA *func, + const bool as_function, const bool all_args, const int max_prop_length); /* Function */ diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 4cdb3b4ca7e..918c67b4513 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -4175,7 +4175,7 @@ static char *rna_idp_path_create(IDP_Chain *child_link) { DynStr *dynstr = BLI_dynstr_new(); char *path; - short first = TRUE; + bool is_first = true; int tot = 0; IDP_Chain *link = child_link; @@ -4194,13 +4194,13 @@ static char *rna_idp_path_create(IDP_Chain *child_link) for (link = link_prev; link; link = link->up) { /* pass */ if (link->index >= 0) { - BLI_dynstr_appendf(dynstr, first ? "%s[%d]" : ".%s[%d]", link->name, link->index); + BLI_dynstr_appendf(dynstr, is_first ? "%s[%d]" : ".%s[%d]", link->name, link->index); } else { - BLI_dynstr_appendf(dynstr, first ? "%s" : ".%s", link->name); + BLI_dynstr_appendf(dynstr, is_first ? "%s" : ".%s", link->name); } - first = FALSE; + is_first = false; } path = BLI_dynstr_get_cstring(dynstr); @@ -5041,9 +5041,9 @@ char *RNA_pointer_as_string(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *p } } -/* context and ptr_default can be NULL */ -char *RNA_pointer_as_string_keywords_ex(bContext *C, PointerRNA *ptr, PointerRNA *ptr_default, - const short as_function, const short all_args, +/* context can be NULL */ +char *RNA_pointer_as_string_keywords_ex(bContext *C, PointerRNA *ptr, + const bool as_function, const bool all_args, const int max_prop_length, PropertyRNA *iterprop) { @@ -5053,13 +5053,9 @@ char *RNA_pointer_as_string_keywords_ex(bContext *C, PointerRNA *ptr, PointerRNA DynStr *dynstr = BLI_dynstr_new(); char *cstring, *buf; - int first_iter = TRUE, ok = TRUE; + bool first_iter = true; int flag; - /* only to get the orginal props for comparisons */ - PropertyRNA *prop_default; - char *buf_default; - RNA_PROP_BEGIN (ptr, propptr, iterprop) { prop = propptr.data; @@ -5079,45 +5075,37 @@ char *RNA_pointer_as_string_keywords_ex(bContext *C, PointerRNA *ptr, PointerRNA if (as_function && (flag & PROP_REQUIRED)) { /* required args don't have useful defaults */ BLI_dynstr_appendf(dynstr, first_iter ? "%s" : ", %s", arg_name); - first_iter = FALSE; + first_iter = false; } else { - if (as_function && RNA_property_type(prop) == PROP_POINTER) { - /* don't expand pointers for functions */ - if (flag & PROP_NEVER_NULL) { - /* we cant really do the right thing here. arg=arg?, hrmf! */ - buf = BLI_strdup(arg_name); - } - else { - buf = BLI_strdup("None"); - } + bool ok = true; + + if (all_args == true) { + /* pass */ } - else { - buf = RNA_property_as_string(C, ptr, prop, -1, max_prop_length); + else if (RNA_struct_idprops_check(ptr->type)) { + ok = RNA_property_is_set(ptr, prop); } - ok = TRUE; - - if (all_args == FALSE && ptr_default) { - /* not verbose, so only add in attributes that use non-default values - * slow but good for tooltips */ - prop_default = RNA_struct_find_property(ptr_default, arg_name); - - if (prop_default) { - buf_default = RNA_property_as_string(C, ptr_default, prop_default, -1, max_prop_length); - - if (strcmp(buf, buf_default) == 0) - ok = FALSE; /* values match, don't bother printing */ - - MEM_freeN(buf_default); - } - } if (ok) { + if (as_function && RNA_property_type(prop) == PROP_POINTER) { + /* don't expand pointers for functions */ + if (flag & PROP_NEVER_NULL) { + /* we cant really do the right thing here. arg=arg?, hrmf! */ + buf = BLI_strdup(arg_name); + } + else { + buf = BLI_strdup("None"); + } + } + else { + buf = RNA_property_as_string(C, ptr, prop, -1, max_prop_length); + } + BLI_dynstr_appendf(dynstr, first_iter ? "%s=%s" : ", %s=%s", arg_name, buf); - first_iter = FALSE; + first_iter = false; + MEM_freeN(buf); } - - MEM_freeN(buf); } } RNA_PROP_END; @@ -5127,20 +5115,20 @@ char *RNA_pointer_as_string_keywords_ex(bContext *C, PointerRNA *ptr, PointerRNA return cstring; } -char *RNA_pointer_as_string_keywords(bContext *C, PointerRNA *ptr, PointerRNA *ptr_default, - const short as_function, const short all_args, +char *RNA_pointer_as_string_keywords(bContext *C, PointerRNA *ptr, + const bool as_function, const bool all_args, const int max_prop_length) { PropertyRNA *iterprop; iterprop = RNA_struct_iterator_property(ptr->type); - return RNA_pointer_as_string_keywords_ex(C, ptr, ptr_default, as_function, all_args, + return RNA_pointer_as_string_keywords_ex(C, ptr, as_function, all_args, max_prop_length, iterprop); } -char *RNA_function_as_string_keywords(bContext *C, FunctionRNA *func, PointerRNA *ptr_default, - const short as_function, const short all_args, +char *RNA_function_as_string_keywords(bContext *C, FunctionRNA *func, + const bool as_function, const bool all_args, const int max_prop_length) { PointerRNA funcptr; @@ -5152,7 +5140,7 @@ char *RNA_function_as_string_keywords(bContext *C, FunctionRNA *func, PointerRNA RNA_struct_iterator_property(funcptr.type); - return RNA_pointer_as_string_keywords_ex(C, &funcptr, ptr_default, as_function, all_args, + return RNA_pointer_as_string_keywords_ex(C, &funcptr, as_function, all_args, max_prop_length, iterprop); } @@ -5263,11 +5251,11 @@ char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop, in RNA_property_enum_items(C, ptr, prop, &item, NULL, &free); if (item) { - short is_first = TRUE; + bool is_first = false; for (; item->identifier; item++) { if (item->identifier[0] && item->value & val) { BLI_dynstr_appendf(dynstr, is_first ? "'%s'" : ", '%s'", item->identifier); - is_first = FALSE; + is_first = false; } } diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 754fd25d32b..afa855d6d99 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -5333,7 +5333,7 @@ static PyObject *pyrna_func_doc_get(BPy_FunctionRNA *self, void *UNUSED(closure) PyObject *ret; char *args; - args = RNA_function_as_string_keywords(NULL, self->func, NULL, true, true, INT_MAX); + args = RNA_function_as_string_keywords(NULL, self->func, true, true, INT_MAX); ret = PyUnicode_FromFormat("%.200s.%.200s(%.200s)\n%s", RNA_struct_identifier(self->ptr.type), diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 46cce278d0e..37bcfa4f591 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -491,7 +491,7 @@ int WM_operator_poll_context(bContext *C, wmOperatorType *ot, short context) static void wm_operator_print(bContext *C, wmOperator *op) { /* context is needed for enum function */ - char *buf = WM_operator_pystring(C, op->type, op->ptr, 1); + char *buf = WM_operator_pystring(C, op->type, op->ptr, false); printf("%s\n", buf); MEM_freeN(buf); } @@ -626,7 +626,7 @@ static void wm_operator_reports(bContext *C, wmOperator *op, int retval, int cal if (op->type->flag & OPTYPE_REGISTER) { if (G.background == 0) { /* ends up printing these in the terminal, gets annoying */ /* Report the python string representation of the operator */ - char *buf = WM_operator_pystring(C, op->type, op->ptr, 1); + char *buf = WM_operator_pystring(C, op->type, op->ptr, false); BKE_report(CTX_wm_reports(C), RPT_OPERATOR, buf); MEM_freeN(buf); } @@ -660,7 +660,7 @@ static void wm_operator_finished(bContext *C, wmOperator *op, int repeat) if (repeat == 0) { if (G.debug & G_DEBUG_WM) { - char *buf = WM_operator_pystring(C, op->type, op->ptr, 1); + char *buf = WM_operator_pystring(C, op->type, op->ptr, false); BKE_report(CTX_wm_reports(C), RPT_OPERATOR, buf); MEM_freeN(buf); } diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 1e984649ca7..03567e864db 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -542,22 +542,20 @@ char *WM_operator_pystring(bContext *C, wmOperatorType *ot, PointerRNA *opptr, i /* only to get the orginal props for comparisons */ PointerRNA opptr_default; - if (all_args == 0 || opptr == NULL) { + if (opptr == NULL) { WM_operator_properties_create_ptr(&opptr_default, ot); - - if (opptr == NULL) - opptr = &opptr_default; + opptr = &opptr_default; } WM_operator_py_idname(idname_py, ot->idname); BLI_dynstr_appendf(dynstr, "bpy.ops.%s(", idname_py); - cstring_args = RNA_pointer_as_string_keywords(C, opptr, &opptr_default, FALSE, + cstring_args = RNA_pointer_as_string_keywords(C, opptr, false, all_args, max_prop_length); BLI_dynstr_append(dynstr, cstring_args); MEM_freeN(cstring_args); - if (all_args == 0 || opptr == &opptr_default) + if (opptr == &opptr_default) WM_operator_properties_free(&opptr_default); BLI_dynstr_append(dynstr, ")"); -- cgit v1.2.3