astropy/utils/xml/src/iterparse.c
/**
 * Reallocate text buffer to the next highest power of two that fits the
 * requested size.
 */
Reallocate text buffer to the next highest power of two that fits the
requested size.
Reallocate text buffer to the next highest power of two that fits the requested size .
static int
text_realloc(IterParser *self, Py_ssize_t req_size)
{
    Py_ssize_t  n       = req_size;
    char       *new_mem = NULL;
    if (req_size < self->text_alloc) {
        return 0;
    }
    n = next_power_of_2(n);
    if (n < req_size) {
        PyErr_SetString(PyExc_MemoryError, "Out of memory for XML text.");
        return -1;
    }
    new_mem = malloc(n * sizeof(XML_Char));
    if (new_mem == NULL) {
        PyErr_SetString(PyExc_MemoryError, "Out of memory for XML text.");
        return -1;
    }
    memcpy(new_mem, self->text, (size_t)(self->text_size + 1) * sizeof(XML_Char));
    free(self->text);
    self->text = new_mem;
    self->text_alloc = n;
    return 0;
}
static int text_realloc ( IterParser * self , Py_ssize_t req_size ) { Py_ssize_t n = req_size ; char * new_mem = NULL ; if ( req_size < self -> text_alloc ) { return 0 ; } n = next_power_of_2 ( n ) ; if ( n < req_size ) { PyErr_SetString ( PyExc_MemoryError , " " ) ; return -1 ; } new_mem = malloc ( n * sizeof ( XML_Char ) ) ; if ( new_mem == NULL ) { PyErr_SetString ( PyExc_MemoryError , " " ) ; return -1 ; } memcpy ( new_mem , self -> text , ( size_t ) ( self -> text_size + 1 ) * sizeof ( XML_Char ) ) ; free ( self -> text ) ; self -> text = new_mem ; self -> text_alloc = n ; return 0 ; }
Reallocate text buffer to the next highest power of two that fits the
 requested size.
Reallocate text buffer to the next highest power of two that fits the requested size .
/* Calculate the next-highest power of two */