[vlc-commits] modules: constify vlc_gettext()

Rémi Denis-Courmont git at videolan.org
Sun Jun 10 12:11:08 CEST 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Jun  9 13:49:57 2018 +0300| [8349b1a82af397d27d0fd820f76e5b80b83707d0] | committer: Rémi Denis-Courmont

modules: constify vlc_gettext()

The returned string is actually not modifiable. We have no obligations
to reproduce the deficient prototype of the standard gettext().

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8349b1a82af397d27d0fd820f76e5b80b83707d0
---

 include/vlc_common.h                        | 5 +++--
 modules/gui/skins2/src/theme_repository.cpp | 4 ++--
 src/misc/actions.c                          | 6 +++---
 src/modules/textdomain.c                    | 9 +++++----
 4 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/include/vlc_common.h b/include/vlc_common.h
index da334710af..0cf3fbca2f 100644
--- a/include/vlc_common.h
+++ b/include/vlc_common.h
@@ -1126,8 +1126,9 @@ static inline void *vlc_alloc(size_t count, size_t size)
 /*****************************************************************************
  * I18n stuff
  *****************************************************************************/
-VLC_API char *vlc_gettext( const char *msgid ) VLC_FORMAT_ARG(1);
-VLC_API char *vlc_ngettext( const char *s, const char *p, unsigned long n ) VLC_FORMAT_ARG(1) VLC_FORMAT_ARG(2);
+VLC_API const char *vlc_gettext(const char *msgid) VLC_FORMAT_ARG(1);
+VLC_API const char *vlc_ngettext(const char *s, const char *p, unsigned long n)
+VLC_FORMAT_ARG(1) VLC_FORMAT_ARG(2);
 
 #define vlc_pgettext( ctx, id ) \
         vlc_pgettext_aux( ctx "\004" id, id )
diff --git a/modules/gui/skins2/src/theme_repository.cpp b/modules/gui/skins2/src/theme_repository.cpp
index 23f61e7328..fdb06fdbf1 100644
--- a/modules/gui/skins2/src/theme_repository.cpp
+++ b/modules/gui/skins2/src/theme_repository.cpp
@@ -55,7 +55,7 @@ ThemeRepository::ThemeRepository( intf_thread_t *pIntf ): SkinObject( pIntf )
 
     // Create a variable to add items in wxwindows popup menu
     var_Create( pIntf, "intf-skins", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
-    text.psz_string = _("Select skin");
+    text.psz_string = (char *)_("Select skin");
     var_Change( pIntf, "intf-skins", VLC_VAR_SETTEXT, &text );
 
     // Scan vlt files in the resource path
@@ -113,7 +113,7 @@ ThemeRepository::ThemeRepository( intf_thread_t *pIntf ): SkinObject( pIntf )
     // variable for opening a dialog box to change skins
     var_Create( pIntf, "intf-skins-interactive", VLC_VAR_VOID |
                 VLC_VAR_ISCOMMAND );
-    text.psz_string = _("Open skin...");
+    text.psz_string = (char *)_("Open skin...");
     var_Change( pIntf, "intf-skins-interactive", VLC_VAR_SETTEXT, &text );
 
     // Set the callback
diff --git a/src/misc/actions.c b/src/misc/actions.c
index 65178c1bf4..72a4398334 100644
--- a/src/misc/actions.c
+++ b/src/misc/actions.c
@@ -210,9 +210,9 @@ uint_fast32_t vlc_str2keycode (const char *name)
     return code;
 }
 
-static char *nooptext (const char *txt)
+static const char *nooptext (const char *txt)
 {
-    return (char *)txt;
+    return txt;
 }
 
 /**
@@ -225,7 +225,7 @@ static char *nooptext (const char *txt)
  */
 char *vlc_keycode2str (uint_fast32_t code, bool locale)
 {
-    char *(*tr) (const char *) = locale ? vlc_gettext : nooptext;
+    const char *(*tr)(const char *) = locale ? vlc_gettext : nooptext;
     const char *name;
     char *str, buf[5];
     uintptr_t key = code & ~KEY_MODIFIER;
diff --git a/src/modules/textdomain.c b/src/modules/textdomain.c
index bdeb936749..d16cecbdb5 100644
--- a/src/modules/textdomain.c
+++ b/src/modules/textdomain.c
@@ -76,20 +76,21 @@ int vlc_bindtextdomain (const char *domain)
 /**
  * In-tree plugins share their gettext domain with LibVLC.
  */
-char *vlc_gettext (const char *msgid)
+const char *vlc_gettext(const char *msgid)
 {
 #ifdef ENABLE_NLS
     if (likely(*msgid))
         return dgettext (PACKAGE_NAME, msgid);
 #endif
-    return (char *)msgid;
+    return msgid;
 }
 
-char *vlc_ngettext (const char *msgid, const char *plural, unsigned long n)
+const char *vlc_ngettext(const char *msgid, const char *plural,
+                         unsigned long n)
 {
 #ifdef ENABLE_NLS
     if (likely(*msgid))
         return dngettext (PACKAGE_NAME, msgid, plural, n);
 #endif
-    return (char *)((n == 1) ? msgid : plural);
+    return ((n == 1) ? msgid : plural);
 }



More information about the vlc-commits mailing list