home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Magazine / HomeAutomation / Apache / include / php / Zend / zend_alloc.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-22  |  6.0 KB  |  137 lines

  1. /*
  2.    +----------------------------------------------------------------------+
  3.    | Zend Engine                                                          |
  4.    +----------------------------------------------------------------------+
  5.    | Copyright (c) 1998-2000 Zend Technologies Ltd. (http://www.zend.com) |
  6.    +----------------------------------------------------------------------+
  7.    | This source file is subject to version 0.92 of the Zend license,     |
  8.    | that is bundled with this package in the file LICENSE, and is        | 
  9.    | available at through the world-wide-web at                           |
  10.    | http://www.zend.com/license/0_92.txt.                                |
  11.    | If you did not receive a copy of the Zend license and are unable to  |
  12.    | obtain it through the world-wide-web, please send a note to          |
  13.    | license@zend.com so we can mail you a copy immediately.              |
  14.    +----------------------------------------------------------------------+
  15.    | Authors: Andi Gutmans <andi@zend.com>                                |
  16.    |          Zeev Suraski <zeev@zend.com>                                |
  17.    +----------------------------------------------------------------------+
  18. */
  19.  
  20.  
  21. #ifndef _ALLOC_H
  22. #define _ALLOC_H
  23.  
  24. #include <stdio.h>
  25.  
  26. #include "zend_globals_macros.h"
  27.  
  28. #define MEM_BLOCK_START_MAGIC    0x7312F8DCL
  29. #define MEM_BLOCK_END_MAGIC    0x2A8FCC84L
  30. #define MEM_BLOCK_FREED_MAGIC    0x99954317L
  31. #define MEM_BLOCK_CACHED_MAGIC    0xFB8277DCL
  32.  
  33. typedef struct _zend_mem_header {
  34. #if ZEND_DEBUG
  35.     long magic;
  36.     char *filename;
  37.     uint lineno;
  38.     int reported;
  39.     char *orig_filename;
  40.     uint orig_lineno;
  41. #endif
  42.     struct _zend_mem_header *pNext;
  43.     struct _zend_mem_header *pLast;
  44.     unsigned int size:30;
  45.     unsigned int persistent:1;
  46.     unsigned int cached:1;
  47. } zend_mem_header;
  48.  
  49. typedef union _align_test {
  50.     void *ptr;
  51.     double dbl;
  52.     long lng;
  53. } align_test;
  54.  
  55. #define MAX_CACHED_MEMORY    11
  56. #define MAX_CACHED_ENTRIES    256
  57. #define PRE_INIT_CACHE_ENTRIES    32
  58.  
  59. #if (defined (__GNUC__) && __GNUC__ >= 2)
  60. #define PLATFORM_ALIGNMENT (__alignof__ (align_test))
  61. #else
  62. #define PLATFORM_ALIGNMENT (sizeof(align_test))
  63. #endif
  64.  
  65. #define PLATFORM_PADDING (((PLATFORM_ALIGNMENT-sizeof(zend_mem_header))%PLATFORM_ALIGNMENT+PLATFORM_ALIGNMENT)%PLATFORM_ALIGNMENT)
  66.  
  67. ZEND_API char *zend_strndup(const char *s, unsigned int length);
  68.  
  69. BEGIN_EXTERN_C()
  70.  
  71. ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
  72. ZEND_API void _efree(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
  73. ZEND_API void *_ecalloc(size_t nmemb, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
  74. ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
  75. ZEND_API char *_estrdup(const char *s ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
  76. ZEND_API char *_estrndup(const char *s, unsigned int length ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
  77. ZEND_API int _persist_alloc(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
  78.  
  79. /* Standard wrapper macros */
  80. #define emalloc(size)                    _emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  81. #define efree(ptr)                        _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  82. #define ecalloc(nmemb,size)                _ecalloc((nmemb), (size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  83. #define erealloc(ptr,size)                _erealloc((ptr), (size),0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  84. #define erealloc_recoverable(ptr,size)    _erealloc((ptr), (size),1 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  85. #define estrdup(s)                        _estrdup((s) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  86. #define estrndup(s,length)                _estrndup((s), (length) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  87. #define persist_alloc(p)                _persist_alloc((p) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  88.  
  89. /* Relay wrapper macros */
  90. #define emalloc_rel(size)                    _emalloc((size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
  91. #define efree_rel(ptr)                        _efree((ptr) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
  92. #define ecalloc_rel(nmemb, size)            _ecalloc((nmemb), (size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
  93. #define erealloc_rel(ptr, size)                _erealloc((ptr), (size), 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
  94. #define erealloc_recoverable_rel(ptr, size)    _erealloc((ptr), (size), 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
  95. #define estrdup_rel(s)                        _estrdup((s) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
  96. #define estrndup_rel(s, length)                _estrndup((s), (length) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
  97. #define persist_alloc_rel(p)                _persist_alloc((p) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
  98.  
  99. /* Selective persistent/non persistent allocation macros */
  100. #define pemalloc(size,persistent) ((persistent)?malloc(size):emalloc(size))
  101. #define pefree(ptr,persistent)  ((persistent)?free(ptr):efree(ptr))
  102. #define pecalloc(nmemb,size,persistent) ((persistent)?calloc((nmemb),(size)):ecalloc((nmemb),(size)))
  103. #define perealloc(ptr,size,persistent) ((persistent)?realloc((ptr),(size)):erealloc((ptr),(size)))
  104. #define perealloc_recoverable(ptr,size,persistent) ((persistent)?realloc((ptr),(size)):erealloc_recoverable((ptr),(size)))
  105. #define pestrdup(s,persistent) ((persistent)?strdup(s):estrdup(s))
  106.  
  107. #define safe_estrdup(ptr)  ((ptr)?(estrdup(ptr)):(empty_string))
  108. #define safe_estrndup(ptr,len) ((ptr)?(estrndup((ptr),(len))):(empty_string))
  109.  
  110. ZEND_API int zend_set_memory_limit(unsigned int memory_limit);
  111.  
  112. ZEND_API void start_memory_manager(ALS_D);
  113. ZEND_API void shutdown_memory_manager(int silent, int clean_cache);
  114.  
  115. #if ZEND_DEBUG
  116. ZEND_API int _mem_block_check(void *ptr, int silent ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
  117. ZEND_API void _full_mem_check(int silent ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
  118. void zend_debug_alloc_output(char *format, ...);
  119. #define mem_block_check(ptr, silent) _mem_block_check(ptr, silent ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  120. #define full_mem_check(silent) _full_mem_check(silent ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  121. #else
  122. #define mem_block_check(type, ptr, silent)
  123. #define full_mem_check(silent)
  124. #endif
  125.  
  126.  
  127. END_EXTERN_C()
  128.  
  129. #endif
  130.  
  131. /*
  132.  * Local variables:
  133.  * tab-width: 4
  134.  * c-basic-offset: 4
  135.  * End:
  136.  */
  137.