[Bf-blender-cvs] [0682af0d63a] master: RNA: add length augmented to RNA_string_get_alloc

Campbell Barton noreply at git.blender.org
Mon Aug 23 07:28:56 CEST 2021


Commit: 0682af0d63a44b050d57bdaf7699e364a311d711
Author: Campbell Barton
Date:   Mon Aug 23 15:01:53 2021 +1000
Branches: master
https://developer.blender.org/rB0682af0d63a44b050d57bdaf7699e364a311d711

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.

===================================================================

M	intern/cycles/blender/blender_util.h
M	source/blender/editors/curve/editfont.c
M	source/blender/editors/space_buttons/buttons_ops.c
M	source/blender/editors/space_console/console_ops.c
M	source/blender/editors/space_image/image_ops.c
M	source/blender/editors/space_image/image_sequence.c
M	source/blender/editors/space_info/info_ops.c
M	source/blender/editors/space_sequencer/sequencer_add.c
M	source/blender/editors/space_sequencer/sequencer_edit.c
M	source/blender/editors/space_text/text_ops.c
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_access.c
M	source/blender/windowmanager/intern/wm_operators.c

===================================================================

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_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list