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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
/*
alloc.c
This software is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This software 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this software; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Original copyright notice follows:
Copyright, 1993, Brent Benson. All Rights Reserved.
0.4 & 0.5 Revisions Copyright 1994, Joseph N. Wilson. All Rights Reserved.
Permission to use, copy, and modify this software and its
documentation is hereby granted only under the following terms and
conditions. Both the above copyright notice and this permission
notice must appear in all copies of the software, derivative works
or modified version, and both notices must appear in supporting
documentation. Users of this software agree to the terms and
conditions set forth in this notice.
*/
#include <string.h>
#include <gc/gc.h>
#include "alloc.h"
#include "env.h"
#include "symbol.h"
#include "error.h"
extern void GC_init (void);
/* function definitions */
void
initialize_gc (void)
{
GC_init ();
return;
}
Object
allocate_object (size_t size)
{
Object obj;
#ifndef SMALL_OBJECTS
obj = (Object) GC_malloc (sizeof (struct object));
#else
obj = (Object) GC_malloc (size);
#endif
if (!obj) {
fatal ("internal error: memory allocation failure.");
}
return (obj);
}
struct frame *
allocate_frame (void)
{
struct frame *frame;
frame = (struct frame *) GC_malloc (sizeof (struct frame));
if (!frame) {
fatal ("internal error: memory allocation failure.");
}
return (frame);
}
struct binding *
allocate_binding (void)
{
struct binding *binding;
binding = (struct binding *) GC_malloc (sizeof (struct binding));
if (!binding) {
fatal ("internal error: memory allocation failure.");
}
return (binding);
}
struct module_binding *
allocate_module_binding (void)
{
struct module_binding *module_binding;
module_binding =
(struct module_binding *) GC_malloc (sizeof (struct module_binding));
if (!module_binding) {
fatal ("internal error: memory allocation failure.");
}
return (module_binding);
}
struct symtab *
allocate_symtab (void)
{
struct symtab *entry;
entry = (struct symtab *) GC_malloc (sizeof (struct symtab));
if (!entry) {
fatal ("internal error: memory allocation failure.");
}
return (entry);
}
void *
checking_malloc (size_t size)
{
void *ptr;
ptr = (void *) GC_malloc (size);
if (!ptr) {
fatal ("internal error: memory allocation failure");
}
return (ptr);
}
void *
checking_realloc (void *ptr, size_t total_size)
{
ptr = (void *) GC_realloc (ptr, total_size);
if (!ptr) {
fatal ("internal error: memory allocation failure");
}
return (ptr);
}
char *
checking_strdup (char *str)
{
int size;
char *copied_str;
size = strlen (str) + 1;
copied_str = (char *) GC_malloc_atomic (size);
if (!copied_str) {
fatal ("internal error: memory allocation failure");
}
strcpy (copied_str, str);
return (copied_str);
}
char *
allocate_string (size_t size)
{
char *str;
str = (char *) GC_malloc_atomic (size);
if (!str) {
fatal ("internal error: memory allocation failure.");
}
return (str);
}
|