Raymond Toy pushed to branch issue-139-add-alias-local-external-format at cmucl / cmucl

Commits:

9 changed files:

Changes:

  • src/code/extfmts.lisp
    ... ... @@ -22,7 +22,7 @@
    22 22
     	  describe-external-format))
    
    23 23
     
    
    24 24
     (defvar *default-external-format*
    
    25
    -  :iso8859-1
    
    25
    +  :utf-8
    
    26 26
       "The default external format to use if no other external format is
    
    27 27
       specified")
    
    28 28
     
    

  • src/code/filesys.lisp
    ... ... @@ -1079,13 +1079,21 @@ optionally keeping some of the most recent old versions."
    1079 1079
     		 :pathname file
    
    1080 1080
     		 :format-control (intl:gettext "~S doesn't exist.")
    
    1081 1081
     		 :format-arguments (list file)))
    
    1082
    -	(multiple-value-bind (winp dev ino mode nlink uid)
    
    1083
    -			     (unix:unix-stat name)
    
    1084
    -	  (declare (ignore dev ino mode nlink))
    
    1085
    -	  (when winp
    
    1086
    -            (let ((user-info (unix:unix-getpwuid uid)))
    
    1087
    -              (when user-info
    
    1088
    -                (unix:user-info-name user-info))))))))
    
    1082
    +	;; unix-namestring converts "." to "".  Convert it back to
    
    1083
    +	;; "." so we can stat the current directory.  (Perhaps
    
    1084
    +	;; that's a bug in unix-namestring?)
    
    1085
    +	(when (zerop (length name))
    
    1086
    +	  (setf name "."))
    
    1087
    +	(let (author)
    
    1088
    +	  (unwind-protect
    
    1089
    +	       (progn
    
    1090
    +		 (setf author (alien:alien-funcall
    
    1091
    +			       (alien:extern-alien "os_file_author"
    
    1092
    +						   (function (alien:* c-call:c-string) c-call:c-string))
    
    1093
    +			       (unix::%name->file name)))
    
    1094
    +		 (unless (alien:null-alien author)
    
    1095
    +		   (alien:cast author c-call:c-string)))
    
    1096
    +	    (alien:free-alien author))))))
    
    1089 1097
     
    
    1090 1098
     
    
    1091 1099
     ;;;; DIRECTORY.
    

  • src/general-info/release-21e.md
    ... ... @@ -22,6 +22,7 @@ public domain.
    22 22
       * Feature enhancements
    
    23 23
       * Changes
    
    24 24
         * Update to ASDF 3.3.6
    
    25
    +    * The default external format is `:utf-8` instead of `:iso8859-1`
    
    25 26
       * ANSI compliance fixes:
    
    26 27
       * Bug fixes:
    
    27 28
         * ~~#97~~ Fixes stepping through the source forms in the debugger.  This has been broken for quite some time, but it works now.
    
    ... ... @@ -56,6 +57,7 @@ public domain.
    56 57
         * ~~#132~~ Ansi test `RENAME-FILE.1` no fails
    
    57 58
         * ~~#134~~ Handle the case of `(expt complex complex-rational)`
    
    58 59
         * ~~#136~~ `ensure-directories-exist` should return the given pathspec
    
    60
    +    * #139 `*default-external-format*` defaults to `:utf-8`
    
    59 61
         * ~~#142~~ `(random 0)` signals incorrect error
    
    60 62
       * Other changes:
    
    61 63
       * Improvements to the PCL implementation of CLOS:
    

  • src/lisp/os-common.c
    ... ... @@ -5,12 +5,16 @@
    5 5
     
    
    6 6
     */
    
    7 7
     
    
    8
    +#include <assert.h>
    
    8 9
     #include <errno.h>
    
    9 10
     #include <math.h>
    
    10 11
     #include <netdb.h>
    
    12
    +#include <pwd.h>
    
    11 13
     #include <stdio.h>
    
    14
    +#include <stdlib.h>
    
    12 15
     #include <string.h>
    
    13 16
     #include <sys/stat.h>
    
    17
    +#include <unistd.h>
    
    14 18
     #include <time.h>
    
    15 19
     
    
    16 20
     #include "os.h"
    
    ... ... @@ -715,3 +719,57 @@ os_lstat(const char* path, u_int64_t *dev, u_int64_t *ino, unsigned int *mode, u
    715 719
     
    
    716 720
         return rc;
    
    717 721
     }
    
    722
    +
    
    723
    +/*
    
    724
    + * Interface for file-author.  Given a pathname, returns a new string
    
    725
    + * holding the author of the file or NULL if some error occurred.  The
    
    726
    + * caller is responsible for freeing the memory used by the string.
    
    727
    + */
    
    728
    +char *
    
    729
    +os_file_author(const char *path)
    
    730
    +{
    
    731
    +    struct stat sb;
    
    732
    +    char initial[1024];
    
    733
    +    char *buffer, *obuffer;
    
    734
    +    size_t size;
    
    735
    +    struct passwd pwd;
    
    736
    +    struct passwd *ppwd;
    
    737
    +    char *result;
    
    738
    +
    
    739
    +    if (stat(path, &sb) != 0) {
    
    740
    +        return NULL;
    
    741
    +    }
    
    742
    +
    
    743
    +    result = NULL;
    
    744
    +    buffer = initial;
    
    745
    +    obuffer = NULL;
    
    746
    +    size = sizeof(initial) / sizeof(initial[0]);
    
    747
    +
    
    748
    +    /*
    
    749
    +     * Keep trying with larger buffers until a maximum is reached.  We
    
    750
    +     * assume (1 << 20) is large enough for any OS.
    
    751
    +     */
    
    752
    +    while (size <= (1 << 20)) {
    
    753
    +        switch (getpwuid_r(sb.st_uid, &pwd, buffer, size, &ppwd)) {
    
    754
    +          case 0:
    
    755
    +              /* Success, though we might not have a matching entry */
    
    756
    +              result = (ppwd == NULL) ? NULL : strdup(pwd.pw_name);
    
    757
    +              goto exit;
    
    758
    +          case ERANGE:
    
    759
    +              /* Buffer is too small, double its size and try again */
    
    760
    +              size *= 2;
    
    761
    +              obuffer = (buffer == initial) ? NULL : buffer;
    
    762
    +              if ((buffer = realloc(obuffer, size)) == NULL) {
    
    763
    +                  goto exit;
    
    764
    +              }
    
    765
    +              continue;
    
    766
    +          default:
    
    767
    +              /* All other errors */
    
    768
    +              goto exit;
    
    769
    +        }
    
    770
    +    }
    
    771
    +exit:
    
    772
    +    free(obuffer);
    
    773
    +    
    
    774
    +    return result;
    
    775
    +}

  • src/pcl/gray-streams.lisp
    ... ... @@ -235,6 +235,9 @@
    235 235
       defined for this function, although it is permissible for it to
    
    236 236
       always return NIL."))
    
    237 237
     
    
    238
    +(defmethod stream-line-column ((stream fundamental-character-output-stream))
    
    239
    +  nil)
    
    240
    +
    
    238 241
     ;;; Stream-line-length is a CMUCL extension to Gray streams.
    
    239 242
     (defgeneric stream-line-length (stream)
    
    240 243
       (:documentation _N"Return the stream line length or Nil."))
    

  • tests/.gitignore
    1
    +/out-utf8.txt

  • tests/issues.lisp
    ... ... @@ -5,6 +5,12 @@
    5 5
     
    
    6 6
     (in-package "ISSUES-TESTS")
    
    7 7
     
    
    8
    +(defparameter *test-path*
    
    9
    +  (merge-pathnames (make-pathname :name :unspecific :type :unspecific
    
    10
    +                                  :version :unspecific)
    
    11
    +                   *load-truename*)
    
    12
    +  "Path to where this file is.")
    
    13
    +
    
    8 14
     (defun square (x)
    
    9 15
       (expt x 2))
    
    10 16
     
    
    ... ... @@ -670,3 +676,72 @@
    670 676
     		 (err (relerr value answer)))
    
    671 677
     	    (assert-true (<= err eps) base err eps)))))))
    
    672 678
     
    
    679
    +(define-test issue.130
    
    680
    +    (:tag :issues)
    
    681
    +  ;; Just verify that file-author works.  In particular "." should
    
    682
    +  ;; work and not return NIL.
    
    683
    +  (assert-true (file-author "."))
    
    684
    +  (assert-true (file-author "bin/build.sh"))
    
    685
    +  (let ((unix::*filename-encoding* :utf-8))
    
    686
    +    ;; Set filename encoding to utf-8 so that we can encode the
    
    687
    +    ;; filename properly.
    
    688
    +    (assert-true
    
    689
    +   (file-author
    
    690
    +    (merge-pathnames 
    
    691
    +     (concatenate 'string
    
    692
    +		  ;; Write the test file name this way so
    
    693
    +		  ;; that it's independent of the encoding
    
    694
    +		  ;; used to load this file.  The name is
    
    695
    +		  ;; "안녕하십니까".
    
    696
    +		  '(#\Hangul_Syllable_An #\Hangul_Syllable_Nyeong #\Hangul_Syllable_Ha
    
    697
    +		    #\Hangul_Syllable_Sib #\Hangul_Syllable_Ni #\Hangul_Syllable_Gga)
    
    698
    +		  ".txt")
    
    699
    +     *test-path*)))))
    
    700
    +
    
    701
    +(define-test issue.139-default-external-format
    
    702
    +    (:tag :issues)
    
    703
    +  (assert-eq :utf-8 stream:*default-external-format*))
    
    704
    +
    
    705
    +(define-test issue.139-default-external-format-read-file
    
    706
    +    (:tag :issues)
    
    707
    +  (let ((string (concatenate 'string
    
    708
    +			     ;; This is "hello" in Korean
    
    709
    +			     '(#\Hangul_syllable_an
    
    710
    +			       #\Hangul_Syllable_Nyeong
    
    711
    +			       #\Hangul_Syllable_Ha
    
    712
    +			       #\Hangul_Syllable_Se
    
    713
    +			       #\Hangul_Syllable_Yo))))
    
    714
    +    ;; Test that opening a file for reading uses the the default :utf8
    
    715
    +    ;; encoding.
    
    716
    +    (with-open-file (s (merge-pathnames "utf8.txt"
    
    717
    +					*test-path*)
    
    718
    +		       :direction :input)
    
    719
    +      ;; The first line should be "hello" in Hangul.
    
    720
    +      (assert-equal (map 'list #'char-name string)
    
    721
    +		    (map 'list #'char-name (read-line s))))))
    
    722
    +
    
    723
    +(define-test issue.139-default-external-format-write-file
    
    724
    +    (:tag :issues)
    
    725
    +  ;; Test that opening a file for writing uses the default :utf8.
    
    726
    +  ;; First write something out to the file.  Then read it back in
    
    727
    +  ;; using an explicit format of utf8 and verifying that we got the
    
    728
    +  ;; right contents.
    
    729
    +  (let ((string (concatenate 'string
    
    730
    +			     ;; This is "hello" in Korean
    
    731
    +			     '(#\Hangul_syllable_an
    
    732
    +			       #\Hangul_Syllable_Nyeong
    
    733
    +			       #\Hangul_Syllable_Ha
    
    734
    +			       #\Hangul_Syllable_Se
    
    735
    +			       #\Hangul_Syllable_Yo))))
    
    736
    +    (with-open-file (s (merge-pathnames "out-utf8.txt"
    
    737
    +					*test-path*)
    
    738
    +		       :direction :output
    
    739
    +		       :if-exists :supersede)
    
    740
    +      (write-line string s))
    
    741
    +    (with-open-file (s (merge-pathnames "out-utf8.txt"
    
    742
    +					*test-path*)
    
    743
    +		       :direction :input
    
    744
    +		       :external-format :utf-8)
    
    745
    +      (assert-equal (map 'list #'char-name string)
    
    746
    +		    (map 'list #'char-name (read-line s))))))
    
    747
    +  

  • tests/utf8.txt
    1
    +안녕하세요
    
    2
    +UTF8 test.  The above line is "Hello" in Hangul.

  • tests/안녕하십니까.txt
    1
    +The file name of this file is "안녕하십니까.txt" ("Hello" in Korean.)
    
    2
    +
    
    3
    +