XMLContentModel* DTDElementDecl::makeContentModel() { XMLContentModel* cmRet = 0; if (fModelType == Mixed_Simple) { // // Just create a mixel content model object. This type of // content model is optimized for mixed content validation. // cmRet = new (getMemoryManager()) MixedContentModel(true, this->getContentSpec(), false, getMemoryManager()); } else if (fModelType == Children) { // // This method will create an optimal model for the complexity // of the element's defined model. If its simple, it will create // a SimpleContentModel object. If its a simple list, it will // create a SimpleListContentModel object. If its complex, it // will create a DFAContentModel object. // cmRet = createChildModel(); } else { ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::CM_MustBeMixedOrChildren, getMemoryManager()); } return cmRet; }
SchemaAttDef::SchemaAttDef(const SchemaAttDef* other) : XMLAttDef(other->getValue(), other->getType(), other->getDefaultType(), other->getEnumeration(), other->getMemoryManager()) , fElemId(XMLElementDecl::fgInvalidElemId) , fAttName(0) , fDatatypeValidator(other->fDatatypeValidator) , fAnyDatatypeValidator(other->fAnyDatatypeValidator) , fMemberTypeValidator(other->fMemberTypeValidator) , fNamespaceList(0) , fValidity(other->fValidity) , fValidation(other->fValidation) , fPSVIScope(other->fPSVIScope) , fBaseAttDecl(other->fBaseAttDecl) { QName* otherName = other->getAttName(); fAttName = new (getMemoryManager()) QName(otherName->getPrefix(), otherName->getLocalPart(), otherName->getURI(), getMemoryManager()); if (other->fNamespaceList && other->fNamespaceList->size()) { fNamespaceList = new (getMemoryManager()) ValueVectorOf<unsigned int>(*(other->fNamespaceList)); } }
size_type write( const XalanDOMChar chars[], XalanDOMString::size_type start, XalanDOMString::size_type length) { XalanDOMChar ch = chars[start]; if (XalanFormatterWriter::isUTF16HighSurrogate(ch) == false) { write((unsigned int)ch); } else { if (start + 1 >= length) { XalanFormatterWriter::throwInvalidUTF16SurrogateException( ch, 0, getMemoryManager()); } else { write( XalanFormatterWriter::decodeUTF16SurrogatePair( ch, chars[++start], getMemoryManager())); } } return start; }
// --------------------------------------------------------------------------- // XMLASCIITranscoder: Implementation of the transcoder API // --------------------------------------------------------------------------- XMLSize_t XMLASCIITranscoder::transcodeFrom( const XMLByte* const srcData , const XMLSize_t srcCount , XMLCh* const toFill , const XMLSize_t maxChars , XMLSize_t& bytesEaten , unsigned char* const charSizes) { // // Calculate the max chars we can do here. Its the lesser of the // max output chars and the source byte count. // const XMLSize_t countToDo = srcCount < maxChars ? srcCount : maxChars; // // Now loop through that many source chars and just cast each one // over to the XMLCh format. Check each source that its really a // valid ASCI char. // const XMLByte* srcPtr = srcData; XMLCh* outPtr = toFill; XMLSize_t countDone = 0; for (; countDone < countToDo; countDone++) { // Do the optimistic work up front if (*srcPtr < 0x80) { *outPtr++ = XMLCh(*srcPtr++); continue; } // // We got non source encoding char. If we got more than 32 chars, // the just break out. We'll come back here later to hit this again // and give an error much closer to the real source position. // if (countDone > 32) break; XMLCh tmpBuf[17]; XMLString::binToText((unsigned int)*srcPtr, tmpBuf, 16, 16, getMemoryManager()); ThrowXMLwithMemMgr2 ( TranscodingException , XMLExcepts::Trans_Unrepresentable , tmpBuf , getEncodingName() , getMemoryManager() ); } // Set the bytes we ate bytesEaten = countDone; // Set the char sizes to the fixed size memset(charSizes, 1, countDone); // Return the chars we transcoded return countDone; }
unsigned int XMLASCIITranscoder::transcodeTo(const XMLCh* const srcData , const unsigned int srcCount , XMLByte* const toFill , const unsigned int maxBytes , unsigned int& charsEaten , const UnRepOpts options) { // If debugging, make sure that the block size is legal #if defined(XERCES_DEBUG) checkBlockSize(maxBytes); #endif // // Calculate the max chars we can do here. Its the lesser of the // max output chars and the source byte count. // const unsigned int countToDo = srcCount < maxBytes ? srcCount : maxBytes; const XMLCh* srcPtr = srcData; XMLByte* outPtr = toFill; for (unsigned int index = 0; index < countToDo; index++) { // If its legal, do it and jump back to the top if (*srcPtr < 0x80) { *outPtr++ = XMLByte(*srcPtr++); continue; } // // Its not representable so use a replacement char. According to // the options, either throw or use the replacement. // if (options == UnRep_Throw) { XMLCh tmpBuf[17]; XMLString::binToText((unsigned int)*srcPtr, tmpBuf, 16, 16, getMemoryManager()); ThrowXMLwithMemMgr2 ( TranscodingException , XMLExcepts::Trans_Unrepresentable , tmpBuf , getEncodingName() , getMemoryManager() ); } // Use the replacement char *outPtr++ = 0x1A; srcPtr++; } // Set the chars we ate charsEaten = countToDo; // Return the byte we transcoded return countToDo; }
// --------------------------------------------------------------------------- // IconvGNUTranscoder: Implementation of the virtual transcoder API // --------------------------------------------------------------------------- unsigned int IconvGNUTranscoder::transcodeFrom ( const XMLByte* const srcData , const unsigned int srcCount , XMLCh* const toFill , const unsigned int maxChars , unsigned int& bytesEaten , unsigned char* const charSizes ) { // Transcode TO XMLCh const char* startSrc = (const char*) srcData; const char* endSrc = (const char*) srcData + srcCount; char tmpWBuff[gTempBuffArraySize]; char *startTarget = 0; char *wBufPtr = 0; size_t len = maxChars * uChSize(); if (uChSize() != sizeof(XMLCh) || UBO() != BYTE_ORDER) { if (len > gTempBuffArraySize) { wBufPtr = (char*) getMemoryManager()->allocate ( len * sizeof(char) );//new char[len]; if (wBufPtr == NULL) return 0; startTarget = wBufPtr; } else startTarget = tmpWBuff; } else startTarget = (char *) toFill; // Do character-by-character transcoding char *orgTarget = startTarget; size_t srcLen = srcCount; size_t prevSrcLen = srcLen; unsigned int toReturn = 0; bytesEaten = 0; for (size_t cnt = 0; cnt < maxChars && srcLen; cnt++) { size_t rc = iconvFrom(startSrc, &srcLen, &orgTarget, uChSize()); if (rc == (size_t)-1) { if (errno != E2BIG || prevSrcLen == srcLen) { if (wBufPtr) getMemoryManager()->deallocate(wBufPtr);//delete [] wBufPtr; ThrowXMLwithMemMgr(TranscodingException, XMLExcepts::Trans_BadSrcSeq, getMemoryManager()); } } charSizes[cnt] = prevSrcLen - srcLen; prevSrcLen = srcLen; bytesEaten += charSizes[cnt]; startSrc = endSrc - srcLen; toReturn++; } if (uChSize() != sizeof(XMLCh) || UBO() != BYTE_ORDER) mbsToXML (startTarget, toReturn, toFill, toReturn); if (wBufPtr) getMemoryManager()->deallocate(wBufPtr);//delete [] wBufPtr; return toReturn; }
void XalanOutputStream::setOutputEncoding(const XalanDOMString& theEncoding) { // Flush, just in case. This should probably be an error... flushBuffer(); XalanTranscodingServices::destroyTranscoder(m_transcoder); XalanTranscodingServices::eCode theCode = XalanTranscodingServices::OK; // This turns on an optimization that we can only do if // XalanDOMChar == sizeof(ushort). See doWrite(). #if !defined(XALAN_XALANDOMCHAR_USHORT_MISMATCH) if (XalanTranscodingServices::encodingIsUTF16(theEncoding) == true) { m_writeAsUTF16 = true; } else #endif { m_transcoder = XalanTranscodingServices::makeNewTranscoder( getMemoryManager(), theEncoding, theCode, m_transcoderBlockSize); if (theCode == XalanTranscodingServices::UnsupportedEncoding) { XalanDOMString theBuffer(getMemoryManager()); throw UnsupportedEncodingException(theEncoding, theBuffer); } else if (theCode != XalanTranscodingServices::OK) { XalanDOMString theBuffer(getMemoryManager()); throw TranscoderInternalFailureException(theEncoding, theBuffer); } assert(m_transcoder != 0); } m_encoding = theEncoding; const XalanTranscodingServices::XalanXMLByte* theProlog = XalanTranscodingServices::getStreamProlog(theEncoding); assert(theProlog != 0); const size_type theLength = XalanTranscodingServices::length(theProlog); if (theLength > 0) { #if defined(XALAN_OLD_STYLE_CASTS) write((const char*)theProlog, theLength); #else write(reinterpret_cast<const char*>(theProlog), theLength); #endif } }
XERCES_CPP_NAMESPACE_BEGIN // private function used to update fXSModel void XMLGrammarPoolImpl::createXSModel() { delete fXSModel; fXSModel = new (getMemoryManager()) XSModel(this, getMemoryManager()); fXSModelIsValid = true; }
XMLSize_t XML88591Transcoder::transcodeTo(const XMLCh* const srcData , const XMLSize_t srcCount , XMLByte* const toFill , const XMLSize_t maxBytes , XMLSize_t& charsEaten , const UnRepOpts options) { // // Calculate the max chars we can do here. Its the lesser of the // max output bytes and the number of chars in the source. // const XMLSize_t countToDo = srcCount < maxBytes ? srcCount : maxBytes; // // Loop through the bytes to do and convert over each byte. Its just // a downcast of the wide char, checking for unrepresentable chars. // const XMLCh* srcPtr = srcData; const XMLCh* srcEnd = srcPtr + countToDo; XMLByte* destPtr = toFill; while (srcPtr < srcEnd) { // If its legal, take it and jump back to top if (*srcPtr < 256) { *destPtr++ = XMLByte(*srcPtr++); continue; } // // Its not representable so use a replacement char. According to // the options, either throw or use the replacement. // if (options == UnRep_Throw) { XMLCh tmpBuf[17]; XMLString::binToText((unsigned int)*srcPtr, tmpBuf, 16, 16, getMemoryManager()); ThrowXMLwithMemMgr2 ( TranscodingException , XMLExcepts::Trans_Unrepresentable , tmpBuf , getEncodingName() , getMemoryManager() ); } *destPtr++ = 0x1A; srcPtr++; } // Set the chars eaten charsEaten = countToDo; // Return the bytes we transcoded return countToDo; }
// --------------------------------------------------------------------------- // XMLASCIITranscoder390: Implementation of the transcoder API // --------------------------------------------------------------------------- unsigned int XMLASCIITranscoder390::transcodeFrom( const XMLByte* const srcData , const unsigned int srcCount , XMLCh* const toFill , const unsigned int maxChars , unsigned int& bytesEaten , unsigned char* const charSizes) { // If debugging, make sure that the block size is legal #if defined(XERCES_DEBUG) checkBlockSize(maxChars); #endif // // Calculate the max chars we can do here. Its the lesser of the // max output chars and the source byte count. // const unsigned int countToDo = srcCount < maxChars ? srcCount : maxChars; // // Now loop through that many source chars and just cast each one // over to the XMLCh format. Check each source that its really a // valid ASCI char. // const XMLByte* srcPtr = srcData; XMLCh* outPtr = toFill; unsigned int countDone = countToDo; int flag = 0; // if flag is set to 1, an non-ASCII character is encountered TROTASC(srcPtr, toFill, &countDone, padding_temp.gFromTable, 0xFFFF, &flag); if (flag == 1 && countDone < 32){ XMLCh tmpBuf[17]; XMLString::binToText((unsigned int)*srcPtr, tmpBuf, 16, 16, getMemoryManager()); ThrowXMLwithMemMgr2 ( TranscodingException , XMLExcepts::Trans_Unrepresentable , tmpBuf , getEncodingName() , getMemoryManager() ); }//end if // Set the bytes we ate bytesEaten = countDone; // Set the char sizes to the fixed size memset(charSizes, 1, countDone); // Return the chars we transcoded return countDone; }
void* memAllocUser(const size_t &bytes) { void *ptr = nullptr; try { ptr = getMemoryManager().alloc(bytes, true); } catch(...) { getQueue().sync(); ptr = getMemoryManager().alloc(bytes, true); } return ptr; }
T* memAlloc(const size_t &elements) { T *ptr = nullptr; try { ptr = (T *)getMemoryManager().alloc(elements * sizeof(T), false); } catch(...) { getQueue().sync(); ptr = (T *)getMemoryManager().alloc(elements * sizeof(T), false); } return ptr; }
// --------------------------------------------------------------------------- // SchemaElementDecl: XMLElementDecl virtual interface implementation // --------------------------------------------------------------------------- XMLAttDef* SchemaElementDecl::findAttr(const XMLCh* const qName , const unsigned int uriId , const XMLCh* const baseName , const XMLCh* const prefix , const LookupOpts options , bool& wasAdded) const { if (fComplexTypeInfo) { return fComplexTypeInfo->findAttr(qName, uriId, baseName, prefix, options, wasAdded); } else { if (options == XMLElementDecl::AddIfNotFound) { SchemaAttDef* retVal = 0; // If no att list exist yet, then create one if (!fAttDefs) { // Use a hash modulus of 29 and tell it owns its elements ((SchemaElementDecl*)this)->fAttDefs = new (getMemoryManager()) RefHash2KeysTableOf<SchemaAttDef>(29, true, getMemoryManager()); } retVal = fAttDefs->get(baseName, uriId); // Fault it in if not found and ask to add it if (!retVal) { // And add a default attribute for this name retVal = new (getMemoryManager()) SchemaAttDef ( prefix , baseName , uriId , XMLAttDef::CData , XMLAttDef::Implied , getMemoryManager() ); retVal->setElemId(getId()); fAttDefs->put((void*)retVal->getAttName()->getLocalPart(), uriId, retVal); wasAdded = true; } else { wasAdded = false; } return retVal; } else { wasAdded = false; return 0; } } }
/*** * 3.2.2.2 Canonical representation * * The canonical representation for boolean is the set of literals {true, false}. ***/ const XMLCh* BooleanDatatypeValidator::getCanonicalRepresentation(const XMLCh* const rawData , MemoryManager* const memMgr , bool toValidate) const { MemoryManager* toUse = memMgr? memMgr : getMemoryManager(); if (toValidate) { BooleanDatatypeValidator *temp = (BooleanDatatypeValidator*) this; try { temp->checkContent(rawData, 0, false, toUse); } catch (...) { return 0; } } return ( XMLString::equals(rawData, XMLUni::fgBooleanValueSpace[0]) || XMLString::equals(rawData, XMLUni::fgBooleanValueSpace[2]) ) ? XMLString::replicate(XMLUni::fgBooleanValueSpace[0], toUse) : XMLString::replicate(XMLUni::fgBooleanValueSpace[1], toUse) ; }
// --------------------------------------------------------------------------- // MemBufInputSource: InputSource interface implementation // --------------------------------------------------------------------------- BinInputStream* MemBufInputSource::makeStream() const { // // Create a memory input stream over our buffer. According to our // fCopyBufToStream flag, we either tell it to copy the buffer or to // just reference it. // return new (getMemoryManager()) BinMemInputStream ( fSrcBytes , fByteCount , fCopyBufToStream ? BinMemInputStream::BufOpt_Copy : BinMemInputStream::BufOpt_Reference , getMemoryManager() ); }
void deviceMemoryInfo(size_t *alloc_bytes, size_t *alloc_buffers, size_t *lock_bytes, size_t *lock_buffers) { getQueue().sync(); getMemoryManager().bufferInfo(alloc_bytes, alloc_buffers, lock_bytes, lock_buffers); }
XMLAttDef* SchemaAttDefList::findAttDef( const XMLCh* const , const XMLCh* const) { //need numeric URI id to locate the attribute, that's how it was stored ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Pool_InvalidId, getMemoryManager()); return 0; }
BinInputStreamType* XSLTInputSource::makeStream() const { BinInputStreamType* theResult = 0; MemoryManager* theManager = getMemoryManager(); assert(theManager != 0 ); if (m_stream != 0) { theResult = new (theManager) StdBinInputStream(*m_stream); } else if (m_node == 0) { const XalanDOMChar* const theSystemId = getSystemId(); if (theSystemId != 0) { XALAN_USING_XERCES(XMLURL) XMLURL theURL(theManager); URISupport::getURLFromString(theSystemId, theURL, *theManager); theResult = theURL.makeNewStream(); } } return theResult; }
AttributesImpl& AttributesImpl::operator=(const AttributesType& theRHS) { if (this != &theRHS) { // Note that we can't chain up to our base class operator=() // because it's private. // Add all of the attributes to this temp list, // then swap at the end. This means we're exception // safe and don't need any try blocks. AttributesImpl theTempList(getMemoryManager()); const unsigned int theLength = theRHS.getLength(); theTempList.reserve(theLength); // Add each attribute. for(unsigned int i = 0; i < theLength; i++) { theTempList.addAttribute( theRHS.getURI(i), theRHS.getLocalName(i), theRHS.getQName(i), theRHS.getType(i), theRHS.getValue(i)); } // Now that the temp list is built, swap everything. This is // guaranteed not to throw. swap(theTempList); } return *this; }
void XalanOutputStream::setBufferSize(size_type theBufferSize) { flushBuffer(); if (theBufferSize == 0) { m_bufferSize = 1; } else { m_bufferSize = theBufferSize; } if (m_buffer.size() < m_bufferSize) { // Enlarge the buffer... m_buffer.reserve(theBufferSize + 1); } else if (m_buffer.size() > m_bufferSize) { // Shrink the buffer. // Create a temp buffer and make it // the correct size. BufferType temp(getMemoryManager()); temp.reserve(theBufferSize + 1); // Swap temp with m_buffer so that // m_buffer is now the correct size. temp.swap(m_buffer); } }
void AttributesImpl::addAttribute( const XMLCh* uri, const XMLCh* localName, const XMLCh* name, const XMLCh* type, const XMLCh* value) { assert(name != 0); assert(type != 0); assert(value != 0); typedef AttributeVectorEntry::XMLChVectorType XMLChVectorType; if (m_attributesVector.capacity() == 0) { m_attributesVector.reserve(eDefaultVectorSize); } typedef XalanMemMgrAutoPtr<AttributeVectorEntryExtended,true> AutoPtr; AutoPtr theEntry(getMemoryManager(), getNewEntry(name, type, value, uri, localName)); // Add the new one. m_attributesVector.push_back(theEntry.get()); theEntry.release(); }
XalanDOMString& XalanDOMString::append( const char* theString, size_type theCount) { invariants(); const size_type theLength = theCount == size_type(npos) ? length(theString) : theCount; if (theLength != 0) { if (empty() == true) { doTranscode(theString, theLength, theCount == size_type(npos), m_data, true); } else { XalanDOMCharVectorType theTempVector(getMemoryManager()); doTranscode(theString, theLength, theCount == size_type(npos), theTempVector, false); append(&*theTempVector.begin(), size_type(theTempVector.size())); } m_size = size_type(m_data.size()) - 1; assert(m_data.size() - 1 == m_size); } invariants(); return *this; }
void XPathExecutionContextDefault::error( const XalanDOMString& msg, const XalanNode* sourceNode, const Locator* locator) const { assert(m_xpathEnvSupport != 0); m_xpathEnvSupport->problem( XPathEnvSupport::eXPATH, XPathEnvSupport::eError, msg, locator, sourceNode); MemoryManager& theManager = getMemoryManager(); XalanDOMString uri(theManager); uri = XalanLocator::getSystemId(locator, uri.c_str()); throw XalanXPathException( msg, theManager, locator); }
// --------------------------------------------------------------------------- // Loading // --------------------------------------------------------------------------- XSerializable* XSerializeEngine::read(XProtoType* const protoType) { ensureLoading(); ensurePointer(protoType); XSerializedObjectId_t objectTag; XSerializable* objRet; if (! read(protoType, &objectTag)) { /*** * We hava a reference to an existing object in * load pool, get it. */ objRet = lookupLoadPool(objectTag); } else { // create the object from the prototype objRet = protoType->fCreateObject(getMemoryManager()); Assert((objRet != 0), XMLExcepts::XSer_CreateObject_Fail); // put it into load pool addLoadPool(objRet); // de-serialize it objRet->serialize(*this); } return objRet; }
SchemaElementDecl::~SchemaElementDecl() { getMemoryManager()->deallocate(fDefaultValue);//delete [] fDefaultValue; delete fAttDefs; delete fIdentityConstraints; delete fAttWildCard; }
DTDElementDecl::~DTDElementDecl() { delete fAttDefs; delete fAttList; delete fContentSpec; delete fContentModel; getMemoryManager()->deallocate(fFormattedModel);//delete [] fFormattedModel; }
XERCES_CPP_NAMESPACE_BEGIN // --------------------------------------------------------------------------- // SchemaAttDefList: Constructors and Destructor // --------------------------------------------------------------------------- SchemaAttDefList::SchemaAttDefList(RefHash2KeysTableOf<SchemaAttDef>* const listToUse, MemoryManager* const manager) : XMLAttDefList(manager) ,fEnum(0) ,fList(listToUse) ,fArray(0) ,fSize(0) ,fCount(0) { fEnum = new (getMemoryManager()) RefHash2KeysTableOfEnumerator<SchemaAttDef>(listToUse, false, getMemoryManager()); fArray = (SchemaAttDef **)((getMemoryManager())->allocate( sizeof(SchemaAttDef*) << 1)); fSize = 2; }
//Switch process by running the scheduler alogrithm void CALLING_CONVENTION CX86Scheduler::schedule() { if (!m_bInitialised) return; m_lock.acquireSpinlock(); size_t curcpu = getHal()->getMultiprocessorIrq()->getCurrentCpuNum(); iterator_t orig, itr = m_runningList.findValue(m_execProcess[curcpu]); PTHREAD curthread = m_execProcess[curcpu]; bool isCurrentlyRunning = true; PTHREAD thread = 0; while (isCurrentlyRunning) { itr = m_runningList.getNext(itr); if (!m_runningList.isEntry(itr)) itr = m_runningList.getHead(); thread = m_runningList.getValue(itr); isCurrentlyRunning = false; for (unsigned int n = 0; n < m_numcpus; n++) { if (m_execProcess[n] == thread) isCurrentlyRunning = true; } if (thread == curthread) { thread = NULL; break; } } //OK, we have our thread if (!thread) { m_lock.releaseSpinlock(); return; } //Check for page context switch PPROCESS process = (PPROCESS)thread->parent; if (thread->parent != curthread->parent) { getMemoryManager()->getVMemMngr()->loadAddressSpace(process->addrspace); } if (setjmp(curthread->context) == 0) { debug_serial("CONTEXT SWITCH\n"); //We get here if we want to change process. this will switch to a different process CAPIC* apic = (CAPIC*)getHal()->getMultiprocessorIrq(); apic->setNewQuantum(20 + process->priority * 4); m_execProcess[curcpu] = thread; m_lock.releaseSpinlock(); longjmp(thread->context, 1); } else { m_lock.releaseSpinlock(); } getHal()->getIrqChip()->eoi(0); }
void SchemaAttDefList::serialize(XSerializeEngine& serEng) { XMLAttDefList::serialize(serEng); if (serEng.isStoring()) { /*** * * Serialize RefHash2KeysTableOf<SchemaAttDef> * ***/ XTemplateSerializer::storeObject(fList, serEng); serEng << fCount; // do not serialize fEnum } else { /*** * * Deserialize RefHash2KeysTableOf<SchemaAttDef> * ***/ XTemplateSerializer::loadObject(&fList, 29, true, serEng); // assume empty so we can size fArray just right serEng >> fSize; if (!fEnum && fList) { fEnum = new (getMemoryManager()) RefHash2KeysTableOfEnumerator<SchemaAttDef>(fList, false, getMemoryManager()); } if(fSize) { (getMemoryManager())->deallocate(fArray); fArray = (SchemaAttDef **)((getMemoryManager())->allocate( sizeof(SchemaAttDef*) * fSize)); fCount = 0; while(fEnum->hasMoreElements()) { fArray[fCount++] = &fEnum->nextElement(); } } } }
XMLAttDefList& SchemaElementDecl::getAttDefList() const { if (!fComplexTypeInfo) { ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::DV_InvalidOperation, getMemoryManager()); } return fComplexTypeInfo->getAttDefList(); }