[Python-checkins] python/dist/src/Modules/expat xmlparse.c,1.4,1.5

fdrake@users.sourceforge.net fdrake@users.sourceforge.net
Mon, 27 Jan 2003 22:42:42 -0800


Update of /cvsroot/python/python/dist/src/Modules/expat
In directory sc8-pr-cvs1:/tmp/cvs-serv7149

Modified Files:
	xmlparse.c 
Log Message:
Update to the final version released as Expat 1.95.6 (maintaining
Martin's integration changes).


Index: xmlparse.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/expat/xmlparse.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** xmlparse.c	26 Jan 2003 08:40:46 -0000	1.4
--- xmlparse.c	28 Jan 2003 06:42:40 -0000	1.5
***************
*** 310,315 ****
  
  static enum XML_Error
! storeAtts(XML_Parser parser, const ENCODING *,
!           const char *s, TAG_NAME *tagNamePtr, BINDING **bindingsPtr);
  static enum XML_Error
  addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId,
--- 310,315 ----
  
  static enum XML_Error
! storeAtts(XML_Parser parser, const ENCODING *, const char *s,
!           TAG_NAME *tagNamePtr, BINDING **bindingsPtr);
  static enum XML_Error
  addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId,
***************
*** 2098,2106 ****
          tag->name.str = (XML_Char *)tag->buf;
          *toPtr = XML_T('\0');
-         if (!startElementHandler && (tok == XML_TOK_START_TAG_NO_ATTS)) {
-           if (defaultHandler)
-             reportDefault(parser, enc, s, next);
-           break;
-         }
          result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings));
          if (result)
--- 2098,2101 ----
***************
*** 2115,2125 ****
        }
      case XML_TOK_EMPTY_ELEMENT_NO_ATTS:
-       if (!startElementHandler && !endElementHandler) {
-         if (defaultHandler)
-           reportDefault(parser, enc, s, next);
-         if (tagLevel == 0)
-           return epilogProcessor(parser, next, end, nextPtr);
-         break;
-       }
        /* fall through */
      case XML_TOK_EMPTY_ELEMENT_WITH_ATTS:
--- 2110,2113 ----
***************
*** 2135,2145 ****
            return XML_ERROR_NO_MEMORY;
          poolFinish(&tempPool);
!         if (startElementHandler || 
!             (tok == XML_TOK_EMPTY_ELEMENT_WITH_ATTS)) {
!           result = storeAtts(parser, enc, s, &name, &bindings);
!           if (result)
!             return result;
!           poolFinish(&tempPool);
!         }
          if (startElementHandler) {
            startElementHandler(handlerArg, name.str, (const XML_Char **)atts);
--- 2123,2130 ----
            return XML_ERROR_NO_MEMORY;
          poolFinish(&tempPool);
!         result = storeAtts(parser, enc, s, &name, &bindings);
!         if (result)
!           return result;
!         poolFinish(&tempPool);
          if (startElementHandler) {
            startElementHandler(handlerArg, name.str, (const XML_Char **)atts);
***************
*** 2344,2349 ****
  }
  
! /* If tagNamePtr is non-null, build a real list of attributes,
!    otherwise just check the attributes for well-formedness.
  */
  static enum XML_Error
--- 2329,2341 ----
  }
  
! /* Precondition: all arguments must be non-NULL;
!    Purpose:
!    - normalize attributes
!    - check attributes for well-formedness
!    - generate namespace aware attribute names (URI, prefix)
!    - build list of attributes for startElementHandler
!    - default attributes
!    - process namespace declarations (check and report them)
!    - generate namespace aware element name (URI, prefix)
  */
  static enum XML_Error
***************
*** 2366,2384 ****
  
    /* lookup the element type name */
!   if (tagNamePtr) {
!     elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, tagNamePtr->str,0);
!     if (!elementType) {
!       const XML_Char *name = poolCopyString(&dtd->pool, tagNamePtr->str);
!       if (!name)
!         return XML_ERROR_NO_MEMORY;
!       elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, name,
!                                            sizeof(ELEMENT_TYPE));
!       if (!elementType)
!         return XML_ERROR_NO_MEMORY;
!       if (ns && !setElementTypePrefix(parser, elementType))
!         return XML_ERROR_NO_MEMORY;
!     }
!     nDefaultAtts = elementType->nDefaultAtts;
    }
    /* get the attributes from the tokenizer */
    n = XmlGetAttributes(enc, attStr, attsSize, atts);
--- 2358,2375 ----
  
    /* lookup the element type name */
!   elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, tagNamePtr->str,0);
!   if (!elementType) {
!     const XML_Char *name = poolCopyString(&dtd->pool, tagNamePtr->str);
!     if (!name)
!       return XML_ERROR_NO_MEMORY;
!     elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, name,
!                                          sizeof(ELEMENT_TYPE));
!     if (!elementType)
!       return XML_ERROR_NO_MEMORY;
!     if (ns && !setElementTypePrefix(parser, elementType))
!       return XML_ERROR_NO_MEMORY;
    }
+   nDefaultAtts = elementType->nDefaultAtts;
+ 
    /* get the attributes from the tokenizer */
    n = XmlGetAttributes(enc, attStr, attsSize, atts);
***************
*** 2394,2397 ****
--- 2385,2389 ----
        XmlGetAttributes(enc, attStr, n, atts);
    }
+ 
    appAtts = (const XML_Char **)atts;
    for (i = 0; i < n; i++) {
***************
*** 2431,2442 ****
        if (result)
          return result;
!       if (tagNamePtr) {
!         appAtts[attIndex] = poolStart(&tempPool);
!         poolFinish(&tempPool);
!       }
!       else
!         poolDiscard(&tempPool);
      }
!     else if (tagNamePtr) {
        /* the value did not need normalizing */
        appAtts[attIndex] = poolStoreString(&tempPool, enc, atts[i].valuePtr,
--- 2423,2430 ----
        if (result)
          return result;
!       appAtts[attIndex] = poolStart(&tempPool);
!       poolFinish(&tempPool);
      }
!     else {
        /* the value did not need normalizing */
        appAtts[attIndex] = poolStoreString(&tempPool, enc, atts[i].valuePtr,
***************
*** 2447,2451 ****
      }
      /* handle prefixed attribute names */
!     if (attId->prefix && tagNamePtr) {
        if (attId->xmlns) {
          /* deal with namespace declarations here */
--- 2435,2439 ----
      }
      /* handle prefixed attribute names */
!     if (attId->prefix) {
        if (attId->xmlns) {
          /* deal with namespace declarations here */
***************
*** 2466,2508 ****
        attIndex++;
    }
!   if (tagNamePtr) {
!     int j;
!     nSpecifiedAtts = attIndex;
!     if (elementType->idAtt && (elementType->idAtt->name)[-1]) {
!       for (i = 0; i < attIndex; i += 2)
!         if (appAtts[i] == elementType->idAtt->name) {
!           idAttIndex = i;
!           break;
!         }
!     }
!     else
!       idAttIndex = -1;
!     /* do attribute defaulting */
!     for (j = 0; j < nDefaultAtts; j++) {
!       const DEFAULT_ATTRIBUTE *da = elementType->defaultAtts + j;
!       if (!(da->id->name)[-1] && da->value) {
!         if (da->id->prefix) {
!           if (da->id->xmlns) {
!             enum XML_Error result = addBinding(parser, da->id->prefix, da->id,
!                                                da->value, bindingsPtr);
!             if (result)
!               return result;
!           }
!           else {
!             (da->id->name)[-1] = 2;
!             nPrefixes++;
!             appAtts[attIndex++] = da->id->name;
!             appAtts[attIndex++] = da->value;
!           }
          }
          else {
!           (da->id->name)[-1] = 1;
            appAtts[attIndex++] = da->id->name;
            appAtts[attIndex++] = da->value;
          }
        }
      }
-     appAtts[attIndex] = 0;
    }
    i = 0;
    if (nPrefixes) {
--- 2454,2497 ----
        attIndex++;
    }
! 
!   /* set-up for XML_GetSpecifiedAttributeCount and XML_GetIdAttributeIndex */
!   nSpecifiedAtts = attIndex;
!   if (elementType->idAtt && (elementType->idAtt->name)[-1]) {
!     for (i = 0; i < attIndex; i += 2)
!       if (appAtts[i] == elementType->idAtt->name) {
!         idAttIndex = i;
!         break;
!       }
!   }
!   else
!     idAttIndex = -1;
! 
!   /* do attribute defaulting */
!   for (i = 0; i < nDefaultAtts; i++) {
!     const DEFAULT_ATTRIBUTE *da = elementType->defaultAtts + i;
!     if (!(da->id->name)[-1] && da->value) {
!       if (da->id->prefix) {
!         if (da->id->xmlns) {
!           enum XML_Error result = addBinding(parser, da->id->prefix, da->id,
!                                              da->value, bindingsPtr);
!           if (result)
!             return result;
          }
          else {
!           (da->id->name)[-1] = 2;
!           nPrefixes++;
            appAtts[attIndex++] = da->id->name;
            appAtts[attIndex++] = da->value;
          }
        }
+       else {
+         (da->id->name)[-1] = 1;
+         appAtts[attIndex++] = da->id->name;
+         appAtts[attIndex++] = da->value;
+       }
      }
    }
+   appAtts[attIndex] = 0;
+ 
    i = 0;
    if (nPrefixes) {
***************
*** 2549,2556 ****
    for (; i < attIndex; i += 2)
      ((XML_Char *)(appAtts[i]))[-1] = 0;
-   if (!tagNamePtr)
-     return XML_ERROR_NONE;
    for (binding = *bindingsPtr; binding; binding = binding->nextTagBinding)
      binding->attId->name[-1] = 0;
    /* expand the element type name */
    if (elementType->prefix) {
--- 2538,2544 ----
    for (; i < attIndex; i += 2)
      ((XML_Char *)(appAtts[i]))[-1] = 0;
    for (binding = *bindingsPtr; binding; binding = binding->nextTagBinding)
      binding->attId->name[-1] = 0;
+ 
    /* expand the element type name */
    if (elementType->prefix) {