diff options
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 36 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 4 |
3 files changed, 38 insertions, 3 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index a975cbbfd7d..e512aebfa71 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -927,6 +927,7 @@ float RNA_property_float_get_default_index(PointerRNA *ptr, PropertyRNA *prop, i void RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop, char *value); char *RNA_property_string_get_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len); void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value); +void RNA_property_string_set_bytes(PointerRNA *ptr, PropertyRNA *prop, const char *value, int len); int RNA_property_string_length(PointerRNA *ptr, PropertyRNA *prop); void RNA_property_string_get_default(PointerRNA *ptr, PropertyRNA *prop, char *value); char *RNA_property_string_get_default_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen); diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index b0a77f9b90a..00566aed810 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -3004,6 +3004,42 @@ void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *val } } +void RNA_property_string_set_bytes(PointerRNA *ptr, PropertyRNA *prop, const char *value, int len) +{ + StringPropertyRNA *sprop = (StringPropertyRNA *)prop; + IDProperty *idprop; + + BLI_assert(RNA_property_type(prop) == PROP_STRING); + BLI_assert(RNA_property_subtype(prop) == PROP_BYTESTRING); + + if ((idprop = rna_idproperty_check(&prop, ptr))) { + IDP_ResizeArray(idprop, len); + memcpy(idprop->data.pointer, value, (size_t)len); + + rna_idproperty_touch(idprop); + } + else if (sprop->set) { + /* XXX, should take length argument (currently not used). */ + sprop->set(ptr, value); /* set function needs to clamp its self */ + } + else if (sprop->set_ex) { + /* XXX, should take length argument (currently not used). */ + sprop->set_ex(ptr, prop, value); /* set function needs to clamp its self */ + } + else if (prop->flag & PROP_EDITABLE) { + IDProperty *group; + + group = RNA_struct_idprops(ptr, 1); + if (group) { + IDPropertyTemplate val = {0}; + val.string.str = value; + val.string.len = len; + val.string.subtype = IDP_STRING_SUB_BYTE; + IDP_AddToGroup(group, IDP_New(IDP_STRING, &val, prop->identifier)); + } + } +} + void RNA_property_string_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop, char *value) { StringPropertyRNA *sprop = (StringPropertyRNA *)rna_ensure_property(prop); diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index deb045c514b..ee593c90d65 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1751,10 +1751,8 @@ static int pyrna_py_to_prop( return -1; } else { - /* same as unicode */ - /* XXX, this is suspect but needed for function calls, need to see if theres a better way */ if (data) *((char **)data) = (char *)param; - else RNA_property_string_set(ptr, prop, param); + else RNA_property_string_set_bytes(ptr, prop, param, PyBytes_Size(value)); } } else { |