Merge with 2.5 -r 21619:21756.
[blender-staging.git] / source / blender / makesrna / intern / rna_access.c
index 206a0daceb67b1dcb00ed0868186f1da06f6a89f..9c133605f96c9f862b4e6abe465fafa1d2d22dd6 100644 (file)
@@ -1404,9 +1404,10 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA
 #if 0
        else if(cprop->add){
                if(!(cprop->add->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */
-                       ParameterList *params= RNA_parameter_list_create(ptr, cprop->add);
-                       RNA_function_call(NULL, NULL, ptr, cprop->add, params);
-                       RNA_parameter_list_free(params);
+                       ParameterList params;
+                       RNA_parameter_list_create(&params, ptr, cprop->add);
+                       RNA_function_call(NULL, NULL, ptr, cprop->add, &params);
+                       RNA_parameter_list_free(&params);
                }
        }
 #endif
@@ -1453,9 +1454,10 @@ void RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key)
 #if 0
        else if(cprop->remove){
                if(!(cprop->remove->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */
-                       ParameterList *params= RNA_parameter_list_create(ptr, cprop->remove);
-                       RNA_function_call(NULL, NULL, ptr, cprop->remove, params);
-                       RNA_parameter_list_free(params);
+                       ParameterList params;
+                       RNA_parameter_list_create(&ptr, cprop->remove);
+                       RNA_function_call(NULL, NULL, ptr, cprop->remove, &params);
+                       RNA_parameter_list_free(&params);
                }
        }
 #endif
@@ -2645,6 +2647,8 @@ char *RNA_property_as_string(PointerRNA *ptr, PropertyRNA *prop)
                        for(i=0; i<len; i++) {
                                BLI_dynstr_appendf(dynstr, i?", %s":"%s", RNA_property_boolean_get_index(ptr, prop, i) ? "True" : "False");
                        }
+                       if(len==1)
+                               BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
                        BLI_dynstr_append(dynstr, ")");
                }
                break;
@@ -2657,6 +2661,8 @@ char *RNA_property_as_string(PointerRNA *ptr, PropertyRNA *prop)
                        for(i=0; i<len; i++) {
                                BLI_dynstr_appendf(dynstr, i?", %d":"%d", RNA_property_int_get_index(ptr, prop, i));
                        }
+                       if(len==1)
+                               BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
                        BLI_dynstr_append(dynstr, ")");
                }
                break;
@@ -2669,6 +2675,8 @@ char *RNA_property_as_string(PointerRNA *ptr, PropertyRNA *prop)
                        for(i=0; i<len; i++) {
                                BLI_dynstr_appendf(dynstr, i?", %g":"%g", RNA_property_float_get_index(ptr, prop, i));
                        }
+                       if(len==1)
+                               BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
                        BLI_dynstr_append(dynstr, ")");
                }
                break;
@@ -2787,20 +2795,17 @@ const struct ListBase *RNA_function_defined_parameters(FunctionRNA *func)
 
 /* Utility */
 
-ParameterList *RNA_parameter_list_create(PointerRNA *ptr, FunctionRNA *func)
+ParameterList *RNA_parameter_list_create(ParameterList *parms, PointerRNA *ptr, FunctionRNA *func)
 {
-       ParameterList *parms;
        PropertyRNA *parm;
-       int tot;
-
-       parms= MEM_callocN(sizeof(ParameterList), "ParameterList");
+       int tot= 0;
 
-       parm= func->cont.properties.first;
-       for(tot= 0; parm; parm= parm->next)
+       for(parm= func->cont.properties.first; parm; parm= parm->next)
                tot+= rna_parameter_size(parm);
 
        parms->data= MEM_callocN(tot, "RNA_parameter_list_create");
        parms->func= func;
+       parms->tot= tot;
 
        return parms;
 }
@@ -2827,8 +2832,11 @@ void RNA_parameter_list_free(ParameterList *parms)
        parms->data= NULL;
 
        parms->func= NULL;
+}
 
-       MEM_freeN(parms);
+int  RNA_parameter_list_size(ParameterList *parms)
+{
+       return parms->tot;
 }
 
 void RNA_parameter_list_begin(ParameterList *parms, ParameterIterator *iter)
@@ -3146,7 +3154,7 @@ static int rna_function_parameter_parse(PointerRNA *ptr, PropertyRNA *prop, Prop
 int RNA_function_call_direct_va(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, const char *format, va_list args)
 {
        PointerRNA funcptr;
-       ParameterList *parms;
+       ParameterList parms;
        ParameterIterator iter;
        PropertyRNA *pret, *parm;
        PropertyType type;
@@ -3162,8 +3170,8 @@ int RNA_function_call_direct_va(bContext *C, ReportList *reports, PointerRNA *pt
        pret= RNA_function_return(func);
        flen= strlen(format);
 
-       parms= RNA_parameter_list_create(ptr, func);
-       RNA_parameter_list_begin(parms, &iter);
+       RNA_parameter_list_create(&parms, ptr, func);
+       RNA_parameter_list_begin(&parms, &iter);
 
        for(i= 0, ofs= 0; iter.valid; RNA_parameter_list_next(&iter), i++) {
                parm= iter.parm;
@@ -3245,7 +3253,7 @@ int RNA_function_call_direct_va(bContext *C, ReportList *reports, PointerRNA *pt
        }
 
        if (err==0)
-               err= RNA_function_call(C, reports, ptr, func, parms);
+               err= RNA_function_call(C, reports, ptr, func, &parms);
 
        /* XXX throw error when more parameters than those needed are passed or leave silent? */
        if (err==0 && pret && ofs<flen && format[ofs++]=='R') {
@@ -3307,7 +3315,7 @@ int RNA_function_call_direct_va(bContext *C, ReportList *reports, PointerRNA *pt
        }
 
        RNA_parameter_list_end(&iter);
-       RNA_parameter_list_free(parms);
+       RNA_parameter_list_free(&parms);
 
        return err;
 }