home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / contrib / smail / smail-3.1 / smail-3 / smail-3.1.28 / src / alloc.h < prev    next >
C/C++ Source or Header  |  1992-07-11  |  2KB  |  71 lines

  1. /* @(#)src/alloc.h    1.5 7/11/92 11:47:51 */
  2.  
  3. /*
  4.  *    Copyright (C) 1987, 1988 Ronald S. Karr and Landon Curt Noll
  5.  *    Copyright (C) 1992  Ronald S. Karr
  6.  * 
  7.  * See the file COPYING, distributed with smail, for restriction
  8.  * and warranty information.
  9.  */
  10.  
  11. /*
  12.  * alloc.h:
  13.  *    block storage allocation
  14.  *         This allows a given stroage allocation to be associated 
  15.  *        with a group of other storage allocations.  It is
  16.  *        possible to free or test for existence of the class.
  17.  *
  18.  *        A block a pointer to a chain of segments.  Each segment
  19.  *        refers to one storage allocation.  A block also contains
  20.  *        the total number of segments allocated.  If this number is
  21.  *        zero, then no stroage is associated with the block.
  22.  */
  23.  
  24. /*
  25.  * block allocation data structure
  26.  */
  27. struct block {
  28.     struct bseg *next;    /* if cnt > 0 then next holds segment chain */
  29.     int cnt;        /* number of segments in the block */
  30. };
  31. struct bseg {
  32.     struct bseg *next;    /* if != NULL, then next alloc in block */
  33.     char *data;        /* the storage allocated */
  34. };
  35.  
  36. /*
  37.  * handy macros to determine if a block is active
  38.  */
  39. #define is_memory(block_ptr) ((struct block *)(block_ptr)->cnt)
  40. #define is_free(block_ptr) (!(struct block *)(block_ptr)->cnt)
  41.  
  42. /*
  43.  * backward compat macros for pmalloc() - XXX
  44.  */
  45. #define pmalloc(size) (bmalloc((size),perm))
  46. #define prealloc(data,size) (brealloc((data),(size),perm))
  47. #define pfree(data) (bfree((data),perm))
  48.  
  49. /*
  50.  * X_CHECK - check for the xmalloc magic number
  51.  *
  52.  * As a debugging aid, the integer X_MAGIC is stored at the beginning
  53.  * of each block allocated with xmalloc().  This integer is then
  54.  * cleared after a call to xfree().  This macro checks for the magic
  55.  * characters and calls panic if they do not exist.
  56.  */
  57. #define X_MAGIC      ((int)0xe8f987b1)
  58. #define X_CHECK(p)                            \
  59.     (((int*)(p))[-1] != X_MAGIC?                    \
  60.         (write_log(LOG_PANIC,                    \
  61.             "X_CHECK failed!  ptr=0x%lx, line=%d, file=%s", \
  62.             (long)(p), __LINE__, __FILE__),            \
  63.          x_dont_panic?                        \
  64.             FAIL:                        \
  65.             (abort(), 0))                    \
  66.         : SUCCEED)
  67.  
  68. /* use these macros to panic code which should not generate a panic */
  69. #define X_NO_PANIC() (x_dont_panic = TRUE)
  70. #define X_PANIC_OKAY() (x_dont_panic = FALSE)
  71.