[pypy-commit] pypy default: Fix the failing test (blob returned by sqlite3 need to be kept alive,

arigo noreply at buildbot.pypy.org
Fri Apr 5 11:58:44 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r63048:961fb066e7b7
Date: 2013-04-05 12:00 +0200
http://bitbucket.org/pypy/pypy/changeset/961fb066e7b7/

Log:	Fix the failing test (blob returned by sqlite3 need to be kept
	alive, which require making a copy; CPython does a copy too.)

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -29,6 +29,7 @@
 import string
 import sys
 import weakref
+import array
 from threading import _get_ident as _thread_get_ident
 try:
     from __pypy__ import newlist_hint
@@ -958,7 +959,11 @@
                 elif typ == _lib.SQLITE_BLOB:
                     blob = _lib.sqlite3_column_blob(self.__statement._statement, i)
                     blob_len = _lib.sqlite3_column_bytes(self.__statement._statement, i)
-                    val = _BLOB_TYPE(_ffi.buffer(blob, blob_len))
+                    # make a copy of the data into an array, in order to get
+                    # a read-write buffer in the end, and one that own the
+                    # memory for a more predictable length of time than 'blob'
+                    copy = array.array("c", _ffi.buffer(blob, blob_len))
+                    val = _BLOB_TYPE(copy)
             row.append(val)
         return tuple(row)
 


More information about the pypy-commit mailing list