[version 0.14.0 ediware**20071230060013] { hunk ./CHANGELOG 1 +Version 0.14.0 +2007-12-30 +Some fixes for LispWorks (when the underlying stream is a character stream) +Optimized methods for UNREAD-CHAR% in case of 8-bit encodings +More tests + hunk ./doc/index.html 224 -current version is 0.13.1. +current version is 0.14.0. hunk ./doc/index.html 278 -is signaled. +is signalled. hunk ./doc/index.html 739 -type FLEXI-STREAM-ENCODING-ERROR would have been signaled otherwise. +type FLEXI-STREAM-ENCODING-ERROR would have been signalled otherwise. hunk ./doc/index.html 804 -All errors related to encoding problems with flexi streams are of this type. (This includes situation where an end of file is encountered in the middle of a multi-octet character.) When this condition is signaled during reading, USE-VALUE +All errors related to encoding problems with flexi streams are of this type. (This includes situation where an end of file is encountered in the middle of a multi-octet character.) When this condition is signalled during reading, USE-VALUE hunk ./doc/index.html 825 -

Errors of this type are signaled if an erroneous +

Errors of this type are signalled if an erroneous hunk ./doc/index.html 965 -An error of this type is signaled if one tries to read from or write to an
in-memory stream which had already been closed. This is a subtype of IN-MEMORY-STREAM-ERROR. +An error of this type is signalled if one tries to read from or write to an in-memory stream which had already been closed. This is a subtype of IN-MEMORY-STREAM-ERROR. hunk ./doc/index.html 1040 -$Header: /usr/local/cvsrep/flexi-streams/doc/index.html,v 1.96 2007/10/11 06:56:51 edi Exp $ +$Header: /usr/local/cvsrep/flexi-streams/doc/index.html,v 1.98 2007/12/29 23:15:27 edi Exp $ hunk ./flexi-streams.asd 2 -;;; $Header: /usr/local/cvsrep/flexi-streams/flexi-streams.asd,v 1.57 2007/10/11 06:56:49 edi Exp $ +;;; $Header: /usr/local/cvsrep/flexi-streams/flexi-streams.asd,v 1.58 2007/12/29 23:15:26 edi Exp $ hunk ./flexi-streams.asd 38 - :version "0.13.1" + :version "0.14.0" hunk ./in-memory.lisp 2 -;;; $Header: /usr/local/cvsrep/flexi-streams/in-memory.lisp,v 1.25 2007/01/12 00:08:15 edi Exp $ +;;; $Header: /usr/local/cvsrep/flexi-streams/in-memory.lisp,v 1.26 2007/12/29 21:17:05 edi Exp $ hunk ./in-memory.lisp 117 - (:documentation "An error that is signaled when someone is trying + (:documentation "An error that is signalled when someone is trying hunk ./input.lisp 2 -;;; $Header: /usr/local/cvsrep/flexi-streams/input.lisp,v 1.48 2007/09/06 23:19:24 edi Exp $ +;;; $Header: /usr/local/cvsrep/flexi-streams/input.lisp,v 1.51 2007/12/29 22:58:43 edi Exp $ hunk ./input.lisp 143 +(defgeneric unread-char% (char-code flexi-input-stream) + (:documentation "Used internally to put a character denoted by the +character code CHAR-CODE which was already read back on the stream. +Uses the OCTET-STACK slot and decrements the POSITION slot +accordingly.")) + hunk ./input.lisp 150 - "Used internally to put a character denoted by the character code -CHAR-CODE which was already read back on the stream. Uses the -OCTET-STACK slot and decrements the POSITION slot accordingly." + "The default method which is un-optimized and uses TRANSLATE-CHAR to +figure out which octets to put on the octet stack." hunk ./input.lisp 162 +(defmethod unread-char% (char-code (flexi-input-stream flexi-latin-1-input-stream)) + "For ISO-8859-1 we can simply put the character code itself on the +octet stack." + (declare (optimize speed)) + (with-accessors ((position flexi-stream-position) + (octet-stack flexi-stream-octet-stack)) + flexi-input-stream + (declare (integer position)) + (decf position) + (push char-code octet-stack))) + +(defmethod unread-char% (char-code (flexi-input-stream flexi-ascii-input-stream)) + "For ASCII we can simply put the character code itself on the octet +stack." + (declare (optimize speed)) + (with-accessors ((position flexi-stream-position) + (octet-stack flexi-stream-octet-stack)) + flexi-input-stream + (declare (integer position)) + (decf position) + (push char-code octet-stack))) + +(defmethod unread-char% (char-code (flexi-input-stream flexi-8-bit-input-stream)) + "For 8-bit encodings we just have to put one octet on the octet +stack which we can look up in the encoding hash." + (declare (optimize speed)) + (with-accessors ((position flexi-stream-position) + (octet-stack flexi-stream-octet-stack) + (encoding-hash flexi-stream-encoding-hash)) + flexi-input-stream + (declare (integer position)) + (decf position) + (push (gethash char-code encoding-hash) octet-stack))) + +(defmethod unread-char% ((char-code (eql #.(char-code #\Newline))) + (flexi-input-stream flexi-cr-8-bit-input-stream)) + "A kind of `safety net' for the optimized 8-bit versions of +UNREAD-CHAR% which checks for the single case where more than one +octet has to be put on the octet stack." + (declare (optimize speed)) + (with-accessors ((position flexi-stream-position) + (octet-stack flexi-stream-octet-stack) + (external-format flexi-stream-external-format)) + flexi-input-stream + (declare (integer position)) + ;; note that below we use the knowledge that in all 8-bit encodings + ;; #\Return and #\Linefeed are mapped to the same octets + (case (external-format-eol-style external-format) + (:crlf + (decf position 2) + (push #.(char-code #\Linefeed) octet-stack) + (push #.(char-code #\Return) octet-stack)) + (otherwise + (decf position) + (push #.(char-code #\Return) octet-stack))))) + +#+:lispworks +(defmethod unread-char% ((char-code (eql #.(char-code #\Newline))) + (flexi-input-stream flexi-binary-cr-8-bit-input-stream)) + "A kind of `safety net' for the optimized 8-bit versions of +UNREAD-CHAR% which checks for the single case where more than one +octet has to be put on the octet stack. + +This method \(identical to the one defined directly above) exists only +for LispWorks' \"binary\" streams and must be there due to the +slightly clunky class hierarchy." + (declare (optimize speed)) + (with-accessors ((position flexi-stream-position) + (octet-stack flexi-stream-octet-stack) + (external-format flexi-stream-external-format)) + flexi-input-stream + (declare (integer position)) + ;; note that below we use the knowledge that in all 8-bit encodings + ;; #\Return and #\Linefeed are mapped to the same octets + (case (external-format-eol-style external-format) + (:crlf + (decf position 2) + (push #.(char-code #\Linefeed) octet-stack) + (push #.(char-code #\Return) octet-stack)) + (otherwise + (decf position) + (push #.(char-code #\Return) octet-stack))))) + hunk ./input.lisp 541 - :format-control "Last character read was different from ~S." - :format-arguments (list char))) + :format-control "Last character read (~S) was different from ~S." + :format-arguments (list (code-char last-char-code) char))) hunk ./output.lisp 2 -;;; $Header: /usr/local/cvsrep/flexi-streams/output.lisp,v 1.42 2007/09/13 19:35:49 edi Exp $ +;;; $Header: /usr/local/cvsrep/flexi-streams/output.lisp,v 1.44 2007/12/29 22:23:23 edi Exp $ hunk ./output.lisp 286 + ;; don't use this optimized method for bivalent character streams on + ;; LispWorks, as it currently gets confused by the fill pointer + #+:lispworks + (unless (typep stream 'flexi-binary-output-stream) + (return-from stream-write-sequence + (call-next-method))) hunk ./packages.lisp 2 -;;; $Header: /usr/local/cvsrep/flexi-streams/packages.lisp,v 1.29 2007/10/11 06:56:49 edi Exp $ +;;; $Header: /usr/local/cvsrep/flexi-streams/packages.lisp,v 1.30 2007/10/11 20:23:53 edi Exp $ hunk ./packages.lisp 32 -(unless (find-symbol (if (eq (readtable-case *readtable*) :upcase) - "STREAM-FILE-POSITION" - "stream-file-position") - :trivial-gray-streams) +(unless (find-symbol (symbol-name :stream-file-position) :trivial-gray-streams) hunk ./specials.lisp 2 -;;; $Header: /usr/local/cvsrep/flexi-streams/specials.lisp,v 1.24 2007/09/05 11:30:23 edi Exp $ +;;; $Header: /usr/local/cvsrep/flexi-streams/specials.lisp,v 1.25 2007/12/29 21:17:06 edi Exp $ hunk ./specials.lisp 130 -type FLEXI-STREAM-ENCODING-ERROR would have been signaled otherwise.") +type FLEXI-STREAM-ENCODING-ERROR would have been signalled otherwise.") hunk ./stream.lisp 2 -;;; $Header: /usr/local/cvsrep/flexi-streams/stream.lisp,v 1.50 2007/09/06 23:46:29 edi Exp $ +;;; $Header: /usr/local/cvsrep/flexi-streams/stream.lisp,v 1.53 2007/12/29 22:26:04 edi Exp $ hunk ./stream.lisp 68 - (:documentation "Errors of this type are signaled if the flexi + (:documentation "Errors of this type are signalled if the flexi hunk ./stream.lisp 73 - (:documentation "Errors of this type are signaled if there is an + (:documentation "Errors of this type are signalled if there is an hunk ./stream.lisp 79 - (:documentation "Errors of this type are signaled if an + (:documentation "Errors of this type are signalled if an hunk ./stream.lisp 235 -(defclass flexi-8-bit-input-stream (flexi-input-stream) +(defclass flexi-8-bit-stream (flexi-stream) + ((encoding-hash :accessor flexi-stream-encoding-hash)) + (:documentation "The class for all flexi streams which use an 8-bit +encoding and thus need an additional slot for the encoding hash.")) + +(defclass flexi-8-bit-input-stream (flexi-input-stream flexi-8-bit-stream) hunk ./stream.lisp 242 - (:documentation "The class for all flexi input streams which -use an 8-bit encoding and thus need an additional slot for the -encoding table.")) + (:documentation "The class for all flexi input streams which use an +8-bit encoding and thus need an additional slot for the encoding +table.")) hunk ./stream.lisp 325 -(defclass flexi-8-bit-output-stream (flexi-output-stream) - ((encoding-hash :accessor flexi-stream-encoding-hash)) - (:documentation "The class for all flexi output streams which -use an 8-bit encoding and thus need an additional slot for the -encoding table.")) +(defclass flexi-8-bit-output-stream (flexi-output-stream flexi-8-bit-stream) + () + (:documentation "The class for all flexi output streams which use an +8-bit encoding.")) hunk ./stream.lisp 411 - (:documentation "The class for all flexi I/O streams which use -an 8-bit encoding and thus need an additional slot for the -encoding table.")) + (:documentation "The class for all flexi I/O streams which use an +8-bit encoding.")) hunk ./stream.lisp 639 - (set-encoding-table stream) - (set-encoding-hash stream)) + (set-encoding-hash stream) + (set-encoding-table stream)) hunk ./stream.lisp 642 -(defgeneric set-encoding-table (stream) +(defgeneric set-encoding-hash (stream) hunk ./stream.lisp 644 - (:documentation "Sets the value of the ENCODING-TABLE slot of + (:documentation "Sets the value of the ENCODING-HASH slot of hunk ./stream.lisp 647 -(defgeneric set-encoding-hash (stream) +(defgeneric set-encoding-table (stream) hunk ./stream.lisp 649 - (:documentation "Sets the value of the ENCODING-HASH slot of + (:documentation "Sets the value of the ENCODING-TABLE slot of hunk ./stream.lisp 652 -(defmethod set-encoding-table ((stream flexi-8-bit-input-stream)) - "Sets the value of the ENCODING-TABLE slot of STREAM depending -on its external format." - (declare (optimize speed)) - (with-accessors ((external-format flexi-stream-external-format) - (encoding-table flexi-stream-encoding-table)) - stream - (let ((external-format-name (external-format-name external-format))) - (setq encoding-table - (cond ((ascii-name-p external-format-name) +ascii-table+) - ((koi8-r-name-p external-format-name) +koi8-r-table+) - ((iso-8859-name-p external-format-name) - (cdr (assoc external-format-name +iso-8859-tables+ :test #'eq))) - ((code-page-name-p external-format-name) - (cdr (assoc (external-format-id external-format) +code-page-tables+)))))))) - -(defmethod set-encoding-hash ((stream flexi-8-bit-output-stream)) +(defmethod set-encoding-hash ((stream flexi-8-bit-stream)) hunk ./stream.lisp 668 +(defmethod set-encoding-table ((stream flexi-8-bit-input-stream)) + "Sets the value of the ENCODING-TABLE slot of STREAM depending +on its external format." + (declare (optimize speed)) + (with-accessors ((external-format flexi-stream-external-format) + (encoding-table flexi-stream-encoding-table)) + stream + (let ((external-format-name (external-format-name external-format))) + (setq encoding-table + (cond ((ascii-name-p external-format-name) +ascii-table+) + ((koi8-r-name-p external-format-name) +koi8-r-table+) + ((iso-8859-name-p external-format-name) + (cdr (assoc external-format-name +iso-8859-tables+ :test #'eq))) + ((code-page-name-p external-format-name) + (cdr (assoc (external-format-id external-format) +code-page-tables+)))))))) hunk ./test/test.lisp 2 -;;; $Header: /usr/local/cvsrep/flexi-streams/test/test.lisp,v 1.12 2007/03/09 01:14:30 edi Exp $ +;;; $Header: /usr/local/cvsrep/flexi-streams/test/test.lisp,v 1.17 2007/12/29 22:58:44 edi Exp $ hunk ./test/test.lisp 34 - "The pathname of the file (`test.lisp') where this variable was + "The pathname of the file \(`test.lisp') where this variable was hunk ./test/test.lisp 37 +#+:lispworks +(defun get-env-variable-as-directory (name) + (lw:when-let (string (lw:environment-variable name)) + (when (plusp (length string)) + (cond ((find (char string (1- (length string))) "\\/" :test #'char=) string) + (t (lw:string-append string "/")))))) + hunk ./test/test.lisp 46 - (merge-pathnames "flexi-streams-test/" + (merge-pathnames "odd-streams-test/" hunk ./test/test.lisp 48 - #+:lispworks (pathname (or (lw:environment-variable "TEMP") - (lw:environment-variable "TMP") + #+:lispworks (pathname (or (get-env-variable-as-directory "TEMP") + (get-env-variable-as-directory "TMP") hunk ./test/test.lisp 150 + :element-type 'base-char hunk ./test/test.lisp 156 + :element-type 'base-char hunk ./test/test.lisp 193 - (copy-file full-path-in external-format-in - full-path-out external-format-out - direction-out direction-in) + (copy-file-lw full-path-in external-format-in + full-path-out external-format-out + direction-out direction-in) hunk ./test/test.lisp 200 + #+:lispworks hunk ./test/test.lisp 206 -level utility, marks the test defined by WITH-TEST as faided. CHECK +level utility, marks the test defined by WITH-TEST as failed. CHECK hunk ./test/test.lisp 209 -signaled, this is also considered a failure. +signalled, this is also considered a failure. hunk ./test/test.lisp 236 -restart each time a FLEXI-STREAM-ENCODING-ERROR is signaled. Signals +restart each time a FLEXI-STREAM-ENCODING-ERROR is signalled. Signals hunk ./test/test.lisp 246 - (error "Too many FLEXI-STREAM-ENCODING-ERRORs signaled, expected only ~A." + (error "Too many FLEXI-STREAM-ENCODING-ERRORs signalled, expected only ~A." hunk ./test/test.lisp 252 - (error "~A FLEXI-STREAM-ENCODING-ERRORs signaled, but ~A were expected." + (error "~A FLEXI-STREAM-ENCODING-ERRORs signalled, but ~A were expected." hunk ./test/test.lisp 262 -(defun encoding-error-handling-test() - (with-test ("Handling of encoding errors") +(defun encoding-error-handling-test () + "Tests several possible encoding errors and how they are handled." + (with-test ("Handling of encoding errors.") hunk ./test/test.lisp 295 - ;; the only case when error is signaled for UTF-32 is at end of file + ;; the only case when error is signalled for UTF-32 is at end of file hunk ./test/test.lisp 308 +(defun unread-char-test () + "Tests whether UNREAD-CHAR behaves as expected." + (with-test ("UNREAD-CHAR behaviour.") + (flet ((test-one-file (file-name external-format) + (with-open-file (in (merge-pathnames file-name *this-file*) + :element-type 'flex:octet) + (setq in (make-flexi-stream in :external-format external-format)) + (loop repeat 300 + for char = (read-char in) + do (unread-char char in) + (check (char= (read-char in) char)))))) + (loop for (file-name symbols) in *test-files* + do (loop for symbol in symbols + do (loop for (file-name . external-format) in (create-file-variants file-name symbol) + do (test-one-file file-name external-format))))))) + hunk ./test/test.lisp 338 + (incf no-tests) + (unread-char-test) }