From 8623935aa838a168f64b54f4fefe472444db72fc Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 15 Nov 2011 09:22:52 +0000 Subject: pass a pointer to IDP_New's IDPropertyTemplate rather then a copy. --- source/blender/blenkernel/BKE_idprop.h | 2 +- source/blender/blenkernel/intern/idprop.c | 31 +++++++++++----------- source/blender/editors/interface/interface.c | 2 +- .../blender/editors/interface/interface_layout.c | 4 +-- source/blender/editors/sculpt_paint/paint_image.c | 2 +- source/blender/makesrna/intern/rna_access.c | 20 +++++++------- source/blender/makesrna/intern/rna_armature.c | 4 +-- source/blender/makesrna/intern/rna_pose.c | 2 +- source/blender/makesrna/intern/rna_wm.c | 2 +- source/blender/python/generic/IDProp.c | 14 +++++----- .../blender/windowmanager/intern/wm_event_system.c | 2 +- source/blender/windowmanager/intern/wm_operators.c | 2 +- 12 files changed, 44 insertions(+), 43 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_idprop.h b/source/blender/blenkernel/BKE_idprop.h index ef760277f56..fbe5bf2ef44 100644 --- a/source/blender/blenkernel/BKE_idprop.h +++ b/source/blender/blenkernel/BKE_idprop.h @@ -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 diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 07057e4ee32..a07af5161db 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -193,7 +193,7 @@ static void idp_resize_group_array(IDProperty *prop, int newlen, void *newarr) for(a=prop->len; adata.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; } diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index be8bee7452d..b34b56f31ed 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -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)))); } diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 1560c32250f..29d37be1dee 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -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) { diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index e283927b76f..ff2a1adbdf5 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -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); diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 47a7420cb7f..2b31f7184b6 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -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); diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c index 1ea1a4e3e7b..6785f1f4caf 100644 --- a/source/blender/makesrna/intern/rna_armature.c +++ b/source/blender/makesrna/intern/rna_armature.c @@ -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; diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c index d224bd0d4e5..6290c01f992 100644 --- a/source/blender/makesrna/intern/rna_pose.c +++ b/source/blender/makesrna/intern/rna_pose.c @@ -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; diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index 77ae7095454..7e55c832f3f 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -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; diff --git a/source/blender/python/generic/IDProp.c b/source/blender/python/generic/IDProp.c index d0759a69d8f..8da80bd99bd 100644 --- a/source/blender/python/generic/IDProp.c +++ b/source/blender/python/generic/IDProp.c @@ -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; iproperties= 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); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 7fb6ba6e26b..0c538865501 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -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) { -- cgit v1.2.3