~ubuntu-branches/ubuntu/hardy/php5/hardy-updates

« back to all changes in this revision

Viewing changes to Zend/zend_operators.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-10-09 03:14:32 UTC
  • Revision ID: james.westby@ubuntu.com-20051009031432-kspik3lobxstafv9
Tags: upstream-5.0.5
ImportĀ upstreamĀ versionĀ 5.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   +----------------------------------------------------------------------+
 
3
   | Zend Engine                                                          |
 
4
   +----------------------------------------------------------------------+
 
5
   | Copyright (c) 1998-2004 Zend Technologies Ltd. (http://www.zend.com) |
 
6
   +----------------------------------------------------------------------+
 
7
   | This source file is subject to version 2.00 of the Zend license,     |
 
8
   | that is bundled with this package in the file LICENSE, and is        | 
 
9
   | available through the world-wide-web at the following url:           |
 
10
   | http://www.zend.com/license/2_00.txt.                                |
 
11
   | If you did not receive a copy of the Zend license and are unable to  |
 
12
   | obtain it through the world-wide-web, please send a note to          |
 
13
   | license@zend.com so we can mail you a copy immediately.              |
 
14
   +----------------------------------------------------------------------+
 
15
   | Authors: Andi Gutmans <andi@zend.com>                                |
 
16
   |          Zeev Suraski <zeev@zend.com>                                |
 
17
   +----------------------------------------------------------------------+
 
18
*/
 
19
 
 
20
/* $Id: zend_operators.h,v 1.88.2.5 2005/01/18 00:30:39 iliaa Exp $ */
 
21
 
 
22
#ifndef ZEND_OPERATORS_H
 
23
#define ZEND_OPERATORS_H
 
24
 
 
25
#include <errno.h>
 
26
#include <math.h>
 
27
 
 
28
#ifdef HAVE_IEEEFP_H
 
29
#include <ieeefp.h>
 
30
#endif
 
31
 
 
32
#include "zend_strtod.h"
 
33
 
 
34
#if 0&&HAVE_BCMATH
 
35
#include "ext/bcmath/libbcmath/src/bcmath.h"
 
36
#endif
 
37
 
 
38
#define MAX_LENGTH_OF_LONG 20
 
39
#define MAX_LENGTH_OF_DOUBLE 32
 
40
 
 
41
BEGIN_EXTERN_C()
 
42
ZEND_API int add_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
43
ZEND_API int sub_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
44
ZEND_API int mul_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
45
ZEND_API int div_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
46
ZEND_API int mod_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
47
ZEND_API int boolean_xor_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
48
ZEND_API int boolean_not_function(zval *result, zval *op1 TSRMLS_DC);
 
49
ZEND_API int bitwise_not_function(zval *result, zval *op1 TSRMLS_DC);
 
50
ZEND_API int bitwise_or_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
51
ZEND_API int bitwise_and_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
52
ZEND_API int bitwise_xor_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
53
ZEND_API int shift_left_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
54
ZEND_API int shift_right_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
55
ZEND_API int concat_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
56
 
 
57
ZEND_API int is_equal_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
58
ZEND_API int is_identical_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
59
ZEND_API int is_not_identical_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
60
ZEND_API int is_not_equal_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
61
ZEND_API int is_smaller_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
62
ZEND_API int is_smaller_or_equal_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
63
 
 
64
ZEND_API zend_bool instanceof_function_ex(zend_class_entry *instance_ce, zend_class_entry *ce, zend_bool interfaces_only TSRMLS_DC);
 
65
ZEND_API zend_bool instanceof_function(zend_class_entry *instance_ce, zend_class_entry *ce TSRMLS_DC);
 
66
END_EXTERN_C()
 
67
 
 
68
static inline zend_bool is_numeric_string(char *str, int length, long *lval, double *dval, zend_bool allow_errors)
 
69
{
 
70
        long local_lval;
 
71
        double local_dval;
 
72
        char *end_ptr_long, *end_ptr_double;
 
73
        int conv_base=10;
 
74
 
 
75
        if (!length) {
 
76
                return 0;
 
77
        }
 
78
        
 
79
        /* handle hex numbers */
 
80
        if (length>=2 && str[0]=='0' && (str[1]=='x' || str[1]=='X')) {
 
81
                conv_base=16;
 
82
        }
 
83
        errno=0;
 
84
        local_lval = strtol(str, &end_ptr_long, conv_base);
 
85
        if (errno!=ERANGE) {
 
86
                if (end_ptr_long == str+length) { /* integer string */
 
87
                        if (lval) {
 
88
                                *lval = local_lval;
 
89
                        }
 
90
                        return IS_LONG;
 
91
                } else if (end_ptr_long == str && *end_ptr_long != '\0' && *str != '.' && *str != '-') { /* ignore partial string matches */
 
92
                        return 0;
 
93
                }
 
94
        } else {
 
95
                end_ptr_long=NULL;
 
96
        }
 
97
 
 
98
        if (conv_base==16) { /* hex string, under UNIX strtod() messes it up */
 
99
                return 0;
 
100
        }
 
101
 
 
102
        errno=0;
 
103
        local_dval = zend_strtod(str, &end_ptr_double);
 
104
        if (errno != ERANGE) {
 
105
                if (end_ptr_double == str+length) { /* floating point string */
 
106
                        if (!zend_finite(local_dval)) {
 
107
                                /* "inf","nan" and maybe other weird ones */
 
108
                                return 0;
 
109
                        }
 
110
 
 
111
                        if (dval) {
 
112
                                *dval = local_dval;
 
113
                        }
 
114
                        return IS_DOUBLE;
 
115
                }
 
116
        } else {
 
117
                end_ptr_double=NULL;
 
118
        }
 
119
        if (allow_errors) {
 
120
                if (end_ptr_double>end_ptr_long && dval) {
 
121
                        *dval = local_dval;
 
122
                        return IS_DOUBLE;
 
123
                } else if (end_ptr_long && lval) {
 
124
                        *lval = local_lval;
 
125
                        return IS_LONG;
 
126
                }
 
127
        }
 
128
        return 0;
 
129
}
 
130
 
 
131
static inline char *
 
132
zend_memnstr(char *haystack, char *needle, int needle_len, char *end)
 
133
{
 
134
        char *p = haystack;
 
135
        char ne = needle[needle_len-1];
 
136
 
 
137
        end -= needle_len;
 
138
 
 
139
        while (p <= end) {
 
140
                if ((p = (char *)memchr(p, *needle, (end-p+1))) && ne == p[needle_len-1]) {
 
141
                        if (!memcmp(needle, p, needle_len-1)) {
 
142
                                return p;
 
143
                        }
 
144
                }
 
145
                
 
146
                if (p == NULL) {
 
147
                        return NULL;
 
148
                }
 
149
                
 
150
                p++;
 
151
        }
 
152
        
 
153
        return NULL;
 
154
}
 
155
 
 
156
 
 
157
BEGIN_EXTERN_C()
 
158
ZEND_API int increment_function(zval *op1);
 
159
ZEND_API int decrement_function(zval *op2);
 
160
 
 
161
ZEND_API void convert_scalar_to_number(zval *op TSRMLS_DC);
 
162
ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC);
 
163
ZEND_API void convert_to_long(zval *op);
 
164
ZEND_API void convert_to_double(zval *op);
 
165
ZEND_API void convert_to_long_base(zval *op, int base);
 
166
ZEND_API void convert_to_null(zval *op);
 
167
ZEND_API void convert_to_boolean(zval *op);
 
168
ZEND_API void convert_to_array(zval *op);
 
169
ZEND_API void convert_to_object(zval *op);
 
170
ZEND_API void multi_convert_to_long_ex(int argc, ...);
 
171
ZEND_API void multi_convert_to_double_ex(int argc, ...);
 
172
ZEND_API void multi_convert_to_string_ex(int argc, ...);
 
173
ZEND_API int add_char_to_string(zval *result, zval *op1, zval *op2);
 
174
ZEND_API int add_string_to_string(zval *result, zval *op1, zval *op2);
 
175
#define convert_to_string(op)                   _convert_to_string((op) ZEND_FILE_LINE_CC)
 
176
 
 
177
ZEND_API double zend_string_to_double(const char *number, zend_uint length);
 
178
 
 
179
ZEND_API int zval_is_true(zval *op);
 
180
ZEND_API int compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
181
ZEND_API int numeric_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
182
ZEND_API int string_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
183
#if HAVE_STRCOLL
 
184
ZEND_API int string_locale_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 
185
#endif
 
186
 
 
187
ZEND_API void zend_str_tolower(char *str, unsigned int length);
 
188
ZEND_API char *zend_str_tolower_copy(char *dest, const char *source, unsigned int length);
 
189
END_EXTERN_C()
 
190
 
 
191
static inline char *
 
192
zend_str_tolower_dup(const char *source, unsigned int length)
 
193
{
 
194
        return zend_str_tolower_copy((char *)emalloc(length+1), source, length);
 
195
}
 
196
 
 
197
BEGIN_EXTERN_C()
 
198
ZEND_API int zend_binary_zval_strcmp(zval *s1, zval *s2);
 
199
ZEND_API int zend_binary_zval_strncmp(zval *s1, zval *s2, zval *s3);
 
200
ZEND_API int zend_binary_zval_strcasecmp(zval *s1, zval *s2);
 
201
ZEND_API int zend_binary_zval_strncasecmp(zval *s1, zval *s2, zval *s3);
 
202
ZEND_API int zend_binary_strcmp(char *s1, uint len1, char *s2, uint len2);
 
203
ZEND_API int zend_binary_strncmp(char *s1, uint len1, char *s2, uint len2, uint length);
 
204
ZEND_API int zend_binary_strcasecmp(char *s1, uint len1, char *s2, uint len2);
 
205
ZEND_API int zend_binary_strncasecmp(char *s1, uint len1, char *s2, uint len2, uint length);
 
206
 
 
207
ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2);
 
208
ZEND_API void zend_compare_symbol_tables(zval *result, HashTable *ht1, HashTable *ht2 TSRMLS_DC);
 
209
ZEND_API void zend_compare_arrays(zval *result, zval *a1, zval *a2 TSRMLS_DC);
 
210
ZEND_API void zend_compare_objects(zval *result, zval *o1, zval *o2 TSRMLS_DC);
 
211
 
 
212
ZEND_API int zend_atoi(const char *str, int str_len);
 
213
 
 
214
ZEND_API void zend_locale_sprintf_double(zval *op ZEND_FILE_LINE_DC);
 
215
END_EXTERN_C()
 
216
#define convert_to_ex_master(ppzv, lower_type, upper_type)      \
 
217
        if ((*ppzv)->type!=IS_##upper_type) {                                   \
 
218
                SEPARATE_ZVAL_IF_NOT_REF(ppzv);                                         \
 
219
                convert_to_##lower_type(*ppzv);                                         \
 
220
        }
 
221
 
 
222
 
 
223
#define convert_to_boolean_ex(ppzv)     convert_to_ex_master(ppzv, boolean, BOOL)
 
224
#define convert_to_long_ex(ppzv)        convert_to_ex_master(ppzv, long, LONG)
 
225
#define convert_to_double_ex(ppzv)      convert_to_ex_master(ppzv, double, DOUBLE)
 
226
#define convert_to_string_ex(ppzv)      convert_to_ex_master(ppzv, string, STRING)
 
227
#define convert_to_array_ex(ppzv)       convert_to_ex_master(ppzv, array, ARRAY)
 
228
#define convert_to_object_ex(ppzv)      convert_to_ex_master(ppzv, object, OBJECT)
 
229
#define convert_to_null_ex(ppzv)        convert_to_ex_master(ppzv, null, NULL)
 
230
 
 
231
#define convert_scalar_to_number_ex(ppzv)                                                       \
 
232
        if ((*ppzv)->type!=IS_LONG && (*ppzv)->type!=IS_DOUBLE) {               \
 
233
                if (!(*ppzv)->is_ref) {                                                                         \
 
234
                        SEPARATE_ZVAL(ppzv);                                                                    \
 
235
                }                                                                                                                       \
 
236
                convert_scalar_to_number(*ppzv TSRMLS_CC);                                      \
 
237
        }
 
238
 
 
239
 
 
240
#define Z_LVAL(zval)                    (zval).value.lval
 
241
#define Z_BVAL(zval)                    ((zend_bool)(zval).value.lval)
 
242
#define Z_DVAL(zval)                    (zval).value.dval
 
243
#define Z_STRVAL(zval)                  (zval).value.str.val
 
244
#define Z_STRLEN(zval)                  (zval).value.str.len
 
245
#define Z_ARRVAL(zval)                  (zval).value.ht
 
246
#define Z_OBJ_HANDLE(zval)              (zval).value.obj.handle
 
247
#define Z_OBJ_HT(zval)                  (zval).value.obj.handlers
 
248
#define Z_OBJCE(zval)                   zend_get_class_entry(&(zval) TSRMLS_CC)
 
249
#define Z_OBJPROP(zval)                 Z_OBJ_HT((zval))->get_properties(&(zval) TSRMLS_CC)
 
250
#define Z_OBJ_HANDLER(zval, hf) Z_OBJ_HT((zval))->hf
 
251
#define Z_RESVAL(zval)                  (zval).value.lval
 
252
 
 
253
#define Z_LVAL_P(zval_p)                Z_LVAL(*zval_p)
 
254
#define Z_BVAL_P(zval_p)                Z_BVAL(*zval_p)
 
255
#define Z_DVAL_P(zval_p)                Z_DVAL(*zval_p)
 
256
#define Z_STRVAL_P(zval_p)              Z_STRVAL(*zval_p)
 
257
#define Z_STRLEN_P(zval_p)              Z_STRLEN(*zval_p)
 
258
#define Z_ARRVAL_P(zval_p)              Z_ARRVAL(*zval_p)
 
259
#define Z_OBJPROP_P(zval_p)             Z_OBJPROP(*zval_p)
 
260
#define Z_OBJCE_P(zval_p)               Z_OBJCE(*zval_p)
 
261
#define Z_RESVAL_P(zval_p)              Z_RESVAL(*zval_p)
 
262
#define Z_OBJ_HANDLE_P(zval_p)  Z_OBJ_HANDLE(*zval_p)
 
263
#define Z_OBJ_HT_P(zval_p)      Z_OBJ_HT(*zval_p)
 
264
#define Z_OBJ_HANDLER_P(zval_p, h) Z_OBJ_HANDLER(*zval_p, h) 
 
265
 
 
266
#define Z_LVAL_PP(zval_pp)              Z_LVAL(**zval_pp)
 
267
#define Z_BVAL_PP(zval_pp)              Z_BVAL(**zval_pp)
 
268
#define Z_DVAL_PP(zval_pp)              Z_DVAL(**zval_pp)
 
269
#define Z_STRVAL_PP(zval_pp)    Z_STRVAL(**zval_pp)
 
270
#define Z_STRLEN_PP(zval_pp)    Z_STRLEN(**zval_pp)
 
271
#define Z_ARRVAL_PP(zval_pp)    Z_ARRVAL(**zval_pp)
 
272
#define Z_OBJPROP_PP(zval_pp)   Z_OBJPROP(**zval_pp)
 
273
#define Z_OBJCE_PP(zval_pp)             Z_OBJCE(**zval_pp)
 
274
#define Z_RESVAL_PP(zval_pp)    Z_RESVAL(**zval_pp)
 
275
#define Z_OBJ_HANDLE_PP(zval_p) Z_OBJ_HANDLE(**zval_p)
 
276
#define Z_OBJ_HT_PP(zval_p)     Z_OBJ_HT(**zval_p)
 
277
#define Z_OBJ_HANDLER_PP(zval_p, h) Z_OBJ_HANDLER(**zval_p, h) 
 
278
 
 
279
#define Z_TYPE(zval)            (zval).type
 
280
#define Z_TYPE_P(zval_p)        Z_TYPE(*zval_p)
 
281
#define Z_TYPE_PP(zval_pp)      Z_TYPE(**zval_pp)
 
282
 
 
283
#endif
 
284
 
 
285
/*
 
286
 * Local variables:
 
287
 * tab-width: 4
 
288
 * c-basic-offset: 4
 
289
 * indent-tabs-mode: t
 
290
 * End:
 
291
 */