1999-04-08 02:10:10 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
2004-01-09 01:33:29 +08:00
|
|
|
| Copyright (c) 1998-2004 Zend Technologies Ltd. (http://www.zend.com) |
|
1999-04-08 02:10:10 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2001-12-11 23:16:21 +08:00
|
|
|
| This source file is subject to version 2.00 of the Zend license, |
|
1999-07-16 22:58:16 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-11 04:04:29 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
2001-12-11 23:16:21 +08:00
|
|
|
| http://www.zend.com/license/2_00.txt. |
|
1999-07-16 22:58:16 +08:00
|
|
|
| If you did not receive a copy of the Zend license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@zend.com so we can mail you a copy immediately. |
|
1999-04-08 02:10:10 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Andi Gutmans <andi@zend.com> |
|
|
|
|
| Zeev Suraski <zeev@zend.com> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2003-02-01 09:49:15 +08:00
|
|
|
/* $Id$ */
|
1999-07-16 22:58:16 +08:00
|
|
|
|
2000-07-03 08:55:36 +08:00
|
|
|
#ifndef ZEND_OPERATORS_H
|
|
|
|
#define ZEND_OPERATORS_H
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2000-06-14 01:58:33 +08:00
|
|
|
#include <errno.h>
|
2000-06-15 03:55:32 +08:00
|
|
|
#include <math.h>
|
|
|
|
|
2000-06-19 00:33:15 +08:00
|
|
|
#ifdef HAVE_IEEEFP_H
|
2000-06-15 03:55:32 +08:00
|
|
|
#include <ieeefp.h>
|
|
|
|
#endif
|
|
|
|
|
2000-11-22 06:41:49 +08:00
|
|
|
|
2003-12-10 07:59:33 +08:00
|
|
|
#if 0&&HAVE_BCMATH
|
2000-11-22 06:41:49 +08:00
|
|
|
#include "ext/bcmath/libbcmath/src/bcmath.h"
|
2000-06-15 03:55:32 +08:00
|
|
|
#endif
|
2000-06-14 01:58:33 +08:00
|
|
|
|
2004-03-04 19:02:05 +08:00
|
|
|
#define MAX_LENGTH_OF_LONG 20
|
1999-04-08 02:10:10 +08:00
|
|
|
#define MAX_LENGTH_OF_DOUBLE 32
|
|
|
|
|
2004-02-20 16:03:27 +08:00
|
|
|
BEGIN_EXTERN_C()
|
2001-07-30 12:54:16 +08:00
|
|
|
ZEND_API int add_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
ZEND_API int sub_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
ZEND_API int mul_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
ZEND_API int div_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
ZEND_API int mod_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
ZEND_API int boolean_xor_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
ZEND_API int boolean_not_function(zval *result, zval *op1 TSRMLS_DC);
|
|
|
|
ZEND_API int bitwise_not_function(zval *result, zval *op1 TSRMLS_DC);
|
|
|
|
ZEND_API int bitwise_or_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
ZEND_API int bitwise_and_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
ZEND_API int bitwise_xor_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
ZEND_API int shift_left_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
ZEND_API int shift_right_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
ZEND_API int concat_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
|
|
|
|
ZEND_API int is_equal_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
ZEND_API int is_identical_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
ZEND_API int is_not_identical_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
ZEND_API int is_not_equal_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
ZEND_API int is_smaller_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
ZEND_API int is_smaller_or_equal_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
|
2003-11-25 04:57:54 +08:00
|
|
|
ZEND_API zend_bool instanceof_function_ex(zend_class_entry *instance_ce, zend_class_entry *ce, zend_bool interfaces_only TSRMLS_DC);
|
2003-03-05 19:14:44 +08:00
|
|
|
ZEND_API zend_bool instanceof_function(zend_class_entry *instance_ce, zend_class_entry *ce TSRMLS_DC);
|
2004-02-20 16:03:27 +08:00
|
|
|
END_EXTERN_C()
|
2002-07-30 12:07:15 +08:00
|
|
|
|
2002-04-24 02:06:54 +08:00
|
|
|
static inline zend_bool is_numeric_string(char *str, int length, long *lval, double *dval, zend_bool allow_errors)
|
2000-06-14 01:58:33 +08:00
|
|
|
{
|
|
|
|
long local_lval;
|
|
|
|
double local_dval;
|
2001-08-13 08:28:18 +08:00
|
|
|
char *end_ptr_long, *end_ptr_double;
|
2001-05-06 20:48:17 +08:00
|
|
|
int conv_base=10;
|
2000-06-14 01:58:33 +08:00
|
|
|
|
|
|
|
if (!length) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-05-06 20:48:17 +08:00
|
|
|
/* handle hex numbers */
|
|
|
|
if (length>=2 && str[0]=='0' && (str[1]=='x' || str[1]=='X')) {
|
|
|
|
conv_base=16;
|
|
|
|
}
|
2000-06-14 01:58:33 +08:00
|
|
|
errno=0;
|
2001-08-13 08:28:18 +08:00
|
|
|
local_lval = strtol(str, &end_ptr_long, conv_base);
|
|
|
|
if (errno!=ERANGE) {
|
|
|
|
if (end_ptr_long == str+length) { /* integer string */
|
|
|
|
if (lval) {
|
|
|
|
*lval = local_lval;
|
|
|
|
}
|
|
|
|
return IS_LONG;
|
2004-07-16 10:03:25 +08:00
|
|
|
} else if (end_ptr_long == str && *end_ptr_long != '\0') { /* ignore partial string matches */
|
|
|
|
return 0;
|
2000-06-14 01:58:33 +08:00
|
|
|
}
|
2001-08-13 08:28:18 +08:00
|
|
|
} else {
|
|
|
|
end_ptr_long=NULL;
|
2000-06-14 01:58:33 +08:00
|
|
|
}
|
|
|
|
|
2001-05-06 20:48:17 +08:00
|
|
|
if (conv_base==16) { /* hex string, under UNIX strtod() messes it up */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-06-14 01:58:33 +08:00
|
|
|
errno=0;
|
2001-08-13 08:28:18 +08:00
|
|
|
local_dval = strtod(str, &end_ptr_double);
|
2004-04-03 19:09:39 +08:00
|
|
|
if (errno != ERANGE) {
|
2001-08-13 08:28:18 +08:00
|
|
|
if (end_ptr_double == str+length) { /* floating point string */
|
2004-04-03 19:09:39 +08:00
|
|
|
if (!zend_finite(local_dval)) {
|
2001-08-13 08:28:18 +08:00
|
|
|
/* "inf","nan" and maybe other weird ones */
|
|
|
|
return 0;
|
|
|
|
}
|
2000-06-14 01:58:33 +08:00
|
|
|
|
2001-08-13 08:28:18 +08:00
|
|
|
if (dval) {
|
|
|
|
*dval = local_dval;
|
|
|
|
}
|
|
|
|
return IS_DOUBLE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
end_ptr_double=NULL;
|
|
|
|
}
|
|
|
|
if (allow_errors) {
|
|
|
|
if (end_ptr_double>end_ptr_long && dval) {
|
|
|
|
*dval = local_dval;
|
|
|
|
return IS_DOUBLE;
|
|
|
|
} else if (end_ptr_long && lval) {
|
|
|
|
*lval = local_lval;
|
|
|
|
return IS_LONG;
|
|
|
|
}
|
2000-06-14 01:58:33 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2003-04-08 23:04:26 +08:00
|
|
|
static inline char *
|
|
|
|
zend_memnstr(char *haystack, char *needle, int needle_len, char *end)
|
|
|
|
{
|
|
|
|
char *p = haystack;
|
|
|
|
char ne = needle[needle_len-1];
|
|
|
|
|
|
|
|
end -= needle_len;
|
|
|
|
|
|
|
|
while (p <= end) {
|
2003-05-20 21:21:26 +08:00
|
|
|
if ((p = (char *)memchr(p, *needle, (end-p+1))) && ne == p[needle_len-1]) {
|
2003-04-08 23:04:26 +08:00
|
|
|
if (!memcmp(needle, p, needle_len-1)) {
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-02-20 16:03:27 +08:00
|
|
|
|
|
|
|
BEGIN_EXTERN_C()
|
1999-04-08 02:10:10 +08:00
|
|
|
ZEND_API int increment_function(zval *op1);
|
|
|
|
ZEND_API int decrement_function(zval *op2);
|
|
|
|
|
2001-07-30 12:54:16 +08:00
|
|
|
ZEND_API void convert_scalar_to_number(zval *op TSRMLS_DC);
|
2000-04-28 21:31:51 +08:00
|
|
|
ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC);
|
1999-04-08 02:10:10 +08:00
|
|
|
ZEND_API void convert_to_long(zval *op);
|
2000-02-19 21:11:39 +08:00
|
|
|
ZEND_API void convert_to_double(zval *op);
|
1999-04-08 02:10:10 +08:00
|
|
|
ZEND_API void convert_to_long_base(zval *op, int base);
|
2000-02-19 21:11:39 +08:00
|
|
|
ZEND_API void convert_to_null(zval *op);
|
1999-04-08 02:10:10 +08:00
|
|
|
ZEND_API void convert_to_boolean(zval *op);
|
|
|
|
ZEND_API void convert_to_array(zval *op);
|
|
|
|
ZEND_API void convert_to_object(zval *op);
|
2000-09-06 01:55:57 +08:00
|
|
|
ZEND_API void multi_convert_to_long_ex(int argc, ...);
|
|
|
|
ZEND_API void multi_convert_to_double_ex(int argc, ...);
|
|
|
|
ZEND_API void multi_convert_to_string_ex(int argc, ...);
|
1999-04-08 02:10:10 +08:00
|
|
|
ZEND_API int add_char_to_string(zval *result, zval *op1, zval *op2);
|
|
|
|
ZEND_API int add_string_to_string(zval *result, zval *op1, zval *op2);
|
2000-04-28 21:31:51 +08:00
|
|
|
#define convert_to_string(op) _convert_to_string((op) ZEND_FILE_LINE_CC)
|
2000-05-26 15:49:56 +08:00
|
|
|
|
|
|
|
ZEND_API double zend_string_to_double(const char *number, zend_uint length);
|
1999-04-08 02:10:10 +08:00
|
|
|
|
|
|
|
ZEND_API int zval_is_true(zval *op);
|
2001-07-30 12:54:16 +08:00
|
|
|
ZEND_API int compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
ZEND_API int numeric_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
|
|
|
ZEND_API int string_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
|
1999-04-08 02:10:10 +08:00
|
|
|
|
|
|
|
ZEND_API void zend_str_tolower(char *str, unsigned int length);
|
2003-05-22 06:36:09 +08:00
|
|
|
ZEND_API char *zend_str_tolower_copy(char *dest, const char *source, unsigned int length);
|
2004-02-20 16:03:27 +08:00
|
|
|
END_EXTERN_C()
|
2003-05-22 05:59:40 +08:00
|
|
|
|
|
|
|
static inline char *
|
2003-05-22 06:36:09 +08:00
|
|
|
zend_str_tolower_dup(const char *source, unsigned int length)
|
2003-05-22 05:59:40 +08:00
|
|
|
{
|
2003-07-01 04:33:02 +08:00
|
|
|
return zend_str_tolower_copy((char *)emalloc(length+1), source, length);
|
2003-05-22 05:59:40 +08:00
|
|
|
}
|
|
|
|
|
2004-02-20 16:03:27 +08:00
|
|
|
BEGIN_EXTERN_C()
|
2000-01-25 03:00:30 +08:00
|
|
|
ZEND_API int zend_binary_zval_strcmp(zval *s1, zval *s2);
|
2000-02-09 01:19:43 +08:00
|
|
|
ZEND_API int zend_binary_zval_strncmp(zval *s1, zval *s2, zval *s3);
|
2000-01-25 03:00:30 +08:00
|
|
|
ZEND_API int zend_binary_zval_strcasecmp(zval *s1, zval *s2);
|
2000-07-26 19:32:15 +08:00
|
|
|
ZEND_API int zend_binary_zval_strncasecmp(zval *s1, zval *s2, zval *s3);
|
2000-01-25 03:00:30 +08:00
|
|
|
ZEND_API int zend_binary_strcmp(char *s1, uint len1, char *s2, uint len2);
|
2000-05-17 08:35:08 +08:00
|
|
|
ZEND_API int zend_binary_strncmp(char *s1, uint len1, char *s2, uint len2, uint length);
|
2000-01-25 03:00:30 +08:00
|
|
|
ZEND_API int zend_binary_strcasecmp(char *s1, uint len1, char *s2, uint len2);
|
2000-07-26 19:32:15 +08:00
|
|
|
ZEND_API int zend_binary_strncasecmp(char *s1, uint len1, char *s2, uint len2, uint length);
|
2000-01-25 03:00:30 +08:00
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2);
|
2001-07-30 12:54:16 +08:00
|
|
|
ZEND_API void zend_compare_symbol_tables(zval *result, HashTable *ht1, HashTable *ht2 TSRMLS_DC);
|
|
|
|
ZEND_API void zend_compare_arrays(zval *result, zval *a1, zval *a2 TSRMLS_DC);
|
|
|
|
ZEND_API void zend_compare_objects(zval *result, zval *o1, zval *o2 TSRMLS_DC);
|
2000-06-03 18:34:19 +08:00
|
|
|
|
2000-10-29 19:38:26 +08:00
|
|
|
ZEND_API int zend_atoi(const char *str, int str_len);
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2002-10-13 05:15:35 +08:00
|
|
|
ZEND_API void zend_locale_sprintf_double(zval *op ZEND_FILE_LINE_DC);
|
2004-02-20 16:03:27 +08:00
|
|
|
END_EXTERN_C()
|
2000-02-19 21:11:39 +08:00
|
|
|
#define convert_to_ex_master(ppzv, lower_type, upper_type) \
|
|
|
|
if ((*ppzv)->type!=IS_##upper_type) { \
|
2003-10-30 01:45:56 +08:00
|
|
|
SEPARATE_ZVAL_IF_NOT_REF(ppzv); \
|
2000-02-19 21:11:39 +08:00
|
|
|
convert_to_##lower_type(*ppzv); \
|
1999-09-17 07:15:34 +08:00
|
|
|
}
|
|
|
|
|
2000-04-19 06:23:28 +08:00
|
|
|
|
2000-02-19 21:11:39 +08:00
|
|
|
#define convert_to_boolean_ex(ppzv) convert_to_ex_master(ppzv, boolean, BOOL)
|
|
|
|
#define convert_to_long_ex(ppzv) convert_to_ex_master(ppzv, long, LONG)
|
|
|
|
#define convert_to_double_ex(ppzv) convert_to_ex_master(ppzv, double, DOUBLE)
|
|
|
|
#define convert_to_string_ex(ppzv) convert_to_ex_master(ppzv, string, STRING)
|
|
|
|
#define convert_to_array_ex(ppzv) convert_to_ex_master(ppzv, array, ARRAY)
|
|
|
|
#define convert_to_object_ex(ppzv) convert_to_ex_master(ppzv, object, OBJECT)
|
|
|
|
#define convert_to_null_ex(ppzv) convert_to_ex_master(ppzv, null, NULL)
|
1999-09-25 03:22:25 +08:00
|
|
|
|
1999-10-15 14:25:42 +08:00
|
|
|
#define convert_scalar_to_number_ex(ppzv) \
|
|
|
|
if ((*ppzv)->type!=IS_LONG && (*ppzv)->type!=IS_DOUBLE) { \
|
|
|
|
if (!(*ppzv)->is_ref) { \
|
|
|
|
SEPARATE_ZVAL(ppzv); \
|
|
|
|
} \
|
2001-07-30 12:54:16 +08:00
|
|
|
convert_scalar_to_number(*ppzv TSRMLS_CC); \
|
1999-10-15 14:25:42 +08:00
|
|
|
}
|
|
|
|
|
2000-04-20 22:32:39 +08:00
|
|
|
|
2003-02-03 00:29:42 +08:00
|
|
|
#define Z_LVAL(zval) (zval).value.lval
|
|
|
|
#define Z_BVAL(zval) ((zend_bool)(zval).value.lval)
|
|
|
|
#define Z_DVAL(zval) (zval).value.dval
|
|
|
|
#define Z_STRVAL(zval) (zval).value.str.val
|
|
|
|
#define Z_STRLEN(zval) (zval).value.str.len
|
|
|
|
#define Z_ARRVAL(zval) (zval).value.ht
|
|
|
|
#define Z_OBJ_HANDLE(zval) (zval).value.obj.handle
|
|
|
|
#define Z_OBJ_HT(zval) (zval).value.obj.handlers
|
2003-03-26 15:44:11 +08:00
|
|
|
#define Z_OBJCE(zval) zend_get_class_entry(&(zval) TSRMLS_CC)
|
2003-02-03 00:29:42 +08:00
|
|
|
#define Z_OBJPROP(zval) Z_OBJ_HT((zval))->get_properties(&(zval) TSRMLS_CC)
|
|
|
|
#define Z_OBJ_HANDLER(zval, hf) Z_OBJ_HT((zval))->hf
|
|
|
|
#define Z_RESVAL(zval) (zval).value.lval
|
2000-04-20 22:55:16 +08:00
|
|
|
|
|
|
|
#define Z_LVAL_P(zval_p) Z_LVAL(*zval_p)
|
2000-09-20 02:18:26 +08:00
|
|
|
#define Z_BVAL_P(zval_p) Z_BVAL(*zval_p)
|
2000-04-20 22:55:16 +08:00
|
|
|
#define Z_DVAL_P(zval_p) Z_DVAL(*zval_p)
|
|
|
|
#define Z_STRVAL_P(zval_p) Z_STRVAL(*zval_p)
|
|
|
|
#define Z_STRLEN_P(zval_p) Z_STRLEN(*zval_p)
|
|
|
|
#define Z_ARRVAL_P(zval_p) Z_ARRVAL(*zval_p)
|
2000-10-27 22:13:03 +08:00
|
|
|
#define Z_OBJPROP_P(zval_p) Z_OBJPROP(*zval_p)
|
|
|
|
#define Z_OBJCE_P(zval_p) Z_OBJCE(*zval_p)
|
2000-11-03 08:35:12 +08:00
|
|
|
#define Z_RESVAL_P(zval_p) Z_RESVAL(*zval_p)
|
2002-02-07 22:08:43 +08:00
|
|
|
#define Z_OBJ_HANDLE_P(zval_p) Z_OBJ_HANDLE(*zval_p)
|
|
|
|
#define Z_OBJ_HT_P(zval_p) Z_OBJ_HT(*zval_p)
|
2003-01-12 22:38:54 +08:00
|
|
|
#define Z_OBJ_HANDLER_P(zval_p, h) Z_OBJ_HANDLER(*zval_p, h)
|
2000-04-20 22:55:16 +08:00
|
|
|
|
|
|
|
#define Z_LVAL_PP(zval_pp) Z_LVAL(**zval_pp)
|
2000-09-20 02:18:26 +08:00
|
|
|
#define Z_BVAL_PP(zval_pp) Z_BVAL(**zval_pp)
|
2000-04-20 22:55:16 +08:00
|
|
|
#define Z_DVAL_PP(zval_pp) Z_DVAL(**zval_pp)
|
|
|
|
#define Z_STRVAL_PP(zval_pp) Z_STRVAL(**zval_pp)
|
|
|
|
#define Z_STRLEN_PP(zval_pp) Z_STRLEN(**zval_pp)
|
|
|
|
#define Z_ARRVAL_PP(zval_pp) Z_ARRVAL(**zval_pp)
|
2000-10-27 22:13:03 +08:00
|
|
|
#define Z_OBJPROP_PP(zval_pp) Z_OBJPROP(**zval_pp)
|
|
|
|
#define Z_OBJCE_PP(zval_pp) Z_OBJCE(**zval_pp)
|
2000-11-03 08:35:12 +08:00
|
|
|
#define Z_RESVAL_PP(zval_pp) Z_RESVAL(**zval_pp)
|
2002-02-07 22:08:43 +08:00
|
|
|
#define Z_OBJ_HANDLE_PP(zval_p) Z_OBJ_HANDLE(**zval_p)
|
|
|
|
#define Z_OBJ_HT_PP(zval_p) Z_OBJ_HT(**zval_p)
|
2003-01-12 22:38:54 +08:00
|
|
|
#define Z_OBJ_HANDLER_PP(zval_p, h) Z_OBJ_HANDLER(**zval_p, h)
|
2000-04-20 22:55:16 +08:00
|
|
|
|
|
|
|
#define Z_TYPE(zval) (zval).type
|
|
|
|
#define Z_TYPE_P(zval_p) Z_TYPE(*zval_p)
|
|
|
|
#define Z_TYPE_PP(zval_pp) Z_TYPE(**zval_pp)
|
2000-04-20 22:32:39 +08:00
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
#endif
|
2003-02-01 09:49:15 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*/
|