emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 0bb8e127b0: Port sqlite.c to OS X 10.6.8 with Xcode 3.2.6


From: Paul Eggert
Subject: master 0bb8e127b0: Port sqlite.c to OS X 10.6.8 with Xcode 3.2.6
Date: Sun, 17 Apr 2022 20:56:48 -0400 (EDT)

branch: master
commit 0bb8e127b08dcddc67c7fd62b966d89db5135a79
Author: Paul Eggert <eggert@cs.ucla.edu>
Commit: Paul Eggert <eggert@cs.ucla.edu>

    Port sqlite.c to OS X 10.6.8 with Xcode 3.2.6
    
    Problem reported by Keith David Bershatsky in:
    https://lists.gnu.org/r/emacs-devel/2022-04/msg00923.html
    * src/sqlite.c (Fsqlite_open): Don’t assume SQLITE_OPEN_MEMORY
    is defined.
---
 src/sqlite.c | 42 ++++++++++++++++++++----------------------
 1 file changed, 20 insertions(+), 22 deletions(-)

diff --git a/src/sqlite.c b/src/sqlite.c
index 1ca8669931..7388b576e9 100644
--- a/src/sqlite.c
+++ b/src/sqlite.c
@@ -240,38 +240,36 @@ DEFUN ("sqlite-open", Fsqlite_open, Ssqlite_open, 0, 1, 0,
 If FILE is nil, an in-memory database will be opened instead.  */)
   (Lisp_Object file)
 {
-  char *name;
+  Lisp_Object name;
+  int flags = (SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX
+              | SQLITE_OPEN_READWRITE);
+#ifdef SQLITE_OPEN_URI
+  flags |= SQLITE_OPEN_URI;
+#endif
+
   if (!init_sqlite_functions ())
     xsignal1 (Qerror, build_string ("sqlite support is not available"));
 
   if (!NILP (file))
+    name = ENCODE_FILE (Fexpand_file_name (file, Qnil));
+  else
     {
-      CHECK_STRING (file);
-      file = ENCODE_FILE (Fexpand_file_name (file, Qnil));
-      name = xstrdup (SSDATA (file));
+#ifdef SQLITE_OPEN_MEMORY
+      /* In-memory database.  These have to have different names to
+        refer to different databases.  */
+      AUTO_STRING (memory_fmt, ":memory:%d");
+      name = CALLN (Fformat, memory_fmt, make_int (++db_count));
+      flags |= SQLITE_OPEN_MEMORY;
+#else
+      xsignal1 (Qerror, build_string ("sqlite in-memory is not available"));
+#endif
     }
-  else
-    /* In-memory database.  These have to have different names to
-       refer to different databases.  */
-    name = xstrdup (SSDATA (CALLN (Fformat, build_string (":memory:%d"),
-                                  make_int (++db_count))));
 
   sqlite3 *sdb;
-  int ret = sqlite3_open_v2 (name,
-                            &sdb,
-                            SQLITE_OPEN_FULLMUTEX
-                            | SQLITE_OPEN_READWRITE
-                            | SQLITE_OPEN_CREATE
-                            | (NILP (file) ? SQLITE_OPEN_MEMORY : 0)
-#ifdef SQLITE_OPEN_URI
-                            | SQLITE_OPEN_URI
-#endif
-                            | 0, NULL);
-
-  if (ret != SQLITE_OK)
+  if (sqlite3_open_v2 (SSDATA (name), &sdb, flags, NULL) != SQLITE_OK)
     return Qnil;
 
-  return make_sqlite (false, sdb, NULL, name);
+  return make_sqlite (false, sdb, NULL, xstrdup (SSDATA (name)));
 }
 
 DEFUN ("sqlite-close", Fsqlite_close, Ssqlite_close, 1, 1, 0,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]