zend_API.h revision 58f88057
1573b4602SAndi Gutmans/*
2573b4602SAndi Gutmans   +----------------------------------------------------------------------+
3573b4602SAndi Gutmans   | Zend Engine                                                          |
4573b4602SAndi Gutmans   +----------------------------------------------------------------------+
5d2c9e807SAndi Gutmans   | Copyright (c) 1998-2001 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>                                |
1758f88057SAndrei Zmievski   |          Andrei Zmievski <andrei@php.net>                            |
18573b4602SAndi Gutmans   +----------------------------------------------------------------------+
19573b4602SAndi Gutmans*/
20573b4602SAndi Gutmans
21b5b11177SZeev Suraski
22b982307dSSascha Schumann#ifndef ZEND_API_H
23b982307dSSascha Schumann#define ZEND_API_H
24573b4602SAndi Gutmans
257080fa5bSAndi Gutmans#include "zend_modules.h"
26573b4602SAndi Gutmans#include "zend_list.h"
27b7a5b3c3SZeev Suraski#include "zend_fast_cache.h"
285dba4774SZeev Suraski#include "zend_operators.h"
295dba4774SZeev Suraski#include "zend_variables.h"
30df74f1dfSSascha Schumann#include "zend_execute.h"
31573b4602SAndi Gutmans
32e9d126a7SAndi Gutmans#define ZEND_FN(name) zend_if_##name
33342c6e0bSZeev Suraski#define ZEND_NAMED_FUNCTION(name) void name(INTERNAL_FUNCTION_PARAMETERS)
34e9d126a7SAndi Gutmans#define ZEND_FUNCTION(name) ZEND_NAMED_FUNCTION(ZEND_FN(name))
35e9d126a7SAndi Gutmans
36e9d126a7SAndi Gutmans#define ZEND_NAMED_FE(zend_name, name, arg_types) { #zend_name, name, arg_types },
37e9d126a7SAndi Gutmans#define ZEND_FE(name, arg_types) ZEND_NAMED_FE(name, ZEND_FN(name), arg_types)
38e9d126a7SAndi Gutmans#define ZEND_FALIAS(name, alias, arg_types) ZEND_NAMED_FE(name, ZEND_FN(alias), arg_types)
39342c6e0bSZeev Suraski
40e9d126a7SAndi Gutmans#define ZEND_MINIT(module)       zend_minit_##module
41e9d126a7SAndi Gutmans#define ZEND_MSHUTDOWN(module)   zend_mshutdown_##module
42e9d126a7SAndi Gutmans#define ZEND_RINIT(module)       zend_rinit_##module
43e9d126a7SAndi Gutmans#define ZEND_RSHUTDOWN(module)   zend_rshutdown_##module
44e9d126a7SAndi Gutmans#define ZEND_MINFO(module)       zend_info_##module
45e9d126a7SAndi Gutmans#define ZEND_GINIT(module)       zend_ginit_##module
46e9d126a7SAndi Gutmans#define ZEND_GSHUTDOWN(module)   zend_gshutdown_##module
47342c6e0bSZeev Suraski
48e9d126a7SAndi Gutmans#define ZEND_MINIT_FUNCTION(module)      int ZEND_MINIT(module)(INIT_FUNC_ARGS)
49e9d126a7SAndi Gutmans#define ZEND_MSHUTDOWN_FUNCTION(module)  int ZEND_MSHUTDOWN(module)(SHUTDOWN_FUNC_ARGS)
50e9d126a7SAndi Gutmans#define ZEND_RINIT_FUNCTION(module)      int ZEND_RINIT(module)(INIT_FUNC_ARGS)
51e9d126a7SAndi Gutmans#define ZEND_RSHUTDOWN_FUNCTION(module)  int ZEND_RSHUTDOWN(module)(SHUTDOWN_FUNC_ARGS)
52e9d126a7SAndi Gutmans#define ZEND_MINFO_FUNCTION(module)      void ZEND_MINFO(module)(ZEND_MODULE_INFO_FUNC_ARGS)
53e9d126a7SAndi Gutmans#define ZEND_GINIT_FUNCTION(module)      int ZEND_GINIT(module)(GINIT_FUNC_ARGS)
54e9d126a7SAndi Gutmans#define ZEND_GSHUTDOWN_FUNCTION(module)  int ZEND_GSHUTDOWN(module)(void)
55342c6e0bSZeev Suraski
560b6d923bSSascha Schumann#define ZEND_GET_MODULE(name) \
570b6d923bSSascha Schumann	ZEND_DLEXPORT zend_module_entry *get_module(void) { return &name##_module_entry; }
580d21940dSZeev Suraski
590d21940dSZeev Suraski#define ZEND_BEGIN_MODULE_GLOBALS(module_name)		\
600d21940dSZeev Suraski	typedef struct _zend_##module_name##_globals {
610d21940dSZeev Suraski#define ZEND_END_MODULE_GLOBALS(module_name)		\
620d21940dSZeev Suraski	} zend_##module_name##_globals;
630d21940dSZeev Suraski
640d21940dSZeev Suraski#ifdef ZTS
650d21940dSZeev Suraski
660d21940dSZeev Suraski#define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
6702af513cSAndi Gutmans	ts_rsrc_id module_name##_globals_id;
6802af513cSAndi Gutmans#define ZEND_EXTERN_MODULE_GLOBALS(module_name)								\
6902af513cSAndi Gutmans	extern ts_rsrc_id module_name##_globals_id;
700d21940dSZeev Suraski#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
710d21940dSZeev Suraski	module_name##_globals_id = ts_allocate_id(sizeof(zend_##module_name##_globals), (ts_allocate_ctor) globals_ctor, (ts_allocate_dtor) globals_dtor);
720d21940dSZeev Suraski
730d21940dSZeev Suraski#else
740d21940dSZeev Suraski
750d21940dSZeev Suraski#define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
7602af513cSAndi Gutmans	zend_##module_name##_globals module_name##_globals;
7702af513cSAndi Gutmans#define ZEND_EXTERN_MODULE_GLOBALS(module_name)								\
7802af513cSAndi Gutmans	extern zend_##module_name##_globals module_name##_globals;
790d21940dSZeev Suraski#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
800d21940dSZeev Suraski	globals_ctor(&module_name##_globals);
810d21940dSZeev Suraski
820d21940dSZeev Suraski#endif
830d21940dSZeev Suraski
840d21940dSZeev Suraski
850d21940dSZeev Suraski
86741b8161SZeev Suraski#define INIT_CLASS_ENTRY(class_container, class_name, functions)	\
87741b8161SZeev Suraski	{																\
88741b8161SZeev Suraski		class_container.name = strdup(class_name);					\
89741b8161SZeev Suraski		class_container.name_length = sizeof(class_name)-1;			\
90741b8161SZeev Suraski		class_container.builtin_functions = functions;				\
91741b8161SZeev Suraski		class_container.handle_function_call = NULL;				\
92741b8161SZeev Suraski		class_container.handle_property_get = NULL;					\
93741b8161SZeev Suraski		class_container.handle_property_set = NULL;					\
94741b8161SZeev Suraski	}
95741b8161SZeev Suraski
96741b8161SZeev Suraski#define INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset) \
97741b8161SZeev Suraski	{															\
98741b8161SZeev Suraski		class_container.name = strdup(class_name);				\
99741b8161SZeev Suraski		class_container.name_length = sizeof(class_name)-1;		\
100741b8161SZeev Suraski		class_container.builtin_functions = functions;			\
101741b8161SZeev Suraski		class_container.handle_function_call = handle_fcall;	\
102741b8161SZeev Suraski		class_container.handle_property_get = handle_propget;	\
103741b8161SZeev Suraski		class_container.handle_property_set = handle_propset;	\
104741b8161SZeev Suraski	}
105741b8161SZeev Suraski
106741b8161SZeev Suraski
107741b8161SZeev Suraski
108573b4602SAndi Gutmansint zend_next_free_module(void);
109573b4602SAndi Gutmans
110f77e6a44SZeev SuraskiZEND_API int zend_get_parameters(int ht, int param_count, ...);
111cd7d5546SZeev SuraskiZEND_API int zend_get_parameters_array(int ht, int param_count, zval **argument_array);
112f77e6a44SZeev SuraskiZEND_API int zend_get_parameters_ex(int param_count, ...);
113cd7d5546SZeev SuraskiZEND_API int zend_get_parameters_array_ex(int param_count, zval ***argument_array);
11439f9487eSAndi Gutmans
11558f88057SAndrei Zmievski
11658f88057SAndrei Zmievski/* Parameter parsing API -- andrei */
11758f88057SAndrei Zmievski
11858f88057SAndrei Zmievski#define ZEND_PARSE_PARAMS_QUIET 1<<1
11958f88057SAndrei ZmievskiZEND_API int zend_parse_parameters(int num_args, char *type_spec, ...);
12058f88057SAndrei ZmievskiZEND_API int zend_parse_parameters_ex(int flags, int num_args, char *type_spec, ...);
12158f88057SAndrei Zmievski
12258f88057SAndrei Zmievski/* Parameter parsing API -- andrei */
12358f88057SAndrei Zmievski
12458f88057SAndrei Zmievski
1259deab411SAndi GutmansZEND_API int ParameterPassedByReference(int ht, uint n);
12639f9487eSAndi Gutmans
127fce92e3cSZeev Suraskiint zend_register_functions(zend_function_entry *functions, HashTable *function_table, int type);
128741b8161SZeev Suraskivoid zend_unregister_functions(zend_function_entry *functions, int count, HashTable *function_table);
1297a87fcbbSZeev SuraskiZEND_API int zend_register_module(zend_module_entry *module_entry);
130eb0e6946SAndi Gutmans
1316ce07a85SAndi GutmansZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry);
132eb0e6946SAndi GutmansZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce, char *parent_name);
133eb0e6946SAndi Gutmans
134bfbe8618SZeev SuraskiZEND_API zend_module_entry *zend_get_module(int module_number);
135bc7abb33SZeev SuraskiZEND_API int zend_disable_function(char *function_name, uint function_name_length);
136573b4602SAndi Gutmans
137573b4602SAndi GutmansZEND_API void wrong_param_count(void);
13813148b54SAndrei ZmievskiZEND_API zend_bool zend_is_callable(zval *callable, zend_bool syntax_only, char **callable_name);
139573b4602SAndi Gutmans
140741b8161SZeev Suraski#define getThis() (this_ptr)
141741b8161SZeev Suraski
142131d9cb2SZeev Suraski#define WRONG_PARAM_COUNT					ZEND_WRONG_PARAM_COUNT()
143131d9cb2SZeev Suraski#define WRONG_PARAM_COUNT_WITH_RETVAL(ret)	ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)
144a1ad2872SZeev Suraski#define ARG_COUNT(dummy)	(ht)
145a1ad2872SZeev Suraski#define ZEND_NUM_ARGS()		(ht)
146131d9cb2SZeev Suraski#define ZEND_WRONG_PARAM_COUNT()					{ wrong_param_count(); return; }
147131d9cb2SZeev Suraski#define ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)		{ wrong_param_count(); return ret; }
148573b4602SAndi Gutmans
14980bdd19eSZeev Suraski#ifndef ZEND_WIN32
150573b4602SAndi Gutmans#define DLEXPORT
151573b4602SAndi Gutmans#endif
152573b4602SAndi Gutmans
153e0628436SAndrei ZmievskiZEND_API int zend_startup_module(zend_module_entry *module);
154573b4602SAndi Gutmans
155ceba50b6SZeev Suraski#define array_init(arg)			_array_init((arg) ZEND_FILE_LINE_CC)
156ceba50b6SZeev Suraski#define object_init(arg)		_object_init((arg) ZEND_FILE_LINE_CC)
157ceba50b6SZeev Suraski#define object_init_ex(arg, ce)	_object_init_ex((arg), (ce) ZEND_FILE_LINE_CC)
158ceba50b6SZeev SuraskiZEND_API int _array_init(zval *arg ZEND_FILE_LINE_DC);
159ceba50b6SZeev SuraskiZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC);
160ceba50b6SZeev SuraskiZEND_API int _object_init_ex(zval *arg, zend_class_entry *ce ZEND_FILE_LINE_DC);
1616847fefaSThies C. Arntzen
1626847fefaSThies C. Arntzen/* no longer supported */
1636847fefaSThies C. ArntzenZEND_API int add_assoc_function(zval *arg, char *key,void (*function_ptr)(INTERNAL_FUNCTION_PARAMETERS));
1646847fefaSThies C. Arntzen
165ef95a346SAndi GutmansZEND_API int add_assoc_long_ex(zval *arg, char *key, uint key_len, long n);
1660611acb9SAndi GutmansZEND_API int add_assoc_null_ex(zval *arg, char *key, uint key_len);
167ef95a346SAndi GutmansZEND_API int add_assoc_bool_ex(zval *arg, char *key, uint key_len, int b);
168ef95a346SAndi GutmansZEND_API int add_assoc_resource_ex(zval *arg, char *key, uint key_len, int r);
169ef95a346SAndi GutmansZEND_API int add_assoc_double_ex(zval *arg, char *key, uint key_len, double d);
170ef95a346SAndi GutmansZEND_API int add_assoc_string_ex(zval *arg, char *key, uint key_len, char *str, int duplicate);
171ef95a346SAndi GutmansZEND_API int add_assoc_stringl_ex(zval *arg, char *key, uint key_len, char *str, uint length, int duplicate);
172ef95a346SAndi GutmansZEND_API int add_assoc_zval_ex(zval *arg, char *key, uint key_len, zval *value);
173ef95a346SAndi Gutmans
174ef95a346SAndi Gutmans#define add_assoc_long(__arg, __key, __n) add_assoc_long_ex(__arg, __key, strlen(__key)+1, __n)
1750611acb9SAndi Gutmans#define add_assoc_null(__arg, __key) add_assoc_null_ex(__arg, __key, strlen(__key) + 1)
176ef95a346SAndi Gutmans#define add_assoc_bool(__arg, __key, __b) add_assoc_bool_ex(__arg, __key, strlen(__key)+1, __b)
177ef95a346SAndi Gutmans#define add_assoc_resource(__arg, __key, __r) add_assoc_resource_ex(__arg, __key, strlen(__key)+1, __r)
178ef95a346SAndi Gutmans#define add_assoc_double(__arg, __key, __d) add_assoc_double_ex(__arg, __key, strlen(__key)+1, __d)
179ef95a346SAndi Gutmans#define add_assoc_string(__arg, __key, __str, __duplicate) add_assoc_string_ex(__arg, __key, strlen(__key)+1, __str, __duplicate)
180ef95a346SAndi Gutmans#define add_assoc_stringl(__arg, __key, __str, __length, __duplicate) add_assoc_stringl_ex(__arg, __key, strlen(__key)+1, __str, __length, __duplicate)
181ef95a346SAndi Gutmans#define add_assoc_zval(__arg, __key, __value) add_assoc_zval_ex(__arg, __key, strlen(__key)+1, __value)
1826847fefaSThies C. Arntzen
1830611acb9SAndi Gutmans/* unset() functions are only suported for legacy modules and null() functions should be used */
1840611acb9SAndi Gutmans#define add_assoc_unset(__arg, __key) add_assoc_null_ex(__arg, __key, strlen(__key) + 1)
1850611acb9SAndi Gutmans#define add_index_unset(__arg, __key) add_index_null(__arg, __key)
1860611acb9SAndi Gutmans#define add_next_index_unset(__arg) add_next_index_null(__arg)
1870611acb9SAndi Gutmans#define add_property_unset(__arg, __key) add_property_null(__arg, __key)
1880611acb9SAndi Gutmans
189573b4602SAndi GutmansZEND_API int add_index_long(zval *arg, uint idx, long n);
1900611acb9SAndi GutmansZEND_API int add_index_null(zval *arg, uint idx);
1916847fefaSThies C. ArntzenZEND_API int add_index_bool(zval *arg, uint idx, int b);
1926847fefaSThies C. ArntzenZEND_API int add_index_resource(zval *arg, uint idx, int r);
193573b4602SAndi GutmansZEND_API int add_index_double(zval *arg, uint idx, double d);
194573b4602SAndi GutmansZEND_API int add_index_string(zval *arg, uint idx, char *str, int duplicate);
195573b4602SAndi GutmansZEND_API int add_index_stringl(zval *arg, uint idx, char *str, uint length, int duplicate);
19657f99633SAndrei ZmievskiZEND_API int add_index_zval(zval *arg, uint index, zval *value);
1976847fefaSThies C. Arntzen
198573b4602SAndi GutmansZEND_API int add_next_index_long(zval *arg, long n);
1990611acb9SAndi GutmansZEND_API int add_next_index_null(zval *arg);
2006847fefaSThies C. ArntzenZEND_API int add_next_index_bool(zval *arg, int b);
2016847fefaSThies C. ArntzenZEND_API int add_next_index_resource(zval *arg, int r);
202573b4602SAndi GutmansZEND_API int add_next_index_double(zval *arg, double d);
203573b4602SAndi GutmansZEND_API int add_next_index_string(zval *arg, char *str, int duplicate);
204573b4602SAndi GutmansZEND_API int add_next_index_stringl(zval *arg, char *str, uint length, int duplicate);
205ef95a346SAndi GutmansZEND_API int add_next_index_zval(zval *arg, zval *value);
206ef95a346SAndi Gutmans
207ef95a346SAndi GutmansZEND_API int add_get_assoc_string_ex(zval *arg, char *key, uint key_len, char *str, void **dest, int duplicate);
208ef95a346SAndi GutmansZEND_API int add_get_assoc_stringl_ex(zval *arg, char *key, uint key_len, char *str, uint length, void **dest, int duplicate);
209ef95a346SAndi Gutmans
210ef95a346SAndi Gutmans#define add_get_assoc_string(__arg, __key, __str, __dest, __duplicate) add_get_assoc_string_ex(__arg, __key, strlen(__key)+1, __str, __dest, __duplicate)
211ef95a346SAndi Gutmans#define add_get_assoc_stringl(__arg, __key, __str, __length, __dest, __duplicate) add_get_assoc_stringl_ex(__arg, __key, strlen(__key)+1, __str, __length, __dest, __duplicate)
212573b4602SAndi Gutmans
213573b4602SAndi GutmansZEND_API int add_get_index_long(zval *arg, uint idx, long l, void **dest);
214573b4602SAndi GutmansZEND_API int add_get_index_double(zval *arg, uint idx, double d, void **dest);
215573b4602SAndi GutmansZEND_API int add_get_index_string(zval *arg, uint idx, char *str, void **dest, int duplicate);
216573b4602SAndi GutmansZEND_API int add_get_index_stringl(zval *arg, uint idx, char *str, uint length, void **dest, int duplicate);
217573b4602SAndi Gutmans
218ef95a346SAndi GutmansZEND_API int add_property_long_ex(zval *arg, char *key, uint key_len, long l);
2190611acb9SAndi GutmansZEND_API int add_property_null_ex(zval *arg, char *key, uint key_len);
220ef95a346SAndi GutmansZEND_API int add_property_bool_ex(zval *arg, char *key, uint key_len, int b);
221ef95a346SAndi GutmansZEND_API int add_property_resource_ex(zval *arg, char *key, uint key_len, long r);
222ef95a346SAndi GutmansZEND_API int add_property_double_ex(zval *arg, char *key, uint key_len, double d);
223ef95a346SAndi GutmansZEND_API int add_property_string_ex(zval *arg, char *key, uint key_len, char *str, int duplicate);
224ef95a346SAndi GutmansZEND_API int add_property_stringl_ex(zval *arg, char *key, uint key_len,  char *str, uint length, int duplicate);
225ef95a346SAndi GutmansZEND_API int add_property_zval_ex(zval *arg, char *key, uint key_len, zval *value);
226ef95a346SAndi Gutmans
227ef95a346SAndi Gutmans#define add_property_long(__arg, __key, __n) add_property_long_ex(__arg, __key, strlen(__key)+1, __n)
2280611acb9SAndi Gutmans#define add_property_null(__arg, __key) add_property_null_ex(__arg, __key, strlen(__key) + 1)
229ef95a346SAndi Gutmans#define add_property_bool(__arg, __key, __b) add_property_bool_ex(__arg, __key, strlen(__key)+1, __b)
230ef95a346SAndi Gutmans#define add_property_resource(__arg, __key, __r) add_property_resource_ex(__arg, __key, strlen(__key)+1, __r)
231ef95a346SAndi Gutmans#define add_property_double(__arg, __key, __d) add_property_double_ex(__arg, __key, strlen(__key)+1, __d)
232ef95a346SAndi Gutmans#define add_property_string(__arg, __key, __str, __duplicate) add_property_string_ex(__arg, __key, strlen(__key)+1, __str, __duplicate)
233ef95a346SAndi Gutmans#define add_property_stringl(__arg, __key, __str, __length, __duplicate) add_property_stringl_ex(__arg, __key, strlen(__key)+1, __str, __length, __duplicate)
234ef95a346SAndi Gutmans#define add_property_zval(__arg, __key, __value) add_property_zval_ex(__arg, __key, strlen(__key)+1, __value)
235ef95a346SAndi Gutmans
236be895bcbSZeev SuraskiZEND_API int call_user_function(HashTable *function_table, zval **object_pp, zval *function_name, zval *retval_ptr, int param_count, zval *params[]);
237be895bcbSZeev SuraskiZEND_API int call_user_function_ex(HashTable *function_table, zval **object_pp, zval *function_name, zval **retval_ptr_ptr, int param_count, zval **params[], int no_separation, HashTable *symbol_table);
238573b4602SAndi Gutmans
239f962a35dSAndrei ZmievskiZEND_API int zend_set_hash_symbol(zval *symbol, char *name, int name_length,
240f962a35dSAndrei Zmievski                                  int is_ref, int num_symbol_tables, ...);
241f962a35dSAndrei Zmievski
242573b4602SAndi Gutmans#define add_method(arg,key,method)	add_assoc_function((arg),(key),(method))
243573b4602SAndi Gutmans
244af22085cSThies C. Arntzen#define ZVAL_RESOURCE(z,l) {			\
245af22085cSThies C. Arntzen		(z)->type = IS_RESOURCE;        \
246af22085cSThies C. Arntzen		(z)->value.lval = l;	        \
247af22085cSThies C. Arntzen	}
248af22085cSThies C. Arntzen#define ZVAL_BOOL(z,b) {				\
249af22085cSThies C. Arntzen		(z)->type = IS_BOOL;	        \
250af22085cSThies C. Arntzen		(z)->value.lval = b;	        \
251af22085cSThies C. Arntzen	}
252af22085cSThies C. Arntzen#define ZVAL_NULL(z) {					\
253af22085cSThies C. Arntzen		(z)->type = IS_NULL;	        \
254af22085cSThies C. Arntzen	}
255af22085cSThies C. Arntzen#define ZVAL_LONG(z,l) {				\
256af22085cSThies C. Arntzen		(z)->type = IS_LONG;	        \
257af22085cSThies C. Arntzen		(z)->value.lval = l;	        \
258af22085cSThies C. Arntzen	}
259af22085cSThies C. Arntzen#define ZVAL_DOUBLE(z,d) {				\
260af22085cSThies C. Arntzen		(z)->type = IS_DOUBLE;	        \
261af22085cSThies C. Arntzen		(z)->value.dval = d;	        \
262af22085cSThies C. Arntzen	}
263af22085cSThies C. Arntzen#define ZVAL_STRING(z,s,duplicate) {	\
264af22085cSThies C. Arntzen		char *__s=(s);					\
265af22085cSThies C. Arntzen		(z)->value.str.len = strlen(__s);	\
266af22085cSThies C. Arntzen		(z)->value.str.val = (duplicate?estrndup(__s,(z)->value.str.len):__s);	\
267af22085cSThies C. Arntzen		(z)->type = IS_STRING;	        \
268af22085cSThies C. Arntzen	}
269af22085cSThies C. Arntzen#define ZVAL_STRINGL(z,s,l,duplicate) {	\
270af22085cSThies C. Arntzen		char *__s=(s); int __l=l;		\
271af22085cSThies C. Arntzen		(z)->value.str.len = __l;	    \
272af22085cSThies C. Arntzen		(z)->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
273af22085cSThies C. Arntzen		(z)->type = IS_STRING;		    \
274af22085cSThies C. Arntzen	}
275af22085cSThies C. Arntzen
276af22085cSThies C. Arntzen#define ZVAL_EMPTY_STRING(z) {	        \
277af22085cSThies C. Arntzen		(z)->value.str.len = 0;  	    \
2781f793fd0SStanislav Malyshev		(z)->value.str.val = empty_string; \
279af22085cSThies C. Arntzen		(z)->type = IS_STRING;		    \
280af22085cSThies C. Arntzen	}
281af22085cSThies C. Arntzen
282af22085cSThies C. Arntzen#define ZVAL_FALSE  { (z)->value.lval = 0;  (z)->type = IS_BOOL; }
283af22085cSThies C. Arntzen#define ZVAL_TRUE   { (z)->value.lval = 1;  (z)->type = IS_BOOL; }
284af22085cSThies C. Arntzen
285eb5c6da5SThies C. Arntzen#define RETVAL_RESOURCE(l) {			\
286eb5c6da5SThies C. Arntzen		return_value->type = IS_RESOURCE;\
287eb5c6da5SThies C. Arntzen		return_value->value.lval = l;	\
288eb5c6da5SThies C. Arntzen	}
2891fe57c95SZeev Suraski#define RETVAL_BOOL(b) {				\
2901fe57c95SZeev Suraski		return_value->type = IS_BOOL;	\
2911fe57c95SZeev Suraski		return_value->value.lval = b;	\
2921fe57c95SZeev Suraski	}
293fb6a1b8bSThies C. Arntzen#define RETVAL_NULL() {					\
294bdefd5daSAndi Gutmans		return_value->type = IS_NULL;	\
295f2d703e9SZeev Suraski	}
2961f985edeSZeev Suraski#define RETVAL_LONG(l) {				\
2971f985edeSZeev Suraski		return_value->type = IS_LONG;	\
2981f985edeSZeev Suraski		return_value->value.lval = l;	\
2991f985edeSZeev Suraski	}
3001f985edeSZeev Suraski#define RETVAL_DOUBLE(d) {				\
3011f985edeSZeev Suraski		return_value->type = IS_DOUBLE;	\
3021f985edeSZeev Suraski		return_value->value.dval = d;	\
3031f985edeSZeev Suraski	}
3041f985edeSZeev Suraski#define RETVAL_STRING(s,duplicate) {	\
3051f985edeSZeev Suraski		char *__s=(s);					\
3061f985edeSZeev Suraski		return_value->value.str.len = strlen(__s);	\
3071f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,return_value->value.str.len):__s);	\
3081f985edeSZeev Suraski		return_value->type = IS_STRING;	\
3091f985edeSZeev Suraski	}
3101f985edeSZeev Suraski#define RETVAL_STRINGL(s,l,duplicate) {		\
3111f985edeSZeev Suraski		char *__s=(s); int __l=l;			\
3121f985edeSZeev Suraski		return_value->value.str.len = __l;	\
3131f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
3141f985edeSZeev Suraski		return_value->type = IS_STRING;		\
3151f985edeSZeev Suraski	}
3161f985edeSZeev Suraski
317af22085cSThies C. Arntzen#define RETVAL_EMPTY_STRING() {	            \
318af22085cSThies C. Arntzen		return_value->value.str.len = 0;  	\
3191f793fd0SStanislav Malyshev		return_value->value.str.val = empty_string; \
320af22085cSThies C. Arntzen		return_value->type = IS_STRING;		\
321af22085cSThies C. Arntzen	}
322af22085cSThies C. Arntzen
3231f985edeSZeev Suraski#define RETVAL_FALSE  { return_value->value.lval = 0;  return_value->type = IS_BOOL; }
3241f985edeSZeev Suraski#define RETVAL_TRUE   { return_value->value.lval = 1;  return_value->type = IS_BOOL; }
3251f985edeSZeev Suraski
326eb5c6da5SThies C. Arntzen#define RETURN_RESOURCE(l) {			\
327eb5c6da5SThies C. Arntzen		return_value->type = IS_RESOURCE;\
328eb5c6da5SThies C. Arntzen		return_value->value.lval = l;	\
329eb5c6da5SThies C. Arntzen		return;							\
330eb5c6da5SThies C. Arntzen	}
3311fe57c95SZeev Suraski
3321fe57c95SZeev Suraski#define RETURN_BOOL(b) {				\
3331fe57c95SZeev Suraski		return_value->type = IS_BOOL;	\
3341fe57c95SZeev Suraski		return_value->value.lval = b;	\
3351fe57c95SZeev Suraski		return;							\
3361fe57c95SZeev Suraski	}
3371fe57c95SZeev Suraski
338fb6a1b8bSThies C. Arntzen#define RETURN_NULL() {				\
339bdefd5daSAndi Gutmans		return_value->type = IS_NULL;	\
340f2d703e9SZeev Suraski		return;							\
341f2d703e9SZeev Suraski	}
342f2d703e9SZeev Suraski
3431f985edeSZeev Suraski#define RETURN_LONG(l) {				\
3441f985edeSZeev Suraski		return_value->type = IS_LONG;	\
3451f985edeSZeev Suraski		return_value->value.lval = l;	\
3461f985edeSZeev Suraski		return;							\
3471f985edeSZeev Suraski	}
3481f985edeSZeev Suraski#define RETURN_DOUBLE(d) {				\
3491f985edeSZeev Suraski		return_value->type = IS_DOUBLE;	\
3501f985edeSZeev Suraski		return_value->value.dval = d;	\
3511f985edeSZeev Suraski		return;							\
3521f985edeSZeev Suraski	}
3531f985edeSZeev Suraski#define RETURN_STRING(s,duplicate) {	\
3541f985edeSZeev Suraski		char *__s=(s);					\
3551f985edeSZeev Suraski		return_value->value.str.len = strlen(__s);	\
3561f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,return_value->value.str.len):__s);	\
3571f985edeSZeev Suraski		return_value->type = IS_STRING;	\
3581f985edeSZeev Suraski		return;							\
3591f985edeSZeev Suraski	}
3601f985edeSZeev Suraski#define RETURN_STRINGL(s,l,duplicate) {		\
3611f985edeSZeev Suraski		char *__s=(s); int __l=l;			\
3621f985edeSZeev Suraski		return_value->value.str.len = __l;	\
3631f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
3641f985edeSZeev Suraski      	return_value->type = IS_STRING;		\
3651f985edeSZeev Suraski		return;								\
3661f985edeSZeev Suraski	}
3671f985edeSZeev Suraski
368af22085cSThies C. Arntzen#define RETURN_EMPTY_STRING() {	            \
369af22085cSThies C. Arntzen		return_value->value.str.len = 0;  	\
3701f793fd0SStanislav Malyshev		return_value->value.str.val = empty_string; \
371af22085cSThies C. Arntzen		return_value->type = IS_STRING;		\
372af22085cSThies C. Arntzen        return;                             \
373af22085cSThies C. Arntzen	}
374af22085cSThies C. Arntzen
3751f985edeSZeev Suraski#define RETURN_FALSE  { RETVAL_FALSE; return; }
3761f985edeSZeev Suraski#define RETURN_TRUE   { RETVAL_TRUE; return; }
3771f985edeSZeev Suraski
37848ffdd79SZeev Suraski#define SET_VAR_STRING(n,v)	{																				\
37948ffdd79SZeev Suraski								{																			\
380235386b2SZeev Suraski									zval *var;																\
38148ffdd79SZeev Suraski									char *str=(v); /* prevent 'v' from being evaluated more than once */	\
38248ffdd79SZeev Suraski																											\
383235386b2SZeev Suraski									ALLOC_ZVAL(var);														\
38448ffdd79SZeev Suraski									var->value.str.val = (str);												\
38548ffdd79SZeev Suraski									var->value.str.len = strlen((str));										\
38648ffdd79SZeev Suraski									var->type = IS_STRING;													\
3876393ab14SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);											\
38848ffdd79SZeev Suraski								}																			\
3891f985edeSZeev Suraski							}
39048ffdd79SZeev Suraski
39148ffdd79SZeev Suraski#define SET_VAR_STRINGL(n,v,l)	{														\
39248ffdd79SZeev Suraski									{													\
393235386b2SZeev Suraski										zval *var;										\
39448ffdd79SZeev Suraski																						\
395235386b2SZeev Suraski										ALLOC_ZVAL(var);								\
39648ffdd79SZeev Suraski										var->value.str.val = (v);						\
39748ffdd79SZeev Suraski										var->value.str.len = (l);						\
39848ffdd79SZeev Suraski										var->type = IS_STRING;							\
39948ffdd79SZeev Suraski										ZEND_SET_GLOBAL_VAR(n, var);					\
40048ffdd79SZeev Suraski									}													\
4011f985edeSZeev Suraski								}
40248ffdd79SZeev Suraski
40348ffdd79SZeev Suraski#define SET_VAR_LONG(n,v)	{															\
40448ffdd79SZeev Suraski								{														\
405235386b2SZeev Suraski									zval *var;											\
40648ffdd79SZeev Suraski																						\
407235386b2SZeev Suraski									ALLOC_ZVAL(var);									\
40848ffdd79SZeev Suraski									var->value.lval = (v);								\
40948ffdd79SZeev Suraski									var->type = IS_LONG;								\
41048ffdd79SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);						\
41148ffdd79SZeev Suraski								}														\
4121f985edeSZeev Suraski							}
41348ffdd79SZeev Suraski
41448ffdd79SZeev Suraski#define SET_VAR_DOUBLE(n,v)	{															\
41548ffdd79SZeev Suraski								{														\
416235386b2SZeev Suraski									zval *var;											\
41748ffdd79SZeev Suraski																						\
418235386b2SZeev Suraski									ALLOC_ZVAL(var);									\
41948ffdd79SZeev Suraski									var->value.dval = (v);								\
42048ffdd79SZeev Suraski									var->type = IS_DOUBLE;								\
42148ffdd79SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);						\
42248ffdd79SZeev Suraski								}														\
4231f985edeSZeev Suraski							}
4241f985edeSZeev Suraski
4251f985edeSZeev Suraski
426c34560b5SAndi Gutmans#define ZEND_SET_SYMBOL(symtable, name, var)										\
427c34560b5SAndi Gutmans	{																				\
428c34560b5SAndi Gutmans		char *_name = (name);														\
429c34560b5SAndi Gutmans																					\
4304c8259b5SAndi Gutmans		ZEND_SET_SYMBOL_WITH_LENGTH(symtable, _name, strlen(_name)+1, var, 1, 0);	\
43148ffdd79SZeev Suraski	}
43248ffdd79SZeev Suraski
433c34560b5SAndi Gutmans#define ZEND_SET_SYMBOL_WITH_LENGTH(symtable, name, name_length, var, _refcount, _is_ref)				\
43448ffdd79SZeev Suraski	{																									\
43548ffdd79SZeev Suraski		zval **orig_var;																				\
43648ffdd79SZeev Suraski																										\
437620d0134SZeev Suraski		if (zend_hash_find(symtable, (name), (name_length), (void **) &orig_var)==SUCCESS				\
43848ffdd79SZeev Suraski			&& PZVAL_IS_REF(*orig_var)) {																\
439158088caSZeev Suraski			(var)->refcount = (*orig_var)->refcount;													\
44052a30fd2SAndrei Zmievski			(var)->is_ref = 1;																			\
44148ffdd79SZeev Suraski																										\
4422ddc4fe4SZeev Suraski			if (_refcount) {																			\
4432ddc4fe4SZeev Suraski				(var)->refcount += _refcount-1;															\
4442ddc4fe4SZeev Suraski			}																							\
44548ffdd79SZeev Suraski			zval_dtor(*orig_var);																		\
446158088caSZeev Suraski			**orig_var = *(var);																		\
44762b2087aSAndi Gutmans			FREE_ZVAL(var);																					\
44848ffdd79SZeev Suraski		} else {																						\
4492f5efbdeSAndi Gutmans			(var)->is_ref = _is_ref;																	\
450158088caSZeev Suraski			if (_refcount) {																			\
451158088caSZeev Suraski				(var)->refcount = _refcount;															\
452158088caSZeev Suraski			}																							\
453158088caSZeev Suraski			zend_hash_update(symtable, (name), (name_length), &(var), sizeof(zval *), NULL);			\
45448ffdd79SZeev Suraski		}																								\
45548ffdd79SZeev Suraski	}
45648ffdd79SZeev Suraski
457620d0134SZeev Suraski
458620d0134SZeev Suraski#define ZEND_SET_GLOBAL_VAR(name, var)				\
459620d0134SZeev Suraski	ZEND_SET_SYMBOL(&EG(symbol_table), name, var)
460620d0134SZeev Suraski
461e3450661SAndrei Zmievski#define ZEND_SET_GLOBAL_VAR_WITH_LENGTH(name, name_length, var, _refcount, _is_ref)		\
462e3450661SAndrei Zmievski	ZEND_SET_SYMBOL_WITH_LENGTH(&EG(symbol_table), name, name_length, var, _refcount, _is_ref)
463fec413c5SAndrei Zmievski
46406a18f16SAndi Gutmans#define HASH_OF(p) ((p)->type==IS_ARRAY ? (p)->value.ht : (((p)->type==IS_OBJECT ? (p)->value.obj.properties : NULL)))
465af22085cSThies C. Arntzen#define ZVAL_IS_NULL(z) ((z)->type==IS_NULL)
46606a18f16SAndi Gutmans
467b982307dSSascha Schumann#endif /* ZEND_API_H */
468573b4602SAndi Gutmans
469573b4602SAndi Gutmans/*
470573b4602SAndi Gutmans * Local variables:
471573b4602SAndi Gutmans * tab-width: 4
472573b4602SAndi Gutmans * c-basic-offset: 4
473573b4602SAndi Gutmans * End:
474573b4602SAndi Gutmans */
475