Raymond Toy pushed to branch master at cmucl / cmucl

Commits:

13 changed files:

Changes:

  • src/code/exports.lisp
    ... ... @@ -1211,7 +1211,9 @@
    1211 1211
     
    
    1212 1212
     	     "*TRUST-DYNAMIC-EXTENT-DECLARATIONS*"
    
    1213 1213
     
    
    1214
    -	     "INVALID-FASL")
    
    1214
    +	     "INVALID-FASL"
    
    1215
    +	     "WITH-TEMPORARY-DIRECTORY"
    
    1216
    +	     "WITH-TEMPORARY-FILE")
    
    1215 1217
       ;; gencgc features
    
    1216 1218
       #+gencgc
    
    1217 1219
       (:export "GET-GC-ASSERTIONS"
    

  • src/code/extensions.lisp
    ... ... @@ -612,3 +612,108 @@
    612 612
       "Return an EQ hash of X.  The value of this hash for any given object can (of
    
    613 613
       course) change at arbitary times."
    
    614 614
       `(lisp::pointer-hash ,x))
    
    615
    +
    
    616
    +
    
    617
    +(defun get-os-temp-path ()
    
    618
    +  "Get a path to an appropriate temporary location from the OS.  A string
    
    619
    +  is returned to that path.  The path ends with a \"/\" character."
    
    620
    +  (let ((path (alien:alien-funcall
    
    621
    +	       (alien:extern-alien "os_temporary_directory"
    
    622
    +				   (function (alien:* c-call:char))))))
    
    623
    +    (when (alien:null-alien path)
    
    624
    +      (error "Unable to find path to temporary directory"))
    
    625
    +
    
    626
    +    (unwind-protect
    
    627
    +	 (unix::%file->name (cast path c-call:c-string))
    
    628
    +      (unless (alien:null-alien path)
    
    629
    +	(alien:free-alien path)))))
    
    630
    +
    
    631
    +;; Create a template suitable for mkstemp and mkdtemp.  DIRECTORY is
    
    632
    +;; the directory for the template.  If DIRECTORY is NIL, an
    
    633
    +;; OS-dependent location is used.  PREFIX is string that is the prefix
    
    634
    +;; for the filename for the template.  In all cases, we append exactly
    
    635
    +;; 6 X's to create the finale template.
    
    636
    +(defun create-template (directory prefix)
    
    637
    +  (concatenate 'string
    
    638
    +	       (or directory
    
    639
    +		   (get-os-temp-path))
    
    640
    +	       "/"
    
    641
    +	       prefix
    
    642
    +	       "XXXXXX"))
    
    643
    +
    
    644
    +;;; WITH-TEMPORARY-FILE  -- Public
    
    645
    +(defmacro with-temporary-file ((filename &key directory (prefix "cmucl-temp-file-"))
    
    646
    +			       &parse-body (forms decls))
    
    647
    +  _N"Creates a temporary file with a name bound to Filename which a
    
    648
    + namestring.  If Directory is not provided, the temporary file is created
    
    649
    + in a OS-dependent location.  The Prefix is a prefix to the file name
    
    650
    + to be created.  If not provided a default prefix is used.
    
    651
    + On completion, the file is automatically removed."
    
    652
    +  (let ((fd (gensym "FD-"))
    
    653
    +	(file-template (gensym "TEMP-PATH-"))
    
    654
    +	(unique-filename (gensym "UNIQUE-FILENAME-")))
    
    655
    +    `(let ((,file-template (create-template ,directory ,prefix))
    
    656
    +	   ,unique-filename)
    
    657
    +       (unwind-protect
    
    658
    +	    (let (,fd)
    
    659
    +	      (multiple-value-setq (,fd ,unique-filename)
    
    660
    +		(unix::unix-mkstemp ,file-template))
    
    661
    +	      (unless ,fd
    
    662
    +		(error "Unable to create temporary file with template ~S: ~A~%"
    
    663
    +		       ,file-template
    
    664
    +		       (unix:get-unix-error-msg ,unique-filename)))
    
    665
    +	      (unix:unix-close ,fd)
    
    666
    +	      (setf ,filename (pathname ,unique-filename))
    
    667
    +	      (locally ,@decls
    
    668
    +		,@forms))
    
    669
    +	 ;; We're done so delete the temp file, if one was created.
    
    670
    +	 (when (pathnamep ,filename)
    
    671
    +	   (delete-file ,filename))))))
    
    672
    +
    
    673
    +(defun delete-directory (dirname &key recursive)
    
    674
    +  _N"Delete the directory Dirname.  If the Recursive is non-NIL,
    
    675
    +  recursively delete the directory Dirname including all files and
    
    676
    +  subdirectories. Dirname must be a pathname to a directory.  Any NAME
    
    677
    +  or TYPE components in Dirname are ignored."
    
    678
    +  (declare (type pathname dirname))
    
    679
    +  (when recusive
    
    680
    +    ;; Find all the files or directories in DIRNAME.
    
    681
    +    (dolist (path (directory (merge-pathnames "*.*" dirname)))
    
    682
    +      ;; If the path is a directory, recursively delete the directory.
    
    683
    +      ;; Otherwise delete the file.  We do not follow any symlinks.
    
    684
    +      (if (eq (unix:unix-file-kind (namestring path)) :directory)
    
    685
    +	  (delete-directory path :recursive t)
    
    686
    +	  (delete-file path))))
    
    687
    +  ;; Finally delete the directory.
    
    688
    +  (unix:unix-rmdir (namestring dirname))
    
    689
    +  (values))
    
    690
    +
    
    691
    +
    
    692
    +;;; WITH-TEMPORARY-DIRECTORY  -- Public
    
    693
    +(defmacro with-temporary-directory ((dirname &key directory (prefix  "cmucl-temp-dir-"))
    
    694
    +				    &parse-body (forms decls))
    
    695
    + _N"Return a namestring to a temporary directory.  If Directory is not
    
    696
    + provided, the directory is created in an OS-dependent location.  The
    
    697
    + Prefix is a string that is used as a prefix for the name of the
    
    698
    + temporary directory.  If Prefix is not given, a default prefix is
    
    699
    + used.  The directory and all its contents are automatically removed
    
    700
    + afterward."
    
    701
    +  (let ((err (gensym "ERR-"))
    
    702
    +	(dir-template (gensym "DIR-TEMPLATE-")))
    
    703
    +    `(let ((,dir-template (create-template ,directory ,prefix))
    
    704
    +	   ,dirname ,err)
    
    705
    +       (unwind-protect
    
    706
    +	    (progn
    
    707
    +	      (multiple-value-setq (,dirname ,err)
    
    708
    +		(unix::unix-mkdtemp ,dir-template))
    
    709
    +	      (unless ,dirname
    
    710
    +		(error "Unable to create temporary directory at ~S: ~A"
    
    711
    +		       ,dir-template
    
    712
    +		       (unix:get-unix-error-msg ,err)))
    
    713
    +	      (setf ,dirname (pathname (concatenate 'string ,dirname "/")))
    
    714
    +	      (locally ,@decls
    
    715
    +		,@forms))
    
    716
    +	 ;; If a temp directory was created, remove it and all its
    
    717
    +	 ;; contents.  Is there a better way?
    
    718
    +	 (when ,dirname
    
    719
    +	   (delete-directory ,dirname :recursive t))))))

  • src/code/pprint.lisp
    ... ... @@ -2092,7 +2092,8 @@ When annotations are present, invoke them at the right positions."
    2092 2092
         (c:deftransform pprint-defun)
    
    2093 2093
         (c:defoptimizer pprint-defun)
    
    2094 2094
         (ext:with-float-traps-masked pprint-with-like)
    
    2095
    -    (ext:with-float-traps-enabled pprint-with-like)))
    
    2095
    +    (ext:with-float-traps-enabled pprint-with-like)
    
    2096
    +    (ext::with-temporary-directory pprint-with-like)))
    
    2096 2097
     
    
    2097 2098
     (defun pprint-init ()
    
    2098 2099
       (setf *initial-pprint-dispatch* (make-pprint-dispatch-table))
    

  • src/i18n/locale/cmucl.pot
    ... ... @@ -5992,6 +5992,39 @@ msgid ""
    5992 5992
     "  course) change at arbitary times."
    
    5993 5993
     msgstr ""
    
    5994 5994
     
    
    5995
    +#: src/code/extensions.lisp
    
    5996
    +msgid ""
    
    5997
    +"Get a path to an appropriate temporary location from the OS.  A string\n"
    
    5998
    +"  is returned to that path.  The path ends with a \"/\" character."
    
    5999
    +msgstr ""
    
    6000
    +
    
    6001
    +#: src/code/extensions.lisp
    
    6002
    +msgid ""
    
    6003
    +"Creates a temporary file with a name bound to Filename which a\n"
    
    6004
    +" namestring.  If Directory is not provided, the temporary file is created\n"
    
    6005
    +" in a OS-dependent location.  The Prefix is a prefix to the file name\n"
    
    6006
    +" to be created.  If not provided a default prefix is used.\n"
    
    6007
    +" On completion, the file is automatically removed."
    
    6008
    +msgstr ""
    
    6009
    +
    
    6010
    +#: src/code/extensions.lisp
    
    6011
    +msgid ""
    
    6012
    +"Delete the directory Dirname.  If the Recursive is non-NIL,\n"
    
    6013
    +"  recursively delete the directory Dirname including all files and\n"
    
    6014
    +"  subdirectories. Dirname must be a pathname to a directory.  Any NAME\n"
    
    6015
    +"  or TYPE components in Dirname are ignored."
    
    6016
    +msgstr ""
    
    6017
    +
    
    6018
    +#: src/code/extensions.lisp
    
    6019
    +msgid ""
    
    6020
    +"Return a namestring to a temporary directory.  If Directory is not\n"
    
    6021
    +" provided, the directory is created in an OS-dependent location.  The\n"
    
    6022
    +" Prefix is a string that is used as a prefix for the name of the\n"
    
    6023
    +" temporary directory.  If Prefix is not given, a default prefix is\n"
    
    6024
    +" used.  The directory and all its contents are automatically removed\n"
    
    6025
    +" afterward."
    
    6026
    +msgstr ""
    
    6027
    +
    
    5995 6028
     #: src/code/commandline.lisp
    
    5996 6029
     msgid "A list of all the command line arguments after --"
    
    5997 6030
     msgstr ""
    

  • src/lisp/Darwin-os.c
    ... ... @@ -23,6 +23,7 @@
    23 23
     #include <dlfcn.h>
    
    24 24
     #include <string.h>
    
    25 25
     #include <assert.h>
    
    26
    +#include <unistd.h>
    
    26 27
     
    
    27 28
     #include "os.h"
    
    28 29
     #include "arch.h"
    
    ... ... @@ -571,3 +572,30 @@ os_support_sse2()
    571 572
         return TRUE;
    
    572 573
     }
    
    573 574
     #endif
    
    575
    +
    
    576
    +/*
    
    577
    + * Return a new string containing the path to an OS-dependent location
    
    578
    + * where temporary files/directories can be stored.  If NULL is
    
    579
    + * returned, such a location could not be found or some other error
    
    580
    + * happened.
    
    581
    + *
    
    582
    + * Caller must call free() on the string returned.
    
    583
    + */
    
    584
    +char *
    
    585
    +os_temporary_directory(void)
    
    586
    +{
    
    587
    +    /*
    
    588
    +     * macosx has a secure per-user temporary directory.
    
    589
    +     * Don't cache the result as this is only called once.
    
    590
    +     */
    
    591
    +    size_t len;
    
    592
    +    char path[PATH_MAX];
    
    593
    +
    
    594
    +    len = confstr(_CS_DARWIN_USER_TEMP_DIR, path, PATH_MAX);
    
    595
    +    if (len == 0 || len > PATH_MAX || (len == PATH_MAX && path[len - 1] != '/')) {
    
    596
    +	strlcpy(path, "/tmp/");
    
    597
    +    } else if (path[len - 1] != '/') {
    
    598
    +	strcat(path, "/");
    
    599
    +    }
    
    600
    +    return strdup(path);
    
    601
    +}

  • src/lisp/FreeBSD-os.c
    ... ... @@ -362,3 +362,37 @@ os_support_sse2()
    362 362
         return TRUE;
    
    363 363
     }
    
    364 364
     #endif
    
    365
    +
    
    366
    +/*
    
    367
    + * Return a new string containing the path to an OS-dependent location
    
    368
    + * where temporary files/directories can be stored.  The string must
    
    369
    + * end with a slash.  If NULL is returned, such a location could not
    
    370
    + * be found or some other error happened.
    
    371
    + *
    
    372
    + * Caller must call free() on the string returned.
    
    373
    + */
    
    374
    +char *
    
    375
    +os_temporary_directory(void)
    
    376
    +{
    
    377
    +    /*
    
    378
    +     * If the TMP envvar is set, use that as the temporary directory.
    
    379
    +     * Otherwise, just assume "/tmp" will work.
    
    380
    +     */
    
    381
    +    char *tmp;
    
    382
    +    size_t len;
    
    383
    +    char *result;
    
    384
    +
    
    385
    +    tmp = getenv("TMP");
    
    386
    +    if (tmp == NULL) {
    
    387
    +	return strdup("/tmp/");
    
    388
    +    }
    
    389
    +    len = strlen(tmp);
    
    390
    +    if (tmp[len] == '/') {
    
    391
    +	return strdup(tmp);
    
    392
    +    }
    
    393
    +    result = malloc(len + 2);
    
    394
    +    if (result) {
    
    395
    +	sprintf(result, "%s/", tmp);
    
    396
    +    }
    
    397
    +    return result;
    
    398
    +}

  • src/lisp/Linux-os.c
    ... ... @@ -628,3 +628,37 @@ os_support_sse2(void)
    628 628
         return TRUE;
    
    629 629
     }
    
    630 630
     #endif
    
    631
    +
    
    632
    +/*
    
    633
    + * Return a new string containing the path to an OS-dependent location
    
    634
    + * where temporary files/directories can be stored.  The string must
    
    635
    + * end with a slash.  If NULL is returned, such a location could not
    
    636
    + * be found or some other error happened.
    
    637
    + *
    
    638
    + * Caller must call free() on the string returned.
    
    639
    + */
    
    640
    +char *
    
    641
    +os_temporary_directory(void)
    
    642
    +{
    
    643
    +    /*
    
    644
    +     * If the TMP envvar is set, use that as the temporary directory.
    
    645
    +     * Otherwise, just assume "/tmp" will work.
    
    646
    +     */
    
    647
    +    char *tmp;
    
    648
    +    size_t len;
    
    649
    +    char *result;
    
    650
    +
    
    651
    +    tmp = getenv("TMP");
    
    652
    +    if (tmp == NULL) {
    
    653
    +	return strdup("/tmp/");
    
    654
    +    }
    
    655
    +    len = strlen(tmp);
    
    656
    +    if (tmp[len] == '/') {
    
    657
    +	return strdup(tmp);
    
    658
    +    }
    
    659
    +    result = malloc(len + 2);
    
    660
    +    if (result) {
    
    661
    +	sprintf(result, "%s/", tmp);
    
    662
    +    }
    
    663
    +    return result;
    
    664
    +}

  • src/lisp/NetBSD-os.c
    ... ... @@ -427,3 +427,37 @@ os_support_sse2()
    427 427
     	return FALSE;
    
    428 428
     }
    
    429 429
     #endif
    
    430
    +
    
    431
    +/*
    
    432
    + * Return a new string containing the path to an OS-dependent location
    
    433
    + * where temporary files/directories can be stored.  The string must
    
    434
    + * end with a slash.  If NULL is returned, such a location could not
    
    435
    + * be found or some other error happened.
    
    436
    + *
    
    437
    + * Caller must call free() on the string returned.
    
    438
    + */
    
    439
    +char *
    
    440
    +os_temporary_directory(void)
    
    441
    +{
    
    442
    +    /*
    
    443
    +     * If the TMP envvar is set, use that as the temporary directory.
    
    444
    +     * Otherwise, just assume "/tmp" will work.
    
    445
    +     */
    
    446
    +    char *tmp;
    
    447
    +    size_t len;
    
    448
    +    char *result;
    
    449
    +
    
    450
    +    tmp = getenv("TMP");
    
    451
    +    if (tmp == NULL) {
    
    452
    +	return strdup("/tmp/");
    
    453
    +    }
    
    454
    +    len = strlen(tmp);
    
    455
    +    if (tmp[len] == '/') {
    
    456
    +	return strdup(tmp);
    
    457
    +    }
    
    458
    +    result = malloc(len + 2);
    
    459
    +    if (result) {
    
    460
    +	sprintf(result, "%s/", tmp);
    
    461
    +    }
    
    462
    +    return result;
    
    463
    +}

  • src/lisp/OpenBSD-os.c
    ... ... @@ -190,3 +190,37 @@ os_install_interrupt_handlers(void)
    190 190
         interrupt_install_low_level_handler(SIGSEGV, sigsegv_handler);
    
    191 191
         interrupt_install_low_level_handler(SIGBUS, sigbus_handler);
    
    192 192
     }
    
    193
    +
    
    194
    +/*
    
    195
    + * Return a new string containing the path to an OS-dependent location
    
    196
    + * where temporary files/directories can be stored.  The string must
    
    197
    + * end with a slash.  If NULL is returned, such a location could not
    
    198
    + * be found or some other error happened.
    
    199
    + *
    
    200
    + * Caller must call free() on the string returned.
    
    201
    + */
    
    202
    +char *
    
    203
    +os_temporary_directory(void)
    
    204
    +{
    
    205
    +    /*
    
    206
    +     * If the TMP envvar is set, use that as the temporary directory.
    
    207
    +     * Otherwise, just assume "/tmp" will work.
    
    208
    +     */
    
    209
    +    char *tmp;
    
    210
    +    size_t len;
    
    211
    +    char *result;
    
    212
    +
    
    213
    +    tmp = getenv("TMP");
    
    214
    +    if (tmp == NULL) {
    
    215
    +	return strdup("/tmp/");
    
    216
    +    }
    
    217
    +    len = strlen(tmp);
    
    218
    +    if (tmp[len] == '/') {
    
    219
    +	return strdup(tmp);
    
    220
    +    }
    
    221
    +    result = malloc(len + 2);
    
    222
    +    if (result) {
    
    223
    +	sprintf(result, "%s/", tmp);
    
    224
    +    }
    
    225
    +    return result;
    
    226
    +}

  • src/lisp/os-common.c
    ... ... @@ -26,6 +26,9 @@
    26 26
     #include <sys/utsname.h>
    
    27 27
     #include <unistd.h>
    
    28 28
     #include <time.h>
    
    29
    +#if defined(DARWIN)
    
    30
    +#include <limits.h>
    
    31
    +#endif
    
    29 32
     
    
    30 33
     #include "os.h"
    
    31 34
     #include "internals.h"
    
    ... ... @@ -940,7 +943,6 @@ os_get_user_homedir(const char* name, int *status)
    940 943
         *status = -1;
    
    941 944
         return NULL;
    
    942 945
     }
    
    943
    -    
    
    944 946
     
    
    945 947
     /*
    
    946 948
      * Return a new string (or NULL) for the current working directory.
    

  • src/lisp/solaris-os.c
    ... ... @@ -643,3 +643,37 @@ os_support_sse2()
    643 643
         return TRUE;
    
    644 644
     }
    
    645 645
     #endif
    
    646
    +
    
    647
    +/*
    
    648
    + * Return a new string containing the path to an OS-dependent location
    
    649
    + * where temporary files/directories can be stored.  The string must
    
    650
    + * end with a slash.  If NULL is returned, such a location could not
    
    651
    + * be found or some other error happened.
    
    652
    + *
    
    653
    + * Caller must call free() on the string returned.
    
    654
    + */
    
    655
    +char *
    
    656
    +os_temporary_directory(void)
    
    657
    +{
    
    658
    +    /*
    
    659
    +     * If the TMP envvar is set, use that as the temporary directory.
    
    660
    +     * Otherwise, just assume "/tmp" will work.
    
    661
    +     */
    
    662
    +    char *tmp;
    
    663
    +    size_t len;
    
    664
    +    char *result;
    
    665
    +
    
    666
    +    tmp = getenv("TMP");
    
    667
    +    if (tmp == NULL) {
    
    668
    +	return strdup("/tmp/");
    
    669
    +    }
    
    670
    +    len = strlen(tmp);
    
    671
    +    if (tmp[len] == '/') {
    
    672
    +	return strdup(tmp);
    
    673
    +    }
    
    674
    +    result = malloc(len + 2);
    
    675
    +    if (result) {
    
    676
    +	sprintf(result, "%s/", tmp);
    
    677
    +    }
    
    678
    +    return result;
    
    679
    +}

  • tests/fd-streams.lisp
    ... ... @@ -18,22 +18,23 @@
    18 18
       (ensure-directories-exist *test-path* :verbose t))
    
    19 19
     
    
    20 20
     (define-test clear-output-1
    
    21
    -  (:tag :trac)
    
    21
    +    (:tag :trac)
    
    22 22
       (assert-eql
    
    23 23
        0
    
    24
    -   (unwind-protect
    
    25
    -	(let ((s (open *test-file*
    
    26
    -		       :direction :output
    
    27
    -		       :if-exists :supersede)))
    
    28
    -	  ;; Write a character to the (fully buffered) output
    
    29
    -	  ;; stream. Clear the output and close the file. Nothing
    
    30
    -	  ;; should have been written to the file.
    
    31
    -	  (write-char #\a s)
    
    32
    -	  (clear-output s)
    
    33
    -	  (close s)
    
    34
    -	  (setf s (open *test-file*))
    
    35
    -	  (file-length s))
    
    36
    -     (delete-file *test-file*))))
    
    24
    +   (ext:with-temporary-file (test-file)
    
    25
    +     (let ((s (open test-file
    
    26
    +		    :direction :output
    
    27
    +		    :if-exists :supersede)))
    
    28
    +       ;; Write a character to the (fully buffered) output
    
    29
    +       ;; stream. Clear the output and close the file. Nothing
    
    30
    +       ;; should have been written to the file.
    
    31
    +       (write-char #\a s)
    
    32
    +       (clear-output s)
    
    33
    +       (close s)
    
    34
    +       (setf s (open test-file))
    
    35
    +       (prog1
    
    36
    +	   (file-length s)
    
    37
    +	 (close s))))))
    
    37 38
     
    
    38 39
     (define-test file-position.1
    
    39 40
         (:tag :issues)
    

  • tests/trac.lisp
    ... ... @@ -104,42 +104,39 @@
    104 104
     		(pathname-directory "/tmp/Foo/BAR/" :case :common)))
    
    105 105
       
    
    106 106
     (define-test trac.36
    
    107
    -  (:tag :trac)
    
    108
    -  (let ((path "/tmp/trac.36.bom.txt"))
    
    109
    -    (flet ((bug (&optional (format :utf16))
    
    107
    +    (:tag :trac)
    
    108
    +  (flet ((bug (&optional (format :utf16))
    
    109
    +	   (ext:with-temporary-file (path)
    
    110 110
     	     (with-open-file (s path
    
    111 111
     				:direction :output
    
    112
    -				:if-exists :supersede
    
    113 112
     				:external-format format)
    
    114 113
     	       (format s "Hello~%"))
    
    115 114
     	     (with-open-file (s path 
    
    116 115
     				:direction :input
    
    117 116
     				:external-format format)
    
    118 117
     	       (let ((ch (read-char s)))
    
    119
    -		 (values ch (file-position s))))))
    
    120
    -      (assert-equal (values #\H 4)
    
    121
    -		    (bug :utf16))
    
    122
    -      (assert-equal (values #\H 8)
    
    123
    -		    (bug :utf32)))))
    
    118
    +		 (values ch (file-position s)))))))
    
    119
    +    (assert-equal (values #\H 4)
    
    120
    +		  (bug :utf16))
    
    121
    +    (assert-equal (values #\H 8)
    
    122
    +		  (bug :utf32))))
    
    124 123
     
    
    125 124
     (define-test trac.43
    
    126
    -  (:tag :trac)
    
    125
    +    (:tag :trac)
    
    127 126
       (assert-true
    
    128
    -   (let ((path "/tmp/trac.43.txt"))
    
    129
    -     (unwind-protect
    
    130
    -	  (progn
    
    131
    -	    (with-open-file (ostream path :direction :output
    
    132
    -					  :external-format :utf-8)
    
    133
    -	      (dotimes (i 1000)
    
    134
    -		(write-char (code-char #x1234) ostream)))
    
    135
    -
    
    136
    -	    (with-open-file (stream path :direction :input
    
    137
    -					 :external-format :utf-8)
    
    138
    -	      (let ((p0 (file-position stream))
    
    139
    -		    (ch (read-char stream)))
    
    140
    -		(unread-char ch stream)
    
    141
    -		(let ((p0* (file-position stream)))
    
    142
    -		  (eql p0* p0)))))))))
    
    127
    +   (ext:with-temporary-file (path)
    
    128
    +     (with-open-file (ostream path :direction :output
    
    129
    +				   :external-format :utf-8)
    
    130
    +       (dotimes (i 1000)
    
    131
    +	 (write-char (code-char #x1234) ostream)))
    
    132
    +
    
    133
    +     (with-open-file (stream path :direction :input
    
    134
    +				  :external-format :utf-8)
    
    135
    +       (let ((p0 (file-position stream))
    
    136
    +	     (ch (read-char stream)))
    
    137
    +	 (unread-char ch stream)
    
    138
    +	 (let ((p0* (file-position stream)))
    
    139
    +	   (eql p0* p0)))))))
    
    143 140
     
    
    144 141
     (define-test trac.50
    
    145 142
       (:tag :trac)
    
    ... ... @@ -147,23 +144,21 @@
    147 144
     		(princ-to-string (make-pathname :directory '(:absolute "tmp" "" "a" "" "b")))))
    
    148 145
     
    
    149 146
     (define-test trac.58
    
    150
    -  (:tag :trac)
    
    147
    +    (:tag :trac)
    
    151 148
       (assert-false
    
    152
    -   (let ((path "/tmp/trac.58.txt")
    
    153
    -	 failures)
    
    154
    -     (unwind-protect
    
    155
    -	  (progn
    
    156
    -	    (with-open-file (s path :direction :output :external-format :utf-16)
    
    157
    -	      (dotimes (i 300)
    
    158
    -		(write-char (code-char i) s)))
    
    159
    -
    
    160
    -	    (with-open-file (s path :direction :input :external-format :utf-16)
    
    161
    -	      (dotimes (i 300)
    
    162
    -		(let ((ch (read-char s nil nil)))
    
    163
    -		  (unless (= i (char-code ch))
    
    164
    -		    (push (list i ch (char-code ch)) failures)))))
    
    165
    -	    failures)
    
    166
    -       (delete-file path)))))
    
    149
    +   (let (failures)
    
    150
    +     (ext:with-temporary-file (path)
    
    151
    +       (with-open-file (s path :direction :output :external-format :utf-16)
    
    152
    +	 (dotimes (i 300)
    
    153
    +	   (write-char (code-char i) s)))
    
    154
    +
    
    155
    +       (with-open-file (s path :direction :input :external-format :utf-16)
    
    156
    +	 (dotimes (i 300)
    
    157
    +	   (let ((ch (read-char s nil nil)))
    
    158
    +	     (unless (= i (char-code ch))
    
    159
    +	       (push (list i ch (char-code ch)) failures)))))
    
    160
    +       failures))
    
    161
    +   failures))
    
    167 162
     
    
    168 163
     (define-test trac.63
    
    169 164
       (:tag :trac)
    
    ... ... @@ -254,19 +249,16 @@
    254 249
       ;; Create a temp file full of latin1 characters.
    
    255 250
       (assert-equal
    
    256 251
        '(0 1)
    
    257
    -   (let ((path "/tmp/trac.70.txt"))
    
    258
    -     (unwind-protect
    
    259
    -	  (progn
    
    260
    -	    (with-open-file (s path :direction :output :if-exists :supersede
    
    261
    -				    :external-format :latin1)
    
    262
    -	      (dotimes (k 255)
    
    263
    -		(write-char (code-char k) s)))
    
    264
    -	    (with-open-file (s path :direction :input :external-format :latin1)
    
    265
    -	      (list (file-position s)
    
    266
    -		    (progn
    
    267
    -		      (read-char s)
    
    268
    -		      (file-position s)))))
    
    269
    -       (delete-file path)))))
    
    252
    +   (ext:with-temporary-file (path)
    
    253
    +     (with-open-file (s path :direction :output :if-exists :supersede
    
    254
    +			     :external-format :latin1)
    
    255
    +       (dotimes (k 255)
    
    256
    +	 (write-char (code-char k) s)))
    
    257
    +     (with-open-file (s path :direction :input :external-format :latin1)
    
    258
    +       (list (file-position s)
    
    259
    +	     (progn
    
    260
    +	       (read-char s)
    
    261
    +	       (file-position s)))))))
    
    270 262
     
    
    271 263
     (define-test trac.80
    
    272 264
       (:tag :trac)
    
    ... ... @@ -278,49 +270,43 @@
    278 270
       (:tag :trac)
    
    279 271
       ;; Test that run-program accepts :element-type and produces the
    
    280 272
       ;; correct output.
    
    281
    -  (let ((path "/tmp/trac.87.output")
    
    282
    -	(string "Hello"))
    
    283
    -    (unwind-protect
    
    284
    -	 (progn
    
    285
    -	   (with-open-file (s path :direction :output :if-exists :supersede
    
    273
    +  (let ((string "Hello"))
    
    274
    +    (ext:with-temporary-file (path)
    
    275
    +      (with-open-file (s path :direction :output :if-exists :supersede
    
    286 276
     			      :external-format :latin1)
    
    287
    -	     (write-string string s))
    
    288
    -	   (let* ((expected (stream:string-to-octets string :external-format :latin1))
    
    289
    -		  (octets (make-array (length expected)
    
    290
    -				      :element-type '(unsigned-byte 8)))
    
    291
    -		  (proc (ext:run-program "/bin/cat" (list path)
    
    292
    -					 :output :stream
    
    293
    -					 :element-type '(unsigned-byte 8))))
    
    294
    -	     (read-sequence octets (ext:process-output proc))
    
    295
    -	     (assert-equalp
    
    296
    -	      expected
    
    297
    -	      octets)))
    
    298
    -      (delete-file path))))
    
    277
    +	(write-string string s))
    
    278
    +      (let* ((expected (stream:string-to-octets string :external-format :latin1))
    
    279
    +	     (octets (make-array (length expected)
    
    280
    +				 :element-type '(unsigned-byte 8)))
    
    281
    +	     (proc (ext:run-program "/bin/cat" (list (namestring path))
    
    282
    +				    :output :stream
    
    283
    +				    :element-type '(unsigned-byte 8))))
    
    284
    +	(read-sequence octets (ext:process-output proc))
    
    285
    +	(assert-equalp
    
    286
    +	 expected
    
    287
    +	 octets)))))
    
    299 288
     
    
    300 289
     (define-test trac.87.input
    
    301 290
       (:tag :trac)
    
    302 291
       ;; Test that run-program accepts :element-type and produces the
    
    303 292
       ;; correct input (and output).
    
    304
    -  (let ((path "/tmp/trac.87.input")
    
    305
    -	(string "Hello"))
    
    306
    -    (unwind-protect
    
    307
    -	 (progn
    
    308
    -	   (with-open-file (s path :direction :output :if-exists :supersede
    
    293
    +  (let ((string "Hello"))
    
    294
    +    (ext:with-temporary-file (path)
    
    295
    +      (with-open-file (s path :direction :output :if-exists :supersede
    
    309 296
     			      :external-format :latin1)
    
    310
    -	     (write-string string s))
    
    311
    -	   (let ((octets (stream:string-to-octets string :external-format :latin1))
    
    312
    -		 (output (make-array (length string)
    
    313
    -				     :element-type '(unsigned-byte 8)))
    
    314
    -		 (proc (ext:run-program "/bin/cat" (list path)
    
    315
    -					:input :stream
    
    316
    -					:output :stream
    
    317
    -					:element-type '(unsigned-byte 8))))
    
    318
    -	     (write-sequence octets (ext:process-input proc))
    
    319
    -	     (read-sequence output (ext:process-output proc))
    
    320
    -	     (assert-equalp
    
    321
    -	      octets
    
    322
    -	      output)))
    
    323
    -      (delete-file path))))
    
    297
    +	(write-string string s))
    
    298
    +      (let ((octets (stream:string-to-octets string :external-format :latin1))
    
    299
    +	    (output (make-array (length string)
    
    300
    +				:element-type '(unsigned-byte 8)))
    
    301
    +	    (proc (ext:run-program "/bin/cat" (list (namestring path))
    
    302
    +				   :input :stream
    
    303
    +				   :output :stream
    
    304
    +				   :element-type '(unsigned-byte 8))))
    
    305
    +	(write-sequence octets (ext:process-input proc))
    
    306
    +	(read-sequence output (ext:process-output proc))
    
    307
    +	(assert-equalp
    
    308
    +	 octets
    
    309
    +	 output)))))
    
    324 310
           
    
    325 311
     (define-test trac.92
    
    326 312
       (:tag :trac)
    
    ... ... @@ -384,18 +370,15 @@
    384 370
       (:tag :trac)
    
    385 371
       (assert-eql
    
    386 372
        0
    
    387
    -   (let ((s (open *test-file*
    
    388
    -		  :direction :output
    
    389
    -		  :if-exists :supersede)))
    
    390
    -     (unwind-protect
    
    391
    -	  (progn
    
    392
    -	    (write-char #\a s)
    
    393
    -	    (clear-output s)
    
    394
    -	    (close s)
    
    395
    -	    (setf s (open *test-file*))
    
    396
    -	    (file-length s))
    
    373
    +   (ext:with-temporary-file (test-file)
    
    374
    +     (let ((s (open test-file
    
    375
    +		    :direction :output
    
    376
    +		    :if-exists :supersede)))
    
    377
    +       (write-char #\a s)
    
    378
    +       (clear-output s)
    
    397 379
            (close s)
    
    398
    -       (delete-file *test-file*)))))
    
    380
    +       (setf s (open test-file))
    
    381
    +       (file-length s)))))
    
    399 382
     
    
    400 383
     (defun read-string-fn (str)
    
    401 384
          (handler-case