diff options
-rw-r--r-- | base/stream.c | 26 | ||||
-rw-r--r-- | base/stream.h | 5 |
2 files changed, 30 insertions, 1 deletions
diff --git a/base/stream.c b/base/stream.c index 22435e11b..8b48f5f02 100644 --- a/base/stream.c +++ b/base/stream.c @@ -1071,6 +1071,11 @@ s_string_reusable_flush(stream *s) s->cursor.r.ptr = s->cursor.r.limit = s->cbuf + s->bsize - 1; /* just set to the end */ return 0; } + +/* String ownership retained by the caller, for example + Postscript string objects owned by the Postscript + interpreter + */ void sread_string_reusable(stream *s, const byte *ptr, uint len) { @@ -1088,6 +1093,27 @@ sread_string_reusable(stream *s, const byte *ptr, uint len) s->close_at_eod = false; } +/* The string ownership is transferred from caller to stream. + string_mem pointer must be allocator used to allocate the + "string" buffer. + */ +void +sread_transient_string_reusable(stream *s, gs_memory_t *string_mem, const byte *ptr, uint len) +{ + /* + * Note that s->procs.close is s_close_disable, to parallel + * file_close_disable. + */ + static const stream_procs p = { + s_string_available, s_string_read_seek, s_string_reusable_reset, + s_string_reusable_flush, s_close_disable, s_string_read_process + }; + + sread_transient_string(s, string_mem, ptr, len); + s->procs = p; + s->close_at_eod = false; +} + /* Return the number of available bytes when reading from a string. */ static int s_string_available(stream *s, gs_offset_t *pl) diff --git a/base/stream.h b/base/stream.h index 3c1aeebca..e4b27910d 100644 --- a/base/stream.h +++ b/base/stream.h @@ -378,14 +378,17 @@ int file_close_disable(stream *); interpreter */ void sread_string(stream *, const byte *, uint); +void sread_string_reusable(stream *, const byte *, uint); + /* The string ownership is transferred from caller to stream. string_mem pointer must be allocator used to allocate the "string" buffer. */ void sread_transient_string(register stream *s, gs_memory_t *string_mem, const byte *ptr, uint len); +void +sread_transient_string_reusable(register stream *s, gs_memory_t *string_mem, const byte *ptr, uint len); -void sread_string_reusable(stream *, const byte *, uint); void swrite_string(stream *, byte *, uint); void sread_file(stream *, gp_file *, byte *, uint), swrite_file(stream *, gp_file *, byte *, uint); |