Added custom memory calls for pobj internal structures.

This commit is contained in:
Gilad Arnold 2004-12-14 07:38:04 +00:00
parent 99f85eb9c4
commit 773df6c690
3 changed files with 24 additions and 19 deletions

View file

@ -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 ();

View file

@ -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)
{

View file

@ -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 *);