[INTERPRETER]

* BUG: Fix the CLOSE instruction when dealing with a string stream.
* NEW: Make WRITE behave the same way as READ on a memory stream. I.e. it 
  writes a null-terminated "C" string.


git-svn-id: svn://localhost/gambas/trunk@5942 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2013-11-04 18:16:26 +00:00
parent 407e74968b
commit 7a9d649219
3 changed files with 36 additions and 8 deletions

View file

@ -1243,8 +1243,17 @@ void STREAM_write_type(STREAM *stream, TYPE type, VALUE *value)
case T_STRING:
case T_CSTRING:
write_length(stream, value->_string.len);
STREAM_write(stream, value->_string.addr + value->_string.start, value->_string.len);
if (stream->type == &STREAM_memory)
{
STREAM_write(stream, value->_string.addr + value->_string.start, value->_string.len);
buffer._byte = 0;
STREAM_write(stream, &buffer._byte, 1);
}
else
{
write_length(stream, value->_string.len);
STREAM_write(stream, value->_string.addr + value->_string.start, value->_string.len);
}
break;
case T_OBJECT:

View file

@ -46,16 +46,23 @@ static int stream_open(STREAM *stream, const char *path, int mode)
{
stream->string.buffer = NULL;
stream->common.available_now = TRUE;
stream->string.size = 0;
stream->string.pos = 0;
if (path && *path)
{
STRING_ref((char *)path);
stream->string.buffer = (char *)path;
if (mode & ST_WRITE)
{
stream->string.buffer = STRING_new(path, STRING_length(path));
}
else
{
stream->string.buffer = (char *)path;
STRING_ref((char *)path);
}
stream->string.size = STRING_length(path);
}
stream->string.pos = 0;
return FALSE;
}
@ -94,9 +101,14 @@ static int stream_read(STREAM *stream, char *buffer, int len)
static int stream_write(STREAM *stream, char *buffer, int len)
{
if ((stream->common.mode & ST_WRITE) == 0)
THROW(E_ACCESS);
stream->string.buffer = STRING_add(stream->string.buffer, buffer, len);
stream->string.pos = stream->string.size + len;
stream->string.size += len;
stream->string.pos = stream->string.size;
return FALSE;
}

View file

@ -213,12 +213,19 @@ void SUBR_close(void)
if (stream->type == &STREAM_string)
{
char *buffer = stream->string.buffer;
RETURN->type = T_STRING;
RETURN->_string.addr = stream->string.buffer;
RETURN->_string.addr = buffer;
RETURN->_string.start = 0;
RETURN->_string.len = stream->string.size;
STRING_ref(buffer);
STREAM_close(stream);
STRING_free_later(buffer);
//fprintf(stderr, "buffer ref = %d\n", STRING_from_ptr(buffer)->ref);
SUBR_LEAVE();
}
else