pass a pointer to IDP_New's IDPropertyTemplate rather then a copy.
authorCampbell Barton <ideasman42@gmail.com>
Tue, 15 Nov 2011 09:22:52 +0000 (09:22 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 15 Nov 2011 09:22:52 +0000 (09:22 +0000)
12 files changed:
source/blender/blenkernel/BKE_idprop.h
source/blender/blenkernel/intern/idprop.c
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_layout.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/makesrna/intern/rna_access.c
source/blender/makesrna/intern/rna_armature.c
source/blender/makesrna/intern/rna_pose.c
source/blender/makesrna/intern/rna_wm.c
source/blender/python/generic/IDProp.c
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_operators.c

index ef76027..fbe5bf2 100644 (file)
@@ -187,7 +187,7 @@ Note that you MUST either attach the id property to an id property group with
 IDP_AddToGroup or MEM_freeN the property, doing anything else might result in
 a memory leak.
 */
-struct IDProperty *IDP_New(int type, IDPropertyTemplate val, const char *name);
+struct IDProperty *IDP_New(const int type, const IDPropertyTemplate *val, const char *name);
 
 /** \note this will free all child properties of list arrays and groups!
   Also, note that this does NOT unlink anything!  Plus it doesn't free
index 07057e4..a07af51 100644 (file)
@@ -193,7 +193,7 @@ static void idp_resize_group_array(IDProperty *prop, int newlen, void *newarr)
 
                for(a=prop->len; a<newlen; a++) {
                        val.i = 0; /* silence MSVC warning about uninitialized var when debugging */
-                       array[a]= IDP_New(IDP_GROUP, val, "IDP_ResizeArray group");
+                       array[a]= IDP_New(IDP_GROUP, &val, "IDP_ResizeArray group");
                }
        }
        else {
@@ -673,32 +673,33 @@ int IDP_EqualsProperties(IDProperty *prop1, IDProperty *prop2)
        return 1;
 }
 
-IDProperty *IDP_New(int type, IDPropertyTemplate val, const char *name)
+/* 'val' is never NULL, dont check */
+IDProperty *IDP_New(const int type, const IDPropertyTemplate *val, const char *name)
 {
        IDProperty *prop=NULL;
 
        switch (type) {
                case IDP_INT:
                        prop = MEM_callocN(sizeof(IDProperty), "IDProperty int");
-                       prop->data.val = val.i;
+                       prop->data.val = val->i;
                        break;
                case IDP_FLOAT:
                        prop = MEM_callocN(sizeof(IDProperty), "IDProperty float");
-                       *(float*)&prop->data.val = val.f;
+                       *(float*)&prop->data.val = val->f;
                        break;
                case IDP_DOUBLE:
                        prop = MEM_callocN(sizeof(IDProperty), "IDProperty float");
-                       *(double*)&prop->data.val = val.d;
+                       *(double*)&prop->data.val = val->d;
                        break;          
                case IDP_ARRAY:
                {
                        /*for now, we only support float and int and double arrays*/
-                       if (val.array.type == IDP_FLOAT || val.array.type == IDP_INT || val.array.type == IDP_DOUBLE || val.array.type == IDP_GROUP) {
+                       if (val->array.type == IDP_FLOAT || val->array.type == IDP_INT || val->array.type == IDP_DOUBLE || val->array.type == IDP_GROUP) {
                                prop = MEM_callocN(sizeof(IDProperty), "IDProperty array");
-                               prop->subtype = val.array.type;
-                               if (val.array.len)
-                                       prop->data.pointer = MEM_callocN(idp_size_table[val.array.type]*val.array.len, "id property array");
-                               prop->len = prop->totallen = val.array.len;
+                               prop->subtype = val->array.type;
+                               if (val->array.len)
+                                       prop->data.pointer = MEM_callocN(idp_size_table[val->array.type]*val->array.len, "id property array");
+                               prop->len = prop->totallen = val->array.len;
                                break;
                        } else {
                                return NULL;
@@ -706,10 +707,10 @@ IDProperty *IDP_New(int type, IDPropertyTemplate val, const char *name)
                }
                case IDP_STRING:
                {
-                       const char *st = val.string.str;
+                       const char *st = val->string.str;
 
                        prop = MEM_callocN(sizeof(IDProperty), "IDProperty string");
-                       if (val.string.subtype == IDP_STRING_SUB_BYTE) {
+                       if (val->string.subtype == IDP_STRING_SUB_BYTE) {
                                /* note, intentionally not null terminated */
                                if (st == NULL) {
                                        prop->data.pointer = MEM_callocN(DEFAULT_ALLOC_FOR_NULL_STRINGS, "id property string 1");
@@ -717,9 +718,9 @@ IDProperty *IDP_New(int type, IDPropertyTemplate val, const char *name)
                                        prop->len = 0;
                                }
                                else {
-                                       prop->data.pointer = MEM_mallocN(val.string.len, "id property string 2");
-                                       prop->len = prop->totallen = val.string.len;
-                                       memcpy(prop->data.pointer, st, val.string.len);
+                                       prop->data.pointer = MEM_mallocN(val->string.len, "id property string 2");
+                                       prop->len = prop->totallen = val->string.len;
+                                       memcpy(prop->data.pointer, st, val->string.len);
                                }
                                prop->subtype= IDP_STRING_SUB_BYTE;
                        }
index be8bee7..b34b56f 100644 (file)
@@ -831,7 +831,7 @@ static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
                        if (prop_menu == NULL) {
                                /* annoying, create a property */
                                IDPropertyTemplate val = {0};
-                               prop_menu= IDP_New(IDP_GROUP, val, __func__); /* dummy, name is unimportant  */
+                               prop_menu= IDP_New(IDP_GROUP, &val, __func__); /* dummy, name is unimportant  */
                                IDP_AddToGroup(prop_menu, (prop_menu_name= IDP_NewString("", "name", sizeof(mt->idname))));
                        }
 
index 1560c32..29d37be 100644 (file)
@@ -677,7 +677,7 @@ PointerRNA uiItemFullO(uiLayout *layout, const char *opname, const char *name, i
                }
                else {
                        IDPropertyTemplate val = {0};
-                       opptr->data= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
+                       opptr->data= IDP_New(IDP_GROUP, &val, "wmOperatorProperties");
                }
 
                return *opptr;
@@ -2747,7 +2747,7 @@ void uiLayoutOperatorButs(const bContext *C, uiLayout *layout, wmOperator *op,in
 {
        if(!op->properties) {
                IDPropertyTemplate val = {0};
-               op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
+               op->properties= IDP_New(IDP_GROUP, &val, "wmOperatorProperties");
        }
 
        if(flag & UI_LAYOUT_OP_SHOW_TITLE) {
index e283927..ff2a1ad 100644 (file)
@@ -5669,7 +5669,7 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
 
                val.array.len = PROJ_VIEW_DATA_SIZE;
                val.array.type = IDP_FLOAT;
-               view_data = IDP_New(IDP_ARRAY, val, PROJ_VIEW_DATA_ID);
+               view_data = IDP_New(IDP_ARRAY, &val, PROJ_VIEW_DATA_ID);
 
                array= (float *)IDP_Array(view_data);
                memcpy(array, rv3d->winmat, sizeof(rv3d->winmat)); array += sizeof(rv3d->winmat)/sizeof(float);
index 47a7420..2b31f71 100644 (file)
@@ -1617,7 +1617,7 @@ void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, int value)
 
                group= RNA_struct_idprops(ptr, 1);
                if(group)
-                       IDP_AddToGroup(group, IDP_New(IDP_INT, val, prop->identifier));
+                       IDP_AddToGroup(group, IDP_New(IDP_INT, &val, prop->identifier));
        }
 }
 
@@ -1696,7 +1696,7 @@ void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const in
 
                group= RNA_struct_idprops(ptr, 1);
                if(group) {
-                       idprop= IDP_New(IDP_ARRAY, val, prop->identifier);
+                       idprop= IDP_New(IDP_ARRAY, &val, prop->identifier);
                        IDP_AddToGroup(group, idprop);
                        memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);
                }
@@ -1814,7 +1814,7 @@ void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
 
                group= RNA_struct_idprops(ptr, 1);
                if(group)
-                       IDP_AddToGroup(group, IDP_New(IDP_INT, val, prop->identifier));
+                       IDP_AddToGroup(group, IDP_New(IDP_INT, &val, prop->identifier));
        }
 }
 
@@ -1930,7 +1930,7 @@ void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *v
 
                group= RNA_struct_idprops(ptr, 1);
                if(group) {
-                       idprop= IDP_New(IDP_ARRAY, val, prop->identifier);
+                       idprop= IDP_New(IDP_ARRAY, &val, prop->identifier);
                        IDP_AddToGroup(group, idprop);
                        memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);
                }
@@ -2050,7 +2050,7 @@ void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
 
                group= RNA_struct_idprops(ptr, 1);
                if(group)
-                       IDP_AddToGroup(group, IDP_New(IDP_FLOAT, val, prop->identifier));
+                       IDP_AddToGroup(group, IDP_New(IDP_FLOAT, &val, prop->identifier));
        }
 }
 
@@ -2184,7 +2184,7 @@ void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const floa
 
                group= RNA_struct_idprops(ptr, 1);
                if(group) {
-                       idprop= IDP_New(IDP_ARRAY, val, prop->identifier);
+                       idprop= IDP_New(IDP_ARRAY, &val, prop->identifier);
                        IDP_AddToGroup(group, idprop);
                        memcpy(IDP_Array(idprop), values, sizeof(float)*idprop->len);
                }
@@ -2439,7 +2439,7 @@ void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
 
                group= RNA_struct_idprops(ptr, 1);
                if(group)
-                       IDP_AddToGroup(group, IDP_New(IDP_INT, val, prop->identifier));
+                       IDP_AddToGroup(group, IDP_New(IDP_INT, &val, prop->identifier));
        }
 }
 
@@ -2535,7 +2535,7 @@ void RNA_property_pointer_add(PointerRNA *ptr, PropertyRNA *prop)
 
                group= RNA_struct_idprops(ptr, 1);
                if(group)
-                       IDP_AddToGroup(group, IDP_New(IDP_GROUP, val, prop->identifier));
+                       IDP_AddToGroup(group, IDP_New(IDP_GROUP, &val, prop->identifier));
        }
        else
                printf("%s %s.%s: only supported for id properties.\n", __func__, ptr->type->identifier, prop->identifier);
@@ -2658,7 +2658,7 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA
                IDPropertyTemplate val = {0};
                IDProperty *item;
 
-               item= IDP_New(IDP_GROUP, val, "");
+               item= IDP_New(IDP_GROUP, &val, "");
                IDP_AppendArray(idprop, item);
                // IDP_FreeProperty(item); // IDP_AppendArray does a shallow copy (memcpy), only free memory 
                MEM_freeN(item);
@@ -2672,7 +2672,7 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA
                        idprop= IDP_NewIDPArray(prop->identifier);
                        IDP_AddToGroup(group, idprop);
 
-                       item= IDP_New(IDP_GROUP, val, "");
+                       item= IDP_New(IDP_GROUP, &val, "");
                        IDP_AppendArray(idprop, item);
                        // IDP_FreeProperty(item); // IDP_AppendArray does a shallow copy (memcpy), only free memory
                        MEM_freeN(item);
index 1ea1a4e..6785f1f 100644 (file)
@@ -169,7 +169,7 @@ static IDProperty *rna_Bone_idprops(PointerRNA *ptr, int create)
 
        if(create && !bone->prop) {
                IDPropertyTemplate val = {0};
-               bone->prop= IDP_New(IDP_GROUP, val, "RNA_Bone ID properties");
+               bone->prop= IDP_New(IDP_GROUP, &val, "RNA_Bone ID properties");
        }
 
        return bone->prop;
@@ -181,7 +181,7 @@ static IDProperty *rna_EditBone_idprops(PointerRNA *ptr, int create)
 
        if(create && !ebone->prop) {
                IDPropertyTemplate val = {0};
-               ebone->prop= IDP_New(IDP_GROUP, val, "RNA_EditBone ID properties");
+               ebone->prop= IDP_New(IDP_GROUP, &val, "RNA_EditBone ID properties");
        }
 
        return ebone->prop;
index d224bd0..6290c01 100644 (file)
@@ -157,7 +157,7 @@ static IDProperty *rna_PoseBone_idprops(PointerRNA *ptr, int create)
 
        if(create && !pchan->prop) {
                IDPropertyTemplate val = {0};
-               pchan->prop= IDP_New(IDP_GROUP, val, "RNA_PoseBone group");
+               pchan->prop= IDP_New(IDP_GROUP, &val, "RNA_PoseBone group");
        }
 
        return pchan->prop;
index 77ae709..7e55c83 100644 (file)
@@ -421,7 +421,7 @@ static IDProperty *rna_OperatorProperties_idprops(PointerRNA *ptr, int create)
 {
        if(create && !ptr->data) {
                IDPropertyTemplate val = {0};
-               ptr->data= IDP_New(IDP_GROUP, val, "RNA_OperatorProperties group");
+               ptr->data= IDP_New(IDP_GROUP, &val, "RNA_OperatorProperties group");
        }
 
        return ptr->data;
index d0759a6..8da80bd 100644 (file)
@@ -330,18 +330,18 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty
 
        if (PyFloat_Check(ob)) {
                val.d = PyFloat_AsDouble(ob);
-               prop = IDP_New(IDP_DOUBLE, val, name);
+               prop = IDP_New(IDP_DOUBLE, &val, name);
        }
        else if (PyLong_Check(ob)) {
                val.i = (int) PyLong_AsSsize_t(ob);
-               prop = IDP_New(IDP_INT, val, name);
+               prop = IDP_New(IDP_INT, &val, name);
        }
        else if (PyUnicode_Check(ob)) {
 #ifdef USE_STRING_COERCE
                PyObject *value_coerce= NULL;
                val.string.str = (char *)PyC_UnicodeAsByte(ob, &value_coerce);
                val.string.subtype = IDP_STRING_SUB_UTF8;
-               prop = IDP_New(IDP_STRING, val, name);
+               prop = IDP_New(IDP_STRING, &val, name);
                Py_XDECREF(value_coerce);
 #else
                val.str = _PyUnicode_AsString(ob);
@@ -353,7 +353,7 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty
                val.string.len= PyBytes_GET_SIZE(ob);
                val.string.subtype= IDP_STRING_SUB_BYTE;
 
-               prop = IDP_New(IDP_STRING, val, name);
+               prop = IDP_New(IDP_STRING, &val, name);
                //prop = IDP_NewString(PyBytes_AS_STRING(ob), name, PyBytes_GET_SIZE(ob));
                //prop->subtype= IDP_STRING_SUB_BYTE;
        }
@@ -372,7 +372,7 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty
 
                switch(val.array.type) {
                case IDP_DOUBLE:
-                       prop = IDP_New(IDP_ARRAY, val, name);
+                       prop = IDP_New(IDP_ARRAY, &val, name);
                        for (i=0; i<val.array.len; i++) {
                                item = PySequence_GetItem(ob, i);
                                ((double*)IDP_Array(prop))[i] = (float)PyFloat_AsDouble(item);
@@ -380,7 +380,7 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty
                        }
                        break;
                case IDP_INT:
-                       prop = IDP_New(IDP_ARRAY, val, name);
+                       prop = IDP_New(IDP_ARRAY, &val, name);
                        for (i=0; i<val.array.len; i++) {
                                item = PySequence_GetItem(ob, i);
                                ((int*)IDP_Array(prop))[i] = (int)PyLong_AsSsize_t(item);
@@ -410,7 +410,7 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty
 
                /*we allocate the group first; if we hit any invalid data,
                  we can delete it easily enough.*/
-               prop = IDP_New(IDP_GROUP, val, name);
+               prop = IDP_New(IDP_GROUP, &val, name);
                len = PyMapping_Length(ob);
                for (i=0; i<len; i++) {
                        key = PySequence_GetItem(keys, i);
index 4342c9f..a7c3e97 100644 (file)
@@ -636,7 +636,7 @@ static wmOperator *wm_operator_create(wmWindowManager *wm, wmOperatorType *ot, P
        }
        else {
                IDPropertyTemplate val = {0};
-               op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
+               op->properties= IDP_New(IDP_GROUP, &val, "wmOperatorProperties");
        }
        RNA_pointer_create(&wm->id, ot->srna, op->properties, op->ptr);
 
index 7fb6ba6..0c53886 100644 (file)
@@ -597,7 +597,7 @@ void WM_operator_properties_alloc(PointerRNA **ptr, IDProperty **properties, con
 {
        if(*properties==NULL) {
                IDPropertyTemplate val = {0};
-               *properties= IDP_New(IDP_GROUP, val, "wmOpItemProp");
+               *properties= IDP_New(IDP_GROUP, &val, "wmOpItemProp");
        }
 
        if(*ptr==NULL) {