Skip to content

Commit b1300e4

Browse files
committed
Use zend_string in bcmath params
1 parent 77becd0 commit b1300e4

File tree

1 file changed

+36
-45
lines changed

1 file changed

+36
-45
lines changed

ext/bcmath/bcmath.c

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,12 @@ static bc_num split_bc_num(bc_num num) {
226226
Returns the sum of two arbitrary precision numbers */
227227
PHP_FUNCTION(bcadd)
228228
{
229-
char *left, *right;
229+
zend_string *left, *right;
230230
zend_long scale_param = 0;
231231
bc_num first, second, result;
232-
size_t left_len, right_len;
233232
int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS();
234233

235-
if (zend_parse_parameters(argc, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) {
234+
if (zend_parse_parameters(argc, "SS|l", &left, &right, &scale_param) == FAILURE) {
236235
return;
237236
}
238237

@@ -243,8 +242,8 @@ PHP_FUNCTION(bcadd)
243242
bc_init_num(&first);
244243
bc_init_num(&second);
245244
bc_init_num(&result);
246-
php_str2num(&first, left);
247-
php_str2num(&second, right);
245+
php_str2num(&first, ZSTR_VAL(left));
246+
php_str2num(&second, ZSTR_VAL(right));
248247
bc_add (first, second, &result, scale);
249248

250249
if (result->n_scale > scale) {
@@ -264,13 +263,12 @@ PHP_FUNCTION(bcadd)
264263
Returns the difference between two arbitrary precision numbers */
265264
PHP_FUNCTION(bcsub)
266265
{
267-
char *left, *right;
268-
size_t left_len, right_len;
266+
zend_string *left, *right;
269267
zend_long scale_param = 0;
270268
bc_num first, second, result;
271269
int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS();
272270

273-
if (zend_parse_parameters(argc, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) {
271+
if (zend_parse_parameters(argc, "SS|l", &left, &right, &scale_param) == FAILURE) {
274272
return;
275273
}
276274

@@ -281,8 +279,8 @@ PHP_FUNCTION(bcsub)
281279
bc_init_num(&first);
282280
bc_init_num(&second);
283281
bc_init_num(&result);
284-
php_str2num(&first, left);
285-
php_str2num(&second, right);
282+
php_str2num(&first, ZSTR_VAL(left));
283+
php_str2num(&second, ZSTR_VAL(right));
286284
bc_sub (first, second, &result, scale);
287285

288286
if (result->n_scale > scale) {
@@ -302,13 +300,12 @@ PHP_FUNCTION(bcsub)
302300
Returns the multiplication of two arbitrary precision numbers */
303301
PHP_FUNCTION(bcmul)
304302
{
305-
char *left, *right;
306-
size_t left_len, right_len;
303+
zend_string *left, *right;
307304
zend_long scale_param = 0;
308305
bc_num first, second, result;
309306
int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS();
310307

311-
if (zend_parse_parameters(argc, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) {
308+
if (zend_parse_parameters(argc, "SS|l", &left, &right, &scale_param) == FAILURE) {
312309
return;
313310
}
314311

@@ -319,8 +316,8 @@ PHP_FUNCTION(bcmul)
319316
bc_init_num(&first);
320317
bc_init_num(&second);
321318
bc_init_num(&result);
322-
php_str2num(&first, left);
323-
php_str2num(&second, right);
319+
php_str2num(&first, ZSTR_VAL(left));
320+
php_str2num(&second, ZSTR_VAL(right));
324321
bc_multiply (first, second, &result, scale);
325322

326323
if (result->n_scale > scale) {
@@ -340,13 +337,12 @@ PHP_FUNCTION(bcmul)
340337
Returns the quotient of two arbitrary precision numbers (division) */
341338
PHP_FUNCTION(bcdiv)
342339
{
343-
char *left, *right;
344-
size_t left_len, right_len;
340+
zend_string *left, *right;
345341
zend_long scale_param = 0;
346342
bc_num first, second, result;
347343
int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS();
348344

349-
if (zend_parse_parameters(argc, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) {
345+
if (zend_parse_parameters(argc, "SS|l", &left, &right, &scale_param) == FAILURE) {
350346
return;
351347
}
352348

@@ -357,8 +353,8 @@ PHP_FUNCTION(bcdiv)
357353
bc_init_num(&first);
358354
bc_init_num(&second);
359355
bc_init_num(&result);
360-
php_str2num(&first, left);
361-
php_str2num(&second, right);
356+
php_str2num(&first, ZSTR_VAL(left));
357+
php_str2num(&second, ZSTR_VAL(right));
362358

363359
switch (bc_divide(first, second, &result, scale)) {
364360
case 0: /* OK */
@@ -384,19 +380,18 @@ PHP_FUNCTION(bcdiv)
384380
Returns the modulus of the two arbitrary precision operands */
385381
PHP_FUNCTION(bcmod)
386382
{
387-
char *left, *right;
388-
size_t left_len, right_len;
383+
zend_string *left, *right;
389384
bc_num first, second, result;
390385

391-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &left, &left_len, &right, &right_len) == FAILURE) {
386+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &left, &right) == FAILURE) {
392387
return;
393388
}
394389

395390
bc_init_num(&first);
396391
bc_init_num(&second);
397392
bc_init_num(&result);
398-
bc_str2num(&first, left, 0);
399-
bc_str2num(&second, right, 0);
393+
bc_str2num(&first, ZSTR_VAL(left), 0);
394+
bc_str2num(&second, ZSTR_VAL(right), 0);
400395

401396
switch (bc_modulo(first, second, &result, 0)) {
402397
case 0:
@@ -418,23 +413,22 @@ PHP_FUNCTION(bcmod)
418413
Returns the value of an arbitrary precision number raised to the power of another reduced by a modulous */
419414
PHP_FUNCTION(bcpowmod)
420415
{
421-
char *left, *right, *modulous;
422-
size_t left_len, right_len, modulous_len;
416+
zend_string *left, *right, *modulous;
423417
bc_num first, second, mod, result;
424418
zend_long scale = BCG(bc_precision);
425419
int scale_int;
426420

427-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss|l", &left, &left_len, &right, &right_len, &modulous, &modulous_len, &scale) == FAILURE) {
421+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSS|l", &left, &right, &modulous, &scale) == FAILURE) {
428422
return;
429423
}
430424

431425
bc_init_num(&first);
432426
bc_init_num(&second);
433427
bc_init_num(&mod);
434428
bc_init_num(&result);
435-
php_str2num(&first, left);
436-
php_str2num(&second, right);
437-
php_str2num(&mod, modulous);
429+
php_str2num(&first, ZSTR_VAL(left));
430+
php_str2num(&second, ZSTR_VAL(right));
431+
php_str2num(&mod, ZSTR_VAL(modulous));
438432

439433
scale_int = (int) ((int)scale < 0 ? 0 : scale);
440434

@@ -460,13 +454,12 @@ PHP_FUNCTION(bcpowmod)
460454
Returns the value of an arbitrary precision number raised to the power of another */
461455
PHP_FUNCTION(bcpow)
462456
{
463-
char *left, *right;
464-
size_t left_len, right_len;
457+
zend_string *left, *right;
465458
zend_long scale_param = 0;
466459
bc_num first, second, result;
467460
int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS();
468461

469-
if (zend_parse_parameters(argc, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) {
462+
if (zend_parse_parameters(argc, "SS|l", &left, &right, &scale_param) == FAILURE) {
470463
return;
471464
}
472465

@@ -477,8 +470,8 @@ PHP_FUNCTION(bcpow)
477470
bc_init_num(&first);
478471
bc_init_num(&second);
479472
bc_init_num(&result);
480-
php_str2num(&first, left);
481-
php_str2num(&second, right);
473+
php_str2num(&first, ZSTR_VAL(left));
474+
php_str2num(&second, ZSTR_VAL(right));
482475
bc_raise (first, second, &result, scale);
483476

484477
if (result->n_scale > scale) {
@@ -498,13 +491,12 @@ PHP_FUNCTION(bcpow)
498491
Returns the square root of an arbitray precision number */
499492
PHP_FUNCTION(bcsqrt)
500493
{
501-
char *left;
502-
size_t left_len;
494+
zend_string *left;
503495
zend_long scale_param = 0;
504496
bc_num result;
505497
int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS();
506498

507-
if (zend_parse_parameters(argc, "s|l", &left, &left_len, &scale_param) == FAILURE) {
499+
if (zend_parse_parameters(argc, "S|l", &left, &scale_param) == FAILURE) {
508500
return;
509501
}
510502

@@ -513,7 +505,7 @@ PHP_FUNCTION(bcsqrt)
513505
}
514506

515507
bc_init_num(&result);
516-
php_str2num(&result, left);
508+
php_str2num(&result, ZSTR_VAL(left));
517509

518510
if (bc_sqrt (&result, scale) != 0) {
519511
if (result->n_scale > scale) {
@@ -534,13 +526,12 @@ PHP_FUNCTION(bcsqrt)
534526
Compares two arbitrary precision numbers */
535527
PHP_FUNCTION(bccomp)
536528
{
537-
char *left, *right;
538-
size_t left_len, right_len;
529+
zend_string *left, *right;
539530
zend_long scale_param = 0;
540531
bc_num first, second;
541532
int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS();
542533

543-
if (zend_parse_parameters(argc, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) {
534+
if (zend_parse_parameters(argc, "SS|l", &left, &right, &scale_param) == FAILURE) {
544535
return;
545536
}
546537

@@ -551,8 +542,8 @@ PHP_FUNCTION(bccomp)
551542
bc_init_num(&first);
552543
bc_init_num(&second);
553544

554-
bc_str2num(&first, left, scale);
555-
bc_str2num(&second, right, scale);
545+
bc_str2num(&first, ZSTR_VAL(left), scale);
546+
bc_str2num(&second, ZSTR_VAL(right), scale);
556547
RETVAL_LONG(bc_compare(first, second));
557548

558549
bc_free_num(&first);

0 commit comments

Comments
 (0)