From 6096a2019f9c6f19eeed9eff1bc96bec3568449a Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Wed, 9 Apr 2025 16:38:41 +0900 Subject: [PATCH 1/3] Use const qualifiers appropriately --- ext/bcmath/bcmath.c | 14 +++++++------- ext/bcmath/libbcmath/src/add.c | 2 +- ext/bcmath/libbcmath/src/compare.c | 10 ++++------ ext/bcmath/libbcmath/src/div.c | 10 +++++----- ext/bcmath/libbcmath/src/divmod.c | 4 ++-- ext/bcmath/libbcmath/src/doaddsub.c | 16 ++++++++-------- ext/bcmath/libbcmath/src/floor_or_ceil.c | 2 +- ext/bcmath/libbcmath/src/private.h | 6 +++--- ext/bcmath/libbcmath/src/recmul.c | 8 ++++---- ext/bcmath/libbcmath/src/round.c | 2 +- ext/bcmath/libbcmath/src/sub.c | 2 +- ext/bcmath/libbcmath/src/zero.c | 4 ++-- 12 files changed, 39 insertions(+), 41 deletions(-) diff --git a/ext/bcmath/bcmath.c b/ext/bcmath/bcmath.c index 962f839ba83f..f6a0bba0bc30 100644 --- a/ext/bcmath/bcmath.c +++ b/ext/bcmath/bcmath.c @@ -1019,7 +1019,7 @@ static void bcmath_number_register_class(void) } static zend_always_inline void bcmath_number_add_internal( - bc_num n1, bc_num n2, bc_num *ret, + const bc_num n1, const bc_num n2, bc_num *ret, size_t n1_full_scale, size_t n2_full_scale, size_t *scale, bool auto_scale ) { if (auto_scale) { @@ -1031,7 +1031,7 @@ static zend_always_inline void bcmath_number_add_internal( } static zend_always_inline void bcmath_number_sub_internal( - bc_num n1, bc_num n2, bc_num *ret, + const bc_num n1, const bc_num n2, bc_num *ret, size_t n1_full_scale, size_t n2_full_scale, size_t *scale, bool auto_scale ) { if (auto_scale) { @@ -1043,7 +1043,7 @@ static zend_always_inline void bcmath_number_sub_internal( } static zend_always_inline zend_result bcmath_number_mul_internal( - bc_num n1, bc_num n2, bc_num *ret, + const bc_num n1, const bc_num n2, bc_num *ret, size_t n1_full_scale, size_t n2_full_scale, size_t *scale, bool auto_scale ) { if (auto_scale) { @@ -1060,7 +1060,7 @@ static zend_always_inline zend_result bcmath_number_mul_internal( } static zend_always_inline zend_result bcmath_number_div_internal( - bc_num n1, bc_num n2, bc_num *ret, + const bc_num n1, const bc_num n2, bc_num *ret, size_t n1_full_scale, size_t *scale, bool auto_scale ) { if (auto_scale) { @@ -1083,7 +1083,7 @@ static zend_always_inline zend_result bcmath_number_div_internal( } static zend_always_inline zend_result bcmath_number_mod_internal( - bc_num n1, bc_num n2, bc_num *ret, + const bc_num n1, const bc_num n2, bc_num *ret, size_t n1_full_scale, size_t n2_full_scale, size_t *scale, bool auto_scale ) { if (auto_scale) { @@ -1164,7 +1164,7 @@ static zend_always_inline bcmath_number_obj_t *bcmath_number_new_obj(bc_num ret, return intern; } -static zend_result bcmath_number_parse_num(zval *zv, zend_object **obj, zend_string **str, zend_long *lval) +static zend_result bcmath_number_parse_num(const zval *zv, zend_object **obj, zend_string **str, zend_long *lval) { if (Z_TYPE_P(zv) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zv), bcmath_number_ce)) { *obj = Z_OBJ_P(zv); @@ -1372,7 +1372,7 @@ static int bcmath_number_compare(zval *op1, zval *op2) } static zend_always_inline zend_result bc_num_from_obj_or_str_or_long_with_err( - bc_num *num, size_t *scale, zend_object *obj, zend_string *str, zend_long lval, uint32_t arg_num) + bc_num *num, size_t *scale, const zend_object *obj, const zend_string *str, zend_long lval, uint32_t arg_num) { size_t full_scale = 0; if (UNEXPECTED(bc_num_from_obj_or_str_or_long(num, &full_scale, obj, str, lval) == FAILURE)) { diff --git a/ext/bcmath/libbcmath/src/add.c b/ext/bcmath/libbcmath/src/add.c index 9a11b98b4877..dd5d93058840 100644 --- a/ext/bcmath/libbcmath/src/add.c +++ b/ext/bcmath/libbcmath/src/add.c @@ -39,7 +39,7 @@ N1 is added to N2 and the result placed into RESULT. SCALE_MIN is the minimum scale for the result. */ -bc_num bc_add(bc_num n1, bc_num n2, size_t scale_min) +bc_num bc_add(const bc_num n1, const bc_num n2, size_t scale_min) { bc_num sum = NULL; diff --git a/ext/bcmath/libbcmath/src/compare.c b/ext/bcmath/libbcmath/src/compare.c index 2c24dab77705..ec17f30d962c 100644 --- a/ext/bcmath/libbcmath/src/compare.c +++ b/ext/bcmath/libbcmath/src/compare.c @@ -39,10 +39,8 @@ than N2 and +1 if N1 is greater than N2. If USE_SIGN is false, just compare the magnitudes. */ -bcmath_compare_result _bc_do_compare(bc_num n1, bc_num n2, size_t scale, bool use_sign) +bcmath_compare_result _bc_do_compare(const bc_num n1, const bc_num n2, size_t scale, bool use_sign) { - char *n1ptr, *n2ptr; - /* First, compare signs. */ if (use_sign && n1->n_sign != n2->n_sign) { /* @@ -91,8 +89,8 @@ bcmath_compare_result _bc_do_compare(bc_num n1, bc_num n2, size_t scale, bool us /* If we get here, they have the same number of integer digits. check the integer part and the equal length part of the fraction. */ size_t count = n1->n_len + MIN (n1_scale, n2_scale); - n1ptr = n1->n_value; - n2ptr = n2->n_value; + const char *n1ptr = n1->n_value; + const char *n2ptr = n2->n_value; while ((count > 0) && (*n1ptr == *n2ptr)) { n1ptr++; @@ -151,7 +149,7 @@ bcmath_compare_result _bc_do_compare(bc_num n1, bc_num n2, size_t scale, bool us /* This is the "user callable" routine to compare numbers N1 and N2. */ -bcmath_compare_result bc_compare(bc_num n1, bc_num n2, size_t scale) +bcmath_compare_result bc_compare(const bc_num n1, const bc_num n2, size_t scale) { return _bc_do_compare(n1, n2, scale, true); } diff --git a/ext/bcmath/libbcmath/src/div.c b/ext/bcmath/libbcmath/src/div.c index 1cf8a434c860..05cd211ccf47 100644 --- a/ext/bcmath/libbcmath/src/div.c +++ b/ext/bcmath/libbcmath/src/div.c @@ -70,7 +70,7 @@ static inline void bc_fast_div( */ static inline void bc_standard_div( BC_VECTOR *numerator_vectors, size_t numerator_arr_size, - BC_VECTOR *divisor_vectors, size_t divisor_arr_size, size_t divisor_len, + const BC_VECTOR *divisor_vectors, size_t divisor_arr_size, size_t divisor_len, BC_VECTOR *quot_vectors, size_t quot_arr_size ) { size_t numerator_top_index = numerator_arr_size - 1; @@ -300,7 +300,7 @@ static void bc_do_div( } } -static inline void bc_divide_by_one(bc_num numerator, bc_num *quot, size_t quot_scale) +static inline void bc_divide_by_one(const bc_num numerator, bc_num *quot, size_t quot_scale) { quot_scale = MIN(numerator->n_scale, quot_scale); *quot = bc_new_num_nonzeroed(numerator->n_len, quot_scale); @@ -332,7 +332,7 @@ static inline void bc_divide_by_pow_10( } } -bool bc_divide(bc_num numerator, bc_num divisor, bc_num *quot, size_t scale) +bool bc_divide(const bc_num numerator, const bc_num divisor, bc_num *quot, size_t scale) { /* divide by zero */ if (bc_is_zero(divisor)) { @@ -354,10 +354,10 @@ bool bc_divide(bc_num numerator, bc_num divisor, bc_num *quot, size_t scale) return true; } - char *numeratorptr = numerator->n_value; + const char *numeratorptr = numerator->n_value; size_t numerator_size = numerator->n_len + quot_scale + divisor->n_scale; - char *divisorptr = divisor->n_value; + const char *divisorptr = divisor->n_value; size_t divisor_size = divisor->n_len + divisor->n_scale; /* check and remove numerator leading zeros */ diff --git a/ext/bcmath/libbcmath/src/divmod.c b/ext/bcmath/libbcmath/src/divmod.c index 477ec30e916e..64fcd831392e 100644 --- a/ext/bcmath/libbcmath/src/divmod.c +++ b/ext/bcmath/libbcmath/src/divmod.c @@ -41,7 +41,7 @@ true otherwise for success. */ -bool bc_divmod(bc_num num1, bc_num num2, bc_num *quot, bc_num *rem, size_t scale) +bool bc_divmod(const bc_num num1, const bc_num num2, bc_num *quot, bc_num *rem, size_t scale) { bc_num quotient = NULL; bc_num temp; @@ -84,7 +84,7 @@ bool bc_divmod(bc_num num1, bc_num num2, bc_num *quot, bc_num *rem, size_t scale /* Modulo for numbers. This computes NUM1 % NUM2 and puts the result in RESULT. */ -bool bc_modulo(bc_num num1, bc_num num2, bc_num *result, size_t scale) +bool bc_modulo(const bc_num num1, const bc_num num2, bc_num *result, size_t scale) { return bc_divmod(num1, num2, NULL, result, scale); } diff --git a/ext/bcmath/libbcmath/src/doaddsub.c b/ext/bcmath/libbcmath/src/doaddsub.c index feb50120c70c..051a0bfe8865 100644 --- a/ext/bcmath/libbcmath/src/doaddsub.c +++ b/ext/bcmath/libbcmath/src/doaddsub.c @@ -38,7 +38,7 @@ returned. The signs of N1 and N2 are ignored. SCALE_MIN is to set the minimum scale of the result. */ -bc_num _bc_do_add(bc_num n1, bc_num n2) +bc_num _bc_do_add(const bc_num n1, const bc_num n2) { bc_num sum; size_t sum_len = MAX(n1->n_len, n2->n_len) + 1; @@ -46,7 +46,7 @@ bc_num _bc_do_add(bc_num n1, bc_num n2) size_t min_len = MIN (n1->n_len, n2->n_len); size_t min_scale = MIN(n1->n_scale, n2->n_scale); size_t min_bytes = min_len + min_scale; - char *n1ptr, *n2ptr, *sumptr; + char *sumptr; bool carry = 0; size_t count; @@ -54,8 +54,8 @@ bc_num _bc_do_add(bc_num n1, bc_num n2) sum = bc_new_num_nonzeroed(sum_len, sum_scale); /* Start with the fraction part. Initialize the pointers. */ - n1ptr = (char *) (n1->n_value + n1->n_len + n1->n_scale - 1); - n2ptr = (char *) (n2->n_value + n2->n_len + n2->n_scale - 1); + const char *n1ptr = (char *) (n1->n_value + n1->n_len + n1->n_scale - 1); + const char *n2ptr = (char *) (n2->n_value + n2->n_len + n2->n_scale - 1); sumptr = (char *) (sum->n_value + sum_scale + sum_len - 1); /* Add the fraction part. First copy the longer fraction.*/ @@ -169,7 +169,7 @@ bc_num _bc_do_add(bc_num n1, bc_num n2) returned. The signs of N1 and N2 are ignored. Also, N1 is assumed to be larger than N2. SCALE_MIN is the minimum scale of the result. */ -bc_num _bc_do_sub(bc_num n1, bc_num n2) +bc_num _bc_do_sub(const bc_num n1, const bc_num n2) { bc_num diff; /* The caller is guaranteed that n1 is always large. */ @@ -182,14 +182,14 @@ bc_num _bc_do_sub(bc_num n1, bc_num n2) size_t borrow = 0; size_t count; int val; - char *n1ptr, *n2ptr, *diffptr; + char *diffptr; /* Allocate temporary storage. */ diff = bc_new_num_nonzeroed(diff_len, diff_scale); /* Initialize the subtract. */ - n1ptr = (char *) (n1->n_value + n1->n_len + n1->n_scale - 1); - n2ptr = (char *) (n2->n_value + n2->n_len + n2->n_scale - 1); + const char *n1ptr = (char *) (n1->n_value + n1->n_len + n1->n_scale - 1); + const char *n2ptr = (char *) (n2->n_value + n2->n_len + n2->n_scale - 1); diffptr = (char *) (diff->n_value + diff_len + diff_scale - 1); /* Take care of the longer scaled number. */ diff --git a/ext/bcmath/libbcmath/src/floor_or_ceil.c b/ext/bcmath/libbcmath/src/floor_or_ceil.c index 98dc94601ac7..3f9addf51383 100644 --- a/ext/bcmath/libbcmath/src/floor_or_ceil.c +++ b/ext/bcmath/libbcmath/src/floor_or_ceil.c @@ -18,7 +18,7 @@ #include "private.h" #include -bc_num bc_floor_or_ceil(bc_num num, bool is_floor) +bc_num bc_floor_or_ceil(const bc_num num, bool is_floor) { /* Initialize result */ bc_num result = bc_new_num(num->n_len, 0); diff --git a/ext/bcmath/libbcmath/src/private.h b/ext/bcmath/libbcmath/src/private.h index 91facfb2f8b4..b5b1f1b71eb8 100644 --- a/ext/bcmath/libbcmath/src/private.h +++ b/ext/bcmath/libbcmath/src/private.h @@ -81,9 +81,9 @@ static const BC_VECTOR BC_POW_10_LUT[9] = { /* routines */ -bcmath_compare_result _bc_do_compare (bc_num n1, bc_num n2, size_t scale, bool use_sign); -bc_num _bc_do_add (bc_num n1, bc_num n2); -bc_num _bc_do_sub (bc_num n1, bc_num n2); +bcmath_compare_result _bc_do_compare (const bc_num n1, const bc_num n2, size_t scale, bool use_sign); +bc_num _bc_do_add (const bc_num n1, const bc_num n2); +bc_num _bc_do_sub (const bc_num n1, const bc_num n2); void _bc_rm_leading_zeros (bc_num num); #endif diff --git a/ext/bcmath/libbcmath/src/recmul.c b/ext/bcmath/libbcmath/src/recmul.c index 26ce1641db41..75e48d1557a2 100644 --- a/ext/bcmath/libbcmath/src/recmul.c +++ b/ext/bcmath/libbcmath/src/recmul.c @@ -52,7 +52,7 @@ static inline void bc_mul_carry_calc(BC_VECTOR *prod_vector, size_t prod_arr_siz * If the n_values of n1 and n2 are both 4 (32-bit) or 8 (64-bit) digits or less, * the calculation will be performed at high speed without using an array. */ -static inline void bc_fast_mul(bc_num n1, size_t n1len, bc_num n2, size_t n2len, bc_num *prod) +static inline void bc_fast_mul(const bc_num n1, size_t n1len, const bc_num n2, size_t n2len, bc_num *prod) { const char *n1end = n1->n_value + n1len - 1; const char *n2end = n2->n_value + n2len - 1; @@ -76,7 +76,7 @@ static inline void bc_fast_mul(bc_num n1, size_t n1len, bc_num n2, size_t n2len, * Equivalent of bc_fast_mul for small numbers to perform computations * without using array. */ -static inline void bc_fast_square(bc_num n1, size_t n1len, bc_num *prod) +static inline void bc_fast_square(const bc_num n1, size_t n1len, bc_num *prod) { const char *n1end = n1->n_value + n1len - 1; @@ -119,7 +119,7 @@ static inline void bc_mul_finish_from_vector(BC_VECTOR *prod_vector, size_t prod * Multiply and add these groups of numbers to perform multiplication fast. * How much to shift the digits when adding values can be calculated from the index of the array. */ -static void bc_standard_mul(bc_num n1, size_t n1len, bc_num n2, size_t n2len, bc_num *prod) +static void bc_standard_mul(const bc_num n1, size_t n1len, const bc_num n2, size_t n2len, bc_num *prod) { size_t i; const char *n1end = n1->n_value + n1len - 1; @@ -181,7 +181,7 @@ static void bc_standard_mul(bc_num n1, size_t n1len, bc_num n2, size_t n2len, bc } /** This is bc_standard_mul implementation for square */ -static void bc_standard_square(bc_num n1, size_t n1len, bc_num *prod) +static void bc_standard_square(const bc_num n1, size_t n1len, bc_num *prod) { size_t i; const char *n1end = n1->n_value + n1len - 1; diff --git a/ext/bcmath/libbcmath/src/round.c b/ext/bcmath/libbcmath/src/round.c index 44df6036cbe3..9e807bfb9540 100644 --- a/ext/bcmath/libbcmath/src/round.c +++ b/ext/bcmath/libbcmath/src/round.c @@ -19,7 +19,7 @@ #include /* Returns the scale of the value after rounding. */ -size_t bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result) +size_t bc_round(const bc_num num, zend_long precision, zend_long mode, bc_num *result) { /* clear result */ bc_free_num(result); diff --git a/ext/bcmath/libbcmath/src/sub.c b/ext/bcmath/libbcmath/src/sub.c index 9e71c4856f81..dfb9f4038a81 100644 --- a/ext/bcmath/libbcmath/src/sub.c +++ b/ext/bcmath/libbcmath/src/sub.c @@ -39,7 +39,7 @@ N2 is subtracted from N1 and the result placed in RESULT. SCALE_MIN is the minimum scale for the result. */ -bc_num bc_sub(bc_num n1, bc_num n2, size_t scale_min) +bc_num bc_sub(const bc_num n1, const bc_num n2, size_t scale_min) { bc_num diff = NULL; diff --git a/ext/bcmath/libbcmath/src/zero.c b/ext/bcmath/libbcmath/src/zero.c index 550ea97df674..62b891e414d8 100644 --- a/ext/bcmath/libbcmath/src/zero.c +++ b/ext/bcmath/libbcmath/src/zero.c @@ -35,7 +35,7 @@ /* In some places we need to check if the number NUM is zero. */ -bool bc_is_zero_for_scale(bc_num num, size_t scale) +bool bc_is_zero_for_scale(const bc_num num, size_t scale) { size_t count; char *nptr; @@ -55,7 +55,7 @@ bool bc_is_zero_for_scale(bc_num num, size_t scale) return count == 0; } -bool bc_is_zero(bc_num num) +bool bc_is_zero(const bc_num num) { return bc_is_zero_for_scale(num, num->n_scale); } From 10e18fd28570fc72c34521816a189966765a98c5 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Thu, 10 Apr 2025 17:37:56 +0900 Subject: [PATCH 2/3] Changed const bc_num back to bc_num --- ext/bcmath/bcmath.c | 10 +++++----- ext/bcmath/libbcmath/src/add.c | 2 +- ext/bcmath/libbcmath/src/compare.c | 4 ++-- ext/bcmath/libbcmath/src/div.c | 4 ++-- ext/bcmath/libbcmath/src/divmod.c | 4 ++-- ext/bcmath/libbcmath/src/doaddsub.c | 4 ++-- ext/bcmath/libbcmath/src/floor_or_ceil.c | 2 +- ext/bcmath/libbcmath/src/private.h | 6 +++--- ext/bcmath/libbcmath/src/recmul.c | 8 ++++---- ext/bcmath/libbcmath/src/round.c | 2 +- ext/bcmath/libbcmath/src/sqrt.c | 2 +- ext/bcmath/libbcmath/src/sub.c | 2 +- ext/bcmath/libbcmath/src/zero.c | 4 ++-- 13 files changed, 27 insertions(+), 27 deletions(-) diff --git a/ext/bcmath/bcmath.c b/ext/bcmath/bcmath.c index f6a0bba0bc30..1e0e6d14d81e 100644 --- a/ext/bcmath/bcmath.c +++ b/ext/bcmath/bcmath.c @@ -1019,7 +1019,7 @@ static void bcmath_number_register_class(void) } static zend_always_inline void bcmath_number_add_internal( - const bc_num n1, const bc_num n2, bc_num *ret, + bc_num n1, bc_num n2, bc_num *ret, size_t n1_full_scale, size_t n2_full_scale, size_t *scale, bool auto_scale ) { if (auto_scale) { @@ -1031,7 +1031,7 @@ static zend_always_inline void bcmath_number_add_internal( } static zend_always_inline void bcmath_number_sub_internal( - const bc_num n1, const bc_num n2, bc_num *ret, + bc_num n1, bc_num n2, bc_num *ret, size_t n1_full_scale, size_t n2_full_scale, size_t *scale, bool auto_scale ) { if (auto_scale) { @@ -1043,7 +1043,7 @@ static zend_always_inline void bcmath_number_sub_internal( } static zend_always_inline zend_result bcmath_number_mul_internal( - const bc_num n1, const bc_num n2, bc_num *ret, + bc_num n1, bc_num n2, bc_num *ret, size_t n1_full_scale, size_t n2_full_scale, size_t *scale, bool auto_scale ) { if (auto_scale) { @@ -1060,7 +1060,7 @@ static zend_always_inline zend_result bcmath_number_mul_internal( } static zend_always_inline zend_result bcmath_number_div_internal( - const bc_num n1, const bc_num n2, bc_num *ret, + bc_num n1, bc_num n2, bc_num *ret, size_t n1_full_scale, size_t *scale, bool auto_scale ) { if (auto_scale) { @@ -1083,7 +1083,7 @@ static zend_always_inline zend_result bcmath_number_div_internal( } static zend_always_inline zend_result bcmath_number_mod_internal( - const bc_num n1, const bc_num n2, bc_num *ret, + bc_num n1, bc_num n2, bc_num *ret, size_t n1_full_scale, size_t n2_full_scale, size_t *scale, bool auto_scale ) { if (auto_scale) { diff --git a/ext/bcmath/libbcmath/src/add.c b/ext/bcmath/libbcmath/src/add.c index dd5d93058840..9a11b98b4877 100644 --- a/ext/bcmath/libbcmath/src/add.c +++ b/ext/bcmath/libbcmath/src/add.c @@ -39,7 +39,7 @@ N1 is added to N2 and the result placed into RESULT. SCALE_MIN is the minimum scale for the result. */ -bc_num bc_add(const bc_num n1, const bc_num n2, size_t scale_min) +bc_num bc_add(bc_num n1, bc_num n2, size_t scale_min) { bc_num sum = NULL; diff --git a/ext/bcmath/libbcmath/src/compare.c b/ext/bcmath/libbcmath/src/compare.c index ec17f30d962c..06ef24678208 100644 --- a/ext/bcmath/libbcmath/src/compare.c +++ b/ext/bcmath/libbcmath/src/compare.c @@ -39,7 +39,7 @@ than N2 and +1 if N1 is greater than N2. If USE_SIGN is false, just compare the magnitudes. */ -bcmath_compare_result _bc_do_compare(const bc_num n1, const bc_num n2, size_t scale, bool use_sign) +bcmath_compare_result _bc_do_compare(bc_num n1, bc_num n2, size_t scale, bool use_sign) { /* First, compare signs. */ if (use_sign && n1->n_sign != n2->n_sign) { @@ -149,7 +149,7 @@ bcmath_compare_result _bc_do_compare(const bc_num n1, const bc_num n2, size_t sc /* This is the "user callable" routine to compare numbers N1 and N2. */ -bcmath_compare_result bc_compare(const bc_num n1, const bc_num n2, size_t scale) +bcmath_compare_result bc_compare(bc_num n1, bc_num n2, size_t scale) { return _bc_do_compare(n1, n2, scale, true); } diff --git a/ext/bcmath/libbcmath/src/div.c b/ext/bcmath/libbcmath/src/div.c index 05cd211ccf47..24ec9a64d77f 100644 --- a/ext/bcmath/libbcmath/src/div.c +++ b/ext/bcmath/libbcmath/src/div.c @@ -300,7 +300,7 @@ static void bc_do_div( } } -static inline void bc_divide_by_one(const bc_num numerator, bc_num *quot, size_t quot_scale) +static inline void bc_divide_by_one(bc_num numerator, bc_num *quot, size_t quot_scale) { quot_scale = MIN(numerator->n_scale, quot_scale); *quot = bc_new_num_nonzeroed(numerator->n_len, quot_scale); @@ -332,7 +332,7 @@ static inline void bc_divide_by_pow_10( } } -bool bc_divide(const bc_num numerator, const bc_num divisor, bc_num *quot, size_t scale) +bool bc_divide(bc_num numerator, bc_num divisor, bc_num *quot, size_t scale) { /* divide by zero */ if (bc_is_zero(divisor)) { diff --git a/ext/bcmath/libbcmath/src/divmod.c b/ext/bcmath/libbcmath/src/divmod.c index 64fcd831392e..477ec30e916e 100644 --- a/ext/bcmath/libbcmath/src/divmod.c +++ b/ext/bcmath/libbcmath/src/divmod.c @@ -41,7 +41,7 @@ true otherwise for success. */ -bool bc_divmod(const bc_num num1, const bc_num num2, bc_num *quot, bc_num *rem, size_t scale) +bool bc_divmod(bc_num num1, bc_num num2, bc_num *quot, bc_num *rem, size_t scale) { bc_num quotient = NULL; bc_num temp; @@ -84,7 +84,7 @@ bool bc_divmod(const bc_num num1, const bc_num num2, bc_num *quot, bc_num *rem, /* Modulo for numbers. This computes NUM1 % NUM2 and puts the result in RESULT. */ -bool bc_modulo(const bc_num num1, const bc_num num2, bc_num *result, size_t scale) +bool bc_modulo(bc_num num1, bc_num num2, bc_num *result, size_t scale) { return bc_divmod(num1, num2, NULL, result, scale); } diff --git a/ext/bcmath/libbcmath/src/doaddsub.c b/ext/bcmath/libbcmath/src/doaddsub.c index 051a0bfe8865..f516f2bda72d 100644 --- a/ext/bcmath/libbcmath/src/doaddsub.c +++ b/ext/bcmath/libbcmath/src/doaddsub.c @@ -38,7 +38,7 @@ returned. The signs of N1 and N2 are ignored. SCALE_MIN is to set the minimum scale of the result. */ -bc_num _bc_do_add(const bc_num n1, const bc_num n2) +bc_num _bc_do_add(bc_num n1, bc_num n2) { bc_num sum; size_t sum_len = MAX(n1->n_len, n2->n_len) + 1; @@ -169,7 +169,7 @@ bc_num _bc_do_add(const bc_num n1, const bc_num n2) returned. The signs of N1 and N2 are ignored. Also, N1 is assumed to be larger than N2. SCALE_MIN is the minimum scale of the result. */ -bc_num _bc_do_sub(const bc_num n1, const bc_num n2) +bc_num _bc_do_sub(bc_num n1, bc_num n2) { bc_num diff; /* The caller is guaranteed that n1 is always large. */ diff --git a/ext/bcmath/libbcmath/src/floor_or_ceil.c b/ext/bcmath/libbcmath/src/floor_or_ceil.c index 3f9addf51383..98dc94601ac7 100644 --- a/ext/bcmath/libbcmath/src/floor_or_ceil.c +++ b/ext/bcmath/libbcmath/src/floor_or_ceil.c @@ -18,7 +18,7 @@ #include "private.h" #include -bc_num bc_floor_or_ceil(const bc_num num, bool is_floor) +bc_num bc_floor_or_ceil(bc_num num, bool is_floor) { /* Initialize result */ bc_num result = bc_new_num(num->n_len, 0); diff --git a/ext/bcmath/libbcmath/src/private.h b/ext/bcmath/libbcmath/src/private.h index b5b1f1b71eb8..91facfb2f8b4 100644 --- a/ext/bcmath/libbcmath/src/private.h +++ b/ext/bcmath/libbcmath/src/private.h @@ -81,9 +81,9 @@ static const BC_VECTOR BC_POW_10_LUT[9] = { /* routines */ -bcmath_compare_result _bc_do_compare (const bc_num n1, const bc_num n2, size_t scale, bool use_sign); -bc_num _bc_do_add (const bc_num n1, const bc_num n2); -bc_num _bc_do_sub (const bc_num n1, const bc_num n2); +bcmath_compare_result _bc_do_compare (bc_num n1, bc_num n2, size_t scale, bool use_sign); +bc_num _bc_do_add (bc_num n1, bc_num n2); +bc_num _bc_do_sub (bc_num n1, bc_num n2); void _bc_rm_leading_zeros (bc_num num); #endif diff --git a/ext/bcmath/libbcmath/src/recmul.c b/ext/bcmath/libbcmath/src/recmul.c index 75e48d1557a2..26ce1641db41 100644 --- a/ext/bcmath/libbcmath/src/recmul.c +++ b/ext/bcmath/libbcmath/src/recmul.c @@ -52,7 +52,7 @@ static inline void bc_mul_carry_calc(BC_VECTOR *prod_vector, size_t prod_arr_siz * If the n_values of n1 and n2 are both 4 (32-bit) or 8 (64-bit) digits or less, * the calculation will be performed at high speed without using an array. */ -static inline void bc_fast_mul(const bc_num n1, size_t n1len, const bc_num n2, size_t n2len, bc_num *prod) +static inline void bc_fast_mul(bc_num n1, size_t n1len, bc_num n2, size_t n2len, bc_num *prod) { const char *n1end = n1->n_value + n1len - 1; const char *n2end = n2->n_value + n2len - 1; @@ -76,7 +76,7 @@ static inline void bc_fast_mul(const bc_num n1, size_t n1len, const bc_num n2, s * Equivalent of bc_fast_mul for small numbers to perform computations * without using array. */ -static inline void bc_fast_square(const bc_num n1, size_t n1len, bc_num *prod) +static inline void bc_fast_square(bc_num n1, size_t n1len, bc_num *prod) { const char *n1end = n1->n_value + n1len - 1; @@ -119,7 +119,7 @@ static inline void bc_mul_finish_from_vector(BC_VECTOR *prod_vector, size_t prod * Multiply and add these groups of numbers to perform multiplication fast. * How much to shift the digits when adding values can be calculated from the index of the array. */ -static void bc_standard_mul(const bc_num n1, size_t n1len, const bc_num n2, size_t n2len, bc_num *prod) +static void bc_standard_mul(bc_num n1, size_t n1len, bc_num n2, size_t n2len, bc_num *prod) { size_t i; const char *n1end = n1->n_value + n1len - 1; @@ -181,7 +181,7 @@ static void bc_standard_mul(const bc_num n1, size_t n1len, const bc_num n2, size } /** This is bc_standard_mul implementation for square */ -static void bc_standard_square(const bc_num n1, size_t n1len, bc_num *prod) +static void bc_standard_square(bc_num n1, size_t n1len, bc_num *prod) { size_t i; const char *n1end = n1->n_value + n1len - 1; diff --git a/ext/bcmath/libbcmath/src/round.c b/ext/bcmath/libbcmath/src/round.c index 9e807bfb9540..44df6036cbe3 100644 --- a/ext/bcmath/libbcmath/src/round.c +++ b/ext/bcmath/libbcmath/src/round.c @@ -19,7 +19,7 @@ #include /* Returns the scale of the value after rounding. */ -size_t bc_round(const bc_num num, zend_long precision, zend_long mode, bc_num *result) +size_t bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result) { /* clear result */ bc_free_num(result); diff --git a/ext/bcmath/libbcmath/src/sqrt.c b/ext/bcmath/libbcmath/src/sqrt.c index 82f71be82810..a2a66b44122b 100644 --- a/ext/bcmath/libbcmath/src/sqrt.c +++ b/ext/bcmath/libbcmath/src/sqrt.c @@ -38,7 +38,7 @@ bool bc_sqrt(bc_num *num, size_t scale) { - const bc_num local_num = *num; + bc_num local_num = *num; /* Initial checks. */ if (bc_is_neg(local_num)) { /* Cannot take the square root of a negative number */ diff --git a/ext/bcmath/libbcmath/src/sub.c b/ext/bcmath/libbcmath/src/sub.c index dfb9f4038a81..9e71c4856f81 100644 --- a/ext/bcmath/libbcmath/src/sub.c +++ b/ext/bcmath/libbcmath/src/sub.c @@ -39,7 +39,7 @@ N2 is subtracted from N1 and the result placed in RESULT. SCALE_MIN is the minimum scale for the result. */ -bc_num bc_sub(const bc_num n1, const bc_num n2, size_t scale_min) +bc_num bc_sub(bc_num n1, bc_num n2, size_t scale_min) { bc_num diff = NULL; diff --git a/ext/bcmath/libbcmath/src/zero.c b/ext/bcmath/libbcmath/src/zero.c index 62b891e414d8..550ea97df674 100644 --- a/ext/bcmath/libbcmath/src/zero.c +++ b/ext/bcmath/libbcmath/src/zero.c @@ -35,7 +35,7 @@ /* In some places we need to check if the number NUM is zero. */ -bool bc_is_zero_for_scale(const bc_num num, size_t scale) +bool bc_is_zero_for_scale(bc_num num, size_t scale) { size_t count; char *nptr; @@ -55,7 +55,7 @@ bool bc_is_zero_for_scale(const bc_num num, size_t scale) return count == 0; } -bool bc_is_zero(const bc_num num) +bool bc_is_zero(bc_num num) { return bc_is_zero_for_scale(num, num->n_scale); } From cec0779b54405d20a25a6f56388fea23e68add6e Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Thu, 10 Apr 2025 17:39:42 +0900 Subject: [PATCH 3/3] put back things that didn't need to be put back, so fixed it --- ext/bcmath/libbcmath/src/sqrt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/bcmath/libbcmath/src/sqrt.c b/ext/bcmath/libbcmath/src/sqrt.c index a2a66b44122b..82f71be82810 100644 --- a/ext/bcmath/libbcmath/src/sqrt.c +++ b/ext/bcmath/libbcmath/src/sqrt.c @@ -38,7 +38,7 @@ bool bc_sqrt(bc_num *num, size_t scale) { - bc_num local_num = *num; + const bc_num local_num = *num; /* Initial checks. */ if (bc_is_neg(local_num)) { /* Cannot take the square root of a negative number */