diff options
| author | Eli Zaretskii | 2021-12-11 11:26:04 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2021-12-11 11:26:04 +0200 |
| commit | 628306c299923551cdc8cf09c874744ae7b74216 (patch) | |
| tree | 375bc58e332676642ea5d8a0c309007cf78586e9 /src/sqlite.c | |
| parent | 6c81683a2791a1a08e4abe9b670f47b2b4037eff (diff) | |
| download | emacs-628306c299923551cdc8cf09c874744ae7b74216.tar.gz emacs-628306c299923551cdc8cf09c874744ae7b74216.zip | |
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.c | 48 |
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) | |||
| 151 | LOAD_DLL_FN (library, sqlite3_prepare_v2); | 151 | LOAD_DLL_FN (library, sqlite3_prepare_v2); |
| 152 | return true; | 152 | return true; |
| 153 | } | 153 | } |
| 154 | |||
| 155 | static bool | ||
| 156 | sqlite_loaded_p (void) | ||
| 157 | { | ||
| 158 | Lisp_Object found = Fassq (Qsqlite3, Vlibrary_cache); | ||
| 159 | |||
| 160 | return CONSP (found) && EQ (XCDR (found), Qt); | ||
| 161 | } | ||
| 162 | #endif /* WINDOWSNT */ | 154 | #endif /* WINDOWSNT */ |
| 163 | 155 | ||
| 164 | static bool | 156 | static bool |
| 165 | init_sqlite_functions (void) | 157 | init_sqlite_functions (void) |
| 166 | { | 158 | { |
| 167 | #ifdef WINDOWSNT | 159 | #ifdef WINDOWSNT |
| 168 | if (sqlite_loaded_p ()) | 160 | static bool sqlite3_initialized; |
| 169 | return true; | 161 | |
| 170 | else | 162 | if (!sqlite3_initialized) |
| 171 | { | 163 | { |
| 172 | HMODULE library; | 164 | HMODULE library = w32_delayed_load (Qsqlite3); |
| 173 | 165 | ||
| 174 | if (!(library = w32_delayed_load (Qsqlite3))) | 166 | if (!library) |
| 167 | message1 ("sqlite3 library was not found"); | ||
| 168 | else if (load_dll_functions (library)) | ||
| 175 | { | 169 | { |
| 176 | message1 ("sqlite3 library not found"); | 170 | sqlite3_initialized = true; |
| 177 | return false; | 171 | Vlibrary_cache = Fcons (Fcons (Qsqlite3, Qt), Vlibrary_cache); |
| 172 | } | ||
| 173 | else | ||
| 174 | { | ||
| 175 | message1 ("sqlite3 library was found, but could not be loaded successfully"); | ||
| 176 | Vlibrary_cache = Fcons (Fcons (Qsqlite3, Qnil), Vlibrary_cache); | ||
| 178 | } | 177 | } |
| 179 | |||
| 180 | if (! load_dll_functions (library)) | ||
| 181 | goto bad_library; | ||
| 182 | |||
| 183 | Vlibrary_cache = Fcons (Fcons (Qsqlite3, Qt), Vlibrary_cache); | ||
| 184 | return true; | ||
| 185 | } | 178 | } |
| 186 | 179 | return sqlite3_initialized; | |
| 187 | bad_library: | ||
| 188 | Vlibrary_cache = Fcons (Fcons (Qsqlite3, Qnil), Vlibrary_cache); | ||
| 189 | |||
| 190 | return false; | ||
| 191 | #else /* !WINDOWSNT */ | 180 | #else /* !WINDOWSNT */ |
| 192 | return true; | 181 | return true; |
| 193 | #endif /* !WINDOWSNT */ | 182 | #endif /* !WINDOWSNT */ |
| @@ -674,12 +663,7 @@ DEFUN ("sqlite-available-p", Fsqlite_available_p, Ssqlite_available_p, 0, 0, 0, | |||
| 674 | if (CONSP (found)) | 663 | if (CONSP (found)) |
| 675 | return XCDR (found); | 664 | return XCDR (found); |
| 676 | else | 665 | else |
| 677 | { | 666 | return init_sqlite_functions () ? Qt : Qnil; |
| 678 | Lisp_Object status; | ||
| 679 | status = init_sqlite_functions () ? Qt : Qnil; | ||
| 680 | Vlibrary_cache = Fcons (Fcons (Qsqlite3, status), Vlibrary_cache); | ||
| 681 | return status; | ||
| 682 | } | ||
| 683 | # else | 667 | # else |
| 684 | return Qt; | 668 | return Qt; |
| 685 | #endif | 669 | #endif |