comparison src/lstream.c @ 398:74fd4e045ea6 r21-2-29

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