zend_API.h revision 1f985ede
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
31573b4602SAndi Gutmansint zend_next_free_module(void);
32573b4602SAndi Gutmans
339deab411SAndi GutmansZEND_API int getParameters(int ht, int param_count,...);
349deab411SAndi GutmansZEND_API int getParametersArray(int ht, int param_count, zval **argument_array);
359deab411SAndi GutmansZEND_API int getParametersEx(int param_count,...);
369deab411SAndi GutmansZEND_API int getParametersArrayEx(int param_count, zval ***argument_array);
3739f9487eSAndi Gutmans
38942f4092SZeev SuraskiZEND_API int getThis(zval **this_ptr);
399deab411SAndi GutmansZEND_API int ParameterPassedByReference(int ht, uint n);
4039f9487eSAndi Gutmans
417a87fcbbSZeev Suraskiint zend_register_functions(zend_function_entry *functions);
427a87fcbbSZeev Suraskivoid zend_unregister_functions(zend_function_entry *functions, int count);
437a87fcbbSZeev SuraskiZEND_API int zend_register_module(zend_module_entry *module_entry);
44bfbe8618SZeev SuraskiZEND_API zend_class_entry *register_internal_class(zend_class_entry *class_entry);
45bfbe8618SZeev SuraskiZEND_API zend_module_entry *zend_get_module(int module_number);
46573b4602SAndi Gutmans
47573b4602SAndi GutmansZEND_API void wrong_param_count(void);
48573b4602SAndi Gutmans
49573b4602SAndi Gutmans#define WRONG_PARAM_COUNT { wrong_param_count(); return; }
50573b4602SAndi Gutmans#define WRONG_PARAM_COUNT_WITH_RETVAL(ret) { wrong_param_count(); return ret; }
5139a7f4c3SZeev Suraski#define ARG_COUNT(ht) (ht)
52573b4602SAndi Gutmans
53573b4602SAndi Gutmans#define BYREF_NONE 0
54573b4602SAndi Gutmans#define BYREF_FORCE 1
55573b4602SAndi Gutmans#define BYREF_ALLOW 2
56573b4602SAndi Gutmans
57573b4602SAndi Gutmans#if !MSVC5
58573b4602SAndi Gutmans#define DLEXPORT
59573b4602SAndi Gutmans#endif
60573b4602SAndi Gutmans
61573b4602SAndi Gutmansint zend_startup_module(zend_module_entry *module);
62573b4602SAndi Gutmans
63573b4602SAndi GutmansZEND_API int array_init(zval *arg);
64573b4602SAndi GutmansZEND_API int object_init(zval *arg);
65573b4602SAndi GutmansZEND_API int object_init_ex(zval *arg, zend_class_entry *ce);
66573b4602SAndi GutmansZEND_API int add_assoc_long(zval *arg, char *key, long n);
67573b4602SAndi GutmansZEND_API int add_assoc_double(zval *arg, char *key, double d);
68573b4602SAndi GutmansZEND_API int add_assoc_string(zval *arg, char *key, char *str, int duplicate);
69573b4602SAndi GutmansZEND_API int add_assoc_stringl(zval *arg, char *key, char *str, uint length, int duplicate);
70573b4602SAndi GutmansZEND_API int add_assoc_function(zval *arg, char *key,void (*function_ptr)(INTERNAL_FUNCTION_PARAMETERS));
71573b4602SAndi GutmansZEND_API int add_index_long(zval *arg, uint idx, long n);
72573b4602SAndi GutmansZEND_API int add_index_double(zval *arg, uint idx, double d);
73573b4602SAndi GutmansZEND_API int add_index_string(zval *arg, uint idx, char *str, int duplicate);
74573b4602SAndi GutmansZEND_API int add_index_stringl(zval *arg, uint idx, char *str, uint length, int duplicate);
75573b4602SAndi GutmansZEND_API int add_next_index_long(zval *arg, long n);
76573b4602SAndi GutmansZEND_API int add_next_index_double(zval *arg, double d);
77573b4602SAndi GutmansZEND_API int add_next_index_string(zval *arg, char *str, int duplicate);
78573b4602SAndi GutmansZEND_API int add_next_index_stringl(zval *arg, char *str, uint length, int duplicate);
79573b4602SAndi Gutmans
80573b4602SAndi GutmansZEND_API int add_get_assoc_string(zval *arg, char *key, char *str, void **dest, int duplicate);
81573b4602SAndi GutmansZEND_API int add_get_assoc_stringl(zval *arg, char *key, char *str, uint length, void **dest, int duplicate);
82573b4602SAndi GutmansZEND_API int add_get_index_long(zval *arg, uint idx, long l, void **dest);
83573b4602SAndi GutmansZEND_API int add_get_index_double(zval *arg, uint idx, double d, void **dest);
84573b4602SAndi GutmansZEND_API int add_get_index_string(zval *arg, uint idx, char *str, void **dest, int duplicate);
85573b4602SAndi GutmansZEND_API int add_get_index_stringl(zval *arg, uint idx, char *str, uint length, void **dest, int duplicate);
86573b4602SAndi Gutmans
87573b4602SAndi GutmansZEND_API int call_user_function(HashTable *function_table, zval *object, zval *function_name, zval *retval, int param_count, zval *params[]);
88573b4602SAndi Gutmans
89573b4602SAndi Gutmans
90573b4602SAndi GutmansZEND_API int add_property_long(zval *arg, char *key, long l);
91573b4602SAndi GutmansZEND_API int add_property_double(zval *arg, char *key, double d);
92573b4602SAndi GutmansZEND_API int add_property_string(zval *arg, char *key, char *str, int duplicate);
93573b4602SAndi GutmansZEND_API int add_property_stringl(zval *arg, char *key, char *str, uint length, int duplicate);
94573b4602SAndi Gutmans
95573b4602SAndi Gutmans#define add_method(arg,key,method)	add_assoc_function((arg),(key),(method))
96573b4602SAndi Gutmans
971f985edeSZeev Suraski#define RETVAL_LONG(l) {				\
981f985edeSZeev Suraski		return_value->type = IS_LONG;	\
991f985edeSZeev Suraski		return_value->value.lval = l;	\
1001f985edeSZeev Suraski	}
1011f985edeSZeev Suraski#define RETVAL_DOUBLE(d) {				\
1021f985edeSZeev Suraski		return_value->type = IS_DOUBLE;	\
1031f985edeSZeev Suraski		return_value->value.dval = d;	\
1041f985edeSZeev Suraski	}
1051f985edeSZeev Suraski#define RETVAL_STRING(s,duplicate) {	\
1061f985edeSZeev Suraski		char *__s=(s);					\
1071f985edeSZeev Suraski		return_value->value.str.len = strlen(__s);	\
1081f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,return_value->value.str.len):__s);	\
1091f985edeSZeev Suraski		return_value->type = IS_STRING;	\
1101f985edeSZeev Suraski	}
1111f985edeSZeev Suraski#define RETVAL_STRINGL(s,l,duplicate) {		\
1121f985edeSZeev Suraski		char *__s=(s); int __l=l;			\
1131f985edeSZeev Suraski		return_value->value.str.len = __l;	\
1141f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
1151f985edeSZeev Suraski		return_value->type = IS_STRING;		\
1161f985edeSZeev Suraski	}
1171f985edeSZeev Suraski
1181f985edeSZeev Suraski#define RETVAL_FALSE  { return_value->value.lval = 0;  return_value->type = IS_BOOL; }
1191f985edeSZeev Suraski#define RETVAL_TRUE   { return_value->value.lval = 1;  return_value->type = IS_BOOL; }
1201f985edeSZeev Suraski
1211f985edeSZeev Suraski#define RETURN_LONG(l) {				\
1221f985edeSZeev Suraski		return_value->type = IS_LONG;	\
1231f985edeSZeev Suraski		return_value->value.lval = l;	\
1241f985edeSZeev Suraski		return;							\
1251f985edeSZeev Suraski	}
1261f985edeSZeev Suraski#define RETURN_DOUBLE(d) {				\
1271f985edeSZeev Suraski		return_value->type = IS_DOUBLE;	\
1281f985edeSZeev Suraski		return_value->value.dval = d;	\
1291f985edeSZeev Suraski		return;							\
1301f985edeSZeev Suraski	}
1311f985edeSZeev Suraski#define RETURN_STRING(s,duplicate) {	\
1321f985edeSZeev Suraski		char *__s=(s);					\
1331f985edeSZeev Suraski		return_value->value.str.len = strlen(__s);	\
1341f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,return_value->value.str.len):__s);	\
1351f985edeSZeev Suraski		return_value->type = IS_STRING;	\
1361f985edeSZeev Suraski		return;							\
1371f985edeSZeev Suraski	}
1381f985edeSZeev Suraski#define RETURN_STRINGL(s,l,duplicate) {		\
1391f985edeSZeev Suraski		char *__s=(s); int __l=l;			\
1401f985edeSZeev Suraski		return_value->value.str.len = __l;	\
1411f985edeSZeev Suraski		return_value->value.str.val = (duplicate?estrndup(__s,__l):__s);	\
1421f985edeSZeev Suraski      	return_value->type = IS_STRING;		\
1431f985edeSZeev Suraski		return;								\
1441f985edeSZeev Suraski	}
1451f985edeSZeev Suraski
1461f985edeSZeev Suraski#define RETURN_FALSE  { RETVAL_FALSE; return; }
1471f985edeSZeev Suraski#define RETURN_TRUE   { RETVAL_TRUE; return; }
1481f985edeSZeev Suraski
1491f985edeSZeev Suraski#define SET_VAR_STRING(n,v)	{ \
1501f985edeSZeev Suraski								{ \
1511f985edeSZeev Suraski									zval *var = (zval *) emalloc(sizeof(zval)); \
1521f985edeSZeev Suraski									\
1531f985edeSZeev Suraski									char *str=v; /* prevent 'v' from being evaluated more than once */ \
1541f985edeSZeev Suraski									var->value.str.val = (str); \
1551f985edeSZeev Suraski									var->value.str.len = strlen((str)); \
1561f985edeSZeev Suraski									var->type = IS_STRING; \
1571f985edeSZeev Suraski									zend_hash_update(&EG(symbol_table), (n), strlen((n))+1, &var, sizeof(zval *), NULL); \
1581f985edeSZeev Suraski								} \
1591f985edeSZeev Suraski							}
1601f985edeSZeev Suraski#define SET_VAR_STRINGL(n,v,l)	{ \
1611f985edeSZeev Suraski									{ \
1621f985edeSZeev Suraski										zval *var = (zval *) emalloc(sizeof(zval)); \
1631f985edeSZeev Suraski										\
1641f985edeSZeev Suraski										char *name=(n); \
1651f985edeSZeev Suraski										var->value.str.val = (v); \
1661f985edeSZeev Suraski										var->value.str.len = (l); \
1671f985edeSZeev Suraski										var->type = IS_STRING; \
1681f985edeSZeev Suraski										zend_hash_update(&EG(symbol_table), name, strlen(name)+1, &var, sizeof(zval *), NULL); \
1691f985edeSZeev Suraski									} \
1701f985edeSZeev Suraski								}
1711f985edeSZeev Suraski#define SET_VAR_LONG(n,v)	{ \
1721f985edeSZeev Suraski								{ \
1731f985edeSZeev Suraski									zval *var = (zval *) emalloc(sizeof(zval)); \
1741f985edeSZeev Suraski									\
1751f985edeSZeev Suraski									var->value.lval = (v); \
1761f985edeSZeev Suraski									var->type = IS_LONG; \
1771f985edeSZeev Suraski									zend_hash_update(&EG(symbol_table), (n), strlen((n))+1, &var, sizeof(zval *), NULL); \
1781f985edeSZeev Suraski								} \
1791f985edeSZeev Suraski							}
1801f985edeSZeev Suraski#define SET_VAR_DOUBLE(n,v)	{ \
1811f985edeSZeev Suraski								{ \
1821f985edeSZeev Suraski									zval *var = (zval *) emalloc(sizeof(zval)); \
1831f985edeSZeev Suraski									\
1841f985edeSZeev Suraski									var->value.dval = (v); \
1851f985edeSZeev Suraski									var->type = IS_DOUBLE; \
1861f985edeSZeev Suraski									zend_hash_update(&EG(symbol_table)), (n), strlen((n))+1, &var, sizeof(zval *), NULL); \
1871f985edeSZeev Suraski								} \
1881f985edeSZeev Suraski							}
1891f985edeSZeev Suraski
1901f985edeSZeev Suraski
191573b4602SAndi Gutmans#endif							/* _ZEND_API_H */
192573b4602SAndi Gutmans
193573b4602SAndi Gutmans/*
194573b4602SAndi Gutmans * Local variables:
195573b4602SAndi Gutmans * tab-width: 4
196573b4602SAndi Gutmans * c-basic-offset: 4
197573b4602SAndi Gutmans * End:
198573b4602SAndi Gutmans */