@@ -1580,42 +1580,43 @@ allocate_from_new_pool(uint size)
1580
1580
1581
1581
/* pymalloc allocator
1582
1582
1583
- Return 1 if pymalloc allocated memory and wrote the pointer into *ptr_p .
1583
+ Return a pointer to newly allocated memory if pymalloc allocated memory .
1584
1584
1585
- Return 0 if pymalloc failed to allocate the memory block: on bigger
1585
+ Return NULL if pymalloc failed to allocate the memory block: on bigger
1586
1586
requests, on error in the code below (as a last chance to serve the request)
1587
1587
or when the max memory limit has been reached.
1588
1588
*/
1589
- static inline int
1590
- pymalloc_alloc (void * ctx , void * * ptr_p , size_t nbytes )
1589
+ static inline void *
1590
+ pymalloc_alloc (void * ctx , size_t nbytes )
1591
1591
{
1592
1592
#ifdef WITH_VALGRIND
1593
1593
if (UNLIKELY (running_on_valgrind == -1 )) {
1594
1594
running_on_valgrind = RUNNING_ON_VALGRIND ;
1595
1595
}
1596
1596
if (UNLIKELY (running_on_valgrind )) {
1597
- return 0 ;
1597
+ return NULL ;
1598
1598
}
1599
1599
#endif
1600
1600
1601
1601
if (UNLIKELY (nbytes == 0 )) {
1602
- return 0 ;
1602
+ return NULL ;
1603
1603
}
1604
1604
if (UNLIKELY (nbytes > SMALL_REQUEST_THRESHOLD )) {
1605
- return 0 ;
1605
+ return NULL ;
1606
1606
}
1607
1607
1608
1608
uint size = (uint )(nbytes - 1 ) >> ALIGNMENT_SHIFT ;
1609
1609
poolp pool = usedpools [size + size ];
1610
1610
block * bp ;
1611
-
1611
+
1612
1612
if (LIKELY (pool != pool -> nextpool )) {
1613
1613
/*
1614
1614
* There is a used pool for this size class.
1615
1615
* Pick up the head block of its free list.
1616
1616
*/
1617
1617
++ pool -> ref .count ;
1618
1618
bp = pool -> freeblock ;
1619
+ assert (bp != NULL );
1619
1620
1620
1621
if (UNLIKELY ((pool -> freeblock = * (block * * )bp ) == NULL )) {
1621
1622
// Reached the end of the free list, try to extend it.
@@ -1627,22 +1628,17 @@ pymalloc_alloc(void *ctx, void **ptr_p, size_t nbytes)
1627
1628
* available: use a free pool.
1628
1629
*/
1629
1630
bp = allocate_from_new_pool (size );
1630
- if (UNLIKELY (bp == NULL )) {
1631
- return 0 ;
1632
- }
1633
1631
}
1634
1632
1635
- assert (bp != NULL );
1636
- * ptr_p = (void * )bp ;
1637
- return 1 ;
1633
+ return (void * )bp ;
1638
1634
}
1639
1635
1640
1636
1641
1637
static void *
1642
1638
_PyObject_Malloc (void * ctx , size_t nbytes )
1643
1639
{
1644
- void * ptr ;
1645
- if (LIKELY (pymalloc_alloc ( ctx , & ptr , nbytes ) )) {
1640
+ void * ptr = pymalloc_alloc ( ctx , nbytes ) ;
1641
+ if (LIKELY (ptr != NULL )) {
1646
1642
return ptr ;
1647
1643
}
1648
1644
@@ -1657,12 +1653,11 @@ _PyObject_Malloc(void *ctx, size_t nbytes)
1657
1653
static void *
1658
1654
_PyObject_Calloc (void * ctx , size_t nelem , size_t elsize )
1659
1655
{
1660
- void * ptr ;
1661
-
1662
1656
assert (elsize == 0 || nelem <= (size_t )PY_SSIZE_T_MAX / elsize );
1663
1657
size_t nbytes = nelem * elsize ;
1664
1658
1665
- if (LIKELY (pymalloc_alloc (ctx , & ptr , nbytes ))) {
1659
+ void * ptr = pymalloc_alloc (ctx , nbytes );
1660
+ if (LIKELY (ptr != NULL )) {
1666
1661
memset (ptr , 0 , nbytes );
1667
1662
return ptr ;
1668
1663
}
@@ -1711,8 +1706,8 @@ insert_to_freepool(poolp pool)
1711
1706
* are no arenas in usable_arenas with that value.
1712
1707
*/
1713
1708
struct arena_object * lastnf = nfp2lasta [nf ];
1714
- assert ((nf == 0 && lastnf == NULL ) ||
1715
- (nf > 0 &&
1709
+ assert ((nf == 0 && lastnf == NULL ) ||
1710
+ (nf > 0 &&
1716
1711
lastnf != NULL &&
1717
1712
lastnf -> nfreepools == nf &&
1718
1713
(lastnf -> nextarena == NULL ||
0 commit comments