Browse Source

* Windows targets: removed 'errno' threadvar, OS error codes can be passed directly to Errno2InOutRes().

git-svn-id: trunk@26815 -
sergei 11 years ago
parent
commit
c83f4c5ddc
6 changed files with 25 additions and 46 deletions
  1. 3 4
      rtl/win/sysdir.inc
  2. 18 25
      rtl/win/sysfile.inc
  3. 4 11
      rtl/win/sysos.inc
  4. 0 2
      rtl/win32/system.pp
  5. 0 2
      rtl/win64/system.pp
  6. 0 2
      rtl/wince/system.pp

+ 3 - 4
rtl/win/sysdir.inc

@@ -30,10 +30,10 @@ begin
   DoDirSeparators(s);
   DoDirSeparators(s);
   if not aFunc(punicodechar(s)) then
   if not aFunc(punicodechar(s)) then
     begin
     begin
-      errno:=GetLastError;
-      Errno2InoutRes;
+      Errno2InoutRes(GetLastError);
     end;
     end;
 end;
 end;
+
 Procedure do_MkDir(const s: UnicodeString);
 Procedure do_MkDir(const s: UnicodeString);
 begin
 begin
   dirfn(TDirFnType(@CreateDirectoryTrunc),s);
   dirfn(TDirFnType(@CreateDirectoryTrunc),s);
@@ -123,8 +123,7 @@ begin
     Len2 := GetFullPathNameW (@Drive, Len, PUnicodeChar (Dir), P);
     Len2 := GetFullPathNameW (@Drive, Len, PUnicodeChar (Dir), P);
     if Len2 = 0 then
     if Len2 = 0 then
      begin
      begin
-      errno := word (GetLastError);
-      Errno2InoutRes;
+      Errno2InoutRes(GetLastError);
       Dir := widechar (DriveNr + Ord ('A') - 1) + ':\';
       Dir := widechar (DriveNr + Ord ('A') - 1) + ':\';
       Exit;
       Exit;
      end
      end

+ 18 - 25
rtl/win/sysfile.inc

@@ -35,18 +35,19 @@ end;
 procedure do_erase(p: pwidechar; pchangeable: boolean);
 procedure do_erase(p: pwidechar; pchangeable: boolean);
 var
 var
   oldp: pwidechar;
   oldp: pwidechar;
+  err: longword;
 begin
 begin
    oldp:=p;
    oldp:=p;
    DoDirSeparators(p,pchangeable);
    DoDirSeparators(p,pchangeable);
    if DeleteFileW(p)=0 then
    if DeleteFileW(p)=0 then
     Begin
     Begin
-      errno:=GetLastError;
-      if errno=5 then
+      err:=GetLastError;
+      if err=5 then
        begin
        begin
          if ((GetFileAttributesW(p) and FILE_ATTRIBUTE_DIRECTORY)=FILE_ATTRIBUTE_DIRECTORY) then
          if ((GetFileAttributesW(p) and FILE_ATTRIBUTE_DIRECTORY)=FILE_ATTRIBUTE_DIRECTORY) then
-          errno:=2;
+          err:=2;
        end;
        end;
-      Errno2InoutRes;
+      Errno2InoutRes(err);
     end;
     end;
    if p<>oldp then
    if p<>oldp then
      freemem(p);
      freemem(p);
@@ -62,10 +63,9 @@ begin
   DoDirSeparators(p1,p1changeable);
   DoDirSeparators(p1,p1changeable);
   DoDirSeparators(p2,p2changeable);
   DoDirSeparators(p2,p2changeable);
   if MoveFileW(p1,p2)=0 then
   if MoveFileW(p1,p2)=0 then
-   Begin
-      errno:=GetLastError;
-      Errno2InoutRes;
-   end;
+    Begin
+      Errno2InoutRes(GetLastError);
+    end;
   if p1<>oldp1 then
   if p1<>oldp1 then
     freemem(p1);
     freemem(p1);
   if p2<>oldp2 then
   if p2<>oldp2 then
@@ -84,8 +84,7 @@ var
 begin
 begin
    if writefile(h,addr,len,size,nil)=0 then
    if writefile(h,addr,len,size,nil)=0 then
     Begin
     Begin
-      errno:=GetLastError;
-      Errno2InoutRes;
+      Errno2InoutRes(GetLastError);
 {$ifndef WINCE}
 {$ifndef WINCE}
     end
     end
    else if (size<len) then
    else if (size<len) then
@@ -120,14 +119,13 @@ end;
 function do_read(h:thandle;addr:pointer;len : longint) : longint;
 function do_read(h:thandle;addr:pointer;len : longint) : longint;
 var
 var
   _result:longint;
   _result:longint;
+  err: longword;
 begin
 begin
   if readfile(h,addr,len,_result,nil)=0 then
   if readfile(h,addr,len,_result,nil)=0 then
     Begin
     Begin
-      errno:=GetLastError;
-      if errno=ERROR_BROKEN_PIPE then
-        errno:=0
-      else
-        Errno2InoutRes;
+      err:=GetLastError;
+      if err<>ERROR_BROKEN_PIPE then
+        Errno2InoutRes(err);
     end;
     end;
   do_read:=_result;
   do_read:=_result;
 end;
 end;
@@ -146,8 +144,7 @@ begin
   rslt.low := SetFilePointer(handle, 0, @rslt.high, FILE_CURRENT);
   rslt.low := SetFilePointer(handle, 0, @rslt.high, FILE_CURRENT);
   if (rslt.low = $FFFFFFFF) and (GetLastError <> 0) then
   if (rslt.low = $FFFFFFFF) and (GetLastError <> 0) then
   begin
   begin
-    errno := GetLastError;
-    Errno2InoutRes;
+    Errno2InoutRes(GetLastError);
   end;
   end;
   do_filepos := int64(rslt);
   do_filepos := int64(rslt);
 end;
 end;
@@ -162,8 +159,7 @@ begin
   { return value of -1 is valid unless GetLastError is non-zero }
   { return value of -1 is valid unless GetLastError is non-zero }
     (GetLastError <> 0) then
     (GetLastError <> 0) then
   begin
   begin
-    errno := GetLastError;
-    Errno2InoutRes;
+    Errno2InoutRes(GetLastError);
   end;
   end;
 end;
 end;
 
 
@@ -176,8 +172,7 @@ begin
   rslt.low := SetFilePointer(handle, 0, @rslt.high, FILE_END);
   rslt.low := SetFilePointer(handle, 0, @rslt.high, FILE_END);
   if (rslt.low = $FFFFFFFF) and (GetLastError <> 0) then
   if (rslt.low = $FFFFFFFF) and (GetLastError <> 0) then
   begin
   begin
-    errno := GetLastError;
-    Errno2InoutRes;
+    Errno2InoutRes(GetLastError);
   end;
   end;
   do_seekend := int64(rslt);
   do_seekend := int64(rslt);
 end;
 end;
@@ -198,8 +193,7 @@ begin
    do_seek(handle,pos);
    do_seek(handle,pos);
    if not(SetEndOfFile(handle)) then
    if not(SetEndOfFile(handle)) then
     begin
     begin
-      errno:=GetLastError;
-      Errno2InoutRes;
+      Errno2InoutRes(GetLastError);
     end;
     end;
 end;
 end;
 
 
@@ -317,8 +311,7 @@ begin
   { handle -1 is returned sometimes !! (PM) }
   { handle -1 is returned sometimes !! (PM) }
   if (filerec(f).handle=0) or (filerec(f).handle=UnusedHandle) then
   if (filerec(f).handle=0) or (filerec(f).handle=UnusedHandle) then
     begin
     begin
-      errno:=GetLastError;
-      Errno2InoutRes;
+      Errno2InoutRes(GetLastError);
     end;
     end;
   if oldp<>p then
   if oldp<>p then
     freemem(p);
     freemem(p);

+ 4 - 11
rtl/win/sysos.inc

@@ -192,10 +192,6 @@ type
   end;
   end;
 
 
 
 
-threadvar
-  errno : longint;
-
-
    { misc. functions }
    { misc. functions }
    function GetLastError : DWORD;
    function GetLastError : DWORD;
      {$ifdef wince}cdecl{$else}stdcall{$endif};external KernelDLL name 'GetLastError';
      {$ifdef wince}cdecl{$else}stdcall{$endif};external KernelDLL name 'GetLastError';
@@ -323,19 +319,17 @@ threadvar
      len:dword): Integer; stdcall;external 'oleaut32.dll' name 'SysReAllocStringLen';
      len:dword): Integer; stdcall;external 'oleaut32.dll' name 'SysReAllocStringLen';
 {$endif WINCE}
 {$endif WINCE}
 
 
-   Procedure Errno2InOutRes;
+   Procedure Errno2InOutRes(oserror: longword);
    var
    var
      res : Word;
      res : Word;
-     pErrno : ^longint;
    Begin
    Begin
      { DO NOT MODIFY UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING }
      { DO NOT MODIFY UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING }
-     pErrno:=@Errno;
-     case pErrno^ of
+     case oserror of
        ERROR_WRITE_PROTECT..ERROR_GEN_FAILURE :
        ERROR_WRITE_PROTECT..ERROR_GEN_FAILURE :
          begin
          begin
            { This is the offset to the Win32 to add to directly map  }
            { This is the offset to the Win32 to add to directly map  }
            { to the DOS/TP compatible error codes when in this range }
            { to the DOS/TP compatible error codes when in this range }
-           res := word(pErrno^)+131;
+           res := word(oserror)+131;
          end;
          end;
        ERROR_DISK_FULL :
        ERROR_DISK_FULL :
          res := 101;
          res := 101;
@@ -348,10 +342,9 @@ threadvar
        else
        else
          begin
          begin
            { other error codes can directly be mapped }
            { other error codes can directly be mapped }
-           res := Word(pErrno^);
+           res := Word(oserror);
          end;
          end;
      end;
      end;
-     pErrno^:=0;
      InOutRes:=res;
      InOutRes:=res;
    end;
    end;
 
 

+ 0 - 2
rtl/win32/system.pp

@@ -683,8 +683,6 @@ begin
   { Reset IO Error }
   { Reset IO Error }
   InOutRes:=0;
   InOutRes:=0;
   ProcessID := GetCurrentProcessID;
   ProcessID := GetCurrentProcessID;
-  { Reset internal error variable }
-  errno:=0;
   initvariantmanager;
   initvariantmanager;
   DispCallByIDProc:=@DoDispCallByIDError;
   DispCallByIDProc:=@DoDispCallByIDError;
 end.
 end.

+ 0 - 2
rtl/win64/system.pp

@@ -615,8 +615,6 @@ begin
   { Reset IO Error }
   { Reset IO Error }
   InOutRes:=0;
   InOutRes:=0;
   ProcessID := GetCurrentProcessID;
   ProcessID := GetCurrentProcessID;
-  { Reset internal error variable }
-  errno:=0;
   initvariantmanager;
   initvariantmanager;
   DispCallByIDProc:=@DoDispCallByIDError;
   DispCallByIDProc:=@DoDispCallByIDError;
 end.
 end.

+ 0 - 2
rtl/wince/system.pp

@@ -1783,8 +1783,6 @@ initialization
   ProcessID := GetCurrentProcessID;
   ProcessID := GetCurrentProcessID;
   { threading }
   { threading }
   InitSystemThreads;
   InitSystemThreads;
-  { Reset internal error variable }
-  errno:=0;
   initvariantmanager;
   initvariantmanager;
   DispCallByIDProc:=@DoDispCallByIDError;
   DispCallByIDProc:=@DoDispCallByIDError;