[INTERPRETER]

* BUG: A stream redirected through the 'Begin' method checks that stream is
  ready for writing only when the 'Send' method is called. Between the 
  'Begin' and 'Send' calls, the PRINT and WRITE instructions will always
  succeed.


git-svn-id: svn://localhost/gambas/trunk@5723 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2013-07-06 19:00:41 +00:00
parent ebf546f609
commit 18c9b762fc
3 changed files with 30 additions and 15 deletions

View file

@ -281,9 +281,11 @@ void STREAM_close(STREAM *stream)
void STREAM_flush(STREAM *stream)
{
STREAM_end(stream);
if (!stream->type)
THROW(E_CLOSED);
(*(stream->type->flush))(stream);
}
@ -306,7 +308,7 @@ void STREAM_read(STREAM *stream, void *addr, int len)
{
STREAM_eff_read = 0;
if (!stream->type)
if (STREAM_is_closed(stream))
THROW(E_CLOSED);
if (len <= 0)
@ -437,7 +439,7 @@ int STREAM_read_max(STREAM *stream, void *addr, int len)
void STREAM_write(STREAM *stream, void *addr, int len)
{
if (!stream->type)
if (STREAM_is_closed_for_writing(stream))
THROW(E_CLOSED);
if (len <= 0)
@ -475,7 +477,7 @@ void STREAM_write_zeros(STREAM *stream, int len)
void STREAM_write_eol(STREAM *stream)
{
if (!stream->type)
if (STREAM_is_closed_for_writing(stream))
THROW(E_CLOSED);
switch(stream->common.eol)
@ -491,7 +493,7 @@ int64_t STREAM_tell(STREAM *stream)
{
int64_t pos;
if (!stream->type)
if (STREAM_is_closed(stream))
THROW(E_CLOSED);
if (stream->type->tell(stream, &pos))
@ -504,7 +506,7 @@ int64_t STREAM_tell(STREAM *stream)
void STREAM_seek(STREAM *stream, int64_t pos, int whence)
{
if (!stream->type)
if (STREAM_is_closed(stream))
THROW(E_CLOSED);
if (stream->type->seek(stream, pos, whence))
@ -1423,7 +1425,7 @@ void STREAM_unmap(char *addr, int len)
int STREAM_handle(STREAM *stream)
{
if (!stream->type)
if (STREAM_is_closed(stream))
THROW(E_CLOSED);
if (stream->type->handle)
@ -1438,7 +1440,7 @@ void STREAM_lock(STREAM *stream)
int64_t pos;
int fd;
if (!stream->type)
if (STREAM_is_closed(stream))
THROW(E_CLOSED);
fd = STREAM_handle(stream);
@ -1484,7 +1486,7 @@ void STREAM_lof(STREAM *stream, int64_t *len)
int fd;
int ilen;
if (!stream->type)
if (STREAM_is_closed(stream))
THROW(E_CLOSED);
if (stream->type->lof)
@ -1503,7 +1505,7 @@ void STREAM_lof(STREAM *stream, int64_t *len)
bool STREAM_eof(STREAM *stream)
{
if (!stream->type)
if (STREAM_is_closed(stream))
THROW(E_CLOSED);
if (stream->common.buffer && stream->common.buffer_pos < stream->common.buffer_len)

View file

@ -241,6 +241,7 @@ int STREAM_write_direct(int fd, char *buffer, int len);
void STREAM_lock(STREAM *stream);
#define STREAM_is_closed(_stream) ((_stream)->type == NULL)
#define STREAM_is_closed_for_writing(_stream) (STREAM_is_closed(_stream) && !(_stream)->common.redirected)
void STREAM_blocking(STREAM *stream, bool block);
#define STREAM_is_blocking(_stream) ((_stream)->common.blocking)

View file

@ -114,8 +114,7 @@ static STREAM *get_default(intptr_t val)
return stream;
}
#define get_stream(_value, _can_default) \
({ \
#define _get_stream(_value, _can_default) \
STREAM *stream; \
\
VARIANT_undo(_value); \
@ -134,7 +133,11 @@ static STREAM *get_default(intptr_t val)
VALUE_conv_object((_value), (TYPE)CLASS_Stream); \
stream = NULL; \
} \
} \
}
#define get_stream(_value, _can_default) \
({ \
_get_stream(_value, _can_default); \
\
if (STREAM_is_closed(stream)) \
THROW(E_CLOSED); \
@ -142,6 +145,15 @@ static STREAM *get_default(intptr_t val)
stream; \
})
#define get_stream_for_writing(_value, _can_default) \
({ \
_get_stream(_value, _can_default); \
\
if (STREAM_is_closed_for_writing(stream)) \
THROW(E_CLOSED); \
\
stream; \
})
static char *get_path(VALUE *param)
{
@ -223,7 +235,7 @@ void SUBR_print(ushort code)
if (NPARAM < 1)
THROW(E_NEPARAM);
_stream = get_stream(PARAM, TRUE);
_stream = get_stream_for_writing(PARAM, TRUE);
//PRINT_init(print_it, FALSE);
@ -455,7 +467,7 @@ void SUBR_write(ushort code)
SUBR_ENTER_PARAM(3);
stream = get_stream(PARAM, TRUE);
stream = get_stream_for_writing(PARAM, TRUE);
if (code & 0x3F)
{