Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PHP NEWS

- BCMath:
. Simplify `bc_divide()` code. (SakiTakamachi)
. If the result is 0, n_scale is set to 0. (SakiTakamachi)

- CLI:
. Add --ini=diff to print INI settings changed from the builtin default.
Expand Down
23 changes: 10 additions & 13 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "zend.h"
#include "zend_execute.h"
#include "zend_API.h"
#include "zend_hash.h"
#include "zend_modules.h"
#include "zend_extensions.h"
#include "zend_constants.h"
Expand Down Expand Up @@ -3263,21 +3264,17 @@ ZEND_API zend_result zend_get_module_started(const char *module_name) /* {{{ */
}
/* }}} */

static int clean_module_class(zval *el, void *arg) /* {{{ */
{
zend_class_entry *ce = (zend_class_entry *)Z_PTR_P(el);
int module_number = *(int *)arg;
if (ce->type == ZEND_INTERNAL_CLASS && ce->info.internal.module->module_number == module_number) {
return ZEND_HASH_APPLY_REMOVE;
} else {
return ZEND_HASH_APPLY_KEEP;
}
}
/* }}} */

static void clean_module_classes(int module_number) /* {{{ */
{
zend_hash_apply_with_argument(EG(class_table), clean_module_class, (void *) &module_number);
/* Child classes may reuse structures from parent classes, so destroy in reverse order. */
Bucket *bucket;
ZEND_HASH_REVERSE_FOREACH_BUCKET(EG(class_table), bucket) {
zend_class_entry *ce = Z_CE(bucket->val);
if (ce->type == ZEND_INTERNAL_CLASS && ce->info.internal.module->module_number == module_number) {
zend_hash_del_bucket(EG(class_table), bucket);
}
} ZEND_HASH_FOREACH_END();

}
/* }}} */

Expand Down
9 changes: 5 additions & 4 deletions ext/bcmath/bcmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,8 @@ PHP_FUNCTION(bcround)
goto cleanup;
}

bc_round(num, precision, mode, &result);
RETVAL_NEW_STR(bc_num2str_ex(result, result->n_scale));
size_t scale = bc_round(num, precision, mode, &result);
RETVAL_NEW_STR(bc_num2str_ex(result, scale));

cleanup: {
bc_free_num(&num);
Expand Down Expand Up @@ -1799,9 +1799,10 @@ PHP_METHOD(BcMath_Number, round)
bcmath_number_obj_t *intern = get_bcmath_number_from_zval(ZEND_THIS);

bc_num ret = NULL;
bc_round(intern->num, precision, rounding_mode, &ret);
size_t scale = bc_round(intern->num, precision, rounding_mode, &ret);
bc_rm_trailing_zeros(ret);

bcmath_number_obj_t *new_intern = bcmath_number_new_obj(ret, ret->n_scale);
bcmath_number_obj_t *new_intern = bcmath_number_new_obj(ret, scale);
RETURN_OBJ(&new_intern->std);
}

Expand Down
2 changes: 1 addition & 1 deletion ext/bcmath/libbcmath/src/bcmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ bool bc_divmod(bc_num num1, bc_num num2, bc_num *quo, bc_num *rem, size_t scale)

bc_num bc_floor_or_ceil(bc_num num, bool is_floor);

void bc_round(bc_num num, zend_long places, zend_long mode, bc_num *result);
size_t bc_round(bc_num num, zend_long places, zend_long mode, bc_num *result);

typedef enum {
OK,
Expand Down
1 change: 1 addition & 0 deletions ext/bcmath/libbcmath/src/div.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ bool bc_divide(bc_num numerator, bc_num divisor, bc_num *quot, size_t scale)
_bc_rm_leading_zeros(*quot);
if (bc_is_zero(*quot)) {
(*quot)->n_sign = PLUS;
(*quot)->n_scale = 0;
} else {
(*quot)->n_sign = numerator->n_sign == divisor->n_sign ? PLUS : MINUS;
}
Expand Down
1 change: 1 addition & 0 deletions ext/bcmath/libbcmath/src/divmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ bool bc_divmod(bc_num num1, bc_num num2, bc_num *quot, bc_num *rem, size_t scale
(*rem)->n_scale = MIN(scale, (*rem)->n_scale);
if (bc_is_zero(*rem)) {
(*rem)->n_sign = PLUS;
(*rem)->n_scale = 0;
}

return true;
Expand Down
1 change: 1 addition & 0 deletions ext/bcmath/libbcmath/src/recmul.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ bc_num bc_multiply(bc_num n1, bc_num n2, size_t scale)
_bc_rm_leading_zeros(prod);
if (bc_is_zero(prod)) {
prod->n_sign = PLUS;
prod->n_scale = 0;
}
return prod;
}
Expand Down
24 changes: 15 additions & 9 deletions ext/bcmath/libbcmath/src/round.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#include "private.h"
#include <stddef.h>

void bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result)
/* Returns the scale of the value after rounding. */
size_t bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result)
{
/* clear result */
bc_free_num(result);
Expand All @@ -43,19 +44,19 @@ void bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result)
case PHP_ROUND_HALF_ODD:
case PHP_ROUND_TOWARD_ZERO:
*result = bc_copy_num(BCG(_zero_));
return;
return 0;

case PHP_ROUND_CEILING:
if (num->n_sign == MINUS) {
*result = bc_copy_num(BCG(_zero_));
return;
return 0;
}
break;

case PHP_ROUND_FLOOR:
if (num->n_sign == PLUS) {
*result = bc_copy_num(BCG(_zero_));
return;
return 0;
}
break;

Expand All @@ -67,7 +68,7 @@ void bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result)

if (bc_is_zero(num)) {
*result = bc_copy_num(BCG(_zero_));
return;
return 0;
}

/* If precision is -3, it becomes 1000. */
Expand All @@ -78,7 +79,7 @@ void bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result)
}
(*result)->n_value[0] = 1;
(*result)->n_sign = num->n_sign;
return;
return 0;
}

/* Just like bcadd('1', '1', 4) becomes '2.0000', it pads with zeros at the end if necessary. */
Expand All @@ -90,7 +91,7 @@ void bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result)
(*result)->n_sign = num->n_sign;
memcpy((*result)->n_value, num->n_value, num->n_len + num->n_scale);
}
return;
return precision;
}

/*
Expand Down Expand Up @@ -222,7 +223,12 @@ void bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result)
}

check_zero:
if (bc_is_zero(*result)) {
(*result)->n_sign = PLUS;
{
size_t scale = (*result)->n_scale;
if (bc_is_zero(*result)) {
(*result)->n_sign = PLUS;
(*result)->n_scale = 0;
}
return scale;
}
}
12 changes: 12 additions & 0 deletions ext/dl_test/dl_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,22 @@ PHP_METHOD(DlTest, test)
RETURN_STR(retval);
}

PHP_METHOD(DlTestSuperClass, test)
{
ZEND_PARSE_PARAMETERS_NONE();

RETURN_NULL();
}

/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(dl_test)
{
zend_class_entry *ce;

register_class_DlTest();
ce = register_class_DlTestSuperClass();
register_class_DlTestSubClass(ce);
register_class_DlTestAliasedClass();

/* Test backwards compatibility */
if (getenv("PHP_DL_TEST_USE_OLD_REGISTER_INI_ENTRIES")) {
Expand Down
15 changes: 13 additions & 2 deletions ext/dl_test/dl_test.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* @undocumentable
*/

/** @var int */
const DL_TEST_CONST = 42;

function dl_test_test1(): void {}

function dl_test_test2(string $str = ""): string {}
Expand All @@ -13,5 +16,13 @@ class DlTest {
public function test(string $str = ""): string {}
}

/** @var int */
const DL_TEST_CONST = 42;
class DlTestSuperClass {
public int $a;
public function test(string $str = ""): string {}
}

class DlTestSubClass extends DlTestSuperClass {
}

class DlTestAliasedClass {
}
46 changes: 45 additions & 1 deletion ext/dl_test/dl_test_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading