diff options
-rw-r--r-- | intern/cycles/blender/blender_util.h | 2 | ||||
-rw-r--r-- | source/blender/editors/curve/editfont.c | 4 | ||||
-rw-r--r-- | source/blender/editors/space_buttons/buttons_ops.c | 12 | ||||
-rw-r--r-- | source/blender/editors/space_console/console_ops.c | 6 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_sequence.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_info/info_ops.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_sequencer/sequencer_add.c | 10 | ||||
-rw-r--r-- | source/blender/editors/space_sequencer/sequencer_edit.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 2 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 9 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 25 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 2 |
13 files changed, 43 insertions, 37 deletions
diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h index 3cf75b338dc..f6824f31b7b 100644 --- a/intern/cycles/blender/blender_util.h +++ b/intern/cycles/blender/blender_util.h @@ -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); diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c index 39fb2882e4b..b7deea5069e 100644 --- a/source/blender/editors/curve/editfont.c +++ b/source/blender/editors/curve/editfont.c @@ -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"); diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c index c141789f171..798f4898aaa 100644 --- a/source/blender/editors/space_buttons/buttons_ops.c +++ b/source/blender/editors/space_buttons/buttons_ops.c @@ -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 { diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c index bdb7c622cd2..763beb8671b 100644 --- a/source/blender/editors/space_console/console_ops.c +++ b/source/blender/editors/space_console/console_ops.c @@ -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); diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 29c1452b988..4f8feda3911 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.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); diff --git a/source/blender/editors/space_image/image_sequence.c b/source/blender/editors/space_image/image_sequence.c index 288b3d94b1d..c4f111264a3 100644 --- a/source/blender/editors/space_image/image_sequence.c +++ b/source/blender/editors/space_image/image_sequence.c @@ -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 */ diff --git a/source/blender/editors/space_info/info_ops.c b/source/blender/editors/space_info/info_ops.c index 94e53958524..a99396ecdf0 100644 --- a/source/blender/editors/space_info/info_ops.c +++ b/source/blender/editors/space_info/info_ops.c @@ -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); diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c index ff8cbdb1a59..16b690dd6e4 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.c +++ b/source/blender/editors/space_sequencer/sequencer_add.c @@ -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++; diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index afad8999e88..9a2225a44c5 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -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++; diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 2b78ecb245d..b5fcadbefe8 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -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); diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index f206bde4705..b943a8fad5a 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -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); diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 41c31dfebcb..c838032f1bb 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -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; diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index b5a038757c2..f1a8f4ffd71 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -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; } |