#include "gras/DataDesc/datadesc_private.h"
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_create,datadesc);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_create,datadesc,"Creating new datadescriptions");
/**
* gras_ddt_freev:
gras_datadesc_type_t *res;
GRAS_IN1("(%s)",name);
- res=malloc(sizeof(gras_datadesc_type_t));
+ res=gras_new0(gras_datadesc_type_t,1);
if (!res)
RAISE_MALLOC;
- memset(res, 0, sizeof(gras_datadesc_type_t));
- res->name = strdup(name);
+ res->name = (char*)strdup(name);
res->name_len = strlen(name);
*dst=res;
for (arch = 0; arch < gras_arch_count; arch ++) {
long int sz;
long int mask;
- res->size[arch] = gras_arches[arch].sizeof_scalars[type];
-
+ res->size[arch] = gras_arches[arch].sizeofs[type];
+ res->alignment[arch] = gras_arches[arch].boundaries[type];
+ res->aligned_size[arch] = aligned(res->size[arch], res->alignment[arch]);
+#if 0
sz = res->size[arch];
mask = sz;
res->alignment[arch] = res->size[arch];
res->aligned_size[arch] = res->size[arch];
}
+#endif
}
res->category_code = e_gras_datadesc_type_cat_scalar;
GRAS_IN;
if (field) {
if (field->name)
- free(field->name);
- free(field);
+ gras_free(field->name);
+ gras_free(field);
}
GRAS_OUT;
}
return no_error;
}
- gras_assert1(field_type->size >= 0,
+ gras_assert1(field_type->size != 0,
"Cannot add a dynamically sized field in structure %s",
struct_type->name);
- field=malloc(sizeof(gras_dd_cat_field_t));
+ field=gras_new(gras_dd_cat_field_t,1);
if (!field)
RAISE_MALLOC;
- field->name = strdup(name);
+ field->name = (char*)strdup(name);
DEBUG0("----------------");
- DEBUG4("PRE s={size=%ld,align=%ld,asize=%ld} struct_boundary=%d",
+ DEBUG3("PRE s={size=%ld,align=%ld,asize=%ld}",
struct_type->size[GRAS_THISARCH],
struct_type->alignment[GRAS_THISARCH],
- struct_type->aligned_size[GRAS_THISARCH],
- gras_arches[GRAS_THISARCH].struct_boundary);
+ struct_type->aligned_size[GRAS_THISARCH]);
for (arch=0; arch<gras_arch_count; arch ++) {
field->offset[arch] = aligned(struct_type->size[arch],
- min(field_type->alignment[arch],
- gras_arches[arch].struct_boundary));
+ field_type->alignment[arch]);
struct_type->size[arch] = field->offset[arch] + field_type->size[arch];
struct_type->alignment[arch] = max(struct_type->alignment[arch],
int arch;
GRAS_IN3("(%s %s.%s;)",field_type->name,union_type->name,name);
- gras_assert1(field_type->size >= 0,
+ gras_assert1(field_type->size != 0,
"Cannot add a dynamically sized field in union %s",
union_type->name);
return no_error;
}
- field=malloc(sizeof(gras_dd_cat_field_t));
+ field=gras_new0(gras_dd_cat_field_t,1);
if (!field)
RAISE_MALLOC;
- field->name = strdup(name);
- for (arch=0; arch<gras_arch_count; arch ++) {
- field->offset[arch] = 0; /* that's the purpose of union ;) */
- }
+ field->name = (char*)strdup(name);
field->type = field_type;
- field->pre = NULL;
- field->post = NULL;
+ /* All offset are left to 0 in an union */
TRY(gras_dynar_push(union_type->category.union_data.fields, &field));
TRY(gras_ddt_new(name,dst));
res=*dst;
- gras_assert1(fixed_size > 0, "'%s' is a array of negative fixed size",name);
+ gras_assert1(fixed_size > 0, "'%s' is a array of null fixed size",name);
for (arch=0; arch<gras_arch_count; arch ++) {
res->size[arch] = fixed_size * element_type->aligned_size[arch];
res->alignment[arch] = element_type->alignment[arch];
"Redefinition of type %s does not match", name);
gras_assert1(res->category.array_data.type == element_type,
"Redefinition of type %s does not match", name);
- gras_assert1(res->category.array_data.fixed_size == -1,
+ gras_assert1(res->category.array_data.fixed_size == 0,
"Redefinition of type %s does not match", name);
gras_assert1(res->category.array_data.dynamic_size == dynamic_size,
"Redefinition of type %s does not match", name);
res=*dst;
for (arch=0; arch<gras_arch_count; arch ++) {
- res->size[arch] = -1; /* make sure it indicates "dynamic" */
+ res->size[arch] = 0; /* make sure it indicates "dynamic" */
res->alignment[arch] = element_type->alignment[arch];
- res->aligned_size[arch] = -1; /*FIXME: That was so in GS, but looks stupid*/
+ res->aligned_size[arch] = 0; /*FIXME: That was so in GS, but looks stupid*/
}
res->category_code = e_gras_datadesc_type_cat_array;
res->category.array_data.type = element_type;
- res->category.array_data.fixed_size = -1;
+ res->category.array_data.fixed_size = 0;
res->category.array_data.dynamic_size = dynamic_size;
return no_error;
gras_datadesc_ref_pop_arr(gras_datadesc_type_t *element_type,
gras_datadesc_type_t **dst) {
gras_error_t errcode;
- char *name=malloc(strlen(element_type->name) + 4);
+ char *name=(char*)gras_malloc(strlen(element_type->name) + 4);
sprintf(name,"%s[]",element_type->name);
sprintf(name,"%s[]*",element_type->name);
TRY(gras_datadesc_ref(name,*dst,dst));
- free(name);
+ gras_free(name);
return no_error;
}
} else if (type->category_code == e_gras_datadesc_type_cat_struct) {
field_array = type->category.struct_data.fields;
} else {
- ERROR2("%s (%p) is not a struct nor an union. There is no field.", type->name,type);
+ ERROR2("%s (%p) is not a struct nor an union. There is no field.", type->name,(void*)type);
gras_abort();
}
gras_dynar_foreach(field_array,field_num,field) {
/* datadesc was invalid. Killing it is like euthanasy, I guess */
break;
}
- free(type->name);
- free(type);
+ gras_free(type->name);
+ gras_free(type);
}