diff --git a/src/pobj/pobj.c b/src/pobj/pobj.c index 8b3e445..d027a34 100644 --- a/src/pobj/pobj.c +++ b/src/pobj/pobj.c @@ -1411,7 +1411,7 @@ pobj_boot_init (void) int -pobj_init (struct pobj_memfunc *ext_memfunc /* , struct pobj_memfunc *int_memfunc */) +pobj_init (struct pobj_memfunc *ext_memfunc, struct pobj_memfunc *int_memfunc) { recordid tmp_rid; int xid; @@ -1446,23 +1446,10 @@ pobj_init (struct pobj_memfunc *ext_memfunc /* , struct pobj_memfunc *int_memfun if (ext_memfunc->free) g_ext_memfunc.free = ext_memfunc->free; } -#if 0 - /* Gilad, 2004-12-13: disabled in order to make project compile... */ - if (int_memfunc) { - /* STOPPED HERE: don't necessarily initiate a whole new structure - * for internal calls, but rather initialize XMALLOC with them. */ - - if (int_memfunc->malloc) - g_int_memfunc.malloc = int_memfunc->malloc; - if (int_memfunc->calloc) - g_int_memfunc.calloc = int_memfunc->calloc; - if (int_memfunc->realloc) - g_int_memfunc.realloc = int_memfunc->realloc; - if (int_memfunc->free) - g_int_memfunc.free = int_memfunc->free; - } -#endif + /* Initialize internal memory manager. */ + if (int_memfunc) + xmem_memfunc (int_memfunc->malloc, int_memfunc->free); Tinit (); diff --git a/src/pobj/xmem.c b/src/pobj/xmem.c index 91fa295..f463534 100644 --- a/src/pobj/xmem.c +++ b/src/pobj/xmem.c @@ -31,12 +31,17 @@ struct xmem_stat { #endif /* HAVE_XMEM */ +/* Default memory calls. */ +void *(*g_memfunc_malloc) (size_t) = malloc; +void (*g_memfunc_free) (void *) = free; + + void * xmem_malloc (int mtype, char *file, int line, size_t size) { struct xmem *x; - x = (struct xmem *) malloc (size + XMEM_OFFSET); + x = (struct xmem *) g_memfunc_malloc (size + XMEM_OFFSET); if (! x) exit (1); @@ -99,9 +104,21 @@ xmem_free (int mtype, void *p) xmem_stats[mtype].count--; #endif /* HAVE_XMEM */ - free (x); + g_memfunc_free (x); } +int +xmem_memfunc (void *(*memfunc_malloc)(size_t), void (*memfunc_free)(void *)) +{ + if (memfunc_malloc) + g_memfunc_malloc = memfunc_malloc; + if (memfunc_free) + g_memfunc_free = memfunc_free; + + return 0; +} + + int xmem_obj_mtype (void *p) { diff --git a/src/pobj/xmem.h b/src/pobj/xmem.h index 41e7260..7eef26a 100644 --- a/src/pobj/xmem.h +++ b/src/pobj/xmem.h @@ -22,6 +22,7 @@ enum { void *xmem_malloc (int, char *, int, size_t); void xmem_free (int, void *); +int xmem_memfunc (void *(*) (size_t), void (*) (void *)); int xmem_obj_mtype (void *); char *xmem_obj_file (void *); int xmem_obj_line (void *);