bugfix [#23656] Problems retrieving properties from inside runtime-created PointerProperties

cant test if this fix solves the problem matt is having but it at least fixes an error caused by classes created in exec(),
when the properties pointers were copied the hash key still referred to the python object which could be freed. in most cases this wouldnt happen (would be kept in bytecode) but with exec() the property string is freed immediately.
This commit is contained in:
2010-09-06 15:54:08 +00:00
parent f6c68f1019
commit 99954545ee
3 changed files with 25 additions and 13 deletions

View File

@@ -192,7 +192,7 @@ void RNA_def_struct_duplicate_pointers(StructRNA *srna);
void RNA_def_struct_free_pointers(StructRNA *srna);
void RNA_def_func_duplicate_pointers(FunctionRNA *func);
void RNA_def_func_free_pointers(FunctionRNA *func);
void RNA_def_property_duplicate_pointers(PropertyRNA *prop);
void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA *prop);
void RNA_def_property_free_pointers(PropertyRNA *prop);
int RNA_def_property_free_identifier(StructOrFunctionRNA *cont_, const char *identifier);

View File

@@ -2617,14 +2617,26 @@ void RNA_def_func_free_pointers(FunctionRNA *func)
}
}
void RNA_def_property_duplicate_pointers(PropertyRNA *prop)
void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA *prop)
{
ContainerRNA *cont= cont_;
EnumPropertyItem *earray;
float *farray;
int *iarray;
int a;
if(prop->identifier) prop->identifier= BLI_strdup(prop->identifier);
/* annoying since we just added this to a hash, could make this add the correct key to the hash in the first place */
if(prop->identifier) {
if(cont->prophash) {
BLI_ghash_remove(cont->prophash, (void*)prop->identifier, NULL, NULL);
prop->identifier= BLI_strdup(prop->identifier);
BLI_ghash_insert(cont->prophash, (void*)prop->identifier, prop);
}
else {
prop->identifier= BLI_strdup(prop->identifier);
}
}
if(prop->name) prop->name= BLI_strdup(prop->name);
if(prop->description) prop->description= BLI_strdup(prop->description);

View File

@@ -160,7 +160,7 @@ PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
Py_RETURN_NONE;
}
else { /* operators defer running this function */
@@ -236,7 +236,7 @@ PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
Py_RETURN_NONE;
}
else { /* operators defer running this function */
@@ -302,7 +302,7 @@ PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
Py_RETURN_NONE;
}
else { /* operators defer running this function */
@@ -379,7 +379,7 @@ PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
Py_RETURN_NONE;
}
else { /* operators defer running this function */
@@ -456,7 +456,7 @@ PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
Py_RETURN_NONE;
}
else { /* operators defer running this function */
@@ -533,7 +533,7 @@ PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
Py_RETURN_NONE;
}
else { /* operators defer running this function */
@@ -598,7 +598,7 @@ PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw)
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
Py_RETURN_NONE;
}
else { /* operators defer running this function */
@@ -704,7 +704,7 @@ PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
MEM_freeN(eitems);
Py_RETURN_NONE;
@@ -787,7 +787,7 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
Py_RETURN_NONE;
}
else { /* operators defer running this function */
@@ -847,7 +847,7 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
Py_RETURN_NONE;
}
else { /* operators defer running this function */