zend_API.h revision 0d21940d
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
540d21940dSZeev Suraski
550d21940dSZeev Suraski#define ZEND_BEGIN_MODULE_GLOBALS(module_name)		\
560d21940dSZeev Suraski	typedef struct _zend_##module_name##_globals {
570d21940dSZeev Suraski#define ZEND_END_MODULE_GLOBALS(module_name)		\
580d21940dSZeev Suraski	} zend_##module_name##_globals;
590d21940dSZeev Suraski
600d21940dSZeev Suraski#ifdef ZTS
610d21940dSZeev Suraski
620d21940dSZeev Suraski#define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
630d21940dSZeev Suraski	static ts_rsrc_id module_name##_globals_id;
640d21940dSZeev Suraski#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
650d21940dSZeev Suraski	module_name##_globals_id = ts_allocate_id(sizeof(zend_##module_name##_globals), (ts_allocate_ctor) globals_ctor, (ts_allocate_dtor) globals_dtor);
660d21940dSZeev Suraski
670d21940dSZeev Suraski#else
680d21940dSZeev Suraski
690d21940dSZeev Suraski#define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
700d21940dSZeev Suraski	static zend_##module_name##_globals module_name##_globals;
710d21940dSZeev Suraski#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
720d21940dSZeev Suraski	globals_ctor(&module_name##_globals);
730d21940dSZeev Suraski
740d21940dSZeev Suraski#endif
750d21940dSZeev Suraski
760d21940dSZeev Suraski
770d21940dSZeev Suraski
78741b8161SZeev Suraski#define INIT_CLASS_ENTRY(class_container, class_name, functions)	\
79741b8161SZeev Suraski	{																\
80741b8161SZeev Suraski		class_container.name = strdup(class_name);					\
81741b8161SZeev Suraski		class_container.name_length = sizeof(class_name)-1;			\
82741b8161SZeev Suraski		class_container.builtin_functions = functions;				\
83741b8161SZeev Suraski		class_container.handle_function_call = NULL;				\
84741b8161SZeev Suraski		class_container.handle_property_get = NULL;					\
85741b8161SZeev Suraski		class_container.handle_property_set = NULL;					\
86741b8161SZeev Suraski	}
87741b8161SZeev Suraski
88741b8161SZeev Suraski#define INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset) \
89741b8161SZeev Suraski	{															\
90741b8161SZeev Suraski		class_container.name = strdup(class_name);				\
91741b8161SZeev Suraski		class_container.name_length = sizeof(class_name)-1;		\
92741b8161SZeev Suraski		class_container.builtin_functions = functions;			\
93741b8161SZeev Suraski		class_container.handle_function_call = handle_fcall;	\
94741b8161SZeev Suraski		class_container.handle_property_get = handle_propget;	\
95741b8161SZeev Suraski		class_container.handle_property_set = handle_propset;	\
96741b8161SZeev Suraski	}
97741b8161SZeev Suraski
98741b8161SZeev Suraski
99741b8161SZeev Suraski
100573b4602SAndi Gutmansint zend_next_free_module(void);
101573b4602SAndi Gutmans
102f77e6a44SZeev SuraskiZEND_API int zend_get_parameters(int ht, int param_count, ...);
103cd7d5546SZeev SuraskiZEND_API int zend_get_parameters_array(int ht, int param_count, zval **argument_array);
104f77e6a44SZeev SuraskiZEND_API int zend_get_parameters_ex(int param_count, ...);
105cd7d5546SZeev SuraskiZEND_API int zend_get_parameters_array_ex(int param_count, zval ***argument_array);
10639f9487eSAndi Gutmans
1079deab411SAndi GutmansZEND_API int ParameterPassedByReference(int ht, uint n);
10839f9487eSAndi Gutmans
109741b8161SZeev Suraskiint zend_register_functions(zend_function_entry *functions, HashTable *function_table);
110741b8161SZeev Suraskivoid zend_unregister_functions(zend_function_entry *functions, int count, HashTable *function_table);
1117a87fcbbSZeev SuraskiZEND_API int zend_register_module(zend_module_entry *module_entry);
112bfbe8618SZeev SuraskiZEND_API zend_class_entry *register_internal_class(zend_class_entry *class_entry);
113bfbe8618SZeev SuraskiZEND_API zend_module_entry *zend_get_module(int module_number);
114573b4602SAndi Gutmans
115573b4602SAndi GutmansZEND_API void wrong_param_count(void);
116573b4602SAndi Gutmans
117741b8161SZeev Suraski#define getThis() (this_ptr)
118741b8161SZeev Suraski
119573b4602SAndi Gutmans#define WRONG_PARAM_COUNT { wrong_param_count(); return; }
120573b4602SAndi Gutmans#define WRONG_PARAM_COUNT_WITH_RETVAL(ret) { wrong_param_count(); return ret; }
121a1ad2872SZeev Suraski#define ARG_COUNT(dummy)	(ht)
122a1ad2872SZeev Suraski#define ZEND_NUM_ARGS()		(ht)
123573b4602SAndi Gutmans
12480bdd19eSZeev Suraski#ifndef ZEND_WIN32
125573b4602SAndi Gutmans#define DLEXPORT
126573b4602SAndi Gutmans#endif
127573b4602SAndi Gutmans
128e0628436SAndrei ZmievskiZEND_API int zend_startup_module(zend_module_entry *module);
129573b4602SAndi Gutmans
130ceba50b6SZeev Suraski#define array_init(arg)			_array_init((arg) ZEND_FILE_LINE_CC)
131ceba50b6SZeev Suraski#define object_init(arg)		_object_init((arg) ZEND_FILE_LINE_CC)
132ceba50b6SZeev Suraski#define object_init_ex(arg, ce)	_object_init_ex((arg), (ce) ZEND_FILE_LINE_CC)
133ceba50b6SZeev SuraskiZEND_API int _array_init(zval *arg ZEND_FILE_LINE_DC);
134ceba50b6SZeev SuraskiZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC);
135ceba50b6SZeev SuraskiZEND_API int _object_init_ex(zval *arg, zend_class_entry *ce ZEND_FILE_LINE_DC);
1366847fefaSThies C. Arntzen
1376847fefaSThies C. Arntzen/* no longer supported */
1386847fefaSThies C. ArntzenZEND_API int add_assoc_function(zval *arg, char *key,void (*function_ptr)(INTERNAL_FUNCTION_PARAMETERS));
1396847fefaSThies C. Arntzen
140573b4602SAndi GutmansZEND_API int add_assoc_long(zval *arg, char *key, long n);
141f2d703e9SZeev SuraskiZEND_API int add_assoc_unset(zval *arg, char *key);
1426847fefaSThies C. ArntzenZEND_API int add_assoc_bool(zval *arg, char *key, int b);
1436847fefaSThies C. ArntzenZEND_API int add_assoc_resource(zval *arg, char *key, int r);
144573b4602SAndi GutmansZEND_API int add_assoc_double(zval *arg, char *key, double d);
145573b4602SAndi GutmansZEND_API int add_assoc_string(zval *arg, char *key, char *str, int duplicate);
146573b4602SAndi GutmansZEND_API int add_assoc_stringl(zval *arg, char *key, char *str, uint length, int duplicate);
1476847fefaSThies C. Arntzen
148573b4602SAndi GutmansZEND_API int add_index_long(zval *arg, uint idx, long n);
149f2d703e9SZeev SuraskiZEND_API int add_index_unset(zval *arg, uint idx);
1506847fefaSThies C. ArntzenZEND_API int add_index_bool(zval *arg, uint idx, int b);
1516847fefaSThies C. ArntzenZEND_API int add_index_resource(zval *arg, uint idx, int r);
152573b4602SAndi GutmansZEND_API int add_index_double(zval *arg, uint idx, double d);
153573b4602SAndi GutmansZEND_API int add_index_string(zval *arg, uint idx, char *str, int duplicate);
154573b4602SAndi GutmansZEND_API int add_index_stringl(zval *arg, uint idx, char *str, uint length, int duplicate);
1556847fefaSThies C. Arntzen
156573b4602SAndi GutmansZEND_API int add_next_index_long(zval *arg, long n);
157f2d703e9SZeev SuraskiZEND_API int add_next_index_unset(zval *arg);
1586847fefaSThies C. ArntzenZEND_API int add_next_index_bool(zval *arg, int b);
1596847fefaSThies C. ArntzenZEND_API int add_next_index_resource(zval *arg, int r);
160573b4602SAndi GutmansZEND_API int add_next_index_double(zval *arg, double d);
161573b4602SAndi GutmansZEND_API int add_next_index_string(zval *arg, char *str, int duplicate);
162573b4602SAndi GutmansZEND_API int add_next_index_stringl(zval *arg, char *str, uint length, int duplicate);
163573b4602SAndi Gutmans
164573b4602SAndi GutmansZEND_API int add_get_index_long(zval *arg, uint idx, long l, void **dest);
165573b4602SAndi GutmansZEND_API int add_get_index_double(zval *arg, uint idx, double d, void **dest);
1666847fefaSThies C. ArntzenZEND_API int add_get_assoc_string(zval *arg, char *key, char *str, void **dest, int duplicate);
1676847fefaSThies C. ArntzenZEND_API int add_get_assoc_stringl(zval *arg, char *key, char *str, uint length, void **dest, int duplicate);
168573b4602SAndi GutmansZEND_API int add_get_index_string(zval *arg, uint idx, char *str, void **dest, int duplicate);
169573b4602SAndi GutmansZEND_API int add_get_index_stringl(zval *arg, uint idx, char *str, uint length, void **dest, int duplicate);
170573b4602SAndi Gutmans
171223c674cSZeev SuraskiZEND_API int call_user_function(HashTable *function_table, zval *object, zval *function_name, zval *retval_ptr, int param_count, zval *params[]);
172223c674cSZeev 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);
173573b4602SAndi Gutmans
174573b4602SAndi GutmansZEND_API int add_property_long(zval *arg, char *key, long l);
175b995d2ccSAndrei ZmievskiZEND_API int add_property_unset(zval *arg, char *key);
176b995d2ccSAndrei ZmievskiZEND_API int add_property_bool(zval *arg, char *key, int b);
177446e5d0fSThies C. ArntzenZEND_API int add_property_resource(zval *arg, char *key, long r);
178573b4602SAndi GutmansZEND_API int add_property_double(zval *arg, char *key, double d);
179573b4602SAndi GutmansZEND_API int add_property_string(zval *arg, char *key, char *str, int duplicate);
180573b4602SAndi GutmansZEND_API int add_property_stringl(zval *arg, char *key, char *str, uint length, int duplicate);
181573b4602SAndi Gutmans
182f962a35dSAndrei ZmievskiZEND_API int zend_set_hash_symbol(zval *symbol, char *name, int name_length,
183f962a35dSAndrei Zmievski                                  int is_ref, int num_symbol_tables, ...);
184f962a35dSAndrei Zmievski
185573b4602SAndi Gutmans#define add_method(arg,key,method)	add_assoc_function((arg),(key),(method))
186573b4602SAndi Gutmans
187af22085cSThies C. Arntzen#define ZVAL_RESOURCE(z,l) {			\
188af22085cSThies C. Arntzen		(z)->type = IS_RESOURCE;        \
189af22085cSThies C. Arntzen		(z)->value.lval = l;	        \
190af22085cSThies C. Arntzen	}
191af22085cSThies C. Arntzen#define ZVAL_BOOL(z,b) {				\
192af22085cSThies C. Arntzen		(z)->type = IS_BOOL;	        \
193af22085cSThies C. Arntzen		(z)->value.lval = b;	        \
194af22085cSThies C. Arntzen	}
195af22085cSThies C. Arntzen#define ZVAL_NULL(z) {					\
196af22085cSThies C. Arntzen		(z)->type = IS_NULL;	        \
197af22085cSThies C. Arntzen	}
198af22085cSThies C. Arntzen#define ZVAL_LONG(z,l) {				\
199af22085cSThies C. Arntzen		(z)->type = IS_LONG;	        \
200af22085cSThies C. Arntzen		(z)->value.lval = l;	        \
201af22085cSThies C. Arntzen	}
202af22085cSThies C. Arntzen#define ZVAL_DOUBLE(z,d) {				\
203af22085cSThies C. Arntzen		(z)->type = IS_DOUBLE;	        \
204af22085cSThies C. Arntzen		(z)->value.dval = d;	        \
205af22085cSThies C. Arntzen	}
206af22085cSThies C. Arntzen#define ZVAL_STRING(z,s,duplicate) {	\
207af22085cSThies C. Arntzen		char *__s=(s);					\
208af22085cSThies C. Arntzen		(z)->value.str.len = strlen(__s);	\
209af22085cSThies C. Arntzen		(z)->value.str.val = (duplicate?estrndup(__s,(z)->value.str.len):__s);	\
210af22085cSThies C. Arntzen		(z)->type = IS_STRING;	        \
211af22085cSThies C. Arntzen	}
212af22085cSThies C. Arntzen#define ZVAL_STRINGL(z,s,l,duplicate) {	\
213af22085cSThies C. Arntzen		char *__s=(s); int __l=l;		\
214af22085cSThies C. Arntzen		(z)->value.str.len = __l;	    \
215af22085cSThies C. Arntzen		(z)->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
216af22085cSThies C. Arntzen		(z)->type = IS_STRING;		    \
217af22085cSThies C. Arntzen	}
218af22085cSThies C. Arntzen
219af22085cSThies C. Arntzen#define ZVAL_EMPTY_STRING(z) {	        \
220af22085cSThies C. Arntzen		(z)->value.str.len = 0;  	    \
221af22085cSThies C. Arntzen		(z)->value.str.val = empty_string \
222af22085cSThies C. Arntzen		(z)->type = IS_STRING;		    \
223af22085cSThies C. Arntzen	}
224af22085cSThies C. Arntzen
225af22085cSThies C. Arntzen#define ZVAL_FALSE  { (z)->value.lval = 0;  (z)->type = IS_BOOL; }
226af22085cSThies C. Arntzen#define ZVAL_TRUE   { (z)->value.lval = 1;  (z)->type = IS_BOOL; }
227af22085cSThies C. Arntzen
228eb5c6da5SThies C. Arntzen#define RETVAL_RESOURCE(l) {			\
229eb5c6da5SThies C. Arntzen		return_value->type = IS_RESOURCE;\
230eb5c6da5SThies C. Arntzen		return_value->value.lval = l;	\
231eb5c6da5SThies C. Arntzen	}
2321fe57c95SZeev Suraski#define RETVAL_BOOL(b) {				\
2331fe57c95SZeev Suraski		return_value->type = IS_BOOL;	\
2341fe57c95SZeev Suraski		return_value->value.lval = b;	\
2351fe57c95SZeev Suraski	}
236fb6a1b8bSThies C. Arntzen#define RETVAL_NULL() {					\
237bdefd5daSAndi Gutmans		return_value->type = IS_NULL;	\
238f2d703e9SZeev Suraski	}
2391f985edeSZeev Suraski#define RETVAL_LONG(l) {				\
2401f985edeSZeev Suraski		return_value->type = IS_LONG;	\
2411f985edeSZeev Suraski		return_value->value.lval = l;	\
2421f985edeSZeev Suraski	}
2431f985edeSZeev Suraski#define RETVAL_DOUBLE(d) {				\
2441f985edeSZeev Suraski		return_value->type = IS_DOUBLE;	\
2451f985edeSZeev Suraski		return_value->value.dval = d;	\
2461f985edeSZeev Suraski	}
2471f985edeSZeev Suraski#define RETVAL_STRING(s,duplicate) {	\
2481f985edeSZeev Suraski		char *__s=(s);					\
2491f985edeSZeev Suraski		return_value->value.str.len = strlen(__s);	\
2501f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,return_value->value.str.len):__s);	\
2511f985edeSZeev Suraski		return_value->type = IS_STRING;	\
2521f985edeSZeev Suraski	}
2531f985edeSZeev Suraski#define RETVAL_STRINGL(s,l,duplicate) {		\
2541f985edeSZeev Suraski		char *__s=(s); int __l=l;			\
2551f985edeSZeev Suraski		return_value->value.str.len = __l;	\
2561f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
2571f985edeSZeev Suraski		return_value->type = IS_STRING;		\
2581f985edeSZeev Suraski	}
2591f985edeSZeev Suraski
260af22085cSThies C. Arntzen#define RETVAL_EMPTY_STRING() {	            \
261af22085cSThies C. Arntzen		return_value->value.str.len = 0;  	\
262af22085cSThies C. Arntzen		return_value->value.str.val = empty_string \
263af22085cSThies C. Arntzen		return_value->type = IS_STRING;		\
264af22085cSThies C. Arntzen	}
265af22085cSThies C. Arntzen
2661f985edeSZeev Suraski#define RETVAL_FALSE  { return_value->value.lval = 0;  return_value->type = IS_BOOL; }
2671f985edeSZeev Suraski#define RETVAL_TRUE   { return_value->value.lval = 1;  return_value->type = IS_BOOL; }
2681f985edeSZeev Suraski
269eb5c6da5SThies C. Arntzen#define RETURN_RESOURCE(l) {			\
270eb5c6da5SThies C. Arntzen		return_value->type = IS_RESOURCE;\
271eb5c6da5SThies C. Arntzen		return_value->value.lval = l;	\
272eb5c6da5SThies C. Arntzen		return;							\
273eb5c6da5SThies C. Arntzen	}
2741fe57c95SZeev Suraski
2751fe57c95SZeev Suraski#define RETURN_BOOL(b) {				\
2761fe57c95SZeev Suraski		return_value->type = IS_BOOL;	\
2771fe57c95SZeev Suraski		return_value->value.lval = b;	\
2781fe57c95SZeev Suraski		return;							\
2791fe57c95SZeev Suraski	}
2801fe57c95SZeev Suraski
281fb6a1b8bSThies C. Arntzen#define RETURN_NULL() {				\
282bdefd5daSAndi Gutmans		return_value->type = IS_NULL;	\
283f2d703e9SZeev Suraski		return;							\
284f2d703e9SZeev Suraski	}
285f2d703e9SZeev Suraski
2861f985edeSZeev Suraski#define RETURN_LONG(l) {				\
2871f985edeSZeev Suraski		return_value->type = IS_LONG;	\
2881f985edeSZeev Suraski		return_value->value.lval = l;	\
2891f985edeSZeev Suraski		return;							\
2901f985edeSZeev Suraski	}
2911f985edeSZeev Suraski#define RETURN_DOUBLE(d) {				\
2921f985edeSZeev Suraski		return_value->type = IS_DOUBLE;	\
2931f985edeSZeev Suraski		return_value->value.dval = d;	\
2941f985edeSZeev Suraski		return;							\
2951f985edeSZeev Suraski	}
2961f985edeSZeev Suraski#define RETURN_STRING(s,duplicate) {	\
2971f985edeSZeev Suraski		char *__s=(s);					\
2981f985edeSZeev Suraski		return_value->value.str.len = strlen(__s);	\
2991f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,return_value->value.str.len):__s);	\
3001f985edeSZeev Suraski		return_value->type = IS_STRING;	\
3011f985edeSZeev Suraski		return;							\
3021f985edeSZeev Suraski	}
3031f985edeSZeev Suraski#define RETURN_STRINGL(s,l,duplicate) {		\
3041f985edeSZeev Suraski		char *__s=(s); int __l=l;			\
3051f985edeSZeev Suraski		return_value->value.str.len = __l;	\
3061f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
3071f985edeSZeev Suraski      	return_value->type = IS_STRING;		\
3081f985edeSZeev Suraski		return;								\
3091f985edeSZeev Suraski	}
3101f985edeSZeev Suraski
311af22085cSThies C. Arntzen#define RETURN_EMPTY_STRING() {	            \
312af22085cSThies C. Arntzen		return_value->value.str.len = 0;  	\
313af22085cSThies C. Arntzen		return_value->value.str.val = empty_string \
314af22085cSThies C. Arntzen		return_value->type = IS_STRING;		\
315af22085cSThies C. Arntzen        return;                             \
316af22085cSThies C. Arntzen	}
317af22085cSThies C. Arntzen
3181f985edeSZeev Suraski#define RETURN_FALSE  { RETVAL_FALSE; return; }
3191f985edeSZeev Suraski#define RETURN_TRUE   { RETVAL_TRUE; return; }
3201f985edeSZeev Suraski
32148ffdd79SZeev Suraski#define SET_VAR_STRING(n,v)	{																				\
32248ffdd79SZeev Suraski								{																			\
323235386b2SZeev Suraski									zval *var;																\
32448ffdd79SZeev Suraski									char *str=(v); /* prevent 'v' from being evaluated more than once */	\
32548ffdd79SZeev Suraski																											\
326235386b2SZeev Suraski									ALLOC_ZVAL(var);														\
32748ffdd79SZeev Suraski									var->value.str.val = (str);												\
32848ffdd79SZeev Suraski									var->value.str.len = strlen((str));										\
32948ffdd79SZeev Suraski									var->type = IS_STRING;													\
3306393ab14SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);											\
33148ffdd79SZeev Suraski								}																			\
3321f985edeSZeev Suraski							}
33348ffdd79SZeev Suraski
33448ffdd79SZeev Suraski#define SET_VAR_STRINGL(n,v,l)	{														\
33548ffdd79SZeev Suraski									{													\
336235386b2SZeev Suraski										zval *var;										\
33748ffdd79SZeev Suraski																						\
338235386b2SZeev Suraski										ALLOC_ZVAL(var);								\
33948ffdd79SZeev Suraski										var->value.str.val = (v);						\
34048ffdd79SZeev Suraski										var->value.str.len = (l);						\
34148ffdd79SZeev Suraski										var->type = IS_STRING;							\
34248ffdd79SZeev Suraski										ZEND_SET_GLOBAL_VAR(n, var);					\
34348ffdd79SZeev Suraski									}													\
3441f985edeSZeev Suraski								}
34548ffdd79SZeev Suraski
34648ffdd79SZeev Suraski#define SET_VAR_LONG(n,v)	{															\
34748ffdd79SZeev Suraski								{														\
348235386b2SZeev Suraski									zval *var;											\
34948ffdd79SZeev Suraski																						\
350235386b2SZeev Suraski									ALLOC_ZVAL(var);									\
35148ffdd79SZeev Suraski									var->value.lval = (v);								\
35248ffdd79SZeev Suraski									var->type = IS_LONG;								\
35348ffdd79SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);						\
35448ffdd79SZeev Suraski								}														\
3551f985edeSZeev Suraski							}
35648ffdd79SZeev Suraski
35748ffdd79SZeev Suraski#define SET_VAR_DOUBLE(n,v)	{															\
35848ffdd79SZeev Suraski								{														\
359235386b2SZeev Suraski									zval *var;											\
36048ffdd79SZeev Suraski																						\
361235386b2SZeev Suraski									ALLOC_ZVAL(var);									\
36248ffdd79SZeev Suraski									var->value.dval = (v);								\
36348ffdd79SZeev Suraski									var->type = IS_DOUBLE;								\
36448ffdd79SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);						\
36548ffdd79SZeev Suraski								}														\
3661f985edeSZeev Suraski							}
3671f985edeSZeev Suraski
3681f985edeSZeev Suraski
369c34560b5SAndi Gutmans#define ZEND_SET_SYMBOL(symtable, name, var)										\
370c34560b5SAndi Gutmans	{																				\
371c34560b5SAndi Gutmans		char *_name = (name);														\
372c34560b5SAndi Gutmans																					\
3734c8259b5SAndi Gutmans		ZEND_SET_SYMBOL_WITH_LENGTH(symtable, _name, strlen(_name)+1, var, 1, 0);	\
37448ffdd79SZeev Suraski	}
37548ffdd79SZeev Suraski
376c34560b5SAndi Gutmans#define ZEND_SET_SYMBOL_WITH_LENGTH(symtable, name, name_length, var, _refcount, _is_ref)				\
37748ffdd79SZeev Suraski	{																									\
37848ffdd79SZeev Suraski		zval **orig_var;																				\
37948ffdd79SZeev Suraski																										\
380620d0134SZeev Suraski		if (zend_hash_find(symtable, (name), (name_length), (void **) &orig_var)==SUCCESS				\
38148ffdd79SZeev Suraski			&& PZVAL_IS_REF(*orig_var)) {																\
382158088caSZeev Suraski			(var)->refcount = (*orig_var)->refcount;													\
38352a30fd2SAndrei Zmievski			(var)->is_ref = 1;																			\
38448ffdd79SZeev Suraski																										\
3852ddc4fe4SZeev Suraski			if (_refcount) {																			\
3862ddc4fe4SZeev Suraski				(var)->refcount += _refcount-1;															\
3872ddc4fe4SZeev Suraski			}																							\
38848ffdd79SZeev Suraski			zval_dtor(*orig_var);																		\
389158088caSZeev Suraski			**orig_var = *(var);																		\
39062b2087aSAndi Gutmans			FREE_ZVAL(var);																					\
39148ffdd79SZeev Suraski		} else {																						\
3922f5efbdeSAndi Gutmans			(var)->is_ref = _is_ref;																	\
393158088caSZeev Suraski			if (_refcount) {																			\
394158088caSZeev Suraski				(var)->refcount = _refcount;															\
395158088caSZeev Suraski			}																							\
396158088caSZeev Suraski			zend_hash_update(symtable, (name), (name_length), &(var), sizeof(zval *), NULL);			\
39748ffdd79SZeev Suraski		}																								\
39848ffdd79SZeev Suraski	}
39948ffdd79SZeev Suraski
400620d0134SZeev Suraski
401620d0134SZeev Suraski#define ZEND_SET_GLOBAL_VAR(name, var)				\
402620d0134SZeev Suraski	ZEND_SET_SYMBOL(&EG(symbol_table), name, var)
403620d0134SZeev Suraski
404e3450661SAndrei Zmievski#define ZEND_SET_GLOBAL_VAR_WITH_LENGTH(name, name_length, var, _refcount, _is_ref)		\
405e3450661SAndrei Zmievski	ZEND_SET_SYMBOL_WITH_LENGTH(&EG(symbol_table), name, name_length, var, _refcount, _is_ref)
406fec413c5SAndrei Zmievski
40706a18f16SAndi Gutmans#define HASH_OF(p) ((p)->type==IS_ARRAY ? (p)->value.ht : (((p)->type==IS_OBJECT ? (p)->value.obj.properties : NULL)))
408af22085cSThies C. Arntzen#define ZVAL_IS_NULL(z) ((z)->type==IS_NULL)
40906a18f16SAndi Gutmans
410f962a35dSAndrei Zmievski#endif /* _ZEND_API_H */
411573b4602SAndi Gutmans
412573b4602SAndi Gutmans/*
413573b4602SAndi Gutmans * Local variables:
414573b4602SAndi Gutmans * tab-width: 4
415573b4602SAndi Gutmans * c-basic-offset: 4
416573b4602SAndi Gutmans * End:
417573b4602SAndi Gutmans */