RNA & PyAPI
authorCampbell Barton <ideasman42@gmail.com>
Mon, 13 Jul 2009 19:33:59 +0000 (19:33 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 13 Jul 2009 19:33:59 +0000 (19:33 +0000)
* support for dynamic enums to be inspected enumProp.items() from python.
* fix, enums check for a separator was flipped, meant no enums were in docs.
* dynamic enum functions now check for a NULL context and return all possible options for the "items" attribute used for docs.
* added an arg for rna arrays to free the array there looping over (needed to free dynamically allocated enum items)
* python api checks for NULL items since this can happen in some cases.
* python api, When getting an enum ID from an int in an array - If it failed it would get the first enum identifier and return that. Brecht? dont understand, making it return an empty string in these cases.

21 files changed:
source/blender/editors/mesh/editmesh_mods.c
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/transform/transform_orientations.c
source/blender/makesrna/intern/makesrna.c
source/blender/makesrna/intern/rna_access.c
source/blender/makesrna/intern/rna_brush.c
source/blender/makesrna/intern/rna_color.c
source/blender/makesrna/intern/rna_constraint.c
source/blender/makesrna/intern/rna_curve.c
source/blender/makesrna/intern/rna_internal.h
source/blender/makesrna/intern/rna_key.c
source/blender/makesrna/intern/rna_lamp.c
source/blender/makesrna/intern/rna_lattice.c
source/blender/makesrna/intern/rna_material.c
source/blender/makesrna/intern/rna_mesh.c
source/blender/makesrna/intern/rna_modifier.c
source/blender/makesrna/intern/rna_particle.c
source/blender/makesrna/intern/rna_rna.c
source/blender/makesrna/intern/rna_space.c
source/blender/makesrna/intern/rna_world.c
source/blender/python/intern/bpy_rna.c

index 2995e2d895bb37b1539032373c8170dba3a23080..5fc2ce467921a9299bd222d5bc5df9ff57996a77 100644 (file)
@@ -1229,12 +1229,25 @@ static int select_similar_exec(bContext *C, wmOperator *op)
 
 static EnumPropertyItem *select_similar_type_itemf(bContext *C, PointerRNA *ptr, int *free)
 {
-       Object *obedit= CTX_data_edit_object(C);
-
+       Object *obedit;
+       EnumPropertyItem *item= NULL;
+       int totitem= 0;
+       
+       if(C==NULL) {
+               /* needed for doc generation */
+               RNA_enum_items_add(&item, &totitem, prop_simvertex_types);
+               RNA_enum_items_add(&item, &totitem, prop_simedge_types);
+               RNA_enum_items_add(&item, &totitem, prop_simface_types);
+               RNA_enum_item_end(&item, &totitem);
+               *free= 1;
+               
+               return item;
+       }
+       
+       obedit= CTX_data_edit_object(C);
+       
        if(obedit && obedit->type == OB_MESH) {
                EditMesh *em= BKE_mesh_get_editmesh(obedit->data); 
-               EnumPropertyItem *item= NULL;
-               int totitem= 0;
 
                if(em->selectmode & SCE_SELECT_VERTEX)
                        RNA_enum_items_add(&item, &totitem, prop_simvertex_types);
@@ -1248,7 +1261,7 @@ static EnumPropertyItem *select_similar_type_itemf(bContext *C, PointerRNA *ptr,
 
                return item;
        }
-
+       
        return NULL;
 }
 
index eab06444a79326fa22e5d21ffddd3b1d4dc957ab..efb68f69dac8eba4862407e0b615f33dba1be419 100644 (file)
@@ -5795,13 +5795,24 @@ static EnumPropertyItem merge_type_items[]= {
        {0, NULL, 0, NULL, NULL}};
 
 static EnumPropertyItem *merge_type_itemf(bContext *C, PointerRNA *ptr, int *free)
-{
-       Object *obedit= CTX_data_edit_object(C);
-
+{      
+       EnumPropertyItem *item= NULL;
+       int totitem= 0;
+       
+       Object *obedit;
+       
+       if(C==NULL) {
+               /* needed for doc generation */
+               RNA_enum_items_add(&item, &totitem, merge_type_items);
+               RNA_enum_item_end(&item, &totitem);
+               
+               *free= 1;
+               return item;
+       }
+       
+       obedit= CTX_data_edit_object(C);
        if(obedit && obedit->type == OB_MESH) {
                EditMesh *em= BKE_mesh_get_editmesh(obedit->data);
-               EnumPropertyItem *item= NULL;
-               int totitem= 0;
 
                if(em->selectmode & SCE_SELECT_VERTEX) {
                        if(em->selected.first && em->selected.last &&
@@ -5824,7 +5835,7 @@ static EnumPropertyItem *merge_type_itemf(bContext *C, PointerRNA *ptr, int *fre
 
                return item;
        }
-
+       
        return NULL;
 }
 
index f3b373f0e48c6e06386e97b2a5d742e67522bc85..6d60c7602f41b916b09ac11947a54793212003a7 100644 (file)
@@ -358,8 +358,10 @@ void BIF_selectTransformOrientationValue(bContext *C, int orientation) {
 
 EnumPropertyItem *BIF_enumTransformOrientation(bContext *C)
 {
-       ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
-       TransformOrientation *ts = transform_spaces->first;
+       Scene *scene;
+       ListBase *transform_spaces;
+       TransformOrientation *ts= NULL;
+
        EnumPropertyItem global = {V3D_MANIP_GLOBAL, "GLOBAL", 0, "Global", ""};
        EnumPropertyItem normal = {V3D_MANIP_NORMAL, "NORMAL", 0, "Normal", ""};
        EnumPropertyItem local = {V3D_MANIP_LOCAL, "LOCAL", 0, "Local", ""};
@@ -374,6 +376,15 @@ EnumPropertyItem *BIF_enumTransformOrientation(bContext *C)
        RNA_enum_item_add(&item, &totitem, &local);
        RNA_enum_item_add(&item, &totitem, &view);
 
+       if(C) {
+               scene= CTX_data_scene(C);
+
+               if(scene) {
+                       transform_spaces = &scene->transform_spaces;
+                       ts = transform_spaces->first;
+               }
+       }
+               
        if(ts)
                RNA_enum_item_add(&item, &totitem, &sepr);
 
index 61a8f8a29e9f04bc1edd5315bf28a14371e51bf7..85c266e3f27838bc4ef70945790cec568869a4e6 100644 (file)
@@ -699,9 +699,9 @@ static char *rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA *
                }
                else {
                        if(dp->dnalengthname)
-                               fprintf(f, "\n  rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), data->%s, NULL);\n", dp->dnaname, dp->dnaname, dp->dnalengthname);
+                               fprintf(f, "\n  rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), data->%s, 0, NULL);\n", dp->dnaname, dp->dnaname, dp->dnalengthname);
                        else
-                               fprintf(f, "\n  rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), %d, NULL);\n", dp->dnaname, dp->dnaname, dp->dnalengthfixed);
+                               fprintf(f, "\n  rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), %d, 0, NULL);\n", dp->dnaname, dp->dnaname, dp->dnalengthfixed);
                }
        }
        else {
index d6ca03c85a229ac4c5fcadb82dc6a96833122ff6..e504d1d030b4ff139072f3270fffdee19aabe753 100644 (file)
@@ -643,15 +643,18 @@ StructRNA *RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop)
 void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, EnumPropertyItem **item, int *totitem, int *free)
 {
        EnumPropertyRNA *eprop= (EnumPropertyRNA*)rna_ensure_property(prop);
-       int tot;
 
        *free= 0;
 
-       if(C && eprop->itemf) {
+       if(eprop->itemf) {
+               int tot= 0;
                *item= eprop->itemf(C, ptr, free);
 
                if(totitem) {
-                       for(tot=0; (*item)[tot].identifier; tot++);
+                       if(*item) {
+                               for( ; (*item)[tot].identifier; tot++);
+                       }
+
                        *totitem= tot;
                }
        }
@@ -710,11 +713,14 @@ int RNA_property_enum_identifier(bContext *C, PointerRNA *ptr, PropertyRNA *prop
        int result, free;
        
        RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
-       result= RNA_enum_identifier(item, value, identifier);
-       if(free)
-               MEM_freeN(item);
+       if(item) {
+               result= RNA_enum_identifier(item, value, identifier);
+               if(free)
+                       MEM_freeN(item);
 
-       return result;
+               return result;
+       }
+       return 0;
 }
 
 const char *RNA_property_ui_name(PropertyRNA *prop)
@@ -1303,9 +1309,9 @@ void RNA_property_collection_begin(PointerRNA *ptr, PropertyRNA *prop, Collectio
                iter->prop= prop;
 
                if(idprop)
-                       rna_iterator_array_begin(iter, IDP_IDPArray(idprop), sizeof(IDProperty), idprop->len, NULL);
+                       rna_iterator_array_begin(iter, IDP_IDPArray(idprop), sizeof(IDProperty), idprop->len, 0, NULL);
                else
-                       rna_iterator_array_begin(iter, NULL, sizeof(IDProperty), 0, NULL);
+                       rna_iterator_array_begin(iter, NULL, sizeof(IDProperty), 0, 0, NULL);
 
                if(iter->valid)
                        rna_property_collection_get_idp(iter);
@@ -1902,7 +1908,7 @@ void rna_iterator_listbase_end(CollectionPropertyIterator *iter)
        iter->internal= NULL;
 }
 
-void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int itemsize, int length, IteratorSkipFunc skip)
+void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int itemsize, int length, int free_ptr, IteratorSkipFunc skip)
 {
        ArrayIterator *internal;
 
@@ -1911,6 +1917,7 @@ void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int i
 
        internal= MEM_callocN(sizeof(ArrayIterator), "ArrayIterator");
        internal->ptr= ptr;
+       internal->free_ptr= free_ptr ? ptr:NULL;
        internal->endptr= ((char*)ptr)+length*itemsize;
        internal->itemsize= itemsize;
        internal->skip= skip;
@@ -1955,6 +1962,11 @@ void *rna_iterator_array_dereference_get(CollectionPropertyIterator *iter)
 
 void rna_iterator_array_end(CollectionPropertyIterator *iter)
 {
+       ArrayIterator *internal= iter->internal;
+       
+       if(internal->free_ptr)
+               MEM_freeN(internal->free_ptr);
+
        MEM_freeN(iter->internal);
        iter->internal= NULL;
 }
index 7355261c5aa80aeddad3a32443608eefc25d973a..3b7df3aa9480294115c0d1c7110352c0359031ab 100644 (file)
@@ -37,7 +37,7 @@
 static void rna_Brush_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
 {
        Brush *brush= (Brush*)ptr->data;
-       rna_iterator_array_begin(iter, (void*)brush->mtex, sizeof(MTex*), MAX_MTEX, NULL);
+       rna_iterator_array_begin(iter, (void*)brush->mtex, sizeof(MTex*), MAX_MTEX, 0, NULL);
 }
 
 static PointerRNA rna_Brush_active_texture_get(PointerRNA *ptr)
index 179808ab66dcdb5c4e2e3cc1c57d94c5ac14ef31..f4248d18db38c769bf8abf83de6e943e27fca3e1 100644 (file)
@@ -50,7 +50,7 @@ static void rna_CurveMapping_curves_begin(CollectionPropertyIterator *iter, Poin
 {
        CurveMapping *cumap= (CurveMapping*)ptr->data;
 
-       rna_iterator_array_begin(iter, cumap->cm, sizeof(CurveMap), rna_CurveMapping_curves_length(ptr), NULL);
+       rna_iterator_array_begin(iter, cumap->cm, sizeof(CurveMap), rna_CurveMapping_curves_length(ptr), 0, NULL);
 }
 
 static void rna_CurveMapping_clip_set(PointerRNA *ptr, int value)
index 56c0ca1b491aca344a0682cebc68802680d05ab2..0e3dd79961251382382588fa6d9e421fc98bcf89 100644 (file)
@@ -181,6 +181,20 @@ static EnumPropertyItem *rna_Constraint_owner_space_itemf(bContext *C, PointerRN
 {
        Object *ob= (Object*)ptr->id.data;
        bConstraint *con= (bConstraint*)ptr->data;
+       
+       if(C==NULL) {
+               EnumPropertyItem *item= NULL;
+               int totitem= 0;
+               
+               /* needed for doc generation */
+               RNA_enum_items_add(&item, &totitem, space_object_items);
+               RNA_enum_items_add(&item, &totitem, space_pchan_items);
+               RNA_enum_item_end(&item, &totitem);
+               
+               *free= 1;
+               
+               return item;
+       }
 
        if(BLI_findindex(&ob->constraints, con) == -1)
                return space_pchan_items;
@@ -195,6 +209,20 @@ static EnumPropertyItem *rna_Constraint_target_space_itemf(bContext *C, PointerR
        ListBase targets = {NULL, NULL};
        bConstraintTarget *ct;
        
+       if(C==NULL) {
+               EnumPropertyItem *item= NULL;
+               int totitem= 0;
+               
+               /* needed for doc generation */
+               RNA_enum_items_add(&item, &totitem, space_object_items);
+               RNA_enum_items_add(&item, &totitem, space_pchan_items);
+               RNA_enum_item_end(&item, &totitem);
+               
+               *free= 1;
+               
+               return item;
+       }
+       
        if(cti && cti->get_constraint_targets) {
                cti->get_constraint_targets(con, &targets);
                
index 5c9da19f9b2e73511a7f13d8348f1bfa2889c813..faf6c3a1f753d9a834174058382c4345cbb1a562 100644 (file)
@@ -139,7 +139,7 @@ static int rna_Nurb_length(PointerRNA *ptr)
 static void rna_BPoint_array_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
 {
        Nurb *nu= (Nurb*)ptr->data;
-       rna_iterator_array_begin(iter, (void*)nu->bp, sizeof(BPoint*), nu->pntsv>0 ? nu->pntsu*nu->pntsv : nu->pntsu, NULL);
+       rna_iterator_array_begin(iter, (void*)nu->bp, sizeof(BPoint*), nu->pntsv>0 ? nu->pntsu*nu->pntsv : nu->pntsu, 0, NULL);
 }
 
 #else
index 6a5d5ccfdc3222d4358fd4bbb3ffbb79e947d89c..ad0e05b91a67d45a14e8c868dcf22364f5f72227 100644 (file)
@@ -240,11 +240,12 @@ void rna_iterator_listbase_end(struct CollectionPropertyIterator *iter);
 typedef struct ArrayIterator {
        char *ptr;
        char *endptr;
+       void *free_ptr; /* will be free'd if set */
        int itemsize;
        IteratorSkipFunc skip;
 } ArrayIterator;
 
-void rna_iterator_array_begin(struct CollectionPropertyIterator *iter, void *ptr, int itemsize, int length, IteratorSkipFunc skip);
+void rna_iterator_array_begin(struct CollectionPropertyIterator *iter, void *ptr, int itemsize, int length, int free_ptr, IteratorSkipFunc skip);
 void rna_iterator_array_next(struct CollectionPropertyIterator *iter);
 void *rna_iterator_array_get(struct CollectionPropertyIterator *iter);
 void *rna_iterator_array_dereference_get(struct CollectionPropertyIterator *iter);
index 0a7e989a93aaf278da665970d830bbcfe965f00e..7297ee8cb975d8a453bb6d170ea8596856cbac9f 100644 (file)
@@ -198,7 +198,7 @@ static void rna_ShapeKey_data_begin(CollectionPropertyIterator *iter, PointerRNA
                }
        }
 
-       rna_iterator_array_begin(iter, (void*)kb->data, size, tot, NULL);
+       rna_iterator_array_begin(iter, (void*)kb->data, size, tot, 0, NULL);
 }
 
 static int rna_ShapeKey_data_length(PointerRNA *ptr)
index a49b4377d9db00733e7dcc07d45acd505d07e3bd..e592cb386933c2c03ce2c606d40a374d31b6245d 100644 (file)
@@ -54,7 +54,7 @@ static PointerRNA rna_Lamp_sky_settings_get(PointerRNA *ptr)
 static void rna_Lamp_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
 {
        Lamp *la= (Lamp*)ptr->data;
-       rna_iterator_array_begin(iter, (void*)la->mtex, sizeof(MTex*), MAX_MTEX, NULL);
+       rna_iterator_array_begin(iter, (void*)la->mtex, sizeof(MTex*), MAX_MTEX, 0, NULL);
 }
 
 static PointerRNA rna_Lamp_active_texture_get(PointerRNA *ptr)
index c685e5b691292b2d950b62fb741c9c55f3f26138..03a1dc9ec8f3b157cd91ce06fe3a23bda5eff15b 100644 (file)
@@ -68,10 +68,10 @@ static void rna_LatticePoint_groups_begin(CollectionPropertyIterator *iter, Poin
                BPoint *bp= (BPoint*)ptr->data;
                MDeformVert *dvert= lt->dvert + (bp-lt->def);
 
-               rna_iterator_array_begin(iter, (void*)dvert->dw, sizeof(MDeformWeight), dvert->totweight, NULL);
+               rna_iterator_array_begin(iter, (void*)dvert->dw, sizeof(MDeformWeight), dvert->totweight, 0, NULL);
        }
        else
-               rna_iterator_array_begin(iter, NULL, 0, 0, NULL);
+               rna_iterator_array_begin(iter, NULL, 0, 0, 0, NULL);
 }
 
 static void rna_Lattice_points_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
@@ -80,11 +80,11 @@ static void rna_Lattice_points_begin(CollectionPropertyIterator *iter, PointerRN
        int tot= lt->pntsu*lt->pntsv*lt->pntsw;
 
        if(lt->editlatt && lt->editlatt->def)
-               rna_iterator_array_begin(iter, (void*)lt->editlatt->def, sizeof(BPoint), tot, NULL);
+               rna_iterator_array_begin(iter, (void*)lt->editlatt->def, sizeof(BPoint), tot, 0, NULL);
        else if(lt->def)
-               rna_iterator_array_begin(iter, (void*)lt->def, sizeof(BPoint), tot, NULL);
+               rna_iterator_array_begin(iter, (void*)lt->def, sizeof(BPoint), tot, 0, NULL);
        else
-               rna_iterator_array_begin(iter, NULL, 0, 0, NULL);
+               rna_iterator_array_begin(iter, NULL, 0, 0, 0, NULL);
 }
 
 static void rna_Lattice_update_data(bContext *C, PointerRNA *ptr)
index 41f31594f6e1a5e0103d257b26e4708b8c776288..17c910887612e75399efb798429f1d47ab0df497 100644 (file)
@@ -75,7 +75,7 @@ static void rna_Material_type_set(PointerRNA *ptr, int value)
 static void rna_Material_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
 {
        Material *ma= (Material*)ptr->data;
-       rna_iterator_array_begin(iter, (void*)ma->mtex, sizeof(MTex*), MAX_MTEX, NULL);
+       rna_iterator_array_begin(iter, (void*)ma->mtex, sizeof(MTex*), MAX_MTEX, 0, NULL);
 }
 
 static PointerRNA rna_Material_active_texture_get(PointerRNA *ptr)
index b69a804cf6ab7feda3cccd372e11aca792fdf241..3a7015b65be335869b72b6e01118efa4c808865c 100644 (file)
@@ -197,10 +197,10 @@ static void rna_MeshVertex_groups_begin(CollectionPropertyIterator *iter, Pointe
                MVert *mvert= (MVert*)ptr->data;
                MDeformVert *dvert= me->dvert + (mvert-me->mvert);
 
-               rna_iterator_array_begin(iter, (void*)dvert->dw, sizeof(MDeformWeight), dvert->totweight, NULL);
+               rna_iterator_array_begin(iter, (void*)dvert->dw, sizeof(MDeformWeight), dvert->totweight, 0, NULL);
        }
        else
-               rna_iterator_array_begin(iter, NULL, 0, 0, NULL);
+               rna_iterator_array_begin(iter, NULL, 0, 0, 0, NULL);
 }
 
 static void rna_MeshFace_material_index_range(PointerRNA *ptr, int *min, int *max)
@@ -262,7 +262,7 @@ static void rna_Mesh_uv_textures_begin(CollectionPropertyIterator *iter, Pointer
 {
        Mesh *me= (Mesh*)ptr->data;
        CustomData *fdata= rna_mesh_fdata(me);
-       rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, rna_uv_texture_check);
+       rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, 0, rna_uv_texture_check);
 }
 
 static int rna_Mesh_uv_textures_length(PointerRNA *ptr)
@@ -390,7 +390,7 @@ static void rna_MeshTextureFaceLayer_data_begin(CollectionPropertyIterator *iter
 {
        Mesh *me= (Mesh*)ptr->id.data;
        CustomDataLayer *layer= (CustomDataLayer*)ptr->data;
-       rna_iterator_array_begin(iter, layer->data, sizeof(MTFace), me->totface, NULL);
+       rna_iterator_array_begin(iter, layer->data, sizeof(MTFace), me->totface, 0, NULL);
 }
 
 static int rna_MeshTextureFaceLayer_data_length(PointerRNA *ptr)
@@ -437,7 +437,7 @@ static void rna_Mesh_vertex_colors_begin(CollectionPropertyIterator *iter, Point
 {
        Mesh *me= (Mesh*)ptr->data;
        CustomData *fdata= rna_mesh_fdata(me);
-       rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, rna_vertex_color_check);
+       rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, 0, rna_vertex_color_check);
 }
 
 static int rna_Mesh_vertex_colors_length(PointerRNA *ptr)
@@ -501,7 +501,7 @@ static void rna_MeshColorLayer_data_begin(CollectionPropertyIterator *iter, Poin
 {
        Mesh *me= (Mesh*)ptr->id.data;
        CustomDataLayer *layer= (CustomDataLayer*)ptr->data;
-       rna_iterator_array_begin(iter, layer->data, sizeof(MCol)*4, me->totface, NULL);
+       rna_iterator_array_begin(iter, layer->data, sizeof(MCol)*4, me->totface, 0, NULL);
 }
 
 static int rna_MeshColorLayer_data_length(PointerRNA *ptr)
@@ -542,7 +542,7 @@ static void rna_MeshFloatPropertyLayer_data_begin(CollectionPropertyIterator *it
 {
        Mesh *me= (Mesh*)ptr->id.data;
        CustomDataLayer *layer= (CustomDataLayer*)ptr->data;
-       rna_iterator_array_begin(iter, layer->data, sizeof(MFloatProperty), me->totface, NULL);
+       rna_iterator_array_begin(iter, layer->data, sizeof(MFloatProperty), me->totface, 0, NULL);
 }
 
 static int rna_MeshFloatPropertyLayer_data_length(PointerRNA *ptr)
@@ -561,7 +561,7 @@ static void rna_Mesh_float_layers_begin(CollectionPropertyIterator *iter, Pointe
 {
        Mesh *me= (Mesh*)ptr->data;
        CustomData *fdata= rna_mesh_fdata(me);
-       rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, rna_float_layer_check);
+       rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, 0, rna_float_layer_check);
 }
 
 static int rna_Mesh_float_layers_length(PointerRNA *ptr)
@@ -579,7 +579,7 @@ static void rna_MeshIntPropertyLayer_data_begin(CollectionPropertyIterator *iter
 {
        Mesh *me= (Mesh*)ptr->id.data;
        CustomDataLayer *layer= (CustomDataLayer*)ptr->data;
-       rna_iterator_array_begin(iter, layer->data, sizeof(MIntProperty), me->totface, NULL);
+       rna_iterator_array_begin(iter, layer->data, sizeof(MIntProperty), me->totface, 0, NULL);
 }
 
 static int rna_MeshIntPropertyLayer_data_length(PointerRNA *ptr)
@@ -592,7 +592,7 @@ static void rna_Mesh_int_layers_begin(CollectionPropertyIterator *iter, PointerR
 {
        Mesh *me= (Mesh*)ptr->data;
        CustomData *fdata= rna_mesh_fdata(me);
-       rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, rna_int_layer_check);
+       rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, 0, rna_int_layer_check);
 }
 
 static int rna_Mesh_int_layers_length(PointerRNA *ptr)
@@ -610,7 +610,7 @@ static void rna_MeshStringPropertyLayer_data_begin(CollectionPropertyIterator *i
 {
        Mesh *me= (Mesh*)ptr->id.data;
        CustomDataLayer *layer= (CustomDataLayer*)ptr->data;
-       rna_iterator_array_begin(iter, layer->data, sizeof(MStringProperty), me->totface, NULL);
+       rna_iterator_array_begin(iter, layer->data, sizeof(MStringProperty), me->totface, 0, NULL);
 }
 
 static int rna_MeshStringPropertyLayer_data_length(PointerRNA *ptr)
@@ -623,7 +623,7 @@ static void rna_Mesh_string_layers_begin(CollectionPropertyIterator *iter, Point
 {
        Mesh *me= (Mesh*)ptr->data;
        CustomData *fdata= rna_mesh_fdata(me);
-       rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, rna_string_layer_check);
+       rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, 0, rna_string_layer_check);
 }
 
 static int rna_Mesh_string_layers_length(PointerRNA *ptr)
index a789f9065e306c6aa3d92fc4949acaed1ab37d66..f207f4f605d0ccd62b83bb119a2ccbe35b1b529b 100644 (file)
@@ -83,7 +83,7 @@ EnumPropertyItem modifier_type_items[] ={
 static void rna_UVProject_projectors_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
 {
        UVProjectModifierData *uvp= (UVProjectModifierData*)ptr->data;
-       rna_iterator_array_begin(iter, (void*)uvp->projectors, sizeof(Object*), 10, NULL);
+       rna_iterator_array_begin(iter, (void*)uvp->projectors, sizeof(Object*), 10, 0, NULL);
 }
 
 static StructRNA* rna_Modifier_refine(struct PointerRNA *ptr)
index 3941175279285b0633eae2fcfb6e263cb000fe10..ef68e0ba01901b5abbe5e17a43eebdf9cf3aac62 100644 (file)
@@ -430,6 +430,20 @@ static EnumPropertyItem *rna_Particle_from_itemf(bContext *C, PointerRNA *ptr, i
 {
        ParticleSettings *part = ptr->id.data;
 
+       if(C==NULL) {
+               EnumPropertyItem *item= NULL;
+               int totitem= 0;
+               
+               /* needed for doc generation */
+               RNA_enum_items_add(&item, &totitem, part_reactor_from_items);
+               RNA_enum_items_add(&item, &totitem, part_from_items);
+               RNA_enum_item_end(&item, &totitem);
+               
+               *free= 1;
+               
+               return item;
+       }
+       
        if(part->type==PART_REACTOR)
                return part_reactor_from_items;
        else
@@ -440,6 +454,20 @@ static EnumPropertyItem *rna_Particle_draw_as_itemf(bContext *C, PointerRNA *ptr
 {
        ParticleSettings *part = ptr->id.data;
 
+       if(C==NULL) {
+               EnumPropertyItem *item= NULL;
+               int totitem= 0;
+               
+               /* needed for doc generation */
+               RNA_enum_items_add(&item, &totitem, part_hair_draw_as_items);
+               RNA_enum_items_add(&item, &totitem, part_draw_as_items);
+               RNA_enum_item_end(&item, &totitem);
+               
+               *free= 1;
+               
+               return item;
+       }
+       
        if(part->type==PART_HAIR)
                return part_hair_draw_as_items;
        else
@@ -450,6 +478,20 @@ static EnumPropertyItem *rna_Particle_ren_as_itemf(bContext *C, PointerRNA *ptr,
 {
        ParticleSettings *part = ptr->id.data;
 
+       if(C==NULL) {
+               EnumPropertyItem *item= NULL;
+               int totitem= 0;
+               
+               /* needed for doc generation */
+               RNA_enum_items_add(&item, &totitem, part_hair_ren_as_items);
+               RNA_enum_items_add(&item, &totitem, part_ren_as_items);
+               RNA_enum_item_end(&item, &totitem);
+               
+               *free= 1;
+               
+               return item;
+       }
+       
        if(part->type==PART_HAIR)
                return part_hair_ren_as_items;
        else
index 0b605db20cfcc0b436adf40a4676959135901599..aeaedd6f81d279cb7670920091b6d6f3420f469b 100644 (file)
@@ -520,18 +520,21 @@ static int rna_enum_check_separator(CollectionPropertyIterator *iter, void *data
 {
        EnumPropertyItem *item= (EnumPropertyItem*)data;
 
-       return (item->identifier[0] != 0);
+       return (item->identifier[0] == 0);
 }
 
 static void rna_EnumProperty_items_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
 {
        PropertyRNA *prop= (PropertyRNA*)ptr->data;
        EnumPropertyRNA *eprop;
-
+       EnumPropertyItem *item= NULL;
+       int totitem, free= 0;
+       
        rna_idproperty_check(&prop, ptr);
        eprop= (EnumPropertyRNA*)prop;
-
-       rna_iterator_array_begin(iter, (void*)eprop->item, sizeof(eprop->item[0]), eprop->totitem, rna_enum_check_separator);
+       
+       RNA_property_enum_items(NULL, ptr, prop, &item, &totitem, &free);
+       rna_iterator_array_begin(iter, (void*)item, sizeof(EnumPropertyItem), totitem, free, rna_enum_check_separator);
 }
 
 static void rna_EnumPropertyItem_identifier_get(PointerRNA *ptr, char *value)
index fa81af8f1408873a093489b133c77e6ad01a17e8..3f9b87a7f37e4a3163817b8522053bab9f230e90 100644 (file)
@@ -179,6 +179,11 @@ static EnumPropertyItem *rna_SpaceImageEditor_draw_channels_itemf(bContext *C, P
        ImBuf *ibuf= ED_space_image_buffer(sima);
        int zbuf, alpha;
 
+       if(C==NULL) {
+               /* needed for doc generation */
+               return dc_all_items;
+       }
+       
        alpha= ibuf && (ibuf->channels == 4);
        zbuf= ibuf && (ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels==1));
 
index 67328455a77507442d730da3b4863bed820bd297..9ff474b82b0c5776013389a6a00c875c51872074 100644 (file)
@@ -56,7 +56,7 @@ static PointerRNA rna_World_mist_get(PointerRNA *ptr)
 static void rna_World_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
 {
        World *wo= (World*)ptr->data;
-       rna_iterator_array_begin(iter, (void*)wo->mtex, sizeof(MTex*), MAX_MTEX, NULL);
+       rna_iterator_array_begin(iter, (void*)wo->mtex, sizeof(MTex*), MAX_MTEX, 0, NULL);
 }
 
 static PointerRNA rna_World_active_texture_get(PointerRNA *ptr)
index 49bca247431b716356cfddabdf47be56cf460ab4..9ce9ec8e838b09adbfa00b8afbe0792bcc864873 100644 (file)
@@ -225,10 +225,16 @@ static char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop)
 {
        EnumPropertyItem *item;
        char *result;
-       int free;
+       int free= 0;
        
        RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free);
-       result= (char*)BPy_enum_as_string(item);
+       if(item) {
+               result= (char*)BPy_enum_as_string(item);
+       }
+       else {
+               result= "";
+       }
+       
        if(free)
                MEM_freeN(item);
        
@@ -319,12 +325,12 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
                        ret = PyUnicode_FromString( identifier );
                } else {
                        EnumPropertyItem *item;
-                       int free;
+                       int free= 0;
 
                        /* don't throw error here, can't trust blender 100% to give the
                         * right values, python code should not generate error for that */
                        RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free);
-                       if(item->identifier) {
+                       if(item && item->identifier) {
                                ret = PyUnicode_FromString( item->identifier );
                        }
                        else {
@@ -1831,20 +1837,12 @@ PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *data)
                        if (RNA_property_enum_identifier(BPy_GetContext(), ptr, prop, val, &identifier)) {
                                ret = PyUnicode_FromString( identifier );
                        } else {
-                               EnumPropertyItem *item;
-                               int free;
-
-                               /* don't throw error here, can't trust blender 100% to give the
-                                * right values, python code should not generate error for that */
-                               RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free);
-                               if(item[0].identifier)
-                                       ret = PyUnicode_FromString( item[0].identifier );
-                               else
-                                       ret = PyUnicode_FromString( "" );
-
-                               if(free)
-                                       MEM_freeN(item);
-
+                               /* prefer not fail silently incase of api errors, maybe disable it later */
+                               char error_str[128];
+                               sprintf(error_str, "RNA Warning: Current value \"%d\" matches no enum", val);
+                               PyErr_Warn(PyExc_RuntimeWarning, error_str);
+                               
+                               ret = PyUnicode_FromString( "" );
                                /*PyErr_Format(PyExc_AttributeError, "RNA Error: Current value \"%d\" matches no enum", val);
                                ret = NULL;*/
                        }