You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Steve Feinstein <sf...@anydevice.com> on 2000/10/28 06:16:51 UTC
Problems reinitializing XMLPlatformUtils/DOM parser (NT4.0)
I put the following code, taken from DOMprint, into a function that gets
called multiple
times during the life of a process. First call to this function works fine;
second time
through, it access violates on the call to the DOMParser constuctor:
try { XMLPlatformUtils::Initialize(); }
catch(const XMLException& toCatch) { ... }
DOMParser *parser = new DOMParser;
parser->setValidationScheme(gValScheme);
parser->setDoNamespaces(gDoNamespaces);
ErrorHandler *errReporter = new DOMTreeErrorReporter();
parser->setErrorHandler(errReporter);
parser->setCreateEntityReferenceNodes(gDoCreate);
parser->setToCreateXMLDeclTypeNode(true);
bool errorsOccured = false;
try
{
parser->parse(gXmlFile);
}
catch (const XMLException& e) { ... }
catch (const DOM_DOMException& e) { ... }
catch (...) { ... }
// If the parse was successful, output the document data from the DOM
tree
if (!errorsOccured) { DOM_Node doc = parser->getDocument();
....}
delete errReporter;
delete parser;
XMLPlatformUtils::Terminate();
}
A few layers down, it turns out the problem is in this function:
static XMLMutex& gScannerMutex()
{
static bool registered = false;
static XMLMutex* scannerMutex = 0;
if (!scannerMutex)
{
XMLMutex* tmpMutex = new XMLMutex;
if (XMLPlatformUtils::compareAndSwap((void**)&scannerMutex,
tmpMutex, 0))
delete tmpMutex;
.
.
.
return *scannerMutex;
}
This code only creates a mutex if the value of scannerMutex is 0, although
after calling
"XMLPlatformUtils::Terminate()", there is no more mutex handle and the
pointer is non-zero
because it's static. What it points to is gone (a mutex handle). Later
when XMLScanner
tries to lock the mutex, the access violation occurs.
My question is: Am I correct in concluding that I'm only supposed to call
XMLPlatrformUtils::Initialize() and new DOMParser() once per process? Or is
there some
way of starting fresh without rerunning the program?
Steven Feinstein
AnyDevice.com
Re: Problems reinitializing XMLPlatformUtils/DOM parser (NT4.0)
Posted by Simon Fell <so...@zaks.demon.co.uk>.
On Sat, 28 Oct 2000 00:16:51 -0400, in soap you wrote:
>I put the following code, taken from DOMprint, into a function that gets
>called multiple
>times during the life of a process. First call to this function works fine;
>second time
>through, it access violates on the call to the DOMParser constuctor:
[snip]
>My question is: Am I correct in concluding that I'm only supposed to call
>XMLPlatrformUtils::Initialize() and new DOMParser() once per process? Or is
>there some way of starting fresh without rerunning the program?
>
>Steven Feinstein
>AnyDevice.com
Call XMLPlatformUtils::Initalize() ( and optionally
XMLPlatformUtils::Terminate() ) once per process. You can call new
DOMParser as many times as you like, as long as it occurs after
Initialize has been called (and before Terminate gets called)
Cheers
Simon
www.4s4c.com