summaryrefslogtreecommitdiff
path: root/src/sqlite.c
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2021-12-11 11:26:04 +0200
committerEli Zaretskii <eliz@gnu.org>2021-12-11 11:26:04 +0200
commit628306c299923551cdc8cf09c874744ae7b74216 (patch)
tree375bc58e332676642ea5d8a0c309007cf78586e9 /src/sqlite.c
parent6c81683a2791a1a08e4abe9b670f47b2b4037eff (diff)
downloademacs-628306c299923551cdc8cf09c874744ae7b74216.tar.gz
Minor cleanups of sqlite3 code on MS-Windows
* src/sqlite.c (sqlite_loaded_p): Function deleted: not used anymore. (init_sqlite_functions) [WINDOWSNT]: Use a static 'bool' variable to indicate if sqlite3 DLL was successfully loaded. (Fsqlite_available_p) [WINDOWSNT]: Just call 'init_sqlite_functions' if Vlibrary_cache doesn't mention 'sqlite3'.
Diffstat (limited to 'src/sqlite.c')
-rw-r--r--src/sqlite.c48
1 files changed, 16 insertions, 32 deletions
diff --git a/src/sqlite.c b/src/sqlite.c
index aea79406aa6..47829cbdf7f 100644
--- a/src/sqlite.c
+++ b/src/sqlite.c
@@ -151,43 +151,32 @@ load_dll_functions (HMODULE library)
LOAD_DLL_FN (library, sqlite3_prepare_v2);
return true;
}
-
-static bool
-sqlite_loaded_p (void)
-{
- Lisp_Object found = Fassq (Qsqlite3, Vlibrary_cache);
-
- return CONSP (found) && EQ (XCDR (found), Qt);
-}
#endif /* WINDOWSNT */
static bool
init_sqlite_functions (void)
{
#ifdef WINDOWSNT
- if (sqlite_loaded_p ())
- return true;
- else
+ static bool sqlite3_initialized;
+
+ if (!sqlite3_initialized)
{
- HMODULE library;
+ HMODULE library = w32_delayed_load (Qsqlite3);
- if (!(library = w32_delayed_load (Qsqlite3)))
+ if (!library)
+ message1 ("sqlite3 library was not found");
+ else if (load_dll_functions (library))
{
- message1 ("sqlite3 library not found");
- return false;
+ sqlite3_initialized = true;
+ Vlibrary_cache = Fcons (Fcons (Qsqlite3, Qt), Vlibrary_cache);
+ }
+ else
+ {
+ message1 ("sqlite3 library was found, but could not be loaded successfully");
+ Vlibrary_cache = Fcons (Fcons (Qsqlite3, Qnil), Vlibrary_cache);
}
-
- if (! load_dll_functions (library))
- goto bad_library;
-
- Vlibrary_cache = Fcons (Fcons (Qsqlite3, Qt), Vlibrary_cache);
- return true;
}
-
- bad_library:
- Vlibrary_cache = Fcons (Fcons (Qsqlite3, Qnil), Vlibrary_cache);
-
- return false;
+ return sqlite3_initialized;
#else /* !WINDOWSNT */
return true;
#endif /* !WINDOWSNT */
@@ -674,12 +663,7 @@ DEFUN ("sqlite-available-p", Fsqlite_available_p, Ssqlite_available_p, 0, 0, 0,
if (CONSP (found))
return XCDR (found);
else
- {
- Lisp_Object status;
- status = init_sqlite_functions () ? Qt : Qnil;
- Vlibrary_cache = Fcons (Fcons (Qsqlite3, status), Vlibrary_cache);
- return status;
- }
+ return init_sqlite_functions () ? Qt : Qnil;
# else
return Qt;
#endif