xref: /PHP-5.3/Zend/zend_list.h (revision 831fbcf3)
1 /*
2    +----------------------------------------------------------------------+
3    | Zend Engine                                                          |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1998-2013 Zend Technologies Ltd. (http://www.zend.com) |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 2.00 of the Zend license,     |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.zend.com/license/2_00.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 /* $Id$ */
21 
22 #ifndef ZEND_LIST_H
23 #define ZEND_LIST_H
24 
25 #include "zend_hash.h"
26 #include "zend_globals.h"
27 
28 BEGIN_EXTERN_C()
29 
30 #define ZEND_RESOURCE_LIST_TYPE_STD	1
31 #define ZEND_RESOURCE_LIST_TYPE_EX	2
32 
33 typedef struct _zend_rsrc_list_entry {
34 	void *ptr;
35 	int type;
36 	int refcount;
37 } zend_rsrc_list_entry;
38 
39 typedef void (*rsrc_dtor_func_t)(zend_rsrc_list_entry *rsrc TSRMLS_DC);
40 #define ZEND_RSRC_DTOR_FUNC(name)		void name(zend_rsrc_list_entry *rsrc TSRMLS_DC)
41 
42 typedef struct _zend_rsrc_list_dtors_entry {
43 	/* old style destructors */
44 	void (*list_dtor)(void *);
45 	void (*plist_dtor)(void *);
46 
47 	/* new style destructors */
48 	rsrc_dtor_func_t list_dtor_ex;
49 	rsrc_dtor_func_t plist_dtor_ex;
50 
51 	char *type_name;
52 
53 	int module_number;
54 	int resource_id;
55 	unsigned char type;
56 } zend_rsrc_list_dtors_entry;
57 
58 
59 #define register_list_destructors(ld, pld) zend_register_list_destructors((void (*)(void *))ld, (void (*)(void *))pld, module_number);
60 ZEND_API int zend_register_list_destructors(void (*ld)(void *), void (*pld)(void *), int module_number);
61 ZEND_API int zend_register_list_destructors_ex(rsrc_dtor_func_t ld, rsrc_dtor_func_t pld, char *type_name, int module_number);
62 
63 void list_entry_destructor(void *ptr);
64 void plist_entry_destructor(void *ptr);
65 
66 void zend_clean_module_rsrc_dtors(int module_number TSRMLS_DC);
67 int zend_init_rsrc_list(TSRMLS_D);
68 int zend_init_rsrc_plist(TSRMLS_D);
69 void zend_destroy_rsrc_list(HashTable *ht TSRMLS_DC);
70 int zend_init_rsrc_list_dtors(void);
71 void zend_destroy_rsrc_list_dtors(void);
72 
73 ZEND_API int zend_list_insert(void *ptr, int type);
74 ZEND_API int _zend_list_addref(int id TSRMLS_DC);
75 ZEND_API int _zend_list_delete(int id TSRMLS_DC);
76 ZEND_API void *_zend_list_find(int id, int *type TSRMLS_DC);
77 
78 #define zend_list_addref(id)		_zend_list_addref(id TSRMLS_CC)
79 #define zend_list_delete(id)		_zend_list_delete(id TSRMLS_CC)
80 #define zend_list_find(id, type)	_zend_list_find(id, type TSRMLS_CC)
81 
82 ZEND_API int zend_register_resource(zval *rsrc_result, void *rsrc_pointer, int rsrc_type);
83 ZEND_API void *zend_fetch_resource(zval **passed_id TSRMLS_DC, int default_id, char *resource_type_name, int *found_resource_type, int num_resource_types, ...);
84 
85 ZEND_API char *zend_rsrc_list_get_rsrc_type(int resource TSRMLS_DC);
86 ZEND_API int zend_fetch_list_dtor_id(char *type_name);
87 
88 extern ZEND_API int le_index_ptr;  /* list entry type for index pointers */
89 
90 #define ZEND_VERIFY_RESOURCE(rsrc)		\
91 	if (!rsrc) {						\
92 		RETURN_FALSE;					\
93 	}
94 
95 #define ZEND_FETCH_RESOURCE(rsrc, rsrc_type, passed_id, default_id, resource_type_name, resource_type)	\
96 	rsrc = (rsrc_type) zend_fetch_resource(passed_id TSRMLS_CC, default_id, resource_type_name, NULL, 1, resource_type);	\
97 	ZEND_VERIFY_RESOURCE(rsrc);
98 
99 #define ZEND_FETCH_RESOURCE_NO_RETURN(rsrc, rsrc_type, passed_id, default_id, resource_type_name, resource_type)	\
100 	(rsrc = (rsrc_type) zend_fetch_resource(passed_id TSRMLS_CC, default_id, resource_type_name, NULL, 1, resource_type))
101 
102 #define ZEND_FETCH_RESOURCE2(rsrc, rsrc_type, passed_id, default_id, resource_type_name, resource_type1, resource_type2)	\
103 	rsrc = (rsrc_type) zend_fetch_resource(passed_id TSRMLS_CC, default_id, resource_type_name, NULL, 2, resource_type1, resource_type2);	\
104 	ZEND_VERIFY_RESOURCE(rsrc);
105 
106 #define ZEND_FETCH_RESOURCE2_NO_RETURN(rsrc, rsrc_type, passed_id, default_id, resource_type_name, resource_type1, resource_type2)	\
107 	(rsrc = (rsrc_type) zend_fetch_resource(passed_id TSRMLS_CC, default_id, resource_type_name, NULL, 2, resource_type1, resource_type2))
108 
109 #define ZEND_REGISTER_RESOURCE(rsrc_result, rsrc_pointer, rsrc_type)  \
110     zend_register_resource(rsrc_result, rsrc_pointer, rsrc_type);
111 
112 #define ZEND_GET_RESOURCE_TYPE_ID(le_id, le_type_name) \
113     if (le_id == 0) {                                  \
114         le_id = zend_fetch_list_dtor_id(le_type_name); \
115 	}
116 END_EXTERN_C()
117 
118 #endif
119 
120 /*
121  * Local variables:
122  * tab-width: 4
123  * c-basic-offset: 4
124  * indent-tabs-mode: t
125  * End:
126  */
127