1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-02 04:40:29 +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:
pcpa 2013-03-29 12:10:36 -03:00
parent be9068f2ee
commit c39def9dce
13 changed files with 263 additions and 148 deletions

View file

@ -109,11 +109,9 @@ _jit_prolog(jit_state_t *_jit)
jit_regset_set_ui(_jitc->regsav, 0);
offset = _jitc->functions.offset;
if (offset >= _jitc->functions.length) {
_jitc->functions.ptr = realloc(_jitc->functions.ptr,
(_jitc->functions.length + 16) *
sizeof(jit_function_t));
memset(_jitc->functions.ptr + _jitc->functions.length, 0,
16 * sizeof(jit_function_t));
jit_realloc((jit_pointer_t *)&_jitc->functions.ptr,
_jitc->functions.length * sizeof(jit_function_t),
(_jitc->functions.length + 16) * sizeof(jit_function_t));
_jitc->functions.length += 16;
}
_jitc->function = _jitc->functions.ptr + _jitc->functions.offset++;
@ -123,7 +121,8 @@ _jit_prolog(jit_state_t *_jit)
/* float conversion */
_jitc->function->self.aoff = -8;
_jitc->function->self.call = jit_call_default;
_jitc->function->regoff = calloc(_jitc->reglen, sizeof(jit_int32_t));
jit_alloc((jit_pointer_t *)&_jitc->function->regoff,
_jitc->reglen * sizeof(jit_int32_t));
_jitc->function->prolog = jit_new_node_no_link(jit_code_prolog);
jit_link(_jitc->function->prolog);
@ -1163,9 +1162,9 @@ _patch(jit_state_t *_jit, jit_word_t instr, jit_node_t *node)
flag = node->u.n->flag;
assert(!(flag & jit_flag_patch));
if (_jitc->patches.offset >= _jitc->patches.length) {
_jitc->patches.ptr = realloc(_jitc->patches.ptr,
(_jitc->patches.length + 1024) *
sizeof(jit_patch_t));
jit_realloc((jit_pointer_t *)&_jitc->patches.ptr,
_jitc->patches.length * sizeof(jit_patch_t),
(_jitc->patches.length + 1024) * sizeof(jit_patch_t));
memset(_jitc->patches.ptr + _jitc->patches.length, 0,
1024 * sizeof(jit_patch_t));
_jitc->patches.length += 1024;