    1    | /***************************************
    2    |   $Header: /home/amb/cxref/RCS/memory.h 1.7 1996/02/24 14:53:30 amb Exp $
    3    |
    4    |   C Cross Referencing & Documentation tool. Version 1.0
    5    |
    6    |   Memory management functions
    7    |   ******************/ /******************
    8    |   Written by Andrew M. Bishop
    9    |
    10   |   This file Copyright 1995,96 Andrew M. Bishop
    11   |   It may be distributed under the GNU Public License, version 2, or
    12   |   any higher version.  See section COPYING of the GNU Public license
    13   |   for conditions under which this file may be redistributed.
    14   |   ***************************************/
    15   |
    16   |
    17   | #ifndef MEMORY_H
    18   | #define MEMORY_H   /*+ To stop multiple inclusions. +*/
    19   |
    20   | /*+ malloc(), calloc(), realloc() and free() replacements +*/
    21   |
    22   | #define Malloc(s)    SafeMalloc (  s,__FILE__,__LINE__)
    23   | #define Calloc(n,s)  SafeCalloc (n,s,__FILE__,__LINE__)
    24   | #define Realloc(p,s) SafeRealloc(p,s,__FILE__,__LINE__)
    25   | #define Free(p)      SafeFree   (p  ,__FILE__,__LINE__)
    26   |
    27   | void* SafeMalloc(unsigned int size,char* file,int line);
    28   | void* SafeCalloc(unsigned int n,unsigned int size,char* file,int line);
    29   | void* SafeRealloc(void* ptr,unsigned int size,char* file,int line);
    30   | void  SafeFree(void* ptr,char* file,int line);
    31   |
    32   | /*+ String manipulation functions on public heap +*/
    33   |
    34   | #define MallocString(p) SafeMallocString (p,__FILE__,__LINE__)
    35   |
    36   | char* SafeMallocString(char* x,char* file,int line);
    37   |
    38   | /* String manipulation functions on private memory heap */
    39   |
    40   | char* CopyString(char* x);
    41   | char* ConcatStrings(int n,char* s, ...);
    42   | void TidyMemory(void);
    43   |
    44   | /* Internal Functions */
    45   |
    46   | void PrintMemoryStatistics(void);
    47   |
    48   | /* Memory handling concepts *
    49   |
    50   |    0) Memory that is private only lasts for the period of parsing the file (including cross-referencing).
    51   |    1) All storage for File, Function etc. data types is to be public (permanent).
    52   |    2) Data used during parsing is to be private.
    53   |    3) Copying of strings is only to be performed if needed, all of the following use the private heap.
    54   |       a) Lex code passes constant values to Yacc code where possible.
    55   |       b) Lex code is to pass copies of strings to Yacc code since it disappears otherwise.
    56   |       c) Yacc code concatanates strings for internal manipulation.
    57   |       d) Lex passes pointers (not copies) to comment.c where private copies are made.
    58   |    4) Comments from comment.c are passed as private data, the receiver must Malloc a copy of them.
    59   |
    60   |  * Memory handling concepts */
    61   |
    62   | #endif