comparison src/lstream.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents de805c49cfc1
children 41dbb7a9d5f2
comparison
equal deleted inserted replaced
411:12e008d41344 412:697ef44129c6
24 24
25 /* Written by Ben Wing. */ 25 /* Written by Ben Wing. */
26 26
27 #include <config.h> 27 #include <config.h>
28 #include "lisp.h" 28 #include "lisp.h"
29 #include <limits.h>
29 30
30 #include "buffer.h" 31 #include "buffer.h"
31 #include "insdel.h" 32 #include "insdel.h"
32 #include "lstream.h" 33 #include "lstream.h"
33 34
49 in C. The reason for this is that "stream" is too generic a name 50 in C. The reason for this is that "stream" is too generic a name
50 for C; too much likelihood of conflict/confusion with C++, etc. */ 51 for C; too much likelihood of conflict/confusion with C++, etc. */
51 52
52 /* Functions are as follows: 53 /* Functions are as follows:
53 54
54 Lstream *Lstream_new (Lstream_implementation *imp, const char *mode) 55 Lstream *Lstream_new (Lstream_implementation *imp, CONST char *mode)
55 Allocate and return a new Lstream. This function is not 56 Allocate and return a new Lstream. This function is not
56 really meant to be called directly; rather, each stream type 57 really meant to be called directly; rather, each stream type
57 should provide its own stream creation function, which 58 should provide its own stream creation function, which
58 creates the stream and does any other necessary creation 59 creates the stream and does any other necessary creation
59 stuff (e.g. opening a file). 60 stuff (e.g. opening a file).
92 int Lstream_fputc (Lstream *stream, int c) 93 int Lstream_fputc (Lstream *stream, int c)
93 int Lstream_fgetc (Lstream *stream) 94 int Lstream_fgetc (Lstream *stream)
94 void Lstream_fungetc (Lstream *stream, int c) 95 void Lstream_fungetc (Lstream *stream, int c)
95 Function equivalents of the above macros. 96 Function equivalents of the above macros.
96 97
97 ssize_t Lstream_read (Lstream *stream, void *data, size_t size) 98 int Lstream_read (Lstream *stream, void *data, size_t size)
98 Read SIZE bytes of DATA from the stream. Return the number of 99 Read SIZE bytes of DATA from the stream. Return the number of
99 bytes read. 0 means EOF. -1 means an error occurred and no 100 bytes read. 0 means EOF. -1 means an error occurred and no
100 bytes were read. 101 bytes were read.
101 102
102 ssize_t Lstream_write (Lstream *stream, void *data, size_t size) 103 int Lstream_write (Lstream *stream, void *data, size_t size)
103 Write SIZE bytes of DATA to the stream. Return the number of 104 Write SIZE bytes of DATA to the stream. Return the number of
104 bytes written. -1 means an error occurred and no bytes were 105 bytes written. -1 means an error occurred and no bytes were
105 written. 106 written.
106 107
107 void Lstream_unread (Lstream *stream, void *data, size_t size) 108 void Lstream_unread (Lstream *stream, void *data, size_t size)
131 132
132 #define DEFAULT_BLOCK_BUFFERING_SIZE 512 133 #define DEFAULT_BLOCK_BUFFERING_SIZE 512
133 #define MAX_READ_SIZE 512 134 #define MAX_READ_SIZE 512
134 135
135 static Lisp_Object 136 static Lisp_Object
136 mark_lstream (Lisp_Object obj) 137 mark_lstream (Lisp_Object obj, void (*markobj) (Lisp_Object))
137 { 138 {
138 Lstream *lstr = XLSTREAM (obj); 139 Lstream *lstr = XLSTREAM (obj);
139 return lstr->imp->marker ? (lstr->imp->marker) (obj) : Qnil; 140 return lstr->imp->marker ? (lstr->imp->marker) (obj, markobj) : Qnil;
140 } 141 }
141 142
142 static void 143 static void
143 print_lstream (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) 144 print_lstream (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
144 { 145 {
177 Lstream_close (lstr); 178 Lstream_close (lstr);
178 } 179 }
179 } 180 }
180 181
181 static size_t 182 static size_t
182 sizeof_lstream (const void *header) 183 sizeof_lstream (CONST void *header)
183 { 184 {
184 const Lstream *lstr = (const Lstream *) header; 185 CONST Lstream *lstr = (CONST Lstream *) header;
185 return sizeof (*lstr) + lstr->imp->size - 1; 186 return sizeof (*lstr) + lstr->imp->size - 1;
186 } 187 }
187 188
188 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION ("stream", lstream, 189 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION ("stream", lstream,
189 mark_lstream, print_lstream, 190 mark_lstream, print_lstream,
190 finalize_lstream, 0, 0, 0, 191 finalize_lstream, 0, 0,
191 sizeof_lstream, Lstream); 192 sizeof_lstream, Lstream);
192 193
193 void 194 void
194 Lstream_set_buffering (Lstream *lstr, Lstream_buffering buffering, 195 Lstream_set_buffering (Lstream *lstr, Lstream_buffering buffering,
195 int buffering_size) 196 int buffering_size)
207 case LSTREAM_UNLIMITED: 208 case LSTREAM_UNLIMITED:
208 lstr->buffering_size = INT_MAX; break; 209 lstr->buffering_size = INT_MAX; break;
209 } 210 }
210 } 211 }
211 212
212 static const Lstream_implementation *lstream_types[32]; 213 static CONST Lstream_implementation *lstream_types[32];
213 static Lisp_Object Vlstream_free_list[32]; 214 static Lisp_Object Vlstream_free_list[32];
214 static int lstream_type_count; 215 static int lstream_type_count;
215 216
216 Lstream * 217 Lstream *
217 Lstream_new (const Lstream_implementation *imp, const char *mode) 218 Lstream_new (CONST Lstream_implementation *imp, CONST char *mode)
218 { 219 {
219 Lstream *p; 220 Lstream *p;
220 int i; 221 int i;
221 222
222 for (i = 0; i < lstream_type_count; i++) 223 for (i = 0; i < lstream_type_count; i++)
279 } 280 }
280 281
281 #define Lstream_internal_error(reason, lstr) \ 282 #define Lstream_internal_error(reason, lstr) \
282 Lstream_signal_simple_error ("Internal error: " reason, lstr) 283 Lstream_signal_simple_error ("Internal error: " reason, lstr)
283 284
284 static void Lstream_signal_simple_error (const char *reason, Lstream *lstr) 285 static void Lstream_signal_simple_error (CONST char *reason, Lstream *lstr)
285 { 286 {
286 Lisp_Object obj; 287 Lisp_Object obj;
287 XSETLSTREAM (obj, lstr); 288 XSETLSTREAM (obj, lstr);
288 signal_simple_error (reason, obj); 289 signal_simple_error (reason, obj);
289 } 290 }
299 /* Attempt to flush out all of the buffered data for writing. */ 300 /* Attempt to flush out all of the buffered data for writing. */
300 301
301 int 302 int
302 Lstream_flush_out (Lstream *lstr) 303 Lstream_flush_out (Lstream *lstr)
303 { 304 {
304 ssize_t num_written; 305 int num_written;
305 306
306 while (lstr->out_buffer_ind > 0) 307 while (lstr->out_buffer_ind > 0)
307 { 308 {
308 size_t size = lstr->out_buffer_ind; 309 int size = lstr->out_buffer_ind;
309 if (! (lstr->flags & LSTREAM_FL_IS_OPEN)) 310 if (! (lstr->flags & LSTREAM_FL_IS_OPEN))
310 Lstream_internal_error ("lstream not open", lstr); 311 Lstream_internal_error ("lstream not open", lstr);
311 if (! (lstr->flags & LSTREAM_FL_WRITE)) 312 if (! (lstr->flags & LSTREAM_FL_WRITE))
312 Lstream_internal_error ("lstream not open for writing", lstr); 313 Lstream_internal_error ("lstream not open for writing", lstr);
313 if (!lstr->imp->writer) 314 if (!lstr->imp->writer)
316 if (lstr->flags & LSTREAM_FL_NO_PARTIAL_CHARS) 317 if (lstr->flags & LSTREAM_FL_NO_PARTIAL_CHARS)
317 /* It's quite possible for us to get passed an incomplete 318 /* It's quite possible for us to get passed an incomplete
318 character at the end. We need to spit back that 319 character at the end. We need to spit back that
319 incomplete character. */ 320 incomplete character. */
320 { 321 {
321 const unsigned char *data = lstr->out_buffer; 322 CONST unsigned char *data = lstr->out_buffer;
322 const unsigned char *dataend = data + size - 1; 323 CONST unsigned char *dataend = data + size - 1;
323 assert (size > 0); /* safety check ... */ 324 assert (size > 0); /* safety check ... */
324 /* Optimize the most common case. */ 325 /* Optimize the most common case. */
325 if (!BYTE_ASCII_P (*dataend)) 326 if (!BYTE_ASCII_P (*dataend))
326 { 327 {
327 /* Go back to the beginning of the last (and possibly partial) 328 /* Go back to the beginning of the last (and possibly partial)
344 /* If nothing got written, then just hold the data. This may 345 /* If nothing got written, then just hold the data. This may
345 occur, for example, if this stream does non-blocking I/O; 346 occur, for example, if this stream does non-blocking I/O;
346 the attempt to write the data might have resulted in an 347 the attempt to write the data might have resulted in an
347 EWOULDBLOCK error. */ 348 EWOULDBLOCK error. */
348 return 0; 349 return 0;
349 else if (num_written >= lstr->out_buffer_ind) 350 else if (num_written >= (int) lstr->out_buffer_ind)
350 lstr->out_buffer_ind = 0; 351 lstr->out_buffer_ind = 0;
351 else if (num_written > 0) 352 else if (num_written > 0)
352 { 353 {
353 memmove (lstr->out_buffer, lstr->out_buffer + num_written, 354 memmove (lstr->out_buffer, lstr->out_buffer + num_written,
354 lstr->out_buffer_ind - num_written); 355 lstr->out_buffer_ind - num_written);
386 the buffering size. (This is used to deal with the possibility 387 the buffering size. (This is used to deal with the possibility
387 that the stream writer might refuse to write any bytes now, e.g. 388 that the stream writer might refuse to write any bytes now, e.g.
388 if it's getting EWOULDBLOCK errors. We have to keep stocking them 389 if it's getting EWOULDBLOCK errors. We have to keep stocking them
389 up until they can be written, so as to avoid losing data. */ 390 up until they can be written, so as to avoid losing data. */
390 391
391 static size_t 392 static int
392 Lstream_adding (Lstream *lstr, size_t num, int force) 393 Lstream_adding (Lstream *lstr, size_t num, int force)
393 { 394 {
394 size_t size = num + lstr->out_buffer_ind; 395 /* Compute the size that the outbuffer needs to be after the
395 396 chars are added. */
396 if (size <= lstr->out_buffer_size) 397 size_t size_needed = max (lstr->out_buffer_size,
397 return num; 398 num + lstr->out_buffer_ind);
398
399 /* Maybe chop it down so that we don't buffer more characters 399 /* Maybe chop it down so that we don't buffer more characters
400 than our advertised buffering size. */ 400 than our advertised buffering size. */
401 if ((size > lstr->buffering_size) && !force) 401 if (!force)
402 { 402 size_needed = min (lstr->buffering_size, size_needed);
403 size = lstr->buffering_size; 403 DO_REALLOC (lstr->out_buffer, lstr->out_buffer_size,
404 /* There might be more data buffered than the buffering size. */ 404 size_needed, unsigned char);
405 if (size <= lstr->out_buffer_ind) 405 /* There might be more data buffered than the buffering size,
406 return 0; 406 so make sure we don't return a negative number here. */
407 } 407 return max (0, min (num, size_needed - lstr->out_buffer_ind));
408
409 DO_REALLOC (lstr->out_buffer, lstr->out_buffer_size, size, unsigned char);
410
411 return size - lstr->out_buffer_ind;
412 } 408 }
413 409
414 /* Like Lstream_write(), but does not handle line-buffering correctly. */ 410 /* Like Lstream_write(), but does not handle line-buffering correctly. */
415 411
416 static ssize_t 412 static int
417 Lstream_write_1 (Lstream *lstr, const void *data, size_t size) 413 Lstream_write_1 (Lstream *lstr, CONST void *data, size_t size)
418 { 414 {
419 const unsigned char *p = (const unsigned char *) data; 415 CONST unsigned char *p = (CONST unsigned char *) data;
420 ssize_t off = 0; 416 int off = 0;
421 if (! (lstr->flags & LSTREAM_FL_IS_OPEN)) 417 if (! (lstr->flags & LSTREAM_FL_IS_OPEN))
422 Lstream_internal_error ("lstream not open", lstr); 418 Lstream_internal_error ("lstream not open", lstr);
423 if (! (lstr->flags & LSTREAM_FL_WRITE)) 419 if (! (lstr->flags & LSTREAM_FL_WRITE))
424 Lstream_internal_error ("lstream not open for writing", lstr); 420 Lstream_internal_error ("lstream not open for writing", lstr);
425 { 421 {
426 int couldnt_write_last_time = 0; 422 int couldnt_write_last_time = 0;
427 423
428 while (1) 424 while (1)
429 { 425 {
430 /* Figure out how much we can add to the buffer */ 426 /* Figure out how much we can add to the buffer */
431 size_t chunk = Lstream_adding (lstr, size, 0); 427 int chunk = Lstream_adding (lstr, size, 0);
432 if (chunk == 0) 428 if (chunk == 0)
433 { 429 {
434 if (couldnt_write_last_time) 430 if (couldnt_write_last_time)
435 /* Ung, we ran out of space and tried to flush 431 /* Ung, we ran out of space and tried to flush
436 the buffer, but it didn't work because the stream 432 the buffer, but it didn't work because the stream
469 } 465 }
470 466
471 /* If the stream is not line-buffered, then we can just call 467 /* If the stream is not line-buffered, then we can just call
472 Lstream_write_1(), which writes in chunks. Otherwise, we 468 Lstream_write_1(), which writes in chunks. Otherwise, we
473 repeatedly call Lstream_putc(), which knows how to handle 469 repeatedly call Lstream_putc(), which knows how to handle
474 line buffering. Returns number of bytes written. */ 470 line buffering. */
475 471
476 ssize_t 472 int
477 Lstream_write (Lstream *lstr, const void *data, size_t size) 473 Lstream_write (Lstream *lstr, CONST void *data, size_t size)
478 { 474 {
479 size_t i; 475 int i;
480 const unsigned char *p = (const unsigned char *) data; 476 CONST unsigned char *p = (CONST unsigned char *) data;
481 477
482 if (size == 0) 478 if (size == 0)
483 return size; 479 return size;
484 if (lstr->buffering != LSTREAM_LINE_BUFFERED) 480 if (lstr->buffering != LSTREAM_LINE_BUFFERED)
485 return Lstream_write_1 (lstr, data, size); 481 return Lstream_write_1 (lstr, data, size);
486 for (i = 0; i < size; i++) 482 for (i = 0; i < (int) size; i++)
487 { 483 {
488 if (Lstream_putc (lstr, p[i]) < 0) 484 if (Lstream_putc (lstr, p[i]) < 0)
489 break; 485 break;
490 } 486 }
491 return i == 0 ? -1 : (ssize_t) i; 487 return i == 0 ? -1 : 0;
492 } 488 }
493 489
494 int 490 int
495 Lstream_was_blocked_p (Lstream *lstr) 491 Lstream_was_blocked_p (Lstream *lstr)
496 { 492 {
497 return lstr->imp->was_blocked_p ? lstr->imp->was_blocked_p (lstr) : 0; 493 if (lstr->imp->was_blocked_p)
494 return (lstr->imp->was_blocked_p) (lstr);
495 else
496 return 0;
498 } 497 }
499 498
500 static int 499 static int
501 Lstream_raw_read (Lstream *lstr, unsigned char *buffer, size_t size) 500 Lstream_raw_read (Lstream *lstr, unsigned char *buffer, size_t size)
502 { 501 {
510 return (lstr->imp->reader) (lstr, buffer, size); 509 return (lstr->imp->reader) (lstr, buffer, size);
511 } 510 }
512 511
513 /* Assuming the buffer is empty, fill it up again. */ 512 /* Assuming the buffer is empty, fill it up again. */
514 513
515 static ssize_t 514 static int
516 Lstream_read_more (Lstream *lstr) 515 Lstream_read_more (Lstream *lstr)
517 { 516 {
518 #if 0 517 #if 0
519 ssize_t size_needed = max (1, min (MAX_READ_SIZE, lstr->buffering_size)); 518 int size_needed = max (1, min (MAX_READ_SIZE, lstr->buffering_size));
520 #else 519 #else
521 /* If someone requested a larger buffer size, so be it! */ 520 /* If someone requested a larger buffer size, so be it! */
522 ssize_t size_needed = max (1, lstr->buffering_size); 521 int size_needed = max (1, lstr->buffering_size);
523 #endif 522 #endif
524 ssize_t size_gotten; 523 int size_gotten;
525 524
526 DO_REALLOC (lstr->in_buffer, lstr->in_buffer_size, 525 DO_REALLOC (lstr->in_buffer, lstr->in_buffer_size,
527 size_needed, unsigned char); 526 size_needed, unsigned char);
528 size_gotten = Lstream_raw_read (lstr, lstr->in_buffer, size_needed); 527 size_gotten = Lstream_raw_read (lstr, lstr->in_buffer, size_needed);
529 lstr->in_buffer_current = max (0, size_gotten); 528 lstr->in_buffer_current = max (0, size_gotten);
530 lstr->in_buffer_ind = 0; 529 lstr->in_buffer_ind = 0;
531 return size_gotten < 0 ? -1 : size_gotten; 530 return size_gotten < 0 ? -1 : size_gotten;
532 } 531 }
533 532
534 ssize_t 533 int
535 Lstream_read (Lstream *lstr, void *data, size_t size) 534 Lstream_read (Lstream *lstr, void *data, size_t size)
536 { 535 {
537 unsigned char *p = (unsigned char *) data; 536 unsigned char *p = (unsigned char *) data;
538 size_t off = 0; 537 int off = 0;
539 size_t chunk; 538 size_t chunk;
540 int error_occurred = 0; 539 int error_occurred = 0;
541 540
542 if (size == 0) 541 if (size == 0)
543 return 0; 542 return 0;
545 /* First try to get some data from the unget buffer */ 544 /* First try to get some data from the unget buffer */
546 chunk = min (size, lstr->unget_buffer_ind); 545 chunk = min (size, lstr->unget_buffer_ind);
547 if (chunk > 0) 546 if (chunk > 0)
548 { 547 {
549 /* The bytes come back in reverse order. */ 548 /* The bytes come back in reverse order. */
550 for (; off < chunk; off++) 549 for (; off < (int) chunk; off++)
551 p[off] = lstr->unget_buffer[--lstr->unget_buffer_ind]; 550 p[off] = lstr->unget_buffer[--lstr->unget_buffer_ind];
552 lstr->byte_count += chunk; 551 lstr->byte_count += chunk;
553 size -= chunk; 552 size -= chunk;
554 } 553 }
555 554
567 } 566 }
568 567
569 /* If we need some more, try to get some more from the stream's end */ 568 /* If we need some more, try to get some more from the stream's end */
570 if (size > 0) 569 if (size > 0)
571 { 570 {
572 ssize_t retval = Lstream_read_more (lstr); 571 int retval = Lstream_read_more (lstr);
573 if (retval < 0) 572 if (retval < 0)
574 error_occurred = 1; 573 error_occurred = 1;
575 if (retval <= 0) 574 if (retval <= 0)
576 break; 575 break;
577 } 576 }
581 if ((lstr->flags & LSTREAM_FL_NO_PARTIAL_CHARS) && off > 0) 580 if ((lstr->flags & LSTREAM_FL_NO_PARTIAL_CHARS) && off > 0)
582 { 581 {
583 /* It's quite possible for us to get passed an incomplete 582 /* It's quite possible for us to get passed an incomplete
584 character at the end. We need to spit back that 583 character at the end. We need to spit back that
585 incomplete character. */ 584 incomplete character. */
586 const unsigned char *dataend = p + off - 1; 585 CONST unsigned char *dataend = p + off - 1;
587 /* Optimize the most common case. */ 586 /* Optimize the most common case. */
588 if (!BYTE_ASCII_P (*dataend)) 587 if (!BYTE_ASCII_P (*dataend))
589 { 588 {
590 /* Go back to the beginning of the last (and possibly partial) 589 /* Go back to the beginning of the last (and possibly partial)
591 character, and bump forward to see if the character is 590 character, and bump forward to see if the character is
592 complete. */ 591 complete. */
593 VALIDATE_CHARPTR_BACKWARD (dataend); 592 VALIDATE_CHARPTR_BACKWARD (dataend);
594 if (dataend + REP_BYTES_BY_FIRST_BYTE (*dataend) != p + off) 593 if (dataend + REP_BYTES_BY_FIRST_BYTE (*dataend) != p + off)
595 { 594 {
596 size_t newoff = dataend - p; 595 int newoff = dataend - p;
597 /* If not, chop the size down to ignore the last char 596 /* If not, chop the size down to ignore the last char
598 and stash it away for next time. */ 597 and stash it away for next time. */
599 Lstream_unread (lstr, dataend, off - newoff); 598 Lstream_unread (lstr, dataend, off - newoff);
600 off = newoff; 599 off = newoff;
601 } 600 }
602 } 601 }
603 } 602 }
604 603
605 return off == 0 && error_occurred ? -1 : (ssize_t) off; 604 return ((off == 0 && error_occurred) ? -1 : off);
606 } 605 }
607 606
608 void 607 void
609 Lstream_unread (Lstream *lstr, const void *data, size_t size) 608 Lstream_unread (Lstream *lstr, CONST void *data, size_t size)
610 { 609 {
611 const unsigned char *p = (const unsigned char *) data; 610 int i;
611 unsigned char *p = (unsigned char *) data;
612 612
613 /* Make sure buffer is big enough */ 613 /* Make sure buffer is big enough */
614
614 DO_REALLOC (lstr->unget_buffer, lstr->unget_buffer_size, 615 DO_REALLOC (lstr->unget_buffer, lstr->unget_buffer_size,
615 lstr->unget_buffer_ind + size, unsigned char); 616 lstr->unget_buffer_ind + size, unsigned char);
616 617
617 lstr->byte_count -= size;
618
619 /* Bytes have to go on in reverse order -- they are reversed 618 /* Bytes have to go on in reverse order -- they are reversed
620 again when read back. */ 619 again when read back. */
621 while (size--) 620 for (i = size - 1; i >= 0; i--)
622 lstr->unget_buffer[lstr->unget_buffer_ind++] = p[size]; 621 lstr->unget_buffer[lstr->unget_buffer_ind++] = p[i];
622 lstr->byte_count -= size;
623 } 623 }
624 624
625 int 625 int
626 Lstream_rewind (Lstream *lstr) 626 Lstream_rewind (Lstream *lstr)
627 { 627 {
644 } 644 }
645 645
646 static int 646 static int
647 Lstream_pseudo_close (Lstream *lstr) 647 Lstream_pseudo_close (Lstream *lstr)
648 { 648 {
649 int rc;
650
649 if (!lstr->flags & LSTREAM_FL_IS_OPEN) 651 if (!lstr->flags & LSTREAM_FL_IS_OPEN)
650 Lstream_internal_error ("lstream is not open", lstr); 652 Lstream_internal_error ("lstream is not open", lstr);
651 653
652 /* don't check errors here -- best not to risk file descriptor loss */ 654 /* don't check errors here -- best not to risk file descriptor loss */
653 return Lstream_flush (lstr); 655 rc = Lstream_flush (lstr);
656
657 return rc;
654 } 658 }
655 659
656 int 660 int
657 Lstream_close (Lstream *lstr) 661 Lstream_close (Lstream *lstr)
658 { 662 {
723 727
724 int 728 int
725 Lstream_fputc (Lstream *lstr, int c) 729 Lstream_fputc (Lstream *lstr, int c)
726 { 730 {
727 unsigned char ch = (unsigned char) c; 731 unsigned char ch = (unsigned char) c;
728 ssize_t retval = Lstream_write_1 (lstr, &ch, 1); 732 int retval = Lstream_write_1 (lstr, &ch, 1);
729 if (retval >= 0 && lstr->buffering == LSTREAM_LINE_BUFFERED && ch == '\n') 733 if (retval >= 0 && lstr->buffering == LSTREAM_LINE_BUFFERED && ch == '\n')
730 return Lstream_flush_out (lstr); 734 return Lstream_flush_out (lstr);
731 return retval < 0 ? -1 : 0; 735 return retval < 0 ? -1 : 0;
732 } 736 }
733 737
762 766
763 DEFINE_LSTREAM_IMPLEMENTATION ("stdio", lstream_stdio, 767 DEFINE_LSTREAM_IMPLEMENTATION ("stdio", lstream_stdio,
764 sizeof (struct stdio_stream)); 768 sizeof (struct stdio_stream));
765 769
766 static Lisp_Object 770 static Lisp_Object
767 make_stdio_stream_1 (FILE *stream, int flags, const char *mode) 771 make_stdio_stream_1 (FILE *stream, int flags, CONST char *mode)
768 { 772 {
769 Lisp_Object obj; 773 Lisp_Object obj;
770 Lstream *lstr = Lstream_new (lstream_stdio, mode); 774 Lstream *lstr = Lstream_new (lstream_stdio, mode);
771 struct stdio_stream *str = STDIO_STREAM_DATA (lstr); 775 struct stdio_stream *str = STDIO_STREAM_DATA (lstr);
772 str->file = stream; 776 str->file = stream;
786 make_stdio_output_stream (FILE *stream, int flags) 790 make_stdio_output_stream (FILE *stream, int flags)
787 { 791 {
788 return make_stdio_stream_1 (stream, flags, "w"); 792 return make_stdio_stream_1 (stream, flags, "w");
789 } 793 }
790 794
791 /* #### From reading the Unix 98 specification, it appears that if we 795 static int
792 want stdio_reader() to be completely correct, we should check for
793 0 < val < size and if so, check to see if an error has occurred.
794 If an error has occurred, but val is non-zero, we should go ahead
795 and act as if the read was successful, but remember in some fashion
796 or other, that an error has occurred, and report that on the next
797 call to stdio_reader instead of calling fread() again.
798
799 Currently, in such a case, we end up calling fread() twice and we
800 assume that
801
802 1) this is not harmful, and
803 2) the error will still be reported on the second read.
804
805 This is probably reasonable, so I don't think we should change this
806 code (it could even be argued that the error might have fixed
807 itself, so we should do the fread() again. */
808
809 static ssize_t
810 stdio_reader (Lstream *stream, unsigned char *data, size_t size) 796 stdio_reader (Lstream *stream, unsigned char *data, size_t size)
811 { 797 {
812 struct stdio_stream *str = STDIO_STREAM_DATA (stream); 798 struct stdio_stream *str = STDIO_STREAM_DATA (stream);
813 size_t val = fread (data, 1, size, str->file); 799 size_t val = fread (data, 1, (size_t) size, str->file);
814 if (!val && ferror (str->file)) 800 if (!val && ferror (str->file))
815 return -1; 801 return -1;
816 return val; 802 return (int) val;
817 } 803 }
818 804
819 static ssize_t 805 static int
820 stdio_writer (Lstream *stream, const unsigned char *data, size_t size) 806 stdio_writer (Lstream *stream, CONST unsigned char *data, size_t size)
821 { 807 {
822 struct stdio_stream *str = STDIO_STREAM_DATA (stream); 808 struct stdio_stream *str = STDIO_STREAM_DATA (stream);
823 size_t val = fwrite (data, 1, size, str->file); 809 size_t val = fwrite (data, 1, size, str->file);
824 if (!val && ferror (str->file)) 810 if (!val && ferror (str->file))
825 return -1; 811 return -1;
826 return val; 812 return (int) val;
827 } 813 }
828 814
829 static int 815 static int
830 stdio_rewinder (Lstream *stream) 816 stdio_rewinder (Lstream *stream)
831 { 817 {
849 { 835 {
850 struct stdio_stream *str = STDIO_STREAM_DATA (stream); 836 struct stdio_stream *str = STDIO_STREAM_DATA (stream);
851 if (stream->flags & LSTREAM_FL_WRITE) 837 if (stream->flags & LSTREAM_FL_WRITE)
852 return fflush (str->file); 838 return fflush (str->file);
853 else 839 else
840 /* call fpurge? Only exists on some systems. #### Why not add a
841 configure check for HAVE_FPURGE and utilize it on systems that
842 support it? --hniksic */
854 return 0; 843 return 0;
855 } 844 }
856 845
857 static int 846 static int
858 stdio_closer (Lstream *stream) 847 stdio_closer (Lstream *stream)
862 return fclose (str->file); 851 return fclose (str->file);
863 else 852 else
864 if (stream->flags & LSTREAM_FL_WRITE) 853 if (stream->flags & LSTREAM_FL_WRITE)
865 return fflush (str->file); 854 return fflush (str->file);
866 else 855 else
856 /* call fpurge? Only exists on some systems. */
867 return 0; 857 return 0;
868 } 858 }
869 859
870 /*********** a file descriptor ***********/ 860 /*********** a file descriptor ***********/
871 861
894 OFFSET is the offset from the *current* file pointer that the reading 884 OFFSET is the offset from the *current* file pointer that the reading
895 should start at. COUNT is the number of bytes to be read (it is 885 should start at. COUNT is the number of bytes to be read (it is
896 ignored when writing); -1 for unlimited. */ 886 ignored when writing); -1 for unlimited. */
897 static Lisp_Object 887 static Lisp_Object
898 make_filedesc_stream_1 (int filedesc, int offset, int count, int flags, 888 make_filedesc_stream_1 (int filedesc, int offset, int count, int flags,
899 const char *mode) 889 CONST char *mode)
900 { 890 {
901 Lisp_Object obj; 891 Lisp_Object obj;
902 Lstream *lstr = Lstream_new (lstream_filedesc, mode); 892 Lstream *lstr = Lstream_new (lstream_filedesc, mode);
903 struct filedesc_stream *fstr = FILEDESC_STREAM_DATA (lstr); 893 struct filedesc_stream *fstr = FILEDESC_STREAM_DATA (lstr);
904 fstr->fd = filedesc; 894 fstr->fd = filedesc;
929 make_filedesc_output_stream (int filedesc, int offset, int count, int flags) 919 make_filedesc_output_stream (int filedesc, int offset, int count, int flags)
930 { 920 {
931 return make_filedesc_stream_1 (filedesc, offset, count, flags, "w"); 921 return make_filedesc_stream_1 (filedesc, offset, count, flags, "w");
932 } 922 }
933 923
934 static ssize_t 924 static int
935 filedesc_reader (Lstream *stream, unsigned char *data, size_t size) 925 filedesc_reader (Lstream *stream, unsigned char *data, size_t size)
936 { 926 {
937 ssize_t nread; 927 int nread;
938 struct filedesc_stream *str = FILEDESC_STREAM_DATA (stream); 928 struct filedesc_stream *str = FILEDESC_STREAM_DATA (stream);
939 if (str->end_pos >= 0) 929 if (str->end_pos >= 0)
940 size = min (size, (size_t) (str->end_pos - str->current_pos)); 930 size = min (size, (size_t) (str->end_pos - str->current_pos));
941 nread = str->allow_quit ? 931 nread = (str->allow_quit ? read_allowing_quit : read) (str->fd, data, size);
942 read_allowing_quit (str->fd, data, size) :
943 read (str->fd, data, size);
944 if (nread > 0) 932 if (nread > 0)
945 str->current_pos += nread; 933 str->current_pos += nread;
946 return nread; 934 return nread;
947 } 935 }
948 936
958 return 1; 946 return 1;
959 #endif 947 #endif
960 return 0; 948 return 0;
961 } 949 }
962 950
963 static ssize_t 951 static int
964 filedesc_writer (Lstream *stream, const unsigned char *data, size_t size) 952 filedesc_writer (Lstream *stream, CONST unsigned char *data, size_t size)
965 { 953 {
966 struct filedesc_stream *str = FILEDESC_STREAM_DATA (stream); 954 struct filedesc_stream *str = FILEDESC_STREAM_DATA (stream);
967 ssize_t retval; 955 int retval;
968 int need_newline = 0; 956 int need_newline = 0;
969 957
970 /* This function would be simple if it were not for the blasted 958 /* This function would be simple if it were not for the blasted
971 PTY max-bytes stuff. Why the hell can't they just have written 959 PTY max-bytes stuff. Why the hell can't they just have written
972 the PTY drivers right so this problem doesn't exist? 960 the PTY drivers right so this problem doesn't exist?
974 Maybe all the PTY crap here should be moved into another stream 962 Maybe all the PTY crap here should be moved into another stream
975 that does nothing but periodically insert EOF's as necessary. */ 963 that does nothing but periodically insert EOF's as necessary. */
976 if (str->pty_flushing) 964 if (str->pty_flushing)
977 { 965 {
978 /* To make life easy, only send out one line at the most. */ 966 /* To make life easy, only send out one line at the most. */
979 const unsigned char *ptr; 967 CONST unsigned char *ptr;
980 968
981 ptr = (const unsigned char *) memchr (data, '\n', size); 969 ptr = (CONST unsigned char *) memchr (data, '\n', size);
982 if (ptr) 970 if (ptr)
983 need_newline = 1; 971 need_newline = 1;
984 else 972 else
985 ptr = data + size; 973 ptr = data + size;
986 if (ptr - data >= str->pty_max_bytes - str->chars_sans_newline) 974 if (ptr - data >= str->pty_max_bytes - str->chars_sans_newline)
991 size = ptr - data; 979 size = ptr - data;
992 } 980 }
993 981
994 /**** start of non-PTY-crap ****/ 982 /**** start of non-PTY-crap ****/
995 if (size > 0) 983 if (size > 0)
996 retval = str->allow_quit ? 984 retval = ((str->allow_quit ? write_allowing_quit : write)
997 write_allowing_quit (str->fd, data, size) : 985 (str->fd, data, size));
998 write (str->fd, data, size);
999 else 986 else
1000 retval = 0; 987 retval = 0;
1001 if (retval < 0 && errno_would_block_p (errno) && str->blocked_ok) 988 if (retval < 0 && errno_would_block_p (errno) && str->blocked_ok)
1002 { 989 {
1003 str->blocking_error_p = 1; 990 str->blocking_error_p = 1;
1016 and flush with an EOF if necessary. Be careful to 1003 and flush with an EOF if necessary. Be careful to
1017 keep track of write errors as we go along and look 1004 keep track of write errors as we go along and look
1018 out for EWOULDBLOCK. */ 1005 out for EWOULDBLOCK. */
1019 if (str->chars_sans_newline >= str->pty_max_bytes) 1006 if (str->chars_sans_newline >= str->pty_max_bytes)
1020 { 1007 {
1021 ssize_t retval2 = str->allow_quit ? 1008 int retval2 = ((str->allow_quit ? write_allowing_quit : write)
1022 write_allowing_quit (str->fd, &str->eof_char, 1) : 1009 (str->fd, &str->eof_char, 1));
1023 write (str->fd, &str->eof_char, 1);
1024
1025 if (retval2 > 0) 1010 if (retval2 > 0)
1026 str->chars_sans_newline = 0; 1011 str->chars_sans_newline = 0;
1027 else if (retval2 < 0) 1012 else if (retval2 < 0)
1028 { 1013 {
1029 /* Error writing the EOF char. If nothing got written, 1014 /* Error writing the EOF char. If nothing got written,
1049 first byte is a newline, we'd get stuck never writing anything 1034 first byte is a newline, we'd get stuck never writing anything
1050 in pty-flushing mode. */ 1035 in pty-flushing mode. */
1051 if (need_newline) 1036 if (need_newline)
1052 { 1037 {
1053 Bufbyte nl = '\n'; 1038 Bufbyte nl = '\n';
1054 ssize_t retval2 = str->allow_quit ? 1039 int retval2 = ((str->allow_quit ? write_allowing_quit : write)
1055 write_allowing_quit (str->fd, &nl, 1) : 1040 (str->fd, &nl, 1));
1056 write (str->fd, &nl, 1);
1057
1058 if (retval2 > 0) 1041 if (retval2 > 0)
1059 { 1042 {
1060 str->chars_sans_newline = 0; 1043 str->chars_sans_newline = 0;
1061 retval++; 1044 retval++;
1062 } 1045 }
1185 str->obj = string; 1168 str->obj = string;
1186 XSETLSTREAM (obj, lstr); 1169 XSETLSTREAM (obj, lstr);
1187 return obj; 1170 return obj;
1188 } 1171 }
1189 1172
1190 static ssize_t 1173 static int
1191 lisp_string_reader (Lstream *stream, unsigned char *data, size_t size) 1174 lisp_string_reader (Lstream *stream, unsigned char *data, size_t size)
1192 { 1175 {
1193 struct lisp_string_stream *str = LISP_STRING_STREAM_DATA (stream); 1176 struct lisp_string_stream *str = LISP_STRING_STREAM_DATA (stream);
1194 /* Don't lose if the string shrank past us ... */ 1177 /* Don't lose if the string shrank past us ... */
1195 Bytecount offset = min (str->offset, XSTRING_LENGTH (str->obj)); 1178 Bytecount offset = min (str->offset, XSTRING_LENGTH (str->obj));
1229 str->offset = pos; 1212 str->offset = pos;
1230 return 0; 1213 return 0;
1231 } 1214 }
1232 1215
1233 static Lisp_Object 1216 static Lisp_Object
1234 lisp_string_marker (Lisp_Object stream) 1217 lisp_string_marker (Lisp_Object stream, void (*markobj) (Lisp_Object))
1235 { 1218 {
1236 struct lisp_string_stream *str = LISP_STRING_STREAM_DATA (XLSTREAM (stream)); 1219 struct lisp_string_stream *str = LISP_STRING_STREAM_DATA (XLSTREAM (stream));
1237 return str->obj; 1220 return str->obj;
1238 } 1221 }
1239 1222
1242 #define FIXED_BUFFER_STREAM_DATA(stream) \ 1225 #define FIXED_BUFFER_STREAM_DATA(stream) \
1243 LSTREAM_TYPE_DATA (stream, fixed_buffer) 1226 LSTREAM_TYPE_DATA (stream, fixed_buffer)
1244 1227
1245 struct fixed_buffer_stream 1228 struct fixed_buffer_stream
1246 { 1229 {
1247 const unsigned char *inbuf; 1230 CONST unsigned char *inbuf;
1248 unsigned char *outbuf; 1231 unsigned char *outbuf;
1249 size_t size; 1232 size_t size;
1250 size_t offset; 1233 size_t offset;
1251 }; 1234 };
1252 1235
1253 DEFINE_LSTREAM_IMPLEMENTATION ("fixed-buffer", lstream_fixed_buffer, 1236 DEFINE_LSTREAM_IMPLEMENTATION ("fixed-buffer", lstream_fixed_buffer,
1254 sizeof (struct fixed_buffer_stream)); 1237 sizeof (struct fixed_buffer_stream));
1255 1238
1256 Lisp_Object 1239 Lisp_Object
1257 make_fixed_buffer_input_stream (const void *buf, size_t size) 1240 make_fixed_buffer_input_stream (CONST unsigned char *buf, size_t size)
1258 { 1241 {
1259 Lisp_Object obj; 1242 Lisp_Object obj;
1260 Lstream *lstr = Lstream_new (lstream_fixed_buffer, "r"); 1243 Lstream *lstr = Lstream_new (lstream_fixed_buffer, "r");
1261 struct fixed_buffer_stream *str = FIXED_BUFFER_STREAM_DATA (lstr); 1244 struct fixed_buffer_stream *str = FIXED_BUFFER_STREAM_DATA (lstr);
1262 str->inbuf = (const unsigned char *) buf; 1245 str->inbuf = buf;
1263 str->size = size; 1246 str->size = size;
1264 XSETLSTREAM (obj, lstr); 1247 XSETLSTREAM (obj, lstr);
1265 return obj; 1248 return obj;
1266 } 1249 }
1267 1250
1268 Lisp_Object 1251 Lisp_Object
1269 make_fixed_buffer_output_stream (void *buf, size_t size) 1252 make_fixed_buffer_output_stream (unsigned char *buf, size_t size)
1270 { 1253 {
1271 Lisp_Object obj; 1254 Lisp_Object obj;
1272 Lstream *lstr = Lstream_new (lstream_fixed_buffer, "w"); 1255 Lstream *lstr = Lstream_new (lstream_fixed_buffer, "w");
1273 struct fixed_buffer_stream *str = FIXED_BUFFER_STREAM_DATA (lstr); 1256 struct fixed_buffer_stream *str = FIXED_BUFFER_STREAM_DATA (lstr);
1274 str->outbuf = (unsigned char *) buf; 1257 str->outbuf = buf;
1275 str->size = size; 1258 str->size = size;
1276 XSETLSTREAM (obj, lstr); 1259 XSETLSTREAM (obj, lstr);
1277 return obj; 1260 return obj;
1278 } 1261 }
1279 1262
1280 static ssize_t 1263 static int
1281 fixed_buffer_reader (Lstream *stream, unsigned char *data, size_t size) 1264 fixed_buffer_reader (Lstream *stream, unsigned char *data, size_t size)
1282 { 1265 {
1283 struct fixed_buffer_stream *str = FIXED_BUFFER_STREAM_DATA (stream); 1266 struct fixed_buffer_stream *str = FIXED_BUFFER_STREAM_DATA (stream);
1284 size = min (size, str->size - str->offset); 1267 size = min (size, str->size - str->offset);
1285 memcpy (data, str->inbuf + str->offset, size); 1268 memcpy (data, str->inbuf + str->offset, size);
1286 str->offset += size; 1269 str->offset += size;
1287 return size; 1270 return size;
1288 } 1271 }
1289 1272
1290 static ssize_t 1273 static int
1291 fixed_buffer_writer (Lstream *stream, const unsigned char *data, size_t size) 1274 fixed_buffer_writer (Lstream *stream, CONST unsigned char *data, size_t size)
1292 { 1275 {
1293 struct fixed_buffer_stream *str = FIXED_BUFFER_STREAM_DATA (stream); 1276 struct fixed_buffer_stream *str = FIXED_BUFFER_STREAM_DATA (stream);
1294 if (str->offset == str->size) 1277 if (str->offset == str->size)
1295 { 1278 {
1296 /* If we're at the end, just throw away the data and pretend 1279 /* If we're at the end, just throw away the data and pretend
1309 { 1292 {
1310 FIXED_BUFFER_STREAM_DATA (stream)->offset = 0; 1293 FIXED_BUFFER_STREAM_DATA (stream)->offset = 0;
1311 return 0; 1294 return 0;
1312 } 1295 }
1313 1296
1314 const unsigned char * 1297 CONST unsigned char *
1315 fixed_buffer_input_stream_ptr (Lstream *stream) 1298 fixed_buffer_input_stream_ptr (Lstream *stream)
1316 { 1299 {
1317 assert (stream->imp == lstream_fixed_buffer); 1300 assert (stream->imp == lstream_fixed_buffer);
1318 return FIXED_BUFFER_STREAM_DATA (stream)->inbuf; 1301 return FIXED_BUFFER_STREAM_DATA (stream)->inbuf;
1319 } 1302 }
1347 Lisp_Object obj; 1330 Lisp_Object obj;
1348 XSETLSTREAM (obj, Lstream_new (lstream_resizing_buffer, "w")); 1331 XSETLSTREAM (obj, Lstream_new (lstream_resizing_buffer, "w"));
1349 return obj; 1332 return obj;
1350 } 1333 }
1351 1334
1352 static ssize_t 1335 static int
1353 resizing_buffer_writer (Lstream *stream, const unsigned char *data, size_t size) 1336 resizing_buffer_writer (Lstream *stream, CONST unsigned char *data, size_t size)
1354 { 1337 {
1355 struct resizing_buffer_stream *str = RESIZING_BUFFER_STREAM_DATA (stream); 1338 struct resizing_buffer_stream *str = RESIZING_BUFFER_STREAM_DATA (stream);
1356 DO_REALLOC (str->buf, str->allocked, str->stored + size, unsigned char); 1339 DO_REALLOC (str->buf, str->allocked, str->stored + size, unsigned char);
1357 memcpy (str->buf + str->stored, data, size); 1340 memcpy (str->buf + str->stored, data, size);
1358 str->stored += size; 1341 str->stored += size;
1409 XSETLSTREAM (obj, Lstream_new (lstream_dynarr, "w")); 1392 XSETLSTREAM (obj, Lstream_new (lstream_dynarr, "w"));
1410 DYNARR_STREAM_DATA (XLSTREAM (obj))->dyn = dyn; 1393 DYNARR_STREAM_DATA (XLSTREAM (obj))->dyn = dyn;
1411 return obj; 1394 return obj;
1412 } 1395 }
1413 1396
1414 static ssize_t 1397 static int
1415 dynarr_writer (Lstream *stream, const unsigned char *data, size_t size) 1398 dynarr_writer (Lstream *stream, CONST unsigned char *data, size_t size)
1416 { 1399 {
1417 struct dynarr_stream *str = DYNARR_STREAM_DATA (stream); 1400 struct dynarr_stream *str = DYNARR_STREAM_DATA (stream);
1418 Dynarr_add_many (str->dyn, data, size); 1401 Dynarr_add_many (str->dyn, data, size);
1419 return size; 1402 return size;
1420 } 1403 }
1453 DEFINE_LSTREAM_IMPLEMENTATION ("lisp-buffer", lstream_lisp_buffer, 1436 DEFINE_LSTREAM_IMPLEMENTATION ("lisp-buffer", lstream_lisp_buffer,
1454 sizeof (struct lisp_buffer_stream)); 1437 sizeof (struct lisp_buffer_stream));
1455 1438
1456 static Lisp_Object 1439 static Lisp_Object
1457 make_lisp_buffer_stream_1 (struct buffer *buf, Bufpos start, Bufpos end, 1440 make_lisp_buffer_stream_1 (struct buffer *buf, Bufpos start, Bufpos end,
1458 int flags, const char *mode) 1441 int flags, CONST char *mode)
1459 { 1442 {
1460 Lisp_Object obj; 1443 Lisp_Object obj;
1461 Lstream *lstr; 1444 Lstream *lstr;
1462 struct lisp_buffer_stream *str; 1445 struct lisp_buffer_stream *str;
1463 Bufpos bmin, bmax; 1446 Bufpos bmin, bmax;
1533 1516
1534 Lstream_set_character_mode (XLSTREAM (lstr)); 1517 Lstream_set_character_mode (XLSTREAM (lstr));
1535 return lstr; 1518 return lstr;
1536 } 1519 }
1537 1520
1538 static ssize_t 1521 static int
1539 lisp_buffer_reader (Lstream *stream, unsigned char *data, size_t size) 1522 lisp_buffer_reader (Lstream *stream, unsigned char *data, size_t size)
1540 { 1523 {
1541 struct lisp_buffer_stream *str = LISP_BUFFER_STREAM_DATA (stream); 1524 struct lisp_buffer_stream *str = LISP_BUFFER_STREAM_DATA (stream);
1542 unsigned char *orig_data = data; 1525 unsigned char *orig_data = data;
1543 Bytind start; 1526 Bytind start;
1591 1574
1592 set_bi_marker_position (str->start, end); 1575 set_bi_marker_position (str->start, end);
1593 return data - orig_data; 1576 return data - orig_data;
1594 } 1577 }
1595 1578
1596 static ssize_t 1579 static int
1597 lisp_buffer_writer (Lstream *stream, const unsigned char *data, size_t size) 1580 lisp_buffer_writer (Lstream *stream, CONST unsigned char *data, size_t size)
1598 { 1581 {
1599 struct lisp_buffer_stream *str = LISP_BUFFER_STREAM_DATA (stream); 1582 struct lisp_buffer_stream *str = LISP_BUFFER_STREAM_DATA (stream);
1600 Bufpos pos; 1583 Bufpos pos;
1601 struct buffer *buf = XBUFFER (str->buffer); 1584 struct buffer *buf = XBUFFER (str->buffer);
1602 1585
1627 set_marker_position (str->start, pos); 1610 set_marker_position (str->start, pos);
1628 return 0; 1611 return 0;
1629 } 1612 }
1630 1613
1631 static Lisp_Object 1614 static Lisp_Object
1632 lisp_buffer_marker (Lisp_Object stream) 1615 lisp_buffer_marker (Lisp_Object stream, void (*markobj) (Lisp_Object))
1633 { 1616 {
1634 struct lisp_buffer_stream *str = 1617 struct lisp_buffer_stream *str =
1635 LISP_BUFFER_STREAM_DATA (XLSTREAM (stream)); 1618 LISP_BUFFER_STREAM_DATA (XLSTREAM (stream));
1636 1619
1637 mark_object (str->start); 1620 markobj (str->start);
1638 mark_object (str->end); 1621 markobj (str->end);
1639 return str->buffer; 1622 return str->buffer;
1640 } 1623 }
1641 1624
1642 Bufpos 1625 Bufpos
1643 lisp_buffer_stream_startpos (Lstream *stream) 1626 lisp_buffer_stream_startpos (Lstream *stream)
1688 LSTREAM_HAS_METHOD (lisp_buffer, rewinder); 1671 LSTREAM_HAS_METHOD (lisp_buffer, rewinder);
1689 LSTREAM_HAS_METHOD (lisp_buffer, marker); 1672 LSTREAM_HAS_METHOD (lisp_buffer, marker);
1690 } 1673 }
1691 1674
1692 void 1675 void
1693 reinit_vars_of_lstream (void) 1676 vars_of_lstream (void)
1694 { 1677 {
1695 int i; 1678 int i;
1696 1679
1697 for (i = 0; i < countof (Vlstream_free_list); i++) 1680 for (i = 0; i < countof (Vlstream_free_list); i++)
1698 { 1681 {
1699 Vlstream_free_list[i] = Qnil; 1682 Vlstream_free_list[i] = Qnil;
1700 staticpro_nodump (&Vlstream_free_list[i]); 1683 staticpro (&Vlstream_free_list[i]);
1701 } 1684 }
1702 } 1685 }
1703
1704 void
1705 vars_of_lstream (void)
1706 {
1707 INIT_LRECORD_IMPLEMENTATION (lstream);
1708
1709 reinit_vars_of_lstream ();
1710 }