Skip to content

Commit 876fd7a

Browse files
committed
Check for the SQLite mutex API in configure
An SQLite built with SQLITE_THREADSAFE=0, such as the Emscripten port, does not export sqlite3_mutex_enter(), sqlite3_mutex_try() or sqlite3_mutex_leave().
1 parent e6f0c98 commit 876fd7a

5 files changed

Lines changed: 71 additions & 1 deletion

File tree

‎Modules/_sqlite/util.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,28 @@ pysqlite_set_ref(PyObject *owner, PyObject **field, PyObject *value)
7373
static inline void
7474
pysqlite_mutex_enter(sqlite3_mutex *mutex)
7575
{
76+
#ifdef PY_SQLITE_HAVE_MUTEX
7677
if (mutex != NULL && sqlite3_mutex_try(mutex) != SQLITE_OK) {
7778
Py_BEGIN_ALLOW_THREADS
7879
sqlite3_mutex_enter(mutex);
7980
Py_END_ALLOW_THREADS
8081
}
82+
#else
83+
/* An SQLite built without mutexes cannot be in serialized mode. */
84+
(void)mutex;
85+
#endif
8186
}
8287

8388
static inline void
8489
pysqlite_mutex_leave(sqlite3_mutex *mutex)
8590
{
91+
#ifdef PY_SQLITE_HAVE_MUTEX
8692
if (mutex != NULL) {
8793
sqlite3_mutex_leave(mutex);
8894
}
95+
#else
96+
(void)mutex;
97+
#endif
8998
}
9099

91100
static inline void

‎PCbuild/_sqlite3.vcxproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
<ItemDefinitionGroup>
9595
<ClCompile>
9696
<AdditionalIncludeDirectories>$(sqlite3Dir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
97-
<PreprocessorDefinitions>PY_SQLITE_HAVE_SERIALIZE;PY_SQLITE_ENABLE_LOAD_EXTENSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
97+
<PreprocessorDefinitions>PY_SQLITE_HAVE_MUTEX;PY_SQLITE_HAVE_SERIALIZE;PY_SQLITE_ENABLE_LOAD_EXTENSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
9898
</ClCompile>
9999
</ItemDefinitionGroup>
100100
<ItemGroup>

‎configure‎

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎configure.ac‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4846,6 +4846,12 @@ dnl hence CPPFLAGS instead of CFLAGS.
48464846
[Define if SQLite was compiled with the serialize API]
48474847
)
48484848
])
4849+
AC_CHECK_LIB([sqlite3], [sqlite3_mutex_try], [
4850+
AC_DEFINE(
4851+
[PY_SQLITE_HAVE_MUTEX], [1],
4852+
[Define if SQLite was compiled with mutexes (SQLITE_THREADSAFE != 0)]
4853+
)
4854+
])
48494855
], [
48504856
have_supported_sqlite3=no
48514857
])

‎pyconfig.h.in‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,9 @@
18121812
/* Define to 1 to build the sqlite module with loadable extensions support. */
18131813
#undef PY_SQLITE_ENABLE_LOAD_EXTENSION
18141814

1815+
/* Define if SQLite was compiled with mutexes (SQLITE_THREADSAFE != 0) */
1816+
#undef PY_SQLITE_HAVE_MUTEX
1817+
18151818
/* Define if SQLite was compiled with the serialize API */
18161819
#undef PY_SQLITE_HAVE_SERIALIZE
18171820

0 commit comments

Comments
 (0)