zend_API.h revision b982307d
1573b4602SAndi Gutmans/*
2573b4602SAndi Gutmans   +----------------------------------------------------------------------+
3573b4602SAndi Gutmans   | Zend Engine                                                          |
4573b4602SAndi Gutmans   +----------------------------------------------------------------------+
55e55e47fSZeev Suraski   | Copyright (c) 1998-2000 Zend Technologies Ltd. (http://www.zend.com) |
6573b4602SAndi Gutmans   +----------------------------------------------------------------------+
75e55e47fSZeev Suraski   | This source file is subject to version 0.92 of the Zend license,     |
8b5b11177SZeev Suraski   | that is bundled with this package in the file LICENSE, and is        |
9b5b11177SZeev Suraski   | available at through the world-wide-web at                           |
105e55e47fSZeev Suraski   | http://www.zend.com/license/0_92.txt.                                |
11b5b11177SZeev Suraski   | If you did not receive a copy of the Zend license and are unable to  |
12b5b11177SZeev Suraski   | obtain it through the world-wide-web, please send a note to          |
13b5b11177SZeev Suraski   | license@zend.com so we can mail you a copy immediately.              |
14573b4602SAndi Gutmans   +----------------------------------------------------------------------+
15573b4602SAndi Gutmans   | Authors: Andi Gutmans <andi@zend.com>                                |
16573b4602SAndi Gutmans   |          Zeev Suraski <zeev@zend.com>                                |
17573b4602SAndi Gutmans   +----------------------------------------------------------------------+
18573b4602SAndi Gutmans*/
19573b4602SAndi Gutmans
20b5b11177SZeev Suraski
21b982307dSSascha Schumann#ifndef ZEND_API_H
22b982307dSSascha Schumann#define ZEND_API_H
23573b4602SAndi Gutmans
24573b4602SAndi Gutmans#include "modules.h"
25573b4602SAndi Gutmans#include "zend_list.h"
26b7a5b3c3SZeev Suraski#include "zend_fast_cache.h"
275dba4774SZeev Suraski#include "zend_operators.h"
285dba4774SZeev Suraski#include "zend_variables.h"
29df74f1dfSSascha Schumann#include "zend_execute.h"
30573b4602SAndi Gutmans
31e9d126a7SAndi Gutmans#define ZEND_FN(name) zend_if_##name
32342c6e0bSZeev Suraski#define ZEND_NAMED_FUNCTION(name) void name(INTERNAL_FUNCTION_PARAMETERS)
33e9d126a7SAndi Gutmans#define ZEND_FUNCTION(name) ZEND_NAMED_FUNCTION(ZEND_FN(name))
34e9d126a7SAndi Gutmans
35e9d126a7SAndi Gutmans#define ZEND_NAMED_FE(zend_name, name, arg_types) { #zend_name, name, arg_types },
36e9d126a7SAndi Gutmans#define ZEND_FE(name, arg_types) ZEND_NAMED_FE(name, ZEND_FN(name), arg_types)
37e9d126a7SAndi Gutmans#define ZEND_FALIAS(name, alias, arg_types) ZEND_NAMED_FE(name, ZEND_FN(alias), arg_types)
38342c6e0bSZeev Suraski
39e9d126a7SAndi Gutmans#define ZEND_MINIT(module)       zend_minit_##module
40e9d126a7SAndi Gutmans#define ZEND_MSHUTDOWN(module)   zend_mshutdown_##module
41e9d126a7SAndi Gutmans#define ZEND_RINIT(module)       zend_rinit_##module
42e9d126a7SAndi Gutmans#define ZEND_RSHUTDOWN(module)   zend_rshutdown_##module
43e9d126a7SAndi Gutmans#define ZEND_MINFO(module)       zend_info_##module
44e9d126a7SAndi Gutmans#define ZEND_GINIT(module)       zend_ginit_##module
45e9d126a7SAndi Gutmans#define ZEND_GSHUTDOWN(module)   zend_gshutdown_##module
46342c6e0bSZeev Suraski
47e9d126a7SAndi Gutmans#define ZEND_MINIT_FUNCTION(module)      int ZEND_MINIT(module)(INIT_FUNC_ARGS)
48e9d126a7SAndi Gutmans#define ZEND_MSHUTDOWN_FUNCTION(module)  int ZEND_MSHUTDOWN(module)(SHUTDOWN_FUNC_ARGS)
49e9d126a7SAndi Gutmans#define ZEND_RINIT_FUNCTION(module)      int ZEND_RINIT(module)(INIT_FUNC_ARGS)
50e9d126a7SAndi Gutmans#define ZEND_RSHUTDOWN_FUNCTION(module)  int ZEND_RSHUTDOWN(module)(SHUTDOWN_FUNC_ARGS)
51e9d126a7SAndi Gutmans#define ZEND_MINFO_FUNCTION(module)      void ZEND_MINFO(module)(ZEND_MODULE_INFO_FUNC_ARGS)
52e9d126a7SAndi Gutmans#define ZEND_GINIT_FUNCTION(module)      int ZEND_GINIT(module)(GINIT_FUNC_ARGS)
53e9d126a7SAndi Gutmans#define ZEND_GSHUTDOWN_FUNCTION(module)  int ZEND_GSHUTDOWN(module)(void)
54342c6e0bSZeev Suraski
550b6d923bSSascha Schumann#define ZEND_GET_MODULE(name) \
560b6d923bSSascha Schumann	ZEND_DLEXPORT zend_module_entry *get_module(void) { return &name##_module_entry; }
570d21940dSZeev Suraski
580d21940dSZeev Suraski#define ZEND_BEGIN_MODULE_GLOBALS(module_name)		\
590d21940dSZeev Suraski	typedef struct _zend_##module_name##_globals {
600d21940dSZeev Suraski#define ZEND_END_MODULE_GLOBALS(module_name)		\
610d21940dSZeev Suraski	} zend_##module_name##_globals;
620d21940dSZeev Suraski
630d21940dSZeev Suraski#ifdef ZTS
640d21940dSZeev Suraski
650d21940dSZeev Suraski#define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
660d21940dSZeev Suraski	static ts_rsrc_id module_name##_globals_id;
670d21940dSZeev Suraski#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
680d21940dSZeev Suraski	module_name##_globals_id = ts_allocate_id(sizeof(zend_##module_name##_globals), (ts_allocate_ctor) globals_ctor, (ts_allocate_dtor) globals_dtor);
690d21940dSZeev Suraski
700d21940dSZeev Suraski#else
710d21940dSZeev Suraski
720d21940dSZeev Suraski#define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
730d21940dSZeev Suraski	static zend_##module_name##_globals module_name##_globals;
740d21940dSZeev Suraski#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
750d21940dSZeev Suraski	globals_ctor(&module_name##_globals);
760d21940dSZeev Suraski
770d21940dSZeev Suraski#endif
780d21940dSZeev Suraski
790d21940dSZeev Suraski
800d21940dSZeev Suraski
81741b8161SZeev Suraski#define INIT_CLASS_ENTRY(class_container, class_name, functions)	\
82741b8161SZeev Suraski	{																\
83741b8161SZeev Suraski		class_container.name = strdup(class_name);					\
84741b8161SZeev Suraski		class_container.name_length = sizeof(class_name)-1;			\
85741b8161SZeev Suraski		class_container.builtin_functions = functions;				\
86741b8161SZeev Suraski		class_container.handle_function_call = NULL;				\
87741b8161SZeev Suraski		class_container.handle_property_get = NULL;					\
88741b8161SZeev Suraski		class_container.handle_property_set = NULL;					\
89741b8161SZeev Suraski	}
90741b8161SZeev Suraski
91741b8161SZeev Suraski#define INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset) \
92741b8161SZeev Suraski	{															\
93741b8161SZeev Suraski		class_container.name = strdup(class_name);				\
94741b8161SZeev Suraski		class_container.name_length = sizeof(class_name)-1;		\
95741b8161SZeev Suraski		class_container.builtin_functions = functions;			\
96741b8161SZeev Suraski		class_container.handle_function_call = handle_fcall;	\
97741b8161SZeev Suraski		class_container.handle_property_get = handle_propget;	\
98741b8161SZeev Suraski		class_container.handle_property_set = handle_propset;	\
99741b8161SZeev Suraski	}
100741b8161SZeev Suraski
101741b8161SZeev Suraski
102741b8161SZeev Suraski
103573b4602SAndi Gutmansint zend_next_free_module(void);
104573b4602SAndi Gutmans
105f77e6a44SZeev SuraskiZEND_API int zend_get_parameters(int ht, int param_count, ...);
106cd7d5546SZeev SuraskiZEND_API int zend_get_parameters_array(int ht, int param_count, zval **argument_array);
107f77e6a44SZeev SuraskiZEND_API int zend_get_parameters_ex(int param_count, ...);
108cd7d5546SZeev SuraskiZEND_API int zend_get_parameters_array_ex(int param_count, zval ***argument_array);
10939f9487eSAndi Gutmans
1109deab411SAndi GutmansZEND_API int ParameterPassedByReference(int ht, uint n);
11139f9487eSAndi Gutmans
112fce92e3cSZeev Suraskiint zend_register_functions(zend_function_entry *functions, HashTable *function_table, int type);
113741b8161SZeev Suraskivoid zend_unregister_functions(zend_function_entry *functions, int count, HashTable *function_table);
1147a87fcbbSZeev SuraskiZEND_API int zend_register_module(zend_module_entry *module_entry);
115eb0e6946SAndi Gutmans
1166ce07a85SAndi GutmansZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry);
117eb0e6946SAndi GutmansZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce, char *parent_name);
118eb0e6946SAndi Gutmans
119bfbe8618SZeev SuraskiZEND_API zend_module_entry *zend_get_module(int module_number);
120bc7abb33SZeev SuraskiZEND_API int zend_disable_function(char *function_name, uint function_name_length);
121573b4602SAndi Gutmans
122573b4602SAndi GutmansZEND_API void wrong_param_count(void);
123573b4602SAndi Gutmans
124741b8161SZeev Suraski#define getThis() (this_ptr)
125741b8161SZeev Suraski
126131d9cb2SZeev Suraski#define WRONG_PARAM_COUNT					ZEND_WRONG_PARAM_COUNT()
127131d9cb2SZeev Suraski#define WRONG_PARAM_COUNT_WITH_RETVAL(ret)	ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)
128a1ad2872SZeev Suraski#define ARG_COUNT(dummy)	(ht)
129a1ad2872SZeev Suraski#define ZEND_NUM_ARGS()		(ht)
130131d9cb2SZeev Suraski#define ZEND_WRONG_PARAM_COUNT()					{ wrong_param_count(); return; }
131131d9cb2SZeev Suraski#define ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)		{ wrong_param_count(); return ret; }
132573b4602SAndi Gutmans
13380bdd19eSZeev Suraski#ifndef ZEND_WIN32
134573b4602SAndi Gutmans#define DLEXPORT
135573b4602SAndi Gutmans#endif
136573b4602SAndi Gutmans
137e0628436SAndrei ZmievskiZEND_API int zend_startup_module(zend_module_entry *module);
138573b4602SAndi Gutmans
139ceba50b6SZeev Suraski#define array_init(arg)			_array_init((arg) ZEND_FILE_LINE_CC)
140ceba50b6SZeev Suraski#define object_init(arg)		_object_init((arg) ZEND_FILE_LINE_CC)
141ceba50b6SZeev Suraski#define object_init_ex(arg, ce)	_object_init_ex((arg), (ce) ZEND_FILE_LINE_CC)
142ceba50b6SZeev SuraskiZEND_API int _array_init(zval *arg ZEND_FILE_LINE_DC);
143ceba50b6SZeev SuraskiZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC);
144ceba50b6SZeev SuraskiZEND_API int _object_init_ex(zval *arg, zend_class_entry *ce ZEND_FILE_LINE_DC);
1456847fefaSThies C. Arntzen
1466847fefaSThies C. Arntzen/* no longer supported */
1476847fefaSThies C. ArntzenZEND_API int add_assoc_function(zval *arg, char *key,void (*function_ptr)(INTERNAL_FUNCTION_PARAMETERS));
1486847fefaSThies C. Arntzen
149573b4602SAndi GutmansZEND_API int add_assoc_long(zval *arg, char *key, long n);
150f2d703e9SZeev SuraskiZEND_API int add_assoc_unset(zval *arg, char *key);
1516847fefaSThies C. ArntzenZEND_API int add_assoc_bool(zval *arg, char *key, int b);
1526847fefaSThies C. ArntzenZEND_API int add_assoc_resource(zval *arg, char *key, int r);
153573b4602SAndi GutmansZEND_API int add_assoc_double(zval *arg, char *key, double d);
154573b4602SAndi GutmansZEND_API int add_assoc_string(zval *arg, char *key, char *str, int duplicate);
155573b4602SAndi GutmansZEND_API int add_assoc_stringl(zval *arg, char *key, char *str, uint length, int duplicate);
1566847fefaSThies C. Arntzen
157573b4602SAndi GutmansZEND_API int add_index_long(zval *arg, uint idx, long n);
158f2d703e9SZeev SuraskiZEND_API int add_index_unset(zval *arg, uint idx);
1596847fefaSThies C. ArntzenZEND_API int add_index_bool(zval *arg, uint idx, int b);
1606847fefaSThies C. ArntzenZEND_API int add_index_resource(zval *arg, uint idx, int r);
161573b4602SAndi GutmansZEND_API int add_index_double(zval *arg, uint idx, double d);
162573b4602SAndi GutmansZEND_API int add_index_string(zval *arg, uint idx, char *str, int duplicate);
163573b4602SAndi GutmansZEND_API int add_index_stringl(zval *arg, uint idx, char *str, uint length, int duplicate);
1646847fefaSThies C. Arntzen
165573b4602SAndi GutmansZEND_API int add_next_index_long(zval *arg, long n);
166f2d703e9SZeev SuraskiZEND_API int add_next_index_unset(zval *arg);
1676847fefaSThies C. ArntzenZEND_API int add_next_index_bool(zval *arg, int b);
1686847fefaSThies C. ArntzenZEND_API int add_next_index_resource(zval *arg, int r);
169573b4602SAndi GutmansZEND_API int add_next_index_double(zval *arg, double d);
170573b4602SAndi GutmansZEND_API int add_next_index_string(zval *arg, char *str, int duplicate);
171573b4602SAndi GutmansZEND_API int add_next_index_stringl(zval *arg, char *str, uint length, int duplicate);
172573b4602SAndi Gutmans
173573b4602SAndi GutmansZEND_API int add_get_index_long(zval *arg, uint idx, long l, void **dest);
174573b4602SAndi GutmansZEND_API int add_get_index_double(zval *arg, uint idx, double d, void **dest);
1756847fefaSThies C. ArntzenZEND_API int add_get_assoc_string(zval *arg, char *key, char *str, void **dest, int duplicate);
1766847fefaSThies C. ArntzenZEND_API int add_get_assoc_stringl(zval *arg, char *key, char *str, uint length, void **dest, int duplicate);
177573b4602SAndi GutmansZEND_API int add_get_index_string(zval *arg, uint idx, char *str, void **dest, int duplicate);
178573b4602SAndi GutmansZEND_API int add_get_index_stringl(zval *arg, uint idx, char *str, uint length, void **dest, int duplicate);
179573b4602SAndi Gutmans
180223c674cSZeev SuraskiZEND_API int call_user_function(HashTable *function_table, zval *object, zval *function_name, zval *retval_ptr, int param_count, zval *params[]);
1813cda6a75SZeev SuraskiZEND_API int call_user_function_ex(HashTable *function_table, zval *object, zval *function_name, zval **retval_ptr_ptr, int param_count, zval **params[], int no_separation, HashTable *symbol_table);
182573b4602SAndi Gutmans
183573b4602SAndi GutmansZEND_API int add_property_long(zval *arg, char *key, long l);
184b995d2ccSAndrei ZmievskiZEND_API int add_property_unset(zval *arg, char *key);
185b995d2ccSAndrei ZmievskiZEND_API int add_property_bool(zval *arg, char *key, int b);
186446e5d0fSThies C. ArntzenZEND_API int add_property_resource(zval *arg, char *key, long r);
187573b4602SAndi GutmansZEND_API int add_property_double(zval *arg, char *key, double d);
188573b4602SAndi GutmansZEND_API int add_property_string(zval *arg, char *key, char *str, int duplicate);
189573b4602SAndi GutmansZEND_API int add_property_stringl(zval *arg, char *key, char *str, uint length, int duplicate);
190573b4602SAndi Gutmans
191f962a35dSAndrei ZmievskiZEND_API int zend_set_hash_symbol(zval *symbol, char *name, int name_length,
192f962a35dSAndrei Zmievski                                  int is_ref, int num_symbol_tables, ...);
193f962a35dSAndrei Zmievski
194573b4602SAndi Gutmans#define add_method(arg,key,method)	add_assoc_function((arg),(key),(method))
195573b4602SAndi Gutmans
196af22085cSThies C. Arntzen#define ZVAL_RESOURCE(z,l) {			\
197af22085cSThies C. Arntzen		(z)->type = IS_RESOURCE;        \
198af22085cSThies C. Arntzen		(z)->value.lval = l;	        \
199af22085cSThies C. Arntzen	}
200af22085cSThies C. Arntzen#define ZVAL_BOOL(z,b) {				\
201af22085cSThies C. Arntzen		(z)->type = IS_BOOL;	        \
202af22085cSThies C. Arntzen		(z)->value.lval = b;	        \
203af22085cSThies C. Arntzen	}
204af22085cSThies C. Arntzen#define ZVAL_NULL(z) {					\
205af22085cSThies C. Arntzen		(z)->type = IS_NULL;	        \
206af22085cSThies C. Arntzen	}
207af22085cSThies C. Arntzen#define ZVAL_LONG(z,l) {				\
208af22085cSThies C. Arntzen		(z)->type = IS_LONG;	        \
209af22085cSThies C. Arntzen		(z)->value.lval = l;	        \
210af22085cSThies C. Arntzen	}
211af22085cSThies C. Arntzen#define ZVAL_DOUBLE(z,d) {				\
212af22085cSThies C. Arntzen		(z)->type = IS_DOUBLE;	        \
213af22085cSThies C. Arntzen		(z)->value.dval = d;	        \
214af22085cSThies C. Arntzen	}
215af22085cSThies C. Arntzen#define ZVAL_STRING(z,s,duplicate) {	\
216af22085cSThies C. Arntzen		char *__s=(s);					\
217af22085cSThies C. Arntzen		(z)->value.str.len = strlen(__s);	\
218af22085cSThies C. Arntzen		(z)->value.str.val = (duplicate?estrndup(__s,(z)->value.str.len):__s);	\
219af22085cSThies C. Arntzen		(z)->type = IS_STRING;	        \
220af22085cSThies C. Arntzen	}
221af22085cSThies C. Arntzen#define ZVAL_STRINGL(z,s,l,duplicate) {	\
222af22085cSThies C. Arntzen		char *__s=(s); int __l=l;		\
223af22085cSThies C. Arntzen		(z)->value.str.len = __l;	    \
224af22085cSThies C. Arntzen		(z)->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
225af22085cSThies C. Arntzen		(z)->type = IS_STRING;		    \
226af22085cSThies C. Arntzen	}
227af22085cSThies C. Arntzen
228af22085cSThies C. Arntzen#define ZVAL_EMPTY_STRING(z) {	        \
229af22085cSThies C. Arntzen		(z)->value.str.len = 0;  	    \
230af22085cSThies C. Arntzen		(z)->value.str.val = empty_string \
231af22085cSThies C. Arntzen		(z)->type = IS_STRING;		    \
232af22085cSThies C. Arntzen	}
233af22085cSThies C. Arntzen
234af22085cSThies C. Arntzen#define ZVAL_FALSE  { (z)->value.lval = 0;  (z)->type = IS_BOOL; }
235af22085cSThies C. Arntzen#define ZVAL_TRUE   { (z)->value.lval = 1;  (z)->type = IS_BOOL; }
236af22085cSThies C. Arntzen
237eb5c6da5SThies C. Arntzen#define RETVAL_RESOURCE(l) {			\
238eb5c6da5SThies C. Arntzen		return_value->type = IS_RESOURCE;\
239eb5c6da5SThies C. Arntzen		return_value->value.lval = l;	\
240eb5c6da5SThies C. Arntzen	}
2411fe57c95SZeev Suraski#define RETVAL_BOOL(b) {				\
2421fe57c95SZeev Suraski		return_value->type = IS_BOOL;	\
2431fe57c95SZeev Suraski		return_value->value.lval = b;	\
2441fe57c95SZeev Suraski	}
245fb6a1b8bSThies C. Arntzen#define RETVAL_NULL() {					\
246bdefd5daSAndi Gutmans		return_value->type = IS_NULL;	\
247f2d703e9SZeev Suraski	}
2481f985edeSZeev Suraski#define RETVAL_LONG(l) {				\
2491f985edeSZeev Suraski		return_value->type = IS_LONG;	\
2501f985edeSZeev Suraski		return_value->value.lval = l;	\
2511f985edeSZeev Suraski	}
2521f985edeSZeev Suraski#define RETVAL_DOUBLE(d) {				\
2531f985edeSZeev Suraski		return_value->type = IS_DOUBLE;	\
2541f985edeSZeev Suraski		return_value->value.dval = d;	\
2551f985edeSZeev Suraski	}
2561f985edeSZeev Suraski#define RETVAL_STRING(s,duplicate) {	\
2571f985edeSZeev Suraski		char *__s=(s);					\
2581f985edeSZeev Suraski		return_value->value.str.len = strlen(__s);	\
2591f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,return_value->value.str.len):__s);	\
2601f985edeSZeev Suraski		return_value->type = IS_STRING;	\
2611f985edeSZeev Suraski	}
2621f985edeSZeev Suraski#define RETVAL_STRINGL(s,l,duplicate) {		\
2631f985edeSZeev Suraski		char *__s=(s); int __l=l;			\
2641f985edeSZeev Suraski		return_value->value.str.len = __l;	\
2651f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
2661f985edeSZeev Suraski		return_value->type = IS_STRING;		\
2671f985edeSZeev Suraski	}
2681f985edeSZeev Suraski
269af22085cSThies C. Arntzen#define RETVAL_EMPTY_STRING() {	            \
270af22085cSThies C. Arntzen		return_value->value.str.len = 0;  	\
271af22085cSThies C. Arntzen		return_value->value.str.val = empty_string \
272af22085cSThies C. Arntzen		return_value->type = IS_STRING;		\
273af22085cSThies C. Arntzen	}
274af22085cSThies C. Arntzen
2751f985edeSZeev Suraski#define RETVAL_FALSE  { return_value->value.lval = 0;  return_value->type = IS_BOOL; }
2761f985edeSZeev Suraski#define RETVAL_TRUE   { return_value->value.lval = 1;  return_value->type = IS_BOOL; }
2771f985edeSZeev Suraski
278eb5c6da5SThies C. Arntzen#define RETURN_RESOURCE(l) {			\
279eb5c6da5SThies C. Arntzen		return_value->type = IS_RESOURCE;\
280eb5c6da5SThies C. Arntzen		return_value->value.lval = l;	\
281eb5c6da5SThies C. Arntzen		return;							\
282eb5c6da5SThies C. Arntzen	}
2831fe57c95SZeev Suraski
2841fe57c95SZeev Suraski#define RETURN_BOOL(b) {				\
2851fe57c95SZeev Suraski		return_value->type = IS_BOOL;	\
2861fe57c95SZeev Suraski		return_value->value.lval = b;	\
2871fe57c95SZeev Suraski		return;							\
2881fe57c95SZeev Suraski	}
2891fe57c95SZeev Suraski
290fb6a1b8bSThies C. Arntzen#define RETURN_NULL() {				\
291bdefd5daSAndi Gutmans		return_value->type = IS_NULL;	\
292f2d703e9SZeev Suraski		return;							\
293f2d703e9SZeev Suraski	}
294f2d703e9SZeev Suraski
2951f985edeSZeev Suraski#define RETURN_LONG(l) {				\
2961f985edeSZeev Suraski		return_value->type = IS_LONG;	\
2971f985edeSZeev Suraski		return_value->value.lval = l;	\
2981f985edeSZeev Suraski		return;							\
2991f985edeSZeev Suraski	}
3001f985edeSZeev Suraski#define RETURN_DOUBLE(d) {				\
3011f985edeSZeev Suraski		return_value->type = IS_DOUBLE;	\
3021f985edeSZeev Suraski		return_value->value.dval = d;	\
3031f985edeSZeev Suraski		return;							\
3041f985edeSZeev Suraski	}
3051f985edeSZeev Suraski#define RETURN_STRING(s,duplicate) {	\
3061f985edeSZeev Suraski		char *__s=(s);					\
3071f985edeSZeev Suraski		return_value->value.str.len = strlen(__s);	\
3081f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,return_value->value.str.len):__s);	\
3091f985edeSZeev Suraski		return_value->type = IS_STRING;	\
3101f985edeSZeev Suraski		return;							\
3111f985edeSZeev Suraski	}
3121f985edeSZeev Suraski#define RETURN_STRINGL(s,l,duplicate) {		\
3131f985edeSZeev Suraski		char *__s=(s); int __l=l;			\
3141f985edeSZeev Suraski		return_value->value.str.len = __l;	\
3151f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
3161f985edeSZeev Suraski      	return_value->type = IS_STRING;		\
3171f985edeSZeev Suraski		return;								\
3181f985edeSZeev Suraski	}
3191f985edeSZeev Suraski
320af22085cSThies C. Arntzen#define RETURN_EMPTY_STRING() {	            \
321af22085cSThies C. Arntzen		return_value->value.str.len = 0;  	\
322af22085cSThies C. Arntzen		return_value->value.str.val = empty_string \
323af22085cSThies C. Arntzen		return_value->type = IS_STRING;		\
324af22085cSThies C. Arntzen        return;                             \
325af22085cSThies C. Arntzen	}
326af22085cSThies C. Arntzen
3271f985edeSZeev Suraski#define RETURN_FALSE  { RETVAL_FALSE; return; }
3281f985edeSZeev Suraski#define RETURN_TRUE   { RETVAL_TRUE; return; }
3291f985edeSZeev Suraski
33048ffdd79SZeev Suraski#define SET_VAR_STRING(n,v)	{																				\
33148ffdd79SZeev Suraski								{																			\
332235386b2SZeev Suraski									zval *var;																\
33348ffdd79SZeev Suraski									char *str=(v); /* prevent 'v' from being evaluated more than once */	\
33448ffdd79SZeev Suraski																											\
335235386b2SZeev Suraski									ALLOC_ZVAL(var);														\
33648ffdd79SZeev Suraski									var->value.str.val = (str);												\
33748ffdd79SZeev Suraski									var->value.str.len = strlen((str));										\
33848ffdd79SZeev Suraski									var->type = IS_STRING;													\
3396393ab14SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);											\
34048ffdd79SZeev Suraski								}																			\
3411f985edeSZeev Suraski							}
34248ffdd79SZeev Suraski
34348ffdd79SZeev Suraski#define SET_VAR_STRINGL(n,v,l)	{														\
34448ffdd79SZeev Suraski									{													\
345235386b2SZeev Suraski										zval *var;										\
34648ffdd79SZeev Suraski																						\
347235386b2SZeev Suraski										ALLOC_ZVAL(var);								\
34848ffdd79SZeev Suraski										var->value.str.val = (v);						\
34948ffdd79SZeev Suraski										var->value.str.len = (l);						\
35048ffdd79SZeev Suraski										var->type = IS_STRING;							\
35148ffdd79SZeev Suraski										ZEND_SET_GLOBAL_VAR(n, var);					\
35248ffdd79SZeev Suraski									}													\
3531f985edeSZeev Suraski								}
35448ffdd79SZeev Suraski
35548ffdd79SZeev Suraski#define SET_VAR_LONG(n,v)	{															\
35648ffdd79SZeev Suraski								{														\
357235386b2SZeev Suraski									zval *var;											\
35848ffdd79SZeev Suraski																						\
359235386b2SZeev Suraski									ALLOC_ZVAL(var);									\
36048ffdd79SZeev Suraski									var->value.lval = (v);								\
36148ffdd79SZeev Suraski									var->type = IS_LONG;								\
36248ffdd79SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);						\
36348ffdd79SZeev Suraski								}														\
3641f985edeSZeev Suraski							}
36548ffdd79SZeev Suraski
36648ffdd79SZeev Suraski#define SET_VAR_DOUBLE(n,v)	{															\
36748ffdd79SZeev Suraski								{														\
368235386b2SZeev Suraski									zval *var;											\
36948ffdd79SZeev Suraski																						\
370235386b2SZeev Suraski									ALLOC_ZVAL(var);									\
37148ffdd79SZeev Suraski									var->value.dval = (v);								\
37248ffdd79SZeev Suraski									var->type = IS_DOUBLE;								\
37348ffdd79SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);						\
37448ffdd79SZeev Suraski								}														\
3751f985edeSZeev Suraski							}
3761f985edeSZeev Suraski
3771f985edeSZeev Suraski
378c34560b5SAndi Gutmans#define ZEND_SET_SYMBOL(symtable, name, var)										\
379c34560b5SAndi Gutmans	{																				\
380c34560b5SAndi Gutmans		char *_name = (name);														\
381c34560b5SAndi Gutmans																					\
3824c8259b5SAndi Gutmans		ZEND_SET_SYMBOL_WITH_LENGTH(symtable, _name, strlen(_name)+1, var, 1, 0);	\
38348ffdd79SZeev Suraski	}
38448ffdd79SZeev Suraski
385c34560b5SAndi Gutmans#define ZEND_SET_SYMBOL_WITH_LENGTH(symtable, name, name_length, var, _refcount, _is_ref)				\
38648ffdd79SZeev Suraski	{																									\
38748ffdd79SZeev Suraski		zval **orig_var;																				\
38848ffdd79SZeev Suraski																										\
389620d0134SZeev Suraski		if (zend_hash_find(symtable, (name), (name_length), (void **) &orig_var)==SUCCESS				\
39048ffdd79SZeev Suraski			&& PZVAL_IS_REF(*orig_var)) {																\
391158088caSZeev Suraski			(var)->refcount = (*orig_var)->refcount;													\
39252a30fd2SAndrei Zmievski			(var)->is_ref = 1;																			\
39348ffdd79SZeev Suraski																										\
3942ddc4fe4SZeev Suraski			if (_refcount) {																			\
3952ddc4fe4SZeev Suraski				(var)->refcount += _refcount-1;															\
3962ddc4fe4SZeev Suraski			}																							\
39748ffdd79SZeev Suraski			zval_dtor(*orig_var);																		\
398158088caSZeev Suraski			**orig_var = *(var);																		\
39962b2087aSAndi Gutmans			FREE_ZVAL(var);																					\
40048ffdd79SZeev Suraski		} else {																						\
4012f5efbdeSAndi Gutmans			(var)->is_ref = _is_ref;																	\
402158088caSZeev Suraski			if (_refcount) {																			\
403158088caSZeev Suraski				(var)->refcount = _refcount;															\
404158088caSZeev Suraski			}																							\
405158088caSZeev Suraski			zend_hash_update(symtable, (name), (name_length), &(var), sizeof(zval *), NULL);			\
40648ffdd79SZeev Suraski		}																								\
40748ffdd79SZeev Suraski	}
40848ffdd79SZeev Suraski
409620d0134SZeev Suraski
410620d0134SZeev Suraski#define ZEND_SET_GLOBAL_VAR(name, var)				\
411620d0134SZeev Suraski	ZEND_SET_SYMBOL(&EG(symbol_table), name, var)
412620d0134SZeev Suraski
413e3450661SAndrei Zmievski#define ZEND_SET_GLOBAL_VAR_WITH_LENGTH(name, name_length, var, _refcount, _is_ref)		\
414e3450661SAndrei Zmievski	ZEND_SET_SYMBOL_WITH_LENGTH(&EG(symbol_table), name, name_length, var, _refcount, _is_ref)
415fec413c5SAndrei Zmievski
41606a18f16SAndi Gutmans#define HASH_OF(p) ((p)->type==IS_ARRAY ? (p)->value.ht : (((p)->type==IS_OBJECT ? (p)->value.obj.properties : NULL)))
417af22085cSThies C. Arntzen#define ZVAL_IS_NULL(z) ((z)->type==IS_NULL)
41806a18f16SAndi Gutmans
419b982307dSSascha Schumann#endif /* ZEND_API_H */
420573b4602SAndi Gutmans
421573b4602SAndi Gutmans/*
422573b4602SAndi Gutmans * Local variables:
423573b4602SAndi Gutmans * tab-width: 4
424573b4602SAndi Gutmans * c-basic-offset: 4
425573b4602SAndi Gutmans * End:
426573b4602SAndi Gutmans */
427