zend_API.h revision 0b6d923b
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
21573b4602SAndi Gutmans#ifndef _ZEND_API_H
22573b4602SAndi Gutmans#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"
29573b4602SAndi Gutmans
30e9d126a7SAndi Gutmans#define ZEND_FN(name) zend_if_##name
31342c6e0bSZeev Suraski#define ZEND_NAMED_FUNCTION(name) void name(INTERNAL_FUNCTION_PARAMETERS)
32e9d126a7SAndi Gutmans#define ZEND_FUNCTION(name) ZEND_NAMED_FUNCTION(ZEND_FN(name))
33e9d126a7SAndi Gutmans
34e9d126a7SAndi Gutmans#define ZEND_NAMED_FE(zend_name, name, arg_types) { #zend_name, name, arg_types },
35e9d126a7SAndi Gutmans#define ZEND_FE(name, arg_types) ZEND_NAMED_FE(name, ZEND_FN(name), arg_types)
36e9d126a7SAndi Gutmans#define ZEND_FALIAS(name, alias, arg_types) ZEND_NAMED_FE(name, ZEND_FN(alias), arg_types)
37342c6e0bSZeev Suraski
38e9d126a7SAndi Gutmans#define ZEND_MINIT(module)       zend_minit_##module
39e9d126a7SAndi Gutmans#define ZEND_MSHUTDOWN(module)   zend_mshutdown_##module
40e9d126a7SAndi Gutmans#define ZEND_RINIT(module)       zend_rinit_##module
41e9d126a7SAndi Gutmans#define ZEND_RSHUTDOWN(module)   zend_rshutdown_##module
42e9d126a7SAndi Gutmans#define ZEND_MINFO(module)       zend_info_##module
43e9d126a7SAndi Gutmans#define ZEND_GINIT(module)       zend_ginit_##module
44e9d126a7SAndi Gutmans#define ZEND_GSHUTDOWN(module)   zend_gshutdown_##module
45342c6e0bSZeev Suraski
46e9d126a7SAndi Gutmans#define ZEND_MINIT_FUNCTION(module)      int ZEND_MINIT(module)(INIT_FUNC_ARGS)
47e9d126a7SAndi Gutmans#define ZEND_MSHUTDOWN_FUNCTION(module)  int ZEND_MSHUTDOWN(module)(SHUTDOWN_FUNC_ARGS)
48e9d126a7SAndi Gutmans#define ZEND_RINIT_FUNCTION(module)      int ZEND_RINIT(module)(INIT_FUNC_ARGS)
49e9d126a7SAndi Gutmans#define ZEND_RSHUTDOWN_FUNCTION(module)  int ZEND_RSHUTDOWN(module)(SHUTDOWN_FUNC_ARGS)
50e9d126a7SAndi Gutmans#define ZEND_MINFO_FUNCTION(module)      void ZEND_MINFO(module)(ZEND_MODULE_INFO_FUNC_ARGS)
51e9d126a7SAndi Gutmans#define ZEND_GINIT_FUNCTION(module)      int ZEND_GINIT(module)(GINIT_FUNC_ARGS)
52e9d126a7SAndi Gutmans#define ZEND_GSHUTDOWN_FUNCTION(module)  int ZEND_GSHUTDOWN(module)(void)
53342c6e0bSZeev Suraski
540b6d923bSSascha Schumann#define ZEND_GET_MODULE(name) \
550b6d923bSSascha Schumann	ZEND_DLEXPORT zend_module_entry *get_module(void) { return &name##_module_entry; }
560d21940dSZeev Suraski
570d21940dSZeev Suraski#define ZEND_BEGIN_MODULE_GLOBALS(module_name)		\
580d21940dSZeev Suraski	typedef struct _zend_##module_name##_globals {
590d21940dSZeev Suraski#define ZEND_END_MODULE_GLOBALS(module_name)		\
600d21940dSZeev Suraski	} zend_##module_name##_globals;
610d21940dSZeev Suraski
620d21940dSZeev Suraski#ifdef ZTS
630d21940dSZeev Suraski
640d21940dSZeev Suraski#define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
650d21940dSZeev Suraski	static ts_rsrc_id module_name##_globals_id;
660d21940dSZeev Suraski#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
670d21940dSZeev Suraski	module_name##_globals_id = ts_allocate_id(sizeof(zend_##module_name##_globals), (ts_allocate_ctor) globals_ctor, (ts_allocate_dtor) globals_dtor);
680d21940dSZeev Suraski
690d21940dSZeev Suraski#else
700d21940dSZeev Suraski
710d21940dSZeev Suraski#define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
720d21940dSZeev Suraski	static zend_##module_name##_globals module_name##_globals;
730d21940dSZeev Suraski#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
740d21940dSZeev Suraski	globals_ctor(&module_name##_globals);
750d21940dSZeev Suraski
760d21940dSZeev Suraski#endif
770d21940dSZeev Suraski
780d21940dSZeev Suraski
790d21940dSZeev Suraski
80741b8161SZeev Suraski#define INIT_CLASS_ENTRY(class_container, class_name, functions)	\
81741b8161SZeev Suraski	{																\
82741b8161SZeev Suraski		class_container.name = strdup(class_name);					\
83741b8161SZeev Suraski		class_container.name_length = sizeof(class_name)-1;			\
84741b8161SZeev Suraski		class_container.builtin_functions = functions;				\
85741b8161SZeev Suraski		class_container.handle_function_call = NULL;				\
86741b8161SZeev Suraski		class_container.handle_property_get = NULL;					\
87741b8161SZeev Suraski		class_container.handle_property_set = NULL;					\
88741b8161SZeev Suraski	}
89741b8161SZeev Suraski
90741b8161SZeev Suraski#define INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset) \
91741b8161SZeev Suraski	{															\
92741b8161SZeev Suraski		class_container.name = strdup(class_name);				\
93741b8161SZeev Suraski		class_container.name_length = sizeof(class_name)-1;		\
94741b8161SZeev Suraski		class_container.builtin_functions = functions;			\
95741b8161SZeev Suraski		class_container.handle_function_call = handle_fcall;	\
96741b8161SZeev Suraski		class_container.handle_property_get = handle_propget;	\
97741b8161SZeev Suraski		class_container.handle_property_set = handle_propset;	\
98741b8161SZeev Suraski	}
99741b8161SZeev Suraski
100741b8161SZeev Suraski
101741b8161SZeev Suraski
102573b4602SAndi Gutmansint zend_next_free_module(void);
103573b4602SAndi Gutmans
104f77e6a44SZeev SuraskiZEND_API int zend_get_parameters(int ht, int param_count, ...);
105cd7d5546SZeev SuraskiZEND_API int zend_get_parameters_array(int ht, int param_count, zval **argument_array);
106f77e6a44SZeev SuraskiZEND_API int zend_get_parameters_ex(int param_count, ...);
107cd7d5546SZeev SuraskiZEND_API int zend_get_parameters_array_ex(int param_count, zval ***argument_array);
10839f9487eSAndi Gutmans
1099deab411SAndi GutmansZEND_API int ParameterPassedByReference(int ht, uint n);
11039f9487eSAndi Gutmans
111741b8161SZeev Suraskiint zend_register_functions(zend_function_entry *functions, HashTable *function_table);
112741b8161SZeev Suraskivoid zend_unregister_functions(zend_function_entry *functions, int count, HashTable *function_table);
1137a87fcbbSZeev SuraskiZEND_API int zend_register_module(zend_module_entry *module_entry);
114bfbe8618SZeev SuraskiZEND_API zend_class_entry *register_internal_class(zend_class_entry *class_entry);
115bfbe8618SZeev SuraskiZEND_API zend_module_entry *zend_get_module(int module_number);
116573b4602SAndi Gutmans
117573b4602SAndi GutmansZEND_API void wrong_param_count(void);
118573b4602SAndi Gutmans
119741b8161SZeev Suraski#define getThis() (this_ptr)
120741b8161SZeev Suraski
121131d9cb2SZeev Suraski#define WRONG_PARAM_COUNT					ZEND_WRONG_PARAM_COUNT()
122131d9cb2SZeev Suraski#define WRONG_PARAM_COUNT_WITH_RETVAL(ret)	ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)
123a1ad2872SZeev Suraski#define ARG_COUNT(dummy)	(ht)
124a1ad2872SZeev Suraski#define ZEND_NUM_ARGS()		(ht)
125131d9cb2SZeev Suraski#define ZEND_WRONG_PARAM_COUNT()					{ wrong_param_count(); return; }
126131d9cb2SZeev Suraski#define ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)		{ wrong_param_count(); return ret; }
127573b4602SAndi Gutmans
12880bdd19eSZeev Suraski#ifndef ZEND_WIN32
129573b4602SAndi Gutmans#define DLEXPORT
130573b4602SAndi Gutmans#endif
131573b4602SAndi Gutmans
132e0628436SAndrei ZmievskiZEND_API int zend_startup_module(zend_module_entry *module);
133573b4602SAndi Gutmans
134ceba50b6SZeev Suraski#define array_init(arg)			_array_init((arg) ZEND_FILE_LINE_CC)
135ceba50b6SZeev Suraski#define object_init(arg)		_object_init((arg) ZEND_FILE_LINE_CC)
136ceba50b6SZeev Suraski#define object_init_ex(arg, ce)	_object_init_ex((arg), (ce) ZEND_FILE_LINE_CC)
137ceba50b6SZeev SuraskiZEND_API int _array_init(zval *arg ZEND_FILE_LINE_DC);
138ceba50b6SZeev SuraskiZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC);
139ceba50b6SZeev SuraskiZEND_API int _object_init_ex(zval *arg, zend_class_entry *ce ZEND_FILE_LINE_DC);
1406847fefaSThies C. Arntzen
1416847fefaSThies C. Arntzen/* no longer supported */
1426847fefaSThies C. ArntzenZEND_API int add_assoc_function(zval *arg, char *key,void (*function_ptr)(INTERNAL_FUNCTION_PARAMETERS));
1436847fefaSThies C. Arntzen
144573b4602SAndi GutmansZEND_API int add_assoc_long(zval *arg, char *key, long n);
145f2d703e9SZeev SuraskiZEND_API int add_assoc_unset(zval *arg, char *key);
1466847fefaSThies C. ArntzenZEND_API int add_assoc_bool(zval *arg, char *key, int b);
1476847fefaSThies C. ArntzenZEND_API int add_assoc_resource(zval *arg, char *key, int r);
148573b4602SAndi GutmansZEND_API int add_assoc_double(zval *arg, char *key, double d);
149573b4602SAndi GutmansZEND_API int add_assoc_string(zval *arg, char *key, char *str, int duplicate);
150573b4602SAndi GutmansZEND_API int add_assoc_stringl(zval *arg, char *key, char *str, uint length, int duplicate);
1516847fefaSThies C. Arntzen
152573b4602SAndi GutmansZEND_API int add_index_long(zval *arg, uint idx, long n);
153f2d703e9SZeev SuraskiZEND_API int add_index_unset(zval *arg, uint idx);
1546847fefaSThies C. ArntzenZEND_API int add_index_bool(zval *arg, uint idx, int b);
1556847fefaSThies C. ArntzenZEND_API int add_index_resource(zval *arg, uint idx, int r);
156573b4602SAndi GutmansZEND_API int add_index_double(zval *arg, uint idx, double d);
157573b4602SAndi GutmansZEND_API int add_index_string(zval *arg, uint idx, char *str, int duplicate);
158573b4602SAndi GutmansZEND_API int add_index_stringl(zval *arg, uint idx, char *str, uint length, int duplicate);
1596847fefaSThies C. Arntzen
160573b4602SAndi GutmansZEND_API int add_next_index_long(zval *arg, long n);
161f2d703e9SZeev SuraskiZEND_API int add_next_index_unset(zval *arg);
1626847fefaSThies C. ArntzenZEND_API int add_next_index_bool(zval *arg, int b);
1636847fefaSThies C. ArntzenZEND_API int add_next_index_resource(zval *arg, int r);
164573b4602SAndi GutmansZEND_API int add_next_index_double(zval *arg, double d);
165573b4602SAndi GutmansZEND_API int add_next_index_string(zval *arg, char *str, int duplicate);
166573b4602SAndi GutmansZEND_API int add_next_index_stringl(zval *arg, char *str, uint length, int duplicate);
167573b4602SAndi Gutmans
168573b4602SAndi GutmansZEND_API int add_get_index_long(zval *arg, uint idx, long l, void **dest);
169573b4602SAndi GutmansZEND_API int add_get_index_double(zval *arg, uint idx, double d, void **dest);
1706847fefaSThies C. ArntzenZEND_API int add_get_assoc_string(zval *arg, char *key, char *str, void **dest, int duplicate);
1716847fefaSThies C. ArntzenZEND_API int add_get_assoc_stringl(zval *arg, char *key, char *str, uint length, void **dest, int duplicate);
172573b4602SAndi GutmansZEND_API int add_get_index_string(zval *arg, uint idx, char *str, void **dest, int duplicate);
173573b4602SAndi GutmansZEND_API int add_get_index_stringl(zval *arg, uint idx, char *str, uint length, void **dest, int duplicate);
174573b4602SAndi Gutmans
175223c674cSZeev SuraskiZEND_API int call_user_function(HashTable *function_table, zval *object, zval *function_name, zval *retval_ptr, int param_count, zval *params[]);
176223c674cSZeev 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);
177573b4602SAndi Gutmans
178573b4602SAndi GutmansZEND_API int add_property_long(zval *arg, char *key, long l);
179b995d2ccSAndrei ZmievskiZEND_API int add_property_unset(zval *arg, char *key);
180b995d2ccSAndrei ZmievskiZEND_API int add_property_bool(zval *arg, char *key, int b);
181446e5d0fSThies C. ArntzenZEND_API int add_property_resource(zval *arg, char *key, long r);
182573b4602SAndi GutmansZEND_API int add_property_double(zval *arg, char *key, double d);
183573b4602SAndi GutmansZEND_API int add_property_string(zval *arg, char *key, char *str, int duplicate);
184573b4602SAndi GutmansZEND_API int add_property_stringl(zval *arg, char *key, char *str, uint length, int duplicate);
185573b4602SAndi Gutmans
186f962a35dSAndrei ZmievskiZEND_API int zend_set_hash_symbol(zval *symbol, char *name, int name_length,
187f962a35dSAndrei Zmievski                                  int is_ref, int num_symbol_tables, ...);
188f962a35dSAndrei Zmievski
189573b4602SAndi Gutmans#define add_method(arg,key,method)	add_assoc_function((arg),(key),(method))
190573b4602SAndi Gutmans
191af22085cSThies C. Arntzen#define ZVAL_RESOURCE(z,l) {			\
192af22085cSThies C. Arntzen		(z)->type = IS_RESOURCE;        \
193af22085cSThies C. Arntzen		(z)->value.lval = l;	        \
194af22085cSThies C. Arntzen	}
195af22085cSThies C. Arntzen#define ZVAL_BOOL(z,b) {				\
196af22085cSThies C. Arntzen		(z)->type = IS_BOOL;	        \
197af22085cSThies C. Arntzen		(z)->value.lval = b;	        \
198af22085cSThies C. Arntzen	}
199af22085cSThies C. Arntzen#define ZVAL_NULL(z) {					\
200af22085cSThies C. Arntzen		(z)->type = IS_NULL;	        \
201af22085cSThies C. Arntzen	}
202af22085cSThies C. Arntzen#define ZVAL_LONG(z,l) {				\
203af22085cSThies C. Arntzen		(z)->type = IS_LONG;	        \
204af22085cSThies C. Arntzen		(z)->value.lval = l;	        \
205af22085cSThies C. Arntzen	}
206af22085cSThies C. Arntzen#define ZVAL_DOUBLE(z,d) {				\
207af22085cSThies C. Arntzen		(z)->type = IS_DOUBLE;	        \
208af22085cSThies C. Arntzen		(z)->value.dval = d;	        \
209af22085cSThies C. Arntzen	}
210af22085cSThies C. Arntzen#define ZVAL_STRING(z,s,duplicate) {	\
211af22085cSThies C. Arntzen		char *__s=(s);					\
212af22085cSThies C. Arntzen		(z)->value.str.len = strlen(__s);	\
213af22085cSThies C. Arntzen		(z)->value.str.val = (duplicate?estrndup(__s,(z)->value.str.len):__s);	\
214af22085cSThies C. Arntzen		(z)->type = IS_STRING;	        \
215af22085cSThies C. Arntzen	}
216af22085cSThies C. Arntzen#define ZVAL_STRINGL(z,s,l,duplicate) {	\
217af22085cSThies C. Arntzen		char *__s=(s); int __l=l;		\
218af22085cSThies C. Arntzen		(z)->value.str.len = __l;	    \
219af22085cSThies C. Arntzen		(z)->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
220af22085cSThies C. Arntzen		(z)->type = IS_STRING;		    \
221af22085cSThies C. Arntzen	}
222af22085cSThies C. Arntzen
223af22085cSThies C. Arntzen#define ZVAL_EMPTY_STRING(z) {	        \
224af22085cSThies C. Arntzen		(z)->value.str.len = 0;  	    \
225af22085cSThies C. Arntzen		(z)->value.str.val = empty_string \
226af22085cSThies C. Arntzen		(z)->type = IS_STRING;		    \
227af22085cSThies C. Arntzen	}
228af22085cSThies C. Arntzen
229af22085cSThies C. Arntzen#define ZVAL_FALSE  { (z)->value.lval = 0;  (z)->type = IS_BOOL; }
230af22085cSThies C. Arntzen#define ZVAL_TRUE   { (z)->value.lval = 1;  (z)->type = IS_BOOL; }
231af22085cSThies C. Arntzen
232eb5c6da5SThies C. Arntzen#define RETVAL_RESOURCE(l) {			\
233eb5c6da5SThies C. Arntzen		return_value->type = IS_RESOURCE;\
234eb5c6da5SThies C. Arntzen		return_value->value.lval = l;	\
235eb5c6da5SThies C. Arntzen	}
2361fe57c95SZeev Suraski#define RETVAL_BOOL(b) {				\
2371fe57c95SZeev Suraski		return_value->type = IS_BOOL;	\
2381fe57c95SZeev Suraski		return_value->value.lval = b;	\
2391fe57c95SZeev Suraski	}
240fb6a1b8bSThies C. Arntzen#define RETVAL_NULL() {					\
241bdefd5daSAndi Gutmans		return_value->type = IS_NULL;	\
242f2d703e9SZeev Suraski	}
2431f985edeSZeev Suraski#define RETVAL_LONG(l) {				\
2441f985edeSZeev Suraski		return_value->type = IS_LONG;	\
2451f985edeSZeev Suraski		return_value->value.lval = l;	\
2461f985edeSZeev Suraski	}
2471f985edeSZeev Suraski#define RETVAL_DOUBLE(d) {				\
2481f985edeSZeev Suraski		return_value->type = IS_DOUBLE;	\
2491f985edeSZeev Suraski		return_value->value.dval = d;	\
2501f985edeSZeev Suraski	}
2511f985edeSZeev Suraski#define RETVAL_STRING(s,duplicate) {	\
2521f985edeSZeev Suraski		char *__s=(s);					\
2531f985edeSZeev Suraski		return_value->value.str.len = strlen(__s);	\
2541f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,return_value->value.str.len):__s);	\
2551f985edeSZeev Suraski		return_value->type = IS_STRING;	\
2561f985edeSZeev Suraski	}
2571f985edeSZeev Suraski#define RETVAL_STRINGL(s,l,duplicate) {		\
2581f985edeSZeev Suraski		char *__s=(s); int __l=l;			\
2591f985edeSZeev Suraski		return_value->value.str.len = __l;	\
2601f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
2611f985edeSZeev Suraski		return_value->type = IS_STRING;		\
2621f985edeSZeev Suraski	}
2631f985edeSZeev Suraski
264af22085cSThies C. Arntzen#define RETVAL_EMPTY_STRING() {	            \
265af22085cSThies C. Arntzen		return_value->value.str.len = 0;  	\
266af22085cSThies C. Arntzen		return_value->value.str.val = empty_string \
267af22085cSThies C. Arntzen		return_value->type = IS_STRING;		\
268af22085cSThies C. Arntzen	}
269af22085cSThies C. Arntzen
2701f985edeSZeev Suraski#define RETVAL_FALSE  { return_value->value.lval = 0;  return_value->type = IS_BOOL; }
2711f985edeSZeev Suraski#define RETVAL_TRUE   { return_value->value.lval = 1;  return_value->type = IS_BOOL; }
2721f985edeSZeev Suraski
273eb5c6da5SThies C. Arntzen#define RETURN_RESOURCE(l) {			\
274eb5c6da5SThies C. Arntzen		return_value->type = IS_RESOURCE;\
275eb5c6da5SThies C. Arntzen		return_value->value.lval = l;	\
276eb5c6da5SThies C. Arntzen		return;							\
277eb5c6da5SThies C. Arntzen	}
2781fe57c95SZeev Suraski
2791fe57c95SZeev Suraski#define RETURN_BOOL(b) {				\
2801fe57c95SZeev Suraski		return_value->type = IS_BOOL;	\
2811fe57c95SZeev Suraski		return_value->value.lval = b;	\
2821fe57c95SZeev Suraski		return;							\
2831fe57c95SZeev Suraski	}
2841fe57c95SZeev Suraski
285fb6a1b8bSThies C. Arntzen#define RETURN_NULL() {				\
286bdefd5daSAndi Gutmans		return_value->type = IS_NULL;	\
287f2d703e9SZeev Suraski		return;							\
288f2d703e9SZeev Suraski	}
289f2d703e9SZeev Suraski
2901f985edeSZeev Suraski#define RETURN_LONG(l) {				\
2911f985edeSZeev Suraski		return_value->type = IS_LONG;	\
2921f985edeSZeev Suraski		return_value->value.lval = l;	\
2931f985edeSZeev Suraski		return;							\
2941f985edeSZeev Suraski	}
2951f985edeSZeev Suraski#define RETURN_DOUBLE(d) {				\
2961f985edeSZeev Suraski		return_value->type = IS_DOUBLE;	\
2971f985edeSZeev Suraski		return_value->value.dval = d;	\
2981f985edeSZeev Suraski		return;							\
2991f985edeSZeev Suraski	}
3001f985edeSZeev Suraski#define RETURN_STRING(s,duplicate) {	\
3011f985edeSZeev Suraski		char *__s=(s);					\
3021f985edeSZeev Suraski		return_value->value.str.len = strlen(__s);	\
3031f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,return_value->value.str.len):__s);	\
3041f985edeSZeev Suraski		return_value->type = IS_STRING;	\
3051f985edeSZeev Suraski		return;							\
3061f985edeSZeev Suraski	}
3071f985edeSZeev Suraski#define RETURN_STRINGL(s,l,duplicate) {		\
3081f985edeSZeev Suraski		char *__s=(s); int __l=l;			\
3091f985edeSZeev Suraski		return_value->value.str.len = __l;	\
3101f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
3111f985edeSZeev Suraski      	return_value->type = IS_STRING;		\
3121f985edeSZeev Suraski		return;								\
3131f985edeSZeev Suraski	}
3141f985edeSZeev Suraski
315af22085cSThies C. Arntzen#define RETURN_EMPTY_STRING() {	            \
316af22085cSThies C. Arntzen		return_value->value.str.len = 0;  	\
317af22085cSThies C. Arntzen		return_value->value.str.val = empty_string \
318af22085cSThies C. Arntzen		return_value->type = IS_STRING;		\
319af22085cSThies C. Arntzen        return;                             \
320af22085cSThies C. Arntzen	}
321af22085cSThies C. Arntzen
3221f985edeSZeev Suraski#define RETURN_FALSE  { RETVAL_FALSE; return; }
3231f985edeSZeev Suraski#define RETURN_TRUE   { RETVAL_TRUE; return; }
3241f985edeSZeev Suraski
32548ffdd79SZeev Suraski#define SET_VAR_STRING(n,v)	{																				\
32648ffdd79SZeev Suraski								{																			\
327235386b2SZeev Suraski									zval *var;																\
32848ffdd79SZeev Suraski									char *str=(v); /* prevent 'v' from being evaluated more than once */	\
32948ffdd79SZeev Suraski																											\
330235386b2SZeev Suraski									ALLOC_ZVAL(var);														\
33148ffdd79SZeev Suraski									var->value.str.val = (str);												\
33248ffdd79SZeev Suraski									var->value.str.len = strlen((str));										\
33348ffdd79SZeev Suraski									var->type = IS_STRING;													\
3346393ab14SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);											\
33548ffdd79SZeev Suraski								}																			\
3361f985edeSZeev Suraski							}
33748ffdd79SZeev Suraski
33848ffdd79SZeev Suraski#define SET_VAR_STRINGL(n,v,l)	{														\
33948ffdd79SZeev Suraski									{													\
340235386b2SZeev Suraski										zval *var;										\
34148ffdd79SZeev Suraski																						\
342235386b2SZeev Suraski										ALLOC_ZVAL(var);								\
34348ffdd79SZeev Suraski										var->value.str.val = (v);						\
34448ffdd79SZeev Suraski										var->value.str.len = (l);						\
34548ffdd79SZeev Suraski										var->type = IS_STRING;							\
34648ffdd79SZeev Suraski										ZEND_SET_GLOBAL_VAR(n, var);					\
34748ffdd79SZeev Suraski									}													\
3481f985edeSZeev Suraski								}
34948ffdd79SZeev Suraski
35048ffdd79SZeev Suraski#define SET_VAR_LONG(n,v)	{															\
35148ffdd79SZeev Suraski								{														\
352235386b2SZeev Suraski									zval *var;											\
35348ffdd79SZeev Suraski																						\
354235386b2SZeev Suraski									ALLOC_ZVAL(var);									\
35548ffdd79SZeev Suraski									var->value.lval = (v);								\
35648ffdd79SZeev Suraski									var->type = IS_LONG;								\
35748ffdd79SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);						\
35848ffdd79SZeev Suraski								}														\
3591f985edeSZeev Suraski							}
36048ffdd79SZeev Suraski
36148ffdd79SZeev Suraski#define SET_VAR_DOUBLE(n,v)	{															\
36248ffdd79SZeev Suraski								{														\
363235386b2SZeev Suraski									zval *var;											\
36448ffdd79SZeev Suraski																						\
365235386b2SZeev Suraski									ALLOC_ZVAL(var);									\
36648ffdd79SZeev Suraski									var->value.dval = (v);								\
36748ffdd79SZeev Suraski									var->type = IS_DOUBLE;								\
36848ffdd79SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);						\
36948ffdd79SZeev Suraski								}														\
3701f985edeSZeev Suraski							}
3711f985edeSZeev Suraski
3721f985edeSZeev Suraski
373c34560b5SAndi Gutmans#define ZEND_SET_SYMBOL(symtable, name, var)										\
374c34560b5SAndi Gutmans	{																				\
375c34560b5SAndi Gutmans		char *_name = (name);														\
376c34560b5SAndi Gutmans																					\
3774c8259b5SAndi Gutmans		ZEND_SET_SYMBOL_WITH_LENGTH(symtable, _name, strlen(_name)+1, var, 1, 0);	\
37848ffdd79SZeev Suraski	}
37948ffdd79SZeev Suraski
380c34560b5SAndi Gutmans#define ZEND_SET_SYMBOL_WITH_LENGTH(symtable, name, name_length, var, _refcount, _is_ref)				\
38148ffdd79SZeev Suraski	{																									\
38248ffdd79SZeev Suraski		zval **orig_var;																				\
38348ffdd79SZeev Suraski																										\
384620d0134SZeev Suraski		if (zend_hash_find(symtable, (name), (name_length), (void **) &orig_var)==SUCCESS				\
38548ffdd79SZeev Suraski			&& PZVAL_IS_REF(*orig_var)) {																\
386158088caSZeev Suraski			(var)->refcount = (*orig_var)->refcount;													\
38752a30fd2SAndrei Zmievski			(var)->is_ref = 1;																			\
38848ffdd79SZeev Suraski																										\
3892ddc4fe4SZeev Suraski			if (_refcount) {																			\
3902ddc4fe4SZeev Suraski				(var)->refcount += _refcount-1;															\
3912ddc4fe4SZeev Suraski			}																							\
39248ffdd79SZeev Suraski			zval_dtor(*orig_var);																		\
393158088caSZeev Suraski			**orig_var = *(var);																		\
39462b2087aSAndi Gutmans			FREE_ZVAL(var);																					\
39548ffdd79SZeev Suraski		} else {																						\
3962f5efbdeSAndi Gutmans			(var)->is_ref = _is_ref;																	\
397158088caSZeev Suraski			if (_refcount) {																			\
398158088caSZeev Suraski				(var)->refcount = _refcount;															\
399158088caSZeev Suraski			}																							\
400158088caSZeev Suraski			zend_hash_update(symtable, (name), (name_length), &(var), sizeof(zval *), NULL);			\
40148ffdd79SZeev Suraski		}																								\
40248ffdd79SZeev Suraski	}
40348ffdd79SZeev Suraski
404620d0134SZeev Suraski
405620d0134SZeev Suraski#define ZEND_SET_GLOBAL_VAR(name, var)				\
406620d0134SZeev Suraski	ZEND_SET_SYMBOL(&EG(symbol_table), name, var)
407620d0134SZeev Suraski
408e3450661SAndrei Zmievski#define ZEND_SET_GLOBAL_VAR_WITH_LENGTH(name, name_length, var, _refcount, _is_ref)		\
409e3450661SAndrei Zmievski	ZEND_SET_SYMBOL_WITH_LENGTH(&EG(symbol_table), name, name_length, var, _refcount, _is_ref)
410fec413c5SAndrei Zmievski
41106a18f16SAndi Gutmans#define HASH_OF(p) ((p)->type==IS_ARRAY ? (p)->value.ht : (((p)->type==IS_OBJECT ? (p)->value.obj.properties : NULL)))
412af22085cSThies C. Arntzen#define ZVAL_IS_NULL(z) ((z)->type==IS_NULL)
41306a18f16SAndi Gutmans
414f962a35dSAndrei Zmievski#endif /* _ZEND_API_H */
415573b4602SAndi Gutmans
416573b4602SAndi Gutmans/*
417573b4602SAndi Gutmans * Local variables:
418573b4602SAndi Gutmans * tab-width: 4
419573b4602SAndi Gutmans * c-basic-offset: 4
420573b4602SAndi Gutmans * End:
421573b4602SAndi Gutmans */
422