Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite 3.7.10 and static linking in Delphi

Latest version of Sqlite (3.7.10) wanted to link __msize function and since Delphi memory manager can not report the size of a memory block, I had to introduce a hack (d5 compatible)

function __msize(p: pointer): Cardinal;cdecl;
begin
  Result:=PInteger(integer(p)-4)^-6;
end;

Are there other solutions inside Sqlite (defines?) or Delphi to fix this so no undocumented features are used.

like image 655
Maksee Avatar asked Dec 28 '22 07:12

Maksee


2 Answers

You can use SizeOfMem from JCL JclSysUtils unit.

like image 26
da-soft Avatar answered Dec 29 '22 19:12

da-soft


Around line # 15195 in the source code, comment the following lines:

/*
** Windows systems have malloc_usable_size() but it is called _msize()
*/
#if !defined(HAVE_MALLOC_USABLE_SIZE) && SQLITE_OS_WIN
# define HAVE_MALLOC_USABLE_SIZE 1
# define malloc_usable_size _msize
#endif

into

/*
** Windows systems have malloc_usable_size() but it is called _msize()
#if !defined(HAVE_MALLOC_USABLE_SIZE) && SQLITE_OS_WIN
# define HAVE_MALLOC_USABLE_SIZE 1
# define malloc_usable_size _msize
#endif
*/

It will disable the memory reuse of SQLite3 malloc, and will rely on the better FastMM4 reallocmem() implementation.

See this commit e.g. for our Open Source implementation of SQLite3 static linking.

Additional information:

I think that we'd get rid of this issue in 3.7.11, as stated by this commit: a new SQLITE_WITHOUT_MSIZE global symbol will be added, and will be able to build the amalgamation source code without changing its content, just by setting the appropriate SQLITE_WITHOUT_MSIZE define. In the meanwhile, the easiest is to comment the above lines.

like image 181
Arnaud Bouchez Avatar answered Dec 29 '22 19:12

Arnaud Bouchez