Skip to content

ext/bcmath: Use const qualifiers appropriately #18284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 11, 2025
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
4 changes: 2 additions & 2 deletions ext/bcmath/bcmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down
6 changes: 2 additions & 4 deletions ext/bcmath/libbcmath/src/compare.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
/*
Expand Down Expand Up @@ -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++;
Expand Down
6 changes: 3 additions & 3 deletions ext/bcmath/libbcmath/src/div.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
12 changes: 6 additions & 6 deletions ext/bcmath/libbcmath/src/doaddsub.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ 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;

/* Prepare sum. */
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.*/
Expand Down Expand Up @@ -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. */
Expand Down
Loading