Raymond Toy pushed to branch master at cmucl / cmucl

Commits:

7 changed files:

Changes:

  • src/code/save.lisp
    ... ... @@ -142,6 +142,30 @@
    142 142
       (file c-call:c-string)
    
    143 143
       (initial-function (alien:unsigned #.vm:word-bits)))
    
    144 144
     
    
    145
    +(defun set-up-locale-external-format ()
    
    146
    +  "Add external format alias for :locale to the format specified by
    
    147
    +  the locale as set by setlocale(3C)."
    
    148
    +  (let ((codeset (unix::unix-get-locale-codeset)))
    
    149
    +    (cond ((zerop (length codeset))
    
    150
    +	   ;; Codeset was the empty string, so just set :locale to
    
    151
    +	   ;; alias to the default external format.  
    
    152
    +	   (setf (gethash :locale stream::*external-format-aliases*)
    
    153
    +		 *default-external-format*))
    
    154
    +	  (t
    
    155
    +	   (let ((codeset-format (intern codeset "KEYWORD")))
    
    156
    +	     ;; If we know the format, we can set the alias.
    
    157
    +	     ;; Otherwise, print a warning and use :iso8859-1 as the
    
    158
    +	     ;; alias.
    
    159
    +	     (setf (gethash :locale stream::*external-format-aliases*)
    
    160
    +		   (if (stream::find-external-format codeset-format nil)
    
    161
    +		       codeset-format
    
    162
    +		       (progn
    
    163
    +			 (warn "Unsupported external format; using :iso8859-1 instead: ~S"
    
    164
    +			       codeset-format)
    
    165
    +			 :iso8859-1)))))))
    
    166
    +  (values))
    
    167
    +
    
    168
    + 
    
    145 169
     (defun save-lisp (core-file-name &key
    
    146 170
     				 (purify t)
    
    147 171
     				 (root-structures ())
    
    ... ... @@ -252,8 +276,13 @@
    252 276
     	     ;; Set the runtime locale
    
    253 277
     	     (unless (zerop (unix::unix-setlocale))
    
    254 278
     	       (warn "os_setlocale failed"))
    
    279
    +	     ;; Load external format aliases now so we can aliases to
    
    280
    +	     ;; specify the external format.
    
    281
    +	     (stream::load-external-format-aliases)
    
    255 282
     	     ;; Set the locale for lisp
    
    256 283
     	     (intl::setlocale)
    
    284
    +	     ;; Set up :locale format
    
    285
    +	     (set-up-locale-external-format)
    
    257 286
     	     (ext::process-command-strings process-command-line)
    
    258 287
     	     (setf *editor-lisp-p* nil)
    
    259 288
     	     (macrolet ((find-switch (name)
    

  • src/code/unix.lisp
    ... ... @@ -2915,3 +2915,10 @@
    2915 2915
     	     256)))
    
    2916 2916
           (when (zerop result)
    
    2917 2917
     	(cast buf c-call:c-string)))))
    
    2918
    +
    
    2919
    +(defun unix-get-locale-codeset ()
    
    2920
    +  _N"Get the codeset from the locale"
    
    2921
    +  (cast (alien-funcall
    
    2922
    +	    (extern-alien "os_get_locale_codeset"
    
    2923
    +			  (function (* char))))
    
    2924
    +	c-string))

  • src/general-info/release-21e.md
    ... ... @@ -59,7 +59,7 @@ public domain.
    59 59
         * ~~#132~~ Ansi test `RENAME-FILE.1` no fails
    
    60 60
         * ~~#134~~ Handle the case of `(expt complex complex-rational)`
    
    61 61
         * ~~#136~~ `ensure-directories-exist` should return the given pathspec
    
    62
    -    * #139 `*default-external-format*` defaults to `:utf-8`
    
    62
    +    * #139 `*default-external-format*` defaults to `:utf-8`; add alias for `:locale` external format
    
    63 63
         * ~~#140~~ External format for streams that are not `file-stream`'s
    
    64 64
         * ~~#141~~ Disallow locales that are pathnames to a localedef file
    
    65 65
         * ~~#142~~ `(random 0)` signals incorrect error
    

  • src/i18n/locale/cmucl-unix.pot
    ... ... @@ -1435,3 +1435,7 @@ msgid ""
    1435 1435
     "  calling this so that the correct locale is returned."
    
    1436 1436
     msgstr ""
    
    1437 1437
     
    
    1438
    +#: src/code/unix.lisp
    
    1439
    +msgid "Get the codeset from the locale"
    
    1440
    +msgstr ""
    
    1441
    +

  • src/i18n/locale/cmucl.pot
    ... ... @@ -6714,6 +6714,12 @@ msgid ""
    6714 6714
     "This is true if and only if the lisp was started with the -edit switch."
    
    6715 6715
     msgstr ""
    
    6716 6716
     
    
    6717
    +#: src/code/save.lisp
    
    6718
    +msgid ""
    
    6719
    +"Add external format alias for :locale to the format specified by\n"
    
    6720
    +"  the locale as set by setlocale(3C)."
    
    6721
    +msgstr ""
    
    6722
    +
    
    6717 6723
     #: src/code/save.lisp
    
    6718 6724
     msgid ""
    
    6719 6725
     "Saves a CMU Common Lisp core image in the file of the specified name.  The\n"
    

  • src/lisp/os-common.c
    ... ... @@ -7,6 +7,7 @@
    7 7
     
    
    8 8
     #include <assert.h>
    
    9 9
     #include <errno.h>
    
    10
    +#include <langinfo.h>
    
    10 11
     #include <locale.h>
    
    11 12
     #include <math.h>
    
    12 13
     #include <netdb.h>
    
    ... ... @@ -796,3 +797,9 @@ os_get_lc_messages(char *buf, int len)
    796 797
         /* Return -1 if setlocale failed. */
    
    797 798
         return locale ? 0 : -1;
    
    798 799
     }
    
    800
    +
    
    801
    +char *
    
    802
    +os_get_locale_codeset()
    
    803
    +{
    
    804
    +    return nl_langinfo(CODESET);
    
    805
    +}

  • tests/issues.lisp
    ... ... @@ -745,6 +745,11 @@
    745 745
           (assert-equal (map 'list #'char-name string)
    
    746 746
     		    (map 'list #'char-name (read-line s))))))
    
    747 747
       
    
    748
    +(define-test issue.139-locale-external-format
    
    749
    +    (:tag :issues)
    
    750
    +  ;; Just verify that :locale format exists
    
    751
    +  (assert-true (stream::find-external-format :locale nil)))
    
    752
    +
    
    748 753
     ;;; Test stream-external-format for various types of streams.
    
    749 754
     
    
    750 755
     (define-test issue.140.two-way-stream
    
    ... ... @@ -792,7 +797,6 @@
    792 797
     		      (stream-external-format
    
    793 798
     		       (make-broadcast-stream s1 s2 s3)))))))
    
    794 799
     
    
    795
    -
    
    796 800
     (define-test issue.150
    
    797 801
         (:tag :issues)
    
    798 802
       (let ((ext:*gc-verbose* nil)