php-src/Zend/zend_alloc.h

135 lines
5.9 KiB
C
Raw Normal View History

1999-04-08 02:10:10 +08:00
/*
+----------------------------------------------------------------------+
| Zend Engine |
+----------------------------------------------------------------------+
2000-03-06 13:26:39 +08:00
| Copyright (c) 1998-2000 Zend Technologies Ltd. (http://www.zend.com) |
1999-04-08 02:10:10 +08:00
+----------------------------------------------------------------------+
2000-03-06 13:26:39 +08:00
| This source file is subject to version 0.92 of the Zend license, |
1999-07-16 22:58:16 +08:00
| that is bundled with this package in the file LICENSE, and is |
| available at through the world-wide-web at |
2000-03-06 13:26:39 +08:00
| http://www.zend.com/license/0_92.txt. |
1999-07-16 22:58:16 +08:00
| If you did not receive a copy of the Zend license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@zend.com so we can mail you a copy immediately. |
1999-04-08 02:10:10 +08:00
+----------------------------------------------------------------------+
| Authors: Andi Gutmans <andi@zend.com> |
| Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
1999-07-16 22:58:16 +08:00
1999-04-08 02:10:10 +08:00
#ifndef _ALLOC_H
#define _ALLOC_H
#include <stdio.h>
1999-09-06 03:03:35 +08:00
#include "zend_globals_macros.h"
1999-04-08 02:10:10 +08:00
#define MEM_BLOCK_START_MAGIC 0x7312F8DCL
#define MEM_BLOCK_END_MAGIC 0x2A8FCC84L
#define MEM_BLOCK_FREED_MAGIC 0x99954317L
#define MEM_BLOCK_CACHED_MAGIC 0xFB8277DCL
1999-12-27 04:45:42 +08:00
typedef struct _zend_mem_header {
1999-04-08 02:10:10 +08:00
#if ZEND_DEBUG
long magic;
char *filename;
uint lineno;
int reported;
1999-08-28 18:18:54 +08:00
char *orig_filename;
uint orig_lineno;
1999-04-08 02:10:10 +08:00
#endif
1999-12-27 04:45:42 +08:00
struct _zend_mem_header *pNext;
struct _zend_mem_header *pLast;
1999-04-08 02:10:10 +08:00
unsigned int size:30;
unsigned int persistent:1;
unsigned int cached:1;
1999-12-27 04:45:42 +08:00
} zend_mem_header;
1999-04-08 02:10:10 +08:00
typedef union _align_test {
1999-04-08 02:10:10 +08:00
void *ptr;
double dbl;
long lng;
} align_test;
#define MAX_CACHED_MEMORY 64
#define MAX_CACHED_ENTRIES 16
#if (defined (__GNUC__) && __GNUC__ >= 2)
2000-01-30 12:49:43 +08:00
#define PLATFORM_ALIGNMENT (__alignof__ (align_test))
#else
1999-04-08 02:10:10 +08:00
#define PLATFORM_ALIGNMENT (sizeof(align_test))
#endif
1999-12-27 04:45:42 +08:00
#define PLATFORM_PADDING (((PLATFORM_ALIGNMENT-sizeof(zend_mem_header))%PLATFORM_ALIGNMENT+PLATFORM_ALIGNMENT)%PLATFORM_ALIGNMENT)
1999-04-08 02:10:10 +08:00
ZEND_API char *zend_strndup(const char *s, unsigned int length);
BEGIN_EXTERN_C()
1999-08-28 18:18:54 +08:00
ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
ZEND_API void _efree(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
ZEND_API void *_ecalloc(size_t nmemb, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
ZEND_API char *_estrdup(const char *s ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
ZEND_API char *_estrndup(const char *s, unsigned int length ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
2000-03-26 03:23:16 +08:00
ZEND_API int _persist_alloc(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
1999-08-28 03:17:19 +08:00
/* Standard wrapper macros */
1999-08-28 18:18:54 +08:00
#define emalloc(size) _emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define efree(ptr) _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define ecalloc(nmemb,size) _ecalloc((nmemb), (size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define erealloc(ptr,size) _erealloc((ptr), (size),0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define erealloc_recoverable(ptr,size) _erealloc((ptr), (size),1 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define estrdup(s) _estrdup((s) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define estrndup(s,length) _estrndup((s), (length) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define persist_alloc(p) _persist_alloc((p) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
1999-08-28 03:17:19 +08:00
/* Relay wrapper macros */
1999-08-28 18:18:54 +08:00
#define emalloc_rel(size) _emalloc((size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define efree_rel(ptr) _efree((ptr) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define ecalloc_rel(nmemb, size) _ecalloc((nmemb), (size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define erealloc_rel(ptr, size) _erealloc((ptr), (size), 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define erealloc_recoverable_rel(ptr, size) _erealloc((ptr), (size), 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define estrdup_rel(s) _estrdup((s) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define estrndup_rel(s, length) _estrndup((s), (length) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define persist_alloc_rel(p) _persist_alloc((p) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
1999-08-28 03:17:19 +08:00
/* Selective persistent/non persistent allocation macros */
1999-04-08 02:10:10 +08:00
#define pemalloc(size,persistent) ((persistent)?malloc(size):emalloc(size))
#define pefree(ptr,persistent) ((persistent)?free(ptr):efree(ptr))
#define pecalloc(nmemb,size,persistent) ((persistent)?calloc((nmemb),(size)):ecalloc((nmemb),(size)))
#define perealloc(ptr,size,persistent) ((persistent)?realloc((ptr),(size)):erealloc((ptr),(size)))
#define perealloc_recoverable(ptr,size,persistent) ((persistent)?realloc((ptr),(size)):erealloc_recoverable((ptr),(size)))
1999-04-08 02:10:10 +08:00
#define pestrdup(s,persistent) ((persistent)?strdup(s):estrdup(s))
#define safe_estrdup(ptr) ((ptr)?(estrdup(ptr)):(empty_string))
#define safe_estrndup(ptr,len) ((ptr)?(estrndup((ptr),(len))):(empty_string))
ZEND_API int zend_set_memory_limit(unsigned int memory_limit);
1999-04-10 22:44:35 +08:00
1999-09-06 03:03:35 +08:00
ZEND_API void start_memory_manager(ALS_D);
1999-04-08 02:10:10 +08:00
ZEND_API void shutdown_memory_manager(int silent, int clean_cache);
#if ZEND_DEBUG
1999-08-28 18:18:54 +08:00
ZEND_API int _mem_block_check(void *ptr, int silent ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
ZEND_API void _full_mem_check(int silent ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
void zend_debug_alloc_output(char *format, ...);
1999-08-28 18:18:54 +08:00
#define mem_block_check(ptr, silent) _mem_block_check(ptr, silent ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define full_mem_check(silent) _full_mem_check(silent ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
1999-04-08 02:10:10 +08:00
#else
#define mem_block_check(type, ptr, silent)
#define full_mem_check(silent)
#endif
END_EXTERN_C()
1999-04-08 02:10:10 +08:00
#endif
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/