[pypy-commit] pypy sqlite-cffi: Probe for sqlite3_enable_load_extension with dlopen()

stefanor noreply at buildbot.pypy.org
Wed Feb 27 22:56:25 CET 2013


Author: Stefano Rivera <stefano at rivera.za.net>
Branch: sqlite-cffi
Changeset: r61867:66403f3ff51d
Date: 2013-02-27 23:54 +0200
http://bitbucket.org/pypy/pypy/changeset/66403f3ff51d/

Log:	Probe for sqlite3_enable_load_extension with dlopen()

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -231,6 +231,21 @@
 int sqlite3_value_numeric_type(sqlite3_value*);
 """)
 
+
+def _has_load_extension():
+    """Only available since 3.3.6"""
+    unverified_ffi = FFI()
+    unverified_ffi.cdef("""
+    typedef ... sqlite3;
+    int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
+    """)
+    unverified_lib = unverified_ffi.dlopen('sqlite3')
+    return hasattr(unverified_lib, 'sqlite3_enable_load_extension')
+
+
+if _has_load_extension():
+    ffi.cdef("int sqlite3_enable_load_extension(sqlite3 *db, int onoff);")
+
 lib = ffi.verify("""
 #include <sqlite3.h>
 """, libraries=['sqlite3'])
@@ -272,7 +287,6 @@
 for symbol in exported_sqlite_symbols:
     globals()[symbol] = getattr(lib, symbol)
 
-
 _SQLITE_TRANSIENT = ffi.cast('void *', lib.SQLITE_TRANSIENT)
 
 
@@ -758,7 +772,7 @@
         from sqlite3.dump import _iterdump
         return _iterdump(self)
 
-    if lib.HAS_LOAD_EXTENSION:
+    if hasattr(lib, 'sqlite3_enable_load_extension'):
         def enable_load_extension(self, enabled):
             self._check_thread()
             self._check_closed()


More information about the pypy-commit mailing list