Skip to content

Commit 463f1f5

Browse files
committed
Convert all remaining float4 and float8 functions to new fmgr style.
At this point I think it'd be possible to make float4 be pass-by-value without too much work --- and float8 too on machines where Datum is 8 bytes. Something to try when the mood strikes, anyway.
1 parent 92bd532 commit 463f1f5

File tree

10 files changed

+910
-1163
lines changed

10 files changed

+910
-1163
lines changed

src/backend/commands/variable.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.39 2000/07/14 15:35:44 thomas Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.40 2000/08/01 18:29:29 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -566,7 +566,7 @@ parse_random_seed(char *value)
566566
else
567567
{
568568
sscanf(value, "%lf", &seed);
569-
setseed(&seed);
569+
DirectFunctionCall1(setseed, Float8GetDatum(seed));
570570
}
571571
return (TRUE);
572572
}
@@ -583,7 +583,7 @@ reset_random_seed(void)
583583
{
584584
double seed = 0.5;
585585

586-
setseed(&seed);
586+
DirectFunctionCall1(setseed, Float8GetDatum(seed));
587587
return (TRUE);
588588
}
589589

src/backend/utils/adt/cash.c

Lines changed: 54 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* workings can be found in the book "Software Solutions in C" by
1010
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
1111
*
12-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.43 2000/07/07 18:49:52 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.44 2000/08/01 18:29:35 tgl Exp $
1313
*/
1414

1515
#include <limits.h>
@@ -425,31 +425,31 @@ cash_mi(Cash *c1, Cash *c2)
425425
/* cash_mul_flt8()
426426
* Multiply cash by float8.
427427
*/
428-
Cash *
429-
cash_mul_flt8(Cash *c, float8 *f)
428+
Datum
429+
cash_mul_flt8(PG_FUNCTION_ARGS)
430430
{
431-
Cash *result;
432-
433-
if (!PointerIsValid(f) || !PointerIsValid(c))
434-
return NULL;
435-
436-
if (!PointerIsValid(result = palloc(sizeof(Cash))))
437-
elog(ERROR, "Memory allocation failed, can't multiply cash");
438-
439-
*result = ((*f) * (*c));
431+
Cash c = PG_GETARG_CASH(0);
432+
float8 f = PG_GETARG_FLOAT8(1);
433+
Cash result;
440434

441-
return result;
442-
} /* cash_mul_flt8() */
435+
result = c * f;
436+
PG_RETURN_CASH(result);
437+
}
443438

444439

445440
/* flt8_mul_cash()
446441
* Multiply float8 by cash.
447442
*/
448-
Cash *
449-
flt8_mul_cash(float8 *f, Cash *c)
443+
Datum
444+
flt8_mul_cash(PG_FUNCTION_ARGS)
450445
{
451-
return cash_mul_flt8(c, f);
452-
} /* flt8_mul_cash() */
446+
float8 f = PG_GETARG_FLOAT8(0);
447+
Cash c = PG_GETARG_CASH(1);
448+
Cash result;
449+
450+
result = f * c;
451+
PG_RETURN_CASH(result);
452+
}
453453

454454

455455
/* cash_div_flt8()
@@ -458,53 +458,48 @@ flt8_mul_cash(float8 *f, Cash *c)
458458
* XXX Don't know if rounding or truncating is correct behavior.
459459
* Round for now. - tgl 97/04/15
460460
*/
461-
Cash *
462-
cash_div_flt8(Cash *c, float8 *f)
461+
Datum
462+
cash_div_flt8(PG_FUNCTION_ARGS)
463463
{
464-
Cash *result;
465-
466-
if (!PointerIsValid(f) || !PointerIsValid(c))
467-
return NULL;
468-
469-
if (!PointerIsValid(result = palloc(sizeof(Cash))))
470-
elog(ERROR, "Memory allocation failed, can't divide cash");
464+
Cash c = PG_GETARG_CASH(0);
465+
float8 f = PG_GETARG_FLOAT8(1);
466+
Cash result;
471467

472-
if (*f == 0.0)
468+
if (f == 0.0)
473469
elog(ERROR, "cash_div: divide by 0.0 error");
474470

475-
*result = rint(*c / *f);
476-
477-
return result;
478-
} /* cash_div_flt8() */
471+
result = rint(c / f);
472+
PG_RETURN_CASH(result);
473+
}
479474

480475
/* cash_mul_flt4()
481476
* Multiply cash by float4.
482477
*/
483-
Cash *
484-
cash_mul_flt4(Cash *c, float4 *f)
478+
Datum
479+
cash_mul_flt4(PG_FUNCTION_ARGS)
485480
{
486-
Cash *result;
487-
488-
if (!PointerIsValid(f) || !PointerIsValid(c))
489-
return NULL;
490-
491-
if (!PointerIsValid(result = palloc(sizeof(Cash))))
492-
elog(ERROR, "Memory allocation failed, can't multiply cash");
493-
494-
*result = ((*f) * (*c));
481+
Cash c = PG_GETARG_CASH(0);
482+
float4 f = PG_GETARG_FLOAT4(1);
483+
Cash result;
495484

496-
return result;
497-
} /* cash_mul_flt4() */
485+
result = c * f;
486+
PG_RETURN_CASH(result);
487+
}
498488

499489

500490
/* flt4_mul_cash()
501-
* Multiply float4 by float4.
491+
* Multiply float4 by cash.
502492
*/
503-
Cash *
504-
flt4_mul_cash(float4 *f, Cash *c)
493+
Datum
494+
flt4_mul_cash(PG_FUNCTION_ARGS)
505495
{
506-
return cash_mul_flt4(c, f);
507-
} /* flt4_mul_cash() */
496+
float4 f = PG_GETARG_FLOAT4(0);
497+
Cash c = PG_GETARG_CASH(1);
498+
Cash result;
499+
500+
result = f * c;
501+
PG_RETURN_CASH(result);
502+
}
508503

509504

510505
/* cash_div_flt4()
@@ -513,24 +508,19 @@ flt4_mul_cash(float4 *f, Cash *c)
513508
* XXX Don't know if rounding or truncating is correct behavior.
514509
* Round for now. - tgl 97/04/15
515510
*/
516-
Cash *
517-
cash_div_flt4(Cash *c, float4 *f)
511+
Datum
512+
cash_div_flt4(PG_FUNCTION_ARGS)
518513
{
519-
Cash *result;
520-
521-
if (!PointerIsValid(f) || !PointerIsValid(c))
522-
return NULL;
523-
524-
if (!PointerIsValid(result = palloc(sizeof(Cash))))
525-
elog(ERROR, "Memory allocation failed, can't divide cash");
514+
Cash c = PG_GETARG_CASH(0);
515+
float4 f = PG_GETARG_FLOAT4(1);
516+
Cash result;
526517

527-
if (*f == 0.0)
518+
if (f == 0.0)
528519
elog(ERROR, "cash_div: divide by 0.0 error");
529520

530-
*result = rint(*c / *f);
531-
532-
return result;
533-
} /* cash_div_flt4() */
521+
result = rint(c / f);
522+
PG_RETURN_CASH(result);
523+
}
534524

535525

536526
/* cash_mul_int4()

0 commit comments

Comments
 (0)