[Git][cmucl/cmucl][issue-120-software-type-in-c] 9 commits: Fix #132: Ansi test RENAME-FILE.1 fails

Raymond Toy (@rtoy) gitlab at common-lisp.net
Wed Mar 8 20:48:50 UTC 2023



Raymond Toy pushed to branch issue-120-software-type-in-c at cmucl / cmucl


Commits:
2591a201 by Raymond Toy at 2023-03-08T12:46:10-08:00
Fix #132: Ansi test RENAME-FILE.1 fails

- - - - -
34a865ec by Raymond Toy at 2023-03-08T12:46:10-08:00
Fix #134: Handle the case of (expt complex complex-rational)

- - - - -
70e6cf5b by Raymond Toy at 2023-03-08T12:46:10-08:00
Fix #146:  CI passes incorrectly

- - - - -
44fcc4af by Raymond Toy at 2023-03-08T12:46:10-08:00
Fix #142: (random 0) signals incorrect error

- - - - -
34e2da7c by Raymond Toy at 2023-03-08T12:46:10-08:00
Fix #136: ensure-directories-exist should return the given pathspec

- - - - -
270cd610 by Raymond Toy at 2023-03-08T12:46:10-08:00
Update release notes based on recent merges

Forgot to update the release notes with recent merges that fixed a few
issues.  Hence update the notes now.

Also testing see if we need to add a strikeout for closed issues, so
didn't add strikeout for these.

- - - - -
351339d3 by Raymond Toy at 2023-03-08T12:46:10-08:00
Add strikeout for closed issues

Nope, gitlab doesn't mark closed issues in anyway, unlike Trac that
would automatically strikeout references to closed issues.  We have to
do it ourselves.

- - - - -
84aced83 by Raymond Toy at 2023-03-08T12:46:10-08:00
Fix #146: CI passes incorrectly

We forgot to update the script for macos to use separate `grep`
commands like we did for linux.

- - - - -
c7eedc4e by Raymond Toy at 2023-03-08T12:48:14-08:00
Fix #130:  Implement file_author in C

- - - - -


9 changed files:

- .gitlab-ci.yml
- src/code/filesys.lisp
- src/code/irrat.lisp
- src/code/rand-xoroshiro.lisp
- src/general-info/release-21e.md
- src/lisp/os-common.c
- tests/filesys.lisp
- tests/issues.lisp
- + tests/안녕하십니까.txt


Changes:

=====================================
.gitlab-ci.yml
=====================================
@@ -80,7 +80,8 @@ linux:ansi-test:
   script:
     - cd ansi-test
     - make LISP="../dist/bin/lisp -batch -noinit -nositeinit"
-    - grep 'No unexpected \(successes\|failures\)' test.out
+    # There should be no unexpected successes or failures; check these separately.
+    - grep -a 'No unexpected successes' test.out && grep -a 'No unexpected failures' test.out
     
 linux:benchmark:
   stage: benchmark
@@ -166,7 +167,8 @@ osx:ansi-test:
   script:
     - cd ansi-test
     - make LISP="../dist/bin/lisp -batch -noinit -nositeinit"
-    - grep 'No unexpected \(successes\|failures\)' test.out 
+    # There should be no unexpected successes or failures; check these separately.
+    - grep -a 'No unexpected successes' test.out && grep -a 'No unexpected failures' test.out
   
 osx:benchmark:
   stage: benchmark


=====================================
src/code/filesys.lisp
=====================================
@@ -950,7 +950,11 @@
   File after it was renamed."
   (let* ((original (truename file))
 	 (original-namestring (unix-namestring original t))
-	 (new-name (merge-pathnames new-name file))
+	 ;; First, merge NEW-FILE-NAME with *DEFAULT-PATHNAME-DEFAULTS* to
+	 ;; fill in the missing components and then merge again with
+	 ;; the FILE to get any missing components from FILE.
+	 (new-name (merge-pathnames (merge-pathnames new-name)
+				    file))
 	 (new-namestring (unix-namestring new-name nil)))
     (unless new-namestring
       (error 'simple-file-error
@@ -1075,13 +1079,21 @@ optionally keeping some of the most recent old versions."
 		 :pathname file
 		 :format-control (intl:gettext "~S doesn't exist.")
 		 :format-arguments (list file)))
-	(multiple-value-bind (winp dev ino mode nlink uid)
-			     (unix:unix-stat name)
-	  (declare (ignore dev ino mode nlink))
-	  (when winp
-            (let ((user-info (unix:unix-getpwuid uid)))
-              (when user-info
-                (unix:user-info-name user-info))))))))
+	;; unix-namestring converts "." to "".  Convert it back to
+	;; "." so we can stat the current directory.  (Perhaps
+	;; that's a bug in unix-namestring?)
+	(when (zerop (length name))
+	  (setf name "."))
+	(let (author)
+	  (unwind-protect
+	       (progn
+		 (setf author (alien:alien-funcall
+			       (alien:extern-alien "os_file_author"
+						   (function (alien:* c-call:c-string) c-call:c-string))
+			       (unix::%name->file name)))
+		 (unless (alien:null-alien author)
+		   (alien:cast author c-call:c-string)))
+	    (alien:free-alien author))))))
 
 
 ;;;; DIRECTORY.
@@ -1474,4 +1486,4 @@ optionally keeping some of the most recent old versions."
 			 (retry () :report "Try to create the directory again"
 				(go retry))))))
 	 ;; Only the first path in a search-list is considered.
-	 (return (values pathname created-p))))))
+	 (return (values pathspec created-p))))))


=====================================
src/code/irrat.lisp
=====================================
@@ -510,12 +510,12 @@
 	     (* base power)
 	     (exp (* power (* (log2 base 1w0) (log 2w0))))))
 	(((foreach fixnum (or bignum ratio) single-float)
-	  (foreach (complex single-float)))
+	  (foreach (complex rational) (complex single-float)))
 	 (if (and (zerop base) (plusp (realpart power)))
 	     (* base power)
 	     (exp (* power (log base)))))
 	(((foreach (complex rational) (complex single-float))
-	  (foreach single-float (complex single-float)))
+	  (foreach single-float (complex rational) (complex single-float)))
 	 (if (and (zerop base) (plusp (realpart power)))
 	     (* base power)
 	     (or (expt-xfrm (coerce base '(complex single-float)) power)
@@ -537,7 +537,7 @@
 		 (exp (* power (log (coerce base '(complex double-double-float))))))))
 	(((foreach (complex double-float))
 	  (foreach single-float double-float
-		   (complex single-float) (complex double-float)))
+		   (complex rational) (complex single-float) (complex double-float)))
 	 (if (and (zerop base) (plusp (realpart power)))
 	     (* base power)
 	     (or (expt-xfrm base power)
@@ -552,7 +552,7 @@
 		 (exp (* power (log (coerce base '(complex double-double-float))))))))
 	#+double-double
 	(((foreach (complex double-double-float))
-	  (foreach float (complex float)))
+	  (foreach float (complex float) (complex rational)))
 	 (if (and (zerop base) (plusp (realpart power)))
 	     (* base power)
 	     (or (expt-xfrm base power)


=====================================
src/code/rand-xoroshiro.lisp
=====================================
@@ -491,8 +491,8 @@
     (t
      (error 'simple-type-error
 	    :expected-type '(or (integer 1) (float (0.0))) :datum arg
-	    :format-control _"Argument is not a positive integer or a positive float: ~S")
-	    :format-arguments (list arg))))
+	    :format-control _"Argument is not a positive integer or a positive float: ~S"
+	    :format-arguments (list arg)))))
 
 ;; Jump function for the generator.  See the jump function in
 ;; http://xoroshiro.di.unimi.it/xoroshiro128plus.c


=====================================
src/general-info/release-21e.md
=====================================
@@ -50,8 +50,13 @@ public domain.
     * ~~#113~~ REQUIRE on contribs can pull in the wrong things via ASDF..
     * ~~#121~~ Wrong column index in FILL-POINTER-OUTPUT-STREAM
     * ~~#122~~ gcc 11 can't build cmucl
+    * ~~#125~~ Linux `unix-stat` returning incorrect values
     * ~~#127~~ Linux unix-getpwuid segfaults when given non-existent uid..
     * ~~#128~~ `QUIT` accepts an exit code
+    * ~~#132~~ Ansi test `RENAME-FILE.1` no fails
+    * ~~#134~~ Handle the case of `(expt complex complex-rational)`
+    * ~~#136~~ `ensure-directories-exist` should return the given pathspec
+    * ~~#142~~ `(random 0)` signals incorrect error
   * Other changes:
   * Improvements to the PCL implementation of CLOS:
   * Changes to building procedure:


=====================================
src/lisp/os-common.c
=====================================
@@ -5,13 +5,17 @@
 
 */
 
+#include <assert.h>
 #include <errno.h>
 #include <math.h>
 #include <netdb.h>
+#include <pwd.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/utsname.h>
+#include <unistd.h>
 #include <time.h>
 
 #include "os.h"
@@ -717,6 +721,59 @@ os_lstat(const char* path, u_int64_t *dev, u_int64_t *ino, unsigned int *mode, u
     return rc;
 }
 
+/*
+ * Interface for file-author.  Given a pathname, returns a new string
+ * holding the author of the file or NULL if some error occurred.  The
+ * caller is responsible for freeing the memory used by the string.
+ */
+char *
+os_file_author(const char *path)
+{
+    struct stat sb;
+    char initial[1024];
+    char *buffer, *obuffer;
+    size_t size;
+    struct passwd pwd;
+    struct passwd *ppwd;
+    char *result;
+
+    if (stat(path, &sb) != 0) {
+        return NULL;
+    }
+
+    result = NULL;
+    buffer = initial;
+    obuffer = NULL;
+    size = sizeof(initial) / sizeof(initial[0]);
+
+    /*
+     * Keep trying with larger buffers until a maximum is reached.  We
+     * assume (1 << 20) is large enough for any OS.
+     */
+    while (size <= (1 << 20)) {
+        switch (getpwuid_r(sb.st_uid, &pwd, buffer, size, &ppwd)) {
+          case 0:
+              /* Success, though we might not have a matching entry */
+              result = (ppwd == NULL) ? NULL : strdup(pwd.pw_name);
+              goto exit;
+          case ERANGE:
+              /* Buffer is too small, double its size and try again */
+              size *= 2;
+              obuffer = (buffer == initial) ? NULL : buffer;
+              if ((buffer = realloc(obuffer, size)) == NULL) {
+                  goto exit;
+              }
+              continue;
+          default:
+              /* All other errors */
+              goto exit;
+        }
+    }
+exit:
+    free(obuffer);
+    
+    return result;
+}
 /*
  * For Linux and solaris, software-version returns the concatenation
  * of the uname release and version fields.  For BSD (including
@@ -769,4 +826,3 @@ os_software_type()
 
     return os_name;
 }
-    


=====================================
tests/filesys.lisp
=====================================
@@ -10,7 +10,7 @@
 
 (define-test unix-namestring.1.exists
   ;; Make sure the desired directories exist.
-  (assert-equal #P"/tmp/foo/bar/hello.txt"
+  (assert-equal "/tmp/foo/bar/hello.txt"
 		(ensure-directories-exist "/tmp/foo/bar/hello.txt"))
   (dolist (path '("/tmp/hello.txt"
 		  "/tmp/foo/"
@@ -27,7 +27,7 @@
 
 (define-test unix-namestring.1.non-existent
   ;; Make sure the desired directories exist.
-  (assert-equal #P"/tmp/foo/bar/hello.txt"
+  (assert-equal "/tmp/foo/bar/hello.txt"
 		(ensure-directories-exist "/tmp/foo/bar/hello.txt"))
   ;; These paths contain directories that don't exist.
   (dolist (path '("/tmp/oops/"
@@ -42,7 +42,7 @@
 
 (define-test unix-namestring.2
   ;; Make sure the desired directories exist.
-  (assert-equal #P"/tmp/foo/bar/hello.txt"
+  (assert-equal "/tmp/foo/bar/hello.txt"
 		(ensure-directories-exist "/tmp/foo/bar/hello.txt"))
   (unwind-protect
        (progn


=====================================
tests/issues.lisp
=====================================
@@ -579,3 +579,101 @@
 	with user-info = (unix:unix-getpwuid uid)
 	while user-info
 	finally (assert-false user-info)))
+
+(define-test issue.132.1
+    (:tag :issues)
+  ;; From a message on cmucl-imp 2008/06/01.  If "d1" is a directory,
+  ;; (rename "d1" "d2") should rename the directory "d1" to "d2".
+  ;; Previously that produced an error trying to rename "d1" to
+  ;; "d1/d2".
+  ;;
+  ;; Create the test directory (that is a subdirectory of "dir").
+  (assert-true (ensure-directories-exist "dir/orig-dir/"))
+  (let ((*default-pathname-defaults* (merge-pathnames "dir/" (ext:default-directory))))
+    (multiple-value-bind (defaulted-new-name old-truename new-truename)
+	;; Rename "dir/orig-dir" to "orig/new-dir".
+	(rename-file "orig-dir/" "new-dir")
+      (let ((orig (merge-pathnames
+		   (make-pathname :directory '(:relative "orig-dir"))))
+	    (new (merge-pathnames
+		  (make-pathname :directory '(:relative "new-dir")))))
+	;; Ensure that the rename worked and that the returned values
+	;; have the expected values.
+	(assert-true defaulted-new-name)
+	(assert-equalp old-truename orig)
+	(assert-equalp new-truename new)))))
+
+(define-test issue.132.2
+    (:tag :issues)
+  (assert-true (ensure-directories-exist "dir/orig.dir/"))
+  (let ((*default-pathname-defaults* (merge-pathnames "dir/" (ext:default-directory))))
+    (multiple-value-bind (defaulted-new-name old-truename new-truename)
+	;; Rename "dir/orig.dir" to "orig/new-dir".  Since the
+	;; original name has a pathname-name of "orig" and a
+	;; pathname-type of "dir", the new file name is merged to
+	;; produce a pathname-name of "new" with a pathname-type of
+	;; "dir".
+	(rename-file "orig.dir" "new")
+      (let ((orig (merge-pathnames
+		   (make-pathname :directory '(:relative "orig.dir"))))
+	    (new (merge-pathnames
+		  (make-pathname :directory '(:relative "new.dir")))))
+	;; Ensure that the rename worked and that the returned values
+	;; have the expected values.
+	(assert-true defaulted-new-name)
+	(assert-equalp old-truename orig)
+	(assert-equalp new-truename new)))))
+
+(define-test issue.132.3
+    (:tag :issues)
+  (assert-true (ensure-directories-exist "dir/orig.dir/"))
+  (let ((*default-pathname-defaults* (merge-pathnames "dir/" (ext:default-directory))))
+    (multiple-value-bind (defaulted-new-name old-truename new-truename)
+	;; Rename "dir/orig.dir/" to "orig/new".  Note that the
+	;; original name is "orig.dir/" which marks a directory so
+	;; that when we merge the new name with the old to fill in
+	;; missing components, there are none because the old name is
+	;; a directory with no pathname-name or pathname-type, so the
+	;; new name stays the same.
+	(rename-file "orig.dir/" "new")
+      (let ((orig (merge-pathnames
+		   (make-pathname :directory '(:relative "orig.dir"))))
+	    (new (merge-pathnames
+		  (make-pathname :directory '(:relative "new")))))
+	;; Ensure that the rename worked and that the returned values
+	;; have the expected values.
+	(assert-true defaulted-new-name)
+	(assert-equalp old-truename orig)
+	(assert-equalp new-truename new)))))
+
+(define-test issue.134
+    (:tag :issues)
+  ;; Verify that we can compute (3+4*%i)^%i (in Maxima format).  This
+  ;; can be written analytically as
+  ;; %i*%e^-atan(4/3)*sin(log(5))+%e^-atan(4/3)*cos(log(5)), so use
+  ;; %this as the reference value.
+  (let ((answer (complex (* (cos (log 5w0))
+			    (exp (- (atan (float (/ 4 3) 0w0)))))
+			 (* (sin (log 5w0))
+			    (exp (- (atan (float (/ 4 3) 0w0))))))))
+    (flet ((relerr (actual true)
+	     ;; Return the relative error between ACTUAL and TRUE
+	     (/ (abs (- actual true))
+		(abs true))))
+      (dolist (test '((#c(3 4) 3.5918w-8)
+		      (#c(3.0 4) 3.5918w-8)
+		      (#c(3d0 4) 9.2977w-17)
+		      (#c(3w0 4) 0w0)))
+	(destructuring-bind (base eps)
+	    test
+	  (let* ((value (expt base #c(0 1)))
+		 (err (relerr value answer)))
+	    (assert-true (<= err eps) base err eps)))))))
+
+(define-test issue.130
+    (:tag :issues)
+  ;; Just verify that file-author works.  In particular "." should
+  ;; work and not return NIL.
+  (assert-true (file-author "."))
+  (assert-true (file-author "bin/build.sh"))
+  (assert-true (file-author "tests/안녕하십니까.txt")))


=====================================
tests/안녕하십니까.txt
=====================================
@@ -0,0 +1,3 @@
+The file name of this file is "안녕하십니까.txt" ("Hello" in Korean.)
+
+



View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/51d4f25b5c61298d978e7df6cfea382c7f161da7...c7eedc4ec8441f2dcca388790be725381cc80340

-- 
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/51d4f25b5c61298d978e7df6cfea382c7f161da7...c7eedc4ec8441f2dcca388790be725381cc80340
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/20230308/1e74e922/attachment-0001.html>


More information about the cmucl-cvs mailing list