Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-07-17 06:31:28 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-07-17 06:31:28 +0400
commit70f6255433fcb1f5551199ef7a285a9ab80a3318 (patch)
tree1471a4451ee14d5b29ed37e2dc86300b01180698 /source/blender/makesrna/intern
parentc6c853d88a9c5ff12b7a56e4bdaca1757f160997 (diff)
bpy rna
Calling rna functions with invalid keywords, too many keywords and too many args would fail silently - now raise an error with invalid keywords and a list of valid ones, raise an error when too many args are given. - calling rna functions would alloc a ParameterList each time, changed to use a stack variable (2 pointers and an int). - store the number of parameters ParameterList - python exception types were wrong in many cases, (using attribute error rather then type error) - fixes to small errors in python UI scripts.
Diffstat (limited to 'source/blender/makesrna/intern')
-rw-r--r--source/blender/makesrna/intern/rna_access.c40
-rw-r--r--source/blender/makesrna/intern/rna_internal_types.h8
-rw-r--r--source/blender/makesrna/intern/rna_ui.c64
3 files changed, 53 insertions, 59 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 838592562b3..b55df31640f 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -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
@@ -2787,20 +2789,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;
}
@@ -2822,8 +2821,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)
@@ -3141,7 +3143,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;
@@ -3157,8 +3159,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;
@@ -3240,7 +3242,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') {
@@ -3302,7 +3304,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;
}
diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h
index b63e347e165..12bd876ce52 100644
--- a/source/blender/makesrna/intern/rna_internal_types.h
+++ b/source/blender/makesrna/intern/rna_internal_types.h
@@ -88,14 +88,6 @@ typedef struct ContainerRNA {
ListBase properties;
} ContainerRNA;
-struct ParameterList {
- /* storage for parameters */
- void *data;
-
- /* function passed at creation time */
- FunctionRNA *func;
-};
-
struct FunctionRNA {
/* structs are containers of properties */
ContainerRNA cont;
diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c
index b10ca6c5e83..217f1ea00a8 100644
--- a/source/blender/makesrna/intern/rna_ui.c
+++ b/source/blender/makesrna/intern/rna_ui.c
@@ -76,7 +76,7 @@ static ARegionType *region_type_find(ReportList *reports, int space_type, int re
static int panel_poll(const bContext *C, PanelType *pt)
{
PointerRNA ptr;
- ParameterList *list;
+ ParameterList list;
FunctionRNA *func;
void *ret;
int visible;
@@ -84,14 +84,14 @@ static int panel_poll(const bContext *C, PanelType *pt)
RNA_pointer_create(NULL, pt->py_srna, NULL, &ptr); /* dummy */
func= RNA_struct_find_function(&ptr, "poll");
- list= RNA_parameter_list_create(&ptr, func);
- RNA_parameter_set_lookup(list, "context", &C);
- pt->py_call(&ptr, func, list);
+ RNA_parameter_list_create(&list, &ptr, func);
+ RNA_parameter_set_lookup(&list, "context", &C);
+ pt->py_call(&ptr, func, &list);
- RNA_parameter_get_lookup(list, "visible", &ret);
+ RNA_parameter_get_lookup(&list, "visible", &ret);
visible= *(int*)ret;
- RNA_parameter_list_free(list);
+ RNA_parameter_list_free(&list);
return visible;
}
@@ -99,33 +99,33 @@ static int panel_poll(const bContext *C, PanelType *pt)
static void panel_draw(const bContext *C, Panel *pnl)
{
PointerRNA ptr;
- ParameterList *list;
+ ParameterList list;
FunctionRNA *func;
RNA_pointer_create(&CTX_wm_screen(C)->id, pnl->type->py_srna, pnl, &ptr);
func= RNA_struct_find_function(&ptr, "draw");
- list= RNA_parameter_list_create(&ptr, func);
- RNA_parameter_set_lookup(list, "context", &C);
- pnl->type->py_call(&ptr, func, list);
+ RNA_parameter_list_create(&list, &ptr, func);
+ RNA_parameter_set_lookup(&list, "context", &C);
+ pnl->type->py_call(&ptr, func, &list);
- RNA_parameter_list_free(list);
+ RNA_parameter_list_free(&list);
}
static void panel_draw_header(const bContext *C, Panel *pnl)
{
PointerRNA ptr;
- ParameterList *list;
+ ParameterList list;
FunctionRNA *func;
RNA_pointer_create(&CTX_wm_screen(C)->id, pnl->type->py_srna, pnl, &ptr);
func= RNA_struct_find_function(&ptr, "draw_header");
- list= RNA_parameter_list_create(&ptr, func);
- RNA_parameter_set_lookup(list, "context", &C);
- pnl->type->py_call(&ptr, func, list);
+ RNA_parameter_list_create(&list, &ptr, func);
+ RNA_parameter_set_lookup(&list, "context", &C);
+ pnl->type->py_call(&ptr, func, &list);
- RNA_parameter_list_free(list);
+ RNA_parameter_list_free(&list);
}
static void rna_Panel_unregister(const bContext *C, StructRNA *type)
@@ -210,17 +210,17 @@ static StructRNA* rna_Panel_refine(struct PointerRNA *ptr)
static void header_draw(const bContext *C, Header *hdr)
{
PointerRNA htr;
- ParameterList *list;
+ ParameterList list;
FunctionRNA *func;
RNA_pointer_create(&CTX_wm_screen(C)->id, hdr->type->py_srna, hdr, &htr);
func= RNA_struct_find_function(&htr, "draw");
- list= RNA_parameter_list_create(&htr, func);
- RNA_parameter_set_lookup(list, "context", &C);
- hdr->type->py_call(&htr, func, list);
+ RNA_parameter_list_create(&list, &htr, func);
+ RNA_parameter_set_lookup(&list, "context", &C);
+ hdr->type->py_call(&htr, func, &list);
- RNA_parameter_list_free(list);
+ RNA_parameter_list_free(&list);
}
static void rna_Header_unregister(const bContext *C, StructRNA *type)
@@ -301,7 +301,7 @@ static StructRNA* rna_Header_refine(struct PointerRNA *htr)
static int menu_poll(const bContext *C, MenuType *pt)
{
PointerRNA ptr;
- ParameterList *list;
+ ParameterList list;
FunctionRNA *func;
void *ret;
int visible;
@@ -309,14 +309,14 @@ static int menu_poll(const bContext *C, MenuType *pt)
RNA_pointer_create(NULL, pt->py_srna, NULL, &ptr); /* dummy */
func= RNA_struct_find_function(&ptr, "poll");
- list= RNA_parameter_list_create(&ptr, func);
- RNA_parameter_set_lookup(list, "context", &C);
- pt->py_call(&ptr, func, list);
+ RNA_parameter_list_create(&list, &ptr, func);
+ RNA_parameter_set_lookup(&list, "context", &C);
+ pt->py_call(&ptr, func, &list);
- RNA_parameter_get_lookup(list, "visible", &ret);
+ RNA_parameter_get_lookup(&list, "visible", &ret);
visible= *(int*)ret;
- RNA_parameter_list_free(list);
+ RNA_parameter_list_free(&list);
return visible;
}
@@ -324,17 +324,17 @@ static int menu_poll(const bContext *C, MenuType *pt)
static void menu_draw(const bContext *C, Menu *hdr)
{
PointerRNA mtr;
- ParameterList *list;
+ ParameterList list;
FunctionRNA *func;
RNA_pointer_create(&CTX_wm_screen(C)->id, hdr->type->py_srna, hdr, &mtr);
func= RNA_struct_find_function(&mtr, "draw");
- list= RNA_parameter_list_create(&mtr, func);
- RNA_parameter_set_lookup(list, "context", &C);
- hdr->type->py_call(&mtr, func, list);
+ RNA_parameter_list_create(&list, &mtr, func);
+ RNA_parameter_set_lookup(&list, "context", &C);
+ hdr->type->py_call(&mtr, func, &list);
- RNA_parameter_list_free(list);
+ RNA_parameter_list_free(&list);
}
static void rna_Menu_unregister(const bContext *C, StructRNA *type)