From 8bb542dbafc6e6d097b39b24f46e7c55df1fbe53 Mon Sep 17 00:00:00 2001
From: Mike Gilbert <floppym@gentoo.org>
Date: Sun, 17 Jun 2018 11:14:43 -0400
Subject: [PATCH 23/36] sqlite loadable extensions

https://bugs.gentoo.org/show_bug.cgi?id=335505
https://bugs.python.org/issue10268
---
 configure.ac | 9 +++++++++
 setup.py     | 6 ++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index efe6922b5d..7561fe7f54 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2536,6 +2536,15 @@ else
   TCLTK_LIBS="$with_tcltk_libs"
 fi
 
+# Check for support for loadable sqlite extensions
+AC_MSG_CHECKING(for --enable-loadable-sqlite-extensions)
+AC_ARG_ENABLE(loadable-sqlite-extensions,
+              AS_HELP_STRING([--enable-loadable-sqlite-extensions], [support loadable extensions in _sqlite module]),
+              [],
+              [enable_loadable_sqlite_extensions="no"])
+
+AC_MSG_RESULT($enable_loadable_sqlite_extensions)
+
 # Check for --with-dbmliborder
 AC_MSG_CHECKING(for --with-dbmliborder)
 AC_ARG_WITH(dbmliborder,
diff --git a/setup.py b/setup.py
index 469fa3c455..89946bcd55 100644
--- a/setup.py
+++ b/setup.py
@@ -1252,8 +1252,10 @@ class PyBuildExt(build_ext):
             else:
                 sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"'))
 
-            # Comment this out if you want the sqlite3 module to be able to load extensions.
-            sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))
+            # Enable support for loadable extensions in the sqlite3 module
+            # if --enable-loadable-sqlite-extensions configure option is used.
+            if '--enable-loadable-sqlite-extensions' not in sysconfig.get_config_var("CONFIG_ARGS"):
+                sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))
 
             if host_platform == 'darwin':
                 # In every directory on the search path search for a dynamic
-- 
2.38.1

