From 139f0ec74424e0ab3e6c5bc7268652d96fb7ff1a Mon Sep 17 00:00:00 2001 From: Nikodemus Siivola Date: Fri, 26 Jun 2009 15:56:09 +0000 Subject: [PATCH] 1.0.29.46: export SB-POSIX:FILENAME and SB-POSIX:FILE-DESCRIPTOR * Also define the non-designator types, and export the designator types. * Document both types and functions separately, moving the docs from manual into docstrings. * Extend FILENAME-DESIGNATOR for STREAMS for consistency with pathnames. --- NEWS | 3 ++ contrib/sb-posix/defpackage.lisp | 8 +++-- contrib/sb-posix/designator.lisp | 26 +++++++++----- contrib/sb-posix/macros.lisp | 57 +++++++++++++++++++++++++---- contrib/sb-posix/sb-posix.texinfo | 72 ++++++++----------------------------- version.lisp-expr | 2 +- 6 files changed, 92 insertions(+), 76 deletions(-) diff --git a/NEWS b/NEWS index f73899a..b7e0b04 100644 --- a/NEWS +++ b/NEWS @@ -27,6 +27,9 @@ note being issued is now considered a bug.) * optimization: compiler is smarter about delegating argument type checks to callees. + * bug fix: SB-POSIX exports the documented types and functions + FILE-DESCRIPTOR and FILENAME, and also the corresponding -DESCRIPTOR + types. (reported by "abhi") * bug fix: on 64 bit platforms FILL worked incorrectly on arrays with upgraded element type (COMPLEX SINGLE-FLOAT), regression from 1.0.28.55. (thanks to Paul Khuong) diff --git a/contrib/sb-posix/defpackage.lisp b/contrib/sb-posix/defpackage.lisp index 3b9d6c2..429df93 100644 --- a/contrib/sb-posix/defpackage.lisp +++ b/contrib/sb-posix/defpackage.lisp @@ -2,12 +2,16 @@ (:shadow close open ftruncate truncate time) (:export #:syscall-error #:syscall-errno - ;; grovel structure accessors + ;; types and type conversion + #:file-descriptor-designator + #:file-descriptor + #:filename-designator + #:filename + ;; grovel structure accessors #:dirent-name ;; wrapper class accessors - #:passwd-name #:passwd-passwd #:passwd-uid #:passwd-gid #:passwd-gecos #:passwd-dir #:passwd-shell #:group-name #:group-gid #:group-passwd diff --git a/contrib/sb-posix/designator.lisp b/contrib/sb-posix/designator.lisp index e3c0df7..ef33e40 100644 --- a/contrib/sb-posix/designator.lisp +++ b/contrib/sb-posix/designator.lisp @@ -1,18 +1,26 @@ (in-package :sb-posix) (defvar *designator-types* (make-hash-table :test #'equal)) -(defmacro define-designator (name result &body conversions) - (let ((type `(quote (or ,@(mapcar #'car conversions)))) - (typename (intern (format nil "~A-~A" - (symbol-name name) +(defmacro define-designator (name (lisp-type alien-type) doc + &body conversions) + (let ((designator-type `(or ,@(mapcar #'car conversions))) + (designator-name (intern (format nil "~A-~A" + (symbol-name name) (symbol-name :designator)) - #.*package*))) + #.*package*)) + (name (intern (symbol-name name) :sb-posix))) `(progn + (deftype ,name () + ,@(when doc (list (first doc))) + ',lisp-type) + (deftype ,designator-name () + ,@(when doc (list (second doc))) + ',designator-type) (eval-when (:compile-toplevel :load-toplevel :execute) - (deftype ,typename () ,type) - (setf (gethash ',name *designator-types*) ',result)) - (defun ,(intern (symbol-name name) :sb-posix) (,name) - (declare (type ,typename ,name)) + (setf (gethash ',name *designator-types*) ',alien-type)) + (declaim (ftype (function (t) (values ,lisp-type &optional)) ,name)) + (defun ,name (,name) + ,@(when doc (list (third doc))) (etypecase ,name ,@conversions))))) diff --git a/contrib/sb-posix/macros.lisp b/contrib/sb-posix/macros.lisp index f80e714..e9ec78b 100644 --- a/contrib/sb-posix/macros.lisp +++ b/contrib/sb-posix/macros.lisp @@ -1,20 +1,63 @@ (in-package :sb-posix) -(define-designator filename c-string +(define-designator filename (string c-string) + ("A STRING designating a filename in native namestring syntax. + +Note that native namestring syntax is distinct from Lisp namestring syntax: + + \(pathname \"/foo*/bar\") + +is a wild pathname with a pattern-matching directory component. +SB-EXT:PARSE-NATIVE-NAMESTRING may be used to construct Lisp pathnames that +denote POSIX filenames as understood by system calls, and +SB-EXT:NATIVE-NAMESTRING can be used to coerce them into strings in the native +namestring syntax. + +Note also that POSIX filename syntax does not distinguish the names of files +from the names of directories: in order to parse the name of a directory in +POSIX filename syntax into a pathname MY-DEFAULTS for which + + \(merge-pathnames (make-pathname :name \"FOO\" :case :common) + my-defaults) + +returns a pathname that denotes a file in the directory, supply a true +:AS-DIRECTORY argument to SB-EXT:PARSE-NATIVE-NAMESTRING. Likewise, to supply +the name of a directory to a POSIX function in non-directory syntax, supply a +true :AS-FILE argument to SB-EXT:NATIVE-NAMESTRING." + "Designator for a FILENAME: a STRING designating itself, or a +designator for a PATHNAME designating the corresponding native namestring." + "Converts FILENAME-DESIGNATOR into a FILENAME.") (pathname (sb-ext:native-namestring (translate-logical-pathname filename) :as-file t)) - (string filename)) + (string + filename) + (stream + (filename (pathname filename)))) + +(define-designator file-descriptor (fixnum (integer 32)) + ("A FIXNUM designating a native file descriptor. + +SB-SYS:MAKE-FD-STREAM can be used to construct a FILE-STREAM associated with a +native file descriptor. -(define-designator file-descriptor (integer 32) - (file-stream (sb-sys:fd-stream-fd file-descriptor)) - (fixnum file-descriptor)) +Note that mixing I/O operations on a FILE-STREAM with operations directly on its +descriptor may produce unexpected results if the stream is buffered." + "Designator for a FILE-DESCRIPTOR: either a fixnum designating itself, or +a FILE-STREAM designating the underlying file-descriptor." + "Converts FILE-DESCRIPTOR-DESIGNATOR into a FILE-DESCRIPTOR.") + (file-stream + (sb-sys:fd-stream-fd file-descriptor)) + (fixnum + file-descriptor)) -(define-designator sap-or-nil sb-sys:system-area-pointer +(define-designator sap-or-nil (sb-sys:system-area-pointer sb-sys:system-area-pointer) + () (null (sb-sys:int-sap 0)) (sb-sys:system-area-pointer sap-or-nil)) -(define-designator alien-pointer-to-anything-or-nil (* t) +(define-designator alien-pointer-to-anything-or-nil (sb-alien-internals::alien-value (* t)) + () (null (sb-alien:sap-alien (sb-sys:int-sap 0) (* t))) ((alien (* t)) alien-pointer-to-anything-or-nil)) diff --git a/contrib/sb-posix/sb-posix.texinfo b/contrib/sb-posix/sb-posix.texinfo index 95fd8be..358d2eb 100644 --- a/contrib/sb-posix/sb-posix.texinfo +++ b/contrib/sb-posix/sb-posix.texinfo @@ -23,12 +23,12 @@ consistency of Lisp. Not all functions are available on all platforms. @menu -* Lisp names for C names:: -* Types:: -* Lisp objects and C structures:: -* Function Parameters:: -* Function Return Values:: -* Functions with idiosyncratic bindings:: +* Lisp names for C names:: +* Types:: +* Function Parameters:: +* Function Return Values:: +* Lisp objects and C structures:: +* Functions with idiosyncratic bindings:: @end menu @@ -67,66 +67,24 @@ introduce designators such that CL pathnames or open streams can be passed to these functions. For example, @code{rename} accepts both pathnames and strings as its arguments. -@menu -* File-descriptors:: -* Filenames:: -* Type conversion functions:: +@menu +* File-descriptors:: +* Filenames:: @end menu @node File-descriptors @subsubsection File-descriptors -A file-descriptor is a non-negative small integer. - -A file-stream is a designator for a file-descriptor: the stream's file -descriptor is extracted. Note that mixing I/O operations on a stream -with operations directly on its descriptor may produce unexpected -results if the stream is buffered. - -@code{SB-EXT:MAKE-FD-STREAM} can be used to construct a stream -associated with a file descriptor. +@include type-sb-posix-file-descriptor.texinfo +@include type-sb-posix-file-descriptor-designator.texinfo +@include fun-sb-posix-file-descriptor.texinfo @node Filenames @subsubsection Filenames -A filename is a string. - -A pathname is a designator for a filename: the filename is computed -using the same mechanism that SBCL uses to map pathnames to OS filenames -internally. - -Note that filename syntax is distinct from namestring syntax, and that -@code{SB-EXT:PARSE-NATIVE-NAMESTRING} may be used to construct -Lisp pathnames that denote POSIX filenames returned by system calls. -@xref{Function sb-ext:parse-native-namestring}. Additionally, notice -that POSIX filename syntax does not distinguish the names of files -from the names of directories. Consequently, in order to parse the -name of a directory in POSIX filename syntax into a pathname -@code{defaults} for which - -@lisp -(merge-pathnames (make-pathname :name "FOO" :case :common) - defaults) -@end lisp - -@noindent -returns a pathname that denotes a file in the directory, supply a true -@code{AS-DIRECTORY} argument to @code{SB-EXT:PARSE-NATIVE-NAMESTRING}. -Likewise, if it is necessary to supply the name of a directory to a -POSIX function in non-directory syntax, supply a true @code{AS-FILE} -argument to @code{SB-EXT:NATIVE-NAMESTRING}. - -@node Type conversion functions -@subsubsection Type conversion functions - -For each of these types there is a function of the same name that -converts any valid designator for the type into an object of said type. - -@lisp -(with-open-file (o "/tmp/foo" :direction :output) - (sb-posix:file-descriptor o)) -=> 4 -@end lisp +@include type-sb-posix-filename.texinfo +@include type-sb-posix-filename-designator.texinfo +@include fun-sb-posix-filename.texinfo @node Function Parameters @subsection Function Parameters diff --git a/version.lisp-expr b/version.lisp-expr index 4ad6157..c8d0637 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -17,4 +17,4 @@ ;;; checkins which aren't released. (And occasionally for internal ;;; versions, especially for internal versions off the main CVS ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".) -"1.0.29.45" +"1.0.29.46" -- 1.7.10.4