summaryrefslogtreecommitdiff
path: root/Zend/zend_operators.c
diff options
context:
space:
mode:
Diffstat (limited to 'Zend/zend_operators.c')
-rw-r--r--Zend/zend_operators.c313
1 files changed, 136 insertions, 177 deletions
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c
index ce47c26854..5dbe1bd90d 100644
--- a/Zend/zend_operators.c
+++ b/Zend/zend_operators.c
@@ -86,7 +86,7 @@ ZEND_API int zend_atoi(const char *str, int str_len) /* {{{ */
if (!str_len) {
str_len = strlen(str);
}
- retval = strtol(str, NULL, 0);
+ retval = ZEND_STRTOL(str, NULL, 0);
if (str_len>0) {
switch (str[str_len-1]) {
case 'g':
@@ -107,14 +107,14 @@ ZEND_API int zend_atoi(const char *str, int str_len) /* {{{ */
}
/* }}} */
-ZEND_API long zend_atol(const char *str, int str_len) /* {{{ */
+ZEND_API zend_long zend_atol(const char *str, int str_len) /* {{{ */
{
- long retval;
+ zend_long retval;
if (!str_len) {
str_len = strlen(str);
}
- retval = strtol(str, NULL, 0);
+ retval = ZEND_STRTOL(str, NULL, 0);
if (str_len>0) {
switch (str[str_len-1]) {
case 'g':
@@ -135,52 +135,6 @@ ZEND_API long zend_atol(const char *str, int str_len) /* {{{ */
}
/* }}} */
-ZEND_API double zend_string_to_double(const char *number, zend_uint length) /* {{{ */
-{
- double divisor = 10.0;
- double result = 0.0;
- double exponent;
- const char *end = number+length;
- const char *digit = number;
-
- if (!length) {
- return result;
- }
-
- while (digit < end) {
- if ((*digit <= '9' && *digit >= '0')) {
- result *= 10;
- result += *digit - '0';
- } else if (*digit == '.') {
- digit++;
- break;
- } else if (toupper(*digit) == 'E') {
- exponent = (double) atoi(digit+1);
- result *= pow(10.0, exponent);
- return result;
- } else {
- return result;
- }
- digit++;
- }
-
- while (digit < end) {
- if ((*digit <= '9' && *digit >= '0')) {
- result += (*digit - '0') / divisor;
- divisor *= 10;
- } else if (toupper(*digit) == 'E') {
- exponent = (double) atoi(digit+1);
- result *= pow(10.0, exponent);
- return result;
- } else {
- return result;
- }
- digit++;
- }
- return result;
-}
-/* }}} */
-
ZEND_API void convert_scalar_to_number(zval *op TSRMLS_DC) /* {{{ */
{
try_again:
@@ -201,7 +155,7 @@ try_again:
if ((Z_TYPE_INFO_P(op)=is_numeric_string(str->val, str->len, &Z_LVAL_P(op), &Z_DVAL_P(op), 1)) == 0) {
ZVAL_LONG(op, 0);
}
- STR_RELEASE(str);
+ zend_string_release(str);
break;
}
case IS_NULL:
@@ -213,7 +167,7 @@ try_again:
break;
case IS_RESOURCE:
{
- long l = Z_RES_HANDLE_P(op);
+ zend_long l = Z_RES_HANDLE_P(op);
zval_ptr_dtor(op);
ZVAL_LONG(op, l);
}
@@ -283,7 +237,7 @@ try_again:
ZVAL_LONG(&holder, zend_dval_to_lval(Z_DVAL_P(op)));\
break; \
case IS_STRING: \
- ZVAL_LONG(&holder, strtol(Z_STRVAL_P(op), NULL, 10));\
+ ZVAL_LONG(&holder, ZEND_STRTOL(Z_STRVAL_P(op), NULL, 10));\
break; \
case IS_ARRAY: \
ZVAL_LONG(&holder, zend_hash_num_elements(Z_ARRVAL_P(op))?1:0); \
@@ -378,7 +332,7 @@ ZEND_API void convert_to_long(zval *op) /* {{{ */
ZEND_API void convert_to_long_base(zval *op, int base) /* {{{ */
{
- long tmp;
+ zend_long tmp;
switch (Z_TYPE_P(op)) {
case IS_NULL:
@@ -389,7 +343,7 @@ ZEND_API void convert_to_long_base(zval *op, int base) /* {{{ */
ZVAL_LONG(op, 1);
break;
case IS_RESOURCE: {
- long l = Z_RES_HANDLE_P(op);
+ zend_long l = Z_RES_HANDLE_P(op);
zval_ptr_dtor(op);
ZVAL_LONG(op, l);
}
@@ -405,8 +359,8 @@ ZEND_API void convert_to_long_base(zval *op, int base) /* {{{ */
{
zend_string *str = Z_STR_P(op);
- ZVAL_LONG(op, strtol(str->val, NULL, base));
- STR_RELEASE(str);
+ ZVAL_LONG(op, ZEND_STRTOL(str->val, NULL, base));
+ zend_string_release(str);
}
break;
case IS_ARRAY:
@@ -464,7 +418,7 @@ ZEND_API void convert_to_double(zval *op) /* {{{ */
zend_string *str = Z_STR_P(op);
ZVAL_DOUBLE(op, zend_strtod(str->val, NULL));
- STR_RELEASE(str);
+ zend_string_release(str);
}
break;
case IS_ARRAY:
@@ -527,7 +481,7 @@ ZEND_API void convert_to_boolean(zval *op) /* {{{ */
ZVAL_BOOL(op, 0);
break;
case IS_RESOURCE: {
- long l = (Z_RES_HANDLE_P(op) ? 1 : 0);
+ zend_long l = (Z_RES_HANDLE_P(op) ? 1 : 0);
zval_ptr_dtor(op);
ZVAL_BOOL(op, l);
@@ -549,7 +503,7 @@ ZEND_API void convert_to_boolean(zval *op) /* {{{ */
} else {
ZVAL_BOOL(op, 1);
}
- STR_RELEASE(str);
+ zend_string_release(str);
}
break;
case IS_ARRAY:
@@ -586,6 +540,7 @@ ZEND_API void _convert_to_cstring(zval *op ZEND_FILE_LINE_DC) /* {{{ */
ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC) /* {{{ */
{
switch (Z_TYPE_P(op)) {
+ case IS_UNDEF:
case IS_NULL:
case IS_FALSE: {
TSRMLS_FETCH();
@@ -593,14 +548,14 @@ ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC) /* {{{ */
break;
}
case IS_TRUE:
- ZVAL_NEW_STR(op, STR_INIT("1", 1, 0));
+ ZVAL_NEW_STR(op, zend_string_init("1", 1, 0));
break;
case IS_STRING:
break;
case IS_RESOURCE: {
char buf[sizeof("Resource id #") + MAX_LENGTH_OF_LONG];
- int len = snprintf(buf, sizeof(buf), "Resource id #%ld", Z_RES_HANDLE_P(op));
- ZVAL_NEW_STR(op, STR_INIT(buf, len, 0));
+ int len = snprintf(buf, sizeof(buf), "Resource id #" ZEND_LONG_FMT, Z_RES_HANDLE_P(op));
+ ZVAL_NEW_STR(op, zend_string_init(buf, len, 0));
break;
}
case IS_LONG: {
@@ -620,7 +575,7 @@ ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC) /* {{{ */
case IS_ARRAY:
zend_error(E_NOTICE, "Array to string conversion");
zval_dtor(op);
- ZVAL_NEW_STR(op, STR_INIT("Array", sizeof("Array")-1, 0));
+ ZVAL_NEW_STR(op, zend_string_init("Array", sizeof("Array")-1, 0));
break;
case IS_OBJECT: {
zval dst;
@@ -634,7 +589,7 @@ ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC) /* {{{ */
} else {
zend_error(E_NOTICE, "Object of class %s to string conversion", Z_OBJCE_P(op)->name->val);
zval_dtor(op);
- ZVAL_NEW_STR(op, STR_INIT("Object", sizeof("Object")-1, 0));
+ ZVAL_NEW_STR(op, zend_string_init("Object", sizeof("Object")-1, 0));
}
break;
}
@@ -716,7 +671,7 @@ ZEND_API void convert_to_object(zval *op) /* {{{ */
memcpy(properties, Z_ARRVAL_P(op), sizeof(HashTable));
object_and_properties_init(op, zend_standard_class_def, properties);
if (--GC_REFCOUNT(arr) == 0) {
- efree(arr);
+ efree_size(arr, sizeof(zend_array));
}
break;
}
@@ -784,7 +739,7 @@ ZEND_API void multi_convert_to_string_ex(int argc, ...) /* {{{ */
}
/* }}} */
-ZEND_API long _zval_get_long_func(zval *op TSRMLS_DC) /* {{{ */
+ZEND_API zend_long _zval_get_long_func(zval *op TSRMLS_DC) /* {{{ */
{
try_again:
switch (Z_TYPE_P(op)) {
@@ -800,7 +755,7 @@ try_again:
case IS_DOUBLE:
return zend_dval_to_lval(Z_DVAL_P(op));
case IS_STRING:
- return strtol(Z_STRVAL_P(op), NULL, 10);
+ return ZEND_STRTOL(Z_STRVAL_P(op), NULL, 10);
case IS_ARRAY:
return zend_hash_num_elements(Z_ARRVAL_P(op)) ? 1 : 0;
case IS_OBJECT:
@@ -868,19 +823,20 @@ ZEND_API zend_string *_zval_get_string_func(zval *op TSRMLS_DC) /* {{{ */
{
try_again:
switch (Z_TYPE_P(op)) {
+ case IS_UNDEF:
case IS_NULL:
case IS_FALSE:
return STR_EMPTY_ALLOC();
case IS_STRING:
- return STR_COPY(Z_STR_P(op));
+ return zend_string_copy(Z_STR_P(op));
case IS_TRUE:
- return STR_INIT("1", 1, 0);
+ return zend_string_init("1", 1, 0);
case IS_RESOURCE: {
char buf[sizeof("Resource id #") + MAX_LENGTH_OF_LONG];
int len;
- len = snprintf(buf, sizeof(buf), "Resource id #%ld", Z_RES_HANDLE_P(op));
- return STR_INIT(buf, len, 0);
+ len = snprintf(buf, sizeof(buf), "Resource id #" ZEND_LONG_FMT, Z_RES_HANDLE_P(op));
+ return zend_string_init(buf, len, 0);
}
case IS_LONG: {
return zend_long_to_str(Z_LVAL_P(op));
@@ -890,7 +846,7 @@ try_again:
}
case IS_ARRAY:
zend_error(E_NOTICE, "Array to string conversion");
- return STR_INIT("Array", sizeof("Array")-1, 0);
+ return zend_string_init("Array", sizeof("Array")-1, 0);
case IS_OBJECT: {
zval tmp;
if (Z_OBJ_HT_P(op)->cast_object) {
@@ -926,7 +882,7 @@ ZEND_API int add_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ *
while (1) {
switch (TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2))) {
case TYPE_PAIR(IS_LONG, IS_LONG): {
- long lval = Z_LVAL_P(op1) + Z_LVAL_P(op2);
+ zend_long lval = Z_LVAL_P(op1) + Z_LVAL_P(op2);
/* check for overflow by comparing sign bits */
if ((Z_LVAL_P(op1) & LONG_SIGN_MASK) == (Z_LVAL_P(op2) & LONG_SIGN_MASK)
@@ -990,7 +946,7 @@ ZEND_API int sub_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ *
while (1) {
switch (TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2))) {
case TYPE_PAIR(IS_LONG, IS_LONG): {
- long lval = Z_LVAL_P(op1) - Z_LVAL_P(op2);
+ zend_long lval = Z_LVAL_P(op1) - Z_LVAL_P(op2);
/* check for overflow by comparing sign bits */
if ((Z_LVAL_P(op1) & LONG_SIGN_MASK) != (Z_LVAL_P(op2) & LONG_SIGN_MASK)
@@ -1043,7 +999,7 @@ ZEND_API int mul_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ *
while (1) {
switch (TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2))) {
case TYPE_PAIR(IS_LONG, IS_LONG): {
- long overflow;
+ 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;
@@ -1091,7 +1047,7 @@ ZEND_API int pow_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ *
switch (TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2))) {
case TYPE_PAIR(IS_LONG, IS_LONG):
if (Z_LVAL_P(op2) >= 0) {
- long l1 = 1, l2 = Z_LVAL_P(op1), i = Z_LVAL_P(op2);
+ zend_long l1 = 1, l2 = Z_LVAL_P(op1), i = Z_LVAL_P(op2);
if (i == 0) {
ZVAL_LONG(result, 1L);
@@ -1102,7 +1058,7 @@ ZEND_API int pow_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ *
}
while (i >= 1) {
- long overflow;
+ zend_long overflow;
double dval = 0.0;
if (i % 2) {
@@ -1182,9 +1138,9 @@ ZEND_API int div_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ *
zend_error(E_WARNING, "Division by zero");
ZVAL_BOOL(result, 0);
return FAILURE; /* division by zero */
- } else if (Z_LVAL_P(op2) == -1 && Z_LVAL_P(op1) == LONG_MIN) {
+ } else if (Z_LVAL_P(op2) == -1 && Z_LVAL_P(op1) == ZEND_LONG_MIN) {
/* Prevent overflow error/crash */
- ZVAL_DOUBLE(result, (double) LONG_MIN / -1);
+ ZVAL_DOUBLE(result, (double) ZEND_LONG_MIN / -1);
return SUCCESS;
}
if (Z_LVAL_P(op1) % Z_LVAL_P(op2) == 0) { /* integer */
@@ -1244,7 +1200,7 @@ ZEND_API int div_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ *
ZEND_API int mod_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
{
zval op1_copy, op2_copy;
- long op1_lval;
+ zend_long op1_lval;
if (Z_TYPE_P(op1) != IS_LONG || Z_TYPE_P(op2) != IS_LONG) {
ZEND_TRY_BINARY_OBJECT_OPERATION(ZEND_MOD);
@@ -1276,7 +1232,7 @@ ZEND_API int mod_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ *
ZEND_API int boolean_xor_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
{
zval op1_copy, op2_copy;
- long op1_lval;
+ zend_long op1_lval;
if ((Z_TYPE_P(op1) != IS_FALSE && Z_TYPE_P(op1) != IS_TRUE) ||
(Z_TYPE_P(op2) != IS_FALSE && Z_TYPE_P(op2) != IS_TRUE)) {
@@ -1324,10 +1280,10 @@ ZEND_API int bitwise_not_function(zval *result, zval *op1 TSRMLS_DC) /* {{{ */
ZVAL_LONG(result, ~zend_dval_to_lval(Z_DVAL_P(op1)));
return SUCCESS;
case IS_STRING: {
- int i;
+ size_t i;
zval op1_copy = *op1;
- ZVAL_NEW_STR(result, STR_ALLOC(Z_STRLEN(op1_copy), 0));
+ ZVAL_NEW_STR(result, zend_string_alloc(Z_STRLEN(op1_copy), 0));
for (i = 0; i < Z_STRLEN(op1_copy); i++) {
Z_STRVAL_P(result)[i] = ~Z_STRVAL(op1_copy)[i];
}
@@ -1346,12 +1302,12 @@ ZEND_API int bitwise_not_function(zval *result, zval *op1 TSRMLS_DC) /* {{{ */
ZEND_API int bitwise_or_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
{
zval op1_copy, op2_copy;
- long op1_lval;
+ zend_long op1_lval;
if (Z_TYPE_P(op1) == IS_STRING && Z_TYPE_P(op2) == IS_STRING) {
zval *longer, *shorter;
zend_string *str;
- int i;
+ size_t i;
if (Z_STRLEN_P(op1) >= Z_STRLEN_P(op2)) {
longer = op1;
@@ -1361,13 +1317,13 @@ ZEND_API int bitwise_or_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /
shorter = op1;
}
- str = STR_ALLOC(Z_STRLEN_P(longer), 0);
+ str = zend_string_alloc(Z_STRLEN_P(longer), 0);
for (i = 0; i < Z_STRLEN_P(shorter); i++) {
str->val[i] = Z_STRVAL_P(longer)[i] | Z_STRVAL_P(shorter)[i];
}
memcpy(str->val + i, Z_STRVAL_P(longer) + i, Z_STRLEN_P(longer) - i + 1);
if (result==op1) {
- STR_RELEASE(Z_STR_P(result));
+ zend_string_release(Z_STR_P(result));
}
ZVAL_NEW_STR(result, str);
return SUCCESS;
@@ -1391,12 +1347,12 @@ ZEND_API int bitwise_or_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /
ZEND_API int bitwise_and_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
{
zval op1_copy, op2_copy;
- long op1_lval;
+ zend_long op1_lval;
if (Z_TYPE_P(op1) == IS_STRING && Z_TYPE_P(op2) == IS_STRING) {
zval *longer, *shorter;
zend_string *str;
- int i;
+ size_t i;
if (Z_STRLEN_P(op1) >= Z_STRLEN_P(op2)) {
longer = op1;
@@ -1406,13 +1362,13 @@ ZEND_API int bitwise_and_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
shorter = op1;
}
- str = STR_ALLOC(Z_STRLEN_P(shorter), 0);
+ str = zend_string_alloc(Z_STRLEN_P(shorter), 0);
for (i = 0; i < Z_STRLEN_P(shorter); i++) {
str->val[i] = Z_STRVAL_P(shorter)[i] & Z_STRVAL_P(longer)[i];
}
str->val[i] = 0;
if (result==op1) {
- STR_RELEASE(Z_STR_P(result));
+ zend_string_release(Z_STR_P(result));
}
ZVAL_NEW_STR(result, str);
return SUCCESS;
@@ -1436,12 +1392,12 @@ ZEND_API int bitwise_and_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
ZEND_API int bitwise_xor_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
{
zval op1_copy, op2_copy;
- long op1_lval;
+ zend_long op1_lval;
if (Z_TYPE_P(op1) == IS_STRING && Z_TYPE_P(op2) == IS_STRING) {
zval *longer, *shorter;
zend_string *str;
- int i;
+ size_t i;
if (Z_STRLEN_P(op1) >= Z_STRLEN_P(op2)) {
longer = op1;
@@ -1451,13 +1407,13 @@ ZEND_API int bitwise_xor_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
shorter = op1;
}
- str = STR_ALLOC(Z_STRLEN_P(shorter), 0);
+ str = zend_string_alloc(Z_STRLEN_P(shorter), 0);
for (i = 0; i < Z_STRLEN_P(shorter); i++) {
str->val[i] = Z_STRVAL_P(shorter)[i] ^ Z_STRVAL_P(longer)[i];
}
str->val[i] = 0;
if (result==op1) {
- STR_RELEASE(Z_STR_P(result));
+ zend_string_release(Z_STR_P(result));
}
ZVAL_NEW_STR(result, str);
return SUCCESS;
@@ -1481,7 +1437,7 @@ ZEND_API int bitwise_xor_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
ZEND_API int shift_left_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
{
zval op1_copy, op2_copy;
- long op1_lval;
+ zend_long op1_lval;
if (Z_TYPE_P(op1) != IS_LONG || Z_TYPE_P(op2) != IS_LONG) {
ZEND_TRY_BINARY_OBJECT_OPERATION(ZEND_SL);
@@ -1513,7 +1469,7 @@ ZEND_API int shift_left_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /
ZEND_API int shift_right_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
{
zval op1_copy, op2_copy;
- long op1_lval;
+ zend_long op1_lval;
if (Z_TYPE_P(op1) != IS_LONG || Z_TYPE_P(op2) != IS_LONG) {
ZEND_TRY_BINARY_OBJECT_OPERATION(ZEND_SR);
@@ -1545,8 +1501,8 @@ ZEND_API int shift_right_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
/* must support result==op1 */
ZEND_API int add_char_to_string(zval *result, const zval *op1, const zval *op2) /* {{{ */
{
- int length = Z_STRLEN_P(op1) + 1;
- zend_string *buf = STR_REALLOC(Z_STR_P(op1), length, 0);
+ size_t length = Z_STRLEN_P(op1) + 1;
+ zend_string *buf = zend_string_realloc(Z_STR_P(op1), length, 0);
buf->val[length - 1] = (char) Z_LVAL_P(op2);
buf->val[length] = 0;
@@ -1558,9 +1514,9 @@ ZEND_API int add_char_to_string(zval *result, const zval *op1, const zval *op2)
/* must support result==op1 */
ZEND_API int add_string_to_string(zval *result, const zval *op1, const zval *op2) /* {{{ */
{
- int op1_len = Z_STRLEN_P(op1);
- int length = op1_len + Z_STRLEN_P(op2);
- zend_string *buf = STR_REALLOC(Z_STR_P(op1), length, 0);
+ size_t op1_len = Z_STRLEN_P(op1);
+ size_t length = op1_len + Z_STRLEN_P(op2);
+ zend_string *buf = zend_string_realloc(Z_STR_P(op1), length, 0);
memcpy(buf->val + op1_len, Z_STRVAL_P(op2), Z_STRLEN_P(op2));
buf->val[length] = 0;
@@ -1599,29 +1555,33 @@ ZEND_API int concat_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{
op2 = &op2_copy;
}
- if (result==op1 && !IS_INTERNED(Z_STR_P(op1))) { /* special case, perform operations on result */
- uint op1_len = Z_STRLEN_P(op1);
- uint op2_len = Z_STRLEN_P(op2);
- uint res_len = op1_len + op2_len;
+ {
+ size_t op1_len = Z_STRLEN_P(op1);
+ size_t op2_len = Z_STRLEN_P(op2);
+ size_t result_len = op1_len + op2_len;
+ zend_string *result_str;
- if (Z_STRLEN_P(result) < 0 || (int) (op1_len + op2_len) < 0) {
- ZVAL_EMPTY_STRING(result);
- zend_error(E_ERROR, "String size overflow");
+ if (op1_len > SIZE_MAX - op2_len) {
+ zend_error_noreturn(E_ERROR, "String size overflow");
}
- Z_STR_P(result) = STR_REALLOC(Z_STR_P(result), res_len, 0 );
- Z_TYPE_INFO_P(result) = IS_STRING_EX;
- memcpy(Z_STRVAL_P(result) + op1_len, Z_STRVAL_P(op2), op2_len);
- Z_STRVAL_P(result)[res_len]=0;
- } else {
- int length = Z_STRLEN_P(op1) + Z_STRLEN_P(op2);
- zend_string *buf = STR_ALLOC(length, 0);
+ if (result == op1 && !IS_INTERNED(Z_STR_P(result))) {
+ /* special case, perform operations on result */
+ result_str = zend_string_realloc(Z_STR_P(result), result_len, 0);
+ } else {
+ result_str = zend_string_alloc(result_len, 0);
+ memcpy(result_str->val, Z_STRVAL_P(op1), op1_len);
+ }
+
+ /* 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. */
+ ZVAL_NEW_STR(result, result_str);
- memcpy(buf->val, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
- memcpy(buf->val + Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2));
- buf->val[length] = 0;
- ZVAL_NEW_STR(result, buf);
+ memcpy(result_str->val + op1_len, Z_STRVAL_P(op2), op2_len);
+ result_str->val[result_len] = '\0';
}
+
if (UNEXPECTED(use_copy1)) {
zval_dtor(op1);
}
@@ -1643,8 +1603,8 @@ ZEND_API int string_compare_function_ex(zval *result, zval *op1, zval *op2, zend
ZVAL_LONG(result, zend_binary_strcmp(str1->val, str1->len, str2->val, str2->len));
}
- STR_RELEASE(str1);
- STR_RELEASE(str2);
+ zend_string_release(str1);
+ zend_string_release(str2);
return SUCCESS;
}
/* }}} */
@@ -1664,8 +1624,8 @@ ZEND_API int string_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_D
ZVAL_LONG(result, zend_binary_strcmp(str1->val, str1->len, str2->val, str2->len));
- STR_RELEASE(str1);
- STR_RELEASE(str2);
+ zend_string_release(str1);
+ zend_string_release(str2);
}
return SUCCESS;
}
@@ -1686,8 +1646,8 @@ ZEND_API int string_case_compare_function(zval *result, zval *op1, zval *op2 TSR
ZVAL_LONG(result, zend_binary_strcasecmp_l(str1->val, str1->len, str2->val, str1->len));
- STR_RELEASE(str1);
- STR_RELEASE(str2);
+ zend_string_release(str1);
+ zend_string_release(str2);
}
return SUCCESS;
}
@@ -1701,8 +1661,8 @@ ZEND_API int string_locale_compare_function(zval *result, zval *op1, zval *op2 T
ZVAL_LONG(result, strcoll(str1->val, str2->val));
- STR_RELEASE(str1);
- STR_RELEASE(str2);
+ zend_string_release(str1);
+ zend_string_release(str2);
return SUCCESS;
}
/* }}} */
@@ -2037,7 +1997,7 @@ ZEND_API int is_smaller_or_equal_function(zval *result, zval *op1, zval *op2 TSR
ZEND_API zend_bool instanceof_function_ex(const zend_class_entry *instance_ce, const zend_class_entry *ce, zend_bool interfaces_only TSRMLS_DC) /* {{{ */
{
- zend_uint i;
+ uint32_t i;
for (i=0; i<instance_ce->num_interfaces; i++) {
if (instanceof_function(instance_ce->interfaces[i], ce TSRMLS_CC)) {
@@ -2070,31 +2030,31 @@ ZEND_API zend_bool instanceof_function(const zend_class_entry *instance_ce, cons
static void increment_string(zval *str) /* {{{ */
{
int carry=0;
- int pos=Z_STRLEN_P(str)-1;
+ size_t pos=Z_STRLEN_P(str)-1;
char *s;
zend_string *t;
int last=0; /* Shut up the compiler warning */
int ch;
if (Z_STRLEN_P(str) == 0) {
- STR_RELEASE(Z_STR_P(str));
- Z_STR_P(str) = STR_INIT("1", sizeof("1")-1, 0);
+ zend_string_release(Z_STR_P(str));
+ Z_STR_P(str) = zend_string_init("1", sizeof("1")-1, 0);
Z_TYPE_INFO_P(str) = IS_STRING_EX;
return;
}
if (IS_INTERNED(Z_STR_P(str))) {
- Z_STR_P(str) = STR_INIT(Z_STRVAL_P(str), Z_STRLEN_P(str), 0);
+ Z_STR_P(str) = zend_string_init(Z_STRVAL_P(str), Z_STRLEN_P(str), 0);
Z_TYPE_INFO_P(str) = IS_STRING_EX;
} else if (Z_REFCOUNT_P(str) > 1) {
Z_DELREF_P(str);
- Z_STR_P(str) = STR_INIT(Z_STRVAL_P(str), Z_STRLEN_P(str), 0);
+ Z_STR_P(str) = zend_string_init(Z_STRVAL_P(str), Z_STRLEN_P(str), 0);
} else {
- STR_FORGET_HASH_VAL(Z_STR_P(str));
+ zend_string_forget_hash_val(Z_STR_P(str));
}
s = Z_STRVAL_P(str);
- while (pos >= 0) {
+ do {
ch = s[pos];
if (ch >= 'a' && ch <= 'z') {
if (ch == 'z') {
@@ -2130,11 +2090,10 @@ static void increment_string(zval *str) /* {{{ */
if (carry == 0) {
break;
}
- pos--;
- }
+ } while (pos-- > 0);
if (carry) {
- t = STR_ALLOC(Z_STRLEN_P(str)+1, 0);
+ t = zend_string_alloc(Z_STRLEN_P(str)+1, 0);
memcpy(t->val + 1, Z_STRVAL_P(str), Z_STRLEN_P(str));
t->val[Z_STRLEN_P(str) + 1] = '\0';
switch (last) {
@@ -2148,7 +2107,7 @@ static void increment_string(zval *str) /* {{{ */
t->val[0] = 'a';
break;
}
- STR_FREE(Z_STR_P(str));
+ zend_string_free(Z_STR_P(str));
ZVAL_NEW_STR(str, t);
}
}
@@ -2159,7 +2118,7 @@ ZEND_API int increment_function(zval *op1) /* {{{ */
try_again:
switch (Z_TYPE_P(op1)) {
case IS_LONG:
- if (Z_LVAL_P(op1) == LONG_MAX) {
+ if (Z_LVAL_P(op1) == ZEND_LONG_MAX) {
/* switch to double */
double d = (double)Z_LVAL_P(op1);
ZVAL_DOUBLE(op1, d+1);
@@ -2174,13 +2133,13 @@ try_again:
ZVAL_LONG(op1, 1);
break;
case IS_STRING: {
- long lval;
+ zend_long lval;
double dval;
switch (is_numeric_string(Z_STRVAL_P(op1), Z_STRLEN_P(op1), &lval, &dval, 0)) {
case IS_LONG:
- STR_RELEASE(Z_STR_P(op1));
- if (lval == LONG_MAX) {
+ zend_string_release(Z_STR_P(op1));
+ if (lval == ZEND_LONG_MAX) {
/* switch to double */
double d = (double)lval;
ZVAL_DOUBLE(op1, d+1);
@@ -2189,7 +2148,7 @@ try_again:
}
break;
case IS_DOUBLE:
- STR_RELEASE(Z_STR_P(op1));
+ zend_string_release(Z_STR_P(op1));
ZVAL_DOUBLE(op1, dval+1);
break;
default:
@@ -2224,13 +2183,13 @@ try_again:
ZEND_API int decrement_function(zval *op1) /* {{{ */
{
- long lval;
+ zend_long lval;
double dval;
try_again:
switch (Z_TYPE_P(op1)) {
case IS_LONG:
- if (Z_LVAL_P(op1) == LONG_MIN) {
+ if (Z_LVAL_P(op1) == ZEND_LONG_MIN) {
double d = (double)Z_LVAL_P(op1);
ZVAL_DOUBLE(op1, d-1);
} else {
@@ -2242,14 +2201,14 @@ try_again:
break;
case IS_STRING: /* Like perl we only support string increment */
if (Z_STRLEN_P(op1) == 0) { /* consider as 0 */
- STR_RELEASE(Z_STR_P(op1));
+ zend_string_release(Z_STR_P(op1));
ZVAL_LONG(op1, -1);
break;
}
switch (is_numeric_string(Z_STRVAL_P(op1), Z_STRLEN_P(op1), &lval, &dval, 0)) {
case IS_LONG:
- STR_RELEASE(Z_STR_P(op1));
- if (lval == LONG_MIN) {
+ zend_string_release(Z_STR_P(op1));
+ if (lval == ZEND_LONG_MIN) {
double d = (double)lval;
ZVAL_DOUBLE(op1, d-1);
} else {
@@ -2257,7 +2216,7 @@ try_again:
}
break;
case IS_DOUBLE:
- STR_RELEASE(Z_STR_P(op1));
+ zend_string_release(Z_STR_P(op1));
ZVAL_DOUBLE(op1, dval - 1);
break;
}
@@ -2301,7 +2260,7 @@ ZEND_API void zend_update_current_locale(void) /* {{{ */
/* }}} */
#endif
-ZEND_API char *zend_str_tolower_copy(char *dest, const char *source, unsigned int length) /* {{{ */
+ZEND_API char *zend_str_tolower_copy(char *dest, const char *source, size_t length) /* {{{ */
{
register unsigned char *str = (unsigned char*)source;
register unsigned char *result = (unsigned char*)dest;
@@ -2316,13 +2275,13 @@ ZEND_API char *zend_str_tolower_copy(char *dest, const char *source, unsigned in
}
/* }}} */
-ZEND_API char *zend_str_tolower_dup(const char *source, unsigned int length) /* {{{ */
+ZEND_API char *zend_str_tolower_dup(const char *source, size_t length) /* {{{ */
{
return zend_str_tolower_copy((char *)emalloc(length+1), source, length);
}
/* }}} */
-ZEND_API void zend_str_tolower(char *str, unsigned int length) /* {{{ */
+ZEND_API void zend_str_tolower(char *str, size_t length) /* {{{ */
{
register unsigned char *p = (unsigned char*)str;
register unsigned char *end = p + length;
@@ -2334,7 +2293,7 @@ ZEND_API void zend_str_tolower(char *str, unsigned int length) /* {{{ */
}
/* }}} */
-ZEND_API int zend_binary_strcmp(const char *s1, uint len1, const char *s2, uint len2) /* {{{ */
+ZEND_API int zend_binary_strcmp(const char *s1, size_t len1, const char *s2, size_t len2) /* {{{ */
{
int retval;
@@ -2343,14 +2302,14 @@ ZEND_API int zend_binary_strcmp(const char *s1, uint len1, const char *s2, uint
}
retval = memcmp(s1, s2, MIN(len1, len2));
if (!retval) {
- return (len1 - len2);
+ return (int)(len1 - len2);
} else {
return retval;
}
}
/* }}} */
-ZEND_API int zend_binary_strncmp(const char *s1, uint len1, const char *s2, uint len2, uint length) /* {{{ */
+ZEND_API int zend_binary_strncmp(const char *s1, size_t len1, const char *s2, size_t len2, size_t length) /* {{{ */
{
int retval;
@@ -2359,16 +2318,16 @@ ZEND_API int zend_binary_strncmp(const char *s1, uint len1, const char *s2, uint
}
retval = memcmp(s1, s2, MIN(length, MIN(len1, len2)));
if (!retval) {
- return (MIN(length, len1) - MIN(length, len2));
+ return (int)(MIN(length, len1) - MIN(length, len2));
} else {
return retval;
}
}
/* }}} */
-ZEND_API int zend_binary_strcasecmp(const char *s1, uint len1, const char *s2, uint len2) /* {{{ */
+ZEND_API int zend_binary_strcasecmp(const char *s1, size_t len1, const char *s2, size_t len2) /* {{{ */
{
- int len;
+ size_t len;
int c1, c2;
if (s1 == s2) {
@@ -2384,13 +2343,13 @@ ZEND_API int zend_binary_strcasecmp(const char *s1, uint len1, const char *s2, u
}
}
- return len1 - len2;
+ return (int)(len1 - len2);
}
/* }}} */
-ZEND_API int zend_binary_strncasecmp(const char *s1, uint len1, const char *s2, uint len2, uint length) /* {{{ */
+ZEND_API int zend_binary_strncasecmp(const char *s1, size_t len1, const char *s2, size_t len2, size_t length) /* {{{ */
{
- int len;
+ size_t len;
int c1, c2;
if (s1 == s2) {
@@ -2405,13 +2364,13 @@ ZEND_API int zend_binary_strncasecmp(const char *s1, uint len1, const char *s2,
}
}
- return MIN(length, len1) - MIN(length, len2);
+ return (int)(MIN(length, len1) - MIN(length, len2));
}
/* }}} */
-ZEND_API int zend_binary_strcasecmp_l(const char *s1, uint len1, const char *s2, uint len2) /* {{{ */
+ZEND_API int zend_binary_strcasecmp_l(const char *s1, size_t len1, const char *s2, size_t len2) /* {{{ */
{
- int len;
+ size_t len;
int c1, c2;
if (s1 == s2) {
@@ -2427,13 +2386,13 @@ ZEND_API int zend_binary_strcasecmp_l(const char *s1, uint len1, const char *s2,
}
}
- return len1 - len2;
+ return (int)(len1 - len2);
}
/* }}} */
-ZEND_API int zend_binary_strncasecmp_l(const char *s1, uint len1, const char *s2, uint len2, uint length) /* {{{ */
+ZEND_API int zend_binary_strncasecmp_l(const char *s1, size_t len1, const char *s2, size_t len2, size_t length) /* {{{ */
{
- int len;
+ size_t len;
int c1, c2;
if (s1 == s2) {
@@ -2448,7 +2407,7 @@ ZEND_API int zend_binary_strncasecmp_l(const char *s1, uint len1, const char *s2
}
}
- return MIN(length, len1) - MIN(length, len2);
+ return (int)(MIN(length, len1) - MIN(length, len2));
}
/* }}} */
@@ -2480,12 +2439,12 @@ ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2) /* {{{ */
{
int ret1, ret2;
int oflow1, oflow2;
- long lval1 = 0, lval2 = 0;
+ zend_long lval1 = 0, lval2 = 0;
double dval1 = 0.0, dval2 = 0.0;
if ((ret1=is_numeric_string_ex(Z_STRVAL_P(s1), Z_STRLEN_P(s1), &lval1, &dval1, 0, &oflow1)) &&
(ret2=is_numeric_string_ex(Z_STRVAL_P(s2), Z_STRLEN_P(s2), &lval2, &dval2, 0, &oflow2))) {
-#if ULONG_MAX == 0xFFFFFFFF
+#if ZEND_ULONG_MAX == 0xFFFFFFFF
if (oflow1 != 0 && oflow1 == oflow2 && dval1 - dval2 == 0. &&
((oflow1 == 1 && dval1 > 9007199254740991. /*0x1FFFFFFFFFFFFF*/)
|| (oflow1 == -1 && dval1 < -9007199254740991.))) {
@@ -2582,16 +2541,16 @@ ZEND_API void zend_locale_sprintf_double(zval *op ZEND_FILE_LINE_DC) /* {{{ */
}
/* }}} */
-ZEND_API zend_string *zend_long_to_str(long num) /* {{{ */
+ZEND_API zend_string *zend_long_to_str(zend_long num) /* {{{ */
{
char buf[MAX_LENGTH_OF_LONG + 1];
char *res;
- _zend_print_signed_to_buf(buf + sizeof(buf) - 1, num, unsigned long, res);
- return STR_INIT(res, buf + sizeof(buf) - 1 - res, 0);
+ _zend_print_signed_to_buf(buf + sizeof(buf) - 1, num, zend_ulong, res);
+ return zend_string_init(res, buf + sizeof(buf) - 1 - res, 0);
}
/* }}} */
-ZEND_API zend_uchar is_numeric_str_function(const zend_string *str, long *lval, double *dval) {
+ZEND_API zend_uchar is_numeric_str_function(const zend_string *str, zend_long *lval, double *dval) {
return is_numeric_string_ex(str->val, str->len, lval, dval, -1, NULL);
}