@@ -1415,13 +1415,13 @@ address_in_range(void *p, poolp pool)
1415
1415
block allocations typically result in a couple of instructions).
1416
1416
Unless the optimizer reorders everything, being too smart...
1417
1417
1418
- Return 1 if pymalloc allocated memory and wrote the pointer into *ptr_p .
1418
+ Return a pointer to newly allocated memory if pymalloc allocated memory .
1419
1419
1420
- Return 0 if pymalloc failed to allocate the memory block: on bigger
1420
+ Return NULL if pymalloc failed to allocate the memory block: on bigger
1421
1421
requests, on error in the code below (as a last chance to serve the request)
1422
1422
or when the max memory limit has been reached. */
1423
- static int
1424
- pymalloc_alloc (void * ctx , void * * ptr_p , size_t nbytes )
1423
+ static void *
1424
+ pymalloc_alloc (void * ctx , size_t nbytes )
1425
1425
{
1426
1426
block * bp ;
1427
1427
poolp pool ;
@@ -1433,15 +1433,15 @@ pymalloc_alloc(void *ctx, void **ptr_p, size_t nbytes)
1433
1433
running_on_valgrind = RUNNING_ON_VALGRIND ;
1434
1434
}
1435
1435
if (UNLIKELY (running_on_valgrind )) {
1436
- return 0 ;
1436
+ return NULL ;
1437
1437
}
1438
1438
#endif
1439
1439
1440
1440
if (nbytes == 0 ) {
1441
- return 0 ;
1441
+ return NULL ;
1442
1442
}
1443
1443
if (nbytes > SMALL_REQUEST_THRESHOLD ) {
1444
- return 0 ;
1444
+ return NULL ;
1445
1445
}
1446
1446
1447
1447
/*
@@ -1609,19 +1609,18 @@ pymalloc_alloc(void *ctx, void **ptr_p, size_t nbytes)
1609
1609
1610
1610
success :
1611
1611
assert (bp != NULL );
1612
- * ptr_p = (void * )bp ;
1613
- return 1 ;
1612
+ return (void * )bp ;
1614
1613
1615
1614
failed :
1616
- return 0 ;
1615
+ return NULL ;
1617
1616
}
1618
1617
1619
1618
1620
1619
static void *
1621
1620
_PyObject_Malloc (void * ctx , size_t nbytes )
1622
1621
{
1623
- void * ptr ;
1624
- if (pymalloc_alloc ( ctx , & ptr , nbytes ) ) {
1622
+ void * ptr = pymalloc_alloc ( ctx , nbytes ) ;
1623
+ if (ptr != NULL ) {
1625
1624
_Py_AllocatedBlocks ++ ;
1626
1625
return ptr ;
1627
1626
}
@@ -1637,12 +1636,11 @@ _PyObject_Malloc(void *ctx, size_t nbytes)
1637
1636
static void *
1638
1637
_PyObject_Calloc (void * ctx , size_t nelem , size_t elsize )
1639
1638
{
1640
- void * ptr ;
1641
-
1642
1639
assert (elsize == 0 || nelem <= (size_t )PY_SSIZE_T_MAX / elsize );
1643
1640
size_t nbytes = nelem * elsize ;
1644
1641
1645
- if (pymalloc_alloc (ctx , & ptr , nbytes )) {
1642
+ void * ptr = pymalloc_alloc (ctx , nbytes );
1643
+ if (ptr != NULL ) {
1646
1644
memset (ptr , 0 , nbytes );
1647
1645
_Py_AllocatedBlocks ++ ;
1648
1646
return ptr ;
@@ -1743,8 +1741,8 @@ pymalloc_free(void *ctx, void *p)
1743
1741
* are no arenas in usable_arenas with that value.
1744
1742
*/
1745
1743
struct arena_object * lastnf = nfp2lasta [nf ];
1746
- assert ((nf == 0 && lastnf == NULL ) ||
1747
- (nf > 0 &&
1744
+ assert ((nf == 0 && lastnf == NULL ) ||
1745
+ (nf > 0 &&
1748
1746
lastnf != NULL &&
1749
1747
lastnf -> nfreepools == nf &&
1750
1748
(lastnf -> nextarena == NULL ||
0 commit comments