You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by Keith Rogers <k_...@yahoo.com> on 2004/05/13 17:34:28 UTC
Re: Access Violation when transcoding a XalanDOMString
I've got a fair amount of code that uses the XalanDOMString::c_str() to create std::string objects, and all linking is with runtime DLLs. I haven't seen a crash. What are you doing, exactly? You can't actually push a char[] array into a vector unless you've got it wrapped in a class that has copy and destruct semantics.
Ryan Sawatzky <rs...@openfox.com> wrote:Hi,
We are trying to move our code over to Windows. In our code we have a
function that converts a XalanDOMString into a old C-Style null
terminated character array. When we try to run through this function,
the program usually crashes on the fourth or fifth time it is called.
The access violation occurrs on the return statement of the function.
In the stack trace that MSVC++ prints out it is clear that the access
violation is occurring in std::vector::~vector() deconstructor.
I searched the archives for this group and found several references to a
similar problem that was apparently solved by changing the linking
options for the project. So I changed the linking to Multithreaded
Debug DLL, and the problem still occurs. I have tried all three of the
Multithreaded linking options and none of them change the behavior.
Does anyone know why this program is crashing? In case it helps, here
is the linkage string that is in the project settings->C++->Code
Generation window.
/nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D
"_MBCS" /FR"Debug/" /Fp"Debug/tst.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD
/GZ /c
Notice the /MDd argument to specify Multithreaded Debug DLL
Thanks for any help,
Ryan
Re: Access Violation when transcoding a XalanDOMString
Posted by Keith Rogers <k_...@yahoo.com>.
This is what I suspected. It definitely won't work. You need to build the DLLs and app with the same version of Visual Studio. Like I said, I had no success with VC7 a while back and have not tried to upgrade. VS.NET still shuts down on me unexpectedly from time to time and tries to send error reports to MS.
Ignore my previous BF posting - I didn't have my own compiler settings right - was using static linking in the test DLL and EXE. It works fine in both VC6 and VC7 with multi-threaded DLL options set.
Keith
david_n_bertoni@us.ibm.com wrote:
> ...BTW I am using VC7 to build my application, perhaps that is the problem?
If you are using Xerces-C and Xalan-C binaries built with VC6, then that's
definitely the problem, because the two compilers have different run-time
libraries. You should really rebuild the binaries using the particular
version of VC you're using, because mixing binaries is dangerous, and the
underlying problem is still there.
Dave
Re: Access Violation when transcoding a XalanDOMString
Posted by da...@us.ibm.com.
> Hey Keith and Dave,
>
> Well I figured out a work-around for my particular problem. I found out
> that I didn't have to be converting to an 8-bit character after all. I
> was using it to do a strtok() on an XML string, and then after some
> digging I found the StringTokenizer class in the Xalan docs. So I
> switched over my code to use that and now everything works. It is still
> rather disconcerting that this has been such a hassle. BTW I am using
> VC7 to build my application, perhaps that is the problem?
If you are using Xerces-C and Xalan-C binaries built with VC6, then that's
definitely the problem, because the two compilers have different run-time
libraries. You should really rebuild the binaries using the particular
version of VC you're using, because mixing binaries is dangerous, and the
underlying problem is still there.
Dave
Re: Access Violation when transcoding a XalanDOMString
Posted by da...@us.ibm.com.
> Ryan,
> No, I don't think it's VC7. You can't do what XalanDOMString::transcode
is trying to
> do - return memory allocated in one heap (the DLLs) and have it released
in the EXE's
> space. Bad idea. I've got a simple test DLL & EXE that confirms this.
It crashes
> whether built with VC6 or VC7.
You can when you use /MD, because there's only one C/C++ run-time heap for
the entire application, which is the whole point of using /MD in the first
place. That option is a requirement for using Xerces-C and Xalan-C.
Dave
Re: Access Violation when transcoding a XalanDOMString
Posted by Keith Rogers <k_...@yahoo.com>.
Ryan,
No, I don't think it's VC7. You can't do what XalanDOMString::transcode is trying to do - return memory allocated in one heap (the DLLs) and have it released in the EXE's space. Bad idea. I've got a simple test DLL & EXE that confirms this. It crashes whether built with VC6 or VC7.
Keith
Ryan Sawatzky <rs...@openfox.com> wrote:
Hey Keith and Dave,
Well I figured out a work-around for my particular problem. I found out
that I didn't have to be converting to an 8-bit character after all. I
was using it to do a strtok() on an XML string, and then after some
digging I found the StringTokenizer class in the Xalan docs. So I
switched over my code to use that and now everything works. It is still
rather disconcerting that this has been such a hassle. BTW I am using
VC7 to build my application, perhaps that is the problem?
Anyways, thanks for your help.
Ryan
Re: Access Violation when transcoding a XalanDOMString
Posted by Ryan Sawatzky <rs...@openfox.com>.
Hey Keith and Dave,
Well I figured out a work-around for my particular problem. I found out
that I didn't have to be converting to an 8-bit character after all. I
was using it to do a strtok() on an XML string, and then after some
digging I found the StringTokenizer class in the Xalan docs. So I
switched over my code to use that and now everything works. It is still
rather disconcerting that this has been such a hassle. BTW I am using
VC7 to build my application, perhaps that is the problem?
Anyways, thanks for your help.
Ryan
Keith Rogers wrote:
> Ryan's compiler options looked Ok (in the first posting) for a debug
> build. If the right library is being linked, it *should* work.
>
> Ryan, what compiler are you building the app with? I know when I
> tried to use a VC7-built app with the VC6 built DLLs (that was Xerces
> 2.2, Xalan 1.5, as I recall), it did not work. I'm sticking with VC6
> for now, and build the X-X DLLs myself, too.
>
> david_n_bertoni@us.ibm.com wrote:
>
> This is a pretty clear indication that you are not building with the
> correct run-time library options. For the release configuration,
> you need
> to use /MD and link with the release version of the Xalan-C and
> Xerces-C
> libraries. For the debug configuration, you need to use /MDd, and link
> with the debug version of the Xalan-C and Xerces-C libraries. The
> debug
> versions of the libraries have a "D" appended to the prefix. For
> example,
> Xalan-C_1D.lib, instead of Xalan-C_1.lib.
>
> Dave
>
Re: Access Violation when transcoding a XalanDOMString
Posted by Keith Rogers <k_...@yahoo.com>.
Ryan's compiler options looked Ok (in the first posting) for a debug build. If the right library is being linked, it *should* work.
Ryan, what compiler are you building the app with? I know when I tried to use a VC7-built app with the VC6 built DLLs (that was Xerces 2.2, Xalan 1.5, as I recall), it did not work. I'm sticking with VC6 for now, and build the X-X DLLs myself, too.
david_n_bertoni@us.ibm.com wrote:
This is a pretty clear indication that you are not building with the
correct run-time library options. For the release configuration, you need
to use /MD and link with the release version of the Xalan-C and Xerces-C
libraries. For the debug configuration, you need to use /MDd, and link
with the debug version of the Xalan-C and Xerces-C libraries. The debug
versions of the libraries have a "D" appended to the prefix. For example,
Xalan-C_1D.lib, instead of Xalan-C_1.lib.
Dave
Re: Access Violation when transcoding a XalanDOMString
Posted by da...@us.ibm.com.
> Hi Keith,
> Thanks for the reply. The function in question calls the
> XalanDOMString.transcode() function to get a CharVectorType back. Then
> the function allocates a char[] of appropraite length, and then it
> copies characters from the vector into the array one by one. When the
> function tries to return, I get an Access Violation. Looking at the
> stack trace, it appears that the violation occurs in the vector's
> deconstructor method.
>
This is a pretty clear indication that you are not building with the
correct run-time library options. For the release configuration, you need
to use /MD and link with the release version of the Xalan-C and Xerces-C
libraries. For the debug configuration, you need to use /MDd, and link
with the debug version of the Xalan-C and Xerces-C libraries. The debug
versions of the libraries have a "D" appended to the prefix. For example,
Xalan-C_1D.lib, instead of Xalan-C_1.lib.
Dave
Re: Access Violation when transcoding a XalanDOMString
Posted by Ryan Sawatzky <rs...@openfox.com>.
Hi Keith,
Thanks for the reply. The function in question calls the
XalanDOMString.transcode() function to get a CharVectorType back. Then
the function allocates a char[] of appropraite length, and then it
copies characters from the vector into the array one by one. When the
function tries to return, I get an Access Violation. Looking at the
stack trace, it appears that the violation occurs in the vector's
deconstructor method.
Ryan
Keith Rogers wrote:
> Ok, I looked at the code. It actually creates a string object that
> encapsulates both std::wstring (UCS2) and std::string (UTF8). We
> don't use the transcode functions -- too many problems some years ago
> (Xalan 1.0?). All of our wide character data is UCS2, and char is
> UTF8. There are Microsoft APIs that do that conversion, or you can
> pretty easily write your own (what I did).
>
> Keith Rogers <k_...@yahoo.com> wrote:
>
> I've got a fair amount of code that uses the
> XalanDOMString::c_str() to create std::string objects,...
>
Re: Access Violation when transcoding a XalanDOMString
Posted by Keith Rogers <k_...@yahoo.com>.
Ok, I looked at the code. It actually creates a string object that encapsulates both std::wstring (UCS2) and std::string (UTF8). We don't use the transcode functions -- too many problems some years ago (Xalan 1.0?). All of our wide character data is UCS2, and char is UTF8. There are Microsoft APIs that do that conversion, or you can pretty easily write your own (what I did).
Keith Rogers <k_...@yahoo.com> wrote:I've got a fair amount of code that uses the XalanDOMString::c_str() to create std::string objects,...