Ensure the type's encoding string is valid.

When encoding a type to a qfo file, the type's encoding string is written
and thus needs to be valid prior to actually doing the encoding. The
problem occurs mostly in self-referential structs (particularly, obj_class)
because the struct is being encoded prior to the pointer to the struct.
This commit is contained in:
Bill Currie 2012-11-11 20:22:48 +09:00
parent 8710977323
commit d13ce81b4f
3 changed files with 18 additions and 10 deletions

View file

@ -146,6 +146,7 @@ void print_type_str (struct dstring_s *str, type_t *type);
void print_type (type_t *type);
const char *encode_params (type_t *type);
void encode_type (struct dstring_s *encoding, type_t *type);
const char *type_get_encoding (type_t *type);
int is_enum (type_t *type);
int is_integral (type_t *type);
int is_float (type_t *type);

View file

@ -273,6 +273,8 @@ qfo_encode_type (type_t *type)
return type->type_def;
if (type->meta < 0 || type->meta > ty_class)
internal_error (0, "bad type meta type");
if (!type->encoding)
type->encoding = type_get_encoding (type);
type->type_def = funcs[type->meta] (type);
return type->type_def;
}

View file

@ -111,6 +111,19 @@ low_level_type (type_t *type)
internal_error (0, "invalid complex type");
}
const char *
type_get_encoding (type_t *type)
{
static dstring_t *encoding;
if (!encoding)
encoding = dstring_newstr();
else
dstring_clearstr (encoding);
encode_type (encoding, type);
return save_string (encoding->str);
}
void
chain_type (type_t *type)
{
@ -118,16 +131,8 @@ chain_type (type_t *type)
internal_error (0, "type already chained");
type->next = pr.types;
pr.types = type;
if (!type->encoding) {
static dstring_t *encoding;
if (!encoding)
encoding = dstring_newstr();
else
dstring_clearstr (encoding);
encode_type (encoding, type);
type->encoding = save_string (encoding->str);
}
if (!type->encoding)
type->encoding = type_get_encoding (type);
if (!type->type_def)
type->type_def = qfo_encode_type (type);
}