
Raymond Toy pushed to branch issue-393-os-common-getpwuid at cmucl / cmucl Commits: a865270d by Raymond Toy at 2025-03-27T20:23:52-07:00 Add os_free_getpwuid() to free up space from os_getpwuid Add the C function `os_free_getpwuid()` to os-common.c to free up the space allocated by `os_getpwuid()`. We do this so that the knowledge of the things were allocated are all in one place instead of having the Lisp code know what `os_getpwuid()` allocated. - - - - - 944881e2 by Raymond Toy at 2025-03-27T20:40:43-07:00 Add declaration to inhibit warnings Inhibit warnings about not being able to optimize away %sap-alien and being force to do runtime allocation. This happens when calling os_getpwuid and also derefing the pointer to the passwd struct. Also fix a warning coming from %file->name by calling `string`. - - - - - 2 changed files: - src/code/unix.lisp - src/lisp/os-common.c Changes: ===================================== src/code/unix.lisp ===================================== @@ -2540,14 +2540,24 @@ (unwind-protect (progn (setf result - (alien-funcall - (extern-alien "os_getpwuid" - (function (* (struct passwd)) - uid-t)) - uid)) + (locally + ;; Inhibit warnings about not being able to + ;; optimize away %sap-alien and doing runtime + ;; allocation. + (declare (optimize (ext:inhibit-warnings 3))) + (alien-funcall + (extern-alien "os_getpwuid" + (function (* (struct passwd)) + uid-t)) + uid))) (if (null-alien result) (values nil (unix-errno)) - (let ((passwd (deref result))) + (let ((passwd (locally + ;; Inhibit warnings about not being able to + ;; optimize away %sap-alien and doing runtime + ;; allocation. + (declare (optimize (ext:inhibit-warnings 3))) + (deref result)))) (make-user-info :name (string (cast (slot passwd 'pw-name) c-call:c-string)) :password (string (cast (slot passwd 'pw-passwd) c-call:c-string)) @@ -2557,16 +2567,14 @@ :gecos (string-decode (cast (slot passwd 'pw-gecos) c-call:c-string) :default) ;; The home directory could be unicode - :dir (%file->name (cast (slot passwd 'pw-dir) c-call:c-string)) + :dir (%file->name (string (cast (slot passwd 'pw-dir) c-call:c-string))) :shell (string (cast (slot passwd 'pw-shell) c-call:c-string)))))) (unless (null-alien result) - (let ((passwd (deref result))) - (free-alien (slot passwd 'pw-name)) - (free-alien (slot passwd 'pw-passwd)) - (free-alien (slot passwd 'pw-gecos)) - (free-alien (slot passwd 'pw-dir)) - (free-alien (slot passwd 'pw-shell))) - (free-alien result)))))) + (alien-funcall + (extern-alien "os_free_getpwuid" + (function c-call:void + (* (struct passwd)))) + result)))))) ;;; Getrusage is not provided in the C library on Solaris 2.4, and is ===================================== src/lisp/os-common.c ===================================== @@ -936,6 +936,16 @@ os_get_user_homedir(const char* name, int *status) return NULL; } + +/* + * Get the passwd info for the user id UID. If the uid does not + * exist, return NULL. Otherwise, return a passwd struct that has the + * slots filled in that are needed to create the USER-INFO structure. + * All other slots in passwd are undefined. + * + * The caller MUST call os_free_getpwuid() to free the space allocated + * by os_getpwuid(). + */ struct passwd* os_getpwuid(uid_t uid) { @@ -994,3 +1004,18 @@ again: return result; } + +/* + * Free the space allocated for the passwd struct returned by + * os_getpwuid(). + */ +void +os_free_getpwuid(struct passwd* pwd) +{ + free(pwd->pw_name); + free(pwd->pw_passwd); + free(pwd->pw_gecos); + free(pwd->pw_dir); + free(pwd->pw_shell); + free(pwd); +} View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/879dd1adafa83bb3c65d083... -- View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/879dd1adafa83bb3c65d083... You're receiving this email because of your account on gitlab.common-lisp.net.
participants (1)
-
Raymond Toy (@rtoy)