mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Fix files being unmapped when still referenced by macros
This commit is contained in:
@@ -257,6 +257,7 @@ struct LexerState {
|
|||||||
char *ptr; /* Technically `const` during the lexer's execution */
|
char *ptr; /* Technically `const` during the lexer's execution */
|
||||||
off_t size;
|
off_t size;
|
||||||
off_t offset;
|
off_t offset;
|
||||||
|
bool isReferenced; /* If a macro in this file requires not unmapping it*/
|
||||||
};
|
};
|
||||||
struct { /* Otherwise */
|
struct { /* Otherwise */
|
||||||
int fd;
|
int fd;
|
||||||
@@ -415,7 +416,7 @@ void lexer_DeleteState(struct LexerState *state)
|
|||||||
{
|
{
|
||||||
if (!state->isMmapped)
|
if (!state->isMmapped)
|
||||||
close(state->fd);
|
close(state->fd);
|
||||||
else if (state->isFile)
|
else if (state->isFile && !state->isReferenced)
|
||||||
munmap(state->ptr, state->size);
|
munmap(state->ptr, state->size);
|
||||||
free(state);
|
free(state);
|
||||||
}
|
}
|
||||||
@@ -1944,6 +1945,11 @@ void lexer_CaptureMacroBody(char **capture, size_t *size)
|
|||||||
unsigned int level = 0;
|
unsigned int level = 0;
|
||||||
int c = peek(0);
|
int c = peek(0);
|
||||||
|
|
||||||
|
/* If the file is `mmap`ed, we need not to unmap it to keep access to the macro */
|
||||||
|
if (lexerState->isMmapped)
|
||||||
|
/* FIXME: this is godawful, but RGBASM doesn't even clean up anything anyways. */
|
||||||
|
lexerState->isReferenced = true;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Due to parser internals, it does not read the EOL after the T_POP_MACRO before calling
|
* Due to parser internals, it does not read the EOL after the T_POP_MACRO before calling
|
||||||
* this. Thus, we need to keep one in the buffer afterwards.
|
* this. Thus, we need to keep one in the buffer afterwards.
|
||||||
|
|||||||
Reference in New Issue
Block a user