summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrill Gorcunov <gorcunov@gmail.com>2011-02-28 01:18:54 +0300
committerCyrill Gorcunov <gorcunov@gmail.com>2011-02-28 01:26:24 +0300
commit3bc3ff2fb685a645698f9db9cfc903df30e4e555 (patch)
treee48cc154b3844959565c289cd68cb70d9c718746
parent11db774a151e9d895fa05f980563a5cafb0f306a (diff)
downloadnasm-3bc3ff2fb685a645698f9db9cfc903df30e4e555.tar.gz
bin: Use nasm_zalloc helper for section allocation in a sake of simplicity
Instead of opencoded zero assignments better to use nasm_zalloc and set fields which are supposed to be non-nil. This simplifies code and makes it more readable. Also note the field 'ifollows' renamed to 'prev' as it should be from the very beginning in terms of lists. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
-rw-r--r--output/outbin.c44
1 files changed, 19 insertions, 25 deletions
diff --git a/output/outbin.c b/output/outbin.c
index 97a29a89..e1794b55 100644
--- a/output/outbin.c
+++ b/output/outbin.c
@@ -130,7 +130,7 @@ static struct Section {
struct bin_label *labels; /* linked-list of label handles for map output. */
struct bin_label **labels_end; /* Holds address of end of labels list. */
- struct Section *ifollows; /* Points to previous section (implicit follows). */
+ struct Section *prev; /* Points to previous section (implicit follows). */
struct Section *next; /* This links sections with a defined start address. */
/* The extended bin format allows for sections to have a "virtual"
@@ -201,28 +201,22 @@ static struct Section *find_section_by_index(int32_t index)
}
static struct Section *create_section(char *name)
-{ /* Create a new section. */
- last_section->next = nasm_malloc(sizeof(struct Section));
- last_section->next->ifollows = last_section;
- last_section = last_section->next;
- last_section->labels = NULL;
- last_section->labels_end = &(last_section->labels);
+{
+ struct Section *s = nasm_zalloc(sizeof(*s));
- /* Initialize section attributes. */
- last_section->name = nasm_strdup(name);
- last_section->contents = saa_init(1L);
- last_section->follows = last_section->vfollows = 0;
- last_section->length = 0;
- last_section->flags = 0;
- last_section->align = 0;
- last_section->valign = 0;
- last_section->start = 0;
- last_section->vstart = 0;
- last_section->next = NULL;
+ s->prev = last_section;
+ s->name = nasm_strdup(name);
+ s->labels_end = &(s->labels);
+ s->contents = saa_init(1L);
/* Register our sections with NASM. */
- last_section->vstart_index = seg_alloc();
- last_section->start_index = seg_alloc();
+ s->vstart_index = seg_alloc();
+ s->start_index = seg_alloc();
+
+ /* FIXME: Append to a tail, we need some helper */
+ last_section->next = s;
+ last_section = s;
+
return last_section;
}
@@ -489,9 +483,9 @@ static void bin_cleanup(int debuginfo)
nasm_error(ERR_FATAL|ERR_NOFILE,
"section %s vfollows unknown section (%s)",
g->name, g->vfollows);
- } else if (g->ifollows != NULL)
- for (s = sections; s && (s != g->ifollows); s = s->next) ;
- /* The .bss section is the only one with ifollows = NULL.
+ } else if (g->prev != NULL)
+ for (s = sections; s && (s != g->prev); s = s->next) ;
+ /* The .bss section is the only one with prev = NULL.
In this case we implicitly follow the last progbits
section. */
else
@@ -1262,7 +1256,7 @@ static int32_t bin_secname(char *name, int pass, int *bits)
sec->flags |= TYPE_DEFINED | TYPE_PROGBITS;
else if (!strcmp(name, ".bss")) {
sec->flags |= TYPE_DEFINED | TYPE_NOBITS;
- sec->ifollows = NULL;
+ sec->prev = NULL;
}
}
@@ -1438,7 +1432,7 @@ static void binfmt_init(void)
last_section->name = nasm_strdup(".text");
last_section->contents = saa_init(1L);
last_section->follows = last_section->vfollows = 0;
- last_section->ifollows = NULL;
+ last_section->prev = NULL;
last_section->length = 0;
last_section->flags = TYPE_DEFINED | TYPE_PROGBITS;
last_section->labels = NULL;