summaryrefslogtreecommitdiff
path: root/libmej/mem.h
blob: 3ab5226db477fb50b84e1c84548acc5e80e4243b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
 /***************************************************************
 * MEM.H -- Header file for mem.c                              *
 *       -- Michael Jennings                                   *
 *       -- 07 January 1997                                    *
 ***************************************************************/
/*
 * This file is original work by Michael Jennings <mej@tcserv.com>.
 *
 * Copyright (C) 1997, Michael Jennings
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * 
 */

#ifndef _MEM_H_

#define _MEM_H_

typedef struct memrec_struct {
  unsigned char init;
  unsigned long Count, TotalSize;
  void **Ptrs;
  size_t *Size;
} MemRec;

#ifdef WITH_DMALLOC
#  include <dmalloc.h>
#  define MALLOC(sz)		malloc(sz)
#  define CALLOC(type,n)	calloc((n),(sizeof(type)))
#  define REALLOC(mem,sz)	fixed_realloc((mem),(sz))
#  define FREE(ptr)		free(ptr)
#elif defined(DEBUG) || !defined(NDEBUG)
#  define MALLOC(sz)		Malloc(sz)
#  define CALLOC(type,n)	Calloc((n),(sizeof(type)))
#  define REALLOC(mem,sz)	Realloc((mem),(sz))
/* #  define FREE(ptr)		Free(ptr) */
#  define FREE(ptr)		{ Free(ptr); ptr = NULL; }
#  define MALLOC_MOD 25
#  define REALLOC_MOD 25
#  define CALLOC_MOD 25
#  define FREE_MOD 25
#else
#  define MALLOC(sz)		malloc(sz)
#  define CALLOC(type,n)	calloc((n),(sizeof(type)))
#  define REALLOC(mem,sz)	fixed_realloc((mem),(sz))
#  define FREE(ptr)		free(ptr)
#endif

#ifndef MEM_C

extern char *SafeStr(char *, unsigned short);
extern MemRec memrec;
extern void memrec_init(void);
void memrec_add_var(void *, size_t);
void memrec_rem_var(void *);
void memrec_chg_var(void *, void *, size_t);
void memrec_dump(void);
extern void *Malloc(size_t);
extern void *Realloc(void *, size_t);
extern void *Calloc(size_t, size_t);
extern void Free(void *);
extern void myalarm(long);
extern void HandleSigSegv(int);
extern char *GarbageCollect(char *, size_t);
extern char *FileGarbageCollect(char *, size_t);
extern void *fixed_realloc(void *, size_t);
#endif /* MEM_C */

#endif /* _MEM_H_ */