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 "Mitchell, Raymond" <Ra...@intuit.com> on 2001/05/08 00:00:30 UTC
Problem initializing and terminating XMLPlatformUtils more than o
nce in a program
I have run into a problem attempting to initialize and terminate
XMLPlatformUtils more than once in a single program. The following code
causes the error.
XMLPlatformUtils::Initialize();
DOMParser *pDOMParser = new DOMParser;
delete pDOMParser;
XMLPlatformUtils::Terminate();
XMLPlatformUtils::Initialize();
pDOMParser = new DOMParser; // Error occurs here
delete pDOMParser;
XMLPlatformUtils::Terminate();
The error message indicates that an illegal memory access has occured. The
stack trace indicates that the error is occuring when trying to obtain the
XMLMutex while constructing the XMLScanner. Here is the stack trace:
NTDLL! 77f8aa57()
XMLMutex::lock() line 117 + 11 bytes
XMLMutexLock::XMLMutexLock(XMLMutex * const 0x007a7b50) line 135
XMLScanner::commonInit() line 784 + 14 bytes
XMLScanner::XMLScanner(XMLValidator * const 0x007a7f90) line 162
DOMParser::DOMParser(XMLValidator * const 0x00000000) line 123 + 41
bytes
main(int 2, char * * 0x007a1870) line 182 + 46 bytes
Is it supposed to be possible to initialize and terminate the
XMLPlatformUtils more than once in a single program, or does calling
XMLPatformUtils::Terminate() cause future calls to
XMLPlatformUtils::Initialize() only to appear to work?
Thanks,
Ray
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: Problem initializing and terminating XMLPlatformUtils more than once in a program
Posted by Boris Tarasyuk <bt...@i4i.com>.
I solved this problem using
FreeLibrary(hModule);
LoadLibrary(hModule);
every time I need reinitialize parser.
Boris
----- Original Message -----
From: "Mitchell, Raymond" <Ra...@intuit.com>
To: <xe...@xml.apache.org>
Sent: Monday, May 07, 2001 6:00 PM
Subject: Problem initializing and terminating XMLPlatformUtils more than
once in a program
> I have run into a problem attempting to initialize and terminate
> XMLPlatformUtils more than once in a single program. The following code
> causes the error.
>
> XMLPlatformUtils::Initialize();
> DOMParser *pDOMParser = new DOMParser;
> delete pDOMParser;
> XMLPlatformUtils::Terminate();
> XMLPlatformUtils::Initialize();
> pDOMParser = new DOMParser; // Error occurs here
> delete pDOMParser;
> XMLPlatformUtils::Terminate();
>
> The error message indicates that an illegal memory access has occured.
The
> stack trace indicates that the error is occuring when trying to obtain the
> XMLMutex while constructing the XMLScanner. Here is the stack trace:
>
> NTDLL! 77f8aa57()
> XMLMutex::lock() line 117 + 11 bytes
> XMLMutexLock::XMLMutexLock(XMLMutex * const 0x007a7b50) line 135
> XMLScanner::commonInit() line 784 + 14 bytes
> XMLScanner::XMLScanner(XMLValidator * const 0x007a7f90) line 162
> DOMParser::DOMParser(XMLValidator * const 0x00000000) line 123 + 41
> bytes
> main(int 2, char * * 0x007a1870) line 182 + 46 bytes
>
> Is it supposed to be possible to initialize and terminate the
> XMLPlatformUtils more than once in a single program, or does calling
> XMLPatformUtils::Terminate() cause future calls to
> XMLPlatformUtils::Initialize() only to appear to work?
>
> Thanks,
> Ray
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: Problem initializing and terminating XMLPlatformUtils more than o nce in a program
Posted by Dee Jay Randall <ra...@circularreasoning.com>.
The API doc says:
"void XMLPlatformUtils::Initialize () [static]
Perform per-process parser initialization."
so I assume it isn't mean to be called repeatedly.
It is also written at http://xml.apache.org/xerces-c/program.html
"Key points to remember when using the C++ DOM classes:
- Create them as local variables, or as member variables of some
other class. Never "new" a DOM object into the heap or make an
ordinary C pointer variable to one, as this will greatly confuse
the automatic memory management. "
So that might be your problem.
You should just create your parser like:
DOMParser myDOMParser;
and you don't need to delete it. If you really want two of
them with the same name, you can put them in their own code
blocks with {}.
I thought I noticed a similar problem in my own project
without using new. It went away when I moved my call to
XMLPlatformUtils::Terminate() to where it would only occur
once. (As it happens I am happily calling XMLPlatformUtils::Initialize()
multiple times with no apparent problems. I will be making that
go away shortly.)
Dee Jay
+-----------------------------+------------------+-----------------------+
| Founding Partner | Software Engineer| Dee Jay Randall, B.Sc.|
| Circular Reasoning | Accrue Software | M.Sc. Student, CS |
| randal@circularreasoning.com| www.accrue.com | ICQ # 43551676 |
+-----------------------------+------------------+-----------------------+
What is the average rank of every song ever written? 42 -- www.launch.com
On Mon, May 07 2001 at 03:00:30P -0700, Mitchell, Raymond wrote:
> I have run into a problem attempting to initialize and terminate
> XMLPlatformUtils more than once in a single program. The following code
> causes the error.
>
> XMLPlatformUtils::Initialize();
> DOMParser *pDOMParser = new DOMParser;
> delete pDOMParser;
> XMLPlatformUtils::Terminate();
> XMLPlatformUtils::Initialize();
> pDOMParser = new DOMParser; // Error occurs here
> delete pDOMParser;
> XMLPlatformUtils::Terminate();
>
> The error message indicates that an illegal memory access has occured. The
> stack trace indicates that the error is occuring when trying to obtain the
> XMLMutex while constructing the XMLScanner. Here is the stack trace:
>
> NTDLL! 77f8aa57()
> XMLMutex::lock() line 117 + 11 bytes
> XMLMutexLock::XMLMutexLock(XMLMutex * const 0x007a7b50) line 135
> XMLScanner::commonInit() line 784 + 14 bytes
> XMLScanner::XMLScanner(XMLValidator * const 0x007a7f90) line 162
> DOMParser::DOMParser(XMLValidator * const 0x00000000) line 123 + 41
> bytes
> main(int 2, char * * 0x007a1870) line 182 + 46 bytes
>
> Is it supposed to be possible to initialize and terminate the
> XMLPlatformUtils more than once in a single program, or does calling
> XMLPatformUtils::Terminate() cause future calls to
> XMLPlatformUtils::Initialize() only to appear to work?
>
> Thanks,
> Ray
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org