Skip to content

Commit

Permalink
add SB-UNIX:UNIX-EXIT back, use the deprecation framwork for it and S…
Browse files Browse the repository at this point in the history
…B-EXT:QUIT

  Also extend the deprecation framwork to support multiple replacements:
  SB-EXT:QUIT should be replaced either by SB-EXT:EXIT or SB-EXT:ABORT-THREAD,
  depending on the way it was being used.
  • Loading branch information
nikodemus committed May 1, 2012
1 parent f0da2f6 commit ef61e6c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 34 deletions.
4 changes: 3 additions & 1 deletion package-data-list.lisp-expr
Expand Up @@ -2469,7 +2469,9 @@ no guarantees of interface stability."
"UNIX-CLOSEDIR" "UNIX-DIRENT-NAME" "UNIX-DUP"
"UNIX-FILE-MODE" "UNIX-FSTAT"
"UNIX-GETHOSTNAME" "UNIX-GETPID" "UNIX-GETRUSAGE"
"UNIX-GETTIMEOFDAY" "UNIX-GETUID" "UNIX-GID" "UNIX-IOCTL"
"UNIX-GETTIMEOFDAY" "UNIX-GETUID" "UNIX-GID"
"UNIX-EXIT"
"UNIX-IOCTL"
"UNIX-ISATTY" "UNIX-LSEEK" "UNIX-LSTAT" "UNIX-MKDIR"
"UNIX-OPEN" "UNIX-OPENDIR" "UNIX-PATHNAME" "UNIX-PID"
"UNIX-PIPE" "UNIX-SIMPLE-POLL" "UNIX-READ" "UNIX-READDIR" "UNIX-READLINK" "UNIX-REALPATH"
Expand Down
6 changes: 2 additions & 4 deletions src/code/cold-init.lisp
Expand Up @@ -274,10 +274,8 @@
(toplevel-init)
(critically-unreachable "after TOPLEVEL-INIT")))

(defun quit (&key recklessly-p (unix-status 0))
#!+sb-doc
"Deprecated. See: SB-EXT:EXIT, SB-THREAD:RETURN-FROM-THREAD,
SB-THREAD:ABORT-THREAD."
(define-deprecated-function :early "1.0.56.55" quit (exit sb!thread:abort-thread)
(&key recklessly-p (unix-status 0))
(if (or recklessly-p (sb!thread:main-thread-p))
(exit :code unix-status :abort recklessly-p)
(sb!thread:abort-thread))
Expand Down
19 changes: 13 additions & 6 deletions src/code/condition.lisp
Expand Up @@ -1614,22 +1614,29 @@ the usual naming convention (names like *FOO*) for special variables"

(define-condition deprecation-condition ()
((name :initarg :name :reader deprecated-name)
(replacement :initarg :replacement :reader deprecated-name-replacement)
(replacements :initarg :replacements :reader deprecated-name-replacements)
(since :initarg :since :reader deprecated-since)
(runtime-error :initarg :runtime-error :reader deprecated-name-runtime-error)))

(def!method print-object ((condition deprecation-condition) stream)
(let ((*package* (find-package :keyword)))
(if *print-escape*
(print-unreadable-object (condition stream :type t)
(format stream "~S is deprecated~@[, use ~S~]"
(apply #'format
stream "~S is deprecated.~
~#[~; Use ~S instead.~; ~
Use ~S or ~S instead.~:; ~
Use~@{~#[~; or~] ~S~^,~} instead.~]"
(deprecated-name condition)
(deprecated-name-replacement condition)))
(format stream "~@<~S has been deprecated as of SBCL ~A~
~@[, use ~S instead~].~:@>"
(deprecated-name-replacements condition)))
(apply #'format
stream "~@<~S has been deprecated as of SBCL ~A.~
~#[~; Use ~S instead.~; ~
Use ~S or ~S instead.~:; ~
Use~@{~#[~; or~] ~S~^,~:_~} instead.~]~:@>"
(deprecated-name condition)
(deprecated-since condition)
(deprecated-name-replacement condition)))))
(deprecated-name-replacements condition)))))

(define-condition early-deprecation-warning (style-warning deprecation-condition)
())
Expand Down
57 changes: 34 additions & 23 deletions src/code/early-extensions.lisp
Expand Up @@ -1089,52 +1089,63 @@

;;;; Deprecating stuff

(defun deprecation-error (since name replacement)
(defun normalize-deprecation-replacements (replacements)
(if (or (not (listp replacements))
(eq 'setf (car replacements)))
(list replacements)
replacements))

(defun deprecation-error (since name replacements)
(error 'deprecation-error
:name name
:replacement replacement
:replacements (normalize-deprecation-replacements replacements)
:since since))

(defun deprecation-warning (state since name replacement
(defun deprecation-warning (state since name replacements
&key (runtime-error (neq :early state)))
(warn (ecase state
(:early 'early-deprecation-warning)
(:late 'late-deprecation-warning)
(:final 'final-deprecation-warning))
:name name
:replacement replacement
:replacements (normalize-deprecation-replacements replacements)
:since since
:runtime-error runtime-error))

(defun deprecated-function (since name replacement)
(defun deprecated-function (since name replacements)
(lambda (&rest deprecated-function-args)
(declare (ignore deprecated-function-args))
(deprecation-error since name replacement)))
(deprecation-error since name replacements)))

(defun deprecation-compiler-macro (state since name replacement)
(defun deprecation-compiler-macro (state since name replacements)
(lambda (form env)
(declare (ignore env))
(deprecation-warning state since name replacement)
(deprecation-warning state since name replacements)
form))

(defmacro define-deprecated-function (state since name replacement lambda-list &body body)
(let ((doc (let ((*package* (find-package :keyword)))
(format nil "~@<~S has been deprecated as of SBCL ~A~@[, use ~S instead~].~:>"
name since replacement))))
(defmacro define-deprecated-function (state since name replacements lambda-list &body body)
(let* ((replacements (normalize-deprecation-replacements replacements))
(doc (let ((*package* (find-package :keyword)))
(apply #'format nil
"~@<~S has been deprecated as of SBCL ~A.~
~#[~; Use ~S instead.~; ~
Use ~S or ~S instead.~:; ~
Use~@{~#[~; or~] ~S~^,~} instead.~]~@:>"
name since replacements))))
`(progn
,(ecase state
((:early :late)
`(defun ,name ,lambda-list
,doc
,@body))
((:final)
`(progn
(declaim (ftype (function * nil) ,name))
(setf (fdefinition ',name)
(deprecated-function ',name ',replacement ,since))
(setf (documentation ',name 'function) ,doc))))
((:early :late)
`(defun ,name ,lambda-list
,doc
,@body))
((:final)
`(progn
(declaim (ftype (function * nil) ,name))
(setf (fdefinition ',name)
(deprecated-function ',name ',replacements ,since))
(setf (documentation ',name 'function) ,doc))))
(setf (compiler-macro-function ',name)
(deprecation-compiler-macro ,state ,since ',name ',replacement)))))
(deprecation-compiler-macro ,state ,since ',name ',replacements)))))

;;; Anaphoric macros
(defmacro awhen (test &body body)
Expand Down
6 changes: 6 additions & 0 deletions src/code/unix.lisp
Expand Up @@ -430,12 +430,18 @@ corresponds to NAME, or NIL if there is none."
(deftype exit-code ()
`(signed-byte 32))
(defun os-exit (code &key abort)
#!+sb-doc
"Exit the process with CODE. If ABORT is true, exit is performed using _exit(2),
avoiding atexit(3) hooks, etc. Otherwise exit(2) is called."
(unless (typep code 'exit-code)
(setf code (if abort 1 0)))
(if abort
(void-syscall ("_exit" int) code)
(void-syscall ("exit" int) code)))

(define-deprecated-function :early "1.0.56.55" unix-exit os-exit (code)
(os-exit code))

;;; Return the process id of the current process.
(define-alien-routine ("getpid" unix-getpid) int)

Expand Down

0 comments on commit ef61e6c

Please sign in to comment.