Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Add the function TRIVIAL-SHELL:EXIT #5

Merged
merged 8 commits into from Sep 5, 2012

Conversation

Projects
None yet
3 participants
Contributor

lokedhs commented Sep 3, 2012

Rationale: There is currently no library that provides a platform-independent way to exit the Lisp runtime. The best library to provide this functionality is trivial-shell. Thus, this patch adds the function TRIVIAL-SHELL:EXIT.

The function takes a single optional argument: The status code. The code can be an integer, or any of the special values :SUCCESS or :FAILURE. The latter are currently mapped to 0 and 1.

stassats commented Sep 3, 2012

Regarding SBCL:
The older SBCL only have sb-ext:quit function.
When called without :recklessly-p it will exit the current thread. With :recklessly-p t it will be the same as (sb-ext:exit :abort t), i.e. it will exit immediately without calling any exit hooks. So, there's really no equivalent to just (sb-ext:exit), which will call exit-hooks.

Now, CMUCL.
ext:quit doesn't have exit code parameter, only recklessly-p optional parameter. And it does the same thing as in SBCL, if it's run not in the main thread, it will just exit the current thread.

Contributor

lokedhs commented Sep 4, 2012

@stassats, in what version did the change in SBCL happen? I need to know which version to download so I can test my solution.

@lokedhs lokedhs commented on the diff Sep 4, 2012

dev/digitool.lisp
@@ -4,3 +4,6 @@
(when input
(error "This version of trivial-shell does not support the input parameter."))
(ccl:do-shell-script command))
+
+(defun %exit (code)
@lokedhs

lokedhs Sep 4, 2012

Contributor

I have been unable to find any reference to how the exit function works in MCL. The documentation doesn't mention it at all.

Older versions of SBCL had a function SB-EXT:QUIT instead of SB-EXT:E…
…XIT.

This fix checks whether SB-EXT:EXIT exists, and if not, will fall back to
the older way of doing it.

@lokedhs lokedhs commented on the diff Sep 4, 2012

dev/shell.lisp
@@ -69,3 +69,12 @@ may be used to find a shell to use in executing `command`."
(defun get-env-var (name)
"Return the value of the environment variable `name`."
(%get-env-var name))
+
+(defun exit (&optional (code :success))
@lokedhs

lokedhs Sep 4, 2012

Contributor

Should CODE be a keyword argument instead?

Old SB-EXT:QUIT does not support an exit code.
In the fallback code for older versions of SBCL, removed the exit code
argument and replaced it with a check that verifies that the requested
code is zero.

@lokedhs lokedhs and 2 others commented on an outdated diff Sep 4, 2012

dev/cmucl.lisp
+ ext:*environment-list*)))
+
+(defun %exit (code)
+ (unless (zerop code)
+ (error "CMUCL does not support exit codes."))
+ (ext:quit))
@lokedhs

lokedhs Sep 4, 2012

Contributor

Should :RECKLESSLY-P be T here?

Also, when googling I found a reference to UNIX:UNIX-EXIT here which does support exit codes. Should it be used instead? http://comments.gmane.org/gmane.lisp.cmucl.devel/10946

I haven't been able to install any version of CMUCL so I haven't been able to test this.

@gwkkwg

gwkkwg Sep 4, 2012

Owner

Hi Elias,

Thanks for this idea and code. I'll pull it in once you're happy about the CMUCL / SBCL idea that Stas brought up.

On Sep 3, 2012, at 10:01 PM, Elias Mårtenson notifications@github.com wrote:

In dev/cmucl.lisp:

\ No newline at end of file

  •     ext:_environment-list_)))
    
    +(defun %exit (code)
  • (unless (zerop code)
  • (error "CMUCL does not support exit codes."))
  • (ext:quit))
    Should :RECLESSLY-P be T here?

Also, when googling I found a reference to UNIX:UNIX-EXIT here which does support exit codes. Should it be used instead? http://comments.gmane.org/gmane.lisp.cmucl.devel/10946

I haven't been able to install any version of CMUCL so I haven't been able to test this.


Reply to this email directly or view it on GitHub.

Gary Warren King, metabang.com
Cell: (413) 559 8738
Fax: (206) 338-4052
gwkkwg on Skype * garethsan on AIM * gwking on twitter

@lokedhs

lokedhs Sep 4, 2012

Contributor

I've addressed those issues. The code now checks whether SB-EXT:EXIT exists, and if not, it will fall back to the older SB-EXT:QUIT.

@stassats

stassats Sep 4, 2012

If you want it to exit the whole lisp, not just the current thread, yes, it should be (ext:quit t)

@lokedhs

lokedhs Sep 4, 2012

Contributor

I've made the necessary change.

Contributor

lokedhs commented Sep 4, 2012

I think the code should be ready for merge, with the only outstanding question as to whether the &OPTIONAL CODE argument should be a &KEY instead.

@stassats stassats and 1 other commented on an outdated diff Sep 4, 2012

dev/sbcl.lisp
+
+(defun symbol-if-external (name package)
+ (multiple-value-bind (symbol s) (find-symbol name package)
+ (when (eq s :external)
+ symbol)))
+
+(defun %exit (code)
+ (let ((exit-sym (symbol-if-external "EXIT" "SB-EXT")))
+ (if exit-sym
+ (funcall exit-sym :code code)
+ (let ((quit-sym (symbol-if-external "QUIT" "SB-EXT")))
+ (if quit-sym
+ (if (zerop code)
+ (funcall quit-sym :recklessly-p t)
+ (error "This version of SBCL does not support exiting with a code."))
@stassats

stassats Sep 4, 2012

sb-ext:quit does support exit codes, it's :unix-status

@lokedhs

lokedhs Sep 4, 2012

Contributor

I've updated the code to reflect this.

gwkkwg added a commit that referenced this pull request Sep 5, 2012

Merge pull request #5 from lokedhs/master
Add the function TRIVIAL-SHELL:EXIT

@gwkkwg gwkkwg merged commit da2a652 into gwkkwg:master Sep 5, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment