[Git][cmucl/cmucl][master] 2 commits: Fix #141: Use setlocale to handle localization settings

Raymond Toy (@rtoy) gitlab at common-lisp.net
Mon Nov 14 05:09:52 UTC 2022



Raymond Toy pushed to branch master at cmucl / cmucl


Commits:
23f66902 by Raymond Toy at 2022-11-14T05:09:37+00:00
Fix #141: Use setlocale to handle localization settings

- - - - -
6764053d by Raymond Toy at 2022-11-14T05:09:38+00:00
Merge branch 'issue-141-locale' into 'master'

Fix #141: Use setlocale to handle localization settings

Closes #141, #136, #142, #146, #134, and #132

See merge request cmucl/cmucl!101
- - - - -


5 changed files:

- src/code/intl.lisp
- src/code/unix.lisp
- src/general-info/release-21e.md
- src/i18n/locale/cmucl-unix.pot
- src/lisp/os-common.c


Changes:

=====================================
src/code/intl.lisp
=====================================
@@ -520,10 +520,7 @@
 
 (defun setlocale (&optional locale)
   (setf *locale* (or locale
-		     (getenv "LANGUAGE")
-		     (getenv "LC_ALL")
-		     (getenv "LC_MESSAGES")
-		     (getenv "LANG")
+		     (unix::unix-get-lc-messages)
 		     *locale*)))
 
 (defmacro textdomain (domain)


=====================================
src/code/unix.lisp
=====================================
@@ -2899,3 +2899,19 @@
   (alien:alien-funcall
    (alien:extern-alien "os_setlocale"
 		       (function c-call:int))))
+
+(defun unix-get-lc-messages ()
+  _N"Get LC_MESSAGES from the current locale.  If we can't, return
+  NIL.  A call to UNIX-SETLOCALE must have been done previously before
+  calling this so that the correct locale is returned."
+  (with-alien ((buf (array c-call:char 256)))
+    (let ((result
+	    (alien-funcall
+	     (extern-alien "os_get_lc_messages"
+			   (function c-call:int
+				     (* c-call:char)
+				     c-call:int))
+	     (cast buf (* c-call:char))
+	     256)))
+      (when (zerop result)
+	(cast buf c-call:c-string)))))


=====================================
src/general-info/release-21e.md
=====================================
@@ -60,6 +60,7 @@ public domain.
     * ~~#134~~ Handle the case of `(expt complex complex-rational)`
     * ~~#136~~ `ensure-directories-exist` should return the given pathspec
     * #139 `*default-external-format*` defaults to `:utf-8`
+    * ~~#141~~ Disallow locales that are pathnames to a localedef file
     * ~~#142~~ `(random 0)` signals incorrect error
     * ~~#147~~ `stream-line-column` method missing for `fundamental-character-output-stream`
     * ~~#149~~ Call setlocale(3C) on startup


=====================================
src/i18n/locale/cmucl-unix.pot
=====================================
@@ -1428,3 +1428,10 @@ msgstr ""
 msgid "Call setlocale(3c) with fixed args.  Returns 0 on success."
 msgstr ""
 
+#: src/code/unix.lisp
+msgid ""
+"Get LC_MESSAGES from the current locale.  If we can't, return\n"
+"  NIL.  A call to UNIX-SETLOCALE must have been done previously before\n"
+"  calling this so that the correct locale is returned."
+msgstr ""
+


=====================================
src/lisp/os-common.c
=====================================
@@ -783,3 +783,16 @@ os_setlocale(void)
     /* Return 0 if setlocale suceeded; otherwise -1. */
     return result != NULL ? 0 : -1;
 }
+
+int
+os_get_lc_messages(char *buf, int len)
+{
+    char *locale = setlocale(LC_MESSAGES, NULL);
+    if (locale) {
+        strncpy(buf, locale, len - 1);
+        buf[len - 1] = '\0';
+    }
+
+    /* Return -1 if setlocale failed. */
+    return locale ? 0 : -1;
+}



View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/68f4ec706ced2efdf3e17f881adf01cd16f5e0c5...6764053dd9530292197b47ff9b7af22d90735232

-- 
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/68f4ec706ced2efdf3e17f881adf01cd16f5e0c5...6764053dd9530292197b47ff9b7af22d90735232
You're receiving this email because of your account on gitlab.common-lisp.net.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cmucl-cvs/attachments/20221114/d09bbc4f/attachment-0001.html>


More information about the cmucl-cvs mailing list