astropy/utils/xml/src/iterparse.c
/*
 * Handle the expat endElement event.
 */
Handle the expat endElement event.
Handle the expat endElement event .
static void
endElement(IterParser *self, const XML_Char *name)
{
    PyObject*       pyname     = NULL;
    PyObject*       tuple      = NULL;
    PyObject*       pytext     = NULL;
    const XML_Char* name_start = NULL;
    XML_Char*       end;
    PyObject*       pos        = NULL;
    if (PyErr_Occurred() != NULL) {
        XML_StopParser(self->parser, 0);
        return;
    }
    if (self->queue_write_idx < self->queue_size) {
        tuple = PyTuple_New(4);
        if (tuple == NULL) {
            goto fail;
        }
        Py_INCREF(Py_False);
        PyTuple_SET_ITEM(tuple, 0, Py_False);
        if ((*(int*)name & TD_AS_INT_MASK) == TD_AS_INT) {
            Py_INCREF(self->td_singleton);
            PyTuple_SetItem(tuple, 1, self->td_singleton);
        } else {
            name_start = remove_namespace(name);
            pyname = PyUnicode_FromString(name_start);
            if (pyname == NULL) {
                goto fail;
            }
            PyTuple_SetItem(tuple, 1, pyname);
            pyname = NULL;
        }
        end = self->text + self->text_size - 1;
        while (end >= self->text && IS_WHITESPACE(*end)) {
            --end;
            --self->text_size;
        }
        pytext = PyUnicode_FromStringAndSize(self->text, self->text_size);
        if (pytext == NULL) {
            goto fail;
        }
        PyTuple_SetItem(tuple, 2, pytext);
        pytext = NULL;
        pos = make_pos(self);
        if (pos == NULL) {
            goto fail;
        }
        PyTuple_SetItem(tuple, 3, pos);
        pos = NULL;
        self->keep_text = 0;
        self->queue[self->queue_write_idx++] = tuple;
    } else {
        PyErr_SetString(
            PyExc_RuntimeError,
            "XML queue overflow in endElement.  This most likely indicates an internal bug.");
        goto fail;
    }
    return;
 fail:
    Py_XDECREF(tuple);
    XML_StopParser(self->parser, 0);
}
static void endElement ( IterParser * self , const XML_Char * name ) { PyObject * pyname = NULL ; PyObject * tuple = NULL ; PyObject * pytext = NULL ; const XML_Char * name_start = NULL ; XML_Char * end ; PyObject * pos = NULL ; if ( PyErr_Occurred ( ) != NULL ) { XML_StopParser ( self -> parser , 0 ) ; return ; } if ( self -> queue_write_idx < self -> queue_size ) { tuple = PyTuple_New ( 4 ) ; if ( tuple == NULL ) { goto fail ; } Py_INCREF ( Py_False ) ; PyTuple_SET_ITEM ( tuple , 0 , Py_False ) ; if ( ( * ( int * ) name & TD_AS_INT_MASK ) == TD_AS_INT ) { Py_INCREF ( self -> td_singleton ) ; PyTuple_SetItem ( tuple , 1 , self -> td_singleton ) ; } else { name_start = remove_namespace ( name ) ; pyname = PyUnicode_FromString ( name_start ) ; if ( pyname == NULL ) { goto fail ; } PyTuple_SetItem ( tuple , 1 , pyname ) ; pyname = NULL ; } end = self -> text + self -> text_size - 1 ; while ( end >= self -> text && IS_WHITESPACE ( * end ) ) { -- end ; -- self -> text_size ; } pytext = PyUnicode_FromStringAndSize ( self -> text , self -> text_size ) ; if ( pytext == NULL ) { goto fail ; } PyTuple_SetItem ( tuple , 2 , pytext ) ; pytext = NULL ; pos = make_pos ( self ) ; if ( pos == NULL ) { goto fail ; } PyTuple_SetItem ( tuple , 3 , pos ) ; pos = NULL ; self -> keep_text = 0 ; self -> queue [ self -> queue_write_idx ++ ] = tuple ; } else { PyErr_SetString ( PyExc_RuntimeError , " " ) ; goto fail ; } return ; fail : Py_XDECREF ( tuple ) ; XML_StopParser ( self -> parser , 0 ) ; }
Handle the expat endElement event.
Handle the expat endElement event .
/* If we've already had an error in a previous call, don't make
       things worse. */ /* Don't overflow the queue -- in practice this should *never* happen */ /* This is an egregious but effective optimization.  Since by
           far the most frequently occurring element name in a large
           VOTABLE file is TD, we explicitly check for it here with
           integer comparison to avoid the lookup in the interned
           string table in PyString_InternFromString, and return a
           singleton string for "TD" */ /* Cut whitespace off the end of the string */