@@ -1377,13 +1377,13 @@ address_in_range(void *p, poolp pool)
1377
1377
block allocations typically result in a couple of instructions).
1378
1378
Unless the optimizer reorders everything, being too smart...
1379
1379
1380
- Return 1 if pymalloc allocated memory and wrote the pointer into *ptr_p .
1380
+ Return a pointer to newly allocated memory if pymalloc allocated memory .
1381
1381
1382
- Return 0 if pymalloc failed to allocate the memory block: on bigger
1382
+ Return NULL if pymalloc failed to allocate the memory block: on bigger
1383
1383
requests, on error in the code below (as a last chance to serve the request)
1384
1384
or when the max memory limit has been reached. */
1385
- static int
1386
- pymalloc_alloc (void * ctx , void * * ptr_p , size_t nbytes )
1385
+ static void *
1386
+ pymalloc_alloc (void * ctx , size_t nbytes )
1387
1387
{
1388
1388
block * bp ;
1389
1389
poolp pool ;
@@ -1395,15 +1395,15 @@ pymalloc_alloc(void *ctx, void **ptr_p, size_t nbytes)
1395
1395
running_on_valgrind = RUNNING_ON_VALGRIND ;
1396
1396
}
1397
1397
if (UNLIKELY (running_on_valgrind )) {
1398
- return 0 ;
1398
+ return NULL ;
1399
1399
}
1400
1400
#endif
1401
1401
1402
1402
if (nbytes == 0 ) {
1403
- return 0 ;
1403
+ return NULL ;
1404
1404
}
1405
1405
if (nbytes > SMALL_REQUEST_THRESHOLD ) {
1406
- return 0 ;
1406
+ return NULL ;
1407
1407
}
1408
1408
1409
1409
LOCK ();
@@ -1564,20 +1564,19 @@ pymalloc_alloc(void *ctx, void **ptr_p, size_t nbytes)
1564
1564
success :
1565
1565
UNLOCK ();
1566
1566
assert (bp != NULL );
1567
- * ptr_p = (void * )bp ;
1568
- return 1 ;
1567
+ return (void * )bp ;
1569
1568
1570
1569
failed :
1571
1570
UNLOCK ();
1572
- return 0 ;
1571
+ return NULL ;
1573
1572
}
1574
1573
1575
1574
1576
1575
static void *
1577
1576
_PyObject_Malloc (void * ctx , size_t nbytes )
1578
1577
{
1579
- void * ptr ;
1580
- if (pymalloc_alloc ( ctx , & ptr , nbytes ) ) {
1578
+ void * ptr = pymalloc_alloc ( ctx , nbytes ) ;
1579
+ if (ptr != NULL ) {
1581
1580
_Py_AllocatedBlocks ++ ;
1582
1581
return ptr ;
1583
1582
}
@@ -1593,12 +1592,11 @@ _PyObject_Malloc(void *ctx, size_t nbytes)
1593
1592
static void *
1594
1593
_PyObject_Calloc (void * ctx , size_t nelem , size_t elsize )
1595
1594
{
1596
- void * ptr ;
1597
-
1598
1595
assert (elsize == 0 || nelem <= (size_t )PY_SSIZE_T_MAX / elsize );
1599
1596
size_t nbytes = nelem * elsize ;
1600
1597
1601
- if (pymalloc_alloc (ctx , & ptr , nbytes )) {
1598
+ void * ptr = pymalloc_alloc (ctx , nbytes );
1599
+ if (ptr != NULL ) {
1602
1600
memset (ptr , 0 , nbytes );
1603
1601
_Py_AllocatedBlocks ++ ;
1604
1602
return ptr ;
0 commit comments