mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Use automatic allocation for section data
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "linkdefs.hpp"
|
#include "linkdefs.hpp"
|
||||||
#include "platform.hpp" // NONNULL
|
#include "platform.hpp" // NONNULL
|
||||||
@@ -38,7 +39,7 @@ struct Section {
|
|||||||
uint8_t align; // Exactly as specified in `ALIGN[]`
|
uint8_t align; // Exactly as specified in `ALIGN[]`
|
||||||
uint16_t alignOfs;
|
uint16_t alignOfs;
|
||||||
std::deque<struct Patch> patches;
|
std::deque<struct Patch> patches;
|
||||||
uint8_t *data;
|
std::vector<uint8_t> data;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SectionSpec {
|
struct SectionSpec {
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ static void writesection(struct Section const §, FILE *f)
|
|||||||
putlong(sect.alignOfs, f);
|
putlong(sect.alignOfs, f);
|
||||||
|
|
||||||
if (sect_HasData(sect.type)) {
|
if (sect_HasData(sect.type)) {
|
||||||
fwrite(sect.data, 1, sect.size, f);
|
fwrite(sect.data.data(), 1, sect.size, f);
|
||||||
putlong(sect.patches.size(), f);
|
putlong(sect.patches.size(), f);
|
||||||
|
|
||||||
for (struct Patch const &patch : sect.patches)
|
for (struct Patch const &patch : sect.patches)
|
||||||
|
|||||||
@@ -286,13 +286,8 @@ static struct Section *createSection(char const *name, enum SectionType type,
|
|||||||
sect.alignOfs = alignOffset;
|
sect.alignOfs = alignOffset;
|
||||||
|
|
||||||
// It is only needed to allocate memory for ROM sections.
|
// It is only needed to allocate memory for ROM sections.
|
||||||
if (sect_HasData(type)) {
|
if (sect_HasData(type))
|
||||||
sect.data = (uint8_t *)malloc(sectionTypeInfo[type].size);
|
sect.data.resize(sectionTypeInfo[type].size);
|
||||||
if (sect.data == NULL)
|
|
||||||
fatalerror("Not enough memory for section: %s\n", strerror(errno));
|
|
||||||
} else {
|
|
||||||
sect.data = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return §
|
return §
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user