1 /*
2 	pr_zone.c
3 
4 	(description)
5 
6 	Copyright (C) 1996-1997  Id Software, Inc.
7 
8 	This program is free software; you can redistribute it and/or
9 	modify it under the terms of the GNU General Public License
10 	as published by the Free Software Foundation; either version 2
11 	of the License, or (at your option) any later version.
12 
13 	This program is distributed in the hope that it will be useful,
14 	but WITHOUT ANY WARRANTY; without even the implied warranty of
15 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 	See the GNU General Public License for more details.
18 
19 	You should have received a copy of the GNU General Public License
20 	along with this program; if not, write to:
21 
22 		Free Software Foundation, Inc.
23 		59 Temple Place - Suite 330
24 		Boston, MA  02111-1307, USA
25 
26 */
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30 
31 #ifdef HAVE_STRING_H
32 # include <string.h>
33 #endif
34 #ifdef HAVE_STRINGS_H
35 # include <strings.h>
36 #endif
37 
38 #include <stdarg.h>
39 
40 #include "QF/cvar.h"
41 #include "QF/mathlib.h"
42 #include "QF/progs.h"
43 #include "QF/sys.h"
44 #include "QF/zone.h"
45 
46 #include "compat.h"
47 
48 static void
pr_zone_error(void * _pr,const char * msg)49 pr_zone_error (void *_pr, const char *msg)
50 {
51 	progs_t    *pr = (progs_t *) _pr;
52 	PR_RunError (pr, "%s", msg);
53 }
54 
55 void
PR_Zone_Init(progs_t * pr)56 PR_Zone_Init (progs_t *pr)
57 {
58 	Z_ClearZone (pr->zone, pr->zone_size,
59 				 (pr_type_t *)pr->zone - pr->pr_globals, sizeof (pr_type_t));
60 	Z_SetError (pr->zone, pr_zone_error, pr);
61 }
62 
63 VISIBLE void
PR_Zone_Free(progs_t * pr,void * ptr)64 PR_Zone_Free (progs_t *pr, void *ptr)
65 {
66 	Z_Free (pr->zone, ptr);
67 }
68 
69 VISIBLE void *
PR_Zone_Malloc(progs_t * pr,pr_int_t size)70 PR_Zone_Malloc (progs_t *pr, pr_int_t size)
71 {
72 	if (size <= 0)
73 		PR_RunError (pr, "attempt to allocate less than 1 byte");
74 	return Z_Malloc (pr->zone, size);
75 }
76 
77 VISIBLE void *
PR_Zone_Realloc(progs_t * pr,void * ptr,pr_int_t size)78 PR_Zone_Realloc (progs_t *pr, void *ptr, pr_int_t size)
79 {
80 	if (ptr && !size) {
81 		Z_Free (pr->zone, ptr);
82 		return 0;
83 	}
84 	if (size <= 0)
85 		PR_RunError (pr, "attempt to allocate less than 1 byte");
86 	return Z_Realloc (pr->zone, ptr, size);
87 }
88