Skip to content

Commit 83804a7

Browse files
committed
ext/bcmath: Use standard C99 bool type instead of char
1 parent e457b21 commit 83804a7

File tree

8 files changed

+31
-27
lines changed

8 files changed

+31
-27
lines changed

ext/bcmath/libbcmath/src/bcmath.h

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ typedef struct bc_struct {
7575
#define MIN(a, b) ((a)>(b)?(b):(a))
7676
#define ODD(a) ((a)&1)
7777

78-
#ifndef TRUE
79-
#define TRUE 1
80-
#define FALSE 0
81-
#endif
82-
8378
#ifndef LONG_MAX
8479
#define LONG_MAX 0x7ffffff
8580
#endif
@@ -89,15 +84,15 @@ typedef struct bc_struct {
8984

9085
void bc_init_numbers(void);
9186

92-
bc_num _bc_new_num_ex(int length, int scale, int persistent);
87+
bc_num _bc_new_num_ex(int length, int scale, bool persistent);
9388

94-
void _bc_free_num_ex(bc_num *num, int persistent);
89+
void _bc_free_num_ex(bc_num *num, bool persistent);
9590

9691
bc_num bc_copy_num(bc_num num);
9792

9893
void bc_init_num(bc_num *num);
9994

100-
int bc_str2num(bc_num *num, char *str, int scale);
95+
bool bc_str2num(bc_num *num, char *str, int scale);
10196

10297
zend_string *bc_num2str_ex(bc_num num, int scale);
10398

@@ -107,9 +102,9 @@ long bc_num2long(bc_num num);
107102

108103
int bc_compare(bc_num n1, bc_num n2);
109104

110-
char bc_is_zero(bc_num num);
105+
bool bc_is_zero(bc_num num);
111106

112-
char bc_is_zero_for_scale(bc_num num, int scale);
107+
bool bc_is_zero_for_scale(bc_num num, int scale);
113108

114109
bool bc_is_near_zero(bc_num num, int scale);
115110

@@ -133,7 +128,7 @@ void bc_raise(bc_num num1, bc_num num2, bc_num *resul, int scale);
133128

134129
bool bc_sqrt(bc_num *num, int scale);
135130

136-
void bc_out_num(bc_num num, int o_base, void (* out_char)(char), int leading_zero);
131+
void bc_out_num(bc_num num, int o_base, void (* out_char)(char), bool leading_zero);
137132

138133
/* Prototypes needed for external utility routines. */
139134
#define bc_new_num(length, scale) _bc_new_num_ex((length), (scale), 0)

ext/bcmath/libbcmath/src/div.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "config.h" /* For safe_emalloc() */
3333
#include "bcmath.h"
3434
#include "private.h"
35+
#include <stdbool.h>
3536

3637

3738
/* Some utility routines for the divide: First a one digit multiply.
@@ -82,7 +83,7 @@ int bc_divide(bc_num n1, bc_num n2, bc_num *quot, int scale)
8283
unsigned int len1, len2, scale2, qdigits, extra, count;
8384
unsigned int qdig, qguess, borrow, carry;
8485
unsigned char *mval;
85-
char zero;
86+
bool zero;
8687
unsigned int norm;
8788

8889
/* Test for divide by zero. */
@@ -134,9 +135,9 @@ int bc_divide(bc_num n1, bc_num n2, bc_num *quot, int scale)
134135
/* Calculate the number of quotient digits. */
135136
if (len2 > len1+scale) {
136137
qdigits = scale+1;
137-
zero = TRUE;
138+
zero = true;
138139
} else {
139-
zero = FALSE;
140+
zero = false;
140141
if (len2 > len1) {
141142
/* One for the zero integer part. */
142143
qdigits = scale+1;

ext/bcmath/libbcmath/src/init.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
*************************************************************************/
3131

3232
#include "config.h"
33+
#include <stdbool.h>
3334
#include "bcmath.h"
3435

3536
/* new_num allocates a number and sets fields to known values. */
36-
bc_num _bc_new_num_ex(int length, int scale, int persistent)
37+
bc_num _bc_new_num_ex(int length, int scale, bool persistent)
3738
{
3839
bc_num temp;
3940
/* PHP Change: malloc() -> pemalloc(), removed free_list code */
@@ -52,7 +53,7 @@ bc_num _bc_new_num_ex(int length, int scale, int persistent)
5253

5354
/* "Frees" a bc_num NUM. Actually decreases reference count and only
5455
frees the storage if reference count is zero. */
55-
void _bc_free_num_ex(bc_num *num, int persistent)
56+
void _bc_free_num_ex(bc_num *num, bool persistent)
5657
{
5758
if (*num == NULL) {
5859
return;

ext/bcmath/libbcmath/src/output.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "config.h" /* For emalloc */
3333
#include "bcmath.h"
34+
#include <stdbool.h>
3435

3536

3637
/* The following routines provide output for bcd numbers package
@@ -71,7 +72,7 @@ void bc_out_long (long val, size_t size, bool space, void (*out_char)(char) )
7172
/* Output of a bcd number. NUM is written in base O_BASE using OUT_CHAR
7273
as the routine to do the actual output of the characters. */
7374

74-
void bc_out_num (bc_num num, int o_base, void (*out_char)(char), int leading_zero)
75+
void bc_out_num (bc_num num, int o_base, void (*out_char)(char), bool leading_zero)
7576
{
7677
char *nptr;
7778
int index, fdigit;

ext/bcmath/libbcmath/src/recmul.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "bcmath.h"
3333
#include <assert.h>
34+
#include <stdbool.h>
3435
#include "config.h" /* For emalloc() */
3536
#include "private.h" /* For _bc_rm_leading_zeros() */
3637

@@ -96,7 +97,7 @@ static void _bc_simp_mul(bc_num n1, int n1len, bc_num n2, int n2len, bc_num *pro
9697
multiply algorithm. Note: if sub is called, accum must
9798
be larger that what is being subtracted. Also, accum and val
9899
must have n_scale = 0. (e.g. they must look like integers. *) */
99-
static void _bc_shift_addsub (bc_num accum, bc_num val, int shift, int sub)
100+
static void _bc_shift_addsub (bc_num accum, bc_num val, int shift, bool sub)
100101
{
101102
signed char *accp, *valp;
102103
int count, carry;

ext/bcmath/libbcmath/src/str2num.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@
3030
*************************************************************************/
3131

3232
#include "bcmath.h"
33+
#include <stdbool.h>
3334

3435
/* Convert strings to bc numbers. Base 10 only.*/
3536

36-
int bc_str2num (bc_num *num, char *str, int scale)
37+
bool bc_str2num (bc_num *num, char *str, int scale)
3738
{
3839
int digits, strscale;
3940
char *ptr, *nptr;
40-
char zero_int;
41+
bool zero_int = false;
4142

4243
/* Prepare num. */
4344
bc_free_num (num);
@@ -46,7 +47,7 @@ int bc_str2num (bc_num *num, char *str, int scale)
4647
ptr = str;
4748
digits = 0;
4849
strscale = 0;
49-
zero_int = FALSE;
50+
5051
if ( (*ptr == '+') || (*ptr == '-')) {
5152
/* Skip Sign */
5253
ptr++;
@@ -77,7 +78,7 @@ int bc_str2num (bc_num *num, char *str, int scale)
7778
/* Adjust numbers and allocate storage and initialize fields. */
7879
strscale = MIN(strscale, scale);
7980
if (digits == 0) {
80-
zero_int = TRUE;
81+
zero_int = true;
8182
digits = 1;
8283
}
8384
*num = bc_new_num (digits, strscale);
@@ -117,5 +118,5 @@ int bc_str2num (bc_num *num, char *str, int scale)
117118
(*num)->n_sign = PLUS;
118119
}
119120

120-
return 1;
121+
return true;
121122
}

ext/bcmath/libbcmath/src/sub.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "bcmath.h"
3333
#include "private.h"
34+
#include <stdbool.h>
3435

3536
/* Here is the full subtract routine that takes care of negative numbers.
3637
N2 is subtracted from N1 and the result placed in RESULT. SCALE_MIN
@@ -48,7 +49,7 @@ void bc_sub(bc_num n1, bc_num n2, bc_num *result, int scale_min)
4849
} else {
4950
/* subtraction must be done. */
5051
/* Compare magnitudes. */
51-
cmp_res = _bc_do_compare (n1, n2, FALSE, FALSE);
52+
cmp_res = _bc_do_compare(n1, n2, false, false);
5253
switch (cmp_res) {
5354
case -1:
5455
/* n1 is less than n2, subtract n1 from n2. */

ext/bcmath/libbcmath/src/zero.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@
3030
*************************************************************************/
3131

3232
#include "bcmath.h"
33+
#include <stdbool.h>
3334

3435
/* In some places we need to check if the number NUM is zero. */
3536

36-
char bc_is_zero_for_scale (bc_num num, int scale)
37+
bool bc_is_zero_for_scale (bc_num num, int scale)
3738
{
3839
int count;
3940
char *nptr;
4041

4142
/* Quick check. */
42-
if (num == BCG(_zero_)) return TRUE;
43+
if (num == BCG(_zero_)) {
44+
return true;
45+
}
4346

4447
/* Initialize */
4548
count = num->n_len + scale;
@@ -51,7 +54,7 @@ char bc_is_zero_for_scale (bc_num num, int scale)
5154
return count == 0;
5255
}
5356

54-
char bc_is_zero (bc_num num)
57+
bool bc_is_zero(bc_num num)
5558
{
5659
return bc_is_zero_for_scale(num, num->n_scale);
5760
}

0 commit comments

Comments
 (0)