1999-04-08 02:10:10 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
2019-01-30 17:23:29 +08:00
|
|
|
| Copyright (c) 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
|
|
|
+----------------------------------------------------------------------+
|
2018-11-01 23:20:07 +08:00
|
|
|
| Authors: Andi Gutmans <andi@php.net> |
|
|
|
|
| Zeev Suraski <zeev@php.net> |
|
|
|
|
| Dmitry Stogov <dmitry@php.net> |
|
1999-04-08 02:10:10 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2017-07-28 20:54:01 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL zend_atoi(const char *str, size_t str_len) /* {{{ */
|
2000-10-29 19:38:26 +08:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (!str_len) {
|
2017-07-28 20:54:01 +08:00
|
|
|
str_len = strlen(str);
|
2000-10-29 19:38:26 +08:00
|
|
|
}
|
2014-08-26 02:22:49 +08:00
|
|
|
retval = ZEND_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
|
|
|
|
2017-07-28 20:54:01 +08:00
|
|
|
ZEND_API zend_long ZEND_FASTCALL zend_atol(const char *str, size_t str_len) /* {{{ */
|
2008-03-19 20:41:23 +08:00
|
|
|
{
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_long retval;
|
2008-03-19 20:41:23 +08:00
|
|
|
|
|
|
|
if (!str_len) {
|
2017-07-28 20:54:01 +08:00
|
|
|
str_len = strlen(str);
|
2008-03-19 20:41:23 +08:00
|
|
|
}
|
2014-08-26 02:22:49 +08:00
|
|
|
retval = ZEND_STRTOL(str, NULL, 0);
|
2008-03-19 20:41:23 +08:00
|
|
|
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
|
|
|
|
2017-12-25 20:18:45 +08:00
|
|
|
/* {{{ convert_object_to_type: dst will be either ctype or UNDEF */
|
|
|
|
#define convert_object_to_type(op, dst, ctype, conv_func) \
|
|
|
|
ZVAL_UNDEF(dst); \
|
|
|
|
if (Z_OBJ_HT_P(op)->cast_object) { \
|
2019-01-31 23:47:58 +08:00
|
|
|
if (Z_OBJ_HT_P(op)->cast_object(Z_OBJ_P(op), dst, ctype) == FAILURE) { \
|
2017-12-25 20:18:45 +08:00
|
|
|
zend_error(E_RECOVERABLE_ERROR, \
|
|
|
|
"Object of class %s could not be converted to %s", ZSTR_VAL(Z_OBJCE_P(op)->name),\
|
|
|
|
zend_get_type_by_const(ctype)); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
2018-05-30 19:03:48 +08:00
|
|
|
static void ZEND_FASTCALL _convert_scalar_to_number(zval *op, zend_bool silent, zend_bool check) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2014-03-14 02:07:14 +08:00
|
|
|
try_again:
|
2007-11-20 21:26:36 +08:00
|
|
|
switch (Z_TYPE_P(op)) {
|
2014-03-14 02:07:14 +08:00
|
|
|
case IS_REFERENCE:
|
2015-06-17 01:55:33 +08:00
|
|
|
zend_unwrap_reference(op);
|
2014-03-14 02:07:14 +08:00
|
|
|
goto try_again;
|
2001-04-29 02:20:46 +08:00
|
|
|
case IS_STRING:
|
|
|
|
{
|
2014-02-10 14:04:30 +08:00
|
|
|
zend_string *str;
|
2001-04-29 02:20:46 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
str = Z_STR_P(op);
|
2016-03-30 08:44:27 +08:00
|
|
|
if ((Z_TYPE_INFO_P(op)=is_numeric_string(ZSTR_VAL(str), ZSTR_LEN(str), &Z_LVAL_P(op), &Z_DVAL_P(op), silent ? 1 : -1)) == 0) {
|
2007-11-20 21:26:36 +08:00
|
|
|
ZVAL_LONG(op, 0);
|
2016-03-30 08:44:27 +08:00
|
|
|
if (!silent) {
|
|
|
|
zend_error(E_WARNING, "A non-numeric value encountered");
|
|
|
|
}
|
2001-04-29 02:20:46 +08:00
|
|
|
}
|
2018-05-28 21:27:12 +08:00
|
|
|
zend_string_release_ex(str, 0);
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
2001-04-29 02:20:46 +08:00
|
|
|
}
|
2014-04-30 22:32:42 +08:00
|
|
|
case IS_NULL:
|
|
|
|
case IS_FALSE:
|
|
|
|
ZVAL_LONG(op, 0);
|
|
|
|
break;
|
|
|
|
case IS_TRUE:
|
|
|
|
ZVAL_LONG(op, 1);
|
2001-04-29 02:20:46 +08:00
|
|
|
break;
|
|
|
|
case IS_RESOURCE:
|
2014-02-10 14:04:30 +08:00
|
|
|
{
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_long l = Z_RES_HANDLE_P(op);
|
2014-02-10 14:04:30 +08:00
|
|
|
zval_ptr_dtor(op);
|
|
|
|
ZVAL_LONG(op, l);
|
|
|
|
}
|
2001-04-29 02:20:46 +08:00
|
|
|
break;
|
2004-03-28 20:08:26 +08:00
|
|
|
case IS_OBJECT:
|
2017-12-25 20:18:45 +08:00
|
|
|
{
|
|
|
|
zval dst;
|
|
|
|
|
|
|
|
convert_object_to_type(op, &dst, _IS_NUMBER, convert_scalar_to_number);
|
2018-05-30 19:03:48 +08:00
|
|
|
if (check && UNEXPECTED(EG(exception))) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-05 04:48:39 +08:00
|
|
|
zval_ptr_dtor(op);
|
2017-12-25 20:18:45 +08:00
|
|
|
|
|
|
|
if (Z_TYPE(dst) == IS_LONG || Z_TYPE(dst) == IS_DOUBLE) {
|
|
|
|
ZVAL_COPY_VALUE(op, &dst);
|
|
|
|
} else {
|
|
|
|
ZVAL_LONG(op, 1);
|
|
|
|
}
|
|
|
|
}
|
2004-03-28 20:08:26 +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
|
|
|
|
2016-03-30 08:44:27 +08:00
|
|
|
ZEND_API void ZEND_FASTCALL convert_scalar_to_number(zval *op) /* {{{ */
|
|
|
|
{
|
2018-05-30 19:03:48 +08:00
|
|
|
_convert_scalar_to_number(op, 1, 0);
|
2016-03-30 08:44:27 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2018-05-30 19:03:48 +08:00
|
|
|
/* {{{ _zendi_convert_scalar_to_number_ex */
|
|
|
|
static zend_always_inline zval* _zendi_convert_scalar_to_number_ex(zval *op, zval *holder, zend_bool silent) /* {{{ */
|
|
|
|
{
|
|
|
|
switch (Z_TYPE_P(op)) {
|
|
|
|
case IS_NULL:
|
|
|
|
case IS_FALSE:
|
|
|
|
ZVAL_LONG(holder, 0);
|
|
|
|
return holder;
|
|
|
|
case IS_TRUE:
|
|
|
|
ZVAL_LONG(holder, 1);
|
|
|
|
return holder;
|
|
|
|
case IS_STRING:
|
|
|
|
if ((Z_TYPE_INFO_P(holder) = is_numeric_string(Z_STRVAL_P(op), Z_STRLEN_P(op), &Z_LVAL_P(holder), &Z_DVAL_P(holder), silent ? 1 : -1)) == 0) {
|
|
|
|
ZVAL_LONG(holder, 0);
|
|
|
|
if (!silent) {
|
|
|
|
zend_error(E_WARNING, "A non-numeric value encountered");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return holder;
|
|
|
|
case IS_RESOURCE:
|
|
|
|
ZVAL_LONG(holder, Z_RES_HANDLE_P(op));
|
|
|
|
return holder;
|
|
|
|
case IS_OBJECT:
|
|
|
|
convert_object_to_type(op, holder, _IS_NUMBER, convert_scalar_to_number);
|
|
|
|
if (UNEXPECTED(EG(exception)) ||
|
|
|
|
UNEXPECTED(Z_TYPE_P(holder) != IS_LONG && Z_TYPE_P(holder) != IS_DOUBLE)) {
|
|
|
|
ZVAL_LONG(holder, 1);
|
|
|
|
}
|
|
|
|
return holder;
|
|
|
|
case IS_LONG:
|
|
|
|
case IS_DOUBLE:
|
|
|
|
default:
|
|
|
|
return op;
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2018-05-30 19:03:48 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2018-05-30 19:03:48 +08:00
|
|
|
/* {{{ _zendi_convert_scalar_to_number */
|
|
|
|
static zend_never_inline zval* ZEND_FASTCALL _zendi_convert_scalar_to_number(zval *op, zval *holder) /* {{{ */
|
|
|
|
{
|
|
|
|
return _zendi_convert_scalar_to_number_ex(op, holder, 1);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ _zendi_convert_scalar_to_number_noisy */
|
|
|
|
static zend_never_inline zval* ZEND_FASTCALL _zendi_convert_scalar_to_number_noisy(zval *op, zval *holder) /* {{{ */
|
|
|
|
{
|
|
|
|
return _zendi_convert_scalar_to_number_ex(op, holder, 0);
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2007-12-25 02:09:50 +08:00
|
|
|
|
2018-05-30 19:03:48 +08:00
|
|
|
#define zendi_convert_scalar_to_number(op, holder, result, silent) \
|
|
|
|
((Z_TYPE_P(op) == IS_LONG || Z_TYPE_P(op) == IS_DOUBLE) ? (op) : \
|
|
|
|
(((op) == result) ? (_convert_scalar_to_number((op), silent, 1), (op)) : \
|
|
|
|
(silent ? _zendi_convert_scalar_to_number((op), holder) : \
|
|
|
|
_zendi_convert_scalar_to_number_noisy((op), holder))))
|
|
|
|
|
2016-12-07 05:41:07 +08:00
|
|
|
#define convert_op1_op2_long(op1, op1_lval, op2, op2_lval, result, op, op_func) \
|
2014-12-23 09:51:19 +08:00
|
|
|
do { \
|
|
|
|
if (UNEXPECTED(Z_TYPE_P(op1) != IS_LONG)) { \
|
|
|
|
if (Z_ISREF_P(op1)) { \
|
|
|
|
op1 = Z_REFVAL_P(op1); \
|
|
|
|
if (Z_TYPE_P(op1) == IS_LONG) { \
|
|
|
|
op1_lval = Z_LVAL_P(op1); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
ZEND_TRY_BINARY_OP1_OBJECT_OPERATION(op, op_func); \
|
2016-03-30 08:44:27 +08:00
|
|
|
op1_lval = _zval_get_long_func_noisy(op1); \
|
2016-12-06 02:45:08 +08:00
|
|
|
if (UNEXPECTED(EG(exception))) { \
|
2016-12-07 05:41:07 +08:00
|
|
|
if (result != op1) { \
|
|
|
|
ZVAL_UNDEF(result); \
|
|
|
|
} \
|
2016-12-06 02:45:08 +08:00
|
|
|
return FAILURE; \
|
|
|
|
} \
|
2014-12-23 09:51:19 +08:00
|
|
|
} else { \
|
|
|
|
op1_lval = Z_LVAL_P(op1); \
|
|
|
|
} \
|
|
|
|
} while (0); \
|
|
|
|
do { \
|
|
|
|
if (UNEXPECTED(Z_TYPE_P(op2) != IS_LONG)) { \
|
|
|
|
if (Z_ISREF_P(op2)) { \
|
|
|
|
op2 = Z_REFVAL_P(op2); \
|
|
|
|
if (Z_TYPE_P(op2) == IS_LONG) { \
|
|
|
|
op2_lval = Z_LVAL_P(op2); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
ZEND_TRY_BINARY_OP2_OBJECT_OPERATION(op); \
|
2016-03-30 08:44:27 +08:00
|
|
|
op2_lval = _zval_get_long_func_noisy(op2); \
|
2016-12-06 02:45:08 +08:00
|
|
|
if (UNEXPECTED(EG(exception))) { \
|
2016-12-07 05:41:07 +08:00
|
|
|
if (result != op1) { \
|
|
|
|
ZVAL_UNDEF(result); \
|
|
|
|
} \
|
2016-12-06 02:45:08 +08:00
|
|
|
return FAILURE; \
|
|
|
|
} \
|
2014-12-23 09:51:19 +08:00
|
|
|
} else { \
|
|
|
|
op2_lval = Z_LVAL_P(op2); \
|
|
|
|
} \
|
2014-12-23 11:59:17 +08:00
|
|
|
} while (0);
|
2014-12-23 09:51:19 +08:00
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API void ZEND_FASTCALL 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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API void ZEND_FASTCALL convert_to_long_base(zval *op, int base) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_long tmp;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2015-06-17 01:55:33 +08:00
|
|
|
try_again:
|
2007-11-20 21:26:36 +08:00
|
|
|
switch (Z_TYPE_P(op)) {
|
2000-01-04 21:22:58 +08:00
|
|
|
case IS_NULL:
|
2014-04-30 22:32:42 +08:00
|
|
|
case IS_FALSE:
|
2014-04-03 19:26:23 +08:00
|
|
|
ZVAL_LONG(op, 0);
|
1999-12-31 21:56:59 +08:00
|
|
|
break;
|
2014-04-30 22:32:42 +08:00
|
|
|
case IS_TRUE:
|
|
|
|
ZVAL_LONG(op, 1);
|
|
|
|
break;
|
2015-01-25 06:11:05 +08:00
|
|
|
case IS_RESOURCE:
|
|
|
|
tmp = Z_RES_HANDLE_P(op);
|
|
|
|
zval_ptr_dtor(op);
|
|
|
|
ZVAL_LONG(op, tmp);
|
2014-04-03 19:26:23 +08:00
|
|
|
break;
|
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:
|
2014-04-03 19:26:23 +08:00
|
|
|
ZVAL_LONG(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
|
|
|
{
|
2014-02-10 14:04:30 +08:00
|
|
|
zend_string *str = Z_STR_P(op);
|
2016-03-30 08:44:27 +08:00
|
|
|
if (base == 10) {
|
|
|
|
ZVAL_LONG(op, zval_get_long(op));
|
|
|
|
} else {
|
|
|
|
ZVAL_LONG(op, ZEND_STRTOL(ZSTR_VAL(str), NULL, base));
|
|
|
|
}
|
2018-05-28 21:27:12 +08:00
|
|
|
zend_string_release_ex(str, 0);
|
2009-05-11 15:52:49 +08:00
|
|
|
}
|
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);
|
2015-06-12 01:41:43 +08:00
|
|
|
zval_ptr_dtor(op);
|
2014-04-03 19:26:23 +08:00
|
|
|
ZVAL_LONG(op, tmp);
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
case IS_OBJECT:
|
2004-03-14 23:45:09 +08:00
|
|
|
{
|
2014-04-25 22:36:29 +08:00
|
|
|
zval dst;
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-04-25 22:36:29 +08:00
|
|
|
convert_object_to_type(op, &dst, IS_LONG, convert_to_long);
|
2018-07-06 17:07:13 +08:00
|
|
|
zval_ptr_dtor(op);
|
2004-05-10 22:56:21 +08:00
|
|
|
|
2014-04-25 22:36:29 +08:00
|
|
|
if (Z_TYPE(dst) == IS_LONG) {
|
2018-07-06 06:26:43 +08:00
|
|
|
ZVAL_LONG(op, Z_LVAL(dst));
|
2014-04-25 22:36:29 +08:00
|
|
|
} else {
|
|
|
|
ZVAL_LONG(op, 1);
|
|
|
|
}
|
2005-08-05 17:02:14 +08:00
|
|
|
return;
|
2003-05-28 02:52:25 +08:00
|
|
|
}
|
2015-06-17 01:55:33 +08:00
|
|
|
case IS_REFERENCE:
|
|
|
|
zend_unwrap_reference(op);
|
|
|
|
goto try_again;
|
2014-05-17 00:54:01 +08:00
|
|
|
EMPTY_SWITCH_DEFAULT_CASE()
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API void ZEND_FASTCALL convert_to_double(zval *op) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
double tmp;
|
|
|
|
|
2015-06-17 01:55:33 +08:00
|
|
|
try_again:
|
2007-11-20 21:26:36 +08:00
|
|
|
switch (Z_TYPE_P(op)) {
|
2000-01-04 21:22:58 +08:00
|
|
|
case IS_NULL:
|
2014-04-30 22:32:42 +08:00
|
|
|
case IS_FALSE:
|
2014-04-03 19:26:23 +08:00
|
|
|
ZVAL_DOUBLE(op, 0.0);
|
1999-12-31 21:56:59 +08:00
|
|
|
break;
|
2014-04-30 22:32:42 +08:00
|
|
|
case IS_TRUE:
|
|
|
|
ZVAL_DOUBLE(op, 1.0);
|
|
|
|
break;
|
2001-07-30 12:54:16 +08:00
|
|
|
case IS_RESOURCE: {
|
2014-02-10 14:04:30 +08:00
|
|
|
double d = (double) Z_RES_HANDLE_P(op);
|
|
|
|
zval_ptr_dtor(op);
|
2014-04-03 19:26:23 +08:00
|
|
|
ZVAL_DOUBLE(op, d);
|
2001-07-30 12:54:16 +08:00
|
|
|
}
|
2014-02-10 14:04:30 +08:00
|
|
|
break;
|
1999-04-08 02:10:10 +08:00
|
|
|
case IS_LONG:
|
2014-04-03 19:26:23 +08:00
|
|
|
ZVAL_DOUBLE(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
|
|
|
{
|
2014-02-10 14:04:30 +08:00
|
|
|
zend_string *str = Z_STR_P(op);
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2015-06-30 18:59:27 +08:00
|
|
|
ZVAL_DOUBLE(op, zend_strtod(ZSTR_VAL(str), NULL));
|
2018-05-28 21:27:12 +08:00
|
|
|
zend_string_release_ex(str, 0);
|
2009-05-11 15:52:49 +08:00
|
|
|
}
|
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);
|
2015-06-12 01:41:43 +08:00
|
|
|
zval_ptr_dtor(op);
|
2014-04-03 19:26:23 +08:00
|
|
|
ZVAL_DOUBLE(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
|
|
|
{
|
2014-04-25 22:36:29 +08:00
|
|
|
zval dst;
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-04-25 22:36:29 +08:00
|
|
|
convert_object_to_type(op, &dst, IS_DOUBLE, convert_to_double);
|
2018-07-06 17:07:13 +08:00
|
|
|
zval_ptr_dtor(op);
|
2004-03-14 23:45:09 +08:00
|
|
|
|
2014-04-25 22:36:29 +08:00
|
|
|
if (Z_TYPE(dst) == IS_DOUBLE) {
|
2018-07-06 06:26:43 +08:00
|
|
|
ZVAL_DOUBLE(op, Z_DVAL(dst));
|
2014-04-25 22:36:29 +08:00
|
|
|
} else {
|
|
|
|
ZVAL_DOUBLE(op, 1.0);
|
|
|
|
}
|
2004-03-14 23:45:09 +08:00
|
|
|
break;
|
2007-11-20 21:26:36 +08:00
|
|
|
}
|
2015-06-17 01:55:33 +08:00
|
|
|
case IS_REFERENCE:
|
|
|
|
zend_unwrap_reference(op);
|
|
|
|
goto try_again;
|
2014-05-17 00:54:01 +08:00
|
|
|
EMPTY_SWITCH_DEFAULT_CASE()
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
1999-12-31 21:56:59 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-12-31 21:56:59 +08:00
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API void ZEND_FASTCALL convert_to_null(zval *op) /* {{{ */
|
1999-12-31 21:56:59 +08:00
|
|
|
{
|
2015-06-12 01:41:43 +08:00
|
|
|
zval_ptr_dtor(op);
|
2014-04-03 19:26:23 +08:00
|
|
|
ZVAL_NULL(op);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API void ZEND_FASTCALL convert_to_boolean(zval *op) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
|
2015-06-17 01:55:33 +08:00
|
|
|
try_again:
|
2007-11-20 21:26:36 +08:00
|
|
|
switch (Z_TYPE_P(op)) {
|
2014-04-30 22:32:42 +08:00
|
|
|
case IS_FALSE:
|
|
|
|
case IS_TRUE:
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
2000-01-04 21:22:58 +08:00
|
|
|
case IS_NULL:
|
2014-12-22 13:10:46 +08:00
|
|
|
ZVAL_FALSE(op);
|
1999-12-31 21:56:59 +08:00
|
|
|
break;
|
2001-07-30 12:54:16 +08:00
|
|
|
case IS_RESOURCE: {
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_long l = (Z_RES_HANDLE_P(op) ? 1 : 0);
|
2001-07-30 12:54:16 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
zval_ptr_dtor(op);
|
2014-04-03 19:26:23 +08:00
|
|
|
ZVAL_BOOL(op, l);
|
2001-07-30 12:54:16 +08:00
|
|
|
}
|
2014-02-10 14:04:30 +08:00
|
|
|
break;
|
1999-09-03 08:11:47 +08:00
|
|
|
case IS_LONG:
|
2014-04-03 19:26:23 +08:00
|
|
|
ZVAL_BOOL(op, Z_LVAL_P(op) ? 1 : 0);
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
case IS_DOUBLE:
|
2014-04-03 19:26:23 +08:00
|
|
|
ZVAL_BOOL(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
|
|
|
{
|
2014-02-10 14:04:30 +08:00
|
|
|
zend_string *str = Z_STR_P(op);
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2015-06-30 18:59:27 +08:00
|
|
|
if (ZSTR_LEN(str) == 0
|
|
|
|
|| (ZSTR_LEN(str) == 1 && ZSTR_VAL(str)[0] == '0')) {
|
2014-12-22 13:10:46 +08:00
|
|
|
ZVAL_FALSE(op);
|
2009-05-11 15:52:49 +08:00
|
|
|
} else {
|
2014-12-22 13:10:46 +08:00
|
|
|
ZVAL_TRUE(op);
|
2009-05-11 15:52:49 +08:00
|
|
|
}
|
2018-05-28 21:27:12 +08:00
|
|
|
zend_string_release_ex(str, 0);
|
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);
|
2015-06-12 01:41:43 +08:00
|
|
|
zval_ptr_dtor(op);
|
2014-04-03 19:26:23 +08:00
|
|
|
ZVAL_BOOL(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
|
|
|
{
|
2014-04-25 22:36:29 +08:00
|
|
|
zval dst;
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-04-30 22:32:42 +08:00
|
|
|
convert_object_to_type(op, &dst, _IS_BOOL, convert_to_boolean);
|
2018-07-06 17:07:13 +08:00
|
|
|
zval_ptr_dtor(op);
|
2004-05-10 22:56:21 +08:00
|
|
|
|
2018-07-06 06:26:43 +08:00
|
|
|
if (Z_TYPE_INFO(dst) == IS_FALSE || Z_TYPE_INFO(dst) == IS_TRUE) {
|
|
|
|
Z_TYPE_INFO_P(op) = Z_TYPE_INFO(dst);
|
2014-04-25 22:36:29 +08:00
|
|
|
} else {
|
2014-12-22 13:10:46 +08:00
|
|
|
ZVAL_TRUE(op);
|
2004-05-10 22:56:21 +08:00
|
|
|
}
|
2004-03-14 23:45:09 +08:00
|
|
|
break;
|
2003-05-28 02:52:25 +08:00
|
|
|
}
|
2015-06-17 01:55:33 +08:00
|
|
|
case IS_REFERENCE:
|
|
|
|
zend_unwrap_reference(op);
|
|
|
|
goto try_again;
|
2014-05-17 00:54:01 +08:00
|
|
|
EMPTY_SWITCH_DEFAULT_CASE()
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2018-07-23 20:24:07 +08:00
|
|
|
ZEND_API void ZEND_FASTCALL _convert_to_cstring(zval *op) /* {{{ */
|
2013-01-15 04:23:52 +08:00
|
|
|
{
|
2015-10-07 09:26:26 +08:00
|
|
|
if (Z_TYPE_P(op) == IS_DOUBLE) {
|
|
|
|
zend_string *str;
|
|
|
|
double dval = Z_DVAL_P(op);
|
|
|
|
|
2017-11-16 19:29:27 +08:00
|
|
|
str = zend_strpprintf_unchecked(0, "%.*H", (int) EG(precision), dval);
|
2015-10-07 09:26:26 +08:00
|
|
|
ZVAL_NEW_STR(op, str);
|
|
|
|
} else {
|
2018-07-23 20:24:07 +08:00
|
|
|
_convert_to_string(op);
|
2015-10-07 09:26:26 +08:00
|
|
|
}
|
2013-01-15 04:23:52 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2018-07-23 20:24:07 +08:00
|
|
|
ZEND_API void ZEND_FASTCALL _convert_to_string(zval *op) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2015-06-17 01:55:33 +08:00
|
|
|
try_again:
|
2007-11-20 21:26:36 +08:00
|
|
|
switch (Z_TYPE_P(op)) {
|
2014-09-16 13:15:47 +08:00
|
|
|
case IS_UNDEF:
|
2014-04-30 22:32:42 +08:00
|
|
|
case IS_NULL:
|
|
|
|
case IS_FALSE: {
|
2015-01-25 06:11:05 +08:00
|
|
|
ZVAL_EMPTY_STRING(op);
|
1999-12-31 21:56:59 +08:00
|
|
|
break;
|
2014-04-09 21:51:28 +08:00
|
|
|
}
|
2014-04-30 22:32:42 +08:00
|
|
|
case IS_TRUE:
|
2017-03-04 17:39:13 +08:00
|
|
|
ZVAL_INTERNED_STR(op, ZSTR_CHAR('1'));
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
2014-04-30 22:32:42 +08:00
|
|
|
case IS_STRING:
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
2000-05-18 18:21:24 +08:00
|
|
|
case IS_RESOURCE: {
|
2018-03-07 02:58:40 +08:00
|
|
|
zend_string *str = zend_strpprintf(0, "Resource id #" ZEND_LONG_FMT, (zend_long)Z_RES_HANDLE_P(op));
|
2015-01-25 06:11:05 +08:00
|
|
|
zval_ptr_dtor(op);
|
2018-03-07 02:58:40 +08:00
|
|
|
ZVAL_NEW_STR(op, str);
|
2000-05-18 18:21:24 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-02-10 14:04:30 +08:00
|
|
|
case IS_LONG: {
|
2017-05-18 22:59:59 +08:00
|
|
|
ZVAL_STR(op, zend_long_to_str(Z_LVAL_P(op)));
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
2014-02-10 14:04:30 +08:00
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
case IS_DOUBLE: {
|
2014-05-10 00:21:49 +08:00
|
|
|
zend_string *str;
|
2014-05-01 14:55:59 +08:00
|
|
|
double dval = Z_DVAL_P(op);
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-05-10 00:21:49 +08:00
|
|
|
str = zend_strpprintf(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 */
|
2014-05-10 00:21:49 +08:00
|
|
|
ZVAL_NEW_STR(op, str);
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IS_ARRAY:
|
2019-10-01 19:20:42 +08:00
|
|
|
zend_error(E_WARNING, "Array to string conversion");
|
2015-06-12 01:41:43 +08:00
|
|
|
zval_ptr_dtor(op);
|
2019-02-26 22:32:18 +08:00
|
|
|
ZVAL_INTERNED_STR(op, ZSTR_KNOWN(ZEND_STR_ARRAY_CAPITALIZED));
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
2003-11-08 22:06:08 +08:00
|
|
|
case IS_OBJECT: {
|
2019-02-26 22:32:18 +08:00
|
|
|
zval tmp;
|
2004-03-28 20:08:26 +08:00
|
|
|
|
2019-02-26 22:32:18 +08:00
|
|
|
if (Z_OBJ_HT_P(op)->cast_object) {
|
2019-06-05 20:38:01 +08:00
|
|
|
if (Z_OBJ_HT_P(op)->cast_object(Z_OBJ_P(op), &tmp, IS_STRING) == SUCCESS) {
|
2019-02-26 22:32:18 +08:00
|
|
|
zval_ptr_dtor(op);
|
|
|
|
ZVAL_COPY_VALUE(op, &tmp);
|
|
|
|
return;
|
|
|
|
}
|
2004-05-10 22:56:21 +08:00
|
|
|
}
|
2019-02-26 22:32:18 +08:00
|
|
|
if (!EG(exception)) {
|
|
|
|
zend_throw_error(NULL, "Object of class %s could not be converted to string", ZSTR_VAL(Z_OBJCE_P(op)->name));
|
2004-05-10 22:56:21 +08:00
|
|
|
}
|
2019-02-26 22:32:18 +08:00
|
|
|
zval_ptr_dtor(op);
|
|
|
|
ZVAL_EMPTY_STRING(op);
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
2003-11-08 22:06:08 +08:00
|
|
|
}
|
2015-06-17 01:55:33 +08:00
|
|
|
case IS_REFERENCE:
|
|
|
|
zend_unwrap_reference(op);
|
|
|
|
goto try_again;
|
2014-05-17 00:54:01 +08:00
|
|
|
EMPTY_SWITCH_DEFAULT_CASE()
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2019-02-26 22:32:18 +08:00
|
|
|
ZEND_API zend_bool ZEND_FASTCALL _try_convert_to_string(zval *op)
|
|
|
|
{
|
2019-06-06 06:47:22 +08:00
|
|
|
zend_string *str;
|
|
|
|
|
|
|
|
ZEND_ASSERT(Z_TYPE_P(op) != IS_STRING);
|
|
|
|
str = zval_try_get_string_func(op);
|
|
|
|
if (UNEXPECTED(!str)) {
|
|
|
|
return 0;
|
2019-02-26 22:32:18 +08:00
|
|
|
}
|
2019-06-06 06:47:22 +08:00
|
|
|
zval_ptr_dtor(op);
|
|
|
|
ZVAL_STR(op, str);
|
2019-02-26 22:32:18 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void convert_scalar_to_array(zval *op) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2018-07-06 06:26:43 +08:00
|
|
|
HashTable *ht = zend_new_array(1);
|
|
|
|
zend_hash_index_add_new(ht, 0, op);
|
|
|
|
ZVAL_ARR(op, ht);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API void ZEND_FASTCALL convert_to_array(zval *op) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2015-06-17 01:55:33 +08:00
|
|
|
try_again:
|
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:
|
2014-04-25 21:48:46 +08:00
|
|
|
if (Z_OBJCE_P(op) == zend_ce_closure) {
|
2014-12-14 06:06:14 +08:00
|
|
|
convert_scalar_to_array(op);
|
2014-04-25 21:48:46 +08:00
|
|
|
} else {
|
2018-10-04 19:58:35 +08:00
|
|
|
HashTable *obj_ht = zend_get_properties_for(op, ZEND_PROP_PURPOSE_ARRAY_CAST);
|
|
|
|
if (obj_ht) {
|
|
|
|
HashTable *new_obj_ht = zend_proptable_to_symtable(obj_ht,
|
|
|
|
(Z_OBJCE_P(op)->default_properties_count ||
|
|
|
|
Z_OBJ_P(op)->handlers != &std_object_handlers ||
|
|
|
|
GC_IS_RECURSIVE(obj_ht)));
|
|
|
|
zval_ptr_dtor(op);
|
|
|
|
ZVAL_ARR(op, new_obj_ht);
|
|
|
|
zend_release_properties(obj_ht);
|
2004-03-28 20:08:26 +08:00
|
|
|
} else {
|
2018-10-04 19:58:35 +08:00
|
|
|
zval_ptr_dtor(op);
|
|
|
|
/*ZVAL_EMPTY_ARRAY(op);*/
|
|
|
|
array_init(op);
|
2002-02-07 22:08:43 +08:00
|
|
|
}
|
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:
|
2017-10-24 22:27:31 +08:00
|
|
|
/*ZVAL_EMPTY_ARRAY(op);*/
|
2017-09-20 07:25:56 +08:00
|
|
|
array_init(op);
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
2015-06-17 01:55:33 +08:00
|
|
|
case IS_REFERENCE:
|
|
|
|
zend_unwrap_reference(op);
|
|
|
|
goto try_again;
|
1999-04-08 02:10:10 +08:00
|
|
|
default:
|
2014-12-14 06:06:14 +08:00
|
|
|
convert_scalar_to_array(op);
|
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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API void ZEND_FASTCALL convert_to_object(zval *op) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2015-06-17 01:55:33 +08:00
|
|
|
try_again:
|
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
|
|
|
{
|
2018-07-06 06:26:43 +08:00
|
|
|
HashTable *ht = zend_symtable_to_proptable(Z_ARR_P(op));
|
|
|
|
zend_object *obj;
|
|
|
|
|
2016-11-15 02:20:45 +08:00
|
|
|
if (GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) {
|
2015-08-26 03:40:33 +08:00
|
|
|
/* TODO: try not to duplicate immutable arrays as well ??? */
|
|
|
|
ht = zend_array_dup(ht);
|
2018-07-06 06:26:43 +08:00
|
|
|
} else if (ht != Z_ARR_P(op)) {
|
2018-07-06 17:07:13 +08:00
|
|
|
zval_ptr_dtor(op);
|
2018-07-06 06:26:43 +08:00
|
|
|
} else {
|
|
|
|
GC_DELREF(ht);
|
2015-08-26 03:40:33 +08:00
|
|
|
}
|
2018-07-06 06:26:43 +08:00
|
|
|
obj = zend_objects_new(zend_standard_class_def);
|
|
|
|
obj->properties = ht;
|
|
|
|
ZVAL_OBJ(op, obj);
|
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;
|
2015-06-17 01:55:33 +08:00
|
|
|
case IS_REFERENCE:
|
|
|
|
zend_unwrap_reference(op);
|
|
|
|
goto try_again;
|
2014-04-25 21:48:46 +08:00
|
|
|
default: {
|
|
|
|
zval tmp;
|
|
|
|
ZVAL_COPY_VALUE(&tmp, op);
|
|
|
|
object_init(op);
|
2017-03-04 17:39:13 +08:00
|
|
|
zend_hash_add_new(Z_OBJPROP_P(op), ZSTR_KNOWN(ZEND_STR_SCALAR), &tmp);
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
2014-04-25 21:48:46 +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
|
|
|
ZEND_API void multi_convert_to_long_ex(int argc, ...) /* {{{ */
|
2000-09-06 01:55:57 +08:00
|
|
|
{
|
2014-02-10 14:04:30 +08:00
|
|
|
zval *arg;
|
2000-09-06 01:55:57 +08:00
|
|
|
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--) {
|
2014-02-10 14:04:30 +08:00
|
|
|
arg = va_arg(ap, zval *);
|
2000-09-06 01:55:57 +08:00
|
|
|
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
|
|
|
{
|
2014-02-10 14:04:30 +08:00
|
|
|
zval *arg;
|
2000-09-06 01:55:57 +08:00
|
|
|
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--) {
|
2014-02-10 14:04:30 +08:00
|
|
|
arg = va_arg(ap, zval *);
|
2000-09-06 01:55:57 +08:00
|
|
|
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
|
|
|
{
|
2014-02-10 14:04:30 +08:00
|
|
|
zval *arg;
|
2000-09-06 01:55:57 +08:00
|
|
|
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--) {
|
2014-02-10 14:04:30 +08:00
|
|
|
arg = va_arg(ap, zval *);
|
2000-09-06 01:55:57 +08:00
|
|
|
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
|
|
|
|
2016-03-30 08:44:27 +08:00
|
|
|
static zend_always_inline zend_long ZEND_FASTCALL _zval_get_long_func_ex(zval *op, zend_bool silent) /* {{{ */
|
2014-04-16 00:33:38 +08:00
|
|
|
{
|
2014-04-25 19:37:07 +08:00
|
|
|
try_again:
|
2014-04-16 00:33:38 +08:00
|
|
|
switch (Z_TYPE_P(op)) {
|
2016-04-13 05:05:19 +08:00
|
|
|
case IS_UNDEF:
|
2014-04-16 00:33:38 +08:00
|
|
|
case IS_NULL:
|
2014-04-30 22:32:42 +08:00
|
|
|
case IS_FALSE:
|
2014-04-16 00:33:38 +08:00
|
|
|
return 0;
|
2014-04-30 22:32:42 +08:00
|
|
|
case IS_TRUE:
|
|
|
|
return 1;
|
2014-04-16 00:33:38 +08:00
|
|
|
case IS_RESOURCE:
|
|
|
|
return Z_RES_HANDLE_P(op);
|
|
|
|
case IS_LONG:
|
|
|
|
return Z_LVAL_P(op);
|
|
|
|
case IS_DOUBLE:
|
|
|
|
return zend_dval_to_lval(Z_DVAL_P(op));
|
|
|
|
case IS_STRING:
|
2016-03-30 08:44:27 +08:00
|
|
|
{
|
|
|
|
zend_uchar type;
|
|
|
|
zend_long lval;
|
|
|
|
double dval;
|
|
|
|
if (0 == (type = is_numeric_string(Z_STRVAL_P(op), Z_STRLEN_P(op), &lval, &dval, silent ? 1 : -1))) {
|
|
|
|
if (!silent) {
|
|
|
|
zend_error(E_WARNING, "A non-numeric value encountered");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
} else if (EXPECTED(type == IS_LONG)) {
|
|
|
|
return lval;
|
|
|
|
} else {
|
|
|
|
/* Previously we used strtol here, not is_numeric_string,
|
|
|
|
* and strtol gives you LONG_MAX/_MIN on overflow.
|
|
|
|
* We use use saturating conversion to emulate strtol()'s
|
|
|
|
* behaviour.
|
|
|
|
*/
|
|
|
|
return zend_dval_to_lval_cap(dval);
|
|
|
|
}
|
|
|
|
}
|
2014-04-16 00:33:38 +08:00
|
|
|
case IS_ARRAY:
|
|
|
|
return zend_hash_num_elements(Z_ARRVAL_P(op)) ? 1 : 0;
|
|
|
|
case IS_OBJECT:
|
|
|
|
{
|
2014-04-25 22:36:29 +08:00
|
|
|
zval dst;
|
|
|
|
convert_object_to_type(op, &dst, IS_LONG, convert_to_long);
|
|
|
|
if (Z_TYPE(dst) == IS_LONG) {
|
|
|
|
return Z_LVAL(dst);
|
2014-04-16 00:33:38 +08:00
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2014-04-25 19:37:07 +08:00
|
|
|
case IS_REFERENCE:
|
|
|
|
op = Z_REFVAL_P(op);
|
|
|
|
goto try_again;
|
2014-05-17 00:54:01 +08:00
|
|
|
EMPTY_SWITCH_DEFAULT_CASE()
|
2014-04-16 00:33:38 +08:00
|
|
|
}
|
2014-08-15 03:53:27 +08:00
|
|
|
return 0;
|
2014-04-16 00:33:38 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2017-11-16 22:09:01 +08:00
|
|
|
ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(zval *op) /* {{{ */
|
2016-03-30 08:44:27 +08:00
|
|
|
{
|
|
|
|
return _zval_get_long_func_ex(op, 1);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
static zend_long ZEND_FASTCALL _zval_get_long_func_noisy(zval *op) /* {{{ */
|
|
|
|
{
|
|
|
|
return _zval_get_long_func_ex(op, 0);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2017-11-16 22:09:01 +08:00
|
|
|
ZEND_API double ZEND_FASTCALL zval_get_double_func(zval *op) /* {{{ */
|
2014-04-16 00:33:38 +08:00
|
|
|
{
|
2014-04-25 19:37:07 +08:00
|
|
|
try_again:
|
2014-04-16 00:33:38 +08:00
|
|
|
switch (Z_TYPE_P(op)) {
|
|
|
|
case IS_NULL:
|
2014-04-30 22:32:42 +08:00
|
|
|
case IS_FALSE:
|
2014-04-16 00:33:38 +08:00
|
|
|
return 0.0;
|
2014-04-30 22:32:42 +08:00
|
|
|
case IS_TRUE:
|
|
|
|
return 1.0;
|
2014-04-16 00:33:38 +08:00
|
|
|
case IS_RESOURCE:
|
|
|
|
return (double) Z_RES_HANDLE_P(op);
|
|
|
|
case IS_LONG:
|
|
|
|
return (double) Z_LVAL_P(op);
|
|
|
|
case IS_DOUBLE:
|
|
|
|
return Z_DVAL_P(op);
|
|
|
|
case IS_STRING:
|
|
|
|
return zend_strtod(Z_STRVAL_P(op), NULL);
|
|
|
|
case IS_ARRAY:
|
|
|
|
return zend_hash_num_elements(Z_ARRVAL_P(op)) ? 1.0 : 0.0;
|
|
|
|
case IS_OBJECT:
|
|
|
|
{
|
2014-04-25 22:36:29 +08:00
|
|
|
zval dst;
|
|
|
|
convert_object_to_type(op, &dst, IS_DOUBLE, convert_to_double);
|
2014-04-16 00:33:38 +08:00
|
|
|
|
2014-04-25 22:36:29 +08:00
|
|
|
if (Z_TYPE(dst) == IS_DOUBLE) {
|
|
|
|
return Z_DVAL(dst);
|
2014-04-16 00:33:38 +08:00
|
|
|
} else {
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
}
|
2014-04-25 19:37:07 +08:00
|
|
|
case IS_REFERENCE:
|
|
|
|
op = Z_REFVAL_P(op);
|
|
|
|
goto try_again;
|
2014-05-17 00:54:01 +08:00
|
|
|
EMPTY_SWITCH_DEFAULT_CASE()
|
2014-04-16 00:33:38 +08:00
|
|
|
}
|
2014-08-15 03:53:27 +08:00
|
|
|
return 0.0;
|
2014-04-16 00:33:38 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2019-06-06 06:47:22 +08:00
|
|
|
static zend_always_inline zend_string* __zval_get_string_func(zval *op, zend_bool try) /* {{{ */
|
2014-04-16 00:33:38 +08:00
|
|
|
{
|
2014-04-22 02:36:01 +08:00
|
|
|
try_again:
|
2014-04-16 00:33:38 +08:00
|
|
|
switch (Z_TYPE_P(op)) {
|
2014-09-16 13:15:47 +08:00
|
|
|
case IS_UNDEF:
|
2014-04-16 00:33:38 +08:00
|
|
|
case IS_NULL:
|
2014-04-30 22:32:42 +08:00
|
|
|
case IS_FALSE:
|
2015-06-29 21:44:54 +08:00
|
|
|
return ZSTR_EMPTY_ALLOC();
|
2014-04-30 22:32:42 +08:00
|
|
|
case IS_TRUE:
|
2017-03-04 17:39:13 +08:00
|
|
|
return ZSTR_CHAR('1');
|
2014-04-16 00:33:38 +08:00
|
|
|
case IS_RESOURCE: {
|
2018-03-07 02:58:40 +08:00
|
|
|
return zend_strpprintf(0, "Resource id #" ZEND_LONG_FMT, (zend_long)Z_RES_HANDLE_P(op));
|
2014-04-16 00:33:38 +08:00
|
|
|
}
|
|
|
|
case IS_LONG: {
|
2014-05-23 19:10:50 +08:00
|
|
|
return zend_long_to_str(Z_LVAL_P(op));
|
2014-04-16 00:33:38 +08:00
|
|
|
}
|
|
|
|
case IS_DOUBLE: {
|
2014-05-10 00:21:49 +08:00
|
|
|
return zend_strpprintf(0, "%.*G", (int) EG(precision), Z_DVAL_P(op));
|
2014-04-16 00:33:38 +08:00
|
|
|
}
|
|
|
|
case IS_ARRAY:
|
2019-10-01 19:20:42 +08:00
|
|
|
zend_error(E_WARNING, "Array to string conversion");
|
2019-06-06 19:09:42 +08:00
|
|
|
return (try && UNEXPECTED(EG(exception))) ?
|
|
|
|
NULL : ZSTR_KNOWN(ZEND_STR_ARRAY_CAPITALIZED);
|
2014-04-16 00:33:38 +08:00
|
|
|
case IS_OBJECT: {
|
|
|
|
zval tmp;
|
2014-04-21 23:10:35 +08:00
|
|
|
if (Z_OBJ_HT_P(op)->cast_object) {
|
2019-01-31 23:47:58 +08:00
|
|
|
if (Z_OBJ_HT_P(op)->cast_object(Z_OBJ_P(op), &tmp, IS_STRING) == SUCCESS) {
|
2014-04-21 23:10:35 +08:00
|
|
|
return Z_STR(tmp);
|
|
|
|
}
|
2014-04-16 00:33:38 +08:00
|
|
|
}
|
2019-02-26 22:32:18 +08:00
|
|
|
if (!EG(exception)) {
|
|
|
|
zend_throw_error(NULL, "Object of class %s could not be converted to string", ZSTR_VAL(Z_OBJCE_P(op)->name));
|
|
|
|
}
|
2019-06-06 06:47:22 +08:00
|
|
|
return try ? NULL : ZSTR_EMPTY_ALLOC();
|
2014-04-16 00:33:38 +08:00
|
|
|
}
|
2014-04-21 23:10:35 +08:00
|
|
|
case IS_REFERENCE:
|
2014-04-22 02:36:01 +08:00
|
|
|
op = Z_REFVAL_P(op);
|
|
|
|
goto try_again;
|
2014-09-23 13:50:00 +08:00
|
|
|
case IS_STRING:
|
|
|
|
return zend_string_copy(Z_STR_P(op));
|
2014-05-17 00:54:01 +08:00
|
|
|
EMPTY_SWITCH_DEFAULT_CASE()
|
2014-04-16 00:33:38 +08:00
|
|
|
}
|
2014-08-15 03:53:27 +08:00
|
|
|
return NULL;
|
2014-04-16 00:33:38 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2019-06-06 06:47:22 +08:00
|
|
|
ZEND_API zend_string* ZEND_FASTCALL zval_get_string_func(zval *op) /* {{{ */
|
|
|
|
{
|
|
|
|
return __zval_get_string_func(op, 0);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2019-02-26 22:32:18 +08:00
|
|
|
ZEND_API zend_string* ZEND_FASTCALL zval_try_get_string_func(zval *op) /* {{{ */
|
|
|
|
{
|
2019-06-06 06:47:22 +08:00
|
|
|
return __zval_get_string_func(op, 1);
|
2019-02-26 22:32:18 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2018-07-25 17:48:16 +08:00
|
|
|
static zend_never_inline void ZEND_FASTCALL add_function_array(zval *result, zval *op1, zval *op2) /* {{{ */
|
|
|
|
{
|
|
|
|
if ((result == op1) && (result == op2)) {
|
|
|
|
/* $a += $a */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (result != op1) {
|
|
|
|
ZVAL_ARR(result, zend_array_dup(Z_ARR_P(op1)));
|
|
|
|
} else {
|
|
|
|
SEPARATE_ARRAY(result);
|
|
|
|
}
|
|
|
|
zend_hash_merge(Z_ARRVAL_P(result), Z_ARRVAL_P(op2), zval_add_ref, 0);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
static zend_always_inline int add_function_fast(zval *result, zval *op1, zval *op2) /* {{{ */
|
|
|
|
{
|
|
|
|
zend_uchar type_pair = TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2));
|
|
|
|
|
|
|
|
if (EXPECTED(type_pair == TYPE_PAIR(IS_LONG, IS_LONG))) {
|
|
|
|
fast_long_add_function(result, op1, op2);
|
|
|
|
return SUCCESS;
|
|
|
|
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_DOUBLE, IS_DOUBLE))) {
|
|
|
|
ZVAL_DOUBLE(result, Z_DVAL_P(op1) + Z_DVAL_P(op2));
|
|
|
|
return SUCCESS;
|
|
|
|
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_LONG, IS_DOUBLE))) {
|
|
|
|
ZVAL_DOUBLE(result, ((double)Z_LVAL_P(op1)) + Z_DVAL_P(op2));
|
|
|
|
return SUCCESS;
|
|
|
|
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_DOUBLE, IS_LONG))) {
|
|
|
|
ZVAL_DOUBLE(result, Z_DVAL_P(op1) + ((double)Z_LVAL_P(op2)));
|
|
|
|
return SUCCESS;
|
|
|
|
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_ARRAY, IS_ARRAY))) {
|
|
|
|
add_function_array(result, op1, op2);
|
|
|
|
return SUCCESS;
|
|
|
|
} else {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
static zend_never_inline int ZEND_FASTCALL add_function_slow(zval *result, zval *op1, zval *op2) /* {{{ */
|
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) {
|
2018-07-25 17:48:16 +08:00
|
|
|
if (Z_ISREF_P(op1)) {
|
|
|
|
op1 = Z_REFVAL_P(op1);
|
|
|
|
} else if (Z_ISREF_P(op2)) {
|
|
|
|
op2 = Z_REFVAL_P(op2);
|
|
|
|
} else if (!converted) {
|
|
|
|
ZEND_TRY_BINARY_OBJECT_OPERATION(ZEND_ADD, add_function);
|
|
|
|
|
|
|
|
if (EXPECTED(op1 != op2)) {
|
|
|
|
op1 = zendi_convert_scalar_to_number(op1, &op1_copy, result, 0);
|
|
|
|
op2 = zendi_convert_scalar_to_number(op2, &op2_copy, result, 0);
|
2018-01-10 20:12:03 +08:00
|
|
|
} else {
|
2018-07-25 17:48:16 +08:00
|
|
|
op1 = zendi_convert_scalar_to_number(op1, &op1_copy, result, 0);
|
|
|
|
op2 = op1;
|
2018-01-10 20:12:03 +08:00
|
|
|
}
|
2018-07-25 17:48:16 +08:00
|
|
|
if (EG(exception)) {
|
2018-01-10 20:12:03 +08:00
|
|
|
if (result != op1) {
|
|
|
|
ZVAL_UNDEF(result);
|
|
|
|
}
|
2018-07-25 17:48:16 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
converted = 1;
|
|
|
|
} else {
|
|
|
|
if (result != op1) {
|
|
|
|
ZVAL_UNDEF(result);
|
2018-01-10 20:12:03 +08:00
|
|
|
}
|
2018-07-25 17:48:16 +08:00
|
|
|
zend_throw_error(NULL, "Unsupported operand types");
|
|
|
|
return FAILURE; /* unknown datatype */
|
|
|
|
}
|
|
|
|
if (add_function_fast(result, op1, op2) == SUCCESS) {
|
|
|
|
return SUCCESS;
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
}
|
2018-07-25 17:48:16 +08:00
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
ZEND_API int ZEND_FASTCALL add_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
|
|
|
{
|
|
|
|
if (add_function_fast(result, op1, op2) == SUCCESS) {
|
|
|
|
return SUCCESS;
|
|
|
|
} else {
|
|
|
|
return add_function_slow(result, op1, op2);
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2018-07-25 17:48:16 +08:00
|
|
|
static zend_always_inline int sub_function_fast(zval *result, zval *op1, zval *op2) /* {{{ */
|
|
|
|
{
|
|
|
|
zend_uchar type_pair = TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2));
|
|
|
|
|
|
|
|
if (EXPECTED(type_pair == TYPE_PAIR(IS_LONG, IS_LONG))) {
|
|
|
|
fast_long_sub_function(result, op1, op2);
|
|
|
|
return SUCCESS;
|
|
|
|
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_DOUBLE, IS_DOUBLE))) {
|
|
|
|
ZVAL_DOUBLE(result, Z_DVAL_P(op1) - Z_DVAL_P(op2));
|
|
|
|
return SUCCESS;
|
|
|
|
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_LONG, IS_DOUBLE))) {
|
|
|
|
ZVAL_DOUBLE(result, ((double)Z_LVAL_P(op1)) - Z_DVAL_P(op2));
|
|
|
|
return SUCCESS;
|
|
|
|
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_DOUBLE, IS_LONG))) {
|
|
|
|
ZVAL_DOUBLE(result, Z_DVAL_P(op1) - ((double)Z_LVAL_P(op2)));
|
|
|
|
return SUCCESS;
|
|
|
|
} else {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
static zend_never_inline int ZEND_FASTCALL sub_function_slow(zval *result, zval *op1, zval *op2) /* {{{ */
|
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) {
|
2018-07-25 17:48:16 +08:00
|
|
|
if (Z_ISREF_P(op1)) {
|
|
|
|
op1 = Z_REFVAL_P(op1);
|
|
|
|
} else if (Z_ISREF_P(op2)) {
|
|
|
|
op2 = Z_REFVAL_P(op2);
|
|
|
|
} else if (!converted) {
|
|
|
|
ZEND_TRY_BINARY_OBJECT_OPERATION(ZEND_SUB, sub_function);
|
|
|
|
|
|
|
|
if (EXPECTED(op1 != op2)) {
|
|
|
|
op1 = zendi_convert_scalar_to_number(op1, &op1_copy, result, 0);
|
|
|
|
op2 = zendi_convert_scalar_to_number(op2, &op2_copy, result, 0);
|
2018-01-10 20:12:03 +08:00
|
|
|
} else {
|
2018-07-25 17:48:16 +08:00
|
|
|
op1 = zendi_convert_scalar_to_number(op1, &op1_copy, result, 0);
|
|
|
|
op2 = op1;
|
|
|
|
}
|
|
|
|
if (EG(exception)) {
|
2018-01-10 20:12:03 +08:00
|
|
|
if (result != op1) {
|
|
|
|
ZVAL_UNDEF(result);
|
|
|
|
}
|
2018-07-25 17:48:16 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
converted = 1;
|
|
|
|
} else {
|
|
|
|
if (result != op1) {
|
|
|
|
ZVAL_UNDEF(result);
|
2018-01-10 20:12:03 +08:00
|
|
|
}
|
2018-07-25 17:48:16 +08:00
|
|
|
zend_throw_error(NULL, "Unsupported operand types");
|
|
|
|
return FAILURE; /* unknown datatype */
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2018-07-25 17:48:16 +08:00
|
|
|
if (sub_function_fast(result, op1, op2) == SUCCESS) {
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
ZEND_API int ZEND_FASTCALL sub_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
|
|
|
{
|
|
|
|
if (sub_function_fast(result, op1, op2) == SUCCESS) {
|
|
|
|
return SUCCESS;
|
|
|
|
} else {
|
|
|
|
return sub_function_slow(result, op1, op2);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL mul_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
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) {
|
2018-01-10 20:12:03 +08:00
|
|
|
zend_uchar type_pair = TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2));
|
|
|
|
|
|
|
|
if (EXPECTED(type_pair == TYPE_PAIR(IS_LONG, IS_LONG))) {
|
|
|
|
zend_long overflow;
|
|
|
|
|
|
|
|
ZEND_SIGNED_MULTIPLY_LONG(Z_LVAL_P(op1),Z_LVAL_P(op2), Z_LVAL_P(result),Z_DVAL_P(result),overflow);
|
|
|
|
Z_TYPE_INFO_P(result) = overflow ? IS_DOUBLE : IS_LONG;
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_DOUBLE, IS_DOUBLE))) {
|
|
|
|
ZVAL_DOUBLE(result, Z_DVAL_P(op1) * Z_DVAL_P(op2));
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_LONG, IS_DOUBLE))) {
|
|
|
|
ZVAL_DOUBLE(result, ((double)Z_LVAL_P(op1)) * Z_DVAL_P(op2));
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_DOUBLE, IS_LONG))) {
|
|
|
|
ZVAL_DOUBLE(result, Z_DVAL_P(op1) * ((double)Z_LVAL_P(op2)));
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (Z_ISREF_P(op1)) {
|
|
|
|
op1 = Z_REFVAL_P(op1);
|
|
|
|
} else if (Z_ISREF_P(op2)) {
|
|
|
|
op2 = Z_REFVAL_P(op2);
|
|
|
|
} else if (!converted) {
|
|
|
|
ZEND_TRY_BINARY_OBJECT_OPERATION(ZEND_MUL, mul_function);
|
|
|
|
|
|
|
|
if (EXPECTED(op1 != op2)) {
|
2018-05-30 19:03:48 +08:00
|
|
|
op1 = zendi_convert_scalar_to_number(op1, &op1_copy, result, 0);
|
|
|
|
op2 = zendi_convert_scalar_to_number(op2, &op2_copy, result, 0);
|
2007-11-20 21:26:36 +08:00
|
|
|
} else {
|
2018-05-30 19:03:48 +08:00
|
|
|
op1 = zendi_convert_scalar_to_number(op1, &op1_copy, result, 0);
|
2018-01-10 20:12:03 +08:00
|
|
|
op2 = op1;
|
2007-11-20 21:26:36 +08:00
|
|
|
}
|
2018-05-30 19:03:48 +08:00
|
|
|
if (EG(exception)) {
|
|
|
|
if (result != op1) {
|
|
|
|
ZVAL_UNDEF(result);
|
|
|
|
}
|
|
|
|
return FAILURE;
|
|
|
|
}
|
2018-01-10 20:12:03 +08:00
|
|
|
converted = 1;
|
|
|
|
} else {
|
|
|
|
if (result != op1) {
|
|
|
|
ZVAL_UNDEF(result);
|
|
|
|
}
|
|
|
|
zend_throw_error(NULL, "Unsupported operand types");
|
|
|
|
return FAILURE; /* unknown datatype */
|
|
|
|
}
|
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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL pow_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
2013-11-19 15:36:06 +08:00
|
|
|
{
|
|
|
|
zval op1_copy, op2_copy;
|
|
|
|
int converted = 0;
|
|
|
|
|
|
|
|
while (1) {
|
2018-01-10 20:12:03 +08:00
|
|
|
zend_uchar type_pair = TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2));
|
2013-11-19 15:36:06 +08:00
|
|
|
|
2018-01-10 20:12:03 +08:00
|
|
|
if (EXPECTED(type_pair == TYPE_PAIR(IS_LONG, IS_LONG))) {
|
|
|
|
if (Z_LVAL_P(op2) >= 0) {
|
|
|
|
zend_long l1 = 1, l2 = Z_LVAL_P(op1), i = Z_LVAL_P(op2);
|
2013-11-19 15:36:06 +08:00
|
|
|
|
2018-01-10 20:12:03 +08:00
|
|
|
if (i == 0) {
|
|
|
|
ZVAL_LONG(result, 1L);
|
|
|
|
return SUCCESS;
|
|
|
|
} else if (l2 == 0) {
|
|
|
|
ZVAL_LONG(result, 0);
|
|
|
|
return SUCCESS;
|
2013-11-19 15:36:06 +08:00
|
|
|
}
|
|
|
|
|
2018-01-10 20:12:03 +08:00
|
|
|
while (i >= 1) {
|
|
|
|
zend_long overflow;
|
|
|
|
double dval = 0.0;
|
2013-11-19 15:36:06 +08:00
|
|
|
|
2018-01-10 20:12:03 +08:00
|
|
|
if (i % 2) {
|
|
|
|
--i;
|
|
|
|
ZEND_SIGNED_MULTIPLY_LONG(l1, l2, l1, dval, overflow);
|
|
|
|
if (overflow) {
|
|
|
|
ZVAL_DOUBLE(result, dval * pow(l2, i));
|
2017-02-12 20:34:08 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2013-11-19 15:36:06 +08:00
|
|
|
} else {
|
2018-01-10 20:12:03 +08:00
|
|
|
i /= 2;
|
|
|
|
ZEND_SIGNED_MULTIPLY_LONG(l2, l2, l2, dval, overflow);
|
|
|
|
if (overflow) {
|
|
|
|
ZVAL_DOUBLE(result, (double)l1 * pow(dval, i));
|
2017-02-12 20:34:08 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2013-11-19 15:36:06 +08:00
|
|
|
}
|
2018-01-10 20:12:03 +08:00
|
|
|
}
|
|
|
|
/* i == 0 */
|
|
|
|
ZVAL_LONG(result, l1);
|
|
|
|
} else {
|
|
|
|
ZVAL_DOUBLE(result, pow((double)Z_LVAL_P(op1), (double)Z_LVAL_P(op2)));
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_DOUBLE, IS_DOUBLE))) {
|
|
|
|
ZVAL_DOUBLE(result, pow(Z_DVAL_P(op1), Z_DVAL_P(op2)));
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_LONG, IS_DOUBLE))) {
|
|
|
|
ZVAL_DOUBLE(result, pow((double)Z_LVAL_P(op1), Z_DVAL_P(op2)));
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_DOUBLE, IS_LONG))) {
|
|
|
|
ZVAL_DOUBLE(result, pow(Z_DVAL_P(op1), (double)Z_LVAL_P(op2)));
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (Z_ISREF_P(op1)) {
|
|
|
|
op1 = Z_REFVAL_P(op1);
|
|
|
|
} else if (Z_ISREF_P(op2)) {
|
|
|
|
op2 = Z_REFVAL_P(op2);
|
|
|
|
} else if (!converted) {
|
|
|
|
ZEND_TRY_BINARY_OBJECT_OPERATION(ZEND_POW, pow_function);
|
|
|
|
|
|
|
|
if (EXPECTED(op1 != op2)) {
|
|
|
|
if (Z_TYPE_P(op1) == IS_ARRAY) {
|
2019-09-26 19:47:19 +08:00
|
|
|
if (op1 == result) {
|
|
|
|
zval_ptr_dtor(result);
|
2017-02-12 20:34:08 +08:00
|
|
|
}
|
2018-01-10 20:12:03 +08:00
|
|
|
ZVAL_LONG(result, 0);
|
|
|
|
return SUCCESS;
|
|
|
|
} else {
|
2018-05-30 19:03:48 +08:00
|
|
|
op1 = zendi_convert_scalar_to_number(op1, &op1_copy, result, 0);
|
2018-01-10 20:12:03 +08:00
|
|
|
}
|
|
|
|
if (Z_TYPE_P(op2) == IS_ARRAY) {
|
2019-09-26 19:47:19 +08:00
|
|
|
if (op1 == result) {
|
|
|
|
zval_ptr_dtor(result);
|
2017-02-12 20:34:08 +08:00
|
|
|
}
|
2018-01-10 20:12:03 +08:00
|
|
|
ZVAL_LONG(result, 1L);
|
|
|
|
return SUCCESS;
|
|
|
|
} else {
|
2018-05-30 19:03:48 +08:00
|
|
|
op2 = zendi_convert_scalar_to_number(op2, &op2_copy, result, 0);
|
2018-01-10 20:12:03 +08:00
|
|
|
}
|
2013-11-19 15:36:06 +08:00
|
|
|
} else {
|
2018-01-10 20:12:03 +08:00
|
|
|
if (Z_TYPE_P(op1) == IS_ARRAY) {
|
2019-09-26 19:47:19 +08:00
|
|
|
if (op1 == result) {
|
|
|
|
zval_ptr_dtor(result);
|
|
|
|
}
|
2018-01-10 20:12:03 +08:00
|
|
|
ZVAL_LONG(result, 0);
|
|
|
|
return SUCCESS;
|
|
|
|
} else {
|
2018-05-30 19:03:48 +08:00
|
|
|
op1 = zendi_convert_scalar_to_number(op1, &op1_copy, result, 0);
|
2016-12-07 05:41:07 +08:00
|
|
|
}
|
2018-01-10 20:12:03 +08:00
|
|
|
op2 = op1;
|
|
|
|
}
|
2018-05-30 19:03:48 +08:00
|
|
|
if (EG(exception)) {
|
|
|
|
if (result != op1) {
|
|
|
|
ZVAL_UNDEF(result);
|
|
|
|
}
|
|
|
|
return FAILURE;
|
|
|
|
}
|
2018-01-10 20:12:03 +08:00
|
|
|
converted = 1;
|
|
|
|
} else {
|
|
|
|
if (result != op1) {
|
|
|
|
ZVAL_UNDEF(result);
|
2013-11-19 15:36:06 +08:00
|
|
|
}
|
2018-01-10 20:12:03 +08:00
|
|
|
zend_throw_error(NULL, "Unsupported operand types");
|
|
|
|
return FAILURE;
|
|
|
|
}
|
2013-11-19 15:36:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-24 21:19:34 +08:00
|
|
|
/* }}} */
|
2013-11-19 15:36:06 +08:00
|
|
|
|
2019-06-20 18:11:30 +08:00
|
|
|
#ifdef __clang__
|
|
|
|
__attribute__((no_sanitize("float-divide-by-zero")))
|
|
|
|
#endif
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL div_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
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) {
|
2018-01-10 20:12:03 +08:00
|
|
|
zend_uchar type_pair = TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2));
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2018-01-10 20:12:03 +08:00
|
|
|
if (EXPECTED(type_pair == TYPE_PAIR(IS_LONG, IS_LONG))) {
|
|
|
|
if (Z_LVAL_P(op2) == 0) {
|
|
|
|
zend_error(E_WARNING, "Division by zero");
|
|
|
|
ZVAL_DOUBLE(result, ((double) Z_LVAL_P(op1) / (double) Z_LVAL_P(op2)));
|
2007-11-20 21:26:36 +08:00
|
|
|
return SUCCESS;
|
2018-01-10 20:12:03 +08:00
|
|
|
} else if (Z_LVAL_P(op2) == -1 && Z_LVAL_P(op1) == ZEND_LONG_MIN) {
|
|
|
|
/* Prevent overflow error/crash */
|
|
|
|
ZVAL_DOUBLE(result, (double) ZEND_LONG_MIN / -1);
|
2007-11-20 21:26:36 +08:00
|
|
|
return SUCCESS;
|
2018-01-10 20:12:03 +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;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2018-01-10 20:12:03 +08:00
|
|
|
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_DOUBLE, IS_DOUBLE))) {
|
|
|
|
if (Z_DVAL_P(op2) == 0) {
|
|
|
|
zend_error(E_WARNING, "Division by zero");
|
|
|
|
}
|
|
|
|
ZVAL_DOUBLE(result, Z_DVAL_P(op1) / Z_DVAL_P(op2));
|
|
|
|
return SUCCESS;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2018-01-10 20:12:03 +08:00
|
|
|
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_DOUBLE, IS_LONG))) {
|
|
|
|
if (Z_LVAL_P(op2) == 0) {
|
|
|
|
zend_error(E_WARNING, "Division by zero");
|
|
|
|
}
|
|
|
|
ZVAL_DOUBLE(result, Z_DVAL_P(op1) / (double)Z_LVAL_P(op2));
|
|
|
|
return SUCCESS;
|
2013-06-17 23:48:13 +08:00
|
|
|
|
2018-01-10 20:12:03 +08:00
|
|
|
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_LONG, IS_DOUBLE))) {
|
|
|
|
if (Z_DVAL_P(op2) == 0) {
|
|
|
|
zend_error(E_WARNING, "Division by zero");
|
|
|
|
}
|
|
|
|
ZVAL_DOUBLE(result, (double)Z_LVAL_P(op1) / Z_DVAL_P(op2));
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (Z_ISREF_P(op1)) {
|
|
|
|
op1 = Z_REFVAL_P(op1);
|
|
|
|
} else if (Z_ISREF_P(op2)) {
|
|
|
|
op2 = Z_REFVAL_P(op2);
|
|
|
|
} else if (!converted) {
|
|
|
|
ZEND_TRY_BINARY_OBJECT_OPERATION(ZEND_DIV, div_function);
|
|
|
|
|
|
|
|
if (EXPECTED(op1 != op2)) {
|
2018-05-30 19:03:48 +08:00
|
|
|
op1 = zendi_convert_scalar_to_number(op1, &op1_copy, result, 0);
|
|
|
|
op2 = zendi_convert_scalar_to_number(op2, &op2_copy, result, 0);
|
2007-11-20 21:26:36 +08:00
|
|
|
} else {
|
2018-05-30 19:03:48 +08:00
|
|
|
op1 = zendi_convert_scalar_to_number(op1, &op1_copy, result, 0);
|
2018-01-10 20:12:03 +08:00
|
|
|
op2 = op1;
|
2007-11-20 21:26:36 +08:00
|
|
|
}
|
2018-05-30 19:03:48 +08:00
|
|
|
if (EG(exception)) {
|
|
|
|
if (result != op1) {
|
|
|
|
ZVAL_UNDEF(result);
|
|
|
|
}
|
|
|
|
return FAILURE;
|
|
|
|
}
|
2018-01-10 20:12:03 +08:00
|
|
|
converted = 1;
|
|
|
|
} else {
|
|
|
|
if (result != op1) {
|
|
|
|
ZVAL_UNDEF(result);
|
|
|
|
}
|
|
|
|
zend_throw_error(NULL, "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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL mod_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2014-12-11 20:01:06 +08:00
|
|
|
zend_long op1_lval, op2_lval;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2016-12-07 05:41:07 +08:00
|
|
|
convert_op1_op2_long(op1, op1_lval, op2, op2_lval, result, ZEND_MOD, mod_function);
|
2015-01-08 06:21:12 +08:00
|
|
|
|
2015-06-29 17:20:09 +08:00
|
|
|
if (op2_lval == 0) {
|
2015-04-06 19:30:05 +08:00
|
|
|
/* modulus by zero */
|
|
|
|
if (EG(current_execute_data) && !CG(in_compilation)) {
|
2015-07-02 07:54:08 +08:00
|
|
|
zend_throw_exception_ex(zend_ce_division_by_zero_error, 0, "Modulo by zero");
|
2015-04-06 19:30:05 +08:00
|
|
|
} else {
|
2015-07-03 02:47:44 +08:00
|
|
|
zend_error_noreturn(E_ERROR, "Modulo by zero");
|
2015-04-06 19:30:05 +08:00
|
|
|
}
|
2016-12-02 18:58:44 +08:00
|
|
|
if (op1 != result) {
|
|
|
|
ZVAL_UNDEF(result);
|
|
|
|
}
|
2015-04-06 19:30:05 +08:00
|
|
|
return FAILURE;
|
2015-06-29 17:20:09 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 18:58:44 +08:00
|
|
|
if (op1 == result) {
|
2018-07-05 04:48:39 +08:00
|
|
|
zval_ptr_dtor(result);
|
2016-12-02 18:58:44 +08:00
|
|
|
}
|
|
|
|
|
2015-06-29 17:20:09 +08:00
|
|
|
if (op2_lval == -1) {
|
|
|
|
/* Prevent overflow error/crash if op1==LONG_MIN */
|
2004-02-23 04:02:26 +08:00
|
|
|
ZVAL_LONG(result, 0);
|
2015-06-29 17:20:09 +08:00
|
|
|
return SUCCESS;
|
2004-02-23 04:02:26 +08:00
|
|
|
}
|
2015-06-29 17:20:09 +08:00
|
|
|
|
|
|
|
ZVAL_LONG(result, op1_lval % op2_lval);
|
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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL boolean_xor_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2014-12-06 07:14:45 +08:00
|
|
|
int op1_val, op2_val;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2014-12-06 07:14:45 +08:00
|
|
|
do {
|
|
|
|
if (Z_TYPE_P(op1) == IS_FALSE) {
|
|
|
|
op1_val = 0;
|
|
|
|
} else if (EXPECTED(Z_TYPE_P(op1) == IS_TRUE)) {
|
|
|
|
op1_val = 1;
|
|
|
|
} else {
|
|
|
|
if (Z_ISREF_P(op1)) {
|
|
|
|
op1 = Z_REFVAL_P(op1);
|
|
|
|
if (Z_TYPE_P(op1) == IS_FALSE) {
|
|
|
|
op1_val = 0;
|
|
|
|
break;
|
|
|
|
} else if (EXPECTED(Z_TYPE_P(op1) == IS_TRUE)) {
|
|
|
|
op1_val = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ZEND_TRY_BINARY_OP1_OBJECT_OPERATION(ZEND_BOOL_XOR, boolean_xor_function);
|
2014-12-11 18:18:40 +08:00
|
|
|
op1_val = zval_is_true(op1);
|
2014-12-06 07:14:45 +08:00
|
|
|
}
|
|
|
|
} while (0);
|
|
|
|
do {
|
|
|
|
if (Z_TYPE_P(op2) == IS_FALSE) {
|
|
|
|
op2_val = 0;
|
|
|
|
} else if (EXPECTED(Z_TYPE_P(op2) == IS_TRUE)) {
|
|
|
|
op2_val = 1;
|
|
|
|
} else {
|
|
|
|
if (Z_ISREF_P(op2)) {
|
|
|
|
op2 = Z_REFVAL_P(op2);
|
|
|
|
if (Z_TYPE_P(op2) == IS_FALSE) {
|
|
|
|
op2_val = 0;
|
|
|
|
break;
|
|
|
|
} else if (EXPECTED(Z_TYPE_P(op2) == IS_TRUE)) {
|
|
|
|
op2_val = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ZEND_TRY_BINARY_OP2_OBJECT_OPERATION(ZEND_BOOL_XOR);
|
2014-12-11 18:18:40 +08:00
|
|
|
op2_val = zval_is_true(op2);
|
2014-12-06 07:14:45 +08:00
|
|
|
}
|
|
|
|
} while (0);
|
2013-06-17 23:48:13 +08:00
|
|
|
|
2014-12-06 07:14:45 +08:00
|
|
|
ZVAL_BOOL(result, op1_val ^ op2_val);
|
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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL boolean_not_function(zval *result, zval *op1) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2014-12-06 07:14:45 +08:00
|
|
|
if (Z_TYPE_P(op1) < IS_TRUE) {
|
2014-04-30 22:32:42 +08:00
|
|
|
ZVAL_TRUE(result);
|
2014-12-06 07:14:45 +08:00
|
|
|
} else if (EXPECTED(Z_TYPE_P(op1) == IS_TRUE)) {
|
2014-04-30 22:32:42 +08:00
|
|
|
ZVAL_FALSE(result);
|
|
|
|
} else {
|
2014-12-06 07:14:45 +08:00
|
|
|
if (Z_ISREF_P(op1)) {
|
|
|
|
op1 = Z_REFVAL_P(op1);
|
|
|
|
if (Z_TYPE_P(op1) < IS_TRUE) {
|
|
|
|
ZVAL_TRUE(result);
|
|
|
|
return SUCCESS;
|
|
|
|
} else if (EXPECTED(Z_TYPE_P(op1) == IS_TRUE)) {
|
|
|
|
ZVAL_FALSE(result);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2013-06-17 23:48:13 +08:00
|
|
|
ZEND_TRY_UNARY_OBJECT_OPERATION(ZEND_BOOL_NOT);
|
|
|
|
|
2014-12-11 18:18:40 +08:00
|
|
|
ZVAL_BOOL(result, !zval_is_true(op1));
|
2014-04-30 22:32:42 +08:00
|
|
|
}
|
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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL bitwise_not_function(zval *result, zval *op1) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2014-12-06 07:14:45 +08:00
|
|
|
try_again:
|
2013-06-17 23:48:13 +08:00
|
|
|
switch (Z_TYPE_P(op1)) {
|
|
|
|
case IS_LONG:
|
|
|
|
ZVAL_LONG(result, ~Z_LVAL_P(op1));
|
|
|
|
return SUCCESS;
|
|
|
|
case IS_DOUBLE:
|
|
|
|
ZVAL_LONG(result, ~zend_dval_to_lval(Z_DVAL_P(op1)));
|
|
|
|
return SUCCESS;
|
|
|
|
case IS_STRING: {
|
2014-08-26 01:24:55 +08:00
|
|
|
size_t i;
|
2013-06-17 23:48:13 +08:00
|
|
|
|
2015-06-03 08:57:16 +08:00
|
|
|
if (Z_STRLEN_P(op1) == 1) {
|
|
|
|
zend_uchar not = (zend_uchar) ~*Z_STRVAL_P(op1);
|
2017-03-04 17:39:13 +08:00
|
|
|
ZVAL_INTERNED_STR(result, ZSTR_CHAR(not));
|
2015-06-03 08:57:16 +08:00
|
|
|
} else {
|
|
|
|
ZVAL_NEW_STR(result, zend_string_alloc(Z_STRLEN_P(op1), 0));
|
|
|
|
for (i = 0; i < Z_STRLEN_P(op1); i++) {
|
|
|
|
Z_STRVAL_P(result)[i] = ~Z_STRVAL_P(op1)[i];
|
|
|
|
}
|
|
|
|
Z_STRVAL_P(result)[i] = 0;
|
2013-06-17 23:48:13 +08:00
|
|
|
}
|
|
|
|
return SUCCESS;
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2014-12-06 07:14:45 +08:00
|
|
|
case IS_REFERENCE:
|
|
|
|
op1 = Z_REFVAL_P(op1);
|
|
|
|
goto try_again;
|
2013-06-17 23:48:13 +08:00
|
|
|
default:
|
|
|
|
ZEND_TRY_UNARY_OBJECT_OPERATION(ZEND_BW_NOT);
|
|
|
|
|
2016-12-07 05:41:07 +08:00
|
|
|
if (result != op1) {
|
|
|
|
ZVAL_UNDEF(result);
|
|
|
|
}
|
2015-07-08 01:10:22 +08:00
|
|
|
zend_throw_error(NULL, "Unsupported operand types");
|
2013-06-17 23:48:13 +08:00
|
|
|
return FAILURE;
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL bitwise_or_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2014-12-11 20:01:06 +08:00
|
|
|
zend_long op1_lval, op2_lval;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2014-12-06 07:14:45 +08:00
|
|
|
if (EXPECTED(Z_TYPE_P(op1) == IS_LONG) && EXPECTED(Z_TYPE_P(op2) == IS_LONG)) {
|
|
|
|
ZVAL_LONG(result, Z_LVAL_P(op1) | Z_LVAL_P(op2));
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-12-06 07:14:45 +08:00
|
|
|
ZVAL_DEREF(op1);
|
|
|
|
ZVAL_DEREF(op2);
|
|
|
|
|
2015-06-03 08:57:16 +08:00
|
|
|
if (Z_TYPE_P(op1) == IS_STRING && EXPECTED(Z_TYPE_P(op2) == IS_STRING)) {
|
1999-04-08 02:10:10 +08:00
|
|
|
zval *longer, *shorter;
|
2014-02-10 14:04:30 +08:00
|
|
|
zend_string *str;
|
2014-08-26 01:24:55 +08:00
|
|
|
size_t i;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2015-06-03 08:57:16 +08:00
|
|
|
if (EXPECTED(Z_STRLEN_P(op1) >= Z_STRLEN_P(op2))) {
|
|
|
|
if (EXPECTED(Z_STRLEN_P(op1) == Z_STRLEN_P(op2)) && Z_STRLEN_P(op1) == 1) {
|
|
|
|
zend_uchar or = (zend_uchar) (*Z_STRVAL_P(op1) | *Z_STRVAL_P(op2));
|
2016-12-02 17:34:46 +08:00
|
|
|
if (result==op1) {
|
2018-07-04 17:08:07 +08:00
|
|
|
zval_ptr_dtor_str(result);
|
2016-12-02 17:34:46 +08:00
|
|
|
}
|
2017-03-04 17:39:13 +08:00
|
|
|
ZVAL_INTERNED_STR(result, ZSTR_CHAR(or));
|
2015-06-03 08:57:16 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
longer = op1;
|
|
|
|
shorter = op2;
|
|
|
|
} else {
|
|
|
|
longer = op2;
|
|
|
|
shorter = op1;
|
|
|
|
}
|
|
|
|
|
2014-08-26 01:24:55 +08:00
|
|
|
str = zend_string_alloc(Z_STRLEN_P(longer), 0);
|
2007-11-20 21:26:36 +08:00
|
|
|
for (i = 0; i < Z_STRLEN_P(shorter); i++) {
|
2015-06-30 18:59:27 +08:00
|
|
|
ZSTR_VAL(str)[i] = Z_STRVAL_P(longer)[i] | Z_STRVAL_P(shorter)[i];
|
2000-04-13 23:56:02 +08:00
|
|
|
}
|
2015-06-30 18:59:27 +08:00
|
|
|
memcpy(ZSTR_VAL(str) + i, Z_STRVAL_P(longer) + i, Z_STRLEN_P(longer) - i + 1);
|
2000-04-13 23:56:02 +08:00
|
|
|
if (result==op1) {
|
2018-07-04 17:08:07 +08:00
|
|
|
zval_ptr_dtor_str(result);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2014-04-03 19:26:23 +08:00
|
|
|
ZVAL_NEW_STR(result, str);
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2013-06-17 23:48:13 +08:00
|
|
|
|
2014-10-21 07:24:20 +08:00
|
|
|
if (UNEXPECTED(Z_TYPE_P(op1) != IS_LONG)) {
|
|
|
|
ZEND_TRY_BINARY_OP1_OBJECT_OPERATION(ZEND_BW_OR, bitwise_or_function);
|
2016-03-30 08:44:27 +08:00
|
|
|
op1_lval = _zval_get_long_func_noisy(op1);
|
2016-12-06 02:45:08 +08:00
|
|
|
if (UNEXPECTED(EG(exception))) {
|
2016-12-07 05:41:07 +08:00
|
|
|
if (result != op1) {
|
|
|
|
ZVAL_UNDEF(result);
|
|
|
|
}
|
2016-12-06 02:45:08 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2014-12-11 20:01:06 +08:00
|
|
|
} else {
|
|
|
|
op1_lval = Z_LVAL_P(op1);
|
2014-10-21 07:24:20 +08:00
|
|
|
}
|
|
|
|
if (UNEXPECTED(Z_TYPE_P(op2) != IS_LONG)) {
|
|
|
|
ZEND_TRY_BINARY_OP2_OBJECT_OPERATION(ZEND_BW_OR);
|
2016-03-30 08:44:27 +08:00
|
|
|
op2_lval = _zval_get_long_func_noisy(op2);
|
2016-12-06 02:45:08 +08:00
|
|
|
if (UNEXPECTED(EG(exception))) {
|
2016-12-07 05:41:07 +08:00
|
|
|
if (result != op1) {
|
|
|
|
ZVAL_UNDEF(result);
|
|
|
|
}
|
2016-12-06 02:45:08 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2014-12-11 20:01:06 +08:00
|
|
|
} else {
|
|
|
|
op2_lval = Z_LVAL_P(op2);
|
2013-06-17 23:48:13 +08:00
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2014-12-14 05:11:09 +08:00
|
|
|
if (op1 == result) {
|
2018-07-05 04:48:39 +08:00
|
|
|
zval_ptr_dtor(result);
|
2014-12-14 05:11:09 +08:00
|
|
|
}
|
2014-12-11 20:01:06 +08:00
|
|
|
ZVAL_LONG(result, op1_lval | op2_lval);
|
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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL bitwise_and_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2014-12-11 20:01:06 +08:00
|
|
|
zend_long op1_lval, op2_lval;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2014-12-06 07:14:45 +08:00
|
|
|
if (EXPECTED(Z_TYPE_P(op1) == IS_LONG) && EXPECTED(Z_TYPE_P(op2) == IS_LONG)) {
|
|
|
|
ZVAL_LONG(result, Z_LVAL_P(op1) & Z_LVAL_P(op2));
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-12-06 07:14:45 +08:00
|
|
|
ZVAL_DEREF(op1);
|
|
|
|
ZVAL_DEREF(op2);
|
|
|
|
|
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;
|
2014-02-10 14:04:30 +08:00
|
|
|
zend_string *str;
|
2014-08-26 01:24:55 +08:00
|
|
|
size_t i;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2015-06-03 08:57:16 +08:00
|
|
|
if (EXPECTED(Z_STRLEN_P(op1) >= Z_STRLEN_P(op2))) {
|
|
|
|
if (EXPECTED(Z_STRLEN_P(op1) == Z_STRLEN_P(op2)) && Z_STRLEN_P(op1) == 1) {
|
|
|
|
zend_uchar and = (zend_uchar) (*Z_STRVAL_P(op1) & *Z_STRVAL_P(op2));
|
2016-12-02 17:34:46 +08:00
|
|
|
if (result==op1) {
|
2018-07-04 17:08:07 +08:00
|
|
|
zval_ptr_dtor_str(result);
|
2016-12-02 17:34:46 +08:00
|
|
|
}
|
2017-03-04 17:39:13 +08:00
|
|
|
ZVAL_INTERNED_STR(result, ZSTR_CHAR(and));
|
2015-06-03 08:57:16 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
longer = op1;
|
|
|
|
shorter = op2;
|
|
|
|
} else {
|
|
|
|
longer = op2;
|
|
|
|
shorter = op1;
|
|
|
|
}
|
|
|
|
|
2014-08-26 01:24:55 +08:00
|
|
|
str = zend_string_alloc(Z_STRLEN_P(shorter), 0);
|
2007-11-20 21:26:36 +08:00
|
|
|
for (i = 0; i < Z_STRLEN_P(shorter); i++) {
|
2015-06-30 18:59:27 +08:00
|
|
|
ZSTR_VAL(str)[i] = Z_STRVAL_P(shorter)[i] & Z_STRVAL_P(longer)[i];
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2015-06-30 18:59:27 +08:00
|
|
|
ZSTR_VAL(str)[i] = 0;
|
2000-04-13 23:56:02 +08:00
|
|
|
if (result==op1) {
|
2018-07-04 17:08:07 +08:00
|
|
|
zval_ptr_dtor_str(result);
|
2000-04-13 23:56:02 +08:00
|
|
|
}
|
2014-04-03 19:26:23 +08:00
|
|
|
ZVAL_NEW_STR(result, str);
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2014-10-21 07:24:20 +08:00
|
|
|
if (UNEXPECTED(Z_TYPE_P(op1) != IS_LONG)) {
|
2015-06-04 22:09:22 +08:00
|
|
|
ZEND_TRY_BINARY_OP1_OBJECT_OPERATION(ZEND_BW_AND, bitwise_and_function);
|
2016-03-30 08:44:27 +08:00
|
|
|
op1_lval = _zval_get_long_func_noisy(op1);
|
2016-12-06 02:45:08 +08:00
|
|
|
if (UNEXPECTED(EG(exception))) {
|
2016-12-07 05:41:07 +08:00
|
|
|
if (result != op1) {
|
|
|
|
ZVAL_UNDEF(result);
|
|
|
|
}
|
2016-12-06 02:45:08 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2014-12-11 20:01:06 +08:00
|
|
|
} else {
|
|
|
|
op1_lval = Z_LVAL_P(op1);
|
2014-10-21 07:24:20 +08:00
|
|
|
}
|
|
|
|
if (UNEXPECTED(Z_TYPE_P(op2) != IS_LONG)) {
|
|
|
|
ZEND_TRY_BINARY_OP2_OBJECT_OPERATION(ZEND_BW_AND);
|
2016-03-30 08:44:27 +08:00
|
|
|
op2_lval = _zval_get_long_func_noisy(op2);
|
2016-12-06 02:45:08 +08:00
|
|
|
if (UNEXPECTED(EG(exception))) {
|
2016-12-07 05:41:07 +08:00
|
|
|
if (result != op1) {
|
|
|
|
ZVAL_UNDEF(result);
|
|
|
|
}
|
2016-12-06 02:45:08 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2014-12-11 20:01:06 +08:00
|
|
|
} else {
|
|
|
|
op2_lval = Z_LVAL_P(op2);
|
2013-06-17 23:48:13 +08:00
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2014-12-14 05:11:09 +08:00
|
|
|
if (op1 == result) {
|
2018-07-05 04:48:39 +08:00
|
|
|
zval_ptr_dtor(result);
|
2014-12-14 05:11:09 +08:00
|
|
|
}
|
2014-12-11 20:01:06 +08:00
|
|
|
ZVAL_LONG(result, op1_lval & op2_lval);
|
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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL bitwise_xor_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2014-12-11 20:01:06 +08:00
|
|
|
zend_long op1_lval, op2_lval;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2014-12-06 07:14:45 +08:00
|
|
|
if (EXPECTED(Z_TYPE_P(op1) == IS_LONG) && EXPECTED(Z_TYPE_P(op2) == IS_LONG)) {
|
|
|
|
ZVAL_LONG(result, Z_LVAL_P(op1) ^ Z_LVAL_P(op2));
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-12-06 07:14:45 +08:00
|
|
|
ZVAL_DEREF(op1);
|
|
|
|
ZVAL_DEREF(op2);
|
|
|
|
|
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;
|
2014-02-10 14:04:30 +08:00
|
|
|
zend_string *str;
|
2014-08-26 01:24:55 +08:00
|
|
|
size_t i;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2015-06-03 08:57:16 +08:00
|
|
|
if (EXPECTED(Z_STRLEN_P(op1) >= Z_STRLEN_P(op2))) {
|
|
|
|
if (EXPECTED(Z_STRLEN_P(op1) == Z_STRLEN_P(op2)) && Z_STRLEN_P(op1) == 1) {
|
|
|
|
zend_uchar xor = (zend_uchar) (*Z_STRVAL_P(op1) ^ *Z_STRVAL_P(op2));
|
2016-12-02 17:34:46 +08:00
|
|
|
if (result==op1) {
|
2018-07-04 17:08:07 +08:00
|
|
|
zval_ptr_dtor_str(result);
|
2016-12-02 17:34:46 +08:00
|
|
|
}
|
2017-03-04 17:39:13 +08:00
|
|
|
ZVAL_INTERNED_STR(result, ZSTR_CHAR(xor));
|
2015-06-03 08:57:16 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
longer = op1;
|
|
|
|
shorter = op2;
|
|
|
|
} else {
|
|
|
|
longer = op2;
|
|
|
|
shorter = op1;
|
|
|
|
}
|
|
|
|
|
2014-08-26 01:24:55 +08:00
|
|
|
str = zend_string_alloc(Z_STRLEN_P(shorter), 0);
|
2007-11-20 21:26:36 +08:00
|
|
|
for (i = 0; i < Z_STRLEN_P(shorter); i++) {
|
2015-06-30 18:59:27 +08:00
|
|
|
ZSTR_VAL(str)[i] = Z_STRVAL_P(shorter)[i] ^ Z_STRVAL_P(longer)[i];
|
2000-04-13 23:56:02 +08:00
|
|
|
}
|
2015-06-30 18:59:27 +08:00
|
|
|
ZSTR_VAL(str)[i] = 0;
|
2000-04-13 23:56:02 +08:00
|
|
|
if (result==op1) {
|
2018-07-04 17:08:07 +08:00
|
|
|
zval_ptr_dtor_str(result);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
2014-04-03 19:26:23 +08:00
|
|
|
ZVAL_NEW_STR(result, str);
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-10-21 07:24:20 +08:00
|
|
|
if (UNEXPECTED(Z_TYPE_P(op1) != IS_LONG)) {
|
2015-06-04 22:09:22 +08:00
|
|
|
ZEND_TRY_BINARY_OP1_OBJECT_OPERATION(ZEND_BW_XOR, bitwise_xor_function);
|
2016-03-30 08:44:27 +08:00
|
|
|
op1_lval = _zval_get_long_func_noisy(op1);
|
2016-12-06 02:45:08 +08:00
|
|
|
if (UNEXPECTED(EG(exception))) {
|
2016-12-07 05:41:07 +08:00
|
|
|
if (result != op1) {
|
|
|
|
ZVAL_UNDEF(result);
|
|
|
|
}
|
2016-12-06 02:45:08 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2014-12-11 20:01:06 +08:00
|
|
|
} else {
|
|
|
|
op1_lval = Z_LVAL_P(op1);
|
2014-10-21 07:24:20 +08:00
|
|
|
}
|
|
|
|
if (UNEXPECTED(Z_TYPE_P(op2) != IS_LONG)) {
|
|
|
|
ZEND_TRY_BINARY_OP2_OBJECT_OPERATION(ZEND_BW_XOR);
|
2016-03-30 08:44:27 +08:00
|
|
|
op2_lval = _zval_get_long_func_noisy(op2);
|
2016-12-06 02:45:08 +08:00
|
|
|
if (UNEXPECTED(EG(exception))) {
|
2016-12-07 05:41:07 +08:00
|
|
|
if (result != op1) {
|
|
|
|
ZVAL_UNDEF(result);
|
|
|
|
}
|
2016-12-06 02:45:08 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2014-12-11 20:01:06 +08:00
|
|
|
} else {
|
|
|
|
op2_lval = Z_LVAL_P(op2);
|
2013-06-17 23:48:13 +08:00
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2014-12-14 05:11:09 +08:00
|
|
|
if (op1 == result) {
|
2018-07-05 04:48:39 +08:00
|
|
|
zval_ptr_dtor(result);
|
2014-12-14 05:11:09 +08:00
|
|
|
}
|
2014-12-11 20:01:06 +08:00
|
|
|
ZVAL_LONG(result, op1_lval ^ op2_lval);
|
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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL shift_left_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2014-12-11 20:01:06 +08:00
|
|
|
zend_long op1_lval, op2_lval;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2016-12-07 05:41:07 +08:00
|
|
|
convert_op1_op2_long(op1, op1_lval, op2, op2_lval, result, ZEND_SL, shift_left_function);
|
2013-06-17 23:48:13 +08:00
|
|
|
|
2014-08-20 03:00:40 +08:00
|
|
|
/* prevent wrapping quirkiness on some processors where << 64 + x == << x */
|
2014-12-11 20:01:06 +08:00
|
|
|
if (UNEXPECTED((zend_ulong)op2_lval >= SIZEOF_ZEND_LONG * 8)) {
|
|
|
|
if (EXPECTED(op2_lval > 0)) {
|
2016-12-02 18:58:44 +08:00
|
|
|
if (op1 == result) {
|
2018-07-05 04:48:39 +08:00
|
|
|
zval_ptr_dtor(result);
|
2016-12-02 18:58:44 +08:00
|
|
|
}
|
2014-12-11 20:01:06 +08:00
|
|
|
ZVAL_LONG(result, 0);
|
|
|
|
return SUCCESS;
|
|
|
|
} else {
|
2015-04-06 19:30:05 +08:00
|
|
|
if (EG(current_execute_data) && !CG(in_compilation)) {
|
2015-07-03 02:47:44 +08:00
|
|
|
zend_throw_exception_ex(zend_ce_arithmetic_error, 0, "Bit shift by negative number");
|
2015-04-06 19:30:05 +08:00
|
|
|
} else {
|
|
|
|
zend_error_noreturn(E_ERROR, "Bit shift by negative number");
|
|
|
|
}
|
2016-12-02 18:58:44 +08:00
|
|
|
if (op1 != result) {
|
|
|
|
ZVAL_UNDEF(result);
|
|
|
|
}
|
2014-12-11 20:01:06 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2014-08-16 00:29:26 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 18:58:44 +08:00
|
|
|
if (op1 == result) {
|
2018-07-05 04:48:39 +08:00
|
|
|
zval_ptr_dtor(result);
|
2016-12-02 18:58:44 +08:00
|
|
|
}
|
|
|
|
|
2019-06-19 18:59:18 +08:00
|
|
|
/* Perform shift on unsigned numbers to get well-defined wrap behavior. */
|
|
|
|
ZVAL_LONG(result, (zend_long) ((zend_ulong) op1_lval << op2_lval));
|
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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL shift_right_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2014-12-11 20:01:06 +08:00
|
|
|
zend_long op1_lval, op2_lval;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2016-12-07 05:41:07 +08:00
|
|
|
convert_op1_op2_long(op1, op1_lval, op2, op2_lval, result, ZEND_SR, shift_right_function);
|
2013-06-17 23:48:13 +08:00
|
|
|
|
2014-08-16 07:54:37 +08:00
|
|
|
/* prevent wrapping quirkiness on some processors where >> 64 + x == >> x */
|
2014-12-11 20:01:06 +08:00
|
|
|
if (UNEXPECTED((zend_ulong)op2_lval >= SIZEOF_ZEND_LONG * 8)) {
|
|
|
|
if (EXPECTED(op2_lval > 0)) {
|
2016-12-02 18:58:44 +08:00
|
|
|
if (op1 == result) {
|
2018-07-05 04:48:39 +08:00
|
|
|
zval_ptr_dtor(result);
|
2016-12-02 18:58:44 +08:00
|
|
|
}
|
2016-12-03 00:03:05 +08:00
|
|
|
ZVAL_LONG(result, (op1_lval < 0) ? -1 : 0);
|
2014-12-11 20:01:06 +08:00
|
|
|
return SUCCESS;
|
|
|
|
} else {
|
2015-04-06 19:30:05 +08:00
|
|
|
if (EG(current_execute_data) && !CG(in_compilation)) {
|
2015-07-03 02:47:44 +08:00
|
|
|
zend_throw_exception_ex(zend_ce_arithmetic_error, 0, "Bit shift by negative number");
|
2015-04-06 19:30:05 +08:00
|
|
|
} else {
|
|
|
|
zend_error_noreturn(E_ERROR, "Bit shift by negative number");
|
|
|
|
}
|
2016-12-02 18:58:44 +08:00
|
|
|
if (op1 != result) {
|
|
|
|
ZVAL_UNDEF(result);
|
|
|
|
}
|
2014-12-11 20:01:06 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2014-08-16 00:29:26 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 18:58:44 +08:00
|
|
|
if (op1 == result) {
|
2018-07-05 04:48:39 +08:00
|
|
|
zval_ptr_dtor(result);
|
2016-12-02 18:58:44 +08:00
|
|
|
}
|
|
|
|
|
2014-12-11 20:01:06 +08:00
|
|
|
ZVAL_LONG(result, op1_lval >> op2_lval);
|
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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL concat_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2016-12-02 18:58:44 +08:00
|
|
|
zval *orig_op1 = op1;
|
2016-12-02 16:58:41 +08:00
|
|
|
zval op1_copy, op2_copy;
|
2018-07-04 17:05:51 +08:00
|
|
|
|
|
|
|
ZVAL_UNDEF(&op1_copy);
|
|
|
|
ZVAL_UNDEF(&op2_copy);
|
1999-06-11 23:37:43 +08:00
|
|
|
|
2014-12-06 07:14:45 +08:00
|
|
|
do {
|
|
|
|
if (UNEXPECTED(Z_TYPE_P(op1) != IS_STRING)) {
|
|
|
|
if (Z_ISREF_P(op1)) {
|
|
|
|
op1 = Z_REFVAL_P(op1);
|
|
|
|
if (Z_TYPE_P(op1) == IS_STRING) break;
|
|
|
|
}
|
|
|
|
ZEND_TRY_BINARY_OBJECT_OPERATION(ZEND_CONCAT, concat_function);
|
2018-07-04 17:05:51 +08:00
|
|
|
ZVAL_STR(&op1_copy, zval_get_string_func(op1));
|
|
|
|
if (UNEXPECTED(EG(exception))) {
|
|
|
|
zval_ptr_dtor_str(&op1_copy);
|
|
|
|
if (orig_op1 != result) {
|
|
|
|
ZVAL_UNDEF(result);
|
2016-12-02 20:13:55 +08:00
|
|
|
}
|
2018-07-04 17:05:51 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
if (result == op1) {
|
|
|
|
if (UNEXPECTED(op1 == op2)) {
|
|
|
|
op2 = &op1_copy;
|
2014-10-21 07:24:20 +08:00
|
|
|
}
|
|
|
|
}
|
2018-07-04 17:05:51 +08:00
|
|
|
op1 = &op1_copy;
|
2013-06-17 23:48:13 +08:00
|
|
|
}
|
2014-12-06 07:14:45 +08:00
|
|
|
} while (0);
|
|
|
|
do {
|
|
|
|
if (UNEXPECTED(Z_TYPE_P(op2) != IS_STRING)) {
|
|
|
|
if (Z_ISREF_P(op2)) {
|
|
|
|
op2 = Z_REFVAL_P(op2);
|
|
|
|
if (Z_TYPE_P(op2) == IS_STRING) break;
|
|
|
|
}
|
|
|
|
ZEND_TRY_BINARY_OP2_OBJECT_OPERATION(ZEND_CONCAT);
|
2018-07-04 17:05:51 +08:00
|
|
|
ZVAL_STR(&op2_copy, zval_get_string_func(op2));
|
|
|
|
if (UNEXPECTED(EG(exception))) {
|
|
|
|
zval_ptr_dtor_str(&op1_copy);
|
|
|
|
zval_ptr_dtor_str(&op2_copy);
|
|
|
|
if (orig_op1 != result) {
|
|
|
|
ZVAL_UNDEF(result);
|
2016-12-02 20:13:55 +08:00
|
|
|
}
|
2018-07-04 17:05:51 +08:00
|
|
|
return FAILURE;
|
2014-12-06 07:14:45 +08:00
|
|
|
}
|
2018-07-04 17:05:51 +08:00
|
|
|
op2 = &op2_copy;
|
2004-03-14 21:14:48 +08:00
|
|
|
}
|
2014-12-06 07:14:45 +08:00
|
|
|
} while (0);
|
2014-07-09 20:05:55 +08:00
|
|
|
|
2017-10-26 14:45:02 +08:00
|
|
|
if (UNEXPECTED(Z_STRLEN_P(op1) == 0)) {
|
|
|
|
if (EXPECTED(result != op2)) {
|
|
|
|
if (result == orig_op1) {
|
2018-09-16 23:12:44 +08:00
|
|
|
i_zval_ptr_dtor(result);
|
2017-10-26 14:45:02 +08:00
|
|
|
}
|
|
|
|
ZVAL_COPY(result, op2);
|
|
|
|
}
|
|
|
|
} else if (UNEXPECTED(Z_STRLEN_P(op2) == 0)) {
|
|
|
|
if (EXPECTED(result != op1)) {
|
|
|
|
ZVAL_COPY(result, op1);
|
|
|
|
}
|
|
|
|
} else {
|
2014-08-26 01:24:55 +08:00
|
|
|
size_t op1_len = Z_STRLEN_P(op1);
|
2014-09-06 18:19:55 +08:00
|
|
|
size_t op2_len = Z_STRLEN_P(op2);
|
|
|
|
size_t result_len = op1_len + op2_len;
|
2014-09-05 17:50:31 +08:00
|
|
|
zend_string *result_str;
|
2004-07-19 15:19:50 +08:00
|
|
|
|
2015-04-02 08:56:42 +08:00
|
|
|
if (UNEXPECTED(op1_len > SIZE_MAX - op2_len)) {
|
2015-07-08 01:10:22 +08:00
|
|
|
zend_throw_error(NULL, "String size overflow");
|
2018-07-04 17:05:51 +08:00
|
|
|
zval_ptr_dtor_str(&op1_copy);
|
|
|
|
zval_ptr_dtor_str(&op2_copy);
|
2016-12-02 18:58:44 +08:00
|
|
|
if (orig_op1 != result) {
|
|
|
|
ZVAL_UNDEF(result);
|
|
|
|
}
|
2015-04-02 01:01:57 +08:00
|
|
|
return FAILURE;
|
2009-11-19 22:04:34 +08:00
|
|
|
}
|
|
|
|
|
2014-09-19 19:41:01 +08:00
|
|
|
if (result == op1 && Z_REFCOUNTED_P(result)) {
|
2014-09-05 17:50:31 +08:00
|
|
|
/* special case, perform operations on result */
|
2015-03-20 07:02:42 +08:00
|
|
|
result_str = zend_string_extend(Z_STR_P(result), result_len, 0);
|
2014-09-05 17:50:31 +08:00
|
|
|
} else {
|
|
|
|
result_str = zend_string_alloc(result_len, 0);
|
2015-06-30 18:59:27 +08:00
|
|
|
memcpy(ZSTR_VAL(result_str), Z_STRVAL_P(op1), op1_len);
|
2016-12-02 18:58:44 +08:00
|
|
|
if (result == orig_op1) {
|
2018-09-16 23:12:44 +08:00
|
|
|
i_zval_ptr_dtor(result);
|
2016-12-02 18:58:44 +08:00
|
|
|
}
|
2014-09-05 17:50:31 +08:00
|
|
|
}
|
2010-04-20 19:05:54 +08:00
|
|
|
|
2014-09-06 18:19:55 +08:00
|
|
|
/* This has to happen first to account for the cases where result == op1 == op2 and
|
|
|
|
* the realloc is done. In this case this line will also update Z_STRVAL_P(op2) to
|
|
|
|
* point to the new string. The first op2_len bytes of result will still be the same. */
|
2014-09-05 17:50:31 +08:00
|
|
|
ZVAL_NEW_STR(result, result_str);
|
2010-04-20 19:05:54 +08:00
|
|
|
|
2015-06-30 18:59:27 +08:00
|
|
|
memcpy(ZSTR_VAL(result_str) + op1_len, Z_STRVAL_P(op2), op2_len);
|
|
|
|
ZSTR_VAL(result_str)[result_len] = '\0';
|
2000-03-23 02:43:25 +08:00
|
|
|
}
|
2014-09-05 17:50:31 +08:00
|
|
|
|
2018-07-04 17:05:51 +08:00
|
|
|
zval_ptr_dtor_str(&op1_copy);
|
|
|
|
zval_ptr_dtor_str(&op2_copy);
|
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
|
|
|
|
2015-09-10 07:51:23 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL string_compare_function_ex(zval *op1, zval *op2, zend_bool case_insensitive) /* {{{ */
|
2000-05-18 02:55:22 +08:00
|
|
|
{
|
2017-11-16 22:09:32 +08:00
|
|
|
zend_string *tmp_str1, *tmp_str2;
|
|
|
|
zend_string *str1 = zval_get_tmp_string(op1, &tmp_str1);
|
|
|
|
zend_string *str2 = zval_get_tmp_string(op2, &tmp_str2);
|
2015-09-10 07:51:23 +08:00
|
|
|
int ret;
|
2000-05-18 02:55:22 +08:00
|
|
|
|
2011-08-30 04:24:09 +08:00
|
|
|
if (case_insensitive) {
|
2015-09-10 07:51:23 +08:00
|
|
|
ret = zend_binary_strcasecmp_l(ZSTR_VAL(str1), ZSTR_LEN(str1), ZSTR_VAL(str2), ZSTR_LEN(str1));
|
2011-08-30 04:24:09 +08:00
|
|
|
} else {
|
2015-09-10 07:51:23 +08:00
|
|
|
ret = zend_binary_strcmp(ZSTR_VAL(str1), ZSTR_LEN(str1), ZSTR_VAL(str2), ZSTR_LEN(str2));
|
2011-08-30 04:24:09 +08:00
|
|
|
}
|
2000-05-18 02:55:22 +08:00
|
|
|
|
2017-11-16 22:09:32 +08:00
|
|
|
zend_tmp_string_release(tmp_str1);
|
|
|
|
zend_tmp_string_release(tmp_str2);
|
2015-09-10 07:51:23 +08:00
|
|
|
return ret;
|
2000-05-18 02:55:22 +08:00
|
|
|
}
|
2009-05-11 15:52:49 +08:00
|
|
|
/* }}} */
|
2000-05-18 02:55:22 +08:00
|
|
|
|
2015-09-10 07:51:23 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL string_compare_function(zval *op1, zval *op2) /* {{{ */
|
2011-08-30 04:24:09 +08:00
|
|
|
{
|
2014-06-09 21:00:22 +08:00
|
|
|
if (EXPECTED(Z_TYPE_P(op1) == IS_STRING) &&
|
|
|
|
EXPECTED(Z_TYPE_P(op2) == IS_STRING)) {
|
|
|
|
if (Z_STR_P(op1) == Z_STR_P(op2)) {
|
2015-09-10 07:51:23 +08:00
|
|
|
return 0;
|
2014-06-09 21:00:22 +08:00
|
|
|
} else {
|
2015-09-10 07:51:23 +08:00
|
|
|
return zend_binary_strcmp(Z_STRVAL_P(op1), Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2));
|
2014-06-09 21:00:22 +08:00
|
|
|
}
|
|
|
|
} else {
|
2017-11-16 22:09:32 +08:00
|
|
|
zend_string *tmp_str1, *tmp_str2;
|
|
|
|
zend_string *str1 = zval_get_tmp_string(op1, &tmp_str1);
|
|
|
|
zend_string *str2 = zval_get_tmp_string(op2, &tmp_str2);
|
2015-09-10 07:51:23 +08:00
|
|
|
int ret = zend_binary_strcmp(ZSTR_VAL(str1), ZSTR_LEN(str1), ZSTR_VAL(str2), ZSTR_LEN(str2));
|
2014-06-09 21:00:22 +08:00
|
|
|
|
2017-11-16 22:09:32 +08:00
|
|
|
zend_tmp_string_release(tmp_str1);
|
|
|
|
zend_tmp_string_release(tmp_str2);
|
2015-09-10 07:51:23 +08:00
|
|
|
return ret;
|
2014-06-09 21:00:22 +08:00
|
|
|
}
|
2011-08-30 04:24:09 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2015-09-10 07:51:23 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL string_case_compare_function(zval *op1, zval *op2) /* {{{ */
|
2011-08-30 04:24:09 +08:00
|
|
|
{
|
2014-06-09 21:00:22 +08:00
|
|
|
if (EXPECTED(Z_TYPE_P(op1) == IS_STRING) &&
|
|
|
|
EXPECTED(Z_TYPE_P(op2) == IS_STRING)) {
|
|
|
|
if (Z_STR_P(op1) == Z_STR_P(op2)) {
|
2015-09-10 07:51:23 +08:00
|
|
|
return 0;
|
2014-06-09 21:00:22 +08:00
|
|
|
} else {
|
2015-09-10 07:51:23 +08:00
|
|
|
return zend_binary_strcasecmp_l(Z_STRVAL_P(op1), Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2));
|
2014-06-09 21:00:22 +08:00
|
|
|
}
|
|
|
|
} else {
|
2017-11-16 22:09:32 +08:00
|
|
|
zend_string *tmp_str1, *tmp_str2;
|
|
|
|
zend_string *str1 = zval_get_tmp_string(op1, &tmp_str1);
|
|
|
|
zend_string *str2 = zval_get_tmp_string(op2, &tmp_str2);
|
2015-09-10 07:51:23 +08:00
|
|
|
int ret = zend_binary_strcasecmp_l(ZSTR_VAL(str1), ZSTR_LEN(str1), ZSTR_VAL(str2), ZSTR_LEN(str1));
|
2014-06-09 21:00:22 +08:00
|
|
|
|
2017-11-16 22:09:32 +08:00
|
|
|
zend_tmp_string_release(tmp_str1);
|
|
|
|
zend_tmp_string_release(tmp_str2);
|
2015-09-10 07:51:23 +08:00
|
|
|
return ret;
|
2014-06-09 21:00:22 +08:00
|
|
|
}
|
2011-08-30 04:24:09 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2015-09-10 07:51:23 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL string_locale_compare_function(zval *op1, zval *op2) /* {{{ */
|
2004-09-11 22:22:35 +08:00
|
|
|
{
|
2017-11-16 22:09:32 +08:00
|
|
|
zend_string *tmp_str1, *tmp_str2;
|
|
|
|
zend_string *str1 = zval_get_tmp_string(op1, &tmp_str1);
|
|
|
|
zend_string *str2 = zval_get_tmp_string(op2, &tmp_str2);
|
2015-09-10 07:51:23 +08:00
|
|
|
int ret = strcoll(ZSTR_VAL(str1), ZSTR_VAL(str2));
|
2004-09-11 22:22:35 +08:00
|
|
|
|
2017-11-16 22:09:32 +08:00
|
|
|
zend_tmp_string_release(tmp_str1);
|
|
|
|
zend_tmp_string_release(tmp_str2);
|
2015-09-10 07:51:23 +08:00
|
|
|
return ret;
|
2004-09-11 22:22:35 +08:00
|
|
|
}
|
2009-05-11 15:52:49 +08:00
|
|
|
/* }}} */
|
2004-09-11 22:22:35 +08:00
|
|
|
|
2015-09-10 07:51:23 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL numeric_compare_function(zval *op1, zval *op2) /* {{{ */
|
2000-05-18 02:55:22 +08:00
|
|
|
{
|
2014-06-03 04:36:31 +08:00
|
|
|
double d1, d2;
|
2000-05-18 02:55:22 +08:00
|
|
|
|
2014-06-03 04:36:31 +08:00
|
|
|
d1 = zval_get_double(op1);
|
|
|
|
d2 = zval_get_double(op2);
|
2000-05-18 02:55:22 +08:00
|
|
|
|
2015-09-10 07:51:23 +08:00
|
|
|
return ZEND_NORMALIZE_BOOL(d1 - d2);
|
2000-05-18 02:55:22 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2000-05-18 02:55:22 +08:00
|
|
|
|
2019-10-07 22:57:49 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
2015-09-09 20:11:03 +08:00
|
|
|
{
|
2019-10-07 22:57:49 +08:00
|
|
|
ZVAL_LONG(result, zend_compare(op1, op2));
|
|
|
|
return SUCCESS;
|
2015-09-09 20:11:03 +08:00
|
|
|
}
|
2015-09-10 15:01:28 +08:00
|
|
|
/* }}} */
|
2015-09-09 20:11:03 +08:00
|
|
|
|
2019-10-07 22:57:49 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL zend_compare(zval *op1, zval *op2) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2007-11-20 21:26:36 +08:00
|
|
|
int converted = 0;
|
2019-10-07 22:57:49 +08:00
|
|
|
zval op1_copy, op2_copy;
|
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):
|
2019-10-07 22:57:49 +08:00
|
|
|
return Z_LVAL_P(op1)>Z_LVAL_P(op2)?1:(Z_LVAL_P(op1)<Z_LVAL_P(op2)?-1:0);
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
case TYPE_PAIR(IS_DOUBLE, IS_LONG):
|
2019-10-07 22:57:49 +08:00
|
|
|
return ZEND_NORMALIZE_BOOL(Z_DVAL_P(op1) - (double)Z_LVAL_P(op2));
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
case TYPE_PAIR(IS_LONG, IS_DOUBLE):
|
2019-10-07 22:57:49 +08:00
|
|
|
return ZEND_NORMALIZE_BOOL((double)Z_LVAL_P(op1) - Z_DVAL_P(op2));
|
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)) {
|
2019-10-07 22:57:49 +08:00
|
|
|
return 0;
|
2010-08-22 16:01:34 +08:00
|
|
|
} else {
|
2019-10-07 22:57:49 +08:00
|
|
|
return ZEND_NORMALIZE_BOOL(Z_DVAL_P(op1) - Z_DVAL_P(op2));
|
2010-08-22 16:01:34 +08:00
|
|
|
}
|
1999-12-31 21:56:59 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
case TYPE_PAIR(IS_ARRAY, IS_ARRAY):
|
2019-10-07 22:57:49 +08:00
|
|
|
return zend_compare_arrays(op1, op2);
|
2004-05-10 22:56:21 +08:00
|
|
|
|
2007-11-20 21:26:36 +08:00
|
|
|
case TYPE_PAIR(IS_NULL, IS_NULL):
|
2014-04-30 22:32:42 +08:00
|
|
|
case TYPE_PAIR(IS_NULL, IS_FALSE):
|
|
|
|
case TYPE_PAIR(IS_FALSE, IS_NULL):
|
|
|
|
case TYPE_PAIR(IS_FALSE, IS_FALSE):
|
|
|
|
case TYPE_PAIR(IS_TRUE, IS_TRUE):
|
2019-10-07 22:57:49 +08:00
|
|
|
return 0;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2014-04-30 22:32:42 +08:00
|
|
|
case TYPE_PAIR(IS_NULL, IS_TRUE):
|
2019-10-07 22:57:49 +08:00
|
|
|
return -1;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2014-04-30 22:32:42 +08:00
|
|
|
case TYPE_PAIR(IS_TRUE, IS_NULL):
|
2019-10-07 22:57:49 +08:00
|
|
|
return 1;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
case TYPE_PAIR(IS_STRING, IS_STRING):
|
2014-06-05 23:14:47 +08:00
|
|
|
if (Z_STR_P(op1) == Z_STR_P(op2)) {
|
2019-10-07 22:57:49 +08:00
|
|
|
return 0;
|
2014-06-05 23:14:47 +08:00
|
|
|
}
|
2019-10-07 22:57:49 +08:00
|
|
|
return zendi_smart_strcmp(Z_STR_P(op1), Z_STR_P(op2));
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
case TYPE_PAIR(IS_NULL, IS_STRING):
|
2019-10-07 22:57:49 +08:00
|
|
|
return Z_STRLEN_P(op2) == 0 ? 0 : -1;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
case TYPE_PAIR(IS_STRING, IS_NULL):
|
2019-10-07 22:57:49 +08:00
|
|
|
return Z_STRLEN_P(op1) == 0 ? 0 : 1;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
case TYPE_PAIR(IS_OBJECT, IS_NULL):
|
2019-10-07 22:57:49 +08:00
|
|
|
return 1;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
case TYPE_PAIR(IS_NULL, IS_OBJECT):
|
2019-10-07 22:57:49 +08:00
|
|
|
return -1;
|
2000-06-03 18:34:19 +08:00
|
|
|
|
2013-06-17 23:48:13 +08:00
|
|
|
default:
|
2014-08-14 19:07:39 +08:00
|
|
|
if (Z_ISREF_P(op1)) {
|
|
|
|
op1 = Z_REFVAL_P(op1);
|
|
|
|
continue;
|
|
|
|
} else if (Z_ISREF_P(op2)) {
|
|
|
|
op2 = Z_REFVAL_P(op2);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-10-07 22:57:49 +08:00
|
|
|
if (Z_TYPE_P(op1) == IS_OBJECT
|
|
|
|
&& Z_TYPE_P(op2) == IS_OBJECT
|
|
|
|
&& Z_OBJ_P(op1) == Z_OBJ_P(op2)) {
|
|
|
|
return 0;
|
|
|
|
} else if (Z_TYPE_P(op1) == IS_OBJECT) {
|
|
|
|
return Z_OBJ_HANDLER_P(op1, compare)(op1, op2);
|
|
|
|
} else if (Z_TYPE_P(op2) == IS_OBJECT) {
|
|
|
|
return Z_OBJ_HANDLER_P(op2, compare)(op1, op2);
|
2013-06-17 23:48:13 +08:00
|
|
|
}
|
|
|
|
|
2014-08-14 19:07:39 +08:00
|
|
|
if (!converted) {
|
2018-09-27 18:11:48 +08:00
|
|
|
if (Z_TYPE_P(op1) < IS_TRUE) {
|
2019-10-07 22:57:49 +08:00
|
|
|
return zval_is_true(op2) ? -1 : 0;
|
2014-04-30 22:32:42 +08:00
|
|
|
} else if (Z_TYPE_P(op1) == IS_TRUE) {
|
2019-10-07 22:57:49 +08:00
|
|
|
return zval_is_true(op2) ? 0 : 1;
|
2018-09-27 18:11:48 +08:00
|
|
|
} else if (Z_TYPE_P(op2) < IS_TRUE) {
|
2019-10-07 22:57:49 +08:00
|
|
|
return zval_is_true(op1) ? 1 : 0;
|
2014-04-30 22:32:42 +08:00
|
|
|
} else if (Z_TYPE_P(op2) == IS_TRUE) {
|
2019-10-07 22:57:49 +08:00
|
|
|
return zval_is_true(op1) ? 0 : -1;
|
2007-11-20 21:26:36 +08:00
|
|
|
} else {
|
2019-10-07 22:57:49 +08:00
|
|
|
op1 = _zendi_convert_scalar_to_number(op1, &op1_copy);
|
|
|
|
op2 = _zendi_convert_scalar_to_number(op2, &op2_copy);
|
2018-05-30 19:03:48 +08:00
|
|
|
if (EG(exception)) {
|
2019-10-07 22:57:49 +08:00
|
|
|
return 1; /* to stop comparison of arrays */
|
2018-05-30 19:03:48 +08:00
|
|
|
}
|
2007-11-20 21:26:36 +08:00
|
|
|
converted = 1;
|
|
|
|
}
|
|
|
|
} else if (Z_TYPE_P(op1)==IS_ARRAY) {
|
2019-10-07 22:57:49 +08:00
|
|
|
return 1;
|
2007-11-20 21:26:36 +08:00
|
|
|
} else if (Z_TYPE_P(op2)==IS_ARRAY) {
|
2019-10-07 22:57:49 +08:00
|
|
|
return -1;
|
2007-11-20 21:26:36 +08:00
|
|
|
} else {
|
2018-09-27 18:11:48 +08:00
|
|
|
ZEND_ASSERT(0);
|
|
|
|
zend_throw_error(NULL, "Unsupported operand types");
|
2019-10-07 22:57:49 +08:00
|
|
|
return 1;
|
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
|
|
|
|
2015-10-07 04:48:12 +08:00
|
|
|
static int hash_zval_identical_function(zval *z1, zval *z2) /* {{{ */
|
|
|
|
{
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
ZVAL_DEREF(z1);
|
|
|
|
ZVAL_DEREF(z2);
|
2019-04-04 23:18:12 +08:00
|
|
|
return fast_is_not_identical_function(z1, z2);
|
2015-10-07 04:48:12 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2019-04-04 23:18:12 +08:00
|
|
|
ZEND_API zend_bool ZEND_FASTCALL zend_is_identical(zval *op1, zval *op2) /* {{{ */
|
1999-10-19 21:33:17 +08:00
|
|
|
{
|
2007-11-20 21:26:36 +08:00
|
|
|
if (Z_TYPE_P(op1) != Z_TYPE_P(op2)) {
|
2015-10-07 04:48:12 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
switch (Z_TYPE_P(op1)) {
|
|
|
|
case IS_NULL:
|
|
|
|
case IS_FALSE:
|
|
|
|
case IS_TRUE:
|
|
|
|
return 1;
|
|
|
|
case IS_LONG:
|
|
|
|
return (Z_LVAL_P(op1) == Z_LVAL_P(op2));
|
|
|
|
case IS_RESOURCE:
|
|
|
|
return (Z_RES_P(op1) == Z_RES_P(op2));
|
|
|
|
case IS_DOUBLE:
|
|
|
|
return (Z_DVAL_P(op1) == Z_DVAL_P(op2));
|
|
|
|
case IS_STRING:
|
2017-12-04 22:17:02 +08:00
|
|
|
return zend_string_equals(Z_STR_P(op1), Z_STR_P(op2));
|
2015-10-07 04:48:12 +08:00
|
|
|
case IS_ARRAY:
|
|
|
|
return (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) == 0);
|
|
|
|
case IS_OBJECT:
|
2018-07-10 16:04:10 +08:00
|
|
|
return (Z_OBJ_P(op1) == Z_OBJ_P(op2));
|
2015-10-07 04:48:12 +08:00
|
|
|
default:
|
2015-04-29 21:43:23 +08:00
|
|
|
return 0;
|
1999-10-19 21:33:17 +08:00
|
|
|
}
|
2015-04-29 21:43:23 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
ZEND_API int ZEND_FASTCALL is_identical_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
|
|
|
{
|
|
|
|
ZVAL_BOOL(result, zend_is_identical(op1, op2));
|
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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL is_not_identical_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
2000-03-30 06:05:19 +08:00
|
|
|
{
|
2015-04-29 21:43:23 +08:00
|
|
|
ZVAL_BOOL(result, !zend_is_identical(op1, op2));
|
2009-05-11 15:52:49 +08:00
|
|
|
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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL is_equal_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2019-10-07 22:57:49 +08:00
|
|
|
ZVAL_BOOL(result, zend_compare(op1, op2) == 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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL is_not_equal_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2019-10-07 22:57:49 +08:00
|
|
|
ZVAL_BOOL(result, (zend_compare(op1, op2) != 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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL is_smaller_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2019-10-07 22:57:49 +08:00
|
|
|
ZVAL_BOOL(result, (zend_compare(op1, op2) < 0));
|
2007-11-20 21:26:36 +08:00
|
|
|
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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL is_smaller_or_equal_function(zval *result, zval *op1, zval *op2) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2019-10-07 22:57:49 +08:00
|
|
|
ZVAL_BOOL(result, (zend_compare(op1, op2) <= 0));
|
2007-11-20 21:26:36 +08:00
|
|
|
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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
static zend_bool ZEND_FASTCALL instanceof_interface_only(const zend_class_entry *instance_ce, const zend_class_entry *ce) /* {{{ */
|
2002-07-30 12:07:15 +08:00
|
|
|
{
|
2014-08-26 01:28:33 +08:00
|
|
|
uint32_t i;
|
2003-03-05 19:14:44 +08:00
|
|
|
|
2018-08-23 22:16:28 +08:00
|
|
|
if (instance_ce->num_interfaces) {
|
2019-05-27 17:39:56 +08:00
|
|
|
ZEND_ASSERT(instance_ce->ce_flags & ZEND_ACC_RESOLVED_INTERFACES);
|
2018-08-23 22:16:28 +08:00
|
|
|
for (i = 0; i < instance_ce->num_interfaces; i++) {
|
|
|
|
if (instanceof_interface_only(instance_ce->interfaces[i], ce)) {
|
|
|
|
return 1;
|
|
|
|
}
|
2003-05-30 03:00:40 +08:00
|
|
|
}
|
|
|
|
}
|
2015-01-14 20:06:26 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
static zend_always_inline zend_bool instanceof_class(const zend_class_entry *instance_ce, const zend_class_entry *ce) /* {{{ */
|
|
|
|
{
|
|
|
|
while (instance_ce) {
|
|
|
|
if (instance_ce == ce) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
instance_ce = instance_ce->parent;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
static zend_bool ZEND_FASTCALL instanceof_interface(const zend_class_entry *instance_ce, const zend_class_entry *ce) /* {{{ */
|
2015-01-14 20:06:26 +08:00
|
|
|
{
|
|
|
|
uint32_t i;
|
|
|
|
|
2018-08-23 22:16:28 +08:00
|
|
|
if (instance_ce->num_interfaces) {
|
2019-05-27 17:39:56 +08:00
|
|
|
ZEND_ASSERT(instance_ce->ce_flags & ZEND_ACC_RESOLVED_INTERFACES);
|
2018-08-23 22:16:28 +08:00
|
|
|
for (i = 0; i < instance_ce->num_interfaces; i++) {
|
|
|
|
if (instanceof_interface(instance_ce->interfaces[i], ce)) {
|
|
|
|
return 1;
|
|
|
|
}
|
2015-01-14 20:06:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return instanceof_class(instance_ce, ce);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API zend_bool ZEND_FASTCALL instanceof_function_ex(const zend_class_entry *instance_ce, const zend_class_entry *ce, zend_bool interfaces_only) /* {{{ */
|
2015-01-14 20:06:26 +08:00
|
|
|
{
|
|
|
|
if (ce->ce_flags & ZEND_ACC_INTERFACE) {
|
|
|
|
if (!interfaces_only) {
|
2015-01-15 02:09:06 +08:00
|
|
|
if (instanceof_interface_only(instance_ce, ce)) {
|
2003-11-25 04:57:54 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2015-01-14 20:06:26 +08:00
|
|
|
} else {
|
|
|
|
return instanceof_interface(instance_ce, ce);
|
2003-03-05 19:14:44 +08:00
|
|
|
}
|
2002-07-30 12:07:15 +08:00
|
|
|
}
|
2015-01-14 20:06:26 +08:00
|
|
|
if (!interfaces_only) {
|
|
|
|
return instanceof_class(instance_ce, ce);
|
|
|
|
}
|
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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API zend_bool ZEND_FASTCALL instanceof_function(const zend_class_entry *instance_ce, const zend_class_entry *ce) /* {{{ */
|
2003-11-25 04:57:54 +08:00
|
|
|
{
|
2015-01-14 20:06:26 +08:00
|
|
|
if (ce->ce_flags & ZEND_ACC_INTERFACE) {
|
|
|
|
return instanceof_interface(instance_ce, ce);
|
|
|
|
} else {
|
|
|
|
return instanceof_class(instance_ce, ce);
|
|
|
|
}
|
2003-11-25 04:57:54 +08:00
|
|
|
}
|
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
|
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
static void ZEND_FASTCALL increment_string(zval *str) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2009-05-11 15:52:49 +08:00
|
|
|
int carry=0;
|
2014-08-26 01:24:55 +08:00
|
|
|
size_t pos=Z_STRLEN_P(str)-1;
|
2014-02-10 14:04:30 +08:00
|
|
|
char *s;
|
|
|
|
zend_string *t;
|
2009-05-11 15:52:49 +08:00
|
|
|
int last=0; /* Shut up the compiler warning */
|
|
|
|
int ch;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
|
|
|
if (Z_STRLEN_P(str) == 0) {
|
2018-07-04 17:08:07 +08:00
|
|
|
zval_ptr_dtor_str(str);
|
2017-03-04 17:39:13 +08:00
|
|
|
ZVAL_INTERNED_STR(str, ZSTR_CHAR('1'));
|
2000-10-14 00:24:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-19 19:41:01 +08:00
|
|
|
if (!Z_REFCOUNTED_P(str)) {
|
2014-08-26 01:24:55 +08:00
|
|
|
Z_STR_P(str) = zend_string_init(Z_STRVAL_P(str), Z_STRLEN_P(str), 0);
|
2014-04-03 19:26:23 +08:00
|
|
|
Z_TYPE_INFO_P(str) = IS_STRING_EX;
|
2014-02-10 14:04:30 +08:00
|
|
|
} else if (Z_REFCOUNT_P(str) > 1) {
|
|
|
|
Z_DELREF_P(str);
|
2014-08-26 01:24:55 +08:00
|
|
|
Z_STR_P(str) = zend_string_init(Z_STRVAL_P(str), Z_STRLEN_P(str), 0);
|
2014-03-05 18:39:20 +08:00
|
|
|
} else {
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_string_forget_hash_val(Z_STR_P(str));
|
2010-04-20 19:05:54 +08:00
|
|
|
}
|
2014-02-10 14:04:30 +08:00
|
|
|
s = Z_STRVAL_P(str);
|
2010-04-20 19:05:54 +08:00
|
|
|
|
2014-09-05 18:44:51 +08:00
|
|
|
do {
|
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;
|
|
|
|
}
|
2014-09-05 18:44:51 +08:00
|
|
|
} while (pos-- > 0);
|
2009-05-11 15:52:49 +08:00
|
|
|
|
|
|
|
if (carry) {
|
2014-08-26 01:24:55 +08:00
|
|
|
t = zend_string_alloc(Z_STRLEN_P(str)+1, 0);
|
2015-06-30 18:59:27 +08:00
|
|
|
memcpy(ZSTR_VAL(t) + 1, Z_STRVAL_P(str), Z_STRLEN_P(str));
|
|
|
|
ZSTR_VAL(t)[Z_STRLEN_P(str) + 1] = '\0';
|
2009-05-11 15:52:49 +08:00
|
|
|
switch (last) {
|
|
|
|
case NUMERIC:
|
2015-06-30 18:59:27 +08:00
|
|
|
ZSTR_VAL(t)[0] = '1';
|
2009-05-11 15:52:49 +08:00
|
|
|
break;
|
|
|
|
case UPPER_CASE:
|
2015-06-30 18:59:27 +08:00
|
|
|
ZSTR_VAL(t)[0] = 'A';
|
2009-05-11 15:52:49 +08:00
|
|
|
break;
|
|
|
|
case LOWER_CASE:
|
2015-06-30 18:59:27 +08:00
|
|
|
ZSTR_VAL(t)[0] = 'a';
|
2009-05-11 15:52:49 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_string_free(Z_STR_P(str));
|
2014-04-03 19:26:23 +08:00
|
|
|
ZVAL_NEW_STR(str, t);
|
2009-05-11 15:52:49 +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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL increment_function(zval *op1) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2014-05-26 23:58:10 +08:00
|
|
|
try_again:
|
2007-11-20 21:26:36 +08:00
|
|
|
switch (Z_TYPE_P(op1)) {
|
1999-04-08 02:10:10 +08:00
|
|
|
case IS_LONG:
|
2015-03-17 23:53:19 +08:00
|
|
|
fast_long_increment_function(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: {
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_long lval;
|
2001-05-10 20:58:31 +08:00
|
|
|
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:
|
2018-07-04 17:08:07 +08:00
|
|
|
zval_ptr_dtor_str(op1);
|
2014-08-26 02:22:49 +08:00
|
|
|
if (lval == ZEND_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:
|
2018-07-04 17:08:07 +08:00
|
|
|
zval_ptr_dtor_str(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;
|
2013-06-17 23:48:13 +08:00
|
|
|
case IS_OBJECT:
|
2019-05-28 22:55:52 +08:00
|
|
|
if (Z_OBJ_HANDLER_P(op1, do_operation)) {
|
2014-02-10 14:04:30 +08:00
|
|
|
zval op2;
|
2013-06-17 23:48:13 +08:00
|
|
|
int res;
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
ZVAL_LONG(&op2, 1);
|
2014-12-14 06:06:14 +08:00
|
|
|
res = Z_OBJ_HANDLER_P(op1, do_operation)(ZEND_ADD, op1, op1, &op2);
|
2013-06-17 23:48:13 +08:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
return FAILURE;
|
2014-05-26 23:58:10 +08:00
|
|
|
case IS_REFERENCE:
|
|
|
|
op1 = Z_REFVAL_P(op1);
|
|
|
|
goto try_again;
|
1999-04-08 02:10:10 +08:00
|
|
|
default:
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL decrement_function(zval *op1) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_long lval;
|
2002-06-29 15:35:41 +08:00
|
|
|
double dval;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2014-05-26 23:58:10 +08:00
|
|
|
try_again:
|
2007-11-20 21:26:36 +08:00
|
|
|
switch (Z_TYPE_P(op1)) {
|
1999-04-08 02:10:10 +08:00
|
|
|
case IS_LONG:
|
2015-03-17 23:53:19 +08:00
|
|
|
fast_long_decrement_function(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;
|
|
|
|
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 */
|
2018-07-04 17:08:07 +08:00
|
|
|
zval_ptr_dtor_str(op1);
|
2007-11-20 21:26:36 +08:00
|
|
|
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:
|
2018-07-04 17:08:07 +08:00
|
|
|
zval_ptr_dtor_str(op1);
|
2014-08-26 02:22:49 +08:00
|
|
|
if (lval == ZEND_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:
|
2018-07-04 17:08:07 +08:00
|
|
|
zval_ptr_dtor_str(op1);
|
2007-11-20 21:26:36 +08:00
|
|
|
ZVAL_DOUBLE(op1, dval - 1);
|
2002-06-29 15:35:41 +08:00
|
|
|
break;
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
break;
|
2013-06-17 23:48:13 +08:00
|
|
|
case IS_OBJECT:
|
2019-05-28 22:55:52 +08:00
|
|
|
if (Z_OBJ_HANDLER_P(op1, do_operation)) {
|
2014-02-10 14:04:30 +08:00
|
|
|
zval op2;
|
2013-06-17 23:48:13 +08:00
|
|
|
int res;
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
ZVAL_LONG(&op2, 1);
|
2014-12-14 06:06:14 +08:00
|
|
|
res = Z_OBJ_HANDLER_P(op1, do_operation)(ZEND_SUB, op1, op1, &op2);
|
2013-06-17 23:48:13 +08:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
return FAILURE;
|
2014-05-26 23:58:10 +08:00
|
|
|
case IS_REFERENCE:
|
|
|
|
op1 = Z_REFVAL_P(op1);
|
|
|
|
goto try_again;
|
1999-04-08 02:10:10 +08:00
|
|
|
default:
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL zend_is_true(zval *op) /* {{{ */
|
2014-12-11 18:18:40 +08:00
|
|
|
{
|
2014-12-14 06:06:14 +08:00
|
|
|
return i_zend_is_true(op);
|
2014-12-11 18:18:40 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL zend_object_is_true(zval *op) /* {{{ */
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2019-01-31 23:47:58 +08:00
|
|
|
zend_object *zobj = Z_OBJ_P(op);
|
|
|
|
|
|
|
|
if (zobj->handlers->cast_object) {
|
2014-12-11 18:18:40 +08:00
|
|
|
zval tmp;
|
2019-01-31 23:47:58 +08:00
|
|
|
if (zobj->handlers->cast_object(zobj, &tmp, _IS_BOOL) == SUCCESS) {
|
2014-12-11 18:18:40 +08:00
|
|
|
return Z_TYPE(tmp) == IS_TRUE;
|
|
|
|
}
|
2019-01-31 23:47:58 +08:00
|
|
|
zend_error(E_RECOVERABLE_ERROR, "Object of class %s could not be converted to bool", ZSTR_VAL(zobj->ce->name));
|
2014-12-11 18:18:40 +08:00
|
|
|
}
|
|
|
|
return 1;
|
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
|
2015-03-14 20:11:55 +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
|
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API char* ZEND_FASTCALL zend_str_tolower_copy(char *dest, const char *source, size_t 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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API char* ZEND_FASTCALL zend_str_tolower_dup(const char *source, size_t 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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API void ZEND_FASTCALL zend_str_tolower(char *str, size_t 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
|
|
|
|
2015-07-02 00:04:18 +08:00
|
|
|
ZEND_API char* ZEND_FASTCALL zend_str_tolower_dup_ex(const char *source, size_t length) /* {{{ */
|
|
|
|
{
|
|
|
|
register const unsigned char *p = (const unsigned char*)source;
|
|
|
|
register const unsigned char *end = p + length;
|
|
|
|
|
|
|
|
while (p < end) {
|
|
|
|
if (*p != zend_tolower_ascii(*p)) {
|
|
|
|
char *res = (char*)emalloc(length + 1);
|
|
|
|
register unsigned char *r;
|
|
|
|
|
|
|
|
if (p != (const unsigned char*)source) {
|
|
|
|
memcpy(res, source, p - (const unsigned char*)source);
|
|
|
|
}
|
|
|
|
r = (unsigned char*)p + (res - source);
|
|
|
|
while (p < end) {
|
|
|
|
*r = zend_tolower_ascii(*p);
|
|
|
|
p++;
|
|
|
|
r++;
|
|
|
|
}
|
|
|
|
*r = '\0';
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2017-11-30 06:13:39 +08:00
|
|
|
ZEND_API zend_string* ZEND_FASTCALL zend_string_tolower_ex(zend_string *str, int persistent) /* {{{ */
|
2014-12-24 20:04:51 +08:00
|
|
|
{
|
2015-06-30 18:59:27 +08:00
|
|
|
register unsigned char *p = (unsigned char*)ZSTR_VAL(str);
|
|
|
|
register unsigned char *end = p + ZSTR_LEN(str);
|
2014-12-24 20:04:51 +08:00
|
|
|
|
|
|
|
while (p < end) {
|
|
|
|
if (*p != zend_tolower_ascii(*p)) {
|
2017-11-30 06:13:39 +08:00
|
|
|
zend_string *res = zend_string_alloc(ZSTR_LEN(str), persistent);
|
2014-12-24 20:04:51 +08:00
|
|
|
register unsigned char *r;
|
|
|
|
|
2015-06-30 18:59:27 +08:00
|
|
|
if (p != (unsigned char*)ZSTR_VAL(str)) {
|
|
|
|
memcpy(ZSTR_VAL(res), ZSTR_VAL(str), p - (unsigned char*)ZSTR_VAL(str));
|
2014-12-24 20:04:51 +08:00
|
|
|
}
|
2015-06-30 18:59:27 +08:00
|
|
|
r = p + (ZSTR_VAL(res) - ZSTR_VAL(str));
|
2014-12-24 20:04:51 +08:00
|
|
|
while (p < end) {
|
|
|
|
*r = zend_tolower_ascii(*p);
|
|
|
|
p++;
|
|
|
|
r++;
|
|
|
|
}
|
|
|
|
*r = '\0';
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
return zend_string_copy(str);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL zend_binary_strcmp(const char *s1, size_t len1, const char *s2, size_t 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) {
|
2014-08-16 23:31:40 +08:00
|
|
|
return (int)(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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL zend_binary_strncmp(const char *s1, size_t len1, const char *s2, size_t len2, size_t 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) {
|
2014-08-16 23:31:40 +08:00
|
|
|
return (int)(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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL zend_binary_strcasecmp(const char *s1, size_t len1, const char *s2, size_t len2) /* {{{ */
|
1999-06-16 06:32:51 +08:00
|
|
|
{
|
2014-08-26 01:24:55 +08:00
|
|
|
size_t 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-16 23:31:40 +08:00
|
|
|
return (int)(len1 - len2);
|
2012-07-11 09:12:13 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL zend_binary_strncasecmp(const char *s1, size_t len1, const char *s2, size_t len2, size_t length) /* {{{ */
|
2012-07-11 09:12:13 +08:00
|
|
|
{
|
2014-08-26 01:24:55 +08:00
|
|
|
size_t len;
|
2012-07-11 09:12:13 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-16 23:31:40 +08:00
|
|
|
return (int)(MIN(length, len1) - MIN(length, len2));
|
2012-07-11 09:12:13 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL zend_binary_strcasecmp_l(const char *s1, size_t len1, const char *s2, size_t len2) /* {{{ */
|
2012-07-11 09:12:13 +08:00
|
|
|
{
|
2014-08-26 01:24:55 +08:00
|
|
|
size_t len;
|
2012-07-11 09:12:13 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-16 23:31:40 +08:00
|
|
|
return (int)(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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL zend_binary_strncasecmp_l(const char *s1, size_t len1, const char *s2, size_t len2, size_t length) /* {{{ */
|
2000-07-26 19:32:15 +08:00
|
|
|
{
|
2014-08-26 01:24:55 +08:00
|
|
|
size_t 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-16 23:31:40 +08:00
|
|
|
return (int)(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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL 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
|
|
|
/* }}} */
|
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL 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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL 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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL 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
|
|
|
|
2018-01-16 22:24:00 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL zendi_smart_streq(zend_string *s1, zend_string *s2) /* {{{ */
|
|
|
|
{
|
|
|
|
int ret1, ret2;
|
|
|
|
int oflow1, oflow2;
|
|
|
|
zend_long lval1 = 0, lval2 = 0;
|
|
|
|
double dval1 = 0.0, dval2 = 0.0;
|
|
|
|
|
|
|
|
if ((ret1 = is_numeric_string_ex(s1->val, s1->len, &lval1, &dval1, 0, &oflow1)) &&
|
|
|
|
(ret2 = is_numeric_string_ex(s2->val, s2->len, &lval2, &dval2, 0, &oflow2))) {
|
|
|
|
#if ZEND_ULONG_MAX == 0xFFFFFFFF
|
|
|
|
if (oflow1 != 0 && oflow1 == oflow2 && dval1 - dval2 == 0. &&
|
|
|
|
((oflow1 == 1 && dval1 > 9007199254740991. /*0x1FFFFFFFFFFFFF*/)
|
|
|
|
|| (oflow1 == -1 && dval1 < -9007199254740991.))) {
|
|
|
|
#else
|
|
|
|
if (oflow1 != 0 && oflow1 == oflow2 && dval1 - dval2 == 0.) {
|
|
|
|
#endif
|
|
|
|
/* both values are integers overflown to the same side, and the
|
|
|
|
* double comparison may have resulted in crucial accuracy lost */
|
|
|
|
goto string_cmp;
|
|
|
|
}
|
|
|
|
if ((ret1 == IS_DOUBLE) || (ret2 == IS_DOUBLE)) {
|
|
|
|
if (ret1 != IS_DOUBLE) {
|
|
|
|
if (oflow2) {
|
|
|
|
/* 2nd operand is integer > LONG_MAX (oflow2==1) or < LONG_MIN (-1) */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
dval1 = (double) lval1;
|
|
|
|
} else if (ret2 != IS_DOUBLE) {
|
|
|
|
if (oflow1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
return dval1 == dval2;
|
|
|
|
} else { /* they both have to be long's */
|
|
|
|
return lval1 == lval2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
string_cmp:
|
|
|
|
return zend_string_equal_content(s1, s2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2017-10-23 01:58:42 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL zendi_smart_strcmp(zend_string *s1, zend_string *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;
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_long lval1 = 0, lval2 = 0;
|
2013-08-27 15:44:30 +08:00
|
|
|
double dval1 = 0.0, dval2 = 0.0;
|
2007-11-20 21:26:36 +08:00
|
|
|
|
2015-09-10 07:51:23 +08:00
|
|
|
if ((ret1 = is_numeric_string_ex(s1->val, s1->len, &lval1, &dval1, 0, &oflow1)) &&
|
|
|
|
(ret2 = is_numeric_string_ex(s2->val, s2->len, &lval2, &dval2, 0, &oflow2))) {
|
2014-08-26 02:57:25 +08:00
|
|
|
#if ZEND_ULONG_MAX == 0xFFFFFFFF
|
2012-05-22 18:36:28 +08:00
|
|
|
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;
|
|
|
|
}
|
2014-12-22 11:35:25 +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) */
|
2014-12-22 11:35:25 +08:00
|
|
|
return -1 * oflow2;
|
2012-05-11 14:58:10 +08:00
|
|
|
}
|
2006-12-30 09:57:01 +08:00
|
|
|
dval1 = (double) lval1;
|
2014-12-22 11:35:25 +08:00
|
|
|
} else if (ret2 != IS_DOUBLE) {
|
2012-05-11 14:58:10 +08:00
|
|
|
if (oflow1) {
|
2014-12-22 11:35:25 +08:00
|
|
|
return oflow1;
|
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
|
|
|
}
|
2014-12-22 11:35:25 +08:00
|
|
|
dval1 = dval1 - dval2;
|
|
|
|
return ZEND_NORMALIZE_BOOL(dval1);
|
1999-04-08 02:10:10 +08:00
|
|
|
} else { /* they both have to be long's */
|
2014-12-22 11:35:25 +08:00
|
|
|
return lval1 > lval2 ? 1 : (lval1 < lval2 ? -1 : 0);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
} else {
|
2014-12-22 11:35:25 +08:00
|
|
|
int strcmp_ret;
|
2006-12-30 09:57:01 +08:00
|
|
|
string_cmp:
|
2015-09-10 07:51:23 +08:00
|
|
|
strcmp_ret = zend_binary_strcmp(s1->val, s1->len, s2->val, s2->len);
|
2014-12-22 11:35:25 +08:00
|
|
|
return ZEND_NORMALIZE_BOOL(strcmp_ret);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static int hash_zval_compare_function(zval *z1, zval *z2) /* {{{ */
|
2000-06-03 18:34:19 +08:00
|
|
|
{
|
2019-10-07 22:57:49 +08:00
|
|
|
return zend_compare(z1, z2);
|
2000-06-03 18:34:19 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2000-06-03 18:34:19 +08:00
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL zend_compare_symbol_tables(HashTable *ht1, HashTable *ht2) /* {{{ */
|
2002-02-07 22:08:43 +08:00
|
|
|
{
|
2014-12-14 06:06:14 +08:00
|
|
|
return ht1 == ht2 ? 0 : zend_hash_compare(ht1, ht2, (compare_func_t) hash_zval_compare_function, 0);
|
2002-02-07 22:08:43 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2002-02-07 22:08:43 +08:00
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL zend_compare_arrays(zval *a1, zval *a2) /* {{{ */
|
2000-06-03 18:34:19 +08:00
|
|
|
{
|
2014-12-22 12:16:25 +08:00
|
|
|
return zend_compare_symbol_tables(Z_ARRVAL_P(a1), Z_ARRVAL_P(a2));
|
2000-06-03 18:34:19 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2000-06-03 18:34:19 +08:00
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API int ZEND_FASTCALL zend_compare_objects(zval *o1, zval *o2) /* {{{ */
|
2000-06-03 18:34:19 +08:00
|
|
|
{
|
2014-02-10 14:04:30 +08:00
|
|
|
if (Z_OBJ_P(o1) == Z_OBJ_P(o2)) {
|
2014-12-22 12:16:25 +08:00
|
|
|
return 0;
|
2004-10-21 01:57:28 +08:00
|
|
|
}
|
|
|
|
|
2019-10-07 22:57:49 +08:00
|
|
|
if (Z_OBJ_HT_P(o1)->compare == NULL) {
|
2014-12-22 12:16:25 +08:00
|
|
|
return 1;
|
2002-02-07 22:08:43 +08:00
|
|
|
} else {
|
2019-10-07 22:57:49 +08:00
|
|
|
return Z_OBJ_HT_P(o1)->compare(o1, o2);
|
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
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API void ZEND_FASTCALL zend_locale_sprintf_double(zval *op ZEND_FILE_LINE_DC) /* {{{ */
|
2002-10-13 05:15:35 +08:00
|
|
|
{
|
2014-05-10 00:21:49 +08:00
|
|
|
zend_string *str;
|
2007-02-24 10:17:47 +08:00
|
|
|
|
2014-05-10 00:21:49 +08:00
|
|
|
str = zend_strpprintf(0, "%.*G", (int) EG(precision), (double)Z_DVAL_P(op));
|
|
|
|
ZVAL_NEW_STR(op, str);
|
2003-02-01 09:49:15 +08:00
|
|
|
}
|
2009-05-11 07:08:52 +08:00
|
|
|
/* }}} */
|
2003-02-01 09:49:15 +08:00
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API zend_string* ZEND_FASTCALL zend_long_to_str(zend_long num) /* {{{ */
|
2014-05-23 19:10:50 +08:00
|
|
|
{
|
2017-05-18 22:59:59 +08:00
|
|
|
if ((zend_ulong)num <= 9) {
|
|
|
|
return ZSTR_CHAR((zend_uchar)'0' + (zend_uchar)num);
|
|
|
|
} else {
|
|
|
|
char buf[MAX_LENGTH_OF_LONG + 1];
|
|
|
|
char *res = zend_print_long_to_buf(buf + sizeof(buf) - 1, num);
|
|
|
|
return zend_string_init(res, buf + sizeof(buf) - 1 - res, 0);
|
|
|
|
}
|
2014-05-23 19:10:50 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API zend_uchar ZEND_FASTCALL is_numeric_str_function(const zend_string *str, zend_long *lval, double *dval) /* {{{ */ {
|
2015-06-30 18:59:27 +08:00
|
|
|
return is_numeric_string_ex(ZSTR_VAL(str), ZSTR_LEN(str), lval, dval, -1, NULL);
|
2014-07-11 20:32:20 +08:00
|
|
|
}
|
2015-01-12 15:34:46 +08:00
|
|
|
/* }}} */
|
2014-07-11 20:32:20 +08:00
|
|
|
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API zend_uchar ZEND_FASTCALL _is_numeric_string_ex(const char *str, size_t length, zend_long *lval, double *dval, int allow_errors, int *oflow_info) /* {{{ */
|
2014-09-19 02:19:51 +08:00
|
|
|
{
|
|
|
|
const char *ptr;
|
2012-04-17 21:45:53 +08:00
|
|
|
int digits = 0, dp_or_e = 0;
|
2014-09-19 02:19:51 +08:00
|
|
|
double local_dval = 0.0;
|
|
|
|
zend_uchar type;
|
2019-06-19 18:53:10 +08:00
|
|
|
zend_ulong tmp_lval = 0;
|
2015-05-05 16:09:18 +08:00
|
|
|
int neg = 0;
|
2014-09-19 02:19:51 +08:00
|
|
|
|
|
|
|
if (!length) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oflow_info != NULL) {
|
|
|
|
*oflow_info = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip any whitespace
|
|
|
|
* This is much faster than the isspace() function */
|
|
|
|
while (*str == ' ' || *str == '\t' || *str == '\n' || *str == '\r' || *str == '\v' || *str == '\f') {
|
|
|
|
str++;
|
|
|
|
length--;
|
|
|
|
}
|
|
|
|
ptr = str;
|
|
|
|
|
2015-05-05 16:09:18 +08:00
|
|
|
if (*ptr == '-') {
|
|
|
|
neg = 1;
|
|
|
|
ptr++;
|
|
|
|
} else if (*ptr == '+') {
|
2014-09-19 02:19:51 +08:00
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ZEND_IS_DIGIT(*ptr)) {
|
|
|
|
/* Skip any leading 0s */
|
|
|
|
while (*ptr == '0') {
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Count the number of digits. If a decimal point/exponent is found,
|
|
|
|
* it's a double. Otherwise, if there's a dval or no need to check for
|
|
|
|
* a full match, stop when there are too many digits for a long */
|
|
|
|
for (type = IS_LONG; !(digits >= MAX_LENGTH_OF_LONG && (dval || allow_errors == 1)); digits++, ptr++) {
|
|
|
|
check_digits:
|
2012-04-17 21:45:53 +08:00
|
|
|
if (ZEND_IS_DIGIT(*ptr)) {
|
2015-05-05 16:09:18 +08:00
|
|
|
tmp_lval = tmp_lval * 10 + (*ptr) - '0';
|
2014-09-19 02:19:51 +08:00
|
|
|
continue;
|
2012-04-17 21:45:53 +08:00
|
|
|
} else if (*ptr == '.' && dp_or_e < 1) {
|
|
|
|
goto process_double;
|
|
|
|
} else if ((*ptr == 'e' || *ptr == 'E') && dp_or_e < 2) {
|
|
|
|
const char *e = ptr + 1;
|
2014-09-19 02:19:51 +08:00
|
|
|
|
2012-04-17 21:45:53 +08:00
|
|
|
if (*e == '-' || *e == '+') {
|
|
|
|
ptr = e++;
|
|
|
|
}
|
|
|
|
if (ZEND_IS_DIGIT(*e)) {
|
|
|
|
goto process_double;
|
2014-09-19 02:19:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-04-17 21:45:53 +08:00
|
|
|
if (digits >= MAX_LENGTH_OF_LONG) {
|
2014-09-19 02:19:51 +08:00
|
|
|
if (oflow_info != NULL) {
|
2012-04-17 21:45:53 +08:00
|
|
|
*oflow_info = *str == '-' ? -1 : 1;
|
2014-09-19 02:19:51 +08:00
|
|
|
}
|
2012-04-17 21:45:53 +08:00
|
|
|
dp_or_e = -1;
|
|
|
|
goto process_double;
|
2014-09-19 02:19:51 +08:00
|
|
|
}
|
|
|
|
} else if (*ptr == '.' && ZEND_IS_DIGIT(ptr[1])) {
|
|
|
|
process_double:
|
|
|
|
type = IS_DOUBLE;
|
|
|
|
|
|
|
|
/* If there's a dval, do the conversion; else continue checking
|
|
|
|
* the digits if we need to check for a full match */
|
|
|
|
if (dval) {
|
|
|
|
local_dval = zend_strtod(str, &ptr);
|
|
|
|
} else if (allow_errors != 1 && dp_or_e != -1) {
|
|
|
|
dp_or_e = (*ptr++ == '.') ? 1 : 2;
|
|
|
|
goto check_digits;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ptr != str + length) {
|
|
|
|
if (!allow_errors) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (allow_errors == -1) {
|
|
|
|
zend_error(E_NOTICE, "A non well formed numeric value encountered");
|
2019-10-08 22:53:23 +08:00
|
|
|
if (EG(exception)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2014-09-19 02:19:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == IS_LONG) {
|
|
|
|
if (digits == MAX_LENGTH_OF_LONG - 1) {
|
|
|
|
int cmp = strcmp(&ptr[-digits], long_min_digits);
|
|
|
|
|
|
|
|
if (!(cmp < 0 || (cmp == 0 && *str == '-'))) {
|
|
|
|
if (dval) {
|
|
|
|
*dval = zend_strtod(str, NULL);
|
|
|
|
}
|
|
|
|
if (oflow_info != NULL) {
|
|
|
|
*oflow_info = *str == '-' ? -1 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return IS_DOUBLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lval) {
|
2015-05-05 16:09:18 +08:00
|
|
|
if (neg) {
|
|
|
|
tmp_lval = -tmp_lval;
|
|
|
|
}
|
2019-06-19 18:53:10 +08:00
|
|
|
*lval = (zend_long) tmp_lval;
|
2014-09-19 02:19:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return IS_LONG;
|
|
|
|
} else {
|
|
|
|
if (dval) {
|
|
|
|
*dval = local_dval;
|
|
|
|
}
|
|
|
|
|
|
|
|
return IS_DOUBLE;
|
|
|
|
}
|
|
|
|
}
|
2015-01-12 15:34:46 +08:00
|
|
|
/* }}} */
|
|
|
|
|
2017-12-31 12:35:25 +08:00
|
|
|
/*
|
2015-01-12 17:24:37 +08:00
|
|
|
* String matching - Sunday algorithm
|
|
|
|
* http://www.iti.fh-flensburg.de/lang/algorithmen/pattern/sundayen.htm
|
|
|
|
*/
|
|
|
|
static zend_always_inline void zend_memnstr_ex_pre(unsigned int td[], const char *needle, size_t needle_len, int reverse) /* {{{ */ {
|
2015-01-12 15:34:46 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
td[i] = needle_len + 1;
|
|
|
|
}
|
|
|
|
|
2015-01-12 17:24:37 +08:00
|
|
|
if (reverse) {
|
|
|
|
for (i = needle_len - 1; i >= 0; i--) {
|
|
|
|
td[(unsigned char)needle[i]] = i + 1;
|
|
|
|
}
|
|
|
|
} else {
|
2016-04-29 19:44:56 +08:00
|
|
|
size_t i;
|
|
|
|
|
2015-01-12 17:24:37 +08:00
|
|
|
for (i = 0; i < needle_len; i++) {
|
|
|
|
td[(unsigned char)needle[i]] = (int)needle_len - i;
|
|
|
|
}
|
2015-01-12 15:34:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2015-07-17 23:19:06 +08:00
|
|
|
ZEND_API const char* ZEND_FASTCALL zend_memnstr_ex(const char *haystack, const char *needle, size_t needle_len, const char *end) /* {{{ */
|
2015-01-12 15:34:46 +08:00
|
|
|
{
|
|
|
|
unsigned int td[256];
|
|
|
|
register size_t i;
|
2015-01-12 17:24:37 +08:00
|
|
|
register const char *p;
|
2015-01-12 15:34:46 +08:00
|
|
|
|
2017-11-29 06:10:50 +08:00
|
|
|
if (needle_len == 0 || (end - haystack) < needle_len) {
|
2015-01-12 15:34:46 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-01-12 17:24:37 +08:00
|
|
|
zend_memnstr_ex_pre(td, needle, needle_len, 0);
|
2015-01-12 15:34:46 +08:00
|
|
|
|
2015-01-12 17:24:37 +08:00
|
|
|
p = haystack;
|
2015-01-12 15:34:46 +08:00
|
|
|
end -= needle_len;
|
|
|
|
|
2015-01-12 17:24:37 +08:00
|
|
|
while (p <= end) {
|
2015-01-12 15:34:46 +08:00
|
|
|
for (i = 0; i < needle_len; i++) {
|
|
|
|
if (needle[i] != p[i]) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == needle_len) {
|
2015-01-12 17:24:37 +08:00
|
|
|
return p;
|
2015-01-12 15:34:46 +08:00
|
|
|
}
|
2016-05-21 23:46:00 +08:00
|
|
|
if (UNEXPECTED(p == end)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-01-12 17:24:37 +08:00
|
|
|
p += td[(unsigned char)(p[needle_len])];
|
2015-01-12 15:34:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2015-07-17 23:19:06 +08:00
|
|
|
ZEND_API const char* ZEND_FASTCALL zend_memnrstr_ex(const char *haystack, const char *needle, size_t needle_len, const char *end) /* {{{ */
|
2015-01-12 17:24:37 +08:00
|
|
|
{
|
|
|
|
unsigned int td[256];
|
|
|
|
register size_t i;
|
|
|
|
register const char *p;
|
|
|
|
|
2017-11-29 06:10:50 +08:00
|
|
|
if (needle_len == 0 || (end - haystack) < needle_len) {
|
2015-01-12 17:24:37 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
zend_memnstr_ex_pre(td, needle, needle_len, 1);
|
|
|
|
|
|
|
|
p = end;
|
|
|
|
p -= needle_len;
|
|
|
|
|
|
|
|
while (p >= haystack) {
|
|
|
|
for (i = 0; i < needle_len; i++) {
|
|
|
|
if (needle[i] != p[i]) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == needle_len) {
|
|
|
|
return (const char *)p;
|
|
|
|
}
|
2017-12-31 12:35:25 +08:00
|
|
|
|
2015-01-13 11:06:40 +08:00
|
|
|
if (UNEXPECTED(p == haystack)) {
|
2015-01-12 17:24:37 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
p -= td[(unsigned char)(p[-1])];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2014-09-19 02:19:51 +08:00
|
|
|
|
2015-02-26 06:28:47 +08:00
|
|
|
#if !ZEND_DVAL_TO_LVAL_CAST_OK
|
|
|
|
# if SIZEOF_ZEND_LONG == 4
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API zend_long ZEND_FASTCALL zend_dval_to_lval_slow(double d)
|
2015-02-26 06:28:47 +08:00
|
|
|
{
|
|
|
|
double two_pow_32 = pow(2., 32.),
|
|
|
|
dmod;
|
|
|
|
|
|
|
|
dmod = fmod(d, two_pow_32);
|
|
|
|
if (dmod < 0) {
|
|
|
|
/* we're going to make this number positive; call ceil()
|
|
|
|
* to simulate rounding towards 0 of the negative number */
|
2018-08-29 15:10:59 +08:00
|
|
|
dmod = ceil(dmod) + two_pow_32;
|
2015-02-26 06:28:47 +08:00
|
|
|
}
|
|
|
|
return (zend_long)(zend_ulong)dmod;
|
|
|
|
}
|
|
|
|
#else
|
2015-03-14 02:10:09 +08:00
|
|
|
ZEND_API zend_long ZEND_FASTCALL zend_dval_to_lval_slow(double d)
|
2015-02-26 06:28:47 +08:00
|
|
|
{
|
|
|
|
double two_pow_64 = pow(2., 64.),
|
|
|
|
dmod;
|
|
|
|
|
|
|
|
dmod = fmod(d, two_pow_64);
|
|
|
|
if (dmod < 0) {
|
|
|
|
/* no need to call ceil; original double must have had no
|
|
|
|
* fractional part, hence dmod does not have one either */
|
|
|
|
dmod += two_pow_64;
|
|
|
|
}
|
|
|
|
return (zend_long)(zend_ulong)dmod;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|