summaryrefslogtreecommitdiff
path: root/packages/sqlite
diff options
context:
space:
mode:
authorivost <ivost@3ad0048d-3df7-0310-abae-a5850022a9f2>2009-09-16 08:50:42 +0000
committerivost <ivost@3ad0048d-3df7-0310-abae-a5850022a9f2>2009-09-16 08:50:42 +0000
commit97c80b91bb496d2161f6b6d7fd3fcd883af05c2d (patch)
tree72ab73b6553a55d5d73a5f6dbb6cd623f02e1f21 /packages/sqlite
parent7c929e577fc46ef9d96ffffa326bc24e49e3fe23 (diff)
downloadfpc-97c80b91bb496d2161f6b6d7fd3fcd883af05c2d.tar.gz
* fixed InitializeSqlite and ReleaseSqlite functions (segfault after a call
to ReleaseSqlite with refcount=0) * changed all shortstrings to ansistrings ({$h+}) git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@13719 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/sqlite')
-rw-r--r--packages/sqlite/src/sqlite3.inc41
1 files changed, 20 insertions, 21 deletions
diff --git a/packages/sqlite/src/sqlite3.inc b/packages/sqlite/src/sqlite3.inc
index a0e04d9855..b86decb9cd 100644
--- a/packages/sqlite/src/sqlite3.inc
+++ b/packages/sqlite/src/sqlite3.inc
@@ -1,4 +1,4 @@
-{$mode objfpc}
+{$mode objfpc}{$h+}
{$ifdef BSD}
{$linklib c}
@@ -5725,7 +5725,7 @@ procedure ReleaseSQLite;
var
SQLiteLibraryHandle: TLibHandle;
- DefaultLibrary: String = Sqlite3Lib;
+ SQLiteDefaultLibrary: String = Sqlite3Lib;
{$ENDIF LOAD_DYNAMICALLY}
implementation
@@ -5912,46 +5912,45 @@ var
function TryInitialiseSqlite(const LibraryName: string): Boolean;
begin
- Result := false;
- if (RefCount=0) then
+ if InterlockedIncrement(RefCount) = 1 then
begin
SQLiteLibraryHandle := LoadLibrary(LibraryName);
- Result := (SQLiteLibraryHandle <> nilhandle);
+ Result := (SQLiteLibraryHandle <> NilHandle);
if not Result then
+ begin
+ RefCount := 0;
Exit;
- Inc(RefCount);
+ end;
LoadedLibrary := LibraryName;
LoadAddresses(SQLiteLibraryHandle);
- end else begin
- if (LoadedLibrary <> LibraryName) then
- raise EInoutError.CreateFmt(SErrAlreadyLoaded,[LoadedLibrary]);
- Inc(RefCount);
+ end else
Result := True;
- end;
end;
procedure InitialiseSQLite;
begin
- InitialiseSQLite(DefaultLibrary);
+ InitialiseSQLite(SQLiteDefaultLibrary);
end;
procedure InitialiseSQLite(LibraryName: String);
begin
+ if (LoadedLibrary <> '') and (LoadedLibrary <> LibraryName) then
+ raise EInoutError.CreateFmt(SErrAlreadyLoaded,[LoadedLibrary]);
+
if not TryInitialiseSQLIte(LibraryName) then
raise EInOutError.CreateFmt(SErrLoadFailed,[LibraryName]);
end;
procedure ReleaseSQLite;
begin
- if RefCount > 1 then
- Dec(RefCount)
- else
- if UnloadLibrary(SQLiteLibraryHandle) then
- begin
- Dec(RefCount);
- SQLiteLibraryHandle := NilHandle;
- LoadedLibrary := '';
- end;
+ if InterlockedDecrement(RefCount) <= 0 then
+ begin
+ if SQLiteLibraryHandle <> NilHandle then
+ UnloadLibrary(SQLiteLibraryHandle);
+ SQLiteLibraryHandle := NilHandle;
+ LoadedLibrary := '';
+ RefCount := 0;
+ end;
end;
{$ENDIF}