diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-01-05 17:49:08 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-01-05 17:49:08 +0300 |
commit | 978bc0d8ace0ea10339afb25b50ef396e9cc1c8d (patch) | |
tree | 439e1df1c4af7367eda88f326416cd622043e703 /source/blender/makesrna/intern | |
parent | 26024445ac8a4af76d6399fbb896772d26a65ddf (diff) |
fix for py/rna mesh.materials[:] where empty materials exist, would raise a runtime exception.
problem was there was no way to tell the difference between getting an empty item from a collection or the item not being found.
Diffstat (limited to 'source/blender/makesrna/intern')
-rw-r--r-- | source/blender/makesrna/intern/makesrna.c | 12 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 6 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_internal.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_internal_types.h | 4 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_pose.c | 12 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_rna.c | 45 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_scene.c | 7 |
7 files changed, 47 insertions, 41 deletions
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 6fbaa76e9df..9be61cdb8dd 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -965,16 +965,16 @@ static char *rna_def_property_lookup_int_func(FILE *f, StructRNA *srna, Property func= rna_alloc_function_name(srna->identifier, prop->identifier, "lookup_int"); - fprintf(f, "PointerRNA %s(PointerRNA *ptr, int index)\n", func); + fprintf(f, "int %s(PointerRNA *ptr, int index, PointerRNA *r_ptr)\n", func); fprintf(f, "{\n"); if(manualfunc) { - fprintf(f, "\n return %s(ptr, index);\n", manualfunc); + fprintf(f, "\n return %s(ptr, index, r_ptr);\n", manualfunc); fprintf(f, "}\n\n"); return func; } - fprintf(f, " PointerRNA r_ptr;\n"); + fprintf(f, " int found= FALSE;\n"); fprintf(f, " CollectionPropertyIterator iter;\n\n"); fprintf(f, " %s_%s_begin(&iter, ptr);\n\n", srna->identifier, prop->identifier); @@ -998,6 +998,7 @@ static char *rna_def_property_lookup_int_func(FILE *f, StructRNA *srna, Property fprintf(f, " }\n"); fprintf(f, " else {\n"); fprintf(f, " internal->ptr += internal->itemsize*index;\n"); + fprintf(f, " found= TRUE;\n"); fprintf(f, " }\n"); } else if(strcmp(nextfunc, "rna_iterator_listbase_next") == 0) { @@ -1013,14 +1014,15 @@ static char *rna_def_property_lookup_int_func(FILE *f, StructRNA *srna, Property fprintf(f, " while(index-- > 0 && internal->link)\n"); fprintf(f, " internal->link= internal->link->next;\n"); fprintf(f, " }\n"); + fprintf(f, " found= (index == -1);\n"); } fprintf(f, " }\n\n"); - fprintf(f, " r_ptr = %s_%s_get(&iter);\n", srna->identifier, prop->identifier); + fprintf(f, " if(found) *r_ptr = %s_%s_get(&iter);\n", srna->identifier, prop->identifier); fprintf(f, " %s_%s_end(&iter);\n\n", srna->identifier, prop->identifier); - fprintf(f, " return r_ptr;\n"); + fprintf(f, " return found;\n"); #if 0 rna_print_data_get(f, dp); diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 23b96926fc0..ce80bb6c6ed 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -2302,8 +2302,7 @@ int RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int k if(cprop->lookupint) { /* we have a callback defined, use it */ - *r_ptr= cprop->lookupint(ptr, key); - return (r_ptr->data != NULL); + return cprop->lookupint(ptr, key, r_ptr); } else { /* no callback defined, just iterate and find the nth item */ @@ -2332,8 +2331,7 @@ int RNA_property_collection_lookup_string(PointerRNA *ptr, PropertyRNA *prop, co if(cprop->lookupstring) { /* we have a callback defined, use it */ - *r_ptr= cprop->lookupstring(ptr, key); - return (r_ptr->data != NULL); + return cprop->lookupstring(ptr, key, r_ptr); } else { /* no callback defined, compare with name properties if they exist */ diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index 90c5a555221..39f12c56e1c 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -301,7 +301,7 @@ void rna_builtin_properties_begin(struct CollectionPropertyIterator *iter, struc void rna_builtin_properties_next(struct CollectionPropertyIterator *iter); PointerRNA rna_builtin_properties_get(struct CollectionPropertyIterator *iter); PointerRNA rna_builtin_type_get(struct PointerRNA *ptr); -PointerRNA rna_builtin_properties_lookup_string(PointerRNA *ptr, const char *key); +int rna_builtin_properties_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr); /* Iterators */ diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h index 216533a8708..ee484c27c03 100644 --- a/source/blender/makesrna/intern/rna_internal_types.h +++ b/source/blender/makesrna/intern/rna_internal_types.h @@ -93,8 +93,8 @@ typedef void (*PropCollectionNextFunc)(struct CollectionPropertyIterator *iter); typedef void (*PropCollectionEndFunc)(struct CollectionPropertyIterator *iter); typedef PointerRNA (*PropCollectionGetFunc)(struct CollectionPropertyIterator *iter); typedef int (*PropCollectionLengthFunc)(struct PointerRNA *ptr); -typedef PointerRNA (*PropCollectionLookupIntFunc)(struct PointerRNA *ptr, int key); -typedef PointerRNA (*PropCollectionLookupStringFunc)(struct PointerRNA *ptr, const char *key); +typedef int (*PropCollectionLookupIntFunc)(struct PointerRNA *ptr, int key, struct PointerRNA *r_ptr); +typedef int (*PropCollectionLookupStringFunc)(struct PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr); /* Container - generic abstracted container of RNA properties */ typedef struct ContainerRNA { diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c index 51a44c027e4..7b1a46dd6e2 100644 --- a/source/blender/makesrna/intern/rna_pose.c +++ b/source/blender/makesrna/intern/rna_pose.c @@ -547,13 +547,17 @@ static int rna_PoseChannel_rotation_4d_editable(PointerRNA *ptr, int index) } /* not essential, but much faster then the default lookup function */ -PointerRNA rna_PoseBones_lookup_string(PointerRNA *ptr, const char *key) +int rna_PoseBones_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr) { - PointerRNA rptr; bPose *pose= (bPose*)ptr->data; bPoseChannel *pchan= get_pose_channel(pose, key); - RNA_pointer_create(ptr->id.data, &RNA_PoseBone, pchan, &rptr); - return rptr; + if(pchan) { + RNA_pointer_create(ptr->id.data, &RNA_PoseBone, pchan, r_ptr); + return TRUE; + } + else { + return FALSE; + } } static void rna_PoseChannel_matrix_basis_get(PointerRNA *ptr, float *values) diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index 9e04132eaba..9158f0c3e68 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -300,7 +300,7 @@ PointerRNA rna_builtin_properties_get(CollectionPropertyIterator *iter) return rna_Struct_properties_get(iter); } -PointerRNA rna_builtin_properties_lookup_string(PointerRNA *ptr, const char *key) +int rna_builtin_properties_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr) { StructRNA *srna; PropertyRNA *prop; @@ -315,7 +315,9 @@ PointerRNA rna_builtin_properties_lookup_string(PointerRNA *ptr, const char *key if(prop) { propptr.type= &RNA_Property; propptr.data= prop; - return propptr; + + *r_ptr= propptr; + return TRUE; } } @@ -323,7 +325,9 @@ PointerRNA rna_builtin_properties_lookup_string(PointerRNA *ptr, const char *key if(!(prop->flag & PROP_BUILTIN) && strcmp(prop->identifier, key)==0) { propptr.type= &RNA_Property; propptr.data= prop; - return propptr; + + *r_ptr= propptr; + return TRUE; } } } while((srna=srna->base)); @@ -342,13 +346,15 @@ PointerRNA rna_builtin_properties_lookup_string(PointerRNA *ptr, const char *key if(strcmp(idp->name, key) == 0) { propptr.type= &RNA_Property; propptr.data= idp; - return propptr; + + *r_ptr= propptr; + return TRUE; } } } } #endif - return propptr; + return FALSE; } PointerRNA rna_builtin_type_get(PointerRNA *ptr) @@ -842,34 +848,29 @@ static int rna_BlenderRNA_structs_length(PointerRNA *ptr) { return BLI_countlist(&((BlenderRNA*)ptr->data)->structs); } -static PointerRNA rna_BlenderRNA_structs_lookup_int(PointerRNA *ptr, int index) +static int rna_BlenderRNA_structs_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr) { StructRNA *srna= BLI_findlink(&((BlenderRNA*)ptr->data)->structs, index); if(srna) { - PointerRNA r_ptr; - RNA_pointer_create(NULL, &RNA_Struct, srna, &r_ptr); - return r_ptr; + RNA_pointer_create(NULL, &RNA_Struct, srna, r_ptr); + return TRUE; } else { - return PointerRNA_NULL; + return FALSE; } } -static PointerRNA rna_BlenderRNA_structs_lookup_string(PointerRNA *ptr, const char *key) +static int rna_BlenderRNA_structs_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr) { StructRNA *srna= ((BlenderRNA*)ptr->data)->structs.first; - for(; srna; srna=srna->cont.next) - if(key[0] == srna->identifier[0] && strcmp(key, srna->identifier)==0) - break; - - if(srna) { - PointerRNA r_ptr; - RNA_pointer_create(NULL, &RNA_Struct, srna, &r_ptr); - return r_ptr; - } - else { - return PointerRNA_NULL; + for(; srna; srna=srna->cont.next) { + if(key[0] == srna->identifier[0] && strcmp(key, srna->identifier)==0) { + RNA_pointer_create(NULL, &RNA_Struct, srna, r_ptr); + return TRUE; + } } + + return FALSE; } diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 43b78dc7ecf..68345efa9e4 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -182,18 +182,19 @@ EnumPropertyItem image_type_items[] = { #include "RE_pipeline.h" -static PointerRNA rna_Scene_object_bases_lookup_string(PointerRNA *ptr, const char *key) +static int rna_Scene_object_bases_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr) { Scene *scene= (Scene*)ptr->data; Base *base; for(base= scene->base.first; base; base= base->next) { if(strncmp(base->object->id.name+2, key, sizeof(base->object->id.name)-2)==0) { - return rna_pointer_inherit_refine(ptr, &RNA_ObjectBase, base); + *r_ptr= rna_pointer_inherit_refine(ptr, &RNA_ObjectBase, base); + return TRUE; } } - return PointerRNA_NULL; + return FALSE; } static PointerRNA rna_Scene_objects_get(CollectionPropertyIterator *iter) |