From af138840b3484e106d247c4a6a18a28e8225f5bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 1 Apr 2017 12:04:28 +0200 Subject: [PATCH] api: return pointer to string in function string_dyn_free() if argument "free_string" is 0 --- doc/en/weechat_plugin_api.en.adoc | 6 +++++- doc/fr/weechat_plugin_api.fr.adoc | 6 +++++- doc/it/weechat_plugin_api.it.adoc | 7 ++++++- doc/ja/weechat_plugin_api.ja.adoc | 7 ++++++- src/core/wee-string.c | 16 ++++++++++++++-- src/core/wee-string.h | 2 +- src/plugins/weechat-plugin.h | 4 ++-- 7 files changed, 39 insertions(+), 9 deletions(-) diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index a1bd8f3d4..264b12d85 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -2335,7 +2335,7 @@ Prototype: [source,C] ---- -void weechat_dyn_free (char **string, int free_string); +char *weechat_dyn_free (char **string, int free_string); ---- Arguments: @@ -2344,6 +2344,10 @@ Arguments: * _free_string_: free the string itself; if 0, the content of _*string_ remains valid after the call to this function +Return value: + +* string pointer if _free_string_ is 0, otherwise NULL + C example: [source,C] diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index e8c80bac6..34e239659 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -2378,7 +2378,7 @@ Prototype : [source,C] ---- -void weechat_dyn_free (char **string, int free_string); +char *weechat_dyn_free (char **string, int free_string); ---- Paramètres : @@ -2387,6 +2387,10 @@ Paramètres : * _free_string_ : libérer la chaîne elle-même ; si 0, le contenu de _*string_ reste valide après l'appel à cette fonction +Valeur de retour : + +* pointeur vers la chaîne si _free_string_ vaut 0, sinon NULL + Exemple en C : [source,C] diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index 633f80998..b1cf8110f 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -2425,7 +2425,7 @@ Prototipo: [source,C] ---- -void weechat_dyn_free (char **string, int free_string); +char *weechat_dyn_free (char **string, int free_string); ---- Argomenti: @@ -2435,6 +2435,11 @@ Argomenti: * _free_string_: free the string itself; if 0, the content of _*string_ remains valid after the call to this function +Valore restituito: + +// TRANSLATION MISSING +* string pointer if _free_string_ is 0, otherwise NULL + Esempio in C: [source,C] diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index 9f260c953..d2e49b78b 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -2343,7 +2343,7 @@ _WeeChat バージョン 1.8 以上で利用可_ [source,C] ---- -void weechat_dyn_free (char **string, int free_string); +char *weechat_dyn_free (char **string, int free_string); ---- 引数: @@ -2352,6 +2352,11 @@ void weechat_dyn_free (char **string, int free_string); * _free_string_: 文字列の解放; 0 を指定することで、この関数を呼び出した後でも _*string_ が指すアドレスのメモリを確保したままにできます。 +戻り値: + +// TRANSLATION MISSING +* string pointer if _free_string_ is 0, otherwise NULL + C 言語での使用例: [source,C] diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 3d332660c..40fac1ba7 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -3433,22 +3433,34 @@ string_dyn_concat (char **string, const char *add) * If free_string == 1, the string itself is freed in the structure. * Otherwise the pointer (*string) remains valid after this call, and * the caller must manually free the string with a call to free(). + * + * Returns the pointer to the string if "free_string" is 0 (string + * pointer is still valid), or NULL if "free_string" is 1 (string + * has been freed). */ -void +char * string_dyn_free (char **string, int free_string) { struct t_string_dyn *ptr_string_dyn; + char *ptr_string; if (!string || !*string) - return; + return NULL; ptr_string_dyn = (struct t_string_dyn *)string; if (free_string) + { free (ptr_string_dyn->string); + return NULL; + } + + ptr_string = ptr_string_dyn->string; free (ptr_string_dyn); + + return ptr_string; } /* diff --git a/src/core/wee-string.h b/src/core/wee-string.h index 8cf1a9b58..3769cf299 100644 --- a/src/core/wee-string.h +++ b/src/core/wee-string.h @@ -121,7 +121,7 @@ extern void string_shared_free (const char *string); extern char **string_dyn_alloc (int size_alloc); extern int string_dyn_copy (char **string, const char *new_string); extern int string_dyn_concat (char **string, const char *add); -extern void string_dyn_free (char **string, int free_string); +extern char *string_dyn_free (char **string, int free_string); extern void string_end (); #endif /* WEECHAT_STRING_H */ diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 4858b810b..2a44d692d 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -59,7 +59,7 @@ struct timeval; * please change the date with current one; for a second change at same * date, increment the 01, otherwise please keep 01. */ -#define WEECHAT_PLUGIN_API_VERSION "20170312-01" +#define WEECHAT_PLUGIN_API_VERSION "20170401-01" /* macros for defining plugin infos */ #define WEECHAT_PLUGIN_NAME(__name) \ @@ -328,7 +328,7 @@ struct t_weechat_plugin char **(*string_dyn_alloc) (int size_alloc); int (*string_dyn_copy) (char **string, const char *new_string); int (*string_dyn_concat) (char **string, const char *add); - void (*string_dyn_free) (char **string, int free_string); + char *(*string_dyn_free) (char **string, int free_string); /* UTF-8 strings */ int (*utf8_has_8bits) (const char *string);