From f39ed3459283bd04d3979ac4c2b38d1ac4063b84 Mon Sep 17 00:00:00 2001 From: gambas Date: Sat, 21 Dec 2019 17:35:30 +0100 Subject: [PATCH] Serializing an object is not ambiguous anymore. [INTERPRETER] * BUG: Serializing an object is not ambiguous anymore. --- main/gbx/gbx_stream.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/main/gbx/gbx_stream.c b/main/gbx/gbx_stream.c index 1c09be276..1975d717e 100644 --- a/main/gbx/gbx_stream.c +++ b/main/gbx/gbx_stream.c @@ -1166,34 +1166,37 @@ void STREAM_read_type(STREAM *stream, TYPE type, VALUE *value) return; } - if (buffer._byte == 'O') + if (buffer._byte == 'O' || buffer._byte == 'o') { - int len; - char *name = COMMON_buffer; - CLASS *class; + CLASS *class = NULL; void *object; void *cstream; - if (variant || type == T_OBJECT) + if (buffer._byte == 'o') { + int len; + char *name = COMMON_buffer; + len = read_length(stream); if (len > 255) THROW_SERIAL(); STREAM_read(stream, name, len); - + class = CLASS_look(name, len); if (!class) THROW_SERIAL(); - - if (TYPE_is_pure_object(type) && (CLASS *)type != class) + } + + if (TYPE_is_pure_object(type)) + { + if (class && (CLASS *)type != class) THROW_SERIAL(); } - else if (TYPE_is_pure_object(type)) - { - class = (CLASS *)type; - } else - THROW_SERIAL(); + { + if (!class) + THROW_SERIAL(); + } object = OBJECT_ref(OBJECT_create(class, NULL, NULL, 0)); @@ -1534,17 +1537,22 @@ void STREAM_write_type(STREAM *stream, TYPE type, VALUE *value) { CSTREAM *ob; - buffer._byte = 'O'; - STREAM_write(stream, &buffer._byte, 1); - - if (variant) + if (variant || type == T_OBJECT) { char *name = class->name; int len = strlen(name); + buffer._byte = 'o'; + STREAM_write(stream, &buffer._byte, 1); + write_length(stream, len); STREAM_write(stream, name, len); } + else + { + buffer._byte = 'O'; + STREAM_write(stream, &buffer._byte, 1); + } ob = CSTREAM_FROM_STREAM(stream); STACK_check(1);