zend_API.h revision b5255495
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
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)
51342c6e0bSZeev Suraski
520b6d923bSSascha Schumann#define ZEND_GET_MODULE(name) \
530b6d923bSSascha Schumann	ZEND_DLEXPORT zend_module_entry *get_module(void) { return &name##_module_entry; }
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)							\
6302af513cSAndi Gutmans	ts_rsrc_id module_name##_globals_id;
6402af513cSAndi Gutmans#define ZEND_EXTERN_MODULE_GLOBALS(module_name)								\
6502af513cSAndi Gutmans	extern ts_rsrc_id module_name##_globals_id;
660d21940dSZeev Suraski#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
672c254ba7SZeev Suraski	ts_allocate_id(&module_name##_globals_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)							\
7202af513cSAndi Gutmans	zend_##module_name##_globals module_name##_globals;
7302af513cSAndi Gutmans#define ZEND_EXTERN_MODULE_GLOBALS(module_name)								\
7402af513cSAndi Gutmans	extern zend_##module_name##_globals module_name##_globals;
750d21940dSZeev Suraski#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
760d21940dSZeev Suraski	globals_ctor(&module_name##_globals);
770d21940dSZeev Suraski
780d21940dSZeev Suraski#endif
790d21940dSZeev Suraski
800d21940dSZeev Suraski
810d21940dSZeev Suraski
82741b8161SZeev Suraski#define INIT_CLASS_ENTRY(class_container, class_name, functions)	\
83741b8161SZeev Suraski	{																\
84741b8161SZeev Suraski		class_container.name = strdup(class_name);					\
85741b8161SZeev Suraski		class_container.name_length = sizeof(class_name)-1;			\
86741b8161SZeev Suraski		class_container.builtin_functions = functions;				\
87741b8161SZeev Suraski		class_container.handle_function_call = NULL;				\
88741b8161SZeev Suraski		class_container.handle_property_get = NULL;					\
89741b8161SZeev Suraski		class_container.handle_property_set = NULL;					\
90741b8161SZeev Suraski	}
91741b8161SZeev Suraski
92741b8161SZeev Suraski#define INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset) \
93741b8161SZeev Suraski	{															\
94741b8161SZeev Suraski		class_container.name = strdup(class_name);				\
95741b8161SZeev Suraski		class_container.name_length = sizeof(class_name)-1;		\
96741b8161SZeev Suraski		class_container.builtin_functions = functions;			\
97741b8161SZeev Suraski		class_container.handle_function_call = handle_fcall;	\
98741b8161SZeev Suraski		class_container.handle_property_get = handle_propget;	\
99741b8161SZeev Suraski		class_container.handle_property_set = handle_propset;	\
100741b8161SZeev Suraski	}
101741b8161SZeev Suraski
102741b8161SZeev Suraski
103741b8161SZeev Suraski
104573b4602SAndi Gutmansint zend_next_free_module(void);
105573b4602SAndi Gutmans
106f77e6a44SZeev SuraskiZEND_API int zend_get_parameters(int ht, int param_count, ...);
10711e5d2f2SZeev SuraskiZEND_API int _zend_get_parameters_array(int ht, int param_count, zval **argument_array TSRMLS_DC);
108f77e6a44SZeev SuraskiZEND_API int zend_get_parameters_ex(int param_count, ...);
10911e5d2f2SZeev SuraskiZEND_API int _zend_get_parameters_array_ex(int param_count, zval ***argument_array TSRMLS_DC);
11011e5d2f2SZeev Suraski
11111e5d2f2SZeev Suraski#define zend_get_parameters_array(ht, param_count, argument_array)			\
11211e5d2f2SZeev Suraski	_zend_get_parameters_array(ht, param_count, argument_array TSRMLS_CC)
11311e5d2f2SZeev Suraski#define zend_get_parameters_array_ex(param_count, argument_array)			\
11411e5d2f2SZeev Suraski	_zend_get_parameters_array_ex(param_count, argument_array TSRMLS_CC)
11539f9487eSAndi Gutmans
11658f88057SAndrei Zmievski
11758f88057SAndrei Zmievski/* Parameter parsing API -- andrei */
11858f88057SAndrei Zmievski
11958f88057SAndrei Zmievski#define ZEND_PARSE_PARAMS_QUIET 1<<1
1208ce8324eSZeev SuraskiZEND_API int zend_parse_parameters(int num_args TSRMLS_DC, char *type_spec, ...);
1213839af35SAndrei ZmievskiZEND_API int zend_parse_parameters_ex(int flags, int num_args TSRMLS_DC, char *type_spec, ...);
12258f88057SAndrei Zmievski
123b5255495SZeev Suraski/* End of parameter parsing API -- andrei */
12439f9487eSAndi Gutmans
125b5770382SZeev Suraskiint zend_register_functions(zend_function_entry *functions, HashTable *function_table, int type TSRMLS_DC);
126b5770382SZeev Suraskivoid zend_unregister_functions(zend_function_entry *functions, int count, HashTable *function_table TSRMLS_DC);
1277a87fcbbSZeev SuraskiZEND_API int zend_register_module(zend_module_entry *module_entry);
128eb0e6946SAndi Gutmans
129b5770382SZeev SuraskiZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry TSRMLS_DC);
130b5770382SZeev SuraskiZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce, char *parent_name TSRMLS_DC);
131eb0e6946SAndi Gutmans
132bfbe8618SZeev SuraskiZEND_API zend_module_entry *zend_get_module(int module_number);
133bc7abb33SZeev SuraskiZEND_API int zend_disable_function(char *function_name, uint function_name_length);
134573b4602SAndi Gutmans
135573b4602SAndi GutmansZEND_API void wrong_param_count(void);
13613148b54SAndrei ZmievskiZEND_API zend_bool zend_is_callable(zval *callable, zend_bool syntax_only, char **callable_name);
137573b4602SAndi Gutmans
138741b8161SZeev Suraski#define getThis() (this_ptr)
139741b8161SZeev Suraski
140131d9cb2SZeev Suraski#define WRONG_PARAM_COUNT					ZEND_WRONG_PARAM_COUNT()
141131d9cb2SZeev Suraski#define WRONG_PARAM_COUNT_WITH_RETVAL(ret)	ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)
142a1ad2872SZeev Suraski#define ARG_COUNT(dummy)	(ht)
143a1ad2872SZeev Suraski#define ZEND_NUM_ARGS()		(ht)
144131d9cb2SZeev Suraski#define ZEND_WRONG_PARAM_COUNT()					{ wrong_param_count(); return; }
145131d9cb2SZeev Suraski#define ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)		{ wrong_param_count(); return ret; }
146573b4602SAndi Gutmans
14780bdd19eSZeev Suraski#ifndef ZEND_WIN32
148573b4602SAndi Gutmans#define DLEXPORT
149573b4602SAndi Gutmans#endif
150573b4602SAndi Gutmans
151e0628436SAndrei ZmievskiZEND_API int zend_startup_module(zend_module_entry *module);
152573b4602SAndi Gutmans
153ceba50b6SZeev Suraski#define array_init(arg)			_array_init((arg) ZEND_FILE_LINE_CC)
154ceba50b6SZeev Suraski#define object_init(arg)		_object_init((arg) ZEND_FILE_LINE_CC)
155ceba50b6SZeev Suraski#define object_init_ex(arg, ce)	_object_init_ex((arg), (ce) ZEND_FILE_LINE_CC)
156ceba50b6SZeev SuraskiZEND_API int _array_init(zval *arg ZEND_FILE_LINE_DC);
157ceba50b6SZeev SuraskiZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC);
158ceba50b6SZeev SuraskiZEND_API int _object_init_ex(zval *arg, zend_class_entry *ce ZEND_FILE_LINE_DC);
1596847fefaSThies C. Arntzen
1606847fefaSThies C. Arntzen/* no longer supported */
1616847fefaSThies C. ArntzenZEND_API int add_assoc_function(zval *arg, char *key,void (*function_ptr)(INTERNAL_FUNCTION_PARAMETERS));
1626847fefaSThies C. Arntzen
163ef95a346SAndi GutmansZEND_API int add_assoc_long_ex(zval *arg, char *key, uint key_len, long n);
1640611acb9SAndi GutmansZEND_API int add_assoc_null_ex(zval *arg, char *key, uint key_len);
165ef95a346SAndi GutmansZEND_API int add_assoc_bool_ex(zval *arg, char *key, uint key_len, int b);
166ef95a346SAndi GutmansZEND_API int add_assoc_resource_ex(zval *arg, char *key, uint key_len, int r);
167ef95a346SAndi GutmansZEND_API int add_assoc_double_ex(zval *arg, char *key, uint key_len, double d);
168ef95a346SAndi GutmansZEND_API int add_assoc_string_ex(zval *arg, char *key, uint key_len, char *str, int duplicate);
169ef95a346SAndi GutmansZEND_API int add_assoc_stringl_ex(zval *arg, char *key, uint key_len, char *str, uint length, int duplicate);
170ef95a346SAndi GutmansZEND_API int add_assoc_zval_ex(zval *arg, char *key, uint key_len, zval *value);
171ef95a346SAndi Gutmans
172ef95a346SAndi Gutmans#define add_assoc_long(__arg, __key, __n) add_assoc_long_ex(__arg, __key, strlen(__key)+1, __n)
1730611acb9SAndi Gutmans#define add_assoc_null(__arg, __key) add_assoc_null_ex(__arg, __key, strlen(__key) + 1)
174ef95a346SAndi Gutmans#define add_assoc_bool(__arg, __key, __b) add_assoc_bool_ex(__arg, __key, strlen(__key)+1, __b)
175ef95a346SAndi Gutmans#define add_assoc_resource(__arg, __key, __r) add_assoc_resource_ex(__arg, __key, strlen(__key)+1, __r)
176ef95a346SAndi Gutmans#define add_assoc_double(__arg, __key, __d) add_assoc_double_ex(__arg, __key, strlen(__key)+1, __d)
177ef95a346SAndi Gutmans#define add_assoc_string(__arg, __key, __str, __duplicate) add_assoc_string_ex(__arg, __key, strlen(__key)+1, __str, __duplicate)
178ef95a346SAndi Gutmans#define add_assoc_stringl(__arg, __key, __str, __length, __duplicate) add_assoc_stringl_ex(__arg, __key, strlen(__key)+1, __str, __length, __duplicate)
179ef95a346SAndi Gutmans#define add_assoc_zval(__arg, __key, __value) add_assoc_zval_ex(__arg, __key, strlen(__key)+1, __value)
1806847fefaSThies C. Arntzen
1810611acb9SAndi Gutmans/* unset() functions are only suported for legacy modules and null() functions should be used */
1820611acb9SAndi Gutmans#define add_assoc_unset(__arg, __key) add_assoc_null_ex(__arg, __key, strlen(__key) + 1)
1830611acb9SAndi Gutmans#define add_index_unset(__arg, __key) add_index_null(__arg, __key)
1840611acb9SAndi Gutmans#define add_next_index_unset(__arg) add_next_index_null(__arg)
1850611acb9SAndi Gutmans#define add_property_unset(__arg, __key) add_property_null(__arg, __key)
1860611acb9SAndi Gutmans
187573b4602SAndi GutmansZEND_API int add_index_long(zval *arg, uint idx, long n);
1880611acb9SAndi GutmansZEND_API int add_index_null(zval *arg, uint idx);
1896847fefaSThies C. ArntzenZEND_API int add_index_bool(zval *arg, uint idx, int b);
1906847fefaSThies C. ArntzenZEND_API int add_index_resource(zval *arg, uint idx, int r);
191573b4602SAndi GutmansZEND_API int add_index_double(zval *arg, uint idx, double d);
192573b4602SAndi GutmansZEND_API int add_index_string(zval *arg, uint idx, char *str, int duplicate);
193573b4602SAndi GutmansZEND_API int add_index_stringl(zval *arg, uint idx, char *str, uint length, int duplicate);
19457f99633SAndrei ZmievskiZEND_API int add_index_zval(zval *arg, uint index, zval *value);
1956847fefaSThies C. Arntzen
196573b4602SAndi GutmansZEND_API int add_next_index_long(zval *arg, long n);
1970611acb9SAndi GutmansZEND_API int add_next_index_null(zval *arg);
1986847fefaSThies C. ArntzenZEND_API int add_next_index_bool(zval *arg, int b);
1996847fefaSThies C. ArntzenZEND_API int add_next_index_resource(zval *arg, int r);
200573b4602SAndi GutmansZEND_API int add_next_index_double(zval *arg, double d);
201573b4602SAndi GutmansZEND_API int add_next_index_string(zval *arg, char *str, int duplicate);
202573b4602SAndi GutmansZEND_API int add_next_index_stringl(zval *arg, char *str, uint length, int duplicate);
203ef95a346SAndi GutmansZEND_API int add_next_index_zval(zval *arg, zval *value);
204ef95a346SAndi Gutmans
205ef95a346SAndi GutmansZEND_API int add_get_assoc_string_ex(zval *arg, char *key, uint key_len, char *str, void **dest, int duplicate);
206ef95a346SAndi GutmansZEND_API int add_get_assoc_stringl_ex(zval *arg, char *key, uint key_len, char *str, uint length, void **dest, int duplicate);
207ef95a346SAndi Gutmans
208ef95a346SAndi Gutmans#define add_get_assoc_string(__arg, __key, __str, __dest, __duplicate) add_get_assoc_string_ex(__arg, __key, strlen(__key)+1, __str, __dest, __duplicate)
209ef95a346SAndi 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)
210573b4602SAndi Gutmans
211573b4602SAndi GutmansZEND_API int add_get_index_long(zval *arg, uint idx, long l, void **dest);
212573b4602SAndi GutmansZEND_API int add_get_index_double(zval *arg, uint idx, double d, void **dest);
213573b4602SAndi GutmansZEND_API int add_get_index_string(zval *arg, uint idx, char *str, void **dest, int duplicate);
214573b4602SAndi GutmansZEND_API int add_get_index_stringl(zval *arg, uint idx, char *str, uint length, void **dest, int duplicate);
215573b4602SAndi Gutmans
216ef95a346SAndi GutmansZEND_API int add_property_long_ex(zval *arg, char *key, uint key_len, long l);
2170611acb9SAndi GutmansZEND_API int add_property_null_ex(zval *arg, char *key, uint key_len);
218ef95a346SAndi GutmansZEND_API int add_property_bool_ex(zval *arg, char *key, uint key_len, int b);
219ef95a346SAndi GutmansZEND_API int add_property_resource_ex(zval *arg, char *key, uint key_len, long r);
220ef95a346SAndi GutmansZEND_API int add_property_double_ex(zval *arg, char *key, uint key_len, double d);
221ef95a346SAndi GutmansZEND_API int add_property_string_ex(zval *arg, char *key, uint key_len, char *str, int duplicate);
222ef95a346SAndi GutmansZEND_API int add_property_stringl_ex(zval *arg, char *key, uint key_len,  char *str, uint length, int duplicate);
223ef95a346SAndi GutmansZEND_API int add_property_zval_ex(zval *arg, char *key, uint key_len, zval *value);
224ef95a346SAndi Gutmans
225ef95a346SAndi Gutmans#define add_property_long(__arg, __key, __n) add_property_long_ex(__arg, __key, strlen(__key)+1, __n)
2260611acb9SAndi Gutmans#define add_property_null(__arg, __key) add_property_null_ex(__arg, __key, strlen(__key) + 1)
227ef95a346SAndi Gutmans#define add_property_bool(__arg, __key, __b) add_property_bool_ex(__arg, __key, strlen(__key)+1, __b)
228ef95a346SAndi Gutmans#define add_property_resource(__arg, __key, __r) add_property_resource_ex(__arg, __key, strlen(__key)+1, __r)
229ef95a346SAndi Gutmans#define add_property_double(__arg, __key, __d) add_property_double_ex(__arg, __key, strlen(__key)+1, __d)
230ef95a346SAndi Gutmans#define add_property_string(__arg, __key, __str, __duplicate) add_property_string_ex(__arg, __key, strlen(__key)+1, __str, __duplicate)
231ef95a346SAndi Gutmans#define add_property_stringl(__arg, __key, __str, __length, __duplicate) add_property_stringl_ex(__arg, __key, strlen(__key)+1, __str, __length, __duplicate)
232ef95a346SAndi Gutmans#define add_property_zval(__arg, __key, __value) add_property_zval_ex(__arg, __key, strlen(__key)+1, __value)
233ef95a346SAndi Gutmans
234be895bcbSZeev SuraskiZEND_API int call_user_function(HashTable *function_table, zval **object_pp, zval *function_name, zval *retval_ptr, int param_count, zval *params[]);
235be895bcbSZeev 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);
236573b4602SAndi Gutmans
237f962a35dSAndrei ZmievskiZEND_API int zend_set_hash_symbol(zval *symbol, char *name, int name_length,
238f962a35dSAndrei Zmievski                                  int is_ref, int num_symbol_tables, ...);
239f962a35dSAndrei Zmievski
240573b4602SAndi Gutmans#define add_method(arg,key,method)	add_assoc_function((arg),(key),(method))
241573b4602SAndi Gutmans
242bcddfd47SThies C. Arntzen#if ZEND_DEBUG
243bcddfd47SThies C. Arntzen#define CHECK_ZVAL_STRING(z) \
24443ebb868SZeev 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);
24543ebb868SZeev Suraski#define CHECK_ZVAL_STRING_REL(z) \
24643ebb868SZeev 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);
247bcddfd47SThies C. Arntzen#else
248bcddfd47SThies C. Arntzen#define CHECK_ZVAL_STRING(z)
24943ebb868SZeev Suraski#define CHECK_ZVAL_STRING_REL(z)
250bcddfd47SThies C. Arntzen#endif
251bcddfd47SThies C. Arntzen
252af22085cSThies C. Arntzen#define ZVAL_RESOURCE(z,l) {			\
253af22085cSThies C. Arntzen		(z)->type = IS_RESOURCE;        \
254af22085cSThies C. Arntzen		(z)->value.lval = l;	        \
255af22085cSThies C. Arntzen	}
256bcddfd47SThies C. Arntzen
257af22085cSThies C. Arntzen#define ZVAL_BOOL(z,b) {				\
258af22085cSThies C. Arntzen		(z)->type = IS_BOOL;	        \
259af22085cSThies C. Arntzen		(z)->value.lval = b;	        \
260af22085cSThies C. Arntzen	}
261bcddfd47SThies C. Arntzen
262af22085cSThies C. Arntzen#define ZVAL_NULL(z) {					\
263af22085cSThies C. Arntzen		(z)->type = IS_NULL;	        \
264af22085cSThies C. Arntzen	}
265bcddfd47SThies C. Arntzen
266af22085cSThies C. Arntzen#define ZVAL_LONG(z,l) {				\
267af22085cSThies C. Arntzen		(z)->type = IS_LONG;	        \
268af22085cSThies C. Arntzen		(z)->value.lval = l;	        \
269af22085cSThies C. Arntzen	}
270bcddfd47SThies C. Arntzen
271af22085cSThies C. Arntzen#define ZVAL_DOUBLE(z,d) {				\
272af22085cSThies C. Arntzen		(z)->type = IS_DOUBLE;	        \
273af22085cSThies C. Arntzen		(z)->value.dval = d;	        \
274af22085cSThies C. Arntzen	}
275bcddfd47SThies C. Arntzen
276af22085cSThies C. Arntzen#define ZVAL_STRING(z,s,duplicate) {	\
277af22085cSThies C. Arntzen		char *__s=(s);					\
278af22085cSThies C. Arntzen		(z)->value.str.len = strlen(__s);	\
279af22085cSThies C. Arntzen		(z)->value.str.val = (duplicate?estrndup(__s,(z)->value.str.len):__s);	\
280af22085cSThies C. Arntzen		(z)->type = IS_STRING;	        \
281af22085cSThies C. Arntzen	}
282bcddfd47SThies C. Arntzen
283af22085cSThies C. Arntzen#define ZVAL_STRINGL(z,s,l,duplicate) {	\
284af22085cSThies C. Arntzen		char *__s=(s); int __l=l;		\
285af22085cSThies C. Arntzen		(z)->value.str.len = __l;	    \
286af22085cSThies C. Arntzen		(z)->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
287af22085cSThies C. Arntzen		(z)->type = IS_STRING;		    \
288af22085cSThies C. Arntzen	}
289af22085cSThies C. Arntzen
290af22085cSThies C. Arntzen#define ZVAL_EMPTY_STRING(z) {	        \
291af22085cSThies C. Arntzen		(z)->value.str.len = 0;  	    \
2921f793fd0SStanislav Malyshev		(z)->value.str.val = empty_string; \
293af22085cSThies C. Arntzen		(z)->type = IS_STRING;		    \
294af22085cSThies C. Arntzen	}
295af22085cSThies C. Arntzen
29607ea0684SThies C. Arntzen#define ZVAL_FALSE(z)  					ZVAL_BOOL(z,0)
29707ea0684SThies C. Arntzen#define ZVAL_TRUE(z)  					ZVAL_BOOL(z,1)
298af22085cSThies C. Arntzen
299bcddfd47SThies C. Arntzen#define RETVAL_RESOURCE(l)				ZVAL_RESOURCE(return_value,l)
300bcddfd47SThies C. Arntzen#define RETVAL_BOOL(b)					ZVAL_BOOL(return_value,b)
301bcddfd47SThies C. Arntzen#define RETVAL_NULL() 					ZVAL_NULL(return_value)
302bcddfd47SThies C. Arntzen#define RETVAL_LONG(l) 					ZVAL_LONG(return_value,l)
303bcddfd47SThies C. Arntzen#define RETVAL_DOUBLE(d) 				ZVAL_DOUBLE(return_value,d)
304bcddfd47SThies C. Arntzen#define RETVAL_STRING(s,duplicate) 		ZVAL_STRING(return_value,s,duplicate)
305bcddfd47SThies C. Arntzen#define RETVAL_STRINGL(s,l,duplicate) 	ZVAL_STRINGL(return_value,s,l,duplicate)
306bcddfd47SThies C. Arntzen#define RETVAL_EMPTY_STRING() 			ZVAL_EMPTY_STRING(return_value)
307bcddfd47SThies C. Arntzen#define RETVAL_FALSE  					ZVAL_BOOL(return_value,0)
308bcddfd47SThies C. Arntzen#define RETVAL_TRUE   					ZVAL_BOOL(return_value,1)
309bcddfd47SThies C. Arntzen
310bcddfd47SThies C. Arntzen#define RETURN_RESOURCE(l) 				{ RETVAL_RESOURCE(l); return; }
311bcddfd47SThies C. Arntzen#define RETURN_BOOL(b) 					{ RETVAL_BOOL(b); return; }
312bcddfd47SThies C. Arntzen#define RETURN_NULL() 					{ RETVAL_NULL(); return;}
313bcddfd47SThies C. Arntzen#define RETURN_LONG(l) 					{ RETVAL_LONG(l); return; }
314bcddfd47SThies C. Arntzen#define RETURN_DOUBLE(d) 				{ RETVAL_DOUBLE(d); return; }
315bcddfd47SThies C. Arntzen#define RETURN_STRING(s,duplicate) 		{ RETVAL_STRING(s,duplicate); return; }
316bcddfd47SThies C. Arntzen#define RETURN_STRINGL(s,l,duplicate) 	{ RETVAL_STRINGL(s,l,duplicate); return; }
317bcddfd47SThies C. Arntzen#define RETURN_EMPTY_STRING() 			{ RETVAL_EMPTY_STRING(); return; }
318bcddfd47SThies C. Arntzen#define RETURN_FALSE  					{ RETVAL_FALSE; return; }
319bcddfd47SThies C. Arntzen#define RETURN_TRUE   					{ RETVAL_TRUE; return; }
3201f985edeSZeev Suraski
32148ffdd79SZeev Suraski#define SET_VAR_STRING(n,v)	{																				\
32248ffdd79SZeev Suraski								{																			\
323235386b2SZeev Suraski									zval *var;																\
324235386b2SZeev Suraski									ALLOC_ZVAL(var);														\
325bcddfd47SThies C. Arntzen									ZVAL_STRING(var,v,0);													\
3266393ab14SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);											\
32748ffdd79SZeev Suraski								}																			\
3281f985edeSZeev Suraski							}
32948ffdd79SZeev Suraski
33048ffdd79SZeev Suraski#define SET_VAR_STRINGL(n,v,l)	{														\
33148ffdd79SZeev Suraski									{													\
332235386b2SZeev Suraski										zval *var;										\
333235386b2SZeev Suraski										ALLOC_ZVAL(var);								\
334bcddfd47SThies C. Arntzen										ZVAL_STRINGL(var,v,l,0);						\
33548ffdd79SZeev Suraski										ZEND_SET_GLOBAL_VAR(n, var);					\
33648ffdd79SZeev Suraski									}													\
3371f985edeSZeev Suraski								}
33848ffdd79SZeev Suraski
33948ffdd79SZeev Suraski#define SET_VAR_LONG(n,v)	{															\
34048ffdd79SZeev Suraski								{														\
341235386b2SZeev Suraski									zval *var;											\
342235386b2SZeev Suraski									ALLOC_ZVAL(var);									\
343bcddfd47SThies C. Arntzen									ZVAL_LONG(var,v);									\
34448ffdd79SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);						\
34548ffdd79SZeev Suraski								}														\
3461f985edeSZeev Suraski							}
34748ffdd79SZeev Suraski
34848ffdd79SZeev Suraski#define SET_VAR_DOUBLE(n,v)	{															\
34948ffdd79SZeev Suraski								{														\
350235386b2SZeev Suraski									zval *var;											\
351235386b2SZeev Suraski									ALLOC_ZVAL(var);									\
352bcddfd47SThies C. Arntzen									ZVAL_DOUBLE(var,v);									\
35348ffdd79SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);						\
35448ffdd79SZeev Suraski								}														\
3551f985edeSZeev Suraski							}
3561f985edeSZeev Suraski
3571f985edeSZeev Suraski
358c34560b5SAndi Gutmans#define ZEND_SET_SYMBOL(symtable, name, var)										\
359c34560b5SAndi Gutmans	{																				\
360c34560b5SAndi Gutmans		char *_name = (name);														\
361c34560b5SAndi Gutmans																					\
3624c8259b5SAndi Gutmans		ZEND_SET_SYMBOL_WITH_LENGTH(symtable, _name, strlen(_name)+1, var, 1, 0);	\
36348ffdd79SZeev Suraski	}
36448ffdd79SZeev Suraski
365c34560b5SAndi Gutmans#define ZEND_SET_SYMBOL_WITH_LENGTH(symtable, name, name_length, var, _refcount, _is_ref)				\
36648ffdd79SZeev Suraski	{																									\
36748ffdd79SZeev Suraski		zval **orig_var;																				\
36848ffdd79SZeev Suraski																										\
369620d0134SZeev Suraski		if (zend_hash_find(symtable, (name), (name_length), (void **) &orig_var)==SUCCESS				\
37048ffdd79SZeev Suraski			&& PZVAL_IS_REF(*orig_var)) {																\
371158088caSZeev Suraski			(var)->refcount = (*orig_var)->refcount;													\
37252a30fd2SAndrei Zmievski			(var)->is_ref = 1;																			\
37348ffdd79SZeev Suraski																										\
3742ddc4fe4SZeev Suraski			if (_refcount) {																			\
3752ddc4fe4SZeev Suraski				(var)->refcount += _refcount-1;															\
3762ddc4fe4SZeev Suraski			}																							\
37748ffdd79SZeev Suraski			zval_dtor(*orig_var);																		\
378158088caSZeev Suraski			**orig_var = *(var);																		\
37962b2087aSAndi Gutmans			FREE_ZVAL(var);																					\
38048ffdd79SZeev Suraski		} else {																						\
3812f5efbdeSAndi Gutmans			(var)->is_ref = _is_ref;																	\
382158088caSZeev Suraski			if (_refcount) {																			\
383158088caSZeev Suraski				(var)->refcount = _refcount;															\
384158088caSZeev Suraski			}																							\
385158088caSZeev Suraski			zend_hash_update(symtable, (name), (name_length), &(var), sizeof(zval *), NULL);			\
38648ffdd79SZeev Suraski		}																								\
38748ffdd79SZeev Suraski	}
38848ffdd79SZeev Suraski
389620d0134SZeev Suraski
390620d0134SZeev Suraski#define ZEND_SET_GLOBAL_VAR(name, var)				\
391620d0134SZeev Suraski	ZEND_SET_SYMBOL(&EG(symbol_table), name, var)
392620d0134SZeev Suraski
393e3450661SAndrei Zmievski#define ZEND_SET_GLOBAL_VAR_WITH_LENGTH(name, name_length, var, _refcount, _is_ref)		\
394e3450661SAndrei Zmievski	ZEND_SET_SYMBOL_WITH_LENGTH(&EG(symbol_table), name, name_length, var, _refcount, _is_ref)
395fec413c5SAndrei Zmievski
39606a18f16SAndi Gutmans#define HASH_OF(p) ((p)->type==IS_ARRAY ? (p)->value.ht : (((p)->type==IS_OBJECT ? (p)->value.obj.properties : NULL)))
397af22085cSThies C. Arntzen#define ZVAL_IS_NULL(z) ((z)->type==IS_NULL)
39806a18f16SAndi Gutmans
399b982307dSSascha Schumann#endif /* ZEND_API_H */
400573b4602SAndi Gutmans
401573b4602SAndi Gutmans/*
402573b4602SAndi Gutmans * Local variables:
403573b4602SAndi Gutmans * tab-width: 4
404573b4602SAndi Gutmans * c-basic-offset: 4
405573b4602SAndi Gutmans * End:
406573b4602SAndi Gutmans */
407