Raymond Toy pushed to branch issue-130-file-author-in-c at cmucl / cmucl
Commits:
6557e832 by Raymond Toy at 2022-09-05T14:45:35-07:00
Reindent according to cmucl style
- - - - -
08b38701 by Raymond Toy at 2022-09-05T14:50:40-07:00
Apply suggested change to test for zero length.
- - - - -
3a41b05c by Raymond Toy at 2022-09-05T14:54:16-07:00
Add a few comments
- - - - -
c4a9d0d8 by Raymond Toy at 2022-09-05T15:16:43-07:00
Add assert.h and replace ARRAYSIZE with sizeof
We need to include assert.h to define the `assert` macro that we use.
`ARRAYSIZE` needs to be replaced with `sizeof` to compute the size of
the `initial` buffer.
- - - - -
2 changed files:
- src/code/filesys.lisp
- src/lisp/os-common.c
Changes:
=====================================
src/code/filesys.lisp
=====================================
@@ -1078,7 +1078,7 @@ optionally keeping some of the most recent old versions."
;; unix-namestring converts "." to "". Convert it back to
;; "." so we can stat the current directory. (Perhaps
;; that's a bug in unix-namestring?)
- (when (string= name "")
+ (when (zerop (length name))
(setf name "."))
(let (author)
(unwind-protect
=====================================
src/lisp/os-common.c
=====================================
@@ -5,6 +5,7 @@
*/
+#include <assert.h>
#include <errno.h>
#include <math.h>
#include <netdb.h>
@@ -738,31 +739,43 @@ os_file_author(const char *path)
if (stat(path, &sb) != 0) {
return NULL;
}
+
result = NULL;
buffer = initial;
- size = ARRAYSIZE(initial);
- assert(sysconf(_SC_GETPW_R_SIZE_MAX) <= 16384));
+ size = sizeof(initial) / sizeof(initial[0]);
+
+ /*
+ * Assume a buffer of size 16384 is enough to for getpwuid_r to do
+ * it's thing.
+ */
+ assert(sysconf(_SC_GETPW_R_SIZE_MAX) <= 16384);
+
+ /*
+ * Keep trying with larger buffers until a maximum is reached.
+ */
while (size <= 16384) {
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) {
- free(obuffer);
- goto exit;
- }
- continue;
- default:
- /* All other errors */
- goto exit;
+ 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) {
+ free(obuffer);
+ goto exit;
+ }
+ continue;
+ default:
+ /* All other errors */
+ goto exit;
}
}
exit:
+ fprintf(stderr, "buffer, initial = %p %p\n", buffer, initial);
+
free(buffer);
return result;
}
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/518ef95922f48ff2e29087…
--
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/518ef95922f48ff2e29087…
You're receiving this email because of your account on gitlab.common-lisp.net.
Raymond Toy pushed to branch issue-130-file-author-in-c at cmucl / cmucl
Commits:
344f246c by Carl S. Shapiro at 2022-09-05T04:55:48+00:00
Apply 1 suggestion(s) to 1 file(s)
- - - - -
1 changed file:
- src/lisp/os-common.c
Changes:
=====================================
src/lisp/os-common.c
=====================================
@@ -9,7 +9,6 @@
#include <math.h>
#include <netdb.h>
#include <pwd.h>
-#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/344f246c2bc4dd290e45f9d…
--
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/344f246c2bc4dd290e45f9d…
You're receiving this email because of your account on gitlab.common-lisp.net.
Raymond Toy pushed to branch issue-130-file-author-in-c at cmucl / cmucl
Commits:
8a90499a by Carl S. Shapiro at 2022-09-05T04:52:30+00:00
Apply 1 suggestion(s) to 1 file(s)
- - - - -
1 changed file:
- src/code/filesys.lisp
Changes:
=====================================
src/code/filesys.lisp
=====================================
@@ -1061,29 +1061,6 @@ optionally keeping some of the most recent old versions."
;;; File-Author -- Public
;;;
-#+nil
-(defun file-author (file)
- "Returns the file author as a string, or nil if the author cannot be
- determined. Signals an error of type file-error if file doesn't exist,
- or file is a wild pathname."
- (if (wild-pathname-p file)
- (error 'simple-file-error
- :pathname file
- :format-control (intl:gettext "Bad place for a wild pathname."))
- (let ((name (unix-namestring (merge-pathnames file) t)))
- (unless name
- (error 'simple-file-error
- :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))))))))
-
(defun file-author (file)
"Returns the file author as a string, or nil if the author cannot be
determined. Signals an error of type file-error if file doesn't exist,
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/8a90499aa2f4c569d8d32da…
--
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/8a90499aa2f4c569d8d32da…
You're receiving this email because of your account on gitlab.common-lisp.net.
Raymond Toy pushed to branch issue-132-ansi-test-rename-files at cmucl / cmucl
Commits:
41147e45 by Raymond Toy at 2022-09-03T21:46:04-07:00
Oops. Look for unexpected successes/failures
We were grep'ing for 'No unexpected' successes or failures. We really
should be looking for unexpected successes or failures.
- - - - -
1 changed file:
- .gitlab-ci.yml
Changes:
=====================================
.gitlab-ci.yml
=====================================
@@ -80,7 +80,7 @@ linux:ansi-test:
script:
- cd ansi-test
- make LISP="../dist/bin/lisp -batch -noinit -nositeinit"
- - grep -a 'No unexpected \(successes\|failures\)' test.out
+ - grep -a 'unexpected \(successes\|failures\)' test.out
linux:benchmark:
stage: benchmark
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/41147e45c35af0c6d947e99…
--
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/41147e45c35af0c6d947e99…
You're receiving this email because of your account on gitlab.common-lisp.net.
Raymond Toy pushed to branch issue-132-ansi-test-rename-files at cmucl / cmucl
Commits:
c0e48e6c by Raymond Toy at 2022-09-03T21:21:49-07:00
Used grep -a to find unexpected changes
Without -a, grep doesn't find any changes, making the test pass. Use
-a to treat the file as text (which is mostly is, except for unicode
characters/strings) so that we can find if there unexpected successes
or failures.
- - - - -
1 changed file:
- .gitlab-ci.yml
Changes:
=====================================
.gitlab-ci.yml
=====================================
@@ -80,7 +80,7 @@ linux:ansi-test:
script:
- cd ansi-test
- make LISP="../dist/bin/lisp -batch -noinit -nositeinit"
- - grep 'No unexpected \(successes\|failures\)' test.out
+ - grep -a 'No unexpected \(successes\|failures\)' test.out
linux:benchmark:
stage: benchmark
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/c0e48e6c63680ca24ff3358…
--
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/c0e48e6c63680ca24ff3358…
You're receiving this email because of your account on gitlab.common-lisp.net.
Raymond Toy pushed to branch issue-120-software-type-in-c at cmucl / cmucl
Commits:
51d4f25b by Raymond Toy at 2022-09-02T16:00:01-07:00
Simplify code and use strdup to copy the strings
Reorder the code for os_software_version to keep all the
UNAME_RELEASE_AND_VERSION code together. When
UNAME_RELEASE_AND_VERSION is not set, use strdup to copy the release.
In os_software_type, use strdup to copy the OS name, instead of
malloc+strcpy.
- - - - -
1 changed file:
- src/lisp/os-common.c
Changes:
=====================================
src/lisp/os-common.c
=====================================
@@ -740,19 +740,15 @@ os_software_version()
int version_length;
#if defined(UNAME_RELEASE_AND_VERSION)
version_length = strlen(uts.release) + strlen(uts.version) + 2;
-#else
- version_length = strlen(uts.version) + 1;
-#endif
version = malloc(version_length);
if (version) {
-#if defined(UNAME_RELEASE_AND_VERSION)
strcpy(version, uts.release);
strcat(version, " ");
strcat(version, uts.version);
+ }
#else
- strcpy(version, uts.version);
+ version = strdup(uts.version);
#endif
- }
}
return version;
@@ -768,10 +764,7 @@ os_software_type()
status = uname(&uts);
if (status == 0) {
- os_name = malloc(strlen(uts.sysname) + 1);
- if (os_name) {
- strcpy(os_name, uts.sysname);
- }
+ os_name = strdup(uts.sysname);
}
return os_name;
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/51d4f25b5c61298d978e7df…
--
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/51d4f25b5c61298d978e7df…
You're receiving this email because of your account on gitlab.common-lisp.net.
Raymond Toy pushed to branch issue-130-file-author-in-c at cmucl / cmucl
Commits:
a6ef2b38 by Raymond Toy at 2022-09-02T10:21:26-07:00
Use strdup to copy the author field.
- - - - -
1 changed file:
- src/lisp/os-common.c
Changes:
=====================================
src/lisp/os-common.c
=====================================
@@ -782,10 +782,7 @@ os_file_author(const char *path)
}
if (result) {
- author = malloc(strlen(result->pw_name) + 1);
- if (author) {
- strcpy(author, result->pw_name);
- }
+ author = strdup(result->pw_name);
}
if (buf) {
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/a6ef2b384cc21b539b90aba…
--
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/a6ef2b384cc21b539b90aba…
You're receiving this email because of your account on gitlab.common-lisp.net.