zend_API.h revision 741b8161
1573b4602SAndi Gutmans/*
2573b4602SAndi Gutmans   +----------------------------------------------------------------------+
3573b4602SAndi Gutmans   | Zend Engine                                                          |
4573b4602SAndi Gutmans   +----------------------------------------------------------------------+
5573b4602SAndi Gutmans   | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski                  |
6573b4602SAndi Gutmans   +----------------------------------------------------------------------+
7573b4602SAndi Gutmans   | This source file is subject to the Zend license, that is bundled     |
8573b4602SAndi Gutmans   | with this package in the file LICENSE.  If you did not receive a     |
9573b4602SAndi Gutmans   | copy of the Zend license, please mail us at zend@zend.com so we can  |
10573b4602SAndi Gutmans   | send you a copy immediately.                                         |
11573b4602SAndi Gutmans   +----------------------------------------------------------------------+
12573b4602SAndi Gutmans   | Authors: Andi Gutmans <andi@zend.com>                                |
13573b4602SAndi Gutmans   |          Zeev Suraski <zeev@zend.com>                                |
14573b4602SAndi Gutmans   +----------------------------------------------------------------------+
15573b4602SAndi Gutmans*/
16573b4602SAndi Gutmans
17573b4602SAndi Gutmans#ifndef _ZEND_API_H
18573b4602SAndi Gutmans#define _ZEND_API_H
19573b4602SAndi Gutmans
20573b4602SAndi Gutmans#include "modules.h"
21573b4602SAndi Gutmans#include "zend_list.h"
22573b4602SAndi Gutmans
23573b4602SAndi Gutmans
24342c6e0bSZeev Suraski#define ZEND_NAMED_FUNCTION(name) void name(INTERNAL_FUNCTION_PARAMETERS)
25342c6e0bSZeev Suraski#define ZEND_FUNCTION(name) ZEND_NAMED_FUNCTION(zend_if_##name)
26342c6e0bSZeev Suraski
27342c6e0bSZeev Suraski#define ZEND_NAMED_FE(runtime_name, name, arg_types) { #runtime_name, name, arg_types },
28342c6e0bSZeev Suraski#define ZEND_FE(name, arg_types) ZEND_NAMED_FE(name, zend_if_##name, arg_types)
29342c6e0bSZeev Suraski
30342c6e0bSZeev Suraski
31741b8161SZeev Suraski#define INIT_CLASS_ENTRY(class_container, class_name, functions)	\
32741b8161SZeev Suraski	{																\
33741b8161SZeev Suraski		class_container.name = strdup(class_name);					\
34741b8161SZeev Suraski		class_container.name_length = sizeof(class_name)-1;			\
35741b8161SZeev Suraski		class_container.builtin_functions = functions;				\
36741b8161SZeev Suraski		class_container.handle_function_call = NULL;				\
37741b8161SZeev Suraski		class_container.handle_property_get = NULL;					\
38741b8161SZeev Suraski		class_container.handle_property_set = NULL;					\
39741b8161SZeev Suraski	}
40741b8161SZeev Suraski
41741b8161SZeev Suraski#define INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset) \
42741b8161SZeev Suraski	{															\
43741b8161SZeev Suraski		class_container.name = strdup(class_name);				\
44741b8161SZeev Suraski		class_container.name_length = sizeof(class_name)-1;		\
45741b8161SZeev Suraski		class_container.builtin_functions = functions;			\
46741b8161SZeev Suraski		class_container.handle_function_call = handle_fcall;	\
47741b8161SZeev Suraski		class_container.handle_property_get = handle_propget;	\
48741b8161SZeev Suraski		class_container.handle_property_set = handle_propset;	\
49741b8161SZeev Suraski	}
50741b8161SZeev Suraski
51741b8161SZeev Suraski
52741b8161SZeev Suraski
53573b4602SAndi Gutmansint zend_next_free_module(void);
54573b4602SAndi Gutmans
559deab411SAndi GutmansZEND_API int getParameters(int ht, int param_count,...);
569deab411SAndi GutmansZEND_API int getParametersArray(int ht, int param_count, zval **argument_array);
579deab411SAndi GutmansZEND_API int getParametersEx(int param_count,...);
589deab411SAndi GutmansZEND_API int getParametersArrayEx(int param_count, zval ***argument_array);
5939f9487eSAndi Gutmans
609deab411SAndi GutmansZEND_API int ParameterPassedByReference(int ht, uint n);
6139f9487eSAndi Gutmans
62741b8161SZeev Suraskiint zend_register_functions(zend_function_entry *functions, HashTable *function_table);
63741b8161SZeev Suraskivoid zend_unregister_functions(zend_function_entry *functions, int count, HashTable *function_table);
647a87fcbbSZeev SuraskiZEND_API int zend_register_module(zend_module_entry *module_entry);
65bfbe8618SZeev SuraskiZEND_API zend_class_entry *register_internal_class(zend_class_entry *class_entry);
66bfbe8618SZeev SuraskiZEND_API zend_module_entry *zend_get_module(int module_number);
67573b4602SAndi Gutmans
68573b4602SAndi GutmansZEND_API void wrong_param_count(void);
69573b4602SAndi Gutmans
70741b8161SZeev Suraski#define getThis() (this_ptr)
71741b8161SZeev Suraski
72573b4602SAndi Gutmans#define WRONG_PARAM_COUNT { wrong_param_count(); return; }
73573b4602SAndi Gutmans#define WRONG_PARAM_COUNT_WITH_RETVAL(ret) { wrong_param_count(); return ret; }
7439a7f4c3SZeev Suraski#define ARG_COUNT(ht) (ht)
75573b4602SAndi Gutmans
76573b4602SAndi Gutmans#define BYREF_NONE 0
77573b4602SAndi Gutmans#define BYREF_FORCE 1
78573b4602SAndi Gutmans#define BYREF_ALLOW 2
79573b4602SAndi Gutmans
80573b4602SAndi Gutmans#if !MSVC5
81573b4602SAndi Gutmans#define DLEXPORT
82573b4602SAndi Gutmans#endif
83573b4602SAndi Gutmans
84573b4602SAndi Gutmansint zend_startup_module(zend_module_entry *module);
85573b4602SAndi Gutmans
86573b4602SAndi GutmansZEND_API int array_init(zval *arg);
87573b4602SAndi GutmansZEND_API int object_init(zval *arg);
88573b4602SAndi GutmansZEND_API int object_init_ex(zval *arg, zend_class_entry *ce);
89573b4602SAndi GutmansZEND_API int add_assoc_long(zval *arg, char *key, long n);
90573b4602SAndi GutmansZEND_API int add_assoc_double(zval *arg, char *key, double d);
91573b4602SAndi GutmansZEND_API int add_assoc_string(zval *arg, char *key, char *str, int duplicate);
92573b4602SAndi GutmansZEND_API int add_assoc_stringl(zval *arg, char *key, char *str, uint length, int duplicate);
93573b4602SAndi GutmansZEND_API int add_assoc_function(zval *arg, char *key,void (*function_ptr)(INTERNAL_FUNCTION_PARAMETERS));
94573b4602SAndi GutmansZEND_API int add_index_long(zval *arg, uint idx, long n);
95573b4602SAndi GutmansZEND_API int add_index_double(zval *arg, uint idx, double d);
96573b4602SAndi GutmansZEND_API int add_index_string(zval *arg, uint idx, char *str, int duplicate);
97573b4602SAndi GutmansZEND_API int add_index_stringl(zval *arg, uint idx, char *str, uint length, int duplicate);
98573b4602SAndi GutmansZEND_API int add_next_index_long(zval *arg, long n);
99573b4602SAndi GutmansZEND_API int add_next_index_double(zval *arg, double d);
100573b4602SAndi GutmansZEND_API int add_next_index_string(zval *arg, char *str, int duplicate);
101573b4602SAndi GutmansZEND_API int add_next_index_stringl(zval *arg, char *str, uint length, int duplicate);
102573b4602SAndi Gutmans
103573b4602SAndi GutmansZEND_API int add_get_assoc_string(zval *arg, char *key, char *str, void **dest, int duplicate);
104573b4602SAndi GutmansZEND_API int add_get_assoc_stringl(zval *arg, char *key, char *str, uint length, void **dest, int duplicate);
105573b4602SAndi GutmansZEND_API int add_get_index_long(zval *arg, uint idx, long l, void **dest);
106573b4602SAndi GutmansZEND_API int add_get_index_double(zval *arg, uint idx, double d, void **dest);
107573b4602SAndi GutmansZEND_API int add_get_index_string(zval *arg, uint idx, char *str, void **dest, int duplicate);
108573b4602SAndi GutmansZEND_API int add_get_index_stringl(zval *arg, uint idx, char *str, uint length, void **dest, int duplicate);
109573b4602SAndi Gutmans
110573b4602SAndi GutmansZEND_API int call_user_function(HashTable *function_table, zval *object, zval *function_name, zval *retval, int param_count, zval *params[]);
111573b4602SAndi Gutmans
112573b4602SAndi Gutmans
113573b4602SAndi GutmansZEND_API int add_property_long(zval *arg, char *key, long l);
114573b4602SAndi GutmansZEND_API int add_property_double(zval *arg, char *key, double d);
115573b4602SAndi GutmansZEND_API int add_property_string(zval *arg, char *key, char *str, int duplicate);
116573b4602SAndi GutmansZEND_API int add_property_stringl(zval *arg, char *key, char *str, uint length, int duplicate);
117573b4602SAndi Gutmans
118573b4602SAndi Gutmans#define add_method(arg,key,method)	add_assoc_function((arg),(key),(method))
119573b4602SAndi Gutmans
1201f985edeSZeev Suraski#define RETVAL_LONG(l) {				\
1211f985edeSZeev Suraski		return_value->type = IS_LONG;	\
1221f985edeSZeev Suraski		return_value->value.lval = l;	\
1231f985edeSZeev Suraski	}
1241f985edeSZeev Suraski#define RETVAL_DOUBLE(d) {				\
1251f985edeSZeev Suraski		return_value->type = IS_DOUBLE;	\
1261f985edeSZeev Suraski		return_value->value.dval = d;	\
1271f985edeSZeev Suraski	}
1281f985edeSZeev Suraski#define RETVAL_STRING(s,duplicate) {	\
1291f985edeSZeev Suraski		char *__s=(s);					\
1301f985edeSZeev Suraski		return_value->value.str.len = strlen(__s);	\
1311f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,return_value->value.str.len):__s);	\
1321f985edeSZeev Suraski		return_value->type = IS_STRING;	\
1331f985edeSZeev Suraski	}
1341f985edeSZeev Suraski#define RETVAL_STRINGL(s,l,duplicate) {		\
1351f985edeSZeev Suraski		char *__s=(s); int __l=l;			\
1361f985edeSZeev Suraski		return_value->value.str.len = __l;	\
1371f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
1381f985edeSZeev Suraski		return_value->type = IS_STRING;		\
1391f985edeSZeev Suraski	}
1401f985edeSZeev Suraski
1411f985edeSZeev Suraski#define RETVAL_FALSE  { return_value->value.lval = 0;  return_value->type = IS_BOOL; }
1421f985edeSZeev Suraski#define RETVAL_TRUE   { return_value->value.lval = 1;  return_value->type = IS_BOOL; }
1431f985edeSZeev Suraski
1441f985edeSZeev Suraski#define RETURN_LONG(l) {				\
1451f985edeSZeev Suraski		return_value->type = IS_LONG;	\
1461f985edeSZeev Suraski		return_value->value.lval = l;	\
1471f985edeSZeev Suraski		return;							\
1481f985edeSZeev Suraski	}
1491f985edeSZeev Suraski#define RETURN_DOUBLE(d) {				\
1501f985edeSZeev Suraski		return_value->type = IS_DOUBLE;	\
1511f985edeSZeev Suraski		return_value->value.dval = d;	\
1521f985edeSZeev Suraski		return;							\
1531f985edeSZeev Suraski	}
1541f985edeSZeev Suraski#define RETURN_STRING(s,duplicate) {	\
1551f985edeSZeev Suraski		char *__s=(s);					\
1561f985edeSZeev Suraski		return_value->value.str.len = strlen(__s);	\
1571f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,return_value->value.str.len):__s);	\
1581f985edeSZeev Suraski		return_value->type = IS_STRING;	\
1591f985edeSZeev Suraski		return;							\
1601f985edeSZeev Suraski	}
1611f985edeSZeev Suraski#define RETURN_STRINGL(s,l,duplicate) {		\
1621f985edeSZeev Suraski		char *__s=(s); int __l=l;			\
1631f985edeSZeev Suraski		return_value->value.str.len = __l;	\
1641f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
1651f985edeSZeev Suraski      	return_value->type = IS_STRING;		\
1661f985edeSZeev Suraski		return;								\
1671f985edeSZeev Suraski	}
1681f985edeSZeev Suraski
1691f985edeSZeev Suraski#define RETURN_FALSE  { RETVAL_FALSE; return; }
1701f985edeSZeev Suraski#define RETURN_TRUE   { RETVAL_TRUE; return; }
1711f985edeSZeev Suraski
1721f985edeSZeev Suraski#define SET_VAR_STRING(n,v)	{ \
1731f985edeSZeev Suraski								{ \
1741f985edeSZeev Suraski									zval *var = (zval *) emalloc(sizeof(zval)); \
1751f985edeSZeev Suraski									\
1761f985edeSZeev Suraski									char *str=v; /* prevent 'v' from being evaluated more than once */ \
1771f985edeSZeev Suraski									var->value.str.val = (str); \
1781f985edeSZeev Suraski									var->value.str.len = strlen((str)); \
1791f985edeSZeev Suraski									var->type = IS_STRING; \
1801f985edeSZeev Suraski									zend_hash_update(&EG(symbol_table), (n), strlen((n))+1, &var, sizeof(zval *), NULL); \
1811f985edeSZeev Suraski								} \
1821f985edeSZeev Suraski							}
1831f985edeSZeev Suraski#define SET_VAR_STRINGL(n,v,l)	{ \
1841f985edeSZeev Suraski									{ \
1851f985edeSZeev Suraski										zval *var = (zval *) emalloc(sizeof(zval)); \
1861f985edeSZeev Suraski										\
1871f985edeSZeev Suraski										char *name=(n); \
1881f985edeSZeev Suraski										var->value.str.val = (v); \
1891f985edeSZeev Suraski										var->value.str.len = (l); \
1901f985edeSZeev Suraski										var->type = IS_STRING; \
1911f985edeSZeev Suraski										zend_hash_update(&EG(symbol_table), name, strlen(name)+1, &var, sizeof(zval *), NULL); \
1921f985edeSZeev Suraski									} \
1931f985edeSZeev Suraski								}
1941f985edeSZeev Suraski#define SET_VAR_LONG(n,v)	{ \
1951f985edeSZeev Suraski								{ \
1961f985edeSZeev Suraski									zval *var = (zval *) emalloc(sizeof(zval)); \
1971f985edeSZeev Suraski									\
1981f985edeSZeev Suraski									var->value.lval = (v); \
1991f985edeSZeev Suraski									var->type = IS_LONG; \
2001f985edeSZeev Suraski									zend_hash_update(&EG(symbol_table), (n), strlen((n))+1, &var, sizeof(zval *), NULL); \
2011f985edeSZeev Suraski								} \
2021f985edeSZeev Suraski							}
2031f985edeSZeev Suraski#define SET_VAR_DOUBLE(n,v)	{ \
2041f985edeSZeev Suraski								{ \
2051f985edeSZeev Suraski									zval *var = (zval *) emalloc(sizeof(zval)); \
2061f985edeSZeev Suraski									\
2071f985edeSZeev Suraski									var->value.dval = (v); \
2081f985edeSZeev Suraski									var->type = IS_DOUBLE; \
2091f985edeSZeev Suraski									zend_hash_update(&EG(symbol_table)), (n), strlen((n))+1, &var, sizeof(zval *), NULL); \
2101f985edeSZeev Suraski								} \
2111f985edeSZeev Suraski							}
2121f985edeSZeev Suraski
2131f985edeSZeev Suraski
214573b4602SAndi Gutmans#endif							/* _ZEND_API_H */
215573b4602SAndi Gutmans
216573b4602SAndi Gutmans/*
217573b4602SAndi Gutmans * Local variables:
218573b4602SAndi Gutmans * tab-width: 4
219573b4602SAndi Gutmans * c-basic-offset: 4
220573b4602SAndi Gutmans * End:
221573b4602SAndi Gutmans */