1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

ext/bcmath: Use const qualifiers appropriately (#18284)

This commit is contained in:
Saki Takamachi
2025-04-11 12:39:31 +09:00
committed by GitHub
parent 10b2754056
commit c927d24af6
4 changed files with 13 additions and 15 deletions

View File

@@ -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 @@ failure:
}
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)) {

View File

@@ -41,8 +41,6 @@
bcmath_compare_result _bc_do_compare(bc_num n1, 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++;

View File

@@ -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;
@@ -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 */

View File

@@ -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.*/
@@ -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. */