[Mingw-users] GetLastError strange behaviour

8 views
Skip to first unread message

benjamin

unread,
Mar 3, 2012, 6:32:02 AM3/3/12
to mingw...@lists.sourceforge.net
Hello,

this is the code snippet:
http://ideone.com/arIAm

on MinGW 4.6.1 the output is : "dwLastError 0"
on MinGW 4.5.0 and 4.5.2 its : "dwLastError 1337" which is the desired
output.

if i write the foobar function like this :
http://ideone.com/5XX80

then it also works on 4.6.1 with "dwLastError 1337".

I dont know what exactly is going on, but i think it could be a MinGW bug. What do you think?

greetings

arIAm.cpp
5XX80.cpp

Earnie Boyd

unread,
Mar 3, 2012, 12:29:42 PM3/3/12
to MinGW Users List

Well not, MinGW, particularly but maybe GCC. Does it work if you change
throw Win32Exception(GetLastError());
to
throw Win32Exception((DWORD)GetLastError());

--
Earnie
-- https://sites.google.com/site/earnieboyd

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
MinGW-users mailing list
MinGW...@lists.sourceforge.net

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same. Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-use...@lists.sourceforge.net?subject=unsubscribe

benjamin

unread,
Mar 3, 2012, 1:49:14 PM3/3/12
to MinGW Users List
Am 03.03.2012 18:29, schrieb Earnie Boyd:
> On Sat, Mar 3, 2012 at 6:32 AM, benjamin<bew...@online.de> wrote:
>> Hello,
>>
>> this is the code snippet:
>> http://ideone.com/arIAm
>>
>> on MinGW 4.6.1 the output is : "dwLastError 0"
>> on MinGW 4.5.0 and 4.5.2 its : "dwLastError 1337" which is the desired
>> output.
>>
>> if i write the foobar function like this :
>> http://ideone.com/5XX80
>>
>> then it also works on 4.6.1 with "dwLastError 1337".
>>
>> I dont know what exactly is going on, but i think it could be a MinGW bug.
>> What do you think?
>>
> Well not, MinGW, particularly but maybe GCC. Does it work if you change
> throw Win32Exception(GetLastError());
> to
> throw Win32Exception((DWORD)GetLastError());
>

No it doesnt help. I only can assume about possible reasons for this
behaviour. Maybe someone has a explanation for it, or its simply a bug.

greetings

Timothy Madden

unread,
Mar 20, 2012, 7:31:21 PM3/20/12
to mingw...@lists.sourceforge.net
On 03.03.2012 19:29, Earnie Boyd wrote:
> On Sat, Mar 3, 2012 at 6:32 AM, benjamin<bew...@online.de> wrote:
>> Hello,
>>
>> this is the code snippet:
>> http://ideone.com/arIAm
>>
>> on MinGW 4.6.1 the output is : "dwLastError 0"
>> on MinGW 4.5.0 and 4.5.2 its : "dwLastError 1337" which is the desired
>> output.
>>
>> if i write the foobar function like this :
>> http://ideone.com/5XX80
>>
>> then it also works on 4.6.1 with "dwLastError 1337".
>>
>> I dont know what exactly is going on, but i think it could be a MinGW bug.
>> What do you think?
>>
>
> Well not, MinGW, particularly but maybe GCC. Does it work if you change
> throw Win32Exception(GetLastError());
> to
> throw Win32Exception((DWORD)GetLastError());
>

Can this be fixed please ? I have just run into it, and I think it is a
bug because it breaks functionality in Windows API (from the user's
perspective).

I used an API monitoring application, that would list all WinAPI
functions that are being called by my program, and so I find that on the
first throw statement (before the first Win32Exception is constructed)
there are several several other system calls before my call to
GetLastError(): malloc() which calls HeapAlloc(),
InterlockedIncrement(), InterlockedDecrement(), CreateSemaphore(),
TlsAlloc() and GetLastError().

Of these, CreateSempahore() was the first to reset the value of
GetLastError().

The calls are listed as originating from that libgcc_s_dw2-1.dll file,
except for malloc which was originating from libstdc++.

I can understand that exceptions may need additional maintenance from
the support libraries, but I think such libraries should save and
restore the value of GetLastError() if they need to change it.

I can post the example program and the list of API and .dll calls if
anyone is interested.

Thank you,
Timothy Madden


------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure

Earnie Boyd

unread,
Mar 21, 2012, 7:34:51 AM3/21/12
to MinGW Users List
On Tue, Mar 20, 2012 at 7:31 PM, Timothy Madden <termin...@gmail.com> wrote:
>
> Can this be fixed please ? I have just run into it, and I think it is a
> bug because it breaks functionality in Windows API (from the user's
> perspective).
>

Not, here. You'll have to take it up with GCC and LIBSTDC++ lists.
We use the sources as distributed by GCC.

------------------------------------------------------------------------------

Reply all
Reply to author
Forward
0 new messages