diff --git a/ir.h b/ir.h index 01d4013..51a9af4 100644 --- a/ir.h +++ b/ir.h @@ -593,10 +593,31 @@ void ir_check(ir_ctx *ctx); void ir_consistency_check(void); /* IR Memmory Allocation */ -#define ir_mem_malloc(size) malloc(size) -#define ir_mem_calloc(n, size) calloc(n, size) -#define ir_mem_realloc(ptr, size) realloc(ptr, size) -#define ir_mem_free(ptr) free(ptr) +#ifndef ir_mem_malloc +# define ir_mem_malloc malloc +#endif +#ifndef ir_mem_calloc +# define ir_mem_calloc calloc +#endif +#ifndef ir_mem_realloc +# define ir_mem_realloc realloc +#endif +#ifndef ir_mem_free +# define ir_mem_free free +#endif + +#ifndef ir_mem_pmalloc +# define ir_mem_pmalloc malloc +#endif +#ifndef ir_mem_pcalloc +# define ir_mem_pcalloc calloc +#endif +#ifndef ir_mem_prealloc +# define ir_mem_prealloc realloc +#endif +#ifndef ir_mem_pfree +# define ir_mem_pfree free +#endif void *ir_mem_mmap(size_t size); int ir_mem_unmap(void *ptr, size_t size); diff --git a/ir_aarch64.dasc b/ir_aarch64.dasc index 75e0e08..05c6d6c 100644 --- a/ir_aarch64.dasc +++ b/ir_aarch64.dasc @@ -10,6 +10,19 @@ # define IR_SET_ALIGNED(alignment, decl) decl #endif +#define DASM_M_GROW(ctx, t, p, sz, need) \ + do { \ + size_t _sz = (sz), _need = (need); \ + if (_sz < _need) { \ + if (_sz < 16) _sz = 16; \ + while (_sz < _need) _sz += _sz; \ + (p) = (t *)ir_mem_realloc((p), _sz); \ + (sz) = _sz; \ + } \ + } while(0) + +#define DASM_M_FREE(ctx, p, sz) ir_mem_free(p) + #if IR_DEBUG # define DASM_CHECKS #endif diff --git a/ir_disasm.c b/ir_disasm.c index 69bf457..47c8794 100644 --- a/ir_disasm.c +++ b/ir_disasm.c @@ -74,7 +74,7 @@ void ir_disasm_add_symbol(const char *name, ir_sym_node *sym; size_t len = strlen(name); - sym = ir_mem_malloc(sizeof(ir_sym_node) + len + 1); + sym = ir_mem_pmalloc(sizeof(ir_sym_node) + len + 1); if (!sym) { return; } @@ -111,7 +111,7 @@ void ir_disasm_add_symbol(const char *name, /* reduce size of the existing symbol */ node->end = sym->end; } - free(sym); + ir_mem_pfree(sym); return; } } while (1); @@ -167,7 +167,7 @@ static void ir_disasm_destroy_symbols(ir_sym_node *n) if (n->child[1]) { ir_disasm_destroy_symbols(n->child[1]); } - free(n); + ir_mem_pfree(n); } } diff --git a/ir_php.h b/ir_php.h index 07fbdd5..6594860 100644 --- a/ir_php.h +++ b/ir_php.h @@ -1,6 +1,13 @@ #ifndef IR_PHP_H #define IR_PHP_H +#include "zend.h" + #define IR_PHP_OPS(_) +#define ir_mem_malloc emalloc +#define ir_mem_calloc ecalloc +#define ir_mem_realloc erealloc +#define ir_mem_free efree + #endif /* IR_PHP_H */ diff --git a/ir_ra.c b/ir_ra.c index 3c7f224..fecf568 100644 --- a/ir_ra.c +++ b/ir_ra.c @@ -615,13 +615,13 @@ void ir_free_live_ranges(ir_live_range *live_range) void ir_free_live_intervals(ir_live_interval **live_intervals, int count) { uint32_t i; - ir_live_interval *ival; + ir_live_interval *ival, *next; ir_use_pos *use_pos; count += IR_REG_NUM; for (i = 0; i <= count; i++) { ival = live_intervals[i]; - if (ival) { + while (ival) { if (ival->range.next) { ir_free_live_ranges(ival->range.next); } @@ -631,7 +631,9 @@ void ir_free_live_intervals(ir_live_interval **live_intervals, int count) use_pos = p->next; ir_mem_free(p); } + next = ival->next; ir_mem_free(ival); + ival = next; } } ir_mem_free(live_intervals); diff --git a/ir_x86.dasc b/ir_x86.dasc index c4b4afb..ba7675e 100644 --- a/ir_x86.dasc +++ b/ir_x86.dasc @@ -10,6 +10,19 @@ # define IR_SET_ALIGNED(alignment, decl) decl #endif +#define DASM_M_GROW(ctx, t, p, sz, need) \ + do { \ + size_t _sz = (sz), _need = (need); \ + if (_sz < _need) { \ + if (_sz < 16) _sz = 16; \ + while (_sz < _need) _sz += _sz; \ + (p) = (t *)ir_mem_realloc((p), _sz); \ + (sz) = _sz; \ + } \ + } while(0) + +#define DASM_M_FREE(ctx, p, sz) ir_mem_free(p) + #if IR_DEBUG # define DASM_CHECKS #endif