1/* malloc.h -- Public #include File (module.h template V1.0) 2 Copyright (C) 1995 Free Software Foundation, Inc. 3 Contributed by James Craig Burley. 4 5This file is part of GNU Fortran. 6 7GNU Fortran is free software; you can redistribute it and/or modify 8it under the terms of the GNU General Public License as published by 9the Free Software Foundation; either version 2, or (at your option) 10any later version. 11 12GNU Fortran is distributed in the hope that it will be useful, 13but WITHOUT ANY WARRANTY; without even the implied warranty of 14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15GNU General Public License for more details. 16 17You should have received a copy of the GNU General Public License 18along with GNU Fortran; see the file COPYING. If not, write to 19the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 2002111-1307, USA. 21 22 Owning Modules: 23 malloc.c 24 25 Modifications: 26*/ 27 28/* Allow multiple inclusion to work. */ 29 30#ifndef _H_f_malloc 31#define _H_f_malloc 32 33#ifndef MALLOC_DEBUG 34#define MALLOC_DEBUG 0 /* 1 means check caller's use of this module. */ 35#endif 36 37/* Simple definitions and enumerations. */ 38 39typedef enum 40 { 41 MALLOC_typeKS_, 42 MALLOC_typeKSR_, 43 MALLOC_typeKP_, 44 MALLOC_typeKPR_, 45 MALLOC_typeUS_, 46 MALLOC_typeUSR_, 47 MALLOC_type_ 48 } mallocType_; 49 50/* Typedefs. */ 51 52typedef struct _malloc_area_ *mallocArea_; 53typedef struct _malloc_pool_ *mallocPool; 54typedef unsigned long int mallocSize; 55#define mallocSize_f "l" 56 57/* Include files needed by this one. */ 58 59 60/* Structure definitions. */ 61 62struct _malloc_area_ 63 { 64 mallocArea_ next; 65 mallocArea_ previous; 66 void *where; 67#if MALLOC_DEBUG 68 mallocSize size; 69 mallocType_ type; 70#endif 71 char name[1]; 72 }; 73 74struct _malloc_pool_ 75 { 76 mallocPool next; 77 mallocPool previous; 78 mallocPool eldest; 79 mallocPool youngest; 80 mallocArea_ first; 81 mallocArea_ last; 82 unsigned long uses; 83#if MALLOC_DEBUG 84 mallocSize allocated; 85 mallocSize freed; 86 mallocSize old_sizes; 87 mallocSize new_sizes; 88 unsigned long allocations; 89 unsigned long frees; 90 unsigned long resizes; 91#endif 92 char name[1]; 93 }; 94 95struct _malloc_root_ 96 { 97 struct _malloc_pool_ malloc_pool_image_; 98 }; 99 100/* Global objects accessed by users of this module. */ 101 102extern struct _malloc_root_ malloc_root_; 103 104/* Declare functions with prototypes. */ 105 106void malloc_display_ (mallocArea_ a); 107mallocArea_ malloc_find_inpool_ (mallocPool pool, void *ptr); 108void malloc_init (void); 109void malloc_kill_inpool_ (mallocPool pool, mallocType_ type, void *ptr, 110 mallocSize size); 111void *malloc_new_ (mallocSize size); 112void *malloc_new_inpool_ (mallocPool pool, mallocType_ type, const char *name, 113 mallocSize size); 114void *malloc_new_zinpool_ (mallocPool pool, mallocType_ type, const char *name, 115 mallocSize size, int z); 116void malloc_pool_display (mallocPool p); 117char malloc_pool_find_ (mallocPool p, mallocPool parent); 118void malloc_pool_kill (mallocPool p); 119mallocPool malloc_pool_new (const char *name, mallocPool parent, unsigned long chunks); 120mallocPool malloc_pool_use (mallocPool p); 121void *malloc_resize_ (void *ptr, mallocSize new_size); 122void *malloc_resize_inpool_ (mallocPool pool, mallocType_ type, void *ptr, 123 mallocSize new_size, mallocSize old_size); 124void malloc_verify_inpool_ (mallocPool pool, mallocType_ type, void *ptr, 125 mallocSize size); 126 127/* Define macros. */ 128 129#define malloc_new_ks(pool,name,size) \ 130 malloc_new_inpool_ (pool,MALLOC_typeKS_,name,size) 131#define malloc_new_ksr(pool,name,size) \ 132 malloc_new_inpool_ (pool,MALLOC_typeKSR_,name,size) 133#define malloc_new_kp(pool,name,size) \ 134 malloc_new_inpool_ (pool,MALLOC_typeKP_,name,size) 135#define malloc_new_kpr(pool,name,size) \ 136 malloc_new_inpool_ (pool,MALLOC_typeKPR_,name,size) 137#define malloc_new_us(pool,name,size) \ 138 malloc_new_inpool_ (pool,MALLOC_typeUS_,name,size) 139#define malloc_new_usr(pool,name,size) \ 140 malloc_new_inpool_ (pool,MALLOC_typeUSR_,name,size) 141#define malloc_new_zks(pool,name,size,z) \ 142 malloc_new_zinpool_ (pool,MALLOC_typeKS_,name,size,z) 143#define malloc_new_zksr(pool,name,size,z) \ 144 malloc_new_zinpool_ (pool,MALLOC_typeKSR_,name,size,z) 145#define malloc_new_zkp(pool,name,size,z) \ 146 malloc_new_zinpool_ (pool,MALLOC_typeKP_,name,size,z) 147#define malloc_new_zkpr(pool,name,size,z) \ 148 malloc_new_zinpool_ (pool,MALLOC_typeKPR_,name,size,z) 149#define malloc_new_zus(pool,name,size,z) \ 150 malloc_new_zinpool_ (pool,MALLOC_typeUS_,name,size,z) 151#define malloc_new_zusr(pool,name,size,z) \ 152 malloc_new_zinpool_ (pool,MALLOC_typeUSR_,name,size,z) 153#define malloc_kill_ks(pool,ptr,size) \ 154 malloc_kill_inpool_ (pool,MALLOC_typeKS_,ptr,size) 155#define malloc_kill_ksr(pool,ptr,size) \ 156 malloc_kill_inpool_ (pool,MALLOC_typeKSR_,ptr,size) 157#define malloc_kill_us(pool,ptr) \ 158 malloc_kill_inpool_ (pool,MALLOC_typeUS_,ptr,0) 159#define malloc_kill_usr(pool,ptr) \ 160 malloc_kill_inpool_ (pool,MALLOC_typeUSR_,ptr,0) 161#define malloc_pool_image() (&malloc_root_.malloc_pool_image_) 162#define malloc_resize_ksr(pool,ptr,new_size,old_size) \ 163 malloc_resize_inpool_ (pool,MALLOC_typeKSR_,ptr,new_size,old_size) 164#define malloc_resize_kpr(pool,ptr,new_size,old_size) \ 165 malloc_resize_inpool_ (pool,MALLOC_typeKPR_,ptr,new_size,old_size) 166#define malloc_resize_usr(pool,ptr,new_size) \ 167 malloc_resize_inpool_ (pool,MALLOC_typeUSR_,ptr,new_size,0) 168#define malloc_verify_kp(pool,name,size) \ 169 malloc_verify_inpool_ (pool,MALLOC_typeKP_,name,size) 170#define malloc_verify_kpr(pool,name,size) \ 171 malloc_verify_inpool_ (pool,MALLOC_typeKPR_,name,size) 172#define malloc_verify_ks(pool,ptr,size) \ 173 malloc_verify_inpool_ (pool,MALLOC_typeKS_,ptr,size) 174#define malloc_verify_ksr(pool,ptr,size) \ 175 malloc_verify_inpool_ (pool,MALLOC_typeKSR_,ptr,size) 176#define malloc_verify_us(pool,ptr) \ 177 malloc_verify_inpool_ (pool,MALLOC_typeUS_,ptr,0) 178#define malloc_verify_usr(pool,ptr) \ 179 malloc_verify_inpool_ (pool,MALLOC_typeUSR_,ptr,0) 180 181/* End of #include file. */ 182 183#endif 184