@@ -1114,8 +1114,8 @@ MemoryContextAllocExtended(MemoryContext context, Size size, int flags)
1114
1114
AssertArg (MemoryContextIsValid (context ));
1115
1115
AssertNotInCriticalSection (context );
1116
1116
1117
- if (((flags & MCXT_ALLOC_HUGE ) != 0 && ! AllocHugeSizeIsValid (size )) ||
1118
- (( flags & MCXT_ALLOC_HUGE ) == 0 && ! AllocSizeIsValid (size )))
1117
+ if (! ((flags & MCXT_ALLOC_HUGE ) != 0 ? AllocHugeSizeIsValid (size ) :
1118
+ AllocSizeIsValid (size )))
1119
1119
elog (ERROR , "invalid memory alloc request size %zu" , size );
1120
1120
1121
1121
context -> isReset = false;
@@ -1269,8 +1269,8 @@ palloc_extended(Size size, int flags)
1269
1269
AssertArg (MemoryContextIsValid (context ));
1270
1270
AssertNotInCriticalSection (context );
1271
1271
1272
- if (((flags & MCXT_ALLOC_HUGE ) != 0 && ! AllocHugeSizeIsValid (size )) ||
1273
- (( flags & MCXT_ALLOC_HUGE ) == 0 && ! AllocSizeIsValid (size )))
1272
+ if (! ((flags & MCXT_ALLOC_HUGE ) != 0 ? AllocHugeSizeIsValid (size ) :
1273
+ AllocSizeIsValid (size )))
1274
1274
elog (ERROR , "invalid memory alloc request size %zu" , size );
1275
1275
1276
1276
context -> isReset = false;
@@ -1351,6 +1351,50 @@ repalloc(void *pointer, Size size)
1351
1351
return ret ;
1352
1352
}
1353
1353
1354
+ /*
1355
+ * repalloc_extended
1356
+ * Adjust the size of a previously allocated chunk,
1357
+ * with HUGE and NO_OOM options.
1358
+ */
1359
+ void *
1360
+ repalloc_extended (void * pointer , Size size , int flags )
1361
+ {
1362
+ #if defined(USE_ASSERT_CHECKING ) || defined(USE_VALGRIND )
1363
+ MemoryContext context = GetMemoryChunkContext (pointer );
1364
+ #endif
1365
+ void * ret ;
1366
+
1367
+ if (!((flags & MCXT_ALLOC_HUGE ) != 0 ? AllocHugeSizeIsValid (size ) :
1368
+ AllocSizeIsValid (size )))
1369
+ elog (ERROR , "invalid memory alloc request size %zu" , size );
1370
+
1371
+ AssertNotInCriticalSection (context );
1372
+
1373
+ /* isReset must be false already */
1374
+ Assert (!context -> isReset );
1375
+
1376
+ ret = MCXT_METHOD (pointer , realloc ) (pointer , size );
1377
+ if (unlikely (ret == NULL ))
1378
+ {
1379
+ if ((flags & MCXT_ALLOC_NO_OOM ) == 0 )
1380
+ {
1381
+ MemoryContext cxt = GetMemoryChunkContext (pointer );
1382
+
1383
+ MemoryContextStats (TopMemoryContext );
1384
+ ereport (ERROR ,
1385
+ (errcode (ERRCODE_OUT_OF_MEMORY ),
1386
+ errmsg ("out of memory" ),
1387
+ errdetail ("Failed on request of size %zu in memory context \"%s\"." ,
1388
+ size , cxt -> name )));
1389
+ }
1390
+ return NULL ;
1391
+ }
1392
+
1393
+ VALGRIND_MEMPOOL_CHANGE (context , pointer , ret , size );
1394
+
1395
+ return ret ;
1396
+ }
1397
+
1354
1398
/*
1355
1399
* MemoryContextAllocHuge
1356
1400
* Allocate (possibly-expansive) space within the specified context.
@@ -1394,35 +1438,8 @@ MemoryContextAllocHuge(MemoryContext context, Size size)
1394
1438
void *
1395
1439
repalloc_huge (void * pointer , Size size )
1396
1440
{
1397
- #if defined(USE_ASSERT_CHECKING ) || defined(USE_VALGRIND )
1398
- MemoryContext context = GetMemoryChunkContext (pointer );
1399
- #endif
1400
- void * ret ;
1401
-
1402
- if (!AllocHugeSizeIsValid (size ))
1403
- elog (ERROR , "invalid memory alloc request size %zu" , size );
1404
-
1405
- AssertNotInCriticalSection (context );
1406
-
1407
- /* isReset must be false already */
1408
- Assert (!context -> isReset );
1409
-
1410
- ret = MCXT_METHOD (pointer , realloc ) (pointer , size );
1411
- if (unlikely (ret == NULL ))
1412
- {
1413
- MemoryContext cxt = GetMemoryChunkContext (pointer );
1414
-
1415
- MemoryContextStats (TopMemoryContext );
1416
- ereport (ERROR ,
1417
- (errcode (ERRCODE_OUT_OF_MEMORY ),
1418
- errmsg ("out of memory" ),
1419
- errdetail ("Failed on request of size %zu in memory context \"%s\"." ,
1420
- size , cxt -> name )));
1421
- }
1422
-
1423
- VALGRIND_MEMPOOL_CHANGE (context , pointer , ret , size );
1424
-
1425
- return ret ;
1441
+ /* this one seems not worth its own implementation */
1442
+ return repalloc_extended (pointer , size , MCXT_ALLOC_HUGE );
1426
1443
}
1427
1444
1428
1445
/*
0 commit comments