Skip to content

Commit fbec1a7

Browse files
committed
Convert bcmath to new parameter parsing API
1 parent b1300e4 commit fbec1a7

File tree

1 file changed

+69
-44
lines changed

1 file changed

+69
-44
lines changed

ext/bcmath/bcmath.c

Lines changed: 69 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,16 @@ PHP_FUNCTION(bcadd)
229229
zend_string *left, *right;
230230
zend_long scale_param = 0;
231231
bc_num first, second, result;
232-
int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS();
232+
int scale = (int)BCG(bc_precision);
233233

234-
if (zend_parse_parameters(argc, "SS|l", &left, &right, &scale_param) == FAILURE) {
235-
return;
236-
}
234+
ZEND_PARSE_PARAMETERS_START(2, 3)
235+
Z_PARAM_STR(left)
236+
Z_PARAM_STR(right)
237+
Z_PARAM_OPTIONAL
238+
Z_PARAM_LONG(scale_param)
239+
ZEND_PARSE_PARAMETERS_END();
237240

238-
if (argc == 3) {
241+
if (ZEND_NUM_ARGS() == 3) {
239242
scale = (int) (scale_param < 0 ? 0 : scale_param);
240243
}
241244

@@ -266,13 +269,16 @@ PHP_FUNCTION(bcsub)
266269
zend_string *left, *right;
267270
zend_long scale_param = 0;
268271
bc_num first, second, result;
269-
int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS();
272+
int scale = (int)BCG(bc_precision);
270273

271-
if (zend_parse_parameters(argc, "SS|l", &left, &right, &scale_param) == FAILURE) {
272-
return;
273-
}
274+
ZEND_PARSE_PARAMETERS_START(2, 3)
275+
Z_PARAM_STR(left)
276+
Z_PARAM_STR(right)
277+
Z_PARAM_OPTIONAL
278+
Z_PARAM_LONG(scale_param)
279+
ZEND_PARSE_PARAMETERS_END();
274280

275-
if (argc == 3) {
281+
if (ZEND_NUM_ARGS() == 3) {
276282
scale = (int) ((int)scale_param < 0 ? 0 : scale_param);
277283
}
278284

@@ -303,13 +309,16 @@ PHP_FUNCTION(bcmul)
303309
zend_string *left, *right;
304310
zend_long scale_param = 0;
305311
bc_num first, second, result;
306-
int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS();
312+
int scale = (int)BCG(bc_precision);
307313

308-
if (zend_parse_parameters(argc, "SS|l", &left, &right, &scale_param) == FAILURE) {
309-
return;
310-
}
314+
ZEND_PARSE_PARAMETERS_START(2, 3)
315+
Z_PARAM_STR(left)
316+
Z_PARAM_STR(right)
317+
Z_PARAM_OPTIONAL
318+
Z_PARAM_LONG(scale_param)
319+
ZEND_PARSE_PARAMETERS_END();
311320

312-
if (argc == 3) {
321+
if (ZEND_NUM_ARGS() == 3) {
313322
scale = (int) ((int)scale_param < 0 ? 0 : scale_param);
314323
}
315324

@@ -340,13 +349,16 @@ PHP_FUNCTION(bcdiv)
340349
zend_string *left, *right;
341350
zend_long scale_param = 0;
342351
bc_num first, second, result;
343-
int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS();
352+
int scale = (int)BCG(bc_precision);
344353

345-
if (zend_parse_parameters(argc, "SS|l", &left, &right, &scale_param) == FAILURE) {
346-
return;
347-
}
354+
ZEND_PARSE_PARAMETERS_START(2, 3)
355+
Z_PARAM_STR(left)
356+
Z_PARAM_STR(right)
357+
Z_PARAM_OPTIONAL
358+
Z_PARAM_LONG(scale_param)
359+
ZEND_PARSE_PARAMETERS_END();
348360

349-
if (argc == 3) {
361+
if (ZEND_NUM_ARGS() == 3) {
350362
scale = (int) ((int)scale_param < 0 ? 0 : scale_param);
351363
}
352364

@@ -383,9 +395,10 @@ PHP_FUNCTION(bcmod)
383395
zend_string *left, *right;
384396
bc_num first, second, result;
385397

386-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &left, &right) == FAILURE) {
387-
return;
388-
}
398+
ZEND_PARSE_PARAMETERS_START(2, 2)
399+
Z_PARAM_STR(left)
400+
Z_PARAM_STR(right)
401+
ZEND_PARSE_PARAMETERS_END();
389402

390403
bc_init_num(&first);
391404
bc_init_num(&second);
@@ -418,9 +431,13 @@ PHP_FUNCTION(bcpowmod)
418431
zend_long scale = BCG(bc_precision);
419432
int scale_int;
420433

421-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSS|l", &left, &right, &modulous, &scale) == FAILURE) {
422-
return;
423-
}
434+
ZEND_PARSE_PARAMETERS_START(3, 4)
435+
Z_PARAM_STR(left)
436+
Z_PARAM_STR(right)
437+
Z_PARAM_STR(modulous)
438+
Z_PARAM_OPTIONAL
439+
Z_PARAM_LONG(scale)
440+
ZEND_PARSE_PARAMETERS_END();
424441

425442
bc_init_num(&first);
426443
bc_init_num(&second);
@@ -457,13 +474,16 @@ PHP_FUNCTION(bcpow)
457474
zend_string *left, *right;
458475
zend_long scale_param = 0;
459476
bc_num first, second, result;
460-
int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS();
477+
int scale = (int)BCG(bc_precision);
461478

462-
if (zend_parse_parameters(argc, "SS|l", &left, &right, &scale_param) == FAILURE) {
463-
return;
464-
}
479+
ZEND_PARSE_PARAMETERS_START(2, 3)
480+
Z_PARAM_STR(left)
481+
Z_PARAM_STR(right)
482+
Z_PARAM_OPTIONAL
483+
Z_PARAM_LONG(scale_param)
484+
ZEND_PARSE_PARAMETERS_END();
465485

466-
if (argc == 3) {
486+
if (ZEND_NUM_ARGS() == 3) {
467487
scale = (int) ((int)scale_param < 0 ? 0 : scale_param);
468488
}
469489

@@ -494,13 +514,15 @@ PHP_FUNCTION(bcsqrt)
494514
zend_string *left;
495515
zend_long scale_param = 0;
496516
bc_num result;
497-
int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS();
517+
int scale = (int)BCG(bc_precision);
498518

499-
if (zend_parse_parameters(argc, "S|l", &left, &scale_param) == FAILURE) {
500-
return;
501-
}
519+
ZEND_PARSE_PARAMETERS_START(1, 2)
520+
Z_PARAM_STR(left)
521+
Z_PARAM_OPTIONAL
522+
Z_PARAM_LONG(scale_param)
523+
ZEND_PARSE_PARAMETERS_END();
502524

503-
if (argc == 2) {
525+
if (ZEND_NUM_ARGS() == 2) {
504526
scale = (int) ((int)scale_param < 0 ? 0 : scale_param);
505527
}
506528

@@ -529,13 +551,16 @@ PHP_FUNCTION(bccomp)
529551
zend_string *left, *right;
530552
zend_long scale_param = 0;
531553
bc_num first, second;
532-
int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS();
554+
int scale = (int)BCG(bc_precision);
533555

534-
if (zend_parse_parameters(argc, "SS|l", &left, &right, &scale_param) == FAILURE) {
535-
return;
536-
}
556+
ZEND_PARSE_PARAMETERS_START(2, 3)
557+
Z_PARAM_STR(left)
558+
Z_PARAM_STR(right)
559+
Z_PARAM_OPTIONAL
560+
Z_PARAM_LONG(scale_param)
561+
ZEND_PARSE_PARAMETERS_END();
537562

538-
if (argc == 3) {
563+
if (ZEND_NUM_ARGS() == 3) {
539564
scale = (int) ((int)scale_param < 0 ? 0 : scale_param);
540565
}
541566

@@ -558,9 +583,9 @@ PHP_FUNCTION(bcscale)
558583
{
559584
zend_long new_scale;
560585

561-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &new_scale) == FAILURE) {
562-
return;
563-
}
586+
ZEND_PARSE_PARAMETERS_START(1, 1)
587+
Z_PARAM_LONG(new_scale)
588+
ZEND_PARSE_PARAMETERS_END();
564589

565590
BCG(bc_precision) = ((int)new_scale < 0) ? 0 : new_scale;
566591

0 commit comments

Comments
 (0)