1999-04-08 02:10:10 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
2013-01-01 16:37:09 +08:00
|
|
|
| Copyright (c) 1998-2013 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, |
|
2007-11-20 21:26:36 +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$ */
|
|
|
|
|
2002-11-05 01:05:11 +08:00
|
|
|
#include <ctype.h>
|
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
#include "zend.h"
|
|
|
|
#include "zend_operators.h"
|
|
|
|
#include "zend_variables.h"
|
|
|
|
#include "zend_globals.h"
|
1999-09-03 08:11:47 +08:00
|
|
|
#include "zend_list.h"
|
2001-07-11 19:35:11 +08:00
|
|
|
#include "zend_API.h"
|
2004-11-04 07:13:32 +08:00
|
|
|
#include "zend_strtod.h"
|
2007-02-24 10:17:47 +08:00
|
|
|
#include "zend_exceptions.h"
|
2010-06-27 01:14:33 +08:00
|
|
|
#include "zend_closures.h"
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2006-12-05 02:37:15 +08:00
|
|
|
#if ZEND_USE_TOLOWER_L
|
|
|
|
#include <locale.h>
|
|
|
|
static _locale_t current_locale = NULL;
|
2009-05-11 07:08:52 +08:00
|
|
|
/* this is true global! may lead to strange effects on ZTS, but so may setlocale() */
|
2006-12-05 02:37:15 +08:00
|
|
|
#define zend_tolower(c) _tolower_l(c, current_locale)
|
|
|
|
#else
|
|
|
|
#define zend_tolower(c) tolower(c)
|
|
|
|
#endif
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
#define TYPE_PAIR(t1,t2) (((t1) << 4) | (t2))
|
|
|
|
|
2012-07-15 12:06:40 +08:00
|
|
|
static const unsigned char tolower_map[256] = {
|
2012-07-11 09:12:13 +08:00
|
|
|
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
|
|
|
|
0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,
|
|
|
|
0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
|
|
|
|
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
|
|
|
|
0x40,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
|
|
|
|
0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x5b,0x5c,0x5d,0x5e,0x5f,
|
|
|
|
0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
|
|
|
|
0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,
|
|
|
|
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
|
|
|
|
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
|
|
|
|
0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,
|
|
|
|
0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,
|
|
|
|
0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,
|
|
|
|
0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,
|
|
|
|
0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,
|
|
|
|
0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
|
|
|
|
};
|
|
|
|
|
2012-07-15 12:06:40 +08:00
|
|
|
#define zend_tolower_ascii(c) (tolower_map[(unsigned char)(c)])
|
2012-07-11 09:12:13 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions using locale lowercase:
|
|
|
|
zend_binary_strncasecmp_l
|
|
|
|
zend_binary_strcasecmp_l
|
|
|
|
zend_binary_zval_strcasecmp
|
|
|
|
zend_binary_zval_strncasecmp
|
|
|
|
string_compare_function_ex
|
|
|
|
string_case_compare_function
|
|
|
|
* Functions using ascii lowercase:
|
|
|
|
zend_str_tolower_copy
|
|
|
|
zend_str_tolower_dup
|
|
|
|
zend_str_tolower
|
|
|
|
zend_binary_strcasecmp
|
|
|
|
zend_binary_strncasecmp
|
|
|
|
*/
|
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int zend_atoi(const char *str, int str_len) /* {{{ */
|
2000-10-29 19:38:26 +08:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (!str_len) {
|
|
|
|
str_len = strlen(str);
|
|
|
|
}
|
2002-09-01 16:30:39 +08:00
|
|
|
retval = strtol(str, NULL, 0);
|
2000-10-29 19:38:26 +08:00
|
|
|
if (str_len>0) {
|
|
|
|
switch (str[str_len-1]) {
|
2004-12-13 17:09:06 +08:00
|
|
|
case 'g':
|
|
|
|
case 'G':
|
2000-10-29 19:38:26 +08:00
|
|
|
retval *= 1024;
|
2004-12-13 17:09:06 +08:00
|
|
|
/* break intentionally missing */
|
2000-10-29 19:38:26 +08:00
|
|
|
case 'm':
|
|
|
|
case 'M':
|
2004-12-13 17:09:06 +08:00
|
|
|
retval *= 1024;
|
|
|
|
/* break intentionally missing */
|
|
|
|
case 'k':
|
|
|
|
case 'K':
|
|
|
|
retval *= 1024;
|
2000-10-29 19:38:26 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2000-10-29 19:38:26 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API long zend_atol(const char *str, int str_len) /* {{{ */
|
2008-03-19 20:41:23 +08:00
|
|
|
{
|
|
|
|
long retval;
|
|
|
|
|
|
|
|
if (!str_len) {
|
|
|
|
str_len = strlen(str);
|
|
|
|
}
|
|
|
|
retval = strtol(str, NULL, 0);
|
|
|
|
if (str_len>0) {
|
|
|
|
switch (str[str_len-1]) {
|
|
|
|
case 'g':
|
|
|
|
case 'G':
|
|
|
|
retval *= 1024;
|
|
|
|
/* break intentionally missing */
|
|
|
|
case 'm':
|
|
|
|
case 'M':
|
|
|
|
retval *= 1024;
|
|
|
|
/* break intentionally missing */
|
|
|
|
case 'k':
|
|
|
|
case 'K':
|
|
|
|
retval *= 1024;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2008-03-19 20:41:23 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API double zend_string_to_double(const char *number, zend_uint length) /* {{{ */
|
2000-05-26 15:49:56 +08:00
|
|
|
{
|
|
|
|
double divisor = 10.0;
|
|
|
|
double result = 0.0;
|
|
|
|
double exponent;
|
2000-05-29 02:59:40 +08:00
|
|
|
const char *end = number+length;
|
|
|
|
const char *digit = number;
|
2000-05-26 15:49:56 +08:00
|
|
|
|
|
|
|
if (!length) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-05-29 02:59:40 +08:00
|
|
|
while (digit < end) {
|
|
|
|
if ((*digit <= '9' && *digit >= '0')) {
|
2000-05-26 15:49:56 +08:00
|
|
|
result *= 10;
|
2000-05-29 02:59:40 +08:00
|
|
|
result += *digit - '0';
|
|
|
|
} else if (*digit == '.') {
|
|
|
|
digit++;
|
2000-05-26 15:49:56 +08:00
|
|
|
break;
|
2000-05-29 02:59:40 +08:00
|
|
|
} else if (toupper(*digit) == 'E') {
|
|
|
|
exponent = (double) atoi(digit+1);
|
2000-05-26 15:49:56 +08:00
|
|
|
result *= pow(10.0, exponent);
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
return result;
|
|
|
|
}
|
2000-05-29 02:59:40 +08:00
|
|
|
digit++;
|
2000-05-26 15:49:56 +08:00
|
|
|
}
|
|
|
|
|
2000-05-29 02:59:40 +08:00
|
|
|
while (digit < end) {
|
|
|
|
if ((*digit <= '9' && *digit >= '0')) {
|
|
|
|
result += (*digit - '0') / divisor;
|
2000-05-26 15:49:56 +08:00
|
|
|
divisor *= 10;
|
2000-05-29 02:59:40 +08:00
|
|
|
} else if (toupper(*digit) == 'E') {
|
|
|
|
exponent = (double) atoi(digit+1);
|
2000-05-26 15:49:56 +08:00
|
|
|
result *= pow(10.0, exponent);
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
return result;
|
|
|
|
}
|
2000-05-29 02:59:40 +08:00
|
|
|
digit++;
|
2000-05-26 15:49:56 +08:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2000-05-26 15:49:56 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API void convert_scalar_to_number(zval *op TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2007-11-20 21:26:36 +08:00
|
|
|
switch (Z_TYPE_P(op)) {
|
2001-04-29 02:20:46 +08:00
|
|
|
case IS_STRING:
|
|
|
|
{
|
|
|
|
char *strval;
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
strval = Z_STRVAL_P(op);
|
|
|
|
if ((Z_TYPE_P(op)=is_numeric_string(strval, Z_STRLEN_P(op), &Z_LVAL_P(op), &Z_DVAL_P(op), 1)) == 0) {
|
|
|
|
ZVAL_LONG(op, 0);
|
2001-04-29 02:20:46 +08:00
|
|
|
}
|
|
|
|
STR_FREE(strval);
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
2001-04-29 02:20:46 +08:00
|
|
|
}
|
|
|
|
case IS_BOOL:
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_TYPE_P(op) = IS_LONG;
|
2001-04-29 02:20:46 +08:00
|
|
|
break;
|
|
|
|
case IS_RESOURCE:
|
2007-11-20 21:26:36 +08:00
|
|
|
zend_list_delete(Z_LVAL_P(op));
|
|
|
|
Z_TYPE_P(op) = IS_LONG;
|
2001-04-29 02:20:46 +08:00
|
|
|
break;
|
2004-03-28 20:08:26 +08:00
|
|
|
case IS_OBJECT:
|
|
|
|
convert_to_long_base(op, 10);
|
|
|
|
break;
|
2001-04-29 02:20:46 +08:00
|
|
|
case IS_NULL:
|
2007-11-20 21:26:36 +08:00
|
|
|
ZVAL_LONG(op, 0);
|
2001-04-29 02:20:46 +08:00
|
|
|
break;
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
/* {{{ zendi_convert_scalar_to_number */
|
1999-09-03 08:11:47 +08:00
|
|
|
#define zendi_convert_scalar_to_number(op, holder, result) \
|
2005-05-31 19:16:51 +08:00
|
|
|
if (op==result) { \
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_TYPE_P(op) != IS_LONG) { \
|
2003-05-22 02:46:34 +08:00
|
|
|
convert_scalar_to_number(op TSRMLS_CC); \
|
|
|
|
} \
|
2001-04-29 02:20:46 +08:00
|
|
|
} else { \
|
2007-11-20 21:26:36 +08:00
|
|
|
switch (Z_TYPE_P(op)) { \
|
2001-04-29 02:20:46 +08:00
|
|
|
case IS_STRING: \
|
|
|
|
{ \
|
2007-11-20 21:26:36 +08:00
|
|
|
if ((Z_TYPE(holder)=is_numeric_string(Z_STRVAL_P(op), Z_STRLEN_P(op), &Z_LVAL(holder), &Z_DVAL(holder), 1)) == 0) { \
|
|
|
|
ZVAL_LONG(&(holder), 0); \
|
2001-04-29 02:20:46 +08:00
|
|
|
} \
|
|
|
|
(op) = &(holder); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
case IS_BOOL: \
|
|
|
|
case IS_RESOURCE: \
|
2007-11-20 21:26:36 +08:00
|
|
|
ZVAL_LONG(&(holder), Z_LVAL_P(op)); \
|
2001-04-29 02:20:46 +08:00
|
|
|
(op) = &(holder); \
|
|
|
|
break; \
|
|
|
|
case IS_NULL: \
|
2007-11-20 21:26:36 +08:00
|
|
|
ZVAL_LONG(&(holder), 0); \
|
2001-04-29 02:20:46 +08:00
|
|
|
(op) = &(holder); \
|
|
|
|
break; \
|
2004-03-28 20:08:26 +08:00
|
|
|
case IS_OBJECT: \
|
|
|
|
(holder) = (*(op)); \
|
|
|
|
zval_copy_ctor(&(holder)); \
|
|
|
|
convert_to_long_base(&(holder), 10); \
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_TYPE(holder) == IS_LONG) { \
|
2004-05-10 22:56:21 +08:00
|
|
|
(op) = &(holder); \
|
|
|
|
} \
|
2004-03-28 20:08:26 +08:00
|
|
|
break; \
|
2001-04-29 02:20:46 +08:00
|
|
|
} \
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2007-12-25 02:09:50 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
/* {{{ zendi_convert_to_long */
|
1999-09-03 08:11:47 +08:00
|
|
|
#define zendi_convert_to_long(op, holder, result) \
|
2005-05-31 19:16:51 +08:00
|
|
|
if (op == result) { \
|
1999-09-03 08:11:47 +08:00
|
|
|
convert_to_long(op); \
|
2007-11-20 21:26:36 +08:00
|
|
|
} else if (Z_TYPE_P(op) != IS_LONG) { \
|
|
|
|
switch (Z_TYPE_P(op)) { \
|
2000-01-04 21:22:58 +08:00
|
|
|
case IS_NULL: \
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL(holder) = 0; \
|
1999-12-31 21:56:59 +08:00
|
|
|
break; \
|
1999-09-03 08:11:47 +08:00
|
|
|
case IS_DOUBLE: \
|
2009-06-05 02:20:45 +08:00
|
|
|
Z_LVAL(holder) = zend_dval_to_lval(Z_DVAL_P(op)); \
|
1999-09-03 08:11:47 +08:00
|
|
|
break; \
|
|
|
|
case IS_STRING: \
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL(holder) = strtol(Z_STRVAL_P(op), NULL, 10); \
|
1999-09-03 08:11:47 +08:00
|
|
|
break; \
|
|
|
|
case IS_ARRAY: \
|
2009-05-11 15:52:49 +08:00
|
|
|
Z_LVAL(holder) = (zend_hash_num_elements(Z_ARRVAL_P(op))?1:0); \
|
1999-09-03 08:11:47 +08:00
|
|
|
break; \
|
|
|
|
case IS_OBJECT: \
|
2004-03-14 21:52:36 +08:00
|
|
|
(holder) = (*(op)); \
|
|
|
|
zval_copy_ctor(&(holder)); \
|
2004-03-28 20:08:26 +08:00
|
|
|
convert_to_long_base(&(holder), 10); \
|
1999-09-03 08:11:47 +08:00
|
|
|
break; \
|
2001-04-29 02:20:46 +08:00
|
|
|
case IS_BOOL: \
|
2001-04-29 17:21:38 +08:00
|
|
|
case IS_RESOURCE: \
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL(holder) = Z_LVAL_P(op); \
|
2001-04-29 02:20:46 +08:00
|
|
|
break; \
|
1999-09-03 08:11:47 +08:00
|
|
|
default: \
|
2009-05-11 15:52:49 +08:00
|
|
|
zend_error(E_WARNING, "Cannot convert to ordinal value"); \
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL(holder) = 0; \
|
1999-09-03 08:11:47 +08:00
|
|
|
break; \
|
|
|
|
} \
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_TYPE(holder) = IS_LONG; \
|
1999-09-03 08:11:47 +08:00
|
|
|
(op) = &(holder); \
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
/* {{{ zendi_convert_to_boolean */
|
1999-09-03 08:11:47 +08:00
|
|
|
#define zendi_convert_to_boolean(op, holder, result) \
|
2005-05-31 19:16:51 +08:00
|
|
|
if (op==result) { \
|
1999-09-03 08:11:47 +08:00
|
|
|
convert_to_boolean(op); \
|
2007-11-20 21:26:36 +08:00
|
|
|
} else if (Z_TYPE_P(op) != IS_BOOL) { \
|
|
|
|
switch (Z_TYPE_P(op)) { \
|
2000-01-04 21:22:58 +08:00
|
|
|
case IS_NULL: \
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL(holder) = 0; \
|
1999-12-31 21:56:59 +08:00
|
|
|
break; \
|
1999-09-03 08:11:47 +08:00
|
|
|
case IS_RESOURCE: \
|
|
|
|
case IS_LONG: \
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL(holder) = (Z_LVAL_P(op) ? 1 : 0); \
|
1999-09-03 08:11:47 +08:00
|
|
|
break; \
|
|
|
|
case IS_DOUBLE: \
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL(holder) = (Z_DVAL_P(op) ? 1 : 0); \
|
1999-09-03 08:11:47 +08:00
|
|
|
break; \
|
|
|
|
case IS_STRING: \
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_STRLEN_P(op) == 0 \
|
|
|
|
|| (Z_STRLEN_P(op)==1 && Z_STRVAL_P(op)[0]=='0')) { \
|
|
|
|
Z_LVAL(holder) = 0; \
|
1999-09-03 08:11:47 +08:00
|
|
|
} else { \
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL(holder) = 1; \
|
1999-09-03 08:11:47 +08:00
|
|
|
} \
|
|
|
|
break; \
|
|
|
|
case IS_ARRAY: \
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL(holder) = (zend_hash_num_elements(Z_ARRVAL_P(op))?1:0); \
|
1999-09-03 08:11:47 +08:00
|
|
|
break; \
|
|
|
|
case IS_OBJECT: \
|
2004-03-14 21:52:36 +08:00
|
|
|
(holder) = (*(op)); \
|
|
|
|
zval_copy_ctor(&(holder)); \
|
|
|
|
convert_to_boolean(&(holder)); \
|
1999-09-03 08:11:47 +08:00
|
|
|
break; \
|
|
|
|
default: \
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL(holder) = 0; \
|
1999-09-03 08:11:47 +08:00
|
|
|
break; \
|
|
|
|
} \
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_TYPE(holder) = IS_BOOL; \
|
1999-09-03 08:11:47 +08:00
|
|
|
(op) = &(holder); \
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
/* {{{ convert_object_to_type */
|
2006-05-10 07:53:23 +08:00
|
|
|
#define convert_object_to_type(op, ctype, conv_func) \
|
2004-03-28 20:08:26 +08:00
|
|
|
if (Z_OBJ_HT_P(op)->cast_object) { \
|
2006-05-10 07:53:23 +08:00
|
|
|
zval dst; \
|
|
|
|
if (Z_OBJ_HT_P(op)->cast_object(op, &dst, ctype TSRMLS_CC) == FAILURE) { \
|
2009-05-11 15:52:49 +08:00
|
|
|
zend_error(E_RECOVERABLE_ERROR, \
|
|
|
|
"Object of class %s could not be converted to %s", Z_OBJCE_P(op)->name, \
|
2006-05-25 18:01:06 +08:00
|
|
|
zend_get_type_by_const(ctype)); \
|
2006-05-10 07:53:23 +08:00
|
|
|
} else { \
|
|
|
|
zval_dtor(op); \
|
|
|
|
Z_TYPE_P(op) = ctype; \
|
|
|
|
op->value = dst.value; \
|
2004-03-28 20:08:26 +08:00
|
|
|
} \
|
|
|
|
} else { \
|
2009-05-11 15:52:49 +08:00
|
|
|
if (Z_OBJ_HT_P(op)->get) { \
|
2004-03-28 20:08:26 +08:00
|
|
|
zval *newop = Z_OBJ_HT_P(op)->get(op TSRMLS_CC); \
|
2009-05-11 15:52:49 +08:00
|
|
|
if (Z_TYPE_P(newop) != IS_OBJECT) { \
|
2004-03-28 20:08:26 +08:00
|
|
|
/* for safety - avoid loop */ \
|
|
|
|
zval_dtor(op); \
|
|
|
|
*op = *newop; \
|
|
|
|
FREE_ZVAL(newop); \
|
|
|
|
conv_func(op); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
ZEND_API void convert_to_long(zval *op) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_TYPE_P(op) != IS_LONG) {
|
2006-12-11 23:16:07 +08:00
|
|
|
convert_to_long_base(op, 10);
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API void convert_to_long_base(zval *op, int base) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
long tmp;
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
switch (Z_TYPE_P(op)) {
|
2000-01-04 21:22:58 +08:00
|
|
|
case IS_NULL:
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(op) = 0;
|
1999-12-31 21:56:59 +08:00
|
|
|
break;
|
2001-07-30 12:54:16 +08:00
|
|
|
case IS_RESOURCE: {
|
|
|
|
TSRMLS_FETCH();
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
zend_list_delete(Z_LVAL_P(op));
|
2001-07-30 12:54:16 +08:00
|
|
|
}
|
2001-04-28 10:06:35 +08:00
|
|
|
/* break missing intentionally */
|
1999-09-03 08:11:47 +08:00
|
|
|
case IS_BOOL:
|
1999-04-08 02:10:10 +08:00
|
|
|
case IS_LONG:
|
1999-07-24 00:02:51 +08:00
|
|
|
break;
|
1999-04-08 02:10:10 +08:00
|
|
|
case IS_DOUBLE:
|
2009-06-05 02:20:45 +08:00
|
|
|
Z_LVAL_P(op) = zend_dval_to_lval(Z_DVAL_P(op));
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
case IS_STRING:
|
2009-05-11 15:52:49 +08:00
|
|
|
{
|
|
|
|
char *strval = Z_STRVAL_P(op);
|
|
|
|
|
|
|
|
Z_LVAL_P(op) = strtol(strval, NULL, base);
|
|
|
|
STR_FREE(strval);
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
case IS_ARRAY:
|
2007-11-20 21:26:36 +08:00
|
|
|
tmp = (zend_hash_num_elements(Z_ARRVAL_P(op))?1:0);
|
1999-04-08 02:10:10 +08:00
|
|
|
zval_dtor(op);
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(op) = tmp;
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
case IS_OBJECT:
|
2004-03-14 23:45:09 +08:00
|
|
|
{
|
2004-03-28 20:08:26 +08:00
|
|
|
int retval = 1;
|
2003-05-28 02:52:25 +08:00
|
|
|
TSRMLS_FETCH();
|
2004-03-14 23:45:09 +08:00
|
|
|
|
2004-03-28 20:08:26 +08:00
|
|
|
convert_object_to_type(op, IS_LONG, convert_to_long);
|
2004-05-10 22:56:21 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_TYPE_P(op) == IS_LONG) {
|
2004-05-10 22:56:21 +08:00
|
|
|
return;
|
|
|
|
}
|
2008-03-18 22:10:45 +08:00
|
|
|
zend_error(E_NOTICE, "Object of class %s could not be converted to int", Z_OBJCE_P(op)->name);
|
2009-05-11 15:52:49 +08:00
|
|
|
|
2005-08-05 17:02:14 +08:00
|
|
|
zval_dtor(op);
|
|
|
|
ZVAL_LONG(op, retval);
|
|
|
|
return;
|
2003-05-28 02:52:25 +08:00
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
default:
|
|
|
|
zend_error(E_WARNING, "Cannot convert to ordinal value");
|
|
|
|
zval_dtor(op);
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(op) = 0;
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_TYPE_P(op) = IS_LONG;
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API void convert_to_double(zval *op) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
double tmp;
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
switch (Z_TYPE_P(op)) {
|
2000-01-04 21:22:58 +08:00
|
|
|
case IS_NULL:
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_DVAL_P(op) = 0.0;
|
1999-12-31 21:56:59 +08:00
|
|
|
break;
|
2001-07-30 12:54:16 +08:00
|
|
|
case IS_RESOURCE: {
|
|
|
|
TSRMLS_FETCH();
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
zend_list_delete(Z_LVAL_P(op));
|
2001-07-30 12:54:16 +08:00
|
|
|
}
|
2001-04-28 10:06:35 +08:00
|
|
|
/* break missing intentionally */
|
1999-09-03 08:11:47 +08:00
|
|
|
case IS_BOOL:
|
1999-04-08 02:10:10 +08:00
|
|
|
case IS_LONG:
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_DVAL_P(op) = (double) Z_LVAL_P(op);
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
case IS_DOUBLE:
|
|
|
|
break;
|
|
|
|
case IS_STRING:
|
2009-05-11 15:52:49 +08:00
|
|
|
{
|
|
|
|
char *strval = Z_STRVAL_P(op);
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 15:52:49 +08:00
|
|
|
Z_DVAL_P(op) = zend_strtod(strval, NULL);
|
|
|
|
STR_FREE(strval);
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
case IS_ARRAY:
|
2007-11-20 21:26:36 +08:00
|
|
|
tmp = (zend_hash_num_elements(Z_ARRVAL_P(op))?1:0);
|
1999-04-08 02:10:10 +08:00
|
|
|
zval_dtor(op);
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_DVAL_P(op) = tmp;
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
1999-05-01 09:04:13 +08:00
|
|
|
case IS_OBJECT:
|
2004-03-14 23:45:09 +08:00
|
|
|
{
|
2004-03-28 20:08:26 +08:00
|
|
|
double retval = 1.0;
|
2003-05-28 02:52:25 +08:00
|
|
|
TSRMLS_FETCH();
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2004-03-28 20:08:26 +08:00
|
|
|
convert_object_to_type(op, IS_DOUBLE, convert_to_double);
|
2004-03-14 23:45:09 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_TYPE_P(op) == IS_DOUBLE) {
|
2004-05-10 22:56:21 +08:00
|
|
|
return;
|
|
|
|
}
|
2008-03-18 22:10:45 +08:00
|
|
|
zend_error(E_NOTICE, "Object of class %s could not be converted to double", Z_OBJCE_P(op)->name);
|
2006-06-05 21:58:52 +08:00
|
|
|
|
2004-03-28 20:08:26 +08:00
|
|
|
zval_dtor(op);
|
|
|
|
ZVAL_DOUBLE(op, retval);
|
2004-03-14 23:45:09 +08:00
|
|
|
break;
|
2007-11-20 21:26:36 +08:00
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
default:
|
2007-11-20 21:26:36 +08:00
|
|
|
zend_error(E_WARNING, "Cannot convert to real value (type=%d)", Z_TYPE_P(op));
|
1999-04-08 02:10:10 +08:00
|
|
|
zval_dtor(op);
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_DVAL_P(op) = 0;
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_TYPE_P(op) = IS_DOUBLE;
|
1999-12-31 21:56:59 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-12-31 21:56:59 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API void convert_to_null(zval *op) /* {{{ */
|
1999-12-31 21:56:59 +08:00
|
|
|
{
|
2006-05-10 07:53:23 +08:00
|
|
|
if (Z_TYPE_P(op) == IS_OBJECT) {
|
2004-03-28 18:44:48 +08:00
|
|
|
if (Z_OBJ_HT_P(op)->cast_object) {
|
2006-05-10 07:53:23 +08:00
|
|
|
zval *org;
|
2003-05-28 02:52:25 +08:00
|
|
|
TSRMLS_FETCH();
|
2006-05-10 07:53:23 +08:00
|
|
|
|
|
|
|
ALLOC_ZVAL(org);
|
|
|
|
*org = *op;
|
|
|
|
if (Z_OBJ_HT_P(op)->cast_object(org, op, IS_NULL TSRMLS_CC) == SUCCESS) {
|
|
|
|
zval_dtor(org);
|
2003-09-18 19:50:05 +08:00
|
|
|
return;
|
|
|
|
}
|
2006-05-10 07:53:23 +08:00
|
|
|
*op = *org;
|
2006-11-16 01:29:08 +08:00
|
|
|
FREE_ZVAL(org);
|
2003-05-28 02:52:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-31 21:56:59 +08:00
|
|
|
zval_dtor(op);
|
2006-05-10 07:53:23 +08:00
|
|
|
Z_TYPE_P(op) = IS_NULL;
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API void convert_to_boolean(zval *op) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
switch (Z_TYPE_P(op)) {
|
1999-04-08 02:10:10 +08:00
|
|
|
case IS_BOOL:
|
|
|
|
break;
|
2000-01-04 21:22:58 +08:00
|
|
|
case IS_NULL:
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(op) = 0;
|
1999-12-31 21:56:59 +08:00
|
|
|
break;
|
2001-07-30 12:54:16 +08:00
|
|
|
case IS_RESOURCE: {
|
|
|
|
TSRMLS_FETCH();
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
zend_list_delete(Z_LVAL_P(op));
|
2001-07-30 12:54:16 +08:00
|
|
|
}
|
2001-04-28 10:06:35 +08:00
|
|
|
/* break missing intentionally */
|
1999-09-03 08:11:47 +08:00
|
|
|
case IS_LONG:
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(op) = (Z_LVAL_P(op) ? 1 : 0);
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
case IS_DOUBLE:
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(op) = (Z_DVAL_P(op) ? 1 : 0);
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
case IS_STRING:
|
2009-05-11 15:52:49 +08:00
|
|
|
{
|
|
|
|
char *strval = Z_STRVAL_P(op);
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 15:52:49 +08:00
|
|
|
if (Z_STRLEN_P(op) == 0
|
|
|
|
|| (Z_STRLEN_P(op)==1 && Z_STRVAL_P(op)[0]=='0')) {
|
|
|
|
Z_LVAL_P(op) = 0;
|
|
|
|
} else {
|
|
|
|
Z_LVAL_P(op) = 1;
|
|
|
|
}
|
|
|
|
STR_FREE(strval);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IS_ARRAY:
|
2007-11-20 21:26:36 +08:00
|
|
|
tmp = (zend_hash_num_elements(Z_ARRVAL_P(op))?1:0);
|
1999-04-08 02:10:10 +08:00
|
|
|
zval_dtor(op);
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(op) = tmp;
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
1999-05-01 09:04:13 +08:00
|
|
|
case IS_OBJECT:
|
2004-03-14 23:45:09 +08:00
|
|
|
{
|
2004-03-28 20:08:26 +08:00
|
|
|
zend_bool retval = 1;
|
2003-05-28 02:52:25 +08:00
|
|
|
TSRMLS_FETCH();
|
2004-03-14 23:45:09 +08:00
|
|
|
|
2005-09-12 19:48:57 +08:00
|
|
|
convert_object_to_type(op, IS_BOOL, convert_to_boolean);
|
2004-05-10 22:56:21 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_TYPE_P(op) == IS_BOOL) {
|
2004-05-10 22:56:21 +08:00
|
|
|
return;
|
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2004-03-28 20:08:26 +08:00
|
|
|
zval_dtor(op);
|
|
|
|
ZVAL_BOOL(op, retval);
|
2004-03-14 23:45:09 +08:00
|
|
|
break;
|
2003-05-28 02:52:25 +08:00
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
default:
|
|
|
|
zval_dtor(op);
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(op) = 0;
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_TYPE_P(op) = IS_BOOL;
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2013-01-15 04:23:52 +08:00
|
|
|
ZEND_API void _convert_to_cstring(zval *op ZEND_FILE_LINE_DC) /* {{{ */
|
|
|
|
{
|
|
|
|
double dval;
|
|
|
|
switch (Z_TYPE_P(op)) {
|
|
|
|
case IS_DOUBLE: {
|
|
|
|
TSRMLS_FETCH();
|
|
|
|
dval = Z_DVAL_P(op);
|
|
|
|
Z_STRLEN_P(op) = zend_spprintf(&Z_STRVAL_P(op), 0, "%.*H", (int) EG(precision), dval);
|
|
|
|
/* %H already handles removing trailing zeros from the fractional part, yay */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2013-01-15 10:08:26 +08:00
|
|
|
_convert_to_string(op ZEND_FILE_LINE_CC);
|
2013-01-15 04:23:52 +08:00
|
|
|
}
|
|
|
|
Z_TYPE_P(op) = IS_STRING;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
long lval;
|
|
|
|
double dval;
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
switch (Z_TYPE_P(op)) {
|
2000-01-04 21:22:58 +08:00
|
|
|
case IS_NULL:
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_STRVAL_P(op) = STR_EMPTY_ALLOC();
|
|
|
|
Z_STRLEN_P(op) = 0;
|
1999-12-31 21:56:59 +08:00
|
|
|
break;
|
1999-04-08 02:10:10 +08:00
|
|
|
case IS_STRING:
|
|
|
|
break;
|
|
|
|
case IS_BOOL:
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_LVAL_P(op)) {
|
|
|
|
Z_STRVAL_P(op) = estrndup_rel("1", 1);
|
|
|
|
Z_STRLEN_P(op) = 1;
|
1999-07-05 07:50:58 +08:00
|
|
|
} else {
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_STRVAL_P(op) = STR_EMPTY_ALLOC();
|
|
|
|
Z_STRLEN_P(op) = 0;
|
1999-07-05 07:50:58 +08:00
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
2000-05-18 18:21:24 +08:00
|
|
|
case IS_RESOURCE: {
|
2007-11-20 21:26:36 +08:00
|
|
|
long tmp = Z_LVAL_P(op);
|
2003-11-08 22:06:08 +08:00
|
|
|
TSRMLS_FETCH();
|
2001-04-28 10:06:35 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
zend_list_delete(Z_LVAL_P(op));
|
|
|
|
Z_STRLEN_P(op) = zend_spprintf(&Z_STRVAL_P(op), 0, "Resource id #%ld", tmp);
|
2000-05-18 18:21:24 +08:00
|
|
|
break;
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
case IS_LONG:
|
2007-11-20 21:26:36 +08:00
|
|
|
lval = Z_LVAL_P(op);
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 15:52:49 +08:00
|
|
|
Z_STRLEN_P(op) = zend_spprintf(&Z_STRVAL_P(op), 0, "%ld", lval);
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
case IS_DOUBLE: {
|
2003-11-08 22:06:08 +08:00
|
|
|
TSRMLS_FETCH();
|
2007-11-20 21:26:36 +08:00
|
|
|
dval = Z_DVAL_P(op);
|
2009-05-11 15:52:49 +08:00
|
|
|
Z_STRLEN_P(op) = zend_spprintf(&Z_STRVAL_P(op), 0, "%.*G", (int) EG(precision), dval);
|
1999-04-08 02:10:10 +08:00
|
|
|
/* %G already handles removing trailing zeros from the fractional part, yay */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IS_ARRAY:
|
2003-11-07 04:33:47 +08:00
|
|
|
zend_error(E_NOTICE, "Array to string conversion");
|
1999-04-08 02:10:10 +08:00
|
|
|
zval_dtor(op);
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_STRVAL_P(op) = estrndup_rel("Array", sizeof("Array")-1);
|
|
|
|
Z_STRLEN_P(op) = sizeof("Array")-1;
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
2003-11-08 22:06:08 +08:00
|
|
|
case IS_OBJECT: {
|
|
|
|
TSRMLS_FETCH();
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2004-03-28 20:08:26 +08:00
|
|
|
convert_object_to_type(op, IS_STRING, convert_to_string);
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_TYPE_P(op) == IS_STRING) {
|
2004-05-10 22:56:21 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-03-28 20:08:26 +08:00
|
|
|
zend_error(E_NOTICE, "Object of class %s to string conversion", Z_OBJCE_P(op)->name);
|
2003-09-18 19:38:33 +08:00
|
|
|
zval_dtor(op);
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_STRVAL_P(op) = estrndup_rel("Object", sizeof("Object")-1);
|
|
|
|
Z_STRLEN_P(op) = sizeof("Object")-1;
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
2003-11-08 22:06:08 +08:00
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
default:
|
|
|
|
zval_dtor(op);
|
2001-07-11 19:35:11 +08:00
|
|
|
ZVAL_BOOL(op, 0);
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_TYPE_P(op) = IS_STRING;
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 15:52:49 +08:00
|
|
|
static void convert_scalar_to_array(zval *op, int type TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
1999-12-27 05:21:33 +08:00
|
|
|
zval *entry;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
1999-12-27 05:21:33 +08:00
|
|
|
ALLOC_ZVAL(entry);
|
1999-04-08 02:10:10 +08:00
|
|
|
*entry = *op;
|
1999-07-10 04:43:59 +08:00
|
|
|
INIT_PZVAL(entry);
|
2007-11-20 21:26:36 +08:00
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
switch (type) {
|
|
|
|
case IS_ARRAY:
|
2007-11-20 21:26:36 +08:00
|
|
|
ALLOC_HASHTABLE(Z_ARRVAL_P(op));
|
|
|
|
zend_hash_init(Z_ARRVAL_P(op), 0, NULL, ZVAL_PTR_DTOR, 0);
|
|
|
|
zend_hash_index_update(Z_ARRVAL_P(op), 0, (void *) &entry, sizeof(zval *), NULL);
|
|
|
|
Z_TYPE_P(op) = IS_ARRAY;
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
case IS_OBJECT:
|
2009-05-11 16:31:15 +08:00
|
|
|
object_init(op);
|
|
|
|
zend_hash_update(Z_OBJPROP_P(op), "scalar", sizeof("scalar"), (void *) &entry, sizeof(zval *), NULL);
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API void convert_to_array(zval *op) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2002-02-07 22:08:43 +08:00
|
|
|
TSRMLS_FETCH();
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
switch (Z_TYPE_P(op)) {
|
1999-04-08 02:10:10 +08:00
|
|
|
case IS_ARRAY:
|
|
|
|
break;
|
2001-08-16 22:04:04 +08:00
|
|
|
/* OBJECTS_OPTIMIZE */
|
1999-04-08 02:10:10 +08:00
|
|
|
case IS_OBJECT:
|
2001-08-16 22:04:04 +08:00
|
|
|
{
|
|
|
|
zval *tmp;
|
|
|
|
HashTable *ht;
|
|
|
|
|
|
|
|
ALLOC_HASHTABLE(ht);
|
|
|
|
zend_hash_init(ht, 0, NULL, ZVAL_PTR_DTOR, 0);
|
2010-06-27 01:14:33 +08:00
|
|
|
if (Z_OBJCE_P(op) == zend_ce_closure) {
|
|
|
|
convert_scalar_to_array(op, IS_ARRAY TSRMLS_CC);
|
|
|
|
if (Z_TYPE_P(op) == IS_ARRAY) {
|
|
|
|
zend_hash_destroy(ht);
|
|
|
|
FREE_HASHTABLE(ht);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (Z_OBJ_HT_P(op)->get_properties) {
|
2004-03-28 20:08:26 +08:00
|
|
|
HashTable *obj_ht = Z_OBJ_HT_P(op)->get_properties(op TSRMLS_CC);
|
2009-05-11 15:52:49 +08:00
|
|
|
if (obj_ht) {
|
2004-03-28 20:08:26 +08:00
|
|
|
zend_hash_copy(ht, obj_ht, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
convert_object_to_type(op, IS_ARRAY, convert_to_array);
|
2004-05-10 22:56:21 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_TYPE_P(op) == IS_ARRAY) {
|
2006-12-21 09:57:05 +08:00
|
|
|
zend_hash_destroy(ht);
|
|
|
|
FREE_HASHTABLE(ht);
|
2004-05-10 22:56:21 +08:00
|
|
|
return;
|
|
|
|
}
|
2002-02-07 22:08:43 +08:00
|
|
|
}
|
2001-08-16 22:04:04 +08:00
|
|
|
zval_dtor(op);
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_TYPE_P(op) = IS_ARRAY;
|
|
|
|
Z_ARRVAL_P(op) = ht;
|
2001-08-16 22:04:04 +08:00
|
|
|
}
|
2009-05-11 15:52:49 +08:00
|
|
|
break;
|
2000-02-13 08:52:33 +08:00
|
|
|
case IS_NULL:
|
2007-11-20 21:26:36 +08:00
|
|
|
ALLOC_HASHTABLE(Z_ARRVAL_P(op));
|
|
|
|
zend_hash_init(Z_ARRVAL_P(op), 0, NULL, ZVAL_PTR_DTOR, 0);
|
|
|
|
Z_TYPE_P(op) = IS_ARRAY;
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
default:
|
2009-05-11 15:52:49 +08:00
|
|
|
convert_scalar_to_array(op, IS_ARRAY TSRMLS_CC);
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API void convert_to_object(zval *op) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2009-05-11 15:52:49 +08:00
|
|
|
TSRMLS_FETCH();
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
switch (Z_TYPE_P(op)) {
|
1999-04-08 02:10:10 +08:00
|
|
|
case IS_ARRAY:
|
2001-08-12 02:04:07 +08:00
|
|
|
{
|
2007-11-20 21:26:36 +08:00
|
|
|
object_and_properties_init(op, zend_standard_class_def, Z_ARRVAL_P(op));
|
2001-08-12 02:04:07 +08:00
|
|
|
break;
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
case IS_OBJECT:
|
2009-05-11 15:52:49 +08:00
|
|
|
break;
|
2000-02-13 08:52:33 +08:00
|
|
|
case IS_NULL:
|
2009-05-11 16:31:15 +08:00
|
|
|
object_init(op);
|
|
|
|
break;
|
1999-04-08 02:10:10 +08:00
|
|
|
default:
|
2009-05-11 15:52:49 +08:00
|
|
|
convert_scalar_to_array(op, IS_OBJECT TSRMLS_CC);
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API void multi_convert_to_long_ex(int argc, ...) /* {{{ */
|
2000-09-06 01:55:57 +08:00
|
|
|
{
|
|
|
|
zval **arg;
|
|
|
|
va_list ap;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2000-09-06 01:55:57 +08:00
|
|
|
va_start(ap, argc);
|
|
|
|
|
|
|
|
while (argc--) {
|
|
|
|
arg = va_arg(ap, zval **);
|
|
|
|
convert_to_long_ex(arg);
|
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2000-09-06 01:55:57 +08:00
|
|
|
va_end(ap);
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2000-09-06 01:55:57 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API void multi_convert_to_double_ex(int argc, ...) /* {{{ */
|
2000-09-06 01:55:57 +08:00
|
|
|
{
|
|
|
|
zval **arg;
|
|
|
|
va_list ap;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2000-09-06 01:55:57 +08:00
|
|
|
va_start(ap, argc);
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
while (argc--) {
|
2000-09-06 01:55:57 +08:00
|
|
|
arg = va_arg(ap, zval **);
|
|
|
|
convert_to_double_ex(arg);
|
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2000-09-06 01:55:57 +08:00
|
|
|
va_end(ap);
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2000-09-06 01:55:57 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API void multi_convert_to_string_ex(int argc, ...) /* {{{ */
|
2000-09-06 01:55:57 +08:00
|
|
|
{
|
|
|
|
zval **arg;
|
|
|
|
va_list ap;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2000-09-06 01:55:57 +08:00
|
|
|
va_start(ap, argc);
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
while (argc--) {
|
2000-09-06 01:55:57 +08:00
|
|
|
arg = va_arg(ap, zval **);
|
|
|
|
convert_to_string_ex(arg);
|
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2000-09-06 01:55:57 +08:00
|
|
|
va_end(ap);
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2000-09-06 01:55:57 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int add_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zval op1_copy, op2_copy;
|
2007-11-20 21:26:36 +08:00
|
|
|
int converted = 0;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
while (1) {
|
|
|
|
switch (TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2))) {
|
|
|
|
case TYPE_PAIR(IS_LONG, IS_LONG): {
|
|
|
|
long lval = Z_LVAL_P(op1) + Z_LVAL_P(op2);
|
1999-09-30 01:45:44 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
/* check for overflow by comparing sign bits */
|
|
|
|
if ((Z_LVAL_P(op1) & LONG_SIGN_MASK) == (Z_LVAL_P(op2) & LONG_SIGN_MASK)
|
|
|
|
&& (Z_LVAL_P(op1) & LONG_SIGN_MASK) != (lval & LONG_SIGN_MASK)) {
|
|
|
|
|
|
|
|
ZVAL_DOUBLE(result, (double) Z_LVAL_P(op1) + (double) Z_LVAL_P(op2));
|
|
|
|
} else {
|
|
|
|
ZVAL_LONG(result, lval);
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
1999-07-27 05:56:45 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
case TYPE_PAIR(IS_LONG, IS_DOUBLE):
|
|
|
|
ZVAL_DOUBLE(result, ((double)Z_LVAL_P(op1)) + Z_DVAL_P(op2));
|
|
|
|
return SUCCESS;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
case TYPE_PAIR(IS_DOUBLE, IS_LONG):
|
|
|
|
ZVAL_DOUBLE(result, Z_DVAL_P(op1) + ((double)Z_LVAL_P(op2)));
|
|
|
|
return SUCCESS;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
case TYPE_PAIR(IS_DOUBLE, IS_DOUBLE):
|
|
|
|
ZVAL_DOUBLE(result, Z_DVAL_P(op1) + Z_DVAL_P(op2));
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
case TYPE_PAIR(IS_ARRAY, IS_ARRAY): {
|
|
|
|
zval *tmp;
|
|
|
|
|
|
|
|
if ((result == op1) && (result == op2)) {
|
|
|
|
/* $a += $a */
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
if (result != op1) {
|
|
|
|
*result = *op1;
|
|
|
|
zval_copy_ctor(result);
|
|
|
|
}
|
|
|
|
zend_hash_merge(Z_ARRVAL_P(result), Z_ARRVAL_P(op2), (void (*)(void *pData)) zval_add_ref, (void *) &tmp, sizeof(zval *), 0);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (!converted) {
|
|
|
|
zendi_convert_scalar_to_number(op1, op1_copy, result);
|
|
|
|
zendi_convert_scalar_to_number(op2, op2_copy, result);
|
|
|
|
converted = 1;
|
|
|
|
} else {
|
|
|
|
zend_error(E_ERROR, "Unsupported operand types");
|
|
|
|
return FAILURE; /* unknown datatype */
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int sub_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zval op1_copy, op2_copy;
|
2007-11-20 21:26:36 +08:00
|
|
|
int converted = 0;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
switch (TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2))) {
|
|
|
|
case TYPE_PAIR(IS_LONG, IS_LONG): {
|
|
|
|
long lval = Z_LVAL_P(op1) - Z_LVAL_P(op2);
|
|
|
|
|
|
|
|
/* check for overflow by comparing sign bits */
|
|
|
|
if ((Z_LVAL_P(op1) & LONG_SIGN_MASK) != (Z_LVAL_P(op2) & LONG_SIGN_MASK)
|
|
|
|
&& (Z_LVAL_P(op1) & LONG_SIGN_MASK) != (lval & LONG_SIGN_MASK)) {
|
|
|
|
|
|
|
|
ZVAL_DOUBLE(result, (double) Z_LVAL_P(op1) - (double) Z_LVAL_P(op2));
|
|
|
|
} else {
|
|
|
|
ZVAL_LONG(result, lval);
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
case TYPE_PAIR(IS_LONG, IS_DOUBLE):
|
|
|
|
ZVAL_DOUBLE(result, ((double)Z_LVAL_P(op1)) - Z_DVAL_P(op2));
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
case TYPE_PAIR(IS_DOUBLE, IS_LONG):
|
|
|
|
ZVAL_DOUBLE(result, Z_DVAL_P(op1) - ((double)Z_LVAL_P(op2)));
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
case TYPE_PAIR(IS_DOUBLE, IS_DOUBLE):
|
|
|
|
ZVAL_DOUBLE(result, Z_DVAL_P(op1) - Z_DVAL_P(op2));
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (!converted) {
|
|
|
|
zendi_convert_scalar_to_number(op1, op1_copy, result);
|
|
|
|
zendi_convert_scalar_to_number(op2, op2_copy, result);
|
|
|
|
converted = 1;
|
|
|
|
} else {
|
|
|
|
zend_error(E_ERROR, "Unsupported operand types");
|
|
|
|
return FAILURE; /* unknown datatype */
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int mul_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zval op1_copy, op2_copy;
|
2007-11-20 21:26:36 +08:00
|
|
|
int converted = 0;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
while (1) {
|
|
|
|
switch (TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2))) {
|
|
|
|
case TYPE_PAIR(IS_LONG, IS_LONG): {
|
|
|
|
long overflow;
|
2004-03-17 17:25:52 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
ZEND_SIGNED_MULTIPLY_LONG(Z_LVAL_P(op1),Z_LVAL_P(op2), Z_LVAL_P(result),Z_DVAL_P(result),overflow);
|
|
|
|
Z_TYPE_P(result) = overflow ? IS_DOUBLE : IS_LONG;
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
case TYPE_PAIR(IS_LONG, IS_DOUBLE):
|
|
|
|
ZVAL_DOUBLE(result, ((double)Z_LVAL_P(op1)) * Z_DVAL_P(op2));
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
case TYPE_PAIR(IS_DOUBLE, IS_LONG):
|
|
|
|
ZVAL_DOUBLE(result, Z_DVAL_P(op1) * ((double)Z_LVAL_P(op2)));
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
case TYPE_PAIR(IS_DOUBLE, IS_DOUBLE):
|
|
|
|
ZVAL_DOUBLE(result, Z_DVAL_P(op1) * Z_DVAL_P(op2));
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (!converted) {
|
|
|
|
zendi_convert_scalar_to_number(op1, op1_copy, result);
|
|
|
|
zendi_convert_scalar_to_number(op2, op2_copy, result);
|
|
|
|
converted = 1;
|
|
|
|
} else {
|
|
|
|
zend_error(E_ERROR, "Unsupported operand types");
|
|
|
|
return FAILURE; /* unknown datatype */
|
|
|
|
}
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int div_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zval op1_copy, op2_copy;
|
2007-11-20 21:26:36 +08:00
|
|
|
int converted = 0;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
switch (TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2))) {
|
|
|
|
case TYPE_PAIR(IS_LONG, IS_LONG):
|
|
|
|
if (Z_LVAL_P(op2) == 0) {
|
|
|
|
zend_error(E_WARNING, "Division by zero");
|
|
|
|
ZVAL_BOOL(result, 0);
|
|
|
|
return FAILURE; /* division by zero */
|
2008-05-29 19:45:13 +08:00
|
|
|
} else if (Z_LVAL_P(op2) == -1 && Z_LVAL_P(op1) == LONG_MIN) {
|
|
|
|
/* Prevent overflow error/crash */
|
|
|
|
ZVAL_DOUBLE(result, (double) LONG_MIN / -1);
|
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
}
|
|
|
|
if (Z_LVAL_P(op1) % Z_LVAL_P(op2) == 0) { /* integer */
|
|
|
|
ZVAL_LONG(result, Z_LVAL_P(op1) / Z_LVAL_P(op2));
|
|
|
|
} else {
|
|
|
|
ZVAL_DOUBLE(result, ((double) Z_LVAL_P(op1)) / Z_LVAL_P(op2));
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
case TYPE_PAIR(IS_DOUBLE, IS_LONG):
|
|
|
|
if (Z_LVAL_P(op2) == 0) {
|
|
|
|
zend_error(E_WARNING, "Division by zero");
|
|
|
|
ZVAL_BOOL(result, 0);
|
|
|
|
return FAILURE; /* division by zero */
|
|
|
|
}
|
|
|
|
ZVAL_DOUBLE(result, Z_DVAL_P(op1) / (double)Z_LVAL_P(op2));
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
case TYPE_PAIR(IS_LONG, IS_DOUBLE):
|
|
|
|
if (Z_DVAL_P(op2) == 0) {
|
|
|
|
zend_error(E_WARNING, "Division by zero");
|
|
|
|
ZVAL_BOOL(result, 0);
|
|
|
|
return FAILURE; /* division by zero */
|
|
|
|
}
|
|
|
|
ZVAL_DOUBLE(result, (double)Z_LVAL_P(op1) / Z_DVAL_P(op2));
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
case TYPE_PAIR(IS_DOUBLE, IS_DOUBLE):
|
|
|
|
if (Z_DVAL_P(op2) == 0) {
|
|
|
|
zend_error(E_WARNING, "Division by zero");
|
|
|
|
ZVAL_BOOL(result, 0);
|
|
|
|
return FAILURE; /* division by zero */
|
|
|
|
}
|
|
|
|
ZVAL_DOUBLE(result, Z_DVAL_P(op1) / Z_DVAL_P(op2));
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (!converted) {
|
|
|
|
zendi_convert_scalar_to_number(op1, op1_copy, result);
|
|
|
|
zendi_convert_scalar_to_number(op2, op2_copy, result);
|
|
|
|
converted = 1;
|
|
|
|
} else {
|
|
|
|
zend_error(E_ERROR, "Unsupported operand types");
|
|
|
|
return FAILURE; /* unknown datatype */
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int mod_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zval op1_copy, op2_copy;
|
2010-05-12 19:10:06 +08:00
|
|
|
long op1_lval;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
1999-07-27 05:56:45 +08:00
|
|
|
zendi_convert_to_long(op1, op1_copy, result);
|
2010-05-12 19:10:06 +08:00
|
|
|
op1_lval = Z_LVAL_P(op1);
|
1999-07-27 05:56:45 +08:00
|
|
|
zendi_convert_to_long(op2, op2_copy, result);
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_LVAL_P(op2) == 0) {
|
2006-10-04 01:54:51 +08:00
|
|
|
zend_error(E_WARNING, "Division by zero");
|
2001-07-11 19:35:11 +08:00
|
|
|
ZVAL_BOOL(result, 0);
|
1999-04-08 02:10:10 +08:00
|
|
|
return FAILURE; /* modulus by zero */
|
|
|
|
}
|
|
|
|
|
2009-02-17 22:15:52 +08:00
|
|
|
if (Z_LVAL_P(op2) == -1) {
|
2009-02-17 23:15:18 +08:00
|
|
|
/* Prevent overflow error/crash if op1==LONG_MIN */
|
2004-02-23 04:02:26 +08:00
|
|
|
ZVAL_LONG(result, 0);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2010-05-12 19:10:06 +08:00
|
|
|
ZVAL_LONG(result, op1_lval % Z_LVAL_P(op2));
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int boolean_xor_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zval op1_copy, op2_copy;
|
2010-05-12 19:10:06 +08:00
|
|
|
long op1_lval;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
1999-07-27 05:56:45 +08:00
|
|
|
zendi_convert_to_boolean(op1, op1_copy, result);
|
2010-05-12 19:10:06 +08:00
|
|
|
op1_lval = Z_LVAL_P(op1);
|
1999-07-27 05:56:45 +08:00
|
|
|
zendi_convert_to_boolean(op2, op2_copy, result);
|
2010-05-12 19:10:06 +08:00
|
|
|
ZVAL_BOOL(result, op1_lval ^ Z_LVAL_P(op2));
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int boolean_not_function(zval *result, zval *op1 TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zval op1_copy;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
1999-07-27 05:56:45 +08:00
|
|
|
zendi_convert_to_boolean(op1, op1_copy, result);
|
2007-11-20 21:26:36 +08:00
|
|
|
ZVAL_BOOL(result, !Z_LVAL_P(op1));
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int bitwise_not_function(zval *result, zval *op1 TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zval op1_copy = *op1;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
op1 = &op1_copy;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
if (Z_TYPE_P(op1) == IS_LONG) {
|
|
|
|
ZVAL_LONG(result, ~Z_LVAL_P(op1));
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
} else if (Z_TYPE_P(op1) == IS_DOUBLE) {
|
2009-06-05 02:20:45 +08:00
|
|
|
ZVAL_LONG(result, ~zend_dval_to_lval(Z_DVAL_P(op1)));
|
2007-11-20 21:26:36 +08:00
|
|
|
return SUCCESS;
|
|
|
|
} else if (Z_TYPE_P(op1) == IS_STRING) {
|
2003-01-31 07:36:08 +08:00
|
|
|
int i;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_TYPE_P(result) = IS_STRING;
|
|
|
|
Z_STRVAL_P(result) = estrndup(Z_STRVAL_P(op1), Z_STRLEN_P(op1));
|
|
|
|
Z_STRLEN_P(result) = Z_STRLEN_P(op1);
|
|
|
|
for (i = 0; i < Z_STRLEN_P(op1); i++) {
|
|
|
|
Z_STRVAL_P(result)[i] = ~Z_STRVAL_P(op1)[i];
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
zend_error(E_ERROR, "Unsupported operand types");
|
|
|
|
return FAILURE; /* unknown datatype */
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int bitwise_or_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zval op1_copy, op2_copy;
|
2010-05-12 19:10:06 +08:00
|
|
|
long op1_lval;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
if (Z_TYPE_P(op1) == IS_STRING && Z_TYPE_P(op2) == IS_STRING) {
|
1999-04-08 02:10:10 +08:00
|
|
|
zval *longer, *shorter;
|
2000-04-13 23:56:02 +08:00
|
|
|
char *result_str;
|
2003-01-31 07:36:08 +08:00
|
|
|
int i, result_len;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_STRLEN_P(op1) >= Z_STRLEN_P(op2)) {
|
1999-04-08 02:10:10 +08:00
|
|
|
longer = op1;
|
|
|
|
shorter = op2;
|
|
|
|
} else {
|
|
|
|
longer = op2;
|
|
|
|
shorter = op1;
|
|
|
|
}
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_TYPE_P(result) = IS_STRING;
|
|
|
|
result_len = Z_STRLEN_P(longer);
|
|
|
|
result_str = estrndup(Z_STRVAL_P(longer), Z_STRLEN_P(longer));
|
|
|
|
for (i = 0; i < Z_STRLEN_P(shorter); i++) {
|
|
|
|
result_str[i] |= Z_STRVAL_P(shorter)[i];
|
2000-04-13 23:56:02 +08:00
|
|
|
}
|
|
|
|
if (result==op1) {
|
2007-11-20 21:26:36 +08:00
|
|
|
STR_FREE(Z_STRVAL_P(result));
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_STRVAL_P(result) = result_str;
|
|
|
|
Z_STRLEN_P(result) = result_len;
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
1999-07-27 05:56:45 +08:00
|
|
|
zendi_convert_to_long(op1, op1_copy, result);
|
2010-05-12 19:10:06 +08:00
|
|
|
op1_lval = Z_LVAL_P(op1);
|
1999-07-27 05:56:45 +08:00
|
|
|
zendi_convert_to_long(op2, op2_copy, result);
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2010-05-12 19:10:06 +08:00
|
|
|
ZVAL_LONG(result, op1_lval | Z_LVAL_P(op2));
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int bitwise_and_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zval op1_copy, op2_copy;
|
2010-05-12 19:10:06 +08:00
|
|
|
long op1_lval;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
if (Z_TYPE_P(op1) == IS_STRING && Z_TYPE_P(op2) == IS_STRING) {
|
1999-04-08 02:10:10 +08:00
|
|
|
zval *longer, *shorter;
|
2000-04-13 23:56:02 +08:00
|
|
|
char *result_str;
|
2003-01-31 07:36:08 +08:00
|
|
|
int i, result_len;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_STRLEN_P(op1) >= Z_STRLEN_P(op2)) {
|
1999-04-08 02:10:10 +08:00
|
|
|
longer = op1;
|
|
|
|
shorter = op2;
|
|
|
|
} else {
|
|
|
|
longer = op2;
|
|
|
|
shorter = op1;
|
|
|
|
}
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_TYPE_P(result) = IS_STRING;
|
|
|
|
result_len = Z_STRLEN_P(shorter);
|
|
|
|
result_str = estrndup(Z_STRVAL_P(shorter), Z_STRLEN_P(shorter));
|
|
|
|
for (i = 0; i < Z_STRLEN_P(shorter); i++) {
|
|
|
|
result_str[i] &= Z_STRVAL_P(longer)[i];
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2000-04-13 23:56:02 +08:00
|
|
|
if (result==op1) {
|
2007-11-20 21:26:36 +08:00
|
|
|
STR_FREE(Z_STRVAL_P(result));
|
2000-04-13 23:56:02 +08:00
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_STRVAL_P(result) = result_str;
|
|
|
|
Z_STRLEN_P(result) = result_len;
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
|
1999-07-27 05:56:45 +08:00
|
|
|
zendi_convert_to_long(op1, op1_copy, result);
|
2010-05-12 19:10:06 +08:00
|
|
|
op1_lval = Z_LVAL_P(op1);
|
1999-07-27 05:56:45 +08:00
|
|
|
zendi_convert_to_long(op2, op2_copy, result);
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2010-05-12 19:10:06 +08:00
|
|
|
ZVAL_LONG(result, op1_lval & Z_LVAL_P(op2));
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int bitwise_xor_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zval op1_copy, op2_copy;
|
2010-05-12 19:10:06 +08:00
|
|
|
long op1_lval;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
if (Z_TYPE_P(op1) == IS_STRING && Z_TYPE_P(op2) == IS_STRING) {
|
1999-04-08 02:10:10 +08:00
|
|
|
zval *longer, *shorter;
|
2000-04-13 23:56:02 +08:00
|
|
|
char *result_str;
|
2003-01-31 07:36:08 +08:00
|
|
|
int i, result_len;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_STRLEN_P(op1) >= Z_STRLEN_P(op2)) {
|
1999-04-08 02:10:10 +08:00
|
|
|
longer = op1;
|
|
|
|
shorter = op2;
|
|
|
|
} else {
|
|
|
|
longer = op2;
|
|
|
|
shorter = op1;
|
|
|
|
}
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_TYPE_P(result) = IS_STRING;
|
|
|
|
result_len = Z_STRLEN_P(shorter);
|
|
|
|
result_str = estrndup(Z_STRVAL_P(shorter), Z_STRLEN_P(shorter));
|
|
|
|
for (i = 0; i < Z_STRLEN_P(shorter); i++) {
|
|
|
|
result_str[i] ^= Z_STRVAL_P(longer)[i];
|
2000-04-13 23:56:02 +08:00
|
|
|
}
|
|
|
|
if (result==op1) {
|
2007-11-20 21:26:36 +08:00
|
|
|
STR_FREE(Z_STRVAL_P(result));
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_STRVAL_P(result) = result_str;
|
|
|
|
Z_STRLEN_P(result) = result_len;
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
1999-07-27 05:56:45 +08:00
|
|
|
zendi_convert_to_long(op1, op1_copy, result);
|
2010-05-12 19:10:06 +08:00
|
|
|
op1_lval = Z_LVAL_P(op1);
|
2007-11-20 21:26:36 +08:00
|
|
|
zendi_convert_to_long(op2, op2_copy, result);
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2010-05-12 19:10:06 +08:00
|
|
|
ZVAL_LONG(result, op1_lval ^ Z_LVAL_P(op2));
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int shift_left_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zval op1_copy, op2_copy;
|
2010-05-12 19:10:06 +08:00
|
|
|
long op1_lval;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
1999-07-27 05:56:45 +08:00
|
|
|
zendi_convert_to_long(op1, op1_copy, result);
|
2010-05-12 19:10:06 +08:00
|
|
|
op1_lval = Z_LVAL_P(op1);
|
1999-07-27 05:56:45 +08:00
|
|
|
zendi_convert_to_long(op2, op2_copy, result);
|
2010-05-12 19:10:06 +08:00
|
|
|
ZVAL_LONG(result, op1_lval << Z_LVAL_P(op2));
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int shift_right_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zval op1_copy, op2_copy;
|
2010-05-12 19:10:06 +08:00
|
|
|
long op1_lval;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
1999-07-27 05:56:45 +08:00
|
|
|
zendi_convert_to_long(op1, op1_copy, result);
|
2010-05-12 19:10:06 +08:00
|
|
|
op1_lval = Z_LVAL_P(op1);
|
1999-07-27 05:56:45 +08:00
|
|
|
zendi_convert_to_long(op2, op2_copy, result);
|
2010-05-12 19:10:06 +08:00
|
|
|
ZVAL_LONG(result, op1_lval >> Z_LVAL_P(op2));
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
|
|
|
/* must support result==op1 */
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int add_char_to_string(zval *result, const zval *op1, const zval *op2) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2010-04-20 19:05:54 +08:00
|
|
|
int length = Z_STRLEN_P(op1) + 1;
|
|
|
|
char *buf;
|
|
|
|
|
|
|
|
if (IS_INTERNED(Z_STRVAL_P(op1))) {
|
|
|
|
buf = (char *) emalloc(length + 1);
|
|
|
|
memcpy(buf, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
|
|
|
|
} else {
|
|
|
|
buf = (char *) erealloc(Z_STRVAL_P(op1), length + 1);
|
|
|
|
}
|
|
|
|
buf[length - 1] = (char) Z_LVAL_P(op2);
|
|
|
|
buf[length] = 0;
|
|
|
|
ZVAL_STRINGL(result, buf, length, 0);
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
|
|
|
/* must support result==op1 */
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int add_string_to_string(zval *result, const zval *op1, const zval *op2) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2007-11-20 21:26:36 +08:00
|
|
|
int length = Z_STRLEN_P(op1) + Z_STRLEN_P(op2);
|
2010-04-20 19:05:54 +08:00
|
|
|
char *buf;
|
2004-07-19 15:19:50 +08:00
|
|
|
|
2010-04-20 19:05:54 +08:00
|
|
|
if (IS_INTERNED(Z_STRVAL_P(op1))) {
|
|
|
|
buf = (char *) emalloc(length+1);
|
|
|
|
memcpy(buf, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
|
|
|
|
} else {
|
|
|
|
buf = (char *) erealloc(Z_STRVAL_P(op1), length+1);
|
|
|
|
}
|
|
|
|
memcpy(buf + Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2));
|
|
|
|
buf[length] = 0;
|
|
|
|
ZVAL_STRINGL(result, buf, length, 0);
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int concat_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
zval op1_copy, op2_copy;
|
2006-12-11 23:16:07 +08:00
|
|
|
int use_copy1 = 0, use_copy2 = 0;
|
1999-06-11 23:37:43 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_TYPE_P(op1) != IS_STRING) {
|
2006-12-11 23:16:07 +08:00
|
|
|
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
|
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_TYPE_P(op2) != IS_STRING) {
|
2006-12-11 23:16:07 +08:00
|
|
|
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
|
1999-06-11 23:37:43 +08:00
|
|
|
if (use_copy1) {
|
2004-03-14 21:14:48 +08:00
|
|
|
/* We have created a converted copy of op1. Therefore, op1 won't become the result so
|
|
|
|
* we have to free it.
|
|
|
|
*/
|
|
|
|
if (result == op1) {
|
|
|
|
zval_dtor(op1);
|
|
|
|
}
|
1999-06-11 23:37:43 +08:00
|
|
|
op1 = &op1_copy;
|
|
|
|
}
|
|
|
|
if (use_copy2) {
|
|
|
|
op2 = &op2_copy;
|
|
|
|
}
|
2010-04-20 19:05:54 +08:00
|
|
|
if (result==op1 && !IS_INTERNED(Z_STRVAL_P(op1))) { /* special case, perform operations on result */
|
2007-11-20 21:26:36 +08:00
|
|
|
uint res_len = Z_STRLEN_P(op1) + Z_STRLEN_P(op2);
|
2004-07-19 15:19:50 +08:00
|
|
|
|
2009-11-23 12:12:36 +08:00
|
|
|
if (Z_STRLEN_P(result) < 0 || (int) (Z_STRLEN_P(op1) + Z_STRLEN_P(op2)) < 0) {
|
2009-11-19 22:04:34 +08:00
|
|
|
efree(Z_STRVAL_P(result));
|
|
|
|
ZVAL_EMPTY_STRING(result);
|
|
|
|
zend_error(E_ERROR, "String size overflow");
|
|
|
|
}
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_STRVAL_P(result) = erealloc(Z_STRVAL_P(result), res_len+1);
|
|
|
|
|
|
|
|
memcpy(Z_STRVAL_P(result)+Z_STRLEN_P(result), Z_STRVAL_P(op2), Z_STRLEN_P(op2));
|
|
|
|
Z_STRVAL_P(result)[res_len]=0;
|
|
|
|
Z_STRLEN_P(result) = res_len;
|
1999-04-08 02:10:10 +08:00
|
|
|
} else {
|
2010-04-20 19:05:54 +08:00
|
|
|
int length = Z_STRLEN_P(op1) + Z_STRLEN_P(op2);
|
|
|
|
char *buf = (char *) emalloc(length + 1);
|
|
|
|
|
|
|
|
memcpy(buf, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
|
|
|
|
memcpy(buf + Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2));
|
|
|
|
buf[length] = 0;
|
|
|
|
ZVAL_STRINGL(result, buf, length, 0);
|
2000-03-23 02:43:25 +08:00
|
|
|
}
|
|
|
|
if (use_copy1) {
|
|
|
|
zval_dtor(op1);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
1999-06-11 23:37:43 +08:00
|
|
|
if (use_copy2) {
|
1999-04-08 02:10:10 +08:00
|
|
|
zval_dtor(op2);
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2011-08-30 04:24:09 +08:00
|
|
|
ZEND_API int string_compare_function_ex(zval *result, zval *op1, zval *op2, zend_bool case_insensitive TSRMLS_DC) /* {{{ */
|
2000-05-18 02:55:22 +08:00
|
|
|
{
|
|
|
|
zval op1_copy, op2_copy;
|
2006-12-27 00:44:20 +08:00
|
|
|
int use_copy1 = 0, use_copy2 = 0;
|
2000-05-18 02:55:22 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_TYPE_P(op1) != IS_STRING) {
|
2006-12-27 00:44:20 +08:00
|
|
|
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
|
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_TYPE_P(op2) != IS_STRING) {
|
2006-12-27 00:44:20 +08:00
|
|
|
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
|
|
|
|
}
|
2000-05-18 02:55:22 +08:00
|
|
|
|
|
|
|
if (use_copy1) {
|
|
|
|
op1 = &op1_copy;
|
|
|
|
}
|
|
|
|
if (use_copy2) {
|
|
|
|
op2 = &op2_copy;
|
|
|
|
}
|
|
|
|
|
2011-08-30 04:24:09 +08:00
|
|
|
if (case_insensitive) {
|
|
|
|
ZVAL_LONG(result, zend_binary_zval_strcasecmp(op1, op2));
|
|
|
|
} else {
|
|
|
|
ZVAL_LONG(result, zend_binary_zval_strcmp(op1, op2));
|
|
|
|
}
|
2000-05-18 02:55:22 +08:00
|
|
|
|
|
|
|
if (use_copy1) {
|
|
|
|
zval_dtor(op1);
|
|
|
|
}
|
|
|
|
if (use_copy2) {
|
|
|
|
zval_dtor(op2);
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 15:52:49 +08:00
|
|
|
/* }}} */
|
2000-05-18 02:55:22 +08:00
|
|
|
|
2011-08-30 04:24:09 +08:00
|
|
|
ZEND_API int string_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
2011-08-30 09:33:42 +08:00
|
|
|
return string_compare_function_ex(result, op1, op2, 0 TSRMLS_CC);
|
2011-08-30 04:24:09 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
ZEND_API int string_case_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
2011-08-30 09:33:42 +08:00
|
|
|
return string_compare_function_ex(result, op1, op2, 1 TSRMLS_CC);
|
2011-08-30 04:24:09 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2004-09-11 22:22:35 +08:00
|
|
|
#if HAVE_STRCOLL
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int string_locale_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
2004-09-11 22:22:35 +08:00
|
|
|
{
|
|
|
|
zval op1_copy, op2_copy;
|
2006-12-27 00:44:20 +08:00
|
|
|
int use_copy1 = 0, use_copy2 = 0;
|
2004-09-11 22:22:35 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_TYPE_P(op1) != IS_STRING) {
|
2006-12-27 00:44:20 +08:00
|
|
|
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
|
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_TYPE_P(op2) != IS_STRING) {
|
2006-12-27 00:44:20 +08:00
|
|
|
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
|
|
|
|
}
|
2004-09-11 22:22:35 +08:00
|
|
|
|
|
|
|
if (use_copy1) {
|
|
|
|
op1 = &op1_copy;
|
|
|
|
}
|
|
|
|
if (use_copy2) {
|
|
|
|
op2 = &op2_copy;
|
|
|
|
}
|
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
ZVAL_LONG(result, strcoll(Z_STRVAL_P(op1), Z_STRVAL_P(op2)));
|
2004-09-11 22:22:35 +08:00
|
|
|
|
|
|
|
if (use_copy1) {
|
|
|
|
zval_dtor(op1);
|
|
|
|
}
|
|
|
|
if (use_copy2) {
|
|
|
|
zval_dtor(op2);
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 15:52:49 +08:00
|
|
|
/* }}} */
|
2004-09-11 22:22:35 +08:00
|
|
|
#endif
|
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int numeric_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
2000-05-18 02:55:22 +08:00
|
|
|
{
|
|
|
|
zval op1_copy, op2_copy;
|
|
|
|
|
|
|
|
op1_copy = *op1;
|
|
|
|
zval_copy_ctor(&op1_copy);
|
|
|
|
|
|
|
|
op2_copy = *op2;
|
|
|
|
zval_copy_ctor(&op2_copy);
|
|
|
|
|
|
|
|
convert_to_double(&op1_copy);
|
|
|
|
convert_to_double(&op2_copy);
|
|
|
|
|
2006-07-10 00:58:05 +08:00
|
|
|
ZVAL_LONG(result, ZEND_NORMALIZE_BOOL(Z_DVAL(op1_copy)-Z_DVAL(op2_copy)));
|
2000-05-18 02:55:22 +08:00
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2000-05-18 02:55:22 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
static inline void zend_free_obj_get_result(zval *op TSRMLS_DC) /* {{{ */
|
2004-03-14 20:44:28 +08:00
|
|
|
{
|
2007-10-29 22:36:55 +08:00
|
|
|
if (Z_REFCOUNT_P(op) == 0) {
|
2008-01-22 17:27:48 +08:00
|
|
|
GC_REMOVE_ZVAL_FROM_BUFFER(op);
|
2007-10-29 22:36:55 +08:00
|
|
|
zval_dtor(op);
|
|
|
|
FREE_ZVAL(op);
|
|
|
|
} else {
|
|
|
|
zval_ptr_dtor(&op);
|
2004-03-14 20:44:28 +08:00
|
|
|
}
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2004-03-14 20:44:28 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2009-05-11 15:52:49 +08:00
|
|
|
int ret;
|
2007-11-20 21:26:36 +08:00
|
|
|
int converted = 0;
|
1999-04-08 02:10:10 +08:00
|
|
|
zval op1_copy, op2_copy;
|
2008-01-22 03:10:25 +08:00
|
|
|
zval *op_free;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
switch (TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2))) {
|
|
|
|
case TYPE_PAIR(IS_LONG, IS_LONG):
|
|
|
|
ZVAL_LONG(result, Z_LVAL_P(op1)>Z_LVAL_P(op2)?1:(Z_LVAL_P(op1)<Z_LVAL_P(op2)?-1:0));
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
case TYPE_PAIR(IS_DOUBLE, IS_LONG):
|
2008-08-07 16:36:24 +08:00
|
|
|
Z_DVAL_P(result) = Z_DVAL_P(op1) - (double)Z_LVAL_P(op2);
|
|
|
|
ZVAL_LONG(result, ZEND_NORMALIZE_BOOL(Z_DVAL_P(result)));
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
case TYPE_PAIR(IS_LONG, IS_DOUBLE):
|
2008-08-07 16:36:24 +08:00
|
|
|
Z_DVAL_P(result) = (double)Z_LVAL_P(op1) - Z_DVAL_P(op2);
|
|
|
|
ZVAL_LONG(result, ZEND_NORMALIZE_BOOL(Z_DVAL_P(result)));
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2005-08-05 17:02:14 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
case TYPE_PAIR(IS_DOUBLE, IS_DOUBLE):
|
2010-08-22 16:01:34 +08:00
|
|
|
if (Z_DVAL_P(op1) == Z_DVAL_P(op2)) {
|
|
|
|
ZVAL_LONG(result, 0);
|
|
|
|
} else {
|
|
|
|
Z_DVAL_P(result) = Z_DVAL_P(op1) - Z_DVAL_P(op2);
|
|
|
|
ZVAL_LONG(result, ZEND_NORMALIZE_BOOL(Z_DVAL_P(result)));
|
|
|
|
}
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
1999-12-31 21:56:59 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
case TYPE_PAIR(IS_ARRAY, IS_ARRAY):
|
|
|
|
zend_compare_arrays(result, op1, op2 TSRMLS_CC);
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2004-05-10 22:56:21 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
case TYPE_PAIR(IS_NULL, IS_NULL):
|
|
|
|
ZVAL_LONG(result, 0);
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
case TYPE_PAIR(IS_NULL, IS_BOOL):
|
|
|
|
ZVAL_LONG(result, Z_LVAL_P(op2) ? -1 : 0);
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2000-06-03 18:34:19 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
case TYPE_PAIR(IS_BOOL, IS_NULL):
|
|
|
|
ZVAL_LONG(result, Z_LVAL_P(op1) ? 1 : 0);
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
case TYPE_PAIR(IS_BOOL, IS_BOOL):
|
|
|
|
ZVAL_LONG(result, ZEND_NORMALIZE_BOOL(Z_LVAL_P(op1) - Z_LVAL_P(op2)));
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
case TYPE_PAIR(IS_STRING, IS_STRING):
|
|
|
|
zendi_smart_strcmp(result, op1, op2);
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
case TYPE_PAIR(IS_NULL, IS_STRING):
|
|
|
|
ZVAL_LONG(result, zend_binary_strcmp("", 0, Z_STRVAL_P(op2), Z_STRLEN_P(op2)));
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
case TYPE_PAIR(IS_STRING, IS_NULL):
|
|
|
|
ZVAL_LONG(result, zend_binary_strcmp(Z_STRVAL_P(op1), Z_STRLEN_P(op1), "", 0));
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
case TYPE_PAIR(IS_OBJECT, IS_NULL):
|
|
|
|
ZVAL_LONG(result, 1);
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
case TYPE_PAIR(IS_NULL, IS_OBJECT):
|
|
|
|
ZVAL_LONG(result, -1);
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2000-06-03 18:34:19 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
case TYPE_PAIR(IS_OBJECT, IS_OBJECT):
|
|
|
|
/* If both are objects sharing the same comparision handler then use is */
|
|
|
|
if (Z_OBJ_HANDLER_P(op1,compare_objects) == Z_OBJ_HANDLER_P(op2,compare_objects)) {
|
|
|
|
if (Z_OBJ_HANDLE_P(op1) == Z_OBJ_HANDLE_P(op2)) {
|
2013-06-11 05:20:18 +08:00
|
|
|
/* object handles are identical, apparently this is the same object */
|
2007-11-20 21:26:36 +08:00
|
|
|
ZVAL_LONG(result, 0);
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
}
|
|
|
|
ZVAL_LONG(result, Z_OBJ_HT_P(op1)->compare_objects(op1, op2 TSRMLS_CC));
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
}
|
|
|
|
/* break missing intentionally */
|
|
|
|
|
|
|
|
default:
|
2008-01-22 03:10:25 +08:00
|
|
|
if (Z_TYPE_P(op1) == IS_OBJECT) {
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_OBJ_HT_P(op1)->get) {
|
2008-01-22 03:10:25 +08:00
|
|
|
op_free = Z_OBJ_HT_P(op1)->get(op1 TSRMLS_CC);
|
|
|
|
ret = compare_function(result, op_free, op2 TSRMLS_CC);
|
2008-08-16 03:47:33 +08:00
|
|
|
zend_free_obj_get_result(op_free TSRMLS_CC);
|
2008-01-22 03:10:25 +08:00
|
|
|
return ret;
|
2009-05-11 15:52:49 +08:00
|
|
|
} else if (Z_TYPE_P(op2) != IS_OBJECT && Z_OBJ_HT_P(op1)->cast_object) {
|
2008-01-22 03:10:25 +08:00
|
|
|
ALLOC_INIT_ZVAL(op_free);
|
|
|
|
if (Z_OBJ_HT_P(op1)->cast_object(op1, op_free, Z_TYPE_P(op2) TSRMLS_CC) == FAILURE) {
|
2007-11-20 21:26:36 +08:00
|
|
|
ZVAL_LONG(result, 1);
|
2008-08-16 03:47:33 +08:00
|
|
|
zend_free_obj_get_result(op_free TSRMLS_CC);
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
}
|
2008-01-22 03:10:25 +08:00
|
|
|
ret = compare_function(result, op_free, op2 TSRMLS_CC);
|
2008-08-16 03:47:33 +08:00
|
|
|
zend_free_obj_get_result(op_free TSRMLS_CC);
|
2008-01-22 03:10:25 +08:00
|
|
|
return ret;
|
2007-11-20 21:26:36 +08:00
|
|
|
}
|
|
|
|
}
|
2008-01-22 03:10:25 +08:00
|
|
|
if (Z_TYPE_P(op2) == IS_OBJECT) {
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_OBJ_HT_P(op2)->get) {
|
2008-01-22 03:10:25 +08:00
|
|
|
op_free = Z_OBJ_HT_P(op2)->get(op2 TSRMLS_CC);
|
|
|
|
ret = compare_function(result, op1, op_free TSRMLS_CC);
|
2008-08-16 03:47:33 +08:00
|
|
|
zend_free_obj_get_result(op_free TSRMLS_CC);
|
2008-01-22 03:10:25 +08:00
|
|
|
return ret;
|
2009-05-11 15:52:49 +08:00
|
|
|
} else if (Z_TYPE_P(op1) != IS_OBJECT && Z_OBJ_HT_P(op2)->cast_object) {
|
2008-01-22 03:10:25 +08:00
|
|
|
ALLOC_INIT_ZVAL(op_free);
|
|
|
|
if (Z_OBJ_HT_P(op2)->cast_object(op2, op_free, Z_TYPE_P(op1) TSRMLS_CC) == FAILURE) {
|
2007-11-20 21:26:36 +08:00
|
|
|
ZVAL_LONG(result, -1);
|
2008-08-16 03:47:33 +08:00
|
|
|
zend_free_obj_get_result(op_free TSRMLS_CC);
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
}
|
2008-01-22 03:10:25 +08:00
|
|
|
ret = compare_function(result, op1, op_free TSRMLS_CC);
|
2008-08-16 03:47:33 +08:00
|
|
|
zend_free_obj_get_result(op_free TSRMLS_CC);
|
2008-01-22 03:10:25 +08:00
|
|
|
return ret;
|
2012-08-31 11:22:43 +08:00
|
|
|
} else if (Z_TYPE_P(op1) == IS_OBJECT) {
|
|
|
|
ZVAL_LONG(result, 1);
|
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!converted) {
|
|
|
|
if (Z_TYPE_P(op1) == IS_NULL) {
|
|
|
|
zendi_convert_to_boolean(op2, op2_copy, result);
|
|
|
|
ZVAL_LONG(result, Z_LVAL_P(op2) ? -1 : 0);
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
} else if (Z_TYPE_P(op2) == IS_NULL) {
|
|
|
|
zendi_convert_to_boolean(op1, op1_copy, result);
|
|
|
|
ZVAL_LONG(result, Z_LVAL_P(op1) ? 1 : 0);
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
} else if (Z_TYPE_P(op1) == IS_BOOL) {
|
|
|
|
zendi_convert_to_boolean(op2, op2_copy, result);
|
|
|
|
ZVAL_LONG(result, ZEND_NORMALIZE_BOOL(Z_LVAL_P(op1) - Z_LVAL_P(op2)));
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
} else if (Z_TYPE_P(op2) == IS_BOOL) {
|
|
|
|
zendi_convert_to_boolean(op1, op1_copy, result);
|
|
|
|
ZVAL_LONG(result, ZEND_NORMALIZE_BOOL(Z_LVAL_P(op1) - Z_LVAL_P(op2)));
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
} else {
|
|
|
|
zendi_convert_scalar_to_number(op1, op1_copy, result);
|
|
|
|
zendi_convert_scalar_to_number(op2, op2_copy, result);
|
|
|
|
converted = 1;
|
|
|
|
}
|
|
|
|
} else if (Z_TYPE_P(op1)==IS_ARRAY) {
|
|
|
|
ZVAL_LONG(result, 1);
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
} else if (Z_TYPE_P(op2)==IS_ARRAY) {
|
|
|
|
ZVAL_LONG(result, -1);
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
} else if (Z_TYPE_P(op1)==IS_OBJECT) {
|
|
|
|
ZVAL_LONG(result, 1);
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
} else if (Z_TYPE_P(op2)==IS_OBJECT) {
|
|
|
|
ZVAL_LONG(result, -1);
|
2008-01-22 03:10:25 +08:00
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
} else {
|
|
|
|
ZVAL_LONG(result, 0);
|
2008-01-22 03:10:25 +08:00
|
|
|
return FAILURE;
|
2007-11-20 21:26:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
static int hash_zval_identical_function(const zval **z1, const zval **z2) /* {{{ */
|
2000-06-03 18:34:19 +08:00
|
|
|
{
|
|
|
|
zval result;
|
2001-07-30 12:54:16 +08:00
|
|
|
TSRMLS_FETCH();
|
2000-06-03 18:34:19 +08:00
|
|
|
|
2000-06-05 05:59:49 +08:00
|
|
|
/* is_identical_function() returns 1 in case of identity and 0 in case
|
|
|
|
* of a difference;
|
|
|
|
* whereas this comparison function is expected to return 0 on identity,
|
|
|
|
* and non zero otherwise.
|
|
|
|
*/
|
2001-07-30 12:54:16 +08:00
|
|
|
if (is_identical_function(&result, (zval *) *z1, (zval *) *z2 TSRMLS_CC)==FAILURE) {
|
2000-06-05 05:59:49 +08:00
|
|
|
return 1;
|
2000-06-03 18:34:19 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
return !Z_LVAL(result);
|
2000-06-03 18:34:19 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2000-06-03 18:34:19 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int is_identical_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
1999-10-19 21:33:17 +08:00
|
|
|
{
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_TYPE_P(result) = IS_BOOL;
|
|
|
|
if (Z_TYPE_P(op1) != Z_TYPE_P(op2)) {
|
|
|
|
Z_LVAL_P(result) = 0;
|
1999-10-19 21:33:17 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
switch (Z_TYPE_P(op1)) {
|
2000-01-04 21:22:58 +08:00
|
|
|
case IS_NULL:
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(result) = 1;
|
1999-12-31 21:56:59 +08:00
|
|
|
break;
|
1999-10-19 22:11:39 +08:00
|
|
|
case IS_BOOL:
|
|
|
|
case IS_LONG:
|
|
|
|
case IS_RESOURCE:
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(result) = (Z_LVAL_P(op1) == Z_LVAL_P(op2));
|
1999-10-19 22:11:39 +08:00
|
|
|
break;
|
|
|
|
case IS_DOUBLE:
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(result) = (Z_DVAL_P(op1) == Z_DVAL_P(op2));
|
1999-10-19 22:11:39 +08:00
|
|
|
break;
|
|
|
|
case IS_STRING:
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(result) = ((Z_STRLEN_P(op1) == Z_STRLEN_P(op2))
|
|
|
|
&& (!memcmp(Z_STRVAL_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op1))));
|
1999-10-19 22:11:39 +08:00
|
|
|
break;
|
|
|
|
case IS_ARRAY:
|
2012-06-04 05:16:57 +08:00
|
|
|
Z_LVAL_P(result) = (Z_ARRVAL_P(op1) == Z_ARRVAL_P(op2) ||
|
|
|
|
zend_hash_compare(Z_ARRVAL_P(op1), Z_ARRVAL_P(op2), (compare_func_t) hash_zval_identical_function, 1 TSRMLS_CC)==0);
|
2000-06-03 18:34:19 +08:00
|
|
|
break;
|
1999-10-19 22:11:39 +08:00
|
|
|
case IS_OBJECT:
|
2004-05-10 22:56:21 +08:00
|
|
|
if (Z_OBJ_HT_P(op1) == Z_OBJ_HT_P(op2)) {
|
2008-03-18 22:10:45 +08:00
|
|
|
Z_LVAL_P(result) = (Z_OBJ_HANDLE_P(op1) == Z_OBJ_HANDLE_P(op2));
|
2000-06-03 18:34:19 +08:00
|
|
|
} else {
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(result) = 0;
|
2000-06-03 18:34:19 +08:00
|
|
|
}
|
1999-10-19 22:11:39 +08:00
|
|
|
break;
|
2000-06-05 05:59:49 +08:00
|
|
|
default:
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(result) = 0;
|
2000-06-05 05:59:49 +08:00
|
|
|
return FAILURE;
|
1999-10-19 21:33:17 +08:00
|
|
|
}
|
2000-06-05 05:59:49 +08:00
|
|
|
return SUCCESS;
|
1999-10-19 21:33:17 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-10-19 21:33:17 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int is_not_identical_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
2000-03-30 06:05:19 +08:00
|
|
|
{
|
2009-05-11 15:52:49 +08:00
|
|
|
if (is_identical_function(result, op1, op2 TSRMLS_CC) == FAILURE) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
Z_LVAL_P(result) = !Z_LVAL_P(result);
|
|
|
|
return SUCCESS;
|
2000-03-30 06:05:19 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2000-03-30 06:05:19 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int is_equal_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2001-07-30 12:54:16 +08:00
|
|
|
if (compare_function(result, op1, op2 TSRMLS_CC) == FAILURE) {
|
1999-04-08 02:10:10 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
ZVAL_BOOL(result, (Z_LVAL_P(result) == 0));
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int is_not_equal_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2001-07-30 12:54:16 +08:00
|
|
|
if (compare_function(result, op1, op2 TSRMLS_CC) == FAILURE) {
|
1999-04-08 02:10:10 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
ZVAL_BOOL(result, (Z_LVAL_P(result) != 0));
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int is_smaller_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2001-07-30 12:54:16 +08:00
|
|
|
if (compare_function(result, op1, op2 TSRMLS_CC) == FAILURE) {
|
1999-04-08 02:10:10 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
ZVAL_BOOL(result, (Z_LVAL_P(result) < 0));
|
|
|
|
return SUCCESS;
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int is_smaller_or_equal_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2001-07-30 12:54:16 +08:00
|
|
|
if (compare_function(result, op1, op2 TSRMLS_CC) == FAILURE) {
|
1999-04-08 02:10:10 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
ZVAL_BOOL(result, (Z_LVAL_P(result) <= 0));
|
|
|
|
return SUCCESS;
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API zend_bool instanceof_function_ex(const zend_class_entry *instance_ce, const zend_class_entry *ce, zend_bool interfaces_only TSRMLS_DC) /* {{{ */
|
2002-07-30 12:07:15 +08:00
|
|
|
{
|
2003-03-05 19:14:44 +08:00
|
|
|
zend_uint i;
|
|
|
|
|
2003-05-30 03:00:40 +08:00
|
|
|
for (i=0; i<instance_ce->num_interfaces; i++) {
|
|
|
|
if (instanceof_function(instance_ce->interfaces[i], ce TSRMLS_CC)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2003-11-25 04:57:54 +08:00
|
|
|
if (!interfaces_only) {
|
|
|
|
while (instance_ce) {
|
|
|
|
if (instance_ce == ce) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
instance_ce = instance_ce->parent;
|
2003-03-05 19:14:44 +08:00
|
|
|
}
|
2002-07-30 12:07:15 +08:00
|
|
|
}
|
2003-03-05 19:14:44 +08:00
|
|
|
|
|
|
|
return 0;
|
2002-07-30 12:07:15 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2002-07-30 12:07:15 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API zend_bool instanceof_function(const zend_class_entry *instance_ce, const zend_class_entry *ce TSRMLS_DC) /* {{{ */
|
2003-11-25 04:57:54 +08:00
|
|
|
{
|
|
|
|
return instanceof_function_ex(instance_ce, ce, 0 TSRMLS_CC);
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2003-11-25 04:57:54 +08:00
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
#define LOWER_CASE 1
|
|
|
|
#define UPPER_CASE 2
|
|
|
|
#define NUMERIC 3
|
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
static void increment_string(zval *str) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2009-05-11 15:52:49 +08:00
|
|
|
int carry=0;
|
|
|
|
int pos=Z_STRLEN_P(str)-1;
|
|
|
|
char *s=Z_STRVAL_P(str);
|
|
|
|
char *t;
|
|
|
|
int last=0; /* Shut up the compiler warning */
|
|
|
|
int ch;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
if (Z_STRLEN_P(str) == 0) {
|
|
|
|
STR_FREE(Z_STRVAL_P(str));
|
|
|
|
Z_STRVAL_P(str) = estrndup("1", sizeof("1")-1);
|
|
|
|
Z_STRLEN_P(str) = 1;
|
2000-10-14 00:24:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-20 19:05:54 +08:00
|
|
|
if (IS_INTERNED(s)) {
|
|
|
|
s = (char*) emalloc(Z_STRLEN_P(str) + 1);
|
|
|
|
memcpy(s, Z_STRVAL_P(str), Z_STRLEN_P(str) + 1);
|
|
|
|
Z_STRVAL_P(str) = s;
|
|
|
|
}
|
|
|
|
|
2001-04-28 02:53:25 +08:00
|
|
|
while (pos >= 0) {
|
2009-05-11 15:52:49 +08:00
|
|
|
ch = s[pos];
|
|
|
|
if (ch >= 'a' && ch <= 'z') {
|
|
|
|
if (ch == 'z') {
|
|
|
|
s[pos] = 'a';
|
|
|
|
carry=1;
|
|
|
|
} else {
|
|
|
|
s[pos]++;
|
|
|
|
carry=0;
|
|
|
|
}
|
|
|
|
last=LOWER_CASE;
|
|
|
|
} else if (ch >= 'A' && ch <= 'Z') {
|
|
|
|
if (ch == 'Z') {
|
|
|
|
s[pos] = 'A';
|
|
|
|
carry=1;
|
|
|
|
} else {
|
|
|
|
s[pos]++;
|
|
|
|
carry=0;
|
|
|
|
}
|
|
|
|
last=UPPER_CASE;
|
|
|
|
} else if (ch >= '0' && ch <= '9') {
|
|
|
|
if (ch == '9') {
|
|
|
|
s[pos] = '0';
|
|
|
|
carry=1;
|
|
|
|
} else {
|
|
|
|
s[pos]++;
|
|
|
|
carry=0;
|
|
|
|
}
|
|
|
|
last = NUMERIC;
|
|
|
|
} else {
|
|
|
|
carry=0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (carry == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pos--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (carry) {
|
|
|
|
t = (char *) emalloc(Z_STRLEN_P(str)+1+1);
|
|
|
|
memcpy(t+1, Z_STRVAL_P(str), Z_STRLEN_P(str));
|
|
|
|
Z_STRLEN_P(str)++;
|
|
|
|
t[Z_STRLEN_P(str)] = '\0';
|
|
|
|
switch (last) {
|
|
|
|
case NUMERIC:
|
|
|
|
t[0] = '1';
|
|
|
|
break;
|
|
|
|
case UPPER_CASE:
|
|
|
|
t[0] = 'A';
|
|
|
|
break;
|
|
|
|
case LOWER_CASE:
|
|
|
|
t[0] = 'a';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
STR_FREE(Z_STRVAL_P(str));
|
|
|
|
Z_STRVAL_P(str) = t;
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int increment_function(zval *op1) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2007-11-20 21:26:36 +08:00
|
|
|
switch (Z_TYPE_P(op1)) {
|
1999-04-08 02:10:10 +08:00
|
|
|
case IS_LONG:
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_LVAL_P(op1) == LONG_MAX) {
|
2001-09-05 17:29:28 +08:00
|
|
|
/* switch to double */
|
2007-11-20 21:26:36 +08:00
|
|
|
double d = (double)Z_LVAL_P(op1);
|
2001-09-05 17:29:28 +08:00
|
|
|
ZVAL_DOUBLE(op1, d+1);
|
|
|
|
} else {
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(op1)++;
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
case IS_DOUBLE:
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_DVAL_P(op1) = Z_DVAL_P(op1) + 1;
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
2000-01-04 21:22:58 +08:00
|
|
|
case IS_NULL:
|
2007-11-20 21:26:36 +08:00
|
|
|
ZVAL_LONG(op1, 1);
|
1999-12-31 21:56:59 +08:00
|
|
|
break;
|
2001-05-10 20:58:31 +08:00
|
|
|
case IS_STRING: {
|
|
|
|
long lval;
|
|
|
|
double dval;
|
|
|
|
|
2009-03-18 19:25:37 +08:00
|
|
|
switch (is_numeric_string(Z_STRVAL_P(op1), Z_STRLEN_P(op1), &lval, &dval, 0)) {
|
2001-05-10 20:58:31 +08:00
|
|
|
case IS_LONG:
|
2010-04-20 19:05:54 +08:00
|
|
|
str_efree(Z_STRVAL_P(op1));
|
2002-09-15 15:45:26 +08:00
|
|
|
if (lval == LONG_MAX) {
|
2001-09-05 17:29:28 +08:00
|
|
|
/* switch to double */
|
|
|
|
double d = (double)lval;
|
|
|
|
ZVAL_DOUBLE(op1, d+1);
|
|
|
|
} else {
|
2007-11-20 21:26:36 +08:00
|
|
|
ZVAL_LONG(op1, lval+1);
|
2001-09-05 17:29:28 +08:00
|
|
|
}
|
2001-05-10 20:58:31 +08:00
|
|
|
break;
|
|
|
|
case IS_DOUBLE:
|
2010-04-20 19:05:54 +08:00
|
|
|
str_efree(Z_STRVAL_P(op1));
|
2007-11-20 21:26:36 +08:00
|
|
|
ZVAL_DOUBLE(op1, dval+1);
|
2001-05-10 20:58:31 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Perl style string increment */
|
|
|
|
increment_string(op1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int decrement_function(zval *op1) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
long lval;
|
2002-06-29 15:35:41 +08:00
|
|
|
double dval;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
switch (Z_TYPE_P(op1)) {
|
1999-04-08 02:10:10 +08:00
|
|
|
case IS_LONG:
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_LVAL_P(op1) == LONG_MIN) {
|
|
|
|
double d = (double)Z_LVAL_P(op1);
|
2001-09-05 17:29:28 +08:00
|
|
|
ZVAL_DOUBLE(op1, d-1);
|
|
|
|
} else {
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(op1)--;
|
2001-09-05 17:29:28 +08:00
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
case IS_DOUBLE:
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_DVAL_P(op1) = Z_DVAL_P(op1) - 1;
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
case IS_STRING: /* Like perl we only support string increment */
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_STRLEN_P(op1) == 0) { /* consider as 0 */
|
|
|
|
STR_FREE(Z_STRVAL_P(op1));
|
|
|
|
ZVAL_LONG(op1, -1);
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
2002-06-29 15:35:41 +08:00
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
switch (is_numeric_string(Z_STRVAL_P(op1), Z_STRLEN_P(op1), &lval, &dval, 0)) {
|
2002-06-29 15:35:41 +08:00
|
|
|
case IS_LONG:
|
2007-11-20 21:26:36 +08:00
|
|
|
STR_FREE(Z_STRVAL_P(op1));
|
2002-09-15 15:45:26 +08:00
|
|
|
if (lval == LONG_MIN) {
|
2002-06-29 15:35:41 +08:00
|
|
|
double d = (double)lval;
|
|
|
|
ZVAL_DOUBLE(op1, d-1);
|
|
|
|
} else {
|
2007-11-20 21:26:36 +08:00
|
|
|
ZVAL_LONG(op1, lval-1);
|
2002-06-29 15:35:41 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IS_DOUBLE:
|
2007-11-20 21:26:36 +08:00
|
|
|
STR_FREE(Z_STRVAL_P(op1));
|
|
|
|
ZVAL_DOUBLE(op1, dval - 1);
|
2002-06-29 15:35:41 +08:00
|
|
|
break;
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int zval_is_true(zval *op) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
convert_to_boolean(op);
|
2007-11-20 21:26:36 +08:00
|
|
|
return (Z_LVAL_P(op) ? 1 : 0);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2009-05-11 15:52:49 +08:00
|
|
|
|
2006-12-05 02:37:15 +08:00
|
|
|
#ifdef ZEND_USE_TOLOWER_L
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API void zend_update_current_locale(void) /* {{{ */
|
2006-12-05 02:37:15 +08:00
|
|
|
{
|
|
|
|
current_locale = _get_current_locale();
|
|
|
|
}
|
2009-05-11 15:52:49 +08:00
|
|
|
/* }}} */
|
2006-12-05 02:37:15 +08:00
|
|
|
#endif
|
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API char *zend_str_tolower_copy(char *dest, const char *source, unsigned int length) /* {{{ */
|
2003-05-21 02:28:14 +08:00
|
|
|
{
|
2003-05-22 05:59:40 +08:00
|
|
|
register unsigned char *str = (unsigned char*)source;
|
2003-08-18 03:14:30 +08:00
|
|
|
register unsigned char *result = (unsigned char*)dest;
|
2003-05-22 05:59:40 +08:00
|
|
|
register unsigned char *end = str + length;
|
2003-05-21 02:28:14 +08:00
|
|
|
|
2003-05-22 05:59:40 +08:00
|
|
|
while (str < end) {
|
2012-07-15 12:06:40 +08:00
|
|
|
*result++ = zend_tolower_ascii(*str++);
|
2003-05-21 06:31:15 +08:00
|
|
|
}
|
2005-12-13 03:10:12 +08:00
|
|
|
*result = '\0';
|
2003-05-21 06:31:15 +08:00
|
|
|
|
2003-05-22 05:59:40 +08:00
|
|
|
return dest;
|
2003-05-21 02:28:14 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API char *zend_str_tolower_dup(const char *source, unsigned int length) /* {{{ */
|
2009-05-11 06:39:33 +08:00
|
|
|
{
|
|
|
|
return zend_str_tolower_copy((char *)emalloc(length+1), source, length);
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2009-05-11 06:39:33 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API void zend_str_tolower(char *str, unsigned int length) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2003-05-22 05:59:40 +08:00
|
|
|
register unsigned char *p = (unsigned char*)str;
|
|
|
|
register unsigned char *end = p + length;
|
2003-05-21 04:39:58 +08:00
|
|
|
|
|
|
|
while (p < end) {
|
2012-07-15 12:06:40 +08:00
|
|
|
*p = zend_tolower_ascii(*p);
|
2003-05-21 04:39:58 +08:00
|
|
|
p++;
|
|
|
|
}
|
2002-09-27 02:56:11 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int zend_binary_strcmp(const char *s1, uint len1, const char *s2, uint len2) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
int retval;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2010-04-20 19:05:54 +08:00
|
|
|
if (s1 == s2) {
|
|
|
|
return 0;
|
|
|
|
}
|
2000-01-25 03:00:30 +08:00
|
|
|
retval = memcmp(s1, s2, MIN(len1, len2));
|
1999-04-08 02:10:10 +08:00
|
|
|
if (!retval) {
|
2000-01-25 03:00:30 +08:00
|
|
|
return (len1 - len2);
|
1999-04-08 02:10:10 +08:00
|
|
|
} else {
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int zend_binary_strncmp(const char *s1, uint len1, const char *s2, uint len2, uint length) /* {{{ */
|
2000-02-09 01:19:43 +08:00
|
|
|
{
|
|
|
|
int retval;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2010-04-20 19:05:54 +08:00
|
|
|
if (s1 == s2) {
|
|
|
|
return 0;
|
|
|
|
}
|
2000-02-09 01:19:43 +08:00
|
|
|
retval = memcmp(s1, s2, MIN(length, MIN(len1, len2)));
|
|
|
|
if (!retval) {
|
2000-02-09 01:59:28 +08:00
|
|
|
return (MIN(length, len1) - MIN(length, len2));
|
2000-02-09 01:19:43 +08:00
|
|
|
} else {
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2000-02-09 01:19:43 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int zend_binary_strcasecmp(const char *s1, uint len1, const char *s2, uint len2) /* {{{ */
|
1999-06-16 06:32:51 +08:00
|
|
|
{
|
2000-05-08 18:05:19 +08:00
|
|
|
int len;
|
2001-08-11 23:44:24 +08:00
|
|
|
int c1, c2;
|
1999-06-16 06:32:51 +08:00
|
|
|
|
2010-04-20 19:05:54 +08:00
|
|
|
if (s1 == s2) {
|
|
|
|
return 0;
|
|
|
|
}
|
1999-06-16 06:32:51 +08:00
|
|
|
|
2012-07-11 09:12:13 +08:00
|
|
|
len = MIN(len1, len2);
|
|
|
|
while (len--) {
|
2012-07-15 12:06:40 +08:00
|
|
|
c1 = zend_tolower_ascii(*(unsigned char *)s1++);
|
|
|
|
c2 = zend_tolower_ascii(*(unsigned char *)s2++);
|
2012-07-11 09:12:13 +08:00
|
|
|
if (c1 != c2) {
|
|
|
|
return c1 - c2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return len1 - len2;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
ZEND_API int zend_binary_strncasecmp(const char *s1, uint len1, const char *s2, uint len2, uint length) /* {{{ */
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
int c1, c2;
|
|
|
|
|
|
|
|
if (s1 == s2) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
len = MIN(length, MIN(len1, len2));
|
|
|
|
while (len--) {
|
2012-07-15 12:06:40 +08:00
|
|
|
c1 = zend_tolower_ascii(*(unsigned char *)s1++);
|
|
|
|
c2 = zend_tolower_ascii(*(unsigned char *)s2++);
|
2012-07-11 09:12:13 +08:00
|
|
|
if (c1 != c2) {
|
|
|
|
return c1 - c2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return MIN(length, len1) - MIN(length, len2);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
ZEND_API int zend_binary_strcasecmp_l(const char *s1, uint len1, const char *s2, uint len2) /* {{{ */
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
int c1, c2;
|
|
|
|
|
|
|
|
if (s1 == s2) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-20 19:05:54 +08:00
|
|
|
len = MIN(len1, len2);
|
2000-05-08 18:05:19 +08:00
|
|
|
while (len--) {
|
2006-12-05 02:37:15 +08:00
|
|
|
c1 = zend_tolower((int)*(unsigned char *)s1++);
|
|
|
|
c2 = zend_tolower((int)*(unsigned char *)s2++);
|
1999-06-16 06:32:51 +08:00
|
|
|
if (c1 != c2) {
|
2000-05-08 18:05:19 +08:00
|
|
|
return c1 - c2;
|
1999-06-16 06:32:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-08 18:05:19 +08:00
|
|
|
return len1 - len2;
|
1999-06-16 06:32:51 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-06-16 06:32:51 +08:00
|
|
|
|
2012-07-11 09:12:13 +08:00
|
|
|
ZEND_API int zend_binary_strncasecmp_l(const char *s1, uint len1, const char *s2, uint len2, uint length) /* {{{ */
|
2000-07-26 19:32:15 +08:00
|
|
|
{
|
|
|
|
int len;
|
2001-08-11 23:44:24 +08:00
|
|
|
int c1, c2;
|
2000-07-26 19:32:15 +08:00
|
|
|
|
2010-04-20 19:05:54 +08:00
|
|
|
if (s1 == s2) {
|
|
|
|
return 0;
|
|
|
|
}
|
2000-07-26 19:32:15 +08:00
|
|
|
len = MIN(length, MIN(len1, len2));
|
|
|
|
while (len--) {
|
2006-12-05 02:37:15 +08:00
|
|
|
c1 = zend_tolower((int)*(unsigned char *)s1++);
|
|
|
|
c2 = zend_tolower((int)*(unsigned char *)s2++);
|
2000-07-26 19:32:15 +08:00
|
|
|
if (c1 != c2) {
|
|
|
|
return c1 - c2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-12 17:47:30 +08:00
|
|
|
return MIN(length, len1) - MIN(length, len2);
|
2000-07-26 19:32:15 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2000-07-26 19:32:15 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int zend_binary_zval_strcmp(zval *s1, zval *s2) /* {{{ */
|
2000-01-25 03:00:30 +08:00
|
|
|
{
|
2007-11-20 21:26:36 +08:00
|
|
|
return zend_binary_strcmp(Z_STRVAL_P(s1), Z_STRLEN_P(s1), Z_STRVAL_P(s2), Z_STRLEN_P(s2));
|
2000-01-25 03:00:30 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
ZEND_API int zend_binary_zval_strncmp(zval *s1, zval *s2, zval *s3) /* {{{ */
|
2000-02-09 01:19:43 +08:00
|
|
|
{
|
2007-11-20 21:26:36 +08:00
|
|
|
return zend_binary_strncmp(Z_STRVAL_P(s1), Z_STRLEN_P(s1), Z_STRVAL_P(s2), Z_STRLEN_P(s2), Z_LVAL_P(s3));
|
2000-02-09 01:19:43 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2000-02-09 01:19:43 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int zend_binary_zval_strcasecmp(zval *s1, zval *s2) /* {{{ */
|
2000-01-25 03:00:30 +08:00
|
|
|
{
|
2012-07-11 09:12:13 +08:00
|
|
|
return zend_binary_strcasecmp_l(Z_STRVAL_P(s1), Z_STRLEN_P(s1), Z_STRVAL_P(s2), Z_STRLEN_P(s2));
|
2000-01-25 03:00:30 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2000-01-25 03:00:30 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int zend_binary_zval_strncasecmp(zval *s1, zval *s2, zval *s3) /* {{{ */
|
2000-07-26 19:32:15 +08:00
|
|
|
{
|
2012-07-11 09:12:13 +08:00
|
|
|
return zend_binary_strncasecmp_l(Z_STRVAL_P(s1), Z_STRLEN_P(s1), Z_STRVAL_P(s2), Z_STRLEN_P(s2), Z_LVAL_P(s3));
|
2000-07-26 19:32:15 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2000-07-26 19:32:15 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2001-08-11 23:44:24 +08:00
|
|
|
int ret1, ret2;
|
2012-05-11 14:58:10 +08:00
|
|
|
int oflow1, oflow2;
|
2013-08-27 15:44:30 +08:00
|
|
|
long lval1 = 0, lval2 = 0;
|
|
|
|
double dval1 = 0.0, dval2 = 0.0;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2012-05-11 14:58:10 +08:00
|
|
|
if ((ret1=is_numeric_string_ex(Z_STRVAL_P(s1), Z_STRLEN_P(s1), &lval1, &dval1, 0, &oflow1)) &&
|
|
|
|
(ret2=is_numeric_string_ex(Z_STRVAL_P(s2), Z_STRLEN_P(s2), &lval2, &dval2, 0, &oflow2))) {
|
2012-05-22 18:36:28 +08:00
|
|
|
#if ULONG_MAX == 0xFFFFFFFF
|
|
|
|
if (oflow1 != 0 && oflow1 == oflow2 && dval1 - dval2 == 0. &&
|
|
|
|
((oflow1 == 1 && dval1 > 9007199254740991. /*0x1FFFFFFFFFFFFF*/)
|
|
|
|
|| (oflow1 == -1 && dval1 < -9007199254740991.))) {
|
|
|
|
#else
|
2012-05-11 14:58:10 +08:00
|
|
|
if (oflow1 != 0 && oflow1 == oflow2 && dval1 - dval2 == 0.) {
|
2012-05-22 18:36:28 +08:00
|
|
|
#endif
|
2012-05-11 14:58:10 +08:00
|
|
|
/* both values are integers overflown to the same side, and the
|
|
|
|
* double comparison may have resulted in crucial accuracy lost */
|
|
|
|
goto string_cmp;
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
if ((ret1==IS_DOUBLE) || (ret2==IS_DOUBLE)) {
|
|
|
|
if (ret1!=IS_DOUBLE) {
|
2012-05-11 14:58:10 +08:00
|
|
|
if (oflow2) {
|
|
|
|
/* 2nd operand is integer > LONG_MAX (oflow2==1) or < LONG_MIN (-1) */
|
|
|
|
ZVAL_LONG(result, -1 * oflow2);
|
|
|
|
return;
|
|
|
|
}
|
2006-12-30 09:57:01 +08:00
|
|
|
dval1 = (double) lval1;
|
1999-04-08 02:10:10 +08:00
|
|
|
} else if (ret2!=IS_DOUBLE) {
|
2012-05-11 14:58:10 +08:00
|
|
|
if (oflow1) {
|
|
|
|
ZVAL_LONG(result, oflow1);
|
2012-07-11 09:12:13 +08:00
|
|
|
return;
|
2012-05-11 14:58:10 +08:00
|
|
|
}
|
2006-12-30 09:57:01 +08:00
|
|
|
dval2 = (double) lval2;
|
|
|
|
} else if (dval1 == dval2 && !zend_finite(dval1)) {
|
|
|
|
/* Both values overflowed and have the same sign,
|
|
|
|
* so a numeric comparison would be inaccurate */
|
|
|
|
goto string_cmp;
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_DVAL_P(result) = dval1 - dval2;
|
|
|
|
ZVAL_LONG(result, ZEND_NORMALIZE_BOOL(Z_DVAL_P(result)));
|
1999-04-08 02:10:10 +08:00
|
|
|
} else { /* they both have to be long's */
|
2007-11-20 21:26:36 +08:00
|
|
|
ZVAL_LONG(result, lval1 > lval2 ? 1 : (lval1 < lval2 ? -1 : 0));
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
} else {
|
2006-12-30 09:57:01 +08:00
|
|
|
string_cmp:
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(result) = zend_binary_zval_strcmp(s1, s2);
|
|
|
|
ZVAL_LONG(result, ZEND_NORMALIZE_BOOL(Z_LVAL_P(result)));
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
static int hash_zval_compare_function(const zval **z1, const zval **z2 TSRMLS_DC) /* {{{ */
|
2000-06-03 18:34:19 +08:00
|
|
|
{
|
|
|
|
zval result;
|
|
|
|
|
2001-07-30 12:54:16 +08:00
|
|
|
if (compare_function(&result, (zval *) *z1, (zval *) *z2 TSRMLS_CC)==FAILURE) {
|
2000-06-05 05:59:49 +08:00
|
|
|
return 1;
|
2000-06-03 18:34:19 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
return Z_LVAL(result);
|
2000-06-03 18:34:19 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2000-06-03 18:34:19 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API int zend_compare_symbol_tables_i(HashTable *ht1, HashTable *ht2 TSRMLS_DC) /* {{{ */
|
2002-02-07 22:08:43 +08:00
|
|
|
{
|
2012-06-04 05:16:57 +08:00
|
|
|
return ht1 == ht2 ? 0 : zend_hash_compare(ht1, ht2, (compare_func_t) hash_zval_compare_function, 0 TSRMLS_CC);
|
2002-02-07 22:08:43 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2002-02-07 22:08:43 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API void zend_compare_symbol_tables(zval *result, HashTable *ht1, HashTable *ht2 TSRMLS_DC) /* {{{ */
|
2000-06-03 18:34:19 +08:00
|
|
|
{
|
2012-06-04 05:16:57 +08:00
|
|
|
ZVAL_LONG(result, ht1 == ht2 ? 0 : zend_hash_compare(ht1, ht2, (compare_func_t) hash_zval_compare_function, 0 TSRMLS_CC));
|
2000-06-03 18:34:19 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2000-06-03 18:34:19 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API void zend_compare_arrays(zval *result, zval *a1, zval *a2 TSRMLS_DC) /* {{{ */
|
2000-06-03 18:34:19 +08:00
|
|
|
{
|
2007-11-20 21:26:36 +08:00
|
|
|
zend_compare_symbol_tables(result, Z_ARRVAL_P(a1), Z_ARRVAL_P(a2) TSRMLS_CC);
|
2000-06-03 18:34:19 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2000-06-03 18:34:19 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API void zend_compare_objects(zval *result, zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
|
2000-06-03 18:34:19 +08:00
|
|
|
{
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_TYPE_P(result) = IS_LONG;
|
2004-03-14 23:56:03 +08:00
|
|
|
|
2004-10-21 01:57:28 +08:00
|
|
|
if (Z_OBJ_HANDLE_P(o1) == Z_OBJ_HANDLE_P(o2)) {
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(result) = 0;
|
2002-02-07 22:08:43 +08:00
|
|
|
return;
|
2004-10-21 01:57:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Z_OBJ_HT_P(o1)->compare_objects == NULL) {
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(result) = 1;
|
2002-02-07 22:08:43 +08:00
|
|
|
} else {
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_LVAL_P(result) = Z_OBJ_HT_P(o1)->compare_objects(o1, o2 TSRMLS_CC);
|
2002-02-07 22:08:43 +08:00
|
|
|
}
|
2000-06-03 18:34:19 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2002-10-13 05:15:35 +08:00
|
|
|
|
2009-05-11 07:08:52 +08:00
|
|
|
ZEND_API void zend_locale_sprintf_double(zval *op ZEND_FILE_LINE_DC) /* {{{ */
|
2002-10-13 05:15:35 +08:00
|
|
|
{
|
|
|
|
TSRMLS_FETCH();
|
2007-02-24 10:17:47 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
Z_STRLEN_P(op) = zend_spprintf(&Z_STRVAL_P(op), 0, "%.*G", (int) EG(precision), (double)Z_DVAL_P(op));
|
2003-02-01 09:49:15 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2003-02-01 09:49:15 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*/
|