astropy/utils/xml/src/iterparse.c
/*
 * Handle the XML declaration so that we can determine its encoding.
 */
Handle the XML declaration so that we can determine its encoding.
Handle the XML declaration so that we can determine its encoding .
static void
xmlDecl(IterParser *self, const XML_Char *version,
        const XML_Char *encoding, int standalone)
{
    PyObject* tuple        = NULL;
    PyObject* xml_str      = NULL;
    PyObject* attrs        = NULL;
    PyObject* encoding_str = NULL;
    PyObject* version_str  = NULL;
    PyObject* pos          = NULL;
    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);
        xml_str = PyUnicode_FromString("xml");
        if (xml_str == NULL) {
            goto fail;
        }
        PyTuple_SET_ITEM(tuple, 1, xml_str);
        xml_str = NULL;
        attrs = PyDict_New();
        if (attrs == NULL) {
            goto fail;
        }
        if (encoding) {
            encoding_str = PyUnicode_FromString(encoding);
        } else {
            encoding_str = PyUnicode_FromString("");
        }
        if (encoding_str == NULL) {
            goto fail;
        }
        if (PyDict_SetItemString(attrs, "encoding", encoding_str)) {
            Py_DECREF(encoding_str);
            goto fail;
        }
        Py_DECREF(encoding_str);
        encoding_str = NULL;
        if (version) {
            version_str = PyUnicode_FromString(version);
        } else {
            version_str = PyUnicode_FromString("");
        }
        if (version_str == NULL) {
            goto fail;
        }
        if (PyDict_SetItemString(attrs, "version", version_str)) {
            Py_DECREF(version_str);
            goto fail;
        }
        Py_DECREF(version_str);
        version_str = NULL;
        PyTuple_SET_ITEM(tuple, 2, attrs);
        attrs = 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;
        self->queue[self->queue_write_idx++] = tuple;
    } else {
        PyErr_SetString(
            PyExc_RuntimeError,
            "XML queue overflow in xmlDecl.  This most likely indicates an internal bug.");
        goto fail;
    }
    return;
 fail:
    Py_XDECREF(tuple);
    Py_XDECREF(attrs);
    XML_StopParser(self->parser, 0);
}
static void xmlDecl ( IterParser * self , const XML_Char * version , const XML_Char * encoding , int standalone ) { PyObject * tuple = NULL ; PyObject * xml_str = NULL ; PyObject * attrs = NULL ; PyObject * encoding_str = NULL ; PyObject * version_str = NULL ; PyObject * pos = NULL ; 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 ) ; xml_str = PyUnicode_FromString ( " " ) ; if ( xml_str == NULL ) { goto fail ; } PyTuple_SET_ITEM ( tuple , 1 , xml_str ) ; xml_str = NULL ; attrs = PyDict_New ( ) ; if ( attrs == NULL ) { goto fail ; } if ( encoding ) { encoding_str = PyUnicode_FromString ( encoding ) ; } else { encoding_str = PyUnicode_FromString ( " " ) ; } if ( encoding_str == NULL ) { goto fail ; } if ( PyDict_SetItemString ( attrs , " " , encoding_str ) ) { Py_DECREF ( encoding_str ) ; goto fail ; } Py_DECREF ( encoding_str ) ; encoding_str = NULL ; if ( version ) { version_str = PyUnicode_FromString ( version ) ; } else { version_str = PyUnicode_FromString ( " " ) ; } if ( version_str == NULL ) { goto fail ; } if ( PyDict_SetItemString ( attrs , " " , version_str ) ) { Py_DECREF ( version_str ) ; goto fail ; } Py_DECREF ( version_str ) ; version_str = NULL ; PyTuple_SET_ITEM ( tuple , 2 , attrs ) ; attrs = 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 ; self -> queue [ self -> queue_write_idx ++ ] = tuple ; } else { PyErr_SetString ( PyExc_RuntimeError , " " ) ; goto fail ; } return ; fail : Py_XDECREF ( tuple ) ; Py_XDECREF ( attrs ) ; XML_StopParser ( self -> parser , 0 ) ; }
Handle the XML declaration so that we can determine its encoding.
Handle the XML declaration so that we can determine its encoding .