Changeset 4918


Ignore:
Timestamp:
Jul 28, 2006, 12:17:18 AM (18 years ago)
Author:
Gary Byers
Message:

Lots of changes; lots more to go.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/level-1/l1-streams.lisp

    r4907 r4918  
    404404(declaim (inline check-ioblock-owner))
    405405(defun check-ioblock-owner (ioblock)
     406  (declare (optimize (speed 3)))
    406407  (let* ((owner (ioblock-owner ioblock)))
    407408    (if owner
     
    420421           read-p))
    421422
    422 (declaim (inline %ioblock-read-byte))
    423423
    424424;;; Should only be called with the ioblock locked, if that's necessary.
    425 ;;; The whole "bivalent streams" nonsense makes this more complicated
    426 ;;; than it should be.  (Yes, I understand the rationale for that,
    427 ;;; but discovering what type of array we have on each call isn't
    428 ;;; a good approach to the problem.)  That's actually not entirely
    429 ;;; the fault of bivalent streams, to be honest.
     425
    430426(defun %ioblock-read-byte (ioblock)
     427  (declare (optimize (speed 3) (safety 0)))
     428  ;;; It's so dumb to be dealing with the effect of UNREAD-CHAR
     429  ;;; on a binary stream, but since this is kind of a general
     430  ;;; method, we kind of have to here.
     431  (if (ioblock-untyi-char ioblock)
     432    (prog1 (%char-code (ioblock-untyi-char ioblock))
     433      (setf (ioblock-untyi-char ioblock) nil))
     434    (let* ((buf (ioblock-inbuf ioblock))
     435           (idx (io-buffer-idx buf))
     436           (limit (io-buffer-count buf)))
     437      (declare (fixnum idx limit))
     438      (when (= idx limit)
     439        (unless (%ioblock-advance ioblock t)
     440          (return-from %ioblock-read-byte :eof))
     441        (setq idx (io-buffer-idx buf)
     442              limit (io-buffer-count buf)))
     443      (setf (io-buffer-idx buf) (the fixnum (1+ idx)))
     444      (uvref (io-buffer-buffer buf) idx))))
     445
     446(defun %bivalent-ioblock-read-u8-byte (ioblock)
    431447  (declare (optimize (speed 3) (safety 0)))
    432448  (if (ioblock-untyi-char ioblock)
     
    439455      (when (= idx limit)
    440456        (unless (%ioblock-advance ioblock t)
    441           (return-from %ioblock-read-byte :eof))
     457          (return-from %bivalent-ioblock-read-u8-byte :eof))
    442458        (setq idx (io-buffer-idx buf)
    443459              limit (io-buffer-count buf)))
    444460      (setf (io-buffer-idx buf) (the fixnum (1+ idx)))
    445       (let* ((vec (io-buffer-buffer buf)))
    446         (if (typep vec 'simple-string)
    447           (aref (the (simple-array (unsigned-byte 8) (*))
    448                   vec) idx)
    449           (uvref vec idx))))))
    450 
    451 (declaim (inline %private-ioblock-read-byte))
    452 (defun %private-ioblock-read-byte (ioblock)
     461      (aref (the (simple-array (unsigned-byte 8) (*))
     462              (io-buffer-buffer buf)) idx))))
     463
     464(defun %ioblock-read-u8-byte (ioblock)
     465  (declare (optimize (speed 3) (safety 0)))
     466  (let* ((buf (ioblock-inbuf ioblock))
     467         (idx (io-buffer-idx buf))
     468         (limit (io-buffer-count buf)))
     469    (declare (fixnum idx limit))
     470    (when (= idx limit)
     471      (unless (%ioblock-advance ioblock t)
     472        (return-from %ioblock-read-u8-byte :eof))
     473      (setq idx (io-buffer-idx buf)
     474            limit (io-buffer-count buf)))
     475    (setf (io-buffer-idx buf) (the fixnum (1+ idx)))
     476    (aref (the (simple-array (unsigned-byte 8) (*))
     477            (io-buffer-buffer buf)) idx)))
     478
     479
     480(defun %bivalent-private-ioblock-read-u8-byte (ioblock)
    453481  (declare (optimize (speed 3) (safety 0)))
    454482  (check-ioblock-owner ioblock)
     
    462490      (when (= idx limit)
    463491        (unless (%ioblock-advance ioblock t)
    464           (return-from %private-ioblock-read-byte :eof))
     492          (return-from %bivalent-private-ioblock-read-u8-byte :eof))
    465493        (setq idx (io-buffer-idx buf)
    466494              limit (io-buffer-count buf)))
    467495      (setf (io-buffer-idx buf) (the fixnum (1+ idx)))
    468       (let* ((vec (io-buffer-buffer buf)))
    469         (if (typep vec 'simple-string)
    470           (aref (the (simple-array (unsigned-byte 8) (*))
    471                   vec) idx)
    472           (uvref vec idx))))))
    473 
    474 (defun %locked-ioblock-read-byte (ioblock)
     496      (aref (the (simple-array (unsigned-byte 8) (*))
     497              (io-buffer-buffer buf)) idx))))
     498
     499(defun %private-ioblock-read-u8-byte (ioblock)
     500  (declare (optimize (speed 3) (safety 0)))
     501  (check-ioblock-owner ioblock)
     502  (let* ((buf (ioblock-inbuf ioblock))
     503         (idx (io-buffer-idx buf))
     504         (limit (io-buffer-count buf)))
     505    (declare (fixnum idx limit))
     506    (when (= idx limit)
     507      (unless (%ioblock-advance ioblock t)
     508        (return-from %private-ioblock-read-u8-byte :eof))
     509      (setq idx (io-buffer-idx buf)
     510            limit (io-buffer-count buf)))
     511    (setf (io-buffer-idx buf) (the fixnum (1+ idx)))
     512    (aref (the (simple-array (unsigned-byte 8) (*))
     513            (io-buffer-buffer buf)) idx)))
     514
     515(defun %bivalent-locked-ioblock-read-u8-byte (ioblock)
    475516  (declare (optimize (speed 3) (safety 0)))
    476517  (with-ioblock-lock-grabbed ((locally (declare (optimize (speed 3) (safety 0)))
    477518                                (ioblock-inbuf-lock ioblock)))
    478   (if (ioblock-untyi-char ioblock)
    479     (prog1 (%char-code (ioblock-untyi-char ioblock))
    480       (setf (ioblock-untyi-char ioblock) nil))
     519    (if (ioblock-untyi-char ioblock)
     520      (prog1 (%char-code (ioblock-untyi-char ioblock))
     521        (setf (ioblock-untyi-char ioblock) nil))
     522      (let* ((buf (ioblock-inbuf ioblock))
     523             (idx (io-buffer-idx buf))
     524             (limit (io-buffer-count buf)))
     525        (declare (fixnum idx limit))
     526        (when (= idx limit)
     527          (unless (%ioblock-advance ioblock t)
     528            (return-from %bivalent-locked-ioblock-read-u8-byte :eof))
     529          (setq idx (io-buffer-idx buf)
     530                limit (io-buffer-count buf)))
     531        (setf (io-buffer-idx buf) (the fixnum (1+ idx)))
     532        (aref (the (simple-array (unsigned-byte 8) (*))
     533                (io-buffer-buffer buf)) idx)))))
     534
     535(defun %locked-ioblock-read-u8-byte (ioblock)
     536  (declare (optimize (speed 3) (safety 0)))
     537  (with-ioblock-lock-grabbed ((locally (declare (optimize (speed 3) (safety 0)))
     538                                (ioblock-inbuf-lock ioblock)))
    481539    (let* ((buf (ioblock-inbuf ioblock))
    482            (idx (io-buffer-idx buf))
    483            (limit (io-buffer-count buf)))
     540           (idx (io-buffer-idx buf))
     541           (limit (io-buffer-count buf)))
    484542      (declare (fixnum idx limit))
    485543      (when (= idx limit)
    486         (unless (%ioblock-advance ioblock t)
    487           (return-from %locked-ioblock-read-byte :eof))
    488         (setq idx (io-buffer-idx buf)
    489               limit (io-buffer-count buf)))
     544        (unless (%ioblock-advance ioblock t)
     545          (return-from %locked-ioblock-read-u8-byte :eof))
     546        (setq idx (io-buffer-idx buf)
     547              limit (io-buffer-count buf)))
    490548      (setf (io-buffer-idx buf) (the fixnum (1+ idx)))
    491       (let* ((vec (io-buffer-buffer buf)))
    492         (if (typep vec 'simple-string)
    493           (aref (the (simple-array (unsigned-byte 8) (*))
    494                   vec) idx)
    495           (uvref vec idx)))))))
    496 
    497 
    498 
    499 (declaim (inline %ioblock-tyi))
     549      (aref (the (simple-array (unsigned-byte 8) (*))
     550              (io-buffer-buffer buf)) idx))))
     551
     552(defun %general-ioblock-read-byte (ioblock)
     553  (declare (optimize (speed 3) (safety 0)))
     554  (with-ioblock-input-locked (ioblock)
     555    (let* ((buf (ioblock-inbuf ioblock))
     556           (idx (io-buffer-idx buf))
     557           (limit (io-buffer-count buf)))
     558      (declare (fixnum idx limit))
     559      (when (= idx limit)
     560        (unless (%ioblock-advance ioblock t)
     561          (return-from %general-ioblock-read-byte :eof))
     562        (setq idx (io-buffer-idx buf)
     563              limit (io-buffer-count buf)))
     564      (setf (io-buffer-idx buf) (the fixnum (1+ idx)))
     565      (uvref (io-buffer-buffer buf) idx))))
     566
     567
    500568
    501569(defun %ioblock-tyi (ioblock)
    502570  (declare (optimize (speed 3) (safety 0)))
    503   (if (ioblock-untyi-char ioblock)
    504     (prog1 (ioblock-untyi-char ioblock)
    505       (setf (ioblock-untyi-char ioblock) nil))
    506     (let* ((buf (ioblock-inbuf ioblock))
    507            (idx (io-buffer-idx buf))
    508            (limit (io-buffer-count buf)))
    509       (declare (fixnum idx limit))
    510       (when (= idx limit)
    511         (unless (%ioblock-advance ioblock t)
    512           (return-from %ioblock-tyi (if (ioblock-eof ioblock) :eof)))
    513         (setq idx (io-buffer-idx buf)
    514               limit (io-buffer-count buf)))
    515       (setf (io-buffer-idx buf) (the fixnum (1+ idx)))
    516       (schar (io-buffer-buffer buf) idx))))
    517 
    518 (declaim (inline %private-ioblock-tyi))
     571  (let* ((ch (ioblock-untyi-char ioblock)))
     572    (if ch
     573      (prog1 ch
     574        (setf (ioblock-untyi-char ioblock) nil))
     575      (let* ((buf (ioblock-inbuf ioblock))
     576             (idx (io-buffer-idx buf))
     577             (limit (io-buffer-count buf)))
     578        (declare (fixnum idx limit))
     579        (when (= idx limit)
     580          (unless (%ioblock-advance ioblock t)
     581            (return-from %ioblock-tyi (if (ioblock-eof ioblock) :eof)))
     582          (setq idx (io-buffer-idx buf)
     583                limit (io-buffer-count buf)))
     584        (setf (io-buffer-idx buf) (the fixnum (1+ idx)))
     585        (schar (io-buffer-buffer buf) idx)))))
     586
    519587(defun %private-ioblock-tyi (ioblock)
    520588  (declare (optimize (speed 3) (safety 0)))
     
    535603      (schar (io-buffer-buffer buf) idx))))
    536604
    537 (declaim (inline %locked-ioblock-tyi))
    538605(defun %locked-ioblock-tyi (ioblock)
    539606  (declare (optimize (speed 3) (safety 0)))
     
    9771044
    9781045
    979 
     1046(defun setup-ioblock-input (ioblock character-p element-type sharing)
     1047  (when character-p
     1048    (setf (ioblock-read-char-function ioblock)
     1049          (case sharing
     1050            (:private '%private-ioblock-tyi)
     1051            (:lock '%locked-ioblock-tyi)
     1052            (t '%ioblock-tyi))))
     1053  (unless (or (eq element-type 'character)
     1054              (subtypep element-type 'character))
     1055    (let* ((subtag (element-type-subtype element-type)))
     1056      (declare (type (unsigned-byte 8) subtag))
     1057      (setf (ioblock-read-byte-function ioblock)
     1058            (cond ((= subtag target::subtag-u8-vector)
     1059                   (if character-p
     1060                     ;; The bivalent case, at least for now
     1061                     (case sharing
     1062                       (:private '%bivalent-private-ioblock-read-u8-byte)
     1063                       (:lock '%bivalent-locked-ioblock-read-u8-byte)
     1064                       (t '%bivalent-ioblock-read-u8-byte))
     1065                     (case sharing
     1066                       (:private '%private-ioblock-read-u8-byte)
     1067                       (:lock '%locked-ioblock-read-u8-byte)
     1068                       (t '%ioblock-read-u8-byte))))
     1069                  (t '%general-ioblock-read-byte)))))) 
    9801070
    9811071(defun init-stream-ioblock (stream
    9821072                            &key
    983                             insize ; integer to allocate inbuf here, nil
     1073                            insize      ; integer to allocate inbuf here, nil
    9841074                                        ; otherwise
    985                             outsize ; integer to allocate outbuf here, nil
     1075                            outsize     ; integer to allocate outbuf here, nil
    9861076                                        ; otherwise
    9871077                            share-buffers-p ; true if input and output
     
    10241114          (when (eq sharing :lock)
    10251115            (setf (ioblock-inbuf-lock ioblock) (make-lock)))
    1026           (if character-p
    1027             (setf (ioblock-read-char-function ioblock)
    1028                    (case sharing
    1029                      (:private '%private-ioblock-tyi)
    1030                      (:lock '%locked-ioblock-tyi)
    1031                      (t '%ioblock-tyi))))
     1116          (setup-ioblock-input ioblock character-p element-type sharing)
    10321117          (setf (ioblock-element-shift ioblock) (max 0 (ceiling (log  (/ in-size-in-octets insize) 2))))
    10331118          )))
    10341119    (if share-buffers-p
    1035         (if insize
    1036             (progn (setf (ioblock-outbuf ioblock)
    1037                          (ioblock-inbuf ioblock))
    1038                    (setf (ioblock-outbuf-lock ioblock)
    1039                          (ioblock-inbuf-lock ioblock)))
    1040           (error "Can't share buffers unless insize is non-zero and non-null"))
    1041      
     1120      (if insize
     1121        (progn (setf (ioblock-outbuf ioblock)
     1122                     (ioblock-inbuf ioblock))
     1123               (setf (ioblock-outbuf-lock ioblock)
     1124                     (ioblock-inbuf-lock ioblock)))
     1125        (error "Can't share buffers unless insize is non-zero and non-null"))
    10421126      (when outsize
    10431127        (unless (ioblock-outbuf ioblock)
     
    11061190
    11071191
    1108 
     1192;;; Note that we can get "bivalent" streams by specifiying :character-p t
     1193;;; with a reasonable element-type (e.g. (UNSIGNED-BYTE 8))
    11091194(defun make-fd-stream (fd &key
    11101195                          (direction :input)
     
    11141199                          (class 'fd-stream)
    11151200                          (sharing :private)
     1201                          (character-p (or (eq element-type 'character)
     1202                                           (subtypep element-type 'character)))
    11161203                          (basic nil))
    11171204  (when basic
     
    11201207  (let* ((in-p (member direction '(:io :input)))
    11211208         (out-p (member direction '(:io :output)))
    1122          (char-p (or (eq element-type 'character)
    1123                      (subtypep element-type 'character)))
    1124          (class-name (select-stream-class class in-p out-p char-p)))
     1209         (class-name (select-stream-class class in-p out-p character-p)))
    11251210    (make-ioblock-stream class-name
    11261211                         :insize (if in-p elements-per-buffer)
     
    11411226                         :close-function 'fd-stream-close
    11421227                         :sharing sharing
    1143                          :character-p char-p)))
     1228                         :character-p character-p)))
    11441229 
    11451230;;;  Fundamental streams.
     
    12521337  (declare (ignore new)))
    12531338
    1254 (defmethod stream-start-line-p ((s fundamental-character-output-stream))
     1339(defmethod stream-start-line-p ((s character-output-stream))
    12551340  (eql 0 (stream-line-column s)))
    12561341
    1257 (defmethod stream-terpri ((s fundamental-character-output-stream))
     1342(defmethod stream-terpri ((s character-output-stream))
    12581343  (stream-write-char s #\Newline))
    12591344
    1260 (defmethod stream-fresh-line ((s fundamental-character-output-stream))
     1345(defmethod stream-fresh-line ((s character-output-stream))
    12611346  (unless (stream-start-line-p s)
    12621347    (stream-terpri s)
     
    13501435
    13511436
     1437(declaim (inline basic-stream-p))
     1438
    13521439(defun basic-stream-p (x)
    13531440  (= (the fixnum (typecode x)) target::subtag-basic-stream))
     
    13621449(make-built-in-class 'basic-input-stream 'basic-stream 'input-stream)
    13631450(make-built-in-class 'basic-output-stream 'basic-stream 'input-stream)
    1364 (make-built-in-class 'basic-character-input-stream 'basic-input-stream 'basic-character-stream)
    1365 (make-built-in-class 'basic-character-output-stream 'basic-output-stream 'basic-character-stream)
     1451(make-built-in-class 'basic-character-input-stream 'basic-input-stream 'basic-character-stream 'character-input-stream)
     1452(make-built-in-class 'basic-character-output-stream 'basic-output-stream 'basic-character-stream 'character-output-stream)
    13661453(make-built-in-class 'basic-character-io-stream 'basic-character-input-stream 'basic-character-output-stream)
    1367 (make-built-in-class 'basic-binary-input-stream 'basic-input-stream 'basic-binary-stream)
    1368 (make-built-in-class 'basic-binary-output-stream 'basic-output-stream 'basic-binary-stream)
     1454(make-built-in-class 'basic-binary-input-stream 'basic-input-stream 'basic-binary-stream 'binary-input-stream)
     1455(make-built-in-class 'basic-binary-output-stream 'basic-output-stream 'basic-binary-stream 'binary-output-stream)
    13691456(make-built-in-class 'basic-binary-io-stream 'basic-binary-input-stream 'basic-binary-output-stream)
    13701457
     1458
     1459(defmethod input-stream-shared-resource ((s basic-input-stream))
     1460  (getf (basic-stream.info s) :shared-resource))
     1461
     1462(defmethod (setf input-stream-shared-resource) (new (s basic-input-stream))
     1463  (setf (getf (basic-stream.info s) :shared-resource) new))
     1464
     1465(defmethod print-object ((s basic-stream) out)
     1466  (print-unreadable-object (s out :type t :identity t)
     1467    (let* ((ioblock (basic-stream.state s))
     1468           (fd (and ioblock (ioblock-device ioblock))))
     1469      (if fd
     1470        (format out "(~a/~d)" (%unix-fd-kind fd) fd)
     1471        (format out "~s" :closed)))))
    13711472
    13721473(defmethod select-stream-class ((s (eql 'basic-stream)) in-p out-p char-p)
     
    14101511        (logior (ash 1 basic-stream-flag.open-binary) (basic-stream.flags s))))
    14111512
     1513(defmethod initialize-basic-stream :after ((s basic-character-stream) &key &allow-other-keys)
     1514  (setf (basic-stream.flags s)
     1515        (logior (ash 1 basic-stream-flag.open-character) (basic-stream.flags s))))
     1516
    14121517(defun make-basic-stream-instance (class &rest initargs)
    14131518  (let* ((s (allocate-basic-stream class)))
     
    14251530  (apply #'make-ioblock :stream stream args))
    14261531
     1532
     1533(defun stream-is-closed (s)
     1534  (error "~s is closed" s))
     1535
    14271536(defmethod stream-read-char ((s basic-character-input-stream))
    1428   (let* ((ioblock (basic-stream.state s)))
    1429     (if ioblock
    1430       (funcall (ioblock-read-char-function ioblock) ioblock)
    1431       (error "~s is closed" s))))
     1537  (let* ((ioblock (basic-stream-ioblock s)))
     1538    (funcall (ioblock-read-char-function ioblock) ioblock)))
     1539
     1540
     1541(defmethod stream-read-char-no-hang ((stream basic-character-input-stream))
     1542  (let* ((ioblock (basic-stream-ioblock stream)))
     1543    (with-ioblock-input-locked (ioblock)
     1544      (%ioblock-tyi-no-hang ioblock))))
    14321545       
    1433 
    1434 
     1546(defmethod stream-peek-char ((stream basic-character-input-stream))
     1547  (let* ((ioblock (basic-stream-ioblock stream)))
     1548    (with-ioblock-input-locked (ioblock)
     1549      (%ioblock-peek-char ioblock))))
     1550
     1551(defmethod stream-clear-input ((stream basic-character-input-stream))
     1552  (let* ((ioblock (basic-stream-ioblock stream)))
     1553    (with-ioblock-input-locked (ioblock)
     1554      (%ioblock-clear-input ioblock))))
     1555
     1556(defmethod stream-unread-char ((s basic-character-input-stream) char)
     1557  (let* ((ioblock (basic-stream-ioblock s)))
     1558    (with-ioblock-input-locked (ioblock)
     1559      (%ioblock-untyi ioblock char))))
     1560
     1561(defmethod stream-read-ivector ((s basic-character-input-stream)
     1562                                iv start nb)
     1563  (let* ((ioblock (basic-stream-ioblock s)))
     1564    (with-ioblock-input-locked (ioblock)
     1565      (%ioblock-character-in-ivect ioblock iv start nb))))
     1566
     1567(defmethod stream-read-vector ((stream basic-character-input-stream)
     1568                               vector start end)
     1569  (declare (fixnum start end))
     1570  (if (not (typep vector 'simple-base-string))
     1571    (call-next-method)
     1572    (let* ((ioblock (basic-stream-ioblock stream)))
     1573      (with-ioblock-input-locked (ioblock)
     1574        (%ioblock-character-read-vector ioblock vector start end)))))
    14351575
    14361576;;; Synonym streams.
     
    18211961(defmethod string-stream-string ((s string-stream))
    18221962  (or (%string-stream-string s)
    1823       (error "~s is closed" s)))
     1963      (values (stream-is-closed s))))
    18241964
    18251965(defmethod open-stream-p ((s string-stream))
     
    20552195  (or (%stream-ioblock stream)
    20562196      (when error-if-nil
    2057         (error "~s is closed" stream))))
     2197        (stream-is-closed stream))))
    20582198
    20592199(defmethod stream-device ((s buffered-stream-mixin) direction)
     
    21302270
    21312271
     2272(defmethod close :after ((stream basic-stream) &key abort)
     2273  (declare (ignore abort))
     2274  (let* ((ioblock (basic-stream.state stream)))
     2275    (when ioblock
     2276      (%ioblock-close ioblock))))
     2277
     2278
     2279(defmethod open-stream-p ((stream basic-stream))
     2280  (not (null (basic-stream.state stream))))
     2281
     2282(defmethod close :before ((stream basic-output-stream) &key abort)
     2283  (unless abort
     2284    (when (open-stream-p stream)
     2285      (stream-force-output stream))))
     2286
    21322287#|
    21332288(defgeneric ioblock-advance (stream ioblock readp)
     
    21952350(defmethod stream-read-byte ((stream buffered-binary-input-stream-mixin))
    21962351  (with-stream-ioblock-input (ioblock stream :speedy t)
    2197     (%ioblock-read-byte ioblock)))
     2352    (funcall (ioblock-read-byte-function ioblock) ioblock)))
    21982353
    21992354(defmethod stream-eofp ((stream buffered-input-stream-mixin))
     
    22182373    (%ioblock-write-char ioblock char)))
    22192374
     2375(defmethod stream-write-char ((stream basic-character-output-stream) char)
     2376  (let* ((ioblock (basic-stream-ioblock stream)))
     2377    (with-ioblock-output-locked (ioblock)
     2378      (%ioblock-write-char ioblock char))))
     2379
     2380
    22202381(defmethod stream-clear-output ((stream buffered-output-stream-mixin))
    22212382  (with-stream-ioblock-output (ioblock stream :speedy t)
     
    22232384  nil)
    22242385
     2386(defmethod stream-clear-output ((stream basic-output-stream))
     2387  (let* ((ioblock (basic-stream-ioblock stream)))
     2388    (with-ioblock-output-locked (ioblock)
     2389      (%ioblock-clear-output ioblock))
     2390    nil))
     2391
    22252392(defmethod stream-line-column ((stream buffered-character-output-stream-mixin))
    22262393  (let* ((ioblock (stream-ioblock stream nil)))
     
    22322399    (and ioblock (setf (ioblock-charpos ioblock) new))))
    22332400
     2401(defmethod stream-set-column ((stream basic-character-output-stream)
     2402                              new)
     2403  (let* ((ioblock (basic-stream.state stream)))
     2404    (and ioblock (setf (ioblock-charpos ioblock) new))))
     2405
    22342406(defmethod stream-force-output ((stream buffered-output-stream-mixin))
    22352407  (with-stream-ioblock-output (ioblock stream :speedy t)
     
    22372409    nil))
    22382410
     2411(defmethod stream-force-output ((stream basic-output-stream))
     2412  (let* ((ioblock (basic-stream-ioblock stream)))
     2413    (with-ioblock-output-locked (ioblock)
     2414      (%ioblock-force-output ioblock nil)
     2415      nil)))
     2416
    22392417(defmethod maybe-stream-force-output ((stream buffered-output-stream-mixin))
    22402418  (with-stream-ioblock-output-maybe (ioblock stream :speedy t)
     
    22422420    nil))
    22432421
     2422(defmethod maybe-stream-force-output ((stream basic-output-stream))
     2423  (let* ((ioblock (basic-stream-ioblock stream)))
     2424    (with-ioblock-output-locked-maybe (ioblock)
     2425      (%ioblock-force-output ioblock nil)
     2426      nil)))
     2427
    22442428(defmethod stream-finish-output ((stream buffered-output-stream-mixin))
    22452429  (with-stream-ioblock-output (ioblock stream :speedy t)
     
    22472431    nil))
    22482432
     2433(defmethod stream-finish-output ((stream basic-output-stream))
     2434  (let* ((ioblock (basic-stream-ioblock stream)))
     2435    (with-ioblock-output-locked (ioblock)
     2436      (%ioblock-force-output ioblock t)
     2437      nil)))
     2438
     2439(defun %ioblock-write-general-string (ioblock string start end)
     2440  (setq end (check-sequence-bounds string start end))
     2441  (locally (declare (fixnum start end))
     2442    (multiple-value-bind (arr offset)
     2443        (if (typep string 'simple-string)
     2444          (values string 0)
     2445          (array-data-and-offset (require-type string 'string)))
     2446      (unless (eql 0 offset)
     2447        (incf start offset)
     2448        (incf end offset))
     2449      (%ioblock-write-simple-string ioblock arr start (the fixnum (- end start))))))
     2450 
    22492451(defmethod stream-write-string ((stream buffered-character-output-stream-mixin)
    22502452                                string &optional (start 0 start-p) end)
     
    22542456             (not start-p))
    22552457      (%ioblock-write-simple-string ioblock string 0 (length string))
    2256       (progn
    2257         (setq end (check-sequence-bounds string start end))
    2258         (locally (declare (fixnum start end))
    2259           (multiple-value-bind (arr offset)
    2260               (if (typep string 'simple-string)
    2261                 (values string 0)
    2262                 (array-data-and-offset (require-type string 'string)))
    2263             (unless (eql 0 offset)
    2264               (incf start offset)
    2265               (incf end offset))
    2266             (%ioblock-write-simple-string ioblock arr start (the fixnum (- end start)))))))))
     2458      (%ioblock-write-general-string ioblock string start end))))
     2459
     2460(defmethod stream-write-string ((stream basic-character-output-stream)
     2461                                string &optional (start 0 start-p) end)
     2462
     2463  (let* ((ioblock (basic-stream-ioblock stream)))
     2464    (with-ioblock-output-locked (ioblock)
     2465    (if (and (typep string 'simple-string)
     2466             (not start-p))
     2467      (%ioblock-write-simple-string ioblock string 0 (length string))
     2468      (%ioblock-write-general-string ioblock string start end)))))
    22672469
    22682470
     
    23682570
    23692571(defun unread-data-available-p (fd)
    2370   (%stack-block ((arg 4))
    2371     (setf (%get-long arg) 0)
     2572  (rlet ((arg (* :char) (%null-ptr)))
    23722573    (when (zerop (syscall syscalls::ioctl fd #$FIONREAD arg))
    2373       (let* ((avail (%get-long arg)))
     2574      (let* ((avail (pref arg :long)))
    23742575        (and (> avail 0) avail)))))
    23752576
     
    24132614  (let* ((wait-end (if ticks (+ (get-tick-count) ticks))))
    24142615    (loop
    2415       (when (fd-input-available-p fd 0)
     2616      ;; FD-INPUT-AVAILABLE-P can return NIL (e.g., if the
     2617      ;; thread receives an interrupt) before a timeout is
     2618      ;; reached.
     2619      (when (fd-input-available-p fd ticks)
    24162620        (return t))
    2417       (let* ((now (if ticks (get-tick-count))))
    2418         (if (and wait-end (>= now wait-end))
    2419           (return))
    2420         (fd-input-available-p fd (if ticks (- wait-end now)))))))
     2621      ;; If it returned and a timeout was specified, check
     2622      ;; to see if it's been exceeded.  If so, return NIL;
     2623      ;; otherwise, adjust the remaining timeout.
     2624      ;; If there was no timeout, continue to wait forever.
     2625      (when ticks
     2626        (let* ((now (get-tick-count)))
     2627          (if (and wait-end (>= now wait-end))
     2628            (return)
     2629            (setq ticks (- wait-end now))))))))
    24212630
    24222631
     
    24252634  "Wait until output is possible on a given file descriptor."
    24262635  (loop
    2427     (when (fd-ready-for-output-p fd 0)
    2428       (return t))
    2429     (process-wait "output-wait" #'fd-ready-for-output-p fd *ticks-per-second*)))
     2636    (when (fd-ready-for-output-p fd nil)
     2637      (return t))))
    24302638
    24312639
     
    24442652  (rletZ ((tv :timeval))
    24452653    (ticks-to-timeval ticks tv)
    2446     (%stack-block ((infds *fd-set-size*)
    2447                    (errfds *fd-set-size*))
     2654    (%stack-block ((infds *fd-set-size*))
    24482655      (fd-zero infds)
    2449       (fd-zero errfds)
    24502656      (fd-set fd infds)
    2451       (fd-set fd errfds)
    2452       (let* ((res (syscall syscalls::select (1+ fd) infds (%null-ptr) errfds
     2657      (let* ((res (syscall syscalls::select (1+ fd) infds (%null-ptr) (%null-ptr)
    24532658                           (if ticks tv (%null-ptr)))))
    24542659        (> res 0)))))
     
    24572662  (rletZ ((tv :timeval))
    24582663    (ticks-to-timeval ticks tv)
    2459     (%stack-block ((outfds *fd-set-size*)
    2460                    (errfds *fd-set-size*))
     2664    (%stack-block ((outfds *fd-set-size*))
    24612665      (fd-zero outfds)
    2462       (fd-zero errfds)
    24632666      (fd-set fd outfds)
    2464       (fd-set fd errfds)
    2465       (let* ((res (#_select (1+ fd) (%null-ptr) outfds errfds
     2667      (let* ((res (#_select (1+ fd) (%null-ptr) outfds (%null-ptr)
    24662668                            (if ticks tv (%null-ptr)))))
    24672669        (> res 0)))))
     
    26982900                                               (t :create)))
    26992901                      (external-format :default)
    2700                       (class 'file-stream)
     2902                      (class 'fundamental-file-stream)
    27012903                      (elements-per-buffer *elements-per-buffer*)
    27022904                      (sharing :private))
     
    27962998
    27972999;;; Initialize the global streams
    2798 ; These are defparameters because they replace the ones that were in l1-init
    2799 ; while bootstrapping.
     3000;;; These are defparameters because they replace the ones that were in l1-init
     3001;;; while bootstrapping.
    28003002
    28013003(defparameter *terminal-io* nil "terminal I/O stream")
     
    28933095
    28943096
     3097
     3098
     3099
    28953100; end of L1-streams.lisp
Note: See TracChangeset for help on using the changeset viewer.