[Bug ada/19526] Windows errorcodes wrong in Ada when tasking

2005-06-20 Thread charlet at gcc dot gnu dot org

--- Additional Comments From charlet at gcc dot gnu dot org  2005-06-20 
08:12 ---
Closing, as discussed, it would be an undesirable performance hit to make 
changes
in this area.

Arno

-- 
   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||WONTFIX


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19526


[Bug ada/19526] Windows errorcodes wrong in Ada when tasking

2005-06-19 Thread pinskia at gcc dot gnu dot org


-- 
   What|Removed |Added

 GCC target triplet||i686-pc-mingw32


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19526


[Bug ada/19526] Windows errorcodes wrong in Ada when tasking

2005-03-19 Thread dannysmith at users dot sourceforge dot net

--- Additional Comments From dannysmith at users dot sourceforge dot net  
2005-03-19 11:14 ---
IMO, resetting the error code set by the kernel whenever the internal Ada
tasking functions are called successfully is a bug.  It can be easily fixed:

* s-osinte-mingw.ads (SetLastError): Import win32api function.
* s-taprop-mingw.adb (Specific.Is_Valid_Task): Save last OS
error code and restore if TlsGetValue succeeds.
(Specific.Set): Likewise.

Index: s-osinte-mingw.ads
===
RCS file: /cvs/gcc/gcc/gcc/ada/s-osinte-mingw.ads,v
retrieving revision 1.1
diff -c -3 -p -r1.1 s-osinte-mingw.ads
*** s-osinte-mingw.ads  14 May 2004 10:02:00 -  1.1
--- s-osinte-mingw.ads  19 Mar 2005 10:57:53 -
*** pragma Preelaborate;
*** 433,438 
--- 433,441 
 function GetLastError return DWORD;
 pragma Import (Stdcall, GetLastError, GetLastError);
  
+procedure SetLastError (dwErrCode : DWORD);
+pragma Import (Stdcall, SetLastError, SetLastError);
+ 
  private
  
 type sigset_t is new Interfaces.C.unsigned_long;
Index: s-taprop-mingw.adb
===
RCS file: /cvs/gcc/gcc/gcc/ada/s-taprop-mingw.adb,v
retrieving revision 1.7
diff -c -3 -p -r1.7 s-taprop-mingw.adb
*** s-taprop-mingw.adb  10 Feb 2005 13:57:21 -  1.7
--- s-taprop-mingw.adb  19 Mar 2005 10:57:55 -
*** package body System.Task_Primitives.Oper
*** 143,160 
  
 end Specific;
  
 package body Specific is
  
function Is_Valid_Task return Boolean is
begin
!  return TlsGetValue (TlsIndex) /= System.Null_Address;
end Is_Valid_Task;
  
procedure Set (Self_Id : Task_Id) is
   Succeeded : BOOL;
begin
   Succeeded := TlsSetValue (TlsIndex, To_Address (Self_Id));
   pragma Assert (Succeeded = True);
end Set;
  
 end Specific;
--- 143,174 
  
 end Specific;
  
+--  Unlike other win32api functions, TlsGetValue resets the OS error
+--  status to O on success.  Save and restore the error code so it
+--  doesn't get clobbered behind the user's back when multi-tasking.
+ 
 package body Specific is
  
function Is_Valid_Task return Boolean is
+  Succeeded : Boolean;
+  Saved_Err_Code : DWORD;
begin
!  Saved_Err_Code := GetLastError;
!  Succeeded := TlsGetValue (TlsIndex) /= System.Null_Address;
!  if Succeeded then
! SetLastError (Saved_Err_Code);
!  end if;
!  return Succeeded;
end Is_Valid_Task;
  
procedure Set (Self_Id : Task_Id) is
   Succeeded : BOOL;
+  Saved_Err_Code : DWORD;
begin
+  Saved_Err_Code := GetLastError;
   Succeeded := TlsSetValue (TlsIndex, To_Address (Self_Id));
   pragma Assert (Succeeded = True);
+  SetLastError (Saved_Err_Code);
end Set;
  
 end Specific;

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19526


[Bug ada/19526] Windows errorcodes wrong in Ada when tasking

2005-03-19 Thread b201 at passagen dot se

--- Additional Comments From b201 at passagen dot se  2005-03-19 13:02 
---
Danny, to me it seems you've got the solution.  
What will happen next? Will your patch make it into 
the next version, or does it have to be approved by 
someone else, who might not think it's a bug at all? 
Or is this not the correct place to ask this question? 
(I'm a bit confused about how the work on mingw/gcc is organized 
with respect to ACT, the 'gnat-company') 
 
/Björn 
 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19526


[Bug ada/19526] Windows errorcodes wrong in Ada when tasking

2005-03-19 Thread charlet at adacore dot com

--- Additional Comments From charlet at adacore dot com  2005-03-19 13:54 
---
Subject: Re:  Windows errorcodes wrong in Ada when tasking

 IMO, resetting the error code set by the kernel whenever the internal Ada
 tasking functions are called successfully is a bug.

So you are saying that there is a bug in the Windows kernel ?
Since the Ada run time does not do any reset of the error code.

 It can be easily fixed:

I don't see how this fixes things, since TlsGetValue is also called
in the Self function.

Is_Valid_Task is not called in the test case at hand, and Set is called
during task elaboration, so that's also not problematic.

Did you get a successfulrun of the application with this patch ?
If so, it probably means that the problem is elsewhere and that this
patch is just hiding it.

The function which is called when you use tasking constructs is
Self, and this function is time critical, so it is simply out of the
question to call GetLastError/SetLastError there.

If you want to know the error code associated with your socket call,
you should save the result right away, and not delay this operation.

Arno


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19526


[Bug ada/19526] Windows errorcodes wrong in Ada when tasking

2005-03-19 Thread dannysmith at users dot sourceforge dot net

--- Additional Comments From dannysmith at users dot sourceforge dot net  
2005-03-20 01:26 ---
Oops, I had split up the patch into a non-critical (as far as
this bug report is concerned) part and a critical part, but messed up when
I pasted into bug report.

Following is the part for Self

In reply to other query in comment #5

The behaviour of TlsGetValue (and the reason for it) is documented, so when
users call it directly, they should know to save and restore the error code
if they want to.

The calls in s-taprop.adb are indirect calls by an internal Ada function, so
users wouldn't know that they should do anything special.

It affects not just windows socket errors, but any error code set by a win32api
function 

But if, as you say, its out of the question to fix this, I won't waste
any more time caring about it.  Perhaps I need to investigate the efects of
these Get/SetLastError calls on c++ code (they are used in gthr-win32.c)

Danny


Index: s-taprop-mingw.adb
===
RCS file: /cvs/gcc/gcc/gcc/ada/s-taprop-mingw.adb,v
retrieving revision 1.7
diff -c -3 -p -r1.7 s-taprop-mingw.adb
*** s-taprop-mingw.adb  10 Feb 2005 13:57:21 -  1.7
--- s-taprop-mingw.adb  20 Mar 2005 00:49:58 -
*** package body System.Task_Primitives.Oper
*** 367,381 
 -- Self --
 --
  
!function Self return Task_Id is
!   Self_Id : constant Task_Id := To_Task_Id (TlsGetValue (TlsIndex));
!begin
!   if Self_Id = null then
!  return Register_Foreign_Thread (GetCurrentThread);
!   else
!  return Self_Id;
!   end if;
!end Self;
  
 -
 -- Initialize_Lock --
--- 381,400 
 -- Self --
 --
  
!  function Self return Task_ID is
! Saved_Err_Code : DWORD;
! Self_Id: Task_ID;
!   
!  begin
! Saved_Err_Code := GetLastError;
! Self_Id := To_Task_Id (TlsGetValue (TlsIndex));
! if Self_Id = null then
!return Register_Foreign_Thread (GetCurrentThread);
! else
!SetLastError (Saved_Err_Code);
!return Self_Id;
! end if;
!  end Self;
  
 -
 -- Initialize_Lock --

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19526


[Bug ada/19526] Windows errorcodes wrong in Ada when tasking

2005-03-18 Thread b201 at passagen dot se

--- Additional Comments From b201 at passagen dot se  2005-03-18 22:45 
---
How come not many people see this as a bug? 
When a program behaves differently, just because 
a totally non-related task was introduced, I  
consider it a bug. I think Danny is on the right track. 
 
As for the remark of using internal gnat-units, I do state 
that I get the same result if I import WSAGetLastError myself, 
in the same way gnat.sockets.this does, and that way is  
the only way to go. 
function Last_Error return Interfaces.c.int (or long) 
pragma Import(stdcall,Last_Error,WSAGetLastError)  
 
/Björn 

-- 
   What|Removed |Added

 Status|RESOLVED|UNCONFIRMED
 Resolution|INVALID |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19526


[Bug ada/19526] Windows errorcodes wrong in Ada when tasking

2005-03-17 Thread charlet at gcc dot gnu dot org

--- Additional Comments From charlet at gcc dot gnu dot org  2005-03-17 
10:27 ---
I do not see any GNAT bug here. Potentially a problem in your code,
or in the Win32 API you used, but that's all.

Note that GNAT.Sockets.Thin as shown in your build output is an internal
unit that should not be used directly.

Arno

-- 
   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19526


[Bug ada/19526] Windows errorcodes wrong in Ada when tasking

2005-01-22 Thread dannysmith at users dot sourceforge dot net


-- 
   What|Removed |Added

 CC||dannysmith at users dot
   ||sourceforge dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19526