From b0f397e108eee45a309f2e5d4b523dd096d7ea32 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Tue, 23 Dec 2003 23:30:53 +0000 Subject: [PATCH] types might be redefined in includes, quick fix to allow this but lacks * xmlschemas.c include/libxml/schemasInternals.h: types might be redefined in includes, quick fix to allow this but lacks the equality of the redefinition test. Daniel --- ChangeLog | 6 ++++ include/libxml/schemasInternals.h | 1 + xmlschemas.c | 60 +++++++++++++++++++++++++++---- 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2f9d629a..48222221 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Dec 24 00:29:30 CET 2003 Daniel Veillard + + * xmlschemas.c include/libxml/schemasInternals.h: types might be + redefined in includes, quick fix to allow this but lacks the + equality of the redefinition test. + Tue Dec 23 15:14:37 HKT 2003 William Brack * valid.c: fixed bug concerning validation using external diff --git a/include/libxml/schemasInternals.h b/include/libxml/schemasInternals.h index d7925870..4a8fd695 100644 --- a/include/libxml/schemasInternals.h +++ b/include/libxml/schemasInternals.h @@ -200,6 +200,7 @@ struct _xmlSchemaType { const xmlChar *baseNs; xmlSchemaTypePtr baseType; xmlSchemaFacetPtr facets; + struct _xmlSchemaType *redef;/* possible redefinitions for the type */ }; /* diff --git a/xmlschemas.c b/xmlschemas.c index 91e53c64..d084f1e1 100644 --- a/xmlschemas.c +++ b/xmlschemas.c @@ -7,6 +7,12 @@ * Daniel Veillard */ +/* + * TODO: + * - when types are redefined in includes, check that all + * types in the redef list are equal + * -> need a type equality operation. + */ #define IN_LIBXML #include "libxml.h" @@ -92,6 +98,7 @@ struct _xmlSchemaParserCtxt { xmlAutomataStatePtr state; xmlDictPtr dict; /* dictionnary for interned string names */ + int includes; /* the inclusion level, 0 for root or imports */ }; @@ -587,6 +594,24 @@ xmlSchemaFreeType(xmlSchemaTypePtr type) xmlFree(type); } +/** + * xmlSchemaFreeTypeList: + * @type: a schema type structure + * + * Deallocate a Schema Type structure. + */ +static void +xmlSchemaFreeTypeList(xmlSchemaTypePtr type) +{ + xmlSchemaTypePtr next; + + while (type != NULL) { + next = type->redef; + xmlSchemaFreeType(type); + type = next; + } +} + /** * xmlSchemaFree: * @schema: a schema structure @@ -613,7 +638,7 @@ xmlSchemaFree(xmlSchemaPtr schema) (xmlHashDeallocator) xmlSchemaFreeElement); if (schema->typeDecl != NULL) xmlHashFree(schema->typeDecl, - (xmlHashDeallocator) xmlSchemaFreeType); + (xmlHashDeallocator) xmlSchemaFreeTypeList); if (schema->groupDecl != NULL) xmlHashFree(schema->groupDecl, (xmlHashDeallocator) xmlSchemaFreeType); @@ -1362,14 +1387,31 @@ xmlSchemaAddType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, } memset(ret, 0, sizeof(xmlSchemaType)); ret->name = xmlDictLookup(ctxt->dict, name, -1); + ret->redef = NULL; val = xmlHashAddEntry2(schema->typeDecl, name, namespace, ret); if (val != 0) { - xmlSchemaPErr(ctxt, (xmlNodePtr) ctxt->doc, - XML_SCHEMAP_REDEFINED_TYPE, - "Type %s already defined\n", - name, NULL); - xmlFree(ret); - return (NULL); + if (ctxt->includes == 0) { + xmlSchemaPErr(ctxt, (xmlNodePtr) ctxt->doc, + XML_SCHEMAP_REDEFINED_TYPE, + "Type %s already defined\n", + name, NULL); + xmlFree(ret); + return (NULL); + } else { + xmlSchemaTypePtr prev; + + prev = xmlHashLookup2(schema->typeDecl, name, namespace); + if (prev == NULL) { + xmlSchemaPErr(ctxt, (xmlNodePtr) ctxt->doc, + XML_ERR_INTERNAL_ERROR, + "Internal error on type %s definition\n", + name, NULL); + xmlFree(ret); + return (NULL); + } + ret->redef = prev->redef; + prev->redef = ret; + } } ret->minOccurs = 1; ret->maxOccurs = 1; @@ -2580,6 +2622,7 @@ xmlSchemaImportSchema(xmlSchemaParserCtxtPtr ctxt, /* Keep the same dictionnary for parsing, really */ xmlDictReference(ctxt->dict); newctxt->dict = ctxt->dict; + newctxt->includes = 0; newctxt->URL = xmlDictLookup(newctxt->dict, schemaLocation, -1); xmlSchemaSetParserErrors(newctxt, ctxt->error, ctxt->warning, @@ -2866,7 +2909,9 @@ xmlSchemaParseSchemaTopLevel(xmlSchemaParserCtxtPtr ctxt, } else if (IS_SCHEMA(child, "import")) { xmlSchemaParseImport(ctxt, schema, child); } else if (IS_SCHEMA(child, "include")) { + ctxt->includes++; xmlSchemaParseInclude(ctxt, schema, child); + ctxt->includes--; } else if (IS_SCHEMA(child, "redefine")) { TODO } @@ -3729,6 +3774,7 @@ xmlSchemaNewParserCtxt(const char *URL) memset(ret, 0, sizeof(xmlSchemaParserCtxt)); ret->dict = xmlDictCreate(); ret->URL = xmlDictLookup(ret->dict, (const xmlChar *) URL, -1); + ret->includes = 0; return (ret); }