"Fossies" - the Fresh Open Source Software Archive

Member "xpdf-4.02/goo/gmem.h" (25 Sep 2019, 2098 Bytes) of package /linux/misc/xpdf-4.02.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "gmem.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 4.01.01_vs_4.02.

    1 /*
    2  * gmem.h
    3  *
    4  * Memory routines with out-of-memory checking.
    5  *
    6  * Copyright 1996-2003 Glyph & Cog, LLC
    7  */
    8 
    9 #ifndef GMEM_H
   10 #define GMEM_H
   11 
   12 #include <stdio.h>
   13 #include <aconf.h>
   14 
   15 #if USE_EXCEPTIONS
   16 
   17 class GMemException {
   18 public:
   19   GMemException() {}
   20   ~GMemException() {}
   21 };
   22 
   23 // This used to be:
   24 //   #define GMEM_EXCEP throw(GMemException)
   25 // but the throw decl was never really very useful, and is deprecated
   26 // as of C++11 and illegal as of C++17.
   27 #define GMEM_EXCEP
   28 
   29 #else // USE_EXCEPTIONS
   30 
   31 #define GMEM_EXCEP
   32 
   33 #endif // USE_EXCEPTIONS
   34 
   35 #ifdef __cplusplus
   36 extern "C" {
   37 #endif
   38 
   39 /*
   40  * Same as malloc, but prints error message and exits if malloc()
   41  * returns NULL.
   42  */
   43 #ifdef DEBUG_MEM
   44 extern void *gmalloc(int size, int ignore = 0) GMEM_EXCEP;
   45 #else
   46 extern void *gmalloc(int size) GMEM_EXCEP;
   47 #endif
   48 
   49 /*
   50  * Same as realloc, but prints error message and exits if realloc()
   51  * returns NULL.  If <p> is NULL, calls malloc instead of realloc().
   52  */
   53 extern void *grealloc(void *p, int size) GMEM_EXCEP;
   54 
   55 /*
   56  * These are similar to gmalloc and grealloc, but take an object count
   57  * and size.  The result is similar to allocating nObjs * objSize
   58  * bytes, but there is an additional error check that the total size
   59  * doesn't overflow an int.
   60  */
   61 extern void *gmallocn(int nObjs, int objSize) GMEM_EXCEP;
   62 extern void *greallocn(void *p, int nObjs, int objSize) GMEM_EXCEP;
   63 
   64 /*
   65  * Same as gmalloc and gmallocn, but allow a 64-bit size on 64-bit
   66  * systems.
   67  */
   68 #ifdef DEBUG_MEM
   69 extern void *gmalloc64(size_t size, int ignore = 0) GMEM_EXCEP;
   70 #else
   71 extern void *gmalloc64(size_t size) GMEM_EXCEP;
   72 #endif
   73 extern void *gmallocn64(int nObjs, size_t objSize) GMEM_EXCEP;
   74 
   75 /*
   76  * Same as free, but checks for and ignores NULL pointers.
   77  */
   78 extern void gfree(void *p);
   79 
   80 /*
   81  * Report a memory error.
   82  */
   83 extern void gMemError(const char *msg) GMEM_EXCEP;
   84 
   85 #ifdef DEBUG_MEM
   86 /*
   87  * Report on unfreed memory.
   88  */
   89 extern void gMemReport(FILE *f);
   90 #else
   91 #define gMemReport(f)
   92 #endif
   93 
   94 /*
   95  * Allocate memory and copy a string into it.
   96  */
   97 extern char *copyString(const char *s);
   98 
   99 #ifdef __cplusplus
  100 }
  101 #endif
  102 
  103 #endif