1
1
/******************************************************************************
2
- $PostgreSQL: pgsql/contrib/cube/cube.c,v 1.30 2006/10/04 00:29:44 momjian Exp $
2
+ $PostgreSQL: pgsql/contrib/cube/cube.c,v 1.31 2007/02/27 23:48:05 tgl Exp $
3
3
4
4
This file contains routines that can be bound to a Postgres backend and
5
5
called by the backend in the process of processing queries. The calling
@@ -223,9 +223,8 @@ cube_a_f8_f8(PG_FUNCTION_ARGS)
223
223
dll = ARRPTR (ll );
224
224
225
225
size = offsetof(NDBOX , x [0 ]) + sizeof (double ) * 2 * dim ;
226
- result = (NDBOX * ) palloc (size );
227
- memset (result , 0 , size );
228
- result -> size = size ;
226
+ result = (NDBOX * ) palloc0 (size );
227
+ SET_VARSIZE (result , size );
229
228
result -> dim = dim ;
230
229
231
230
for (i = 0 ; i < dim ; i ++ )
@@ -264,9 +263,8 @@ cube_a_f8(PG_FUNCTION_ARGS)
264
263
dur = ARRPTR (ur );
265
264
266
265
size = offsetof(NDBOX , x [0 ]) + sizeof (double ) * 2 * dim ;
267
- result = (NDBOX * ) palloc (size );
268
- memset (result , 0 , size );
269
- result -> size = size ;
266
+ result = (NDBOX * ) palloc0 (size );
267
+ SET_VARSIZE (result , size );
270
268
result -> dim = dim ;
271
269
272
270
for (i = 0 ; i < dim ; i ++ )
@@ -303,9 +301,8 @@ cube_subset(PG_FUNCTION_ARGS)
303
301
304
302
dim = ARRNELEMS (idx );
305
303
size = offsetof(NDBOX , x [0 ]) + sizeof (double ) * 2 * dim ;
306
- result = (NDBOX * ) palloc (size );
307
- memset (result , 0 , size );
308
- result -> size = size ;
304
+ result = (NDBOX * ) palloc0 (size );
305
+ SET_VARSIZE (result , size );
309
306
result -> dim = dim ;
310
307
311
308
for (i = 0 ; i < dim ; i ++ )
@@ -432,7 +429,7 @@ g_cube_union(PG_FUNCTION_ARGS)
432
429
/*
433
430
* sizep = sizeof(NDBOX); -- NDBOX has variable size
434
431
*/
435
- * sizep = tmp -> size ;
432
+ * sizep = VARSIZE ( tmp ) ;
436
433
437
434
for (i = 1 ; i < entryvec -> n ; i ++ )
438
435
{
@@ -744,7 +741,7 @@ g_cube_binary_union(NDBOX * r1, NDBOX * r2, int *sizep)
744
741
NDBOX * retval ;
745
742
746
743
retval = cube_union_v0 (r1 , r2 );
747
- * sizep = retval -> size ;
744
+ * sizep = VARSIZE ( retval ) ;
748
745
749
746
return (retval );
750
747
}
@@ -759,16 +756,14 @@ cube_union_v0(NDBOX * a, NDBOX * b)
759
756
760
757
if (a -> dim >= b -> dim )
761
758
{
762
- result = palloc (a -> size );
763
- memset (result , 0 , a -> size );
764
- result -> size = a -> size ;
759
+ result = palloc0 (VARSIZE (a ));
760
+ SET_VARSIZE (result , VARSIZE (a ));
765
761
result -> dim = a -> dim ;
766
762
}
767
763
else
768
764
{
769
- result = palloc (b -> size );
770
- memset (result , 0 , b -> size );
771
- result -> size = b -> size ;
765
+ result = palloc0 (VARSIZE (b ));
766
+ SET_VARSIZE (result , VARSIZE (b ));
772
767
result -> dim = b -> dim ;
773
768
}
774
769
@@ -834,16 +829,14 @@ cube_inter(PG_FUNCTION_ARGS)
834
829
835
830
if (a -> dim >= b -> dim )
836
831
{
837
- result = palloc (a -> size );
838
- memset (result , 0 , a -> size );
839
- result -> size = a -> size ;
832
+ result = palloc0 (VARSIZE (a ));
833
+ SET_VARSIZE (result , VARSIZE (a ));
840
834
result -> dim = a -> dim ;
841
835
}
842
836
else
843
837
{
844
- result = palloc (b -> size );
845
- memset (result , 0 , b -> size );
846
- result -> size = b -> size ;
838
+ result = palloc0 (VARSIZE (b ));
839
+ SET_VARSIZE (result , VARSIZE (b ));
847
840
result -> dim = b -> dim ;
848
841
}
849
842
@@ -1371,9 +1364,8 @@ cube_enlarge(PG_FUNCTION_ARGS)
1371
1364
if (a -> dim > dim )
1372
1365
dim = a -> dim ;
1373
1366
size = offsetof(NDBOX , x [0 ]) + sizeof (double ) * dim * 2 ;
1374
- result = (NDBOX * ) palloc (size );
1375
- memset (result , 0 , size );
1376
- result -> size = size ;
1367
+ result = (NDBOX * ) palloc0 (size );
1368
+ SET_VARSIZE (result , size );
1377
1369
result -> dim = dim ;
1378
1370
for (i = 0 , j = dim , k = a -> dim ; i < a -> dim ; i ++ , j ++ , k ++ )
1379
1371
{
@@ -1411,9 +1403,8 @@ cube_f8(PG_FUNCTION_ARGS)
1411
1403
int size ;
1412
1404
1413
1405
size = offsetof(NDBOX , x [0 ]) + sizeof (double ) * 2 ;
1414
- result = (NDBOX * ) palloc (size );
1415
- memset (result , 0 , size );
1416
- result -> size = size ;
1406
+ result = (NDBOX * ) palloc0 (size );
1407
+ SET_VARSIZE (result , size );
1417
1408
result -> dim = 1 ;
1418
1409
result -> x [0 ] = PG_GETARG_FLOAT8 (0 );
1419
1410
result -> x [1 ] = result -> x [0 ];
@@ -1429,9 +1420,8 @@ cube_f8_f8(PG_FUNCTION_ARGS)
1429
1420
int size ;
1430
1421
1431
1422
size = offsetof(NDBOX , x [0 ]) + sizeof (double ) * 2 ;
1432
- result = (NDBOX * ) palloc (size );
1433
- memset (result , 0 , size );
1434
- result -> size = size ;
1423
+ result = (NDBOX * ) palloc0 (size );
1424
+ SET_VARSIZE (result , size );
1435
1425
result -> dim = 1 ;
1436
1426
result -> x [0 ] = PG_GETARG_FLOAT8 (0 );
1437
1427
result -> x [1 ] = PG_GETARG_FLOAT8 (1 );
@@ -1454,9 +1444,8 @@ cube_c_f8(PG_FUNCTION_ARGS)
1454
1444
x = PG_GETARG_FLOAT8 (1 );
1455
1445
1456
1446
size = offsetof(NDBOX , x [0 ]) + sizeof (double ) * (c -> dim + 1 ) * 2 ;
1457
- result = (NDBOX * ) palloc (size );
1458
- memset (result , 0 , size );
1459
- result -> size = size ;
1447
+ result = (NDBOX * ) palloc0 (size );
1448
+ SET_VARSIZE (result , size );
1460
1449
result -> dim = c -> dim + 1 ;
1461
1450
for (i = 0 ; i < c -> dim ; i ++ )
1462
1451
{
@@ -1485,9 +1474,8 @@ cube_c_f8_f8(PG_FUNCTION_ARGS)
1485
1474
x2 = PG_GETARG_FLOAT8 (2 );
1486
1475
1487
1476
size = offsetof(NDBOX , x [0 ]) + sizeof (double ) * (c -> dim + 1 ) * 2 ;
1488
- result = (NDBOX * ) palloc (size );
1489
- memset (result , 0 , size );
1490
- result -> size = size ;
1477
+ result = (NDBOX * ) palloc0 (size );
1478
+ SET_VARSIZE (result , size );
1491
1479
result -> dim = c -> dim + 1 ;
1492
1480
for (i = 0 ; i < c -> dim ; i ++ )
1493
1481
{
0 commit comments