zend_API.h revision 2c254ba7
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)	\
712c254ba7SZeev Suraski	ts_allocate_id(&module_name##_globals_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
244bcddfd47SThies C. Arntzen#if ZEND_DEBUG
245bcddfd47SThies C. Arntzen#define CHECK_ZVAL_STRING(z) \
24643ebb868SZeev Suraski	if ((z)->value.str.val[ (z)->value.str.len ] != '\0') zend_error(E_WARNING, "String is not zero-terminated (%s)", (z)->value.str.val);
24743ebb868SZeev Suraski#define CHECK_ZVAL_STRING_REL(z) \
24843ebb868SZeev Suraski	if ((z)->value.str.val[ (z)->value.str.len ] != '\0') zend_error(E_WARNING, "String is not zero-terminated (%s) (source: %s:%d)", (z)->value.str.val ZEND_FILE_LINE_RELAY_CC);
249bcddfd47SThies C. Arntzen#else
250bcddfd47SThies C. Arntzen#define CHECK_ZVAL_STRING(z)
25143ebb868SZeev Suraski#define CHECK_ZVAL_STRING_REL(z)
252bcddfd47SThies C. Arntzen#endif
253bcddfd47SThies C. Arntzen
254af22085cSThies C. Arntzen#define ZVAL_RESOURCE(z,l) {			\
255af22085cSThies C. Arntzen		(z)->type = IS_RESOURCE;        \
256af22085cSThies C. Arntzen		(z)->value.lval = l;	        \
257af22085cSThies C. Arntzen	}
258bcddfd47SThies C. Arntzen
259af22085cSThies C. Arntzen#define ZVAL_BOOL(z,b) {				\
260af22085cSThies C. Arntzen		(z)->type = IS_BOOL;	        \
261af22085cSThies C. Arntzen		(z)->value.lval = b;	        \
262af22085cSThies C. Arntzen	}
263bcddfd47SThies C. Arntzen
264af22085cSThies C. Arntzen#define ZVAL_NULL(z) {					\
265af22085cSThies C. Arntzen		(z)->type = IS_NULL;	        \
266af22085cSThies C. Arntzen	}
267bcddfd47SThies C. Arntzen
268af22085cSThies C. Arntzen#define ZVAL_LONG(z,l) {				\
269af22085cSThies C. Arntzen		(z)->type = IS_LONG;	        \
270af22085cSThies C. Arntzen		(z)->value.lval = l;	        \
271af22085cSThies C. Arntzen	}
272bcddfd47SThies C. Arntzen
273af22085cSThies C. Arntzen#define ZVAL_DOUBLE(z,d) {				\
274af22085cSThies C. Arntzen		(z)->type = IS_DOUBLE;	        \
275af22085cSThies C. Arntzen		(z)->value.dval = d;	        \
276af22085cSThies C. Arntzen	}
277bcddfd47SThies C. Arntzen
278af22085cSThies C. Arntzen#define ZVAL_STRING(z,s,duplicate) {	\
279af22085cSThies C. Arntzen		char *__s=(s);					\
280af22085cSThies C. Arntzen		(z)->value.str.len = strlen(__s);	\
281af22085cSThies C. Arntzen		(z)->value.str.val = (duplicate?estrndup(__s,(z)->value.str.len):__s);	\
282af22085cSThies C. Arntzen		(z)->type = IS_STRING;	        \
283af22085cSThies C. Arntzen	}
284bcddfd47SThies C. Arntzen
285af22085cSThies C. Arntzen#define ZVAL_STRINGL(z,s,l,duplicate) {	\
286af22085cSThies C. Arntzen		char *__s=(s); int __l=l;		\
287af22085cSThies C. Arntzen		(z)->value.str.len = __l;	    \
288af22085cSThies C. Arntzen		(z)->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
289af22085cSThies C. Arntzen		(z)->type = IS_STRING;		    \
290af22085cSThies C. Arntzen	}
291af22085cSThies C. Arntzen
292af22085cSThies C. Arntzen#define ZVAL_EMPTY_STRING(z) {	        \
293af22085cSThies C. Arntzen		(z)->value.str.len = 0;  	    \
2941f793fd0SStanislav Malyshev		(z)->value.str.val = empty_string; \
295af22085cSThies C. Arntzen		(z)->type = IS_STRING;		    \
296af22085cSThies C. Arntzen	}
297af22085cSThies C. Arntzen
29807ea0684SThies C. Arntzen#define ZVAL_FALSE(z)  					ZVAL_BOOL(z,0)
29907ea0684SThies C. Arntzen#define ZVAL_TRUE(z)  					ZVAL_BOOL(z,1)
300af22085cSThies C. Arntzen
301bcddfd47SThies C. Arntzen#define RETVAL_RESOURCE(l)				ZVAL_RESOURCE(return_value,l)
302bcddfd47SThies C. Arntzen#define RETVAL_BOOL(b)					ZVAL_BOOL(return_value,b)
303bcddfd47SThies C. Arntzen#define RETVAL_NULL() 					ZVAL_NULL(return_value)
304bcddfd47SThies C. Arntzen#define RETVAL_LONG(l) 					ZVAL_LONG(return_value,l)
305bcddfd47SThies C. Arntzen#define RETVAL_DOUBLE(d) 				ZVAL_DOUBLE(return_value,d)
306bcddfd47SThies C. Arntzen#define RETVAL_STRING(s,duplicate) 		ZVAL_STRING(return_value,s,duplicate)
307bcddfd47SThies C. Arntzen#define RETVAL_STRINGL(s,l,duplicate) 	ZVAL_STRINGL(return_value,s,l,duplicate)
308bcddfd47SThies C. Arntzen#define RETVAL_EMPTY_STRING() 			ZVAL_EMPTY_STRING(return_value)
309bcddfd47SThies C. Arntzen#define RETVAL_FALSE  					ZVAL_BOOL(return_value,0)
310bcddfd47SThies C. Arntzen#define RETVAL_TRUE   					ZVAL_BOOL(return_value,1)
311bcddfd47SThies C. Arntzen
312bcddfd47SThies C. Arntzen#define RETURN_RESOURCE(l) 				{ RETVAL_RESOURCE(l); return; }
313bcddfd47SThies C. Arntzen#define RETURN_BOOL(b) 					{ RETVAL_BOOL(b); return; }
314bcddfd47SThies C. Arntzen#define RETURN_NULL() 					{ RETVAL_NULL(); return;}
315bcddfd47SThies C. Arntzen#define RETURN_LONG(l) 					{ RETVAL_LONG(l); return; }
316bcddfd47SThies C. Arntzen#define RETURN_DOUBLE(d) 				{ RETVAL_DOUBLE(d); return; }
317bcddfd47SThies C. Arntzen#define RETURN_STRING(s,duplicate) 		{ RETVAL_STRING(s,duplicate); return; }
318bcddfd47SThies C. Arntzen#define RETURN_STRINGL(s,l,duplicate) 	{ RETVAL_STRINGL(s,l,duplicate); return; }
319bcddfd47SThies C. Arntzen#define RETURN_EMPTY_STRING() 			{ RETVAL_EMPTY_STRING(); return; }
320bcddfd47SThies C. Arntzen#define RETURN_FALSE  					{ RETVAL_FALSE; return; }
321bcddfd47SThies C. Arntzen#define RETURN_TRUE   					{ RETVAL_TRUE; return; }
3221f985edeSZeev Suraski
32348ffdd79SZeev Suraski#define SET_VAR_STRING(n,v)	{																				\
32448ffdd79SZeev Suraski								{																			\
325235386b2SZeev Suraski									zval *var;																\
326235386b2SZeev Suraski									ALLOC_ZVAL(var);														\
327bcddfd47SThies C. Arntzen									ZVAL_STRING(var,v,0);													\
3286393ab14SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);											\
32948ffdd79SZeev Suraski								}																			\
3301f985edeSZeev Suraski							}
33148ffdd79SZeev Suraski
33248ffdd79SZeev Suraski#define SET_VAR_STRINGL(n,v,l)	{														\
33348ffdd79SZeev Suraski									{													\
334235386b2SZeev Suraski										zval *var;										\
335235386b2SZeev Suraski										ALLOC_ZVAL(var);								\
336bcddfd47SThies C. Arntzen										ZVAL_STRINGL(var,v,l,0);						\
33748ffdd79SZeev Suraski										ZEND_SET_GLOBAL_VAR(n, var);					\
33848ffdd79SZeev Suraski									}													\
3391f985edeSZeev Suraski								}
34048ffdd79SZeev Suraski
34148ffdd79SZeev Suraski#define SET_VAR_LONG(n,v)	{															\
34248ffdd79SZeev Suraski								{														\
343235386b2SZeev Suraski									zval *var;											\
344235386b2SZeev Suraski									ALLOC_ZVAL(var);									\
345bcddfd47SThies C. Arntzen									ZVAL_LONG(var,v);									\
34648ffdd79SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);						\
34748ffdd79SZeev Suraski								}														\
3481f985edeSZeev Suraski							}
34948ffdd79SZeev Suraski
35048ffdd79SZeev Suraski#define SET_VAR_DOUBLE(n,v)	{															\
35148ffdd79SZeev Suraski								{														\
352235386b2SZeev Suraski									zval *var;											\
353235386b2SZeev Suraski									ALLOC_ZVAL(var);									\
354bcddfd47SThies C. Arntzen									ZVAL_DOUBLE(var,v);									\
35548ffdd79SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);						\
35648ffdd79SZeev Suraski								}														\
3571f985edeSZeev Suraski							}
3581f985edeSZeev Suraski
3591f985edeSZeev Suraski
360c34560b5SAndi Gutmans#define ZEND_SET_SYMBOL(symtable, name, var)										\
361c34560b5SAndi Gutmans	{																				\
362c34560b5SAndi Gutmans		char *_name = (name);														\
363c34560b5SAndi Gutmans																					\
3644c8259b5SAndi Gutmans		ZEND_SET_SYMBOL_WITH_LENGTH(symtable, _name, strlen(_name)+1, var, 1, 0);	\
36548ffdd79SZeev Suraski	}
36648ffdd79SZeev Suraski
367c34560b5SAndi Gutmans#define ZEND_SET_SYMBOL_WITH_LENGTH(symtable, name, name_length, var, _refcount, _is_ref)				\
36848ffdd79SZeev Suraski	{																									\
36948ffdd79SZeev Suraski		zval **orig_var;																				\
37048ffdd79SZeev Suraski																										\
371620d0134SZeev Suraski		if (zend_hash_find(symtable, (name), (name_length), (void **) &orig_var)==SUCCESS				\
37248ffdd79SZeev Suraski			&& PZVAL_IS_REF(*orig_var)) {																\
373158088caSZeev Suraski			(var)->refcount = (*orig_var)->refcount;													\
37452a30fd2SAndrei Zmievski			(var)->is_ref = 1;																			\
37548ffdd79SZeev Suraski																										\
3762ddc4fe4SZeev Suraski			if (_refcount) {																			\
3772ddc4fe4SZeev Suraski				(var)->refcount += _refcount-1;															\
3782ddc4fe4SZeev Suraski			}																							\
37948ffdd79SZeev Suraski			zval_dtor(*orig_var);																		\
380158088caSZeev Suraski			**orig_var = *(var);																		\
38162b2087aSAndi Gutmans			FREE_ZVAL(var);																					\
38248ffdd79SZeev Suraski		} else {																						\
3832f5efbdeSAndi Gutmans			(var)->is_ref = _is_ref;																	\
384158088caSZeev Suraski			if (_refcount) {																			\
385158088caSZeev Suraski				(var)->refcount = _refcount;															\
386158088caSZeev Suraski			}																							\
387158088caSZeev Suraski			zend_hash_update(symtable, (name), (name_length), &(var), sizeof(zval *), NULL);			\
38848ffdd79SZeev Suraski		}																								\
38948ffdd79SZeev Suraski	}
39048ffdd79SZeev Suraski
391620d0134SZeev Suraski
392620d0134SZeev Suraski#define ZEND_SET_GLOBAL_VAR(name, var)				\
393620d0134SZeev Suraski	ZEND_SET_SYMBOL(&EG(symbol_table), name, var)
394620d0134SZeev Suraski
395e3450661SAndrei Zmievski#define ZEND_SET_GLOBAL_VAR_WITH_LENGTH(name, name_length, var, _refcount, _is_ref)		\
396e3450661SAndrei Zmievski	ZEND_SET_SYMBOL_WITH_LENGTH(&EG(symbol_table), name, name_length, var, _refcount, _is_ref)
397fec413c5SAndrei Zmievski
39806a18f16SAndi Gutmans#define HASH_OF(p) ((p)->type==IS_ARRAY ? (p)->value.ht : (((p)->type==IS_OBJECT ? (p)->value.obj.properties : NULL)))
399af22085cSThies C. Arntzen#define ZVAL_IS_NULL(z) ((z)->type==IS_NULL)
40006a18f16SAndi Gutmans
401b982307dSSascha Schumann#endif /* ZEND_API_H */
402573b4602SAndi Gutmans
403573b4602SAndi Gutmans/*
404573b4602SAndi Gutmans * Local variables:
405573b4602SAndi Gutmans * tab-width: 4
406573b4602SAndi Gutmans * c-basic-offset: 4
407573b4602SAndi Gutmans * End:
408573b4602SAndi Gutmans */
409