Explorar o código

* don't destroy LastError when resolving a threadvar on windows, resolves #10205 (?)

git-svn-id: trunk@10621 -
florian %!s(int64=17) %!d(string=hai) anos
pai
achega
6c5471f324
Modificáronse 3 ficheiros con 33 adicións e 12 borrados
  1. 0 3
      rtl/objpas/classes/lists.inc
  2. 3 0
      rtl/win/sysos.inc
  3. 30 9
      rtl/win/systhrd.inc

+ 0 - 3
rtl/objpas/classes/lists.inc

@@ -826,7 +826,6 @@ destructor TThreadList.Destroy;
   end;
 
 
-
 procedure TThreadList.Add(Item: Pointer);
   begin
     LockList;
@@ -876,5 +875,3 @@ procedure TThreadList.UnlockList;
   begin
     System.LeaveCriticalSection(FLock);
   end;
-
-

+ 3 - 0
rtl/win/sysos.inc

@@ -173,6 +173,9 @@ threadvar
    function GetLastError : DWORD;
      {$ifdef wince}cdecl{$else}stdcall{$endif};external KernelDLL name 'GetLastError';
 
+   procedure SetLastError(dwErrCode : DWORD);
+     {$ifdef wince}cdecl{$else}stdcall{$endif};external KernelDLL name 'SetLastError';
+
    { time and date functions }
    function GetTickCount : longint;
      {$ifdef wince}cdecl{$else}stdcall{$endif};external KernelDLL name 'GetTickCount';

+ 30 - 9
rtl/win/systhrd.inc

@@ -99,20 +99,41 @@ CONST
         TlsSetValue(tlskey,dataindex);
       end;
 
+
     function SysRelocateThreadvar(offset : dword) : pointer;
-	var
+      var
         dataindex : pointer;
+        errorsave : dword;
       begin
-        dataindex := TlsGetValue(tlskey);
-        if dataindex = nil then begin
-          SysAllocateThreadVars;
-          dataindex := TlsGetValue(tlskey);
+{$ifdef dummy}
+        { I've no clue why this doesn't read dataindex, imo it should (FK) }
+        asm
+          movl TLSKey,%edx
+          movl $0x2c,%eax
+          movl %fs:(%eax),%eax
+          movl (%eax,%edx,4),%eax
+          movl %eax,dataindex
         end;
+        if DataIndex=nil then
+          begin
+            errorsave:=GetLastError;
+            SysAllocateThreadVars;
+            DataIndex:=TlsGetValue(tlskey);
+            SetLastError(errorsave);
+          end;
+{$else win32}
+        errorsave:=GetLastError;
+        dataindex:=TlsGetValue(tlskey);
+        if dataindex=nil then
+          begin
+            SysAllocateThreadVars;
+            dataindex:=TlsGetValue(tlskey);
+          end;
+        SetLastError(errorsave);
+{$endif win32}
         SysRelocateThreadvar:=DataIndex+Offset;
-{
-      begin
-        SysRelocateThreadvar:=TlsGetValue(tlskey)+Offset;
-}      end;
+      end;
+
 
     procedure SysReleaseThreadVars;
       begin