astropy/utils/xml/src/iterparse.c
/*
 * Handle the expat startElement event.
 */
Handle the expat startElement event.
Handle the expat startElement event .
static void
startElement(IterParser *self, const XML_Char *name, const XML_Char **atts)
{
    PyObject*        pyname = NULL;
    PyObject*        pyatts = NULL;
    const XML_Char** att_ptr = atts;
    const XML_Char*  name_start = NULL;
    PyObject*        tuple = NULL;
    PyObject*        key = NULL;
    PyObject*        val = NULL;
    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_True);
        PyTuple_SET_ITEM(tuple, 0, Py_True);
        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;
        }
        if (*att_ptr) {
            pyatts = PyDict_New();
            if (pyatts == NULL) {
                goto fail;
            }
            do {
                if (*(*(att_ptr + 1)) != 0) {
                    key = PyUnicode_FromString(*att_ptr);
                    if (key == NULL) {
                        goto fail;
                    }
                    val = PyUnicode_FromString(*(att_ptr + 1));
                    if (val == NULL) {
                        Py_DECREF(key);
                        goto fail;
                    }
                    if (PyDict_SetItem(pyatts, key, val)) {
                        Py_DECREF(key);
                        Py_DECREF(val);
                        goto fail;
                    }
                    Py_DECREF(key);
                    Py_DECREF(val);
                    key = val = NULL;
                }
                att_ptr += 2;
            } while (*att_ptr);
        } else {
            Py_INCREF(self->dict_singleton);
            pyatts = self->dict_singleton;
        }
        PyTuple_SetItem(tuple, 2, pyatts);
        pyatts = NULL;
        self->last_line = (unsigned long)XML_GetCurrentLineNumber(
            self->parser);
        self->last_col = (unsigned long)XML_GetCurrentColumnNumber(
            self->parser);
        pos = make_pos(self);
        if (pos == NULL) {
            goto fail;
        }
        PyTuple_SetItem(tuple, 3, pos);
        pos = NULL;
        text_clear(self);
        self->keep_text = 1;
        self->queue[self->queue_write_idx++] = tuple;
    } else {
        PyErr_SetString(
            PyExc_RuntimeError,
            "XML queue overflow in startElement.  This most likely indicates an internal bug.");
        goto fail;
    }
    return;
 fail:
    Py_XDECREF(tuple);
    Py_XDECREF(pyatts);
    XML_StopParser(self->parser, 0);
}
static void startElement ( IterParser * self , const XML_Char * name , const XML_Char * * atts ) { PyObject * pyname = NULL ; PyObject * pyatts = NULL ; const XML_Char * * att_ptr = atts ; const XML_Char * name_start = NULL ; PyObject * tuple = NULL ; PyObject * key = NULL ; PyObject * val = NULL ; 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_True ) ; PyTuple_SET_ITEM ( tuple , 0 , Py_True ) ; 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 ; } if ( * att_ptr ) { pyatts = PyDict_New ( ) ; if ( pyatts == NULL ) { goto fail ; } do { if ( * ( * ( att_ptr + 1 ) ) != 0 ) { key = PyUnicode_FromString ( * att_ptr ) ; if ( key == NULL ) { goto fail ; } val = PyUnicode_FromString ( * ( att_ptr + 1 ) ) ; if ( val == NULL ) { Py_DECREF ( key ) ; goto fail ; } if ( PyDict_SetItem ( pyatts , key , val ) ) { Py_DECREF ( key ) ; Py_DECREF ( val ) ; goto fail ; } Py_DECREF ( key ) ; Py_DECREF ( val ) ; key = val = NULL ; } att_ptr += 2 ; } while ( * att_ptr ) ; } else { Py_INCREF ( self -> dict_singleton ) ; pyatts = self -> dict_singleton ; } PyTuple_SetItem ( tuple , 2 , pyatts ) ; pyatts = NULL ; self -> last_line = ( unsigned long ) XML_GetCurrentLineNumber ( self -> parser ) ; self -> last_col = ( unsigned long ) XML_GetCurrentColumnNumber ( self -> parser ) ; pos = make_pos ( self ) ; if ( pos == NULL ) { goto fail ; } PyTuple_SetItem ( tuple , 3 , pos ) ; pos = NULL ; text_clear ( self ) ; self -> keep_text = 1 ; self -> queue [ self -> queue_write_idx ++ ] = tuple ; } else { PyErr_SetString ( PyExc_RuntimeError , " " ) ; goto fail ; } return ; fail : Py_XDECREF ( tuple ) ; Py_XDECREF ( pyatts ) ; XML_StopParser ( self -> parser , 0 ) ; }
Handle the expat startElement event.
Handle the expat startElement 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" */