RNA: add length augmented to RNA_string_get_alloc
This was noted as a TODO as it wraps RNA_property_string_get_alloc which takes a length return argument.
This commit is contained in:
@@ -424,7 +424,7 @@ static inline void set_enum(PointerRNA &ptr, const char *name, const string &ide
|
||||
static inline string get_string(PointerRNA &ptr, const char *name)
|
||||
{
|
||||
char cstrbuf[1024];
|
||||
char *cstr = RNA_string_get_alloc(&ptr, name, cstrbuf, sizeof(cstrbuf));
|
||||
char *cstr = RNA_string_get_alloc(&ptr, name, cstrbuf, sizeof(cstrbuf), NULL);
|
||||
string str(cstr);
|
||||
if (cstr != cstrbuf)
|
||||
MEM_freeN(cstr);
|
||||
|
||||
@@ -576,7 +576,7 @@ static int paste_from_file_exec(bContext *C, wmOperator *op)
|
||||
char *path;
|
||||
int retval;
|
||||
|
||||
path = RNA_string_get_alloc(op->ptr, "filepath", NULL, 0);
|
||||
path = RNA_string_get_alloc(op->ptr, "filepath", NULL, 0, NULL);
|
||||
retval = paste_from_file(C, op->reports, path);
|
||||
MEM_freeN(path);
|
||||
|
||||
@@ -1627,7 +1627,7 @@ static int insert_text_exec(bContext *C, wmOperator *op)
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
inserted_utf8 = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
|
||||
inserted_utf8 = RNA_string_get_alloc(op->ptr, "text", NULL, 0, NULL);
|
||||
len = BLI_strlen_utf8(inserted_utf8);
|
||||
|
||||
inserted_text = MEM_callocN(sizeof(char32_t) * (len + 1), "FONT_insert_text");
|
||||
|
||||
@@ -198,7 +198,8 @@ static int file_browse_exec(bContext *C, wmOperator *op)
|
||||
Main *bmain = CTX_data_main(C);
|
||||
FileBrowseOp *fbo = op->customdata;
|
||||
ID *id;
|
||||
char *str, path[FILE_MAX];
|
||||
char *str;
|
||||
int str_len;
|
||||
const char *path_prop = RNA_struct_find_property(op->ptr, "directory") ? "directory" :
|
||||
"filepath";
|
||||
|
||||
@@ -206,10 +207,11 @@ static int file_browse_exec(bContext *C, wmOperator *op)
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
str = RNA_string_get_alloc(op->ptr, path_prop, NULL, 0);
|
||||
str = RNA_string_get_alloc(op->ptr, path_prop, NULL, 0, &str_len);
|
||||
|
||||
/* Add slash for directories, important for some properties. */
|
||||
if (RNA_property_subtype(fbo->prop) == PROP_DIRPATH) {
|
||||
char path[FILE_MAX];
|
||||
const bool is_relative = RNA_boolean_get(op->ptr, "relative_path");
|
||||
id = fbo->ptr.owner_id;
|
||||
|
||||
@@ -220,13 +222,13 @@ static int file_browse_exec(bContext *C, wmOperator *op)
|
||||
/* Do this first so '//' isn't converted to '//\' on windows. */
|
||||
BLI_path_slash_ensure(path);
|
||||
if (is_relative) {
|
||||
BLI_strncpy(path, str, FILE_MAX);
|
||||
const int path_len = BLI_strncpy_rlen(path, str, FILE_MAX);
|
||||
BLI_path_rel(path, BKE_main_blendfile_path(bmain));
|
||||
str = MEM_reallocN(str, strlen(path) + 2);
|
||||
str = MEM_reallocN(str, path_len + 2);
|
||||
BLI_strncpy(str, path, FILE_MAX);
|
||||
}
|
||||
else {
|
||||
str = MEM_reallocN(str, strlen(str) + 2);
|
||||
str = MEM_reallocN(str, str_len + 2);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -384,7 +384,7 @@ static int console_insert_exec(bContext *C, wmOperator *op)
|
||||
SpaceConsole *sc = CTX_wm_space_console(C);
|
||||
ARegion *region = CTX_wm_region(C);
|
||||
ConsoleLine *ci = console_history_verify(C);
|
||||
char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
|
||||
char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0, NULL);
|
||||
int len;
|
||||
|
||||
if (str[0] == '\t' && str[1] == '\0') {
|
||||
@@ -860,7 +860,7 @@ static int console_history_append_exec(bContext *C, wmOperator *op)
|
||||
ScrArea *area = CTX_wm_area(C);
|
||||
ConsoleLine *ci = console_history_verify(C);
|
||||
/* own this text in the new line, don't free */
|
||||
char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
|
||||
char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0, NULL);
|
||||
int cursor = RNA_int_get(op->ptr, "current_character");
|
||||
const bool rem_dupes = RNA_boolean_get(op->ptr, "remove_duplicates");
|
||||
int prev_len = ci->len;
|
||||
@@ -923,7 +923,7 @@ static int console_scrollback_append_exec(bContext *C, wmOperator *op)
|
||||
ConsoleLine *ci;
|
||||
|
||||
/* own this text in the new line, don't free */
|
||||
char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
|
||||
char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0, NULL);
|
||||
int type = RNA_enum_get(op->ptr, "type");
|
||||
|
||||
console_history_verify(C);
|
||||
|
||||
@@ -3935,7 +3935,7 @@ static int tile_add_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
|
||||
bool fill_tile = RNA_boolean_get(op->ptr, "fill");
|
||||
char *label = RNA_string_get_alloc(op->ptr, "label", NULL, 0);
|
||||
char *label = RNA_string_get_alloc(op->ptr, "label", NULL, 0, NULL);
|
||||
|
||||
/* BKE_image_add_tile assumes a pre-sorted list of tiles. */
|
||||
BKE_image_sort_tiles(ima);
|
||||
|
||||
@@ -68,7 +68,7 @@ static void image_sequence_get_frame_ranges(wmOperator *op, ListBase *ranges)
|
||||
RNA_BEGIN (op->ptr, itemptr, "files") {
|
||||
char head[FILE_MAX], tail[FILE_MAX];
|
||||
ushort digits;
|
||||
char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0);
|
||||
char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0, NULL);
|
||||
ImageFrame *frame = MEM_callocN(sizeof(ImageFrame), "image_frame");
|
||||
|
||||
/* use the first file in the list as base filename */
|
||||
|
||||
@@ -512,7 +512,7 @@ void FILE_OT_report_missing_files(wmOperatorType *ot)
|
||||
static int find_missing_files_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Main *bmain = CTX_data_main(C);
|
||||
const char *searchpath = RNA_string_get_alloc(op->ptr, "directory", NULL, 0);
|
||||
const char *searchpath = RNA_string_get_alloc(op->ptr, "directory", NULL, 0, NULL);
|
||||
const bool find_all = RNA_boolean_get(op->ptr, "find_all");
|
||||
|
||||
BKE_bpath_missing_files_find(bmain, searchpath, op->reports, find_all);
|
||||
|
||||
@@ -254,11 +254,11 @@ static void load_data_init_from_operator(SeqLoadData *load_data, bContext *C, wm
|
||||
BLI_strncpy(load_data->name, BLI_path_basename(load_data->path), sizeof(load_data->name));
|
||||
}
|
||||
else if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
|
||||
char *directory = RNA_string_get_alloc(op->ptr, "directory", NULL, 0);
|
||||
char *directory = RNA_string_get_alloc(op->ptr, "directory", NULL, 0, NULL);
|
||||
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "files"))) {
|
||||
RNA_PROP_BEGIN (op->ptr, itemptr, prop) {
|
||||
char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0);
|
||||
char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0, NULL);
|
||||
BLI_strncpy(load_data->name, filename, sizeof(load_data->name));
|
||||
BLI_join_dirfile(load_data->path, sizeof(load_data->path), directory, filename);
|
||||
MEM_freeN(filename);
|
||||
@@ -944,7 +944,7 @@ int sequencer_image_seq_get_minmax_frame(wmOperator *op,
|
||||
RNA_BEGIN (op->ptr, itemptr, "files") {
|
||||
char *filename;
|
||||
int frame;
|
||||
filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0);
|
||||
filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0, NULL);
|
||||
|
||||
if (filename) {
|
||||
if (BLI_path_frame_get(filename, &frame, &numdigits)) {
|
||||
@@ -973,7 +973,7 @@ void sequencer_image_seq_reserve_frames(
|
||||
{
|
||||
char *filename = NULL;
|
||||
RNA_BEGIN (op->ptr, itemptr, "files") {
|
||||
filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0);
|
||||
filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0, NULL);
|
||||
break;
|
||||
}
|
||||
RNA_END;
|
||||
@@ -1023,7 +1023,7 @@ static void sequencer_add_image_strip_load_files(
|
||||
else {
|
||||
size_t strip_frame = 0;
|
||||
RNA_BEGIN (op->ptr, itemptr, "files") {
|
||||
char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0);
|
||||
char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0, NULL);
|
||||
SEQ_add_image_load_file(seq, strip_frame, filename);
|
||||
MEM_freeN(filename);
|
||||
strip_frame++;
|
||||
|
||||
@@ -2826,7 +2826,7 @@ static int sequencer_change_path_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
else {
|
||||
RNA_BEGIN (op->ptr, itemptr, "files") {
|
||||
char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0);
|
||||
char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0, NULL);
|
||||
BLI_strncpy(se->name, filename, sizeof(se->name));
|
||||
MEM_freeN(filename);
|
||||
se++;
|
||||
|
||||
@@ -3430,7 +3430,7 @@ static int text_insert_exec(bContext *C, wmOperator *op)
|
||||
|
||||
text_drawcache_tag_update(st, 0);
|
||||
|
||||
str = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
|
||||
str = RNA_string_get_alloc(op->ptr, "text", NULL, 0, NULL);
|
||||
|
||||
ED_text_undo_push_init(C);
|
||||
|
||||
|
||||
@@ -1029,10 +1029,8 @@ 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);
|
||||
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);
|
||||
char *RNA_property_string_get_default_alloc(
|
||||
PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len);
|
||||
int RNA_property_string_default_length(PointerRNA *ptr, PropertyRNA *prop);
|
||||
|
||||
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop);
|
||||
@@ -1238,7 +1236,8 @@ bool RNA_enum_icon_from_value(const EnumPropertyItem *item, int value, int *r_ic
|
||||
bool RNA_enum_name_from_value(const EnumPropertyItem *item, int value, const char **r_name);
|
||||
|
||||
void RNA_string_get(PointerRNA *ptr, const char *name, char *value);
|
||||
char *RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen);
|
||||
char *RNA_string_get_alloc(
|
||||
PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen, int *r_len);
|
||||
int RNA_string_length(PointerRNA *ptr, const char *name);
|
||||
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value);
|
||||
|
||||
|
||||
@@ -3397,7 +3397,7 @@ char *RNA_property_string_get_alloc(
|
||||
buf = fixedbuf;
|
||||
}
|
||||
else {
|
||||
buf = MEM_mallocN(sizeof(char) * (length + 1), "RNA_string_get_alloc");
|
||||
buf = MEM_mallocN(sizeof(char) * (length + 1), __func__);
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
@@ -3537,10 +3537,8 @@ void RNA_property_string_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop,
|
||||
strcpy(value, sprop->defaultvalue);
|
||||
}
|
||||
|
||||
char *RNA_property_string_get_default_alloc(PointerRNA *ptr,
|
||||
PropertyRNA *prop,
|
||||
char *fixedbuf,
|
||||
int fixedlen)
|
||||
char *RNA_property_string_get_default_alloc(
|
||||
PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len)
|
||||
{
|
||||
char *buf;
|
||||
int length;
|
||||
@@ -3553,11 +3551,15 @@ char *RNA_property_string_get_default_alloc(PointerRNA *ptr,
|
||||
buf = fixedbuf;
|
||||
}
|
||||
else {
|
||||
buf = MEM_callocN(sizeof(char) * (length + 1), "RNA_string_get_alloc");
|
||||
buf = MEM_callocN(sizeof(char) * (length + 1), __func__);
|
||||
}
|
||||
|
||||
RNA_property_string_get_default(ptr, prop, buf);
|
||||
|
||||
if (r_len) {
|
||||
*r_len = length;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -6587,15 +6589,18 @@ void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
|
||||
}
|
||||
}
|
||||
|
||||
char *RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen)
|
||||
char *RNA_string_get_alloc(
|
||||
PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen, int *r_len)
|
||||
{
|
||||
PropertyRNA *prop = RNA_struct_find_property(ptr, name);
|
||||
|
||||
if (prop) {
|
||||
/* TODO: pass length. */
|
||||
return RNA_property_string_get_alloc(ptr, prop, fixedbuf, fixedlen, NULL);
|
||||
return RNA_property_string_get_alloc(ptr, prop, fixedbuf, fixedlen, r_len);
|
||||
}
|
||||
printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
|
||||
if (r_len != NULL) {
|
||||
*r_len = 0;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -8166,7 +8171,7 @@ bool RNA_property_reset(PointerRNA *ptr, PropertyRNA *prop, int index)
|
||||
}
|
||||
|
||||
case PROP_STRING: {
|
||||
char *value = RNA_property_string_get_default_alloc(ptr, prop, NULL, 0);
|
||||
char *value = RNA_property_string_get_default_alloc(ptr, prop, NULL, 0, NULL);
|
||||
RNA_property_string_set(ptr, prop, value);
|
||||
MEM_freeN(value);
|
||||
return true;
|
||||
|
||||
@@ -2497,7 +2497,7 @@ static int radial_control_get_path(PointerRNA *ctx_ptr,
|
||||
|
||||
/* get an rna string path from the operator's properties */
|
||||
char *str;
|
||||
if (!(str = RNA_string_get_alloc(op->ptr, name, NULL, 0))) {
|
||||
if (!(str = RNA_string_get_alloc(op->ptr, name, NULL, 0, NULL))) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user