IBX fbintf isc_start_transaction exception on Win64 lazarus / 16-Databases ---------------------------------------------------------------------- ttomas · 2024-02-01 20:25 Using only fbintf and trying to connect to Fb3/4/5 with legacy interface (-dLEGACYFIREBIRDAPIONLY) on Win64 TCP connection, some times isc_start_transaction raise exception "Access violation reading from addresss...". Win32 Local and Remote and Win64 Local(Embedded) connection never raise exception, only Win64 Remote localhost:mybase.fdb. Can you check isc_start_transaction definition, its look like some stack corruption. In program that work, changing some lines, start raising this exception. USEFIREBIRD3API don't have this problem. In ibase.h isc_start_transaction is defined as Code: [Select]ISC_STATUS ISC_EXPORT_VARARG isc_start_transaction(ISC_STATUS*,    isc_tr_handle*,    short, ...); I solve the problem with this change in client\IB_Header Code: [Select]Tisc_start_transaction = function (status_vector         : PISC_STATUS;                                 tran_handle               : PISC_TR_HANDLE;                                 db_handle_count           : Short): ISC_STATUS;                                 cdecl; varargs; In fpc 3.2fix packages\ibase\src\ibase60.inc this function is defined as Code: [Select]function isc_start_transaction(_para1:PISC_STATUS;  _para2:Pisc_tr_handle;  _para3:smallint;  args:array of const):ISC_STATUS;  cdecl; external gdslib; fbintf 1.4, Win 10 x64, Lazarus 3, Fpc 3.2fix ---------------------------------------------------------------------- tonyw · 2024-02-01 22:55 Interesting... This type definition is largely unchanged from the original Borland IBX. The only change I have made was to change PChar to PByte (to keep Delphi happy). The InterBase 6 API guide defines the function as: Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ISC_STATUS isc_start_transaction(ISC_STATUS *status_vector,isc_tr_handle *trans_handle,short db_handle_count,isc_db_handle *db_handle,unsigned short tpb_length,char *tpb_address,[isc_db_handle *db_handle,unsigned short tpb_length,char *tpb_address ...]); which in IBHeader.pas is translated to Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function (status_vector           : PISC_STATUS;                               tran_handle               : PISC_TR_HANDLE;                               db_handle_count           : Short;                               db_handle                 : PISC_DB_HANDLE;                               tpb_length                : UShort;                               tpb_address               : PByte): ISC_STATUS;                              cdecl;   i.e. only a single database group is supported. Given that start_transaction is only ever called by IBX to start a transaction against a single database, this definition has sufficed for the last 25 or so years (start_multiple is used by IBX to start a transaction against multiple databases). My guess is that the IBX definition predated Delphi support for varargs - and maybe start_multiple was added to in InterBase API in consequence. So the interesting question is why has this bug suddenly arisen? Is there something different in the way 'C' handles varargs in win64 compared with win32 or Linux (32 and 64)? Before publishing a change to use varargs, I will need to check out the behaviour under all platforms and not just win64. ---------------------------------------------------------------------- ttomas · 2024-02-02 00:52 Yes must be checked on all platforms. This simple test in attach don't raise exception. Debugging/Watching in TFB25Transaction.InternalStartSingle, I change code to Code: [Select]procedure TFB25Transaction.InternalStartSingle(attachment: IAttachment); var db_handle: TISC_DB_HANDLE;     pb: PByte;  // add     i: integer;  // add begin   with FFirebird25ClientAPI do   try     db_handle := (attachment as TFB25Attachment).Handle;     pb := (FTPB as TTPB).getBuffer;  //add     Call(isc_start_transaction(StatusVector, @FHandle,1,               @db_handle,(FTPB as TTPB).getDataLength,(FTPB as TTPB).getBuffer));   except     FHandle := nil;     raise;   end end; And exception start raising. If you remove dummy/not used var i, exception is not raising.