This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: gthr-win32.h patch
- To: Thomas Pfaff <tpfaff at gmx dot net>
- Subject: Re: gthr-win32.h patch
- From: Christopher Faylor <cgf at redhat dot com>
- Date: Wed, 10 Jan 2001 10:36:49 -0500
- Cc: gcc-patches at gcc dot gnu dot org
- References: <002201c07adf$eec4e270$69856286@pcs.ditec.de>
This patch looks like it will do the right thing but you need to supply
a ChangeLog, too.
I'll apply the patch once you supply the ChangeLog. Send it to gcc-patches,
please.
cgf
On Wed, Jan 10, 2001 at 09:31:58AM +0100, Thomas Pfaff wrote:
>Hi,
>
>there is a problem with the -mthreads support for mingw32. If you compile
>with -mthreads and call a function that will throw an exception,
>__get_eh_context is called on function entry and the WIN32 LastError is
>cleared by TlsGetValue in gthread_getspecific. I have attached a patch that
>will preserve the WIN32 error.
>This patch will apply to gcc-current.
>
>Here is an example:
>
>#include <windows.h>
>
>#include <string>
>#include <iostream>
>
>using namespace std;
>
>static void FormatError( void );
>
>int main( void )
>{
>
> try {
> SetLastError( ERROR_ACCESS_DENIED );
> FormatError();
> return 0;
> }
>
> catch( string &szError ) {
> cerr << szError << endl;
> }
>
> catch( ... ) {
> }
>
> return 0;
>}
>
>static void FormatError( void )
>{
>
> int nLastError = GetLastError();
> char szLastError[2048];
> int nBufferSize = sizeof( szLastError );
>
> if( 0 == nLastError ) {
> throw( string( "Last Error cleared by TlsGetValue" ) );
> }
>
> FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL,
> nLastError, MAKELANGID( LANG_NEUTRAL, SUBLANG_SYS_DEFAULT ),
> szLastError, nBufferSize, NULL );
>
> cerr << szLastError;
>}
>
>Without this patch you will see the "Last Error cleared" message, otherwise
>an "Access denied" as you would expect.
>
>Regards,
>
>Thomas Pfaff
>