RNA: Add RNA_property_string_set_bytes
This is needed to set values that contain zero bytes (where the length isn't fixed).
This commit is contained in:
parent
02a01b3505
commit
ec52e64a5d
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user