Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing directives in Firebird.pas [CORE5765] #6028

Closed
firebird-issue-importer opened this issue Mar 4, 2018 · 9 comments
Closed

Missing directives in Firebird.pas [CORE5765] #6028

firebird-issue-importer opened this issue Mar 4, 2018 · 9 comments

Comments

@firebird-issue-importer
Copy link

firebird-issue-importer commented Mar 4, 2018

Submitted by: Tony Whyman (twhyman)

Votes: 1

In order to compile and use with FPC, the Firebird.pas file requires the following directives to be placed at the top of the file:

{$IFDEF FPC}
{$mode delphi}
{$OBJECTCHECKS OFF}
{$ENDIF}

If mode delphi is not specified then it will not compile unless this mode is specified on the command line.

If Objectchecks off is not specified then if the using program is compiled with the -CR debugging switch (Verify object method call validity) then a run-time error is reported whenever an attempt is made to call a Firebird 3 API method.

The Firebird.pas file in the source code distribution needs to be updated to include the above directives.

Commits: f40802d e81ecc6

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Mar 5, 2018

Modified by: @AlexPeshkoff

assignee: Alexander Peshkov [ alexpeshkoff ]

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Mar 5, 2018

Commented by: @AlexPeshkoff

What's the scope of this control comments in FPC - till the end of included file or wider?

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Mar 5, 2018

Commented by: Tony Whyman (twhyman)

Used in this way, it is simply to the end of file. (see https://www.freepascal.org/docs-html/current/prog/progse2.html#x7-60001.2)

I only found out about the OBJECTCHECKS issue this weekend when an IBX user complained that the new release of IBX was failing with an "Invalid typecast". This was later found to be because he was debugging with all debug switches on. Putting this directive in the file allows users to use this debugging feature while still allowing use of the Firebird API.

When checking the 3.0.3 source I was surprised to find the "mode delphi" issue still not fixed as I am sure this came up on the lists ages ago. The IBX copy of Firebird.pas has had this directive in it since support for the Firebird 3 API was added.

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Mar 6, 2018

Commented by: @AlexPeshkoff

Sorry by according to that docs https://www.freepascal.org/docs-html/current/prog/progsu104.html#x112-1130001.3.21 MODE is global directive. I see no problems adding OBJECTCHECKS, but what a sense in adding MODE - what a sense with it if it's anyway global and will affect overall project?

But probably I'm missing something with Pascal project structure... (I do not use Pascal for last 30 years). Can you provide a sample of use of MODE DELPHI and desired content of firebird.pas?

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Mar 6, 2018

Commented by: Tony Whyman (twhyman)

The following is how I propose that the first few lines of Firebird.pas should look. Note that I have capitalised the $MODE DELPHI to look prettier - Pascal is case insensitive.

As to your question, and quoting from the FPC docs:

"Global directives affect the whole of the compilation process of a single compilation unit (program, unit, library). They also have a command line counterpart, which is given for each of the directives. They must be specified before the first statement different from the program, unit or library clause in a source file, or they will have no effect. "

Be careful of the use of the word "program" here. In Pascal the "main" unit starts with "Program <program name>;", while normal source code modules start with "Unit <unitname>;", while the main unit for a DLL starts with "Library <libname>;". So when the above refers to a "Program", it is only referring to the main unit's source code and not to all units linked together to form a program.

Global Directives are global to the unit in which they are declared but have no affect on any unit that uses them. Unlike 'C' header files, Pascal declarations in the interfaces section are imported into other units as post compilation symbol tables rather than pre-compilation source code.

The use of the "MODE" directive in Firebird.pas is essential because Firebird.pas is a Delphi compliant source unit and has minor syntax differences from the default FPC Pascal dialect. However, there is no problem mixing Delphi compliant units and FPC compliant units in the same program given that the symbol information is imported post compilation rather than pre-compilation.

{ This file was autogenerated by cloop - Cross Language Object Oriented Programming }

unit Firebird;

{$IFDEF FPC}
{$MODE DELPHI}
{$OBJECTCHECKS OFF}
{$ENDIF}

interface

uses Classes, SysUtils;

type
{$IFNDEF FPC}
QWord = UInt64;
{$ENDIF}

IVersioned = class;
IReferenceCounted = class;
IDisposable = class;
IStatus = class;
IMaster = class;
IPluginBase = class;
IPluginSet = class;
IConfigEntry = class;

....

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Mar 6, 2018

Commented by: @AlexPeshkoff

Ahh - got it, the key here is that "there is no problem mixing Delphi compliant units and FPC compliant units in the same program".
Will fix.

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Mar 9, 2018

Modified by: @AlexPeshkoff

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 4.0 Beta 1 [ 10750 ]

Fix Version: 3.0.4 [ 10863 ]

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Mar 25, 2018

Modified by: @pavel-zotov

status: Resolved [ 5 ] => Resolved [ 5 ]

QA Status: No test => Cannot be tested

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Mar 25, 2018

Modified by: @pavel-zotov

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment