View Issue Details

IDProjectCategoryView StatusLast Update
0033204FPCRTLpublic2018-02-24 20:16
ReportersilvioprogAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Product VersionProduct Build 
Target Version3.2.0Fixed in Version3.1.1 
Summary0033204: [patch] adds CheckOSError() for Delphi compatibility
DescriptionHi.

Patch in attachment.
Additional InformationIn general, it is used to check the result of system/library function returning.

More:

Reference: http://docwiki.embarcadero.com/Libraries/Tokyo/en/System.SysUtils.CheckOSError
Example: http://docwiki.embarcadero.com/CodeExamples/Tokyo/en/LastOSError_(Delphi)
TagsNo tags attached.
Fixed in Revision38327
FPCOldBugId
FPCTarget
Attached Files
  • 0001-rtl-added-CheckOSError-function.-patch-by-silvioprog.patch (1,581 bytes)
    From 932429a6b3d6313efdb87ea7d0887418d47d3c4e Mon Sep 17 00:00:00 2001
    From: silvioprog <silvioprog@gmail.com>
    Date: Tue, 20 Feb 2018 23:38:16 -0300
    Subject: [PATCH 1/1] rtl: added CheckOSError() function. (patch by silvioprog)
    
    ---
     rtl/objpas/sysutils/osutilsh.inc | 1 +
     rtl/objpas/sysutils/sysutils.inc | 8 ++++++++
     2 files changed, 9 insertions(+)
    
    diff --git a/rtl/objpas/sysutils/osutilsh.inc b/rtl/objpas/sysutils/osutilsh.inc
    index 7d3f905..b10a679 100644
    --- a/rtl/objpas/sysutils/osutilsh.inc
    +++ b/rtl/objpas/sysutils/osutilsh.inc
    @@ -21,6 +21,7 @@ Function GetLastOSError : Integer;
     {$endif}
     Procedure RaiseLastOSError;overload;
     Procedure RaiseLastOSError(LastError: Integer);overload;
    +procedure CheckOSError(LastError: Integer);{$ifdef SYSTEMINLINE}inline;{$endif}
     
     Function GetEnvironmentVariable(Const EnvVar : AnsiString) : AnsiString;
     Function GetEnvironmentVariable(Const EnvVar : UnicodeString) : UnicodeString;
    diff --git a/rtl/objpas/sysutils/sysutils.inc b/rtl/objpas/sysutils/sysutils.inc
    index 0280110..9442609 100644
    --- a/rtl/objpas/sysutils/sysutils.inc
    +++ b/rtl/objpas/sysutils/sysutils.inc
    @@ -459,6 +459,11 @@ begin
       Raise E;
     end;
     
    +procedure CheckOSError(LastError: Integer);
    +begin
    +  if LastError <> 0 then
    +    RaiseLastOSError(LastError);
    +end;
     {$else}
     Procedure RaiseLastOSError;overload;
     begin
    @@ -470,6 +475,9 @@ begin
       RaiseLastOSError;
     end;
     
    +procedure CheckOSError(LastError: Integer);
    +begin
    +end;
     {$endif}
     Procedure AssertErrorHandler (Const Msg,FN : ShortString;LineNo:longint; TheAddr : pointer);
     Var
    -- 
    2.7.4
    
    

Activities

silvioprog

2018-02-21 03:46

reporter  

0001-rtl-added-CheckOSError-function.-patch-by-silvioprog.patch (1,581 bytes)
From 932429a6b3d6313efdb87ea7d0887418d47d3c4e Mon Sep 17 00:00:00 2001
From: silvioprog <silvioprog@gmail.com>
Date: Tue, 20 Feb 2018 23:38:16 -0300
Subject: [PATCH 1/1] rtl: added CheckOSError() function. (patch by silvioprog)

---
 rtl/objpas/sysutils/osutilsh.inc | 1 +
 rtl/objpas/sysutils/sysutils.inc | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/rtl/objpas/sysutils/osutilsh.inc b/rtl/objpas/sysutils/osutilsh.inc
index 7d3f905..b10a679 100644
--- a/rtl/objpas/sysutils/osutilsh.inc
+++ b/rtl/objpas/sysutils/osutilsh.inc
@@ -21,6 +21,7 @@ Function GetLastOSError : Integer;
 {$endif}
 Procedure RaiseLastOSError;overload;
 Procedure RaiseLastOSError(LastError: Integer);overload;
+procedure CheckOSError(LastError: Integer);{$ifdef SYSTEMINLINE}inline;{$endif}
 
 Function GetEnvironmentVariable(Const EnvVar : AnsiString) : AnsiString;
 Function GetEnvironmentVariable(Const EnvVar : UnicodeString) : UnicodeString;
diff --git a/rtl/objpas/sysutils/sysutils.inc b/rtl/objpas/sysutils/sysutils.inc
index 0280110..9442609 100644
--- a/rtl/objpas/sysutils/sysutils.inc
+++ b/rtl/objpas/sysutils/sysutils.inc
@@ -459,6 +459,11 @@ begin
   Raise E;
 end;
 
+procedure CheckOSError(LastError: Integer);
+begin
+  if LastError <> 0 then
+    RaiseLastOSError(LastError);
+end;
 {$else}
 Procedure RaiseLastOSError;overload;
 begin
@@ -470,6 +475,9 @@ begin
   RaiseLastOSError;
 end;
 
+procedure CheckOSError(LastError: Integer);
+begin
+end;
 {$endif}
 Procedure AssertErrorHandler (Const Msg,FN : ShortString;LineNo:longint; TheAddr : pointer);
 Var
-- 
2.7.4

Marco van de Voort

2018-02-23 11:18

manager   ~0106544

If there is no Unix implementation, why is it OS independent?

Just make it platform dependent?

Thaddy de Koning

2018-02-23 15:40

reporter   ~0106547

Last edited: 2018-02-23 15:55

View 7 revisions

The patch is even incorrect: https://msdn.microsoft.com/en-us/library/windows/desktop/ms679360(v=vs.85).aspx
"Error codes are 32-bit values (bit 31 is the most significant bit). Bit 29 is reserved for application-defined error codes; no system error code has this bit set. If you are defining an error code for your application, set this bit to one. That indicates that the error code has been defined by an application, and ensures that your error code does not conflict with any error codes defined by the system."

Which conflicts with CheckOSError (But Delphi does that wrong..)
If bit 29 is set the patch would eventually return an application error, not an OS error, under Windows.

Thaddy de Koning

2018-02-23 15:54

reporter   ~0106549

Not a good idea to copy bugs...

silvioprog

2018-02-24 06:34

reporter   ~0106552

So what is the correct way to implement the feature?

Serge Anvarov

2018-02-24 09:15

reporter   ~0106553

@Thaddy - too abstruse. If even some library (such did not meet) will be use OS facility (SetLastError) to transmit errors, then it is logical to check as for other OS errors. For fans of complicating - write your function CheckLastUserError, you can call along with CheckOSError. I suspect that such a function is not needed by anyone, because usually libraries use BOOL result and/or self error codes.

Michael Van Canneyt

2018-02-24 12:14

administrator   ~0106561

Applied the patch, changed so it does the same on all platforms, and marked it as 'platform'. So it will do what it says on the tin. I will document that it's better not to use on platforms other than Windows.

silvioprog

2018-02-24 20:16

reporter   ~0106592

@Serge @Michael: dudes, thanks a lot for explaining it so clearly, fixing and applying the patch. I'm going to use it and remove my previous "{$IFDEF FPC}procedure CheckOSError(LastError: Integer); inline;{$ENDIF}" from my own sources. Thank you very much!

Issue History

Date Modified Username Field Change
2018-02-21 03:46 silvioprog New Issue
2018-02-21 03:46 silvioprog File Added: 0001-rtl-added-CheckOSError-function.-patch-by-silvioprog.patch
2018-02-23 11:18 Marco van de Voort Note Added: 0106544
2018-02-23 15:40 Thaddy de Koning Note Added: 0106547
2018-02-23 15:45 Thaddy de Koning Note Edited: 0106547 View Revisions
2018-02-23 15:45 Thaddy de Koning Note Edited: 0106547 View Revisions
2018-02-23 15:46 Thaddy de Koning Note Edited: 0106547 View Revisions
2018-02-23 15:47 Thaddy de Koning Note Edited: 0106547 View Revisions
2018-02-23 15:51 Thaddy de Koning Note Edited: 0106547 View Revisions
2018-02-23 15:54 Thaddy de Koning Note Added: 0106549
2018-02-23 15:55 Thaddy de Koning Note Edited: 0106547 View Revisions
2018-02-24 06:34 silvioprog Note Added: 0106552
2018-02-24 09:15 Serge Anvarov Note Added: 0106553
2018-02-24 12:14 Michael Van Canneyt Fixed in Revision => 38327
2018-02-24 12:14 Michael Van Canneyt Note Added: 0106561
2018-02-24 12:14 Michael Van Canneyt Status new => resolved
2018-02-24 12:14 Michael Van Canneyt Fixed in Version => 3.1.1
2018-02-24 12:14 Michael Van Canneyt Resolution open => fixed
2018-02-24 12:14 Michael Van Canneyt Assigned To => Michael Van Canneyt
2018-02-24 12:14 Michael Van Canneyt Target Version => 3.2.0
2018-02-24 20:16 silvioprog Note Added: 0106592
2018-02-24 20:16 silvioprog Status resolved => closed