Ignore:
Timestamp:
Jan 5, 2014, 7:04:30 AM (5 years ago)
Author:
cameron
Message:

Namespace bug fix for icXML-0.95

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icXML/icXML-0.95/src/icxmlc/XMLNamespaceResolver.c

    r3563 r3602  
    235235gid_t XMLNamespaceResolver::addOrFindPrefixId(const XMLCh * qName, const XMLSize_t length)
    236236{
    237     return addOrFindPrefix(qName, length)->getId();
     237    const gid_t prefixId = addOrFindPrefix(qName, length)->getId();
     238    DEBUG_NAMESPACE_MESSAGE(" -- prefixId=" << prefixId)
     239    return prefixId;
    238240}
    239241
     
    260262XMLNamespaceResolver::findPrefix(const XMLCh * prefix, const int length) const
    261263{
     264    DEBUG_NAMESPACE_MESSAGE("XMLNamespaceResolver::findPrefix(" << prefix << ',' << length << ')')
    262265    // resolve the prefix id from the prefix; since this will not be required
    263266    // very often, just iterate through a list.
     
    266269        if (fPrefixList[index].equals(prefix, length))
    267270        {
     271            DEBUG_NAMESPACE_MESSAGE(" -- found @ " << index)
    268272            return &fPrefixList[index];
    269273        }
     
    279283XMLNamespaceResolver::getPrefixForId(const gid_t prefixId) const
    280284{
    281     if (likely((prefixId < fPrefixCount) && (fPrefixList[prefixId].id == prefixId)))
    282     {
    283         return fPrefixList[prefixId].getKey();
     285    DEBUG_NAMESPACE_MESSAGE("XMLNamespaceResolver::getPrefixForId(" << prefixId << ") " << fPrefixList.capacity())
     286
     287    assert (prefixId < fPrefixList.capacity());
     288
     289    if (likely(prefixId < fPrefixCount))
     290    {
     291        const XMLPrefixEntry & prefix = fPrefixList[prefixId];
     292        DEBUG_MESSAGE(" &(prefix)=" << (size_t)(&prefix))
     293        if (prefix.id == prefixId)
     294        {
     295            return prefix.getKey();
     296        }
    284297    }
    285298
     
    288301    for (gid_t index = 0; index < fPrefixCount; index++)
    289302    {
    290         if (fPrefixList[index].id == prefixId)
    291         {
    292             return fPrefixList[index].getKey();
     303        const XMLPrefixEntry & entry = fPrefixList[index];
     304        DEBUG_MESSAGE("entry[" << index << "]=" << (size_t)(&entry))
     305        if (entry.id == prefixId)
     306        {
     307            return entry.getKey();
    293308        }
    294309    }
     
    315330    const gid_t prefixId = max<size_t>(fPrefixCount, fUriPool.count());
    316331
     332    DEBUG_NAMESPACE_MESSAGE(" -- new prefixId=max(" << fPrefixCount << ',' << fUriPool.count() << ")=" << prefixId)
     333
    317334        if (unlikely(fPrefixToNamespaceBindingTable.setCapacity() <= prefixId))
    318335        {
     
    324341
    325342    // if our prefix count equals our capacity, then we need to expand all of the related buffers
    326     if (unlikely(fPrefixCount == fPrefixList.capacity()))
     343    if (unlikely(fPrefixCount >= fPrefixList.capacity()))
    327344    {
    328345        DEBUG_NAMESPACE_MESSAGE(" -- resizing fPrefixList");
    329         fPrefixList.resizeToFit(fPrefixList.capacity(), fPrefixList.capacity() * 2);
    330     }
    331 
    332     XMLPrefixEntry * newPrefix = &fPrefixList[fPrefixCount++];
     346        fPrefixList.resizeToFit(fPrefixList.capacity() * 2);
     347    }
     348
     349    XMLPrefixEntry & newPrefix = fPrefixList[fPrefixCount++];
    333350        // QUESTION: does storing the prefixes in the string pool help or hinder? we can just point to
    334351        // the symbols and store only the prefix's length?
    335352        // NOTE: this may require modifying the TraverseSchema class to do this safely.
    336     newPrefix->key = fPrefixPool.insert(prefix, length);
    337     newPrefix->length = length;
    338     newPrefix->id = prefixId;
     353    newPrefix.key = fPrefixPool.insert(prefix, length);
     354    newPrefix.length = length;
     355    newPrefix.id = prefixId;
     356
     357    DEBUG_NAMESPACE_MESSAGE(" &(newPrefix)=" << (size_t)(&newPrefix))
    339358
    340359        // add this entry to the canonical prefix set since we assume that the prefix and uri ids
     
    342361        fCanonicalBindingSet += prefixId;
    343362
    344     return newPrefix;
     363    return &newPrefix;
    345364}
    346365
     
    354373    if (unlikely(linkId == XMLNamespaceResolver::fUnknownUriId))
    355374        {
    356         DEBUG_MESSAGE(" -- adding new uriId")
     375        DEBUG_MESSAGE(" -- adding new uriId (prefixId=" << prefixId << " of " << fUriPool.capacity() << ')')
    357376        linkId = prefixId;
    358377        if (unlikely(prefixId > fUriPool.capacity()))
     
    381400XMLNamespaceResolver::mapPrefixToUri(const gid_t prefixId, const gid_t uriId)
    382401{
    383 
    384402    // both the prefixId and the uriId exist, but they are not mapped to one another.
    385403    const gid_t namespaceId = bindPrefixToUri(prefixId, uriId);
     404
     405    assert (fScope < fLocallyModifiedNamespaces.setCapacity());
     406    assert (namespaceId < fLocallyModifiedNamespaces.bitCapacity());
     407    assert (namespaceId < fCurrentlyVisibleNamespaces.capacity());
    386408
    387409    // add the new namespace to the namespace 'stack'
     
    498520
    499521
    500         XMLPrefixEntry * entry = &fPrefixList[id];
     522    XMLPrefixEntry & entry = fPrefixList[id];
    501523        // QUESTION: does storing the prefixes in the string pool help or hinder? we can just point to
    502524        // the symbols and store only the prefix's length?
    503525        // NOTE: this may require modifying the TraverseSchema class to do this safely.
    504         entry->key = prefix; // _prefixAndUriStringPool.insert(prefix, length);
    505         entry->length = prefixLength;
    506         entry->id = id;
     526    entry.key = prefix; // _prefixAndUriStringPool.insert(prefix, length);
     527    entry.length = prefixLength;
     528    entry.id = id;
    507529
    508530        // create the namespace entry and add it
     
    567589    }
    568590    else
    569     {
     591    {       
    570592        fCurrentContextId = contextId;
     593        assert (fScope < fContextIdStack.capacity());
    571594        fContextIdStack[fScope] = contextId;
    572595    }
     
    588611IDISA_ALWAYS_INLINE
    589612BindingSetIterator XMLNamespaceResolver::getNamespaceIterator(const gid_t contextId) const
    590 {   
     613{
     614    assert (contextId < fDistinctContextSet.setCapacity());
     615
    591616    return BindingSetIterator(fDistinctContextSet[contextId]);
    592617}
     
    597622MaskedBindingSetIterator XMLNamespaceResolver::getNamespaceIterator(const gid_t contextId0, const gid_t contextId1) const
    598623{
     624    assert (contextId0 < fDistinctContextSet.setCapacity());
     625    assert (contextId1 < fDistinctContextSet.setCapacity());
     626
    599627    return MaskedBindingSetIterator(fDistinctContextSet[contextId0], fDistinctContextSet[contextId1], true);
    600628}
     
    628656XMLNamespaceResolver::getPrefixForNamespaceId(const gid_t namespaceId) const
    629657{
     658    assert (namespaceId < fNamespaceToPrefixBindingTable.capacity());
    630659    return getPrefixForId(fNamespaceToPrefixBindingTable[namespaceId]);
    631660}
     
    637666XMLNamespaceResolver::getUriForNamespaceId(const gid_t namespaceId) const
    638667{
     668    assert (namespaceId < fNamespaceToUriBindingTable.capacity());
    639669    return getUriForId(fNamespaceToUriBindingTable[namespaceId]);
    640670}
Note: See TracChangeset for help on using the changeset viewer.