mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-04 14:00:18 +02:00
Add a simple memory management wrapper.
* lib/jit_memory.c: Implement a simple memory allocation wrapper to allow overriding calls to malloc/calloc/realloc/free, as well as ensuring all memory containing pointers is zero or points to allocated memory. * include/lightning.h, include/lightning/jit_private.h: Definitions for the memory allocation wrapper. * lib/Makefile.am: Update for new jit_memory.c file. * lib/jit_arm.c, lib/jit_disasm.c, lib/jit_mips.c, lib/jit_note.c, lib/jit_ppc.c, lib/jit_sparc.c, lib/jit_x86.c, lib/lightning.c: Use the new memory allocation wrapper code.
This commit is contained in:
parent
be9068f2ee
commit
c39def9dce
13 changed files with 263 additions and 148 deletions
|
@ -134,7 +134,7 @@ _jit_annotate(jit_state_t *_jit)
|
|||
length = sizeof(jit_line_t) * note->length;
|
||||
assert(_jitc->note.base + length < _jit->data.ptr + _jit->data.length);
|
||||
memcpy(_jitc->note.base, note->lines, length);
|
||||
free(note->lines);
|
||||
jit_free((jit_pointer_t *)¬e->lines);
|
||||
note->lines = (jit_line_t *)_jitc->note.base;
|
||||
_jitc->note.base += length;
|
||||
}
|
||||
|
@ -148,13 +148,13 @@ _jit_annotate(jit_state_t *_jit)
|
|||
assert(_jitc->note.base + length <
|
||||
_jit->data.ptr + _jit->data.length);
|
||||
memcpy(_jitc->note.base, line->linenos, length);
|
||||
free(line->linenos);
|
||||
jit_free((jit_pointer_t *)&line->linenos);
|
||||
line->linenos = (jit_int32_t *)_jitc->note.base;
|
||||
_jitc->note.base += length;
|
||||
assert(_jitc->note.base + length <
|
||||
_jit->data.ptr + _jit->data.length);
|
||||
memcpy(_jitc->note.base, line->offsets, length);
|
||||
free(line->offsets);
|
||||
jit_free((jit_pointer_t *)&line->offsets);
|
||||
line->offsets = (jit_int32_t *)_jitc->note.base;
|
||||
_jitc->note.base += length;
|
||||
}
|
||||
|
@ -190,10 +190,12 @@ _jit_set_note(jit_state_t *_jit, jit_note_t *note,
|
|||
else {
|
||||
/* line or offset changed */
|
||||
if ((line->length & 15) == 0) {
|
||||
line->linenos = realloc(line->linenos, (line->length + 17) *
|
||||
sizeof(jit_int32_t));
|
||||
line->offsets = realloc(line->offsets, (line->length + 17) *
|
||||
sizeof(jit_int32_t));
|
||||
jit_realloc((jit_pointer_t *)&line->linenos,
|
||||
line->length * sizeof(jit_int32_t),
|
||||
(line->length + 17) * sizeof(jit_int32_t));
|
||||
jit_realloc((jit_pointer_t *)&line->offsets,
|
||||
line->length * sizeof(jit_int32_t),
|
||||
(line->length + 17) * sizeof(jit_int32_t));
|
||||
}
|
||||
if (index < note->length) {
|
||||
memmove(line->linenos + index + 1, line->linenos + index,
|
||||
|
@ -268,10 +270,11 @@ new_line(jit_int32_t index, jit_note_t *note,
|
|||
jit_line_t *line;
|
||||
|
||||
if (note->lines == NULL)
|
||||
note->lines = malloc(16 * sizeof(jit_line_t));
|
||||
jit_alloc((jit_pointer_t *)¬e->lines, 16 * sizeof(jit_line_t));
|
||||
else if ((note->length & 15) == 15)
|
||||
note->lines = realloc(note->lines,
|
||||
(note->length + 17) * sizeof(jit_line_t));
|
||||
jit_realloc((jit_pointer_t *)¬e->lines,
|
||||
note->length * sizeof(jit_line_t),
|
||||
(note->length + 17) * sizeof(jit_line_t));
|
||||
|
||||
if (index < note->length)
|
||||
memmove(note->lines + index + 1, note->lines + index,
|
||||
|
@ -281,9 +284,9 @@ new_line(jit_int32_t index, jit_note_t *note,
|
|||
|
||||
line->file = file;
|
||||
line->length = 1;
|
||||
line->linenos = malloc(16 * sizeof(jit_int32_t));
|
||||
jit_alloc((jit_pointer_t *)&line->linenos, 16 * sizeof(jit_int32_t));
|
||||
line->linenos[0] = lineno;
|
||||
line->offsets = malloc(16 * sizeof(jit_int32_t));
|
||||
jit_alloc((jit_pointer_t *)&line->offsets, 16 * sizeof(jit_int32_t));
|
||||
line->offsets[0] = offset;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue