zend_API.h revision f962a35d
1573b4602SAndi Gutmans/*
2573b4602SAndi Gutmans   +----------------------------------------------------------------------+
3573b4602SAndi Gutmans   | Zend Engine                                                          |
4573b4602SAndi Gutmans   +----------------------------------------------------------------------+
5573b4602SAndi Gutmans   | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski                  |
6573b4602SAndi Gutmans   +----------------------------------------------------------------------+
78d1de13aSZeev Suraski   | This source file is subject to version 0.91 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                           |
108d1de13aSZeev Suraski   | http://www.zend.com/license/0_91.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"
26573b4602SAndi Gutmans
27573b4602SAndi Gutmans
28342c6e0bSZeev Suraski#define ZEND_NAMED_FUNCTION(name) void name(INTERNAL_FUNCTION_PARAMETERS)
29342c6e0bSZeev Suraski#define ZEND_FUNCTION(name) ZEND_NAMED_FUNCTION(zend_if_##name)
30342c6e0bSZeev Suraski
31342c6e0bSZeev Suraski#define ZEND_NAMED_FE(runtime_name, name, arg_types) { #runtime_name, name, arg_types },
32342c6e0bSZeev Suraski#define ZEND_FE(name, arg_types) ZEND_NAMED_FE(name, zend_if_##name, arg_types)
33342c6e0bSZeev Suraski
34342c6e0bSZeev Suraski
35741b8161SZeev Suraski#define INIT_CLASS_ENTRY(class_container, class_name, functions)	\
36741b8161SZeev Suraski	{																\
37741b8161SZeev Suraski		class_container.name = strdup(class_name);					\
38741b8161SZeev Suraski		class_container.name_length = sizeof(class_name)-1;			\
39741b8161SZeev Suraski		class_container.builtin_functions = functions;				\
40741b8161SZeev Suraski		class_container.handle_function_call = NULL;				\
41741b8161SZeev Suraski		class_container.handle_property_get = NULL;					\
42741b8161SZeev Suraski		class_container.handle_property_set = NULL;					\
43741b8161SZeev Suraski	}
44741b8161SZeev Suraski
45741b8161SZeev Suraski#define INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset) \
46741b8161SZeev Suraski	{															\
47741b8161SZeev Suraski		class_container.name = strdup(class_name);				\
48741b8161SZeev Suraski		class_container.name_length = sizeof(class_name)-1;		\
49741b8161SZeev Suraski		class_container.builtin_functions = functions;			\
50741b8161SZeev Suraski		class_container.handle_function_call = handle_fcall;	\
51741b8161SZeev Suraski		class_container.handle_property_get = handle_propget;	\
52741b8161SZeev Suraski		class_container.handle_property_set = handle_propset;	\
53741b8161SZeev Suraski	}
54741b8161SZeev Suraski
55741b8161SZeev Suraski
56741b8161SZeev Suraski
57573b4602SAndi Gutmansint zend_next_free_module(void);
58573b4602SAndi Gutmans
599deab411SAndi GutmansZEND_API int getParameters(int ht, int param_count,...);
609deab411SAndi GutmansZEND_API int getParametersArray(int ht, int param_count, zval **argument_array);
619deab411SAndi GutmansZEND_API int getParametersEx(int param_count,...);
629deab411SAndi GutmansZEND_API int getParametersArrayEx(int param_count, zval ***argument_array);
6339f9487eSAndi Gutmans
649deab411SAndi GutmansZEND_API int ParameterPassedByReference(int ht, uint n);
6539f9487eSAndi Gutmans
66741b8161SZeev Suraskiint zend_register_functions(zend_function_entry *functions, HashTable *function_table);
67741b8161SZeev Suraskivoid zend_unregister_functions(zend_function_entry *functions, int count, HashTable *function_table);
687a87fcbbSZeev SuraskiZEND_API int zend_register_module(zend_module_entry *module_entry);
69bfbe8618SZeev SuraskiZEND_API zend_class_entry *register_internal_class(zend_class_entry *class_entry);
70bfbe8618SZeev SuraskiZEND_API zend_module_entry *zend_get_module(int module_number);
71573b4602SAndi Gutmans
72573b4602SAndi GutmansZEND_API void wrong_param_count(void);
73573b4602SAndi Gutmans
74741b8161SZeev Suraski#define getThis() (this_ptr)
75741b8161SZeev Suraski
76573b4602SAndi Gutmans#define WRONG_PARAM_COUNT { wrong_param_count(); return; }
77573b4602SAndi Gutmans#define WRONG_PARAM_COUNT_WITH_RETVAL(ret) { wrong_param_count(); return ret; }
7839a7f4c3SZeev Suraski#define ARG_COUNT(ht) (ht)
79573b4602SAndi Gutmans
80573b4602SAndi Gutmans#define BYREF_NONE 0
81573b4602SAndi Gutmans#define BYREF_FORCE 1
82573b4602SAndi Gutmans#define BYREF_ALLOW 2
836d988ec6SAndi Gutmans#define BYREF_FORCE_REST 3
84573b4602SAndi Gutmans
859108abc2SZeev Suraski#if !(WIN32||WINNT)
86573b4602SAndi Gutmans#define DLEXPORT
87573b4602SAndi Gutmans#endif
88573b4602SAndi Gutmans
89573b4602SAndi Gutmansint zend_startup_module(zend_module_entry *module);
90573b4602SAndi Gutmans
91573b4602SAndi GutmansZEND_API int array_init(zval *arg);
92573b4602SAndi GutmansZEND_API int object_init(zval *arg);
93573b4602SAndi GutmansZEND_API int object_init_ex(zval *arg, zend_class_entry *ce);
946847fefaSThies C. Arntzen
956847fefaSThies C. Arntzen/* no longer supported */
966847fefaSThies C. ArntzenZEND_API int add_assoc_function(zval *arg, char *key,void (*function_ptr)(INTERNAL_FUNCTION_PARAMETERS));
976847fefaSThies C. Arntzen
98573b4602SAndi GutmansZEND_API int add_assoc_long(zval *arg, char *key, long n);
996847fefaSThies C. ArntzenZEND_API int add_assoc_bool(zval *arg, char *key, int b);
1006847fefaSThies C. ArntzenZEND_API int add_assoc_resource(zval *arg, char *key, int r);
101573b4602SAndi GutmansZEND_API int add_assoc_double(zval *arg, char *key, double d);
102573b4602SAndi GutmansZEND_API int add_assoc_string(zval *arg, char *key, char *str, int duplicate);
103573b4602SAndi GutmansZEND_API int add_assoc_stringl(zval *arg, char *key, char *str, uint length, int duplicate);
1046847fefaSThies C. Arntzen
105573b4602SAndi GutmansZEND_API int add_index_long(zval *arg, uint idx, long n);
1066847fefaSThies C. ArntzenZEND_API int add_index_bool(zval *arg, uint idx, int b);
1076847fefaSThies C. ArntzenZEND_API int add_index_resource(zval *arg, uint idx, int r);
108573b4602SAndi GutmansZEND_API int add_index_double(zval *arg, uint idx, double d);
109573b4602SAndi GutmansZEND_API int add_index_string(zval *arg, uint idx, char *str, int duplicate);
110573b4602SAndi GutmansZEND_API int add_index_stringl(zval *arg, uint idx, char *str, uint length, int duplicate);
1116847fefaSThies C. Arntzen
112573b4602SAndi GutmansZEND_API int add_next_index_long(zval *arg, long n);
1136847fefaSThies C. ArntzenZEND_API int add_next_index_bool(zval *arg, int b);
1146847fefaSThies C. ArntzenZEND_API int add_next_index_resource(zval *arg, int r);
115573b4602SAndi GutmansZEND_API int add_next_index_double(zval *arg, double d);
116573b4602SAndi GutmansZEND_API int add_next_index_string(zval *arg, char *str, int duplicate);
117573b4602SAndi GutmansZEND_API int add_next_index_stringl(zval *arg, char *str, uint length, int duplicate);
118573b4602SAndi Gutmans
119573b4602SAndi GutmansZEND_API int add_get_index_long(zval *arg, uint idx, long l, void **dest);
120573b4602SAndi GutmansZEND_API int add_get_index_double(zval *arg, uint idx, double d, void **dest);
1216847fefaSThies C. ArntzenZEND_API int add_get_assoc_string(zval *arg, char *key, char *str, void **dest, int duplicate);
1226847fefaSThies C. ArntzenZEND_API int add_get_assoc_stringl(zval *arg, char *key, char *str, uint length, void **dest, int duplicate);
123573b4602SAndi GutmansZEND_API int add_get_index_string(zval *arg, uint idx, char *str, void **dest, int duplicate);
124573b4602SAndi GutmansZEND_API int add_get_index_stringl(zval *arg, uint idx, char *str, uint length, void **dest, int duplicate);
125573b4602SAndi Gutmans
126573b4602SAndi GutmansZEND_API int call_user_function(HashTable *function_table, zval *object, zval *function_name, zval *retval, int param_count, zval *params[]);
127f95edc01SZeev SuraskiZEND_API int call_user_function_ex(HashTable *function_table, zval *object, zval *function_name, zval *retval, int param_count, zval **params[], int no_separation);
128573b4602SAndi Gutmans
129573b4602SAndi GutmansZEND_API int add_property_long(zval *arg, char *key, long l);
130446e5d0fSThies C. ArntzenZEND_API int add_property_resource(zval *arg, char *key, long r);
131573b4602SAndi GutmansZEND_API int add_property_double(zval *arg, char *key, double d);
132573b4602SAndi GutmansZEND_API int add_property_string(zval *arg, char *key, char *str, int duplicate);
133573b4602SAndi GutmansZEND_API int add_property_stringl(zval *arg, char *key, char *str, uint length, int duplicate);
134573b4602SAndi Gutmans
135f962a35dSAndrei ZmievskiZEND_API int zend_set_hash_symbol(zval *symbol, char *name, int name_length,
136f962a35dSAndrei Zmievski                                  int is_ref, int num_symbol_tables, ...);
137f962a35dSAndrei Zmievski
138573b4602SAndi Gutmans#define add_method(arg,key,method)	add_assoc_function((arg),(key),(method))
139573b4602SAndi Gutmans
140eb5c6da5SThies C. Arntzen#define RETVAL_RESOURCE(l) {			\
141eb5c6da5SThies C. Arntzen		return_value->type = IS_RESOURCE;\
142eb5c6da5SThies C. Arntzen		return_value->value.lval = l;	\
143eb5c6da5SThies C. Arntzen	}
1441f985edeSZeev Suraski#define RETVAL_LONG(l) {				\
1451f985edeSZeev Suraski		return_value->type = IS_LONG;	\
1461f985edeSZeev Suraski		return_value->value.lval = l;	\
1471f985edeSZeev Suraski	}
1481f985edeSZeev Suraski#define RETVAL_DOUBLE(d) {				\
1491f985edeSZeev Suraski		return_value->type = IS_DOUBLE;	\
1501f985edeSZeev Suraski		return_value->value.dval = d;	\
1511f985edeSZeev Suraski	}
1521f985edeSZeev Suraski#define RETVAL_STRING(s,duplicate) {	\
1531f985edeSZeev Suraski		char *__s=(s);					\
1541f985edeSZeev Suraski		return_value->value.str.len = strlen(__s);	\
1551f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,return_value->value.str.len):__s);	\
1561f985edeSZeev Suraski		return_value->type = IS_STRING;	\
1571f985edeSZeev Suraski	}
1581f985edeSZeev Suraski#define RETVAL_STRINGL(s,l,duplicate) {		\
1591f985edeSZeev Suraski		char *__s=(s); int __l=l;			\
1601f985edeSZeev Suraski		return_value->value.str.len = __l;	\
1611f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
1621f985edeSZeev Suraski		return_value->type = IS_STRING;		\
1631f985edeSZeev Suraski	}
1641f985edeSZeev Suraski
1651f985edeSZeev Suraski#define RETVAL_FALSE  { return_value->value.lval = 0;  return_value->type = IS_BOOL; }
1661f985edeSZeev Suraski#define RETVAL_TRUE   { return_value->value.lval = 1;  return_value->type = IS_BOOL; }
1671f985edeSZeev Suraski
168eb5c6da5SThies C. Arntzen#define RETURN_RESOURCE(l) {			\
169eb5c6da5SThies C. Arntzen		return_value->type = IS_RESOURCE;\
170eb5c6da5SThies C. Arntzen		return_value->value.lval = l;	\
171eb5c6da5SThies C. Arntzen		return;							\
172eb5c6da5SThies C. Arntzen	}
1731f985edeSZeev Suraski#define RETURN_LONG(l) {				\
1741f985edeSZeev Suraski		return_value->type = IS_LONG;	\
1751f985edeSZeev Suraski		return_value->value.lval = l;	\
1761f985edeSZeev Suraski		return;							\
1771f985edeSZeev Suraski	}
1781f985edeSZeev Suraski#define RETURN_DOUBLE(d) {				\
1791f985edeSZeev Suraski		return_value->type = IS_DOUBLE;	\
1801f985edeSZeev Suraski		return_value->value.dval = d;	\
1811f985edeSZeev Suraski		return;							\
1821f985edeSZeev Suraski	}
1831f985edeSZeev Suraski#define RETURN_STRING(s,duplicate) {	\
1841f985edeSZeev Suraski		char *__s=(s);					\
1851f985edeSZeev Suraski		return_value->value.str.len = strlen(__s);	\
1861f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,return_value->value.str.len):__s);	\
1871f985edeSZeev Suraski		return_value->type = IS_STRING;	\
1881f985edeSZeev Suraski		return;							\
1891f985edeSZeev Suraski	}
1901f985edeSZeev Suraski#define RETURN_STRINGL(s,l,duplicate) {		\
1911f985edeSZeev Suraski		char *__s=(s); int __l=l;			\
1921f985edeSZeev Suraski		return_value->value.str.len = __l;	\
1931f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
1941f985edeSZeev Suraski      	return_value->type = IS_STRING;		\
1951f985edeSZeev Suraski		return;								\
1961f985edeSZeev Suraski	}
1971f985edeSZeev Suraski
1981f985edeSZeev Suraski#define RETURN_FALSE  { RETVAL_FALSE; return; }
1991f985edeSZeev Suraski#define RETURN_TRUE   { RETVAL_TRUE; return; }
2001f985edeSZeev Suraski
20148ffdd79SZeev Suraski#define SET_VAR_STRING(n,v)	{																				\
20248ffdd79SZeev Suraski								{																			\
2030a276c2fSThies C. Arntzen									zval *var = (zval *) emalloc(sizeof(zval));								\
20448ffdd79SZeev Suraski									char *str=(v); /* prevent 'v' from being evaluated more than once */	\
20548ffdd79SZeev Suraski																											\
20648ffdd79SZeev Suraski									var->value.str.val = (str);												\
20748ffdd79SZeev Suraski									var->value.str.len = strlen((str));										\
20848ffdd79SZeev Suraski									var->type = IS_STRING;													\
2096393ab14SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);											\
21048ffdd79SZeev Suraski								}																			\
2111f985edeSZeev Suraski							}
21248ffdd79SZeev Suraski
21348ffdd79SZeev Suraski#define SET_VAR_STRINGL(n,v,l)	{														\
21448ffdd79SZeev Suraski									{													\
2150a276c2fSThies C. Arntzen										zval *var = (zval *) emalloc(sizeof(zval));		\
21648ffdd79SZeev Suraski																						\
21748ffdd79SZeev Suraski										var->value.str.val = (v);						\
21848ffdd79SZeev Suraski										var->value.str.len = (l);						\
21948ffdd79SZeev Suraski										var->type = IS_STRING;							\
22048ffdd79SZeev Suraski										ZEND_SET_GLOBAL_VAR(n, var);					\
22148ffdd79SZeev Suraski									}													\
2221f985edeSZeev Suraski								}
22348ffdd79SZeev Suraski
22448ffdd79SZeev Suraski#define SET_VAR_LONG(n,v)	{															\
22548ffdd79SZeev Suraski								{														\
2260a276c2fSThies C. Arntzen									zval *var = (zval *) emalloc(sizeof(zval));			\
22748ffdd79SZeev Suraski																						\
22848ffdd79SZeev Suraski									var->value.lval = (v);								\
22948ffdd79SZeev Suraski									var->type = IS_LONG;								\
23048ffdd79SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);						\
23148ffdd79SZeev Suraski								}														\
2321f985edeSZeev Suraski							}
23348ffdd79SZeev Suraski
23448ffdd79SZeev Suraski#define SET_VAR_DOUBLE(n,v)	{															\
23548ffdd79SZeev Suraski								{														\
2360a276c2fSThies C. Arntzen									zval *var = (zval *) emalloc(sizeof(zval));			\
23748ffdd79SZeev Suraski																						\
23848ffdd79SZeev Suraski									var->value.dval = (v);								\
23948ffdd79SZeev Suraski									var->type = IS_DOUBLE;								\
24048ffdd79SZeev Suraski									ZEND_SET_GLOBAL_VAR(n, var);						\
24148ffdd79SZeev Suraski								}														\
2421f985edeSZeev Suraski							}
2431f985edeSZeev Suraski
2441f985edeSZeev Suraski
245c34560b5SAndi Gutmans#define ZEND_SET_SYMBOL(symtable, name, var)										\
246c34560b5SAndi Gutmans	{																				\
247c34560b5SAndi Gutmans		char *_name = (name);														\
248c34560b5SAndi Gutmans																					\
2494c8259b5SAndi Gutmans		ZEND_SET_SYMBOL_WITH_LENGTH(symtable, _name, strlen(_name)+1, var, 1, 0);	\
25048ffdd79SZeev Suraski	}
25148ffdd79SZeev Suraski
252c34560b5SAndi Gutmans#define ZEND_SET_SYMBOL_WITH_LENGTH(symtable, name, name_length, var, _refcount, _is_ref)				\
25348ffdd79SZeev Suraski	{																									\
25448ffdd79SZeev Suraski		zval **orig_var;																				\
25548ffdd79SZeev Suraski																										\
256620d0134SZeev Suraski		if (zend_hash_find(symtable, (name), (name_length), (void **) &orig_var)==SUCCESS				\
25748ffdd79SZeev Suraski			&& PZVAL_IS_REF(*orig_var)) {																\
258158088caSZeev Suraski			(var)->refcount = (*orig_var)->refcount;													\
25952a30fd2SAndrei Zmievski			(var)->is_ref = 1;																			\
26048ffdd79SZeev Suraski																										\
2612ddc4fe4SZeev Suraski			if (_refcount) {																			\
2622ddc4fe4SZeev Suraski				(var)->refcount += _refcount-1;															\
2632ddc4fe4SZeev Suraski			}																							\
26448ffdd79SZeev Suraski			zval_dtor(*orig_var);																		\
265158088caSZeev Suraski			**orig_var = *(var);																		\
26648ffdd79SZeev Suraski			efree(var);																					\
26748ffdd79SZeev Suraski		} else {																						\
2682f5efbdeSAndi Gutmans			(var)->is_ref = _is_ref;																	\
269158088caSZeev Suraski			if (_refcount) {																			\
270158088caSZeev Suraski				(var)->refcount = _refcount;															\
271158088caSZeev Suraski			}																							\
272158088caSZeev Suraski			zend_hash_update(symtable, (name), (name_length), &(var), sizeof(zval *), NULL);			\
27348ffdd79SZeev Suraski		}																								\
27448ffdd79SZeev Suraski	}
27548ffdd79SZeev Suraski
276620d0134SZeev Suraski
277620d0134SZeev Suraski#define ZEND_SET_GLOBAL_VAR(name, var)				\
278620d0134SZeev Suraski	ZEND_SET_SYMBOL(&EG(symbol_table), name, var)
279620d0134SZeev Suraski
280e3450661SAndrei Zmievski#define ZEND_SET_GLOBAL_VAR_WITH_LENGTH(name, name_length, var, _refcount, _is_ref)		\
281e3450661SAndrei Zmievski	ZEND_SET_SYMBOL_WITH_LENGTH(&EG(symbol_table), name, name_length, var, _refcount, _is_ref)
282fec413c5SAndrei Zmievski
28306a18f16SAndi Gutmans#define HASH_OF(p) ((p)->type==IS_ARRAY ? (p)->value.ht : (((p)->type==IS_OBJECT ? (p)->value.obj.properties : NULL)))
28406a18f16SAndi Gutmans
285f962a35dSAndrei Zmievski#endif /* _ZEND_API_H */
286573b4602SAndi Gutmans
287573b4602SAndi Gutmans/*
288573b4602SAndi Gutmans * Local variables:
289573b4602SAndi Gutmans * tab-width: 4
290573b4602SAndi Gutmans * c-basic-offset: 4
291573b4602SAndi Gutmans * End:
292573b4602SAndi Gutmans */
293