ref: 35396e6410e471626db52c917f405fcf65034373
parent: 8d18b39eeed5188216483e21675911c046586b72
author: ISSOtm <[email protected]>
date: Sun Aug 16 20:06:02 EDT 2020
Fix files being unmapped when still referenced by macros
--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -257,6 +257,7 @@
char *ptr; /* Technically `const` during the lexer's execution */
off_t size;
off_t offset;
+ bool isReferenced; /* If a macro in this file requires not unmapping it*/
};
struct { /* Otherwise */
int fd;
@@ -415,7 +416,7 @@
{
if (!state->isMmapped)
close(state->fd);
- else if (state->isFile)
+ else if (state->isFile && !state->isReferenced)
munmap(state->ptr, state->size);
free(state);
}
@@ -1943,6 +1944,11 @@
char *captureStart = startCapture();
unsigned int level = 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