Changeset 4918
- Timestamp:
- Jul 28, 2006, 12:17:18 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/ccl/level-1/l1-streams.lisp (modified) (35 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ccl/level-1/l1-streams.lisp
r4907 r4918 404 404 (declaim (inline check-ioblock-owner)) 405 405 (defun check-ioblock-owner (ioblock) 406 (declare (optimize (speed 3))) 406 407 (let* ((owner (ioblock-owner ioblock))) 407 408 (if owner … … 420 421 read-p)) 421 422 422 (declaim (inline %ioblock-read-byte))423 423 424 424 ;;; 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 430 426 (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) 431 447 (declare (optimize (speed 3) (safety 0))) 432 448 (if (ioblock-untyi-char ioblock) … … 439 455 (when (= idx limit) 440 456 (unless (%ioblock-advance ioblock t) 441 (return-from % ioblock-read-byte :eof))457 (return-from %bivalent-ioblock-read-u8-byte :eof)) 442 458 (setq idx (io-buffer-idx buf) 443 459 limit (io-buffer-count buf))) 444 460 (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) 453 481 (declare (optimize (speed 3) (safety 0))) 454 482 (check-ioblock-owner ioblock) … … 462 490 (when (= idx limit) 463 491 (unless (%ioblock-advance ioblock t) 464 (return-from % private-ioblock-read-byte :eof))492 (return-from %bivalent-private-ioblock-read-u8-byte :eof)) 465 493 (setq idx (io-buffer-idx buf) 466 494 limit (io-buffer-count buf))) 467 495 (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) 475 516 (declare (optimize (speed 3) (safety 0))) 476 517 (with-ioblock-lock-grabbed ((locally (declare (optimize (speed 3) (safety 0))) 477 518 (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))) 481 539 (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))) 484 542 (declare (fixnum idx limit)) 485 543 (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))) 490 548 (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 500 568 501 569 (defun %ioblock-tyi (ioblock) 502 570 (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 ioblockt)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 519 587 (defun %private-ioblock-tyi (ioblock) 520 588 (declare (optimize (speed 3) (safety 0))) … … 535 603 (schar (io-buffer-buffer buf) idx)))) 536 604 537 (declaim (inline %locked-ioblock-tyi))538 605 (defun %locked-ioblock-tyi (ioblock) 539 606 (declare (optimize (speed 3) (safety 0))) … … 977 1044 978 1045 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)))))) 980 1070 981 1071 (defun init-stream-ioblock (stream 982 1072 &key 983 insize ; integer to allocate inbuf here, nil1073 insize ; integer to allocate inbuf here, nil 984 1074 ; otherwise 985 outsize ; integer to allocate outbuf here, nil1075 outsize ; integer to allocate outbuf here, nil 986 1076 ; otherwise 987 1077 share-buffers-p ; true if input and output … … 1024 1114 (when (eq sharing :lock) 1025 1115 (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) 1032 1117 (setf (ioblock-element-shift ioblock) (max 0 (ceiling (log (/ in-size-in-octets insize) 2)))) 1033 1118 ))) 1034 1119 (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")) 1042 1126 (when outsize 1043 1127 (unless (ioblock-outbuf ioblock) … … 1106 1190 1107 1191 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)) 1109 1194 (defun make-fd-stream (fd &key 1110 1195 (direction :input) … … 1114 1199 (class 'fd-stream) 1115 1200 (sharing :private) 1201 (character-p (or (eq element-type 'character) 1202 (subtypep element-type 'character))) 1116 1203 (basic nil)) 1117 1204 (when basic … … 1120 1207 (let* ((in-p (member direction '(:io :input))) 1121 1208 (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))) 1125 1210 (make-ioblock-stream class-name 1126 1211 :insize (if in-p elements-per-buffer) … … 1141 1226 :close-function 'fd-stream-close 1142 1227 :sharing sharing 1143 :character-p char -p)))1228 :character-p character-p))) 1144 1229 1145 1230 ;;; Fundamental streams. … … 1252 1337 (declare (ignore new))) 1253 1338 1254 (defmethod stream-start-line-p ((s fundamental-character-output-stream))1339 (defmethod stream-start-line-p ((s character-output-stream)) 1255 1340 (eql 0 (stream-line-column s))) 1256 1341 1257 (defmethod stream-terpri ((s fundamental-character-output-stream))1342 (defmethod stream-terpri ((s character-output-stream)) 1258 1343 (stream-write-char s #\Newline)) 1259 1344 1260 (defmethod stream-fresh-line ((s fundamental-character-output-stream))1345 (defmethod stream-fresh-line ((s character-output-stream)) 1261 1346 (unless (stream-start-line-p s) 1262 1347 (stream-terpri s) … … 1350 1435 1351 1436 1437 (declaim (inline basic-stream-p)) 1438 1352 1439 (defun basic-stream-p (x) 1353 1440 (= (the fixnum (typecode x)) target::subtag-basic-stream)) … … 1362 1449 (make-built-in-class 'basic-input-stream 'basic-stream 'input-stream) 1363 1450 (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) 1366 1453 (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) 1369 1456 (make-built-in-class 'basic-binary-io-stream 'basic-binary-input-stream 'basic-binary-output-stream) 1370 1457 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))))) 1371 1472 1372 1473 (defmethod select-stream-class ((s (eql 'basic-stream)) in-p out-p char-p) … … 1410 1511 (logior (ash 1 basic-stream-flag.open-binary) (basic-stream.flags s)))) 1411 1512 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 1412 1517 (defun make-basic-stream-instance (class &rest initargs) 1413 1518 (let* ((s (allocate-basic-stream class))) … … 1425 1530 (apply #'make-ioblock :stream stream args)) 1426 1531 1532 1533 (defun stream-is-closed (s) 1534 (error "~s is closed" s)) 1535 1427 1536 (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)))) 1432 1545 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))))) 1435 1575 1436 1576 ;;; Synonym streams. … … 1821 1961 (defmethod string-stream-string ((s string-stream)) 1822 1962 (or (%string-stream-string s) 1823 ( error "~s is closed" s)))1963 (values (stream-is-closed s)))) 1824 1964 1825 1965 (defmethod open-stream-p ((s string-stream)) … … 2055 2195 (or (%stream-ioblock stream) 2056 2196 (when error-if-nil 2057 ( error "~s is closed"stream))))2197 (stream-is-closed stream)))) 2058 2198 2059 2199 (defmethod stream-device ((s buffered-stream-mixin) direction) … … 2130 2270 2131 2271 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 2132 2287 #| 2133 2288 (defgeneric ioblock-advance (stream ioblock readp) … … 2195 2350 (defmethod stream-read-byte ((stream buffered-binary-input-stream-mixin)) 2196 2351 (with-stream-ioblock-input (ioblock stream :speedy t) 2197 ( %ioblock-read-byteioblock)))2352 (funcall (ioblock-read-byte-function ioblock) ioblock))) 2198 2353 2199 2354 (defmethod stream-eofp ((stream buffered-input-stream-mixin)) … … 2218 2373 (%ioblock-write-char ioblock char))) 2219 2374 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 2220 2381 (defmethod stream-clear-output ((stream buffered-output-stream-mixin)) 2221 2382 (with-stream-ioblock-output (ioblock stream :speedy t) … … 2223 2384 nil) 2224 2385 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 2225 2392 (defmethod stream-line-column ((stream buffered-character-output-stream-mixin)) 2226 2393 (let* ((ioblock (stream-ioblock stream nil))) … … 2232 2399 (and ioblock (setf (ioblock-charpos ioblock) new)))) 2233 2400 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 2234 2406 (defmethod stream-force-output ((stream buffered-output-stream-mixin)) 2235 2407 (with-stream-ioblock-output (ioblock stream :speedy t) … … 2237 2409 nil)) 2238 2410 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 2239 2417 (defmethod maybe-stream-force-output ((stream buffered-output-stream-mixin)) 2240 2418 (with-stream-ioblock-output-maybe (ioblock stream :speedy t) … … 2242 2420 nil)) 2243 2421 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 2244 2428 (defmethod stream-finish-output ((stream buffered-output-stream-mixin)) 2245 2429 (with-stream-ioblock-output (ioblock stream :speedy t) … … 2247 2431 nil)) 2248 2432 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 2249 2451 (defmethod stream-write-string ((stream buffered-character-output-stream-mixin) 2250 2452 string &optional (start 0 start-p) end) … … 2254 2456 (not start-p)) 2255 2457 (%ioblock-write-simple-string ioblock string 0 (length string)) 2256 ( progn2257 (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))))) 2267 2469 2268 2470 … … 2368 2570 2369 2571 (defun unread-data-available-p (fd) 2370 (%stack-block ((arg 4)) 2371 (setf (%get-long arg) 0) 2572 (rlet ((arg (* :char) (%null-ptr))) 2372 2573 (when (zerop (syscall syscalls::ioctl fd #$FIONREAD arg)) 2373 (let* ((avail ( %get-long arg)))2574 (let* ((avail (pref arg :long))) 2374 2575 (and (> avail 0) avail))))) 2375 2576 … … 2413 2614 (let* ((wait-end (if ticks (+ (get-tick-count) ticks)))) 2414 2615 (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) 2416 2620 (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)))))))) 2421 2630 2422 2631 … … 2425 2634 "Wait until output is possible on a given file descriptor." 2426 2635 (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)))) 2430 2638 2431 2639 … … 2444 2652 (rletZ ((tv :timeval)) 2445 2653 (ticks-to-timeval ticks tv) 2446 (%stack-block ((infds *fd-set-size*) 2447 (errfds *fd-set-size*)) 2654 (%stack-block ((infds *fd-set-size*)) 2448 2655 (fd-zero infds) 2449 (fd-zero errfds)2450 2656 (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) 2453 2658 (if ticks tv (%null-ptr))))) 2454 2659 (> res 0))))) … … 2457 2662 (rletZ ((tv :timeval)) 2458 2663 (ticks-to-timeval ticks tv) 2459 (%stack-block ((outfds *fd-set-size*) 2460 (errfds *fd-set-size*)) 2664 (%stack-block ((outfds *fd-set-size*)) 2461 2665 (fd-zero outfds) 2462 (fd-zero errfds)2463 2666 (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) 2466 2668 (if ticks tv (%null-ptr))))) 2467 2669 (> res 0))))) … … 2698 2900 (t :create))) 2699 2901 (external-format :default) 2700 (class 'f ile-stream)2902 (class 'fundamental-file-stream) 2701 2903 (elements-per-buffer *elements-per-buffer*) 2702 2904 (sharing :private)) … … 2796 2998 2797 2999 ;;; Initialize the global streams 2798 ; These are defparameters because they replace the ones that were in l1-init2799 ; while bootstrapping.3000 ;;; These are defparameters because they replace the ones that were in l1-init 3001 ;;; while bootstrapping. 2800 3002 2801 3003 (defparameter *terminal-io* nil "terminal I/O stream") … … 2893 3095 2894 3096 3097 3098 3099 2895 3100 ; end of L1-streams.lisp
Note:
See TracChangeset
for help on using the changeset viewer.
