Skip to content

Firebird Interfaces don't work with FPC trunk

Summary

When working with Firebird interface based API, fetching information on the master interface fails for FPC trunk whereas the same code works for FPC 3.2.2 and FPC 3.2-fixes.

System Information

  • Operating system: Windows 10
  • Processor architecture: x86
  • Compiler version: trunk
  • Device: Computer

Steps to reproduce

Execute example project with the Firebird 3 client library. Other libraries should be affected too.

Example Project

program project1;

{$mode delphi}

type
  VersionedVTable = class
  public
    version: NativeInt;
  end;

  IVersioned = class
  public
    vTable: VersionedVTable;
    {$IFDEF WITH_CLASS_CONST}
    const VERSION = 1;
    {$ENDIF WITH_CLASS_CONST}
  end;

  IMaster = class(IVersioned)
  public
    {$IFDEF WITH_CLASS_CONST}
    const VERSION = 2;
    {$ENDIF WITH_CLASS_CONST}
    // The following declarations are not necessary for the test.
    {
    function getStatus(): IStatus;
    function getDispatcher(): IProvider;
    function getPluginManager(): IPluginManager;
    function getTimerControl(): ITimerControl;
    function getDtc(): IDtc;
    function registerAttachment(provider: IProvider; attachment: IAttachment): IAttachment;
    function registerTransaction(attachment: IAttachment; transaction: ITransaction): ITransaction;
    function getMetadataBuilder(status: IStatus; fieldCount: Cardinal): IMetadataBuilder;
    function serverMode(mode: Integer): Integer;
    function getUtilInterface(): IUtil;
    function getConfigManager(): IConfigManager;
    function getProcessExiting(): Boolean;
    }
  end;

  TFbGetMasterInterface = function: IMaster; cdecl;

var
  FbLibHandle: TLibHandle;
  FbGetMasterInterface: TFbGetMasterInterface;
  MasterIntf: IMaster;

begin
  FbLibHandle := LoadLibrary('C:\Program Files (x86)\Firebird\Firebird_3_0\fbclient.dll');
  if FbLibHandle = 0 then
    exit
  else
    WriteLn('Library Loaded');

  FbGetMasterInterface := GetProcAddress(FbLibHandle, 'fb_get_master_interface');
  if not Assigned(FbGetMasterInterface) then
    exit
  else
    WriteLn('procedure loaded');

  MasterIntf := FbGetMasterInterface();
  if not Assigned(MasterIntf) then
    exit
  else
    WriteLn('interface loaded');

  if Assigned(MasterIntf.vTable) then
    Writeln('Success -> vTable is assigned')
  else
    Writeln('Fail -> vTable is not assigned');

  ReadLn;
end.

What is the current bug behavior?

VTable is not assigned.

What is the expected (correct) behavior?

The correct VTable.

Edited by marsupilami79
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information