From 9ebbbbbce3cb56e092d95edf918c1bce78b8d7e2 Mon Sep 17 00:00:00 2001 From: Hordur Freyr Yngvason Date: Tue, 9 Jul 2024 23:22:17 -0400 Subject: [PATCH 1/2] Fix bind-param of displaced vectors When the underlying vector is displaced on another array, and potentially with a fill pointer below its capacity, we need to do some pointer arithmetic. We use babel to extract the underlying simple array because it's already a transitive dependency via cffi. --- sqlite.asd | 4 +++- sqlite.lisp | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sqlite.asd b/sqlite.asd index 0e292f2..3efbc62 100644 --- a/sqlite.asd +++ b/sqlite.asd @@ -13,9 +13,11 @@ (:file "cache") (:file "sqlite" :depends-on ("sqlite-ffi" "cache"))) - :depends-on (:iterate :cffi) + :depends-on (:iterate :cffi :babel) :in-order-to ((test-op (load-op sqlite-tests)))) +(register-system-packages "babel" '(#:babel-encodings)) + (defmethod perform ((o asdf:test-op) (c (eql (find-system :sqlite)))) (funcall (intern "RUN-ALL-SQLITE-TESTS" :sqlite-tests))) diff --git a/sqlite.lisp b/sqlite.lisp index de0f97d..540025f 100644 --- a/sqlite.lisp +++ b/sqlite.lisp @@ -386,8 +386,9 @@ Supported types: (double-float (sqlite-ffi:sqlite3-bind-double (handle statement) index value)) (real (sqlite-ffi:sqlite3-bind-double (handle statement) index (coerce value 'double-float))) (string (sqlite-ffi:sqlite3-bind-text (handle statement) index value -1 (sqlite-ffi:destructor-transient))) - ((vector (unsigned-byte 8)) (cffi:with-pointer-to-vector-data (ptr value) - (sqlite-ffi:sqlite3-bind-blob (handle statement) index ptr (length value) (sqlite-ffi:destructor-transient)))) + ((vector (unsigned-byte 8)) (babel-encodings:with-checked-simple-vector ((value value) (start (nth-value 1 (array-displacement value))) (end (length value))) + (cffi:with-pointer-to-vector-data (ptr value) + (sqlite-ffi:sqlite3-bind-blob (handle statement) index (cffi:inc-pointer ptr start) (length value) (sqlite-ffi:destructor-transient))))) (vector (cffi:with-foreign-object (array :unsigned-char (length value)) (loop for i from 0 below (length value) From 23150573aaf2c7e6fa75de76d297aa9d30c1bbd9 Mon Sep 17 00:00:00 2001 From: Hordur Freyr Yngvason Date: Wed, 10 Jul 2024 09:42:05 -0400 Subject: [PATCH 2/2] Fix call to with-checked-simple-vector We can just put start 0 and end nil. The underlying library figures out the right values. --- sqlite.lisp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sqlite.lisp b/sqlite.lisp index 540025f..b3d525a 100644 --- a/sqlite.lisp +++ b/sqlite.lisp @@ -386,9 +386,9 @@ Supported types: (double-float (sqlite-ffi:sqlite3-bind-double (handle statement) index value)) (real (sqlite-ffi:sqlite3-bind-double (handle statement) index (coerce value 'double-float))) (string (sqlite-ffi:sqlite3-bind-text (handle statement) index value -1 (sqlite-ffi:destructor-transient))) - ((vector (unsigned-byte 8)) (babel-encodings:with-checked-simple-vector ((value value) (start (nth-value 1 (array-displacement value))) (end (length value))) + ((vector (unsigned-byte 8)) (babel-encodings:with-checked-simple-vector ((value value) (start 0) (end nil)) (cffi:with-pointer-to-vector-data (ptr value) - (sqlite-ffi:sqlite3-bind-blob (handle statement) index (cffi:inc-pointer ptr start) (length value) (sqlite-ffi:destructor-transient))))) + (sqlite-ffi:sqlite3-bind-blob (handle statement) index (cffi:inc-pointer ptr start) (- end start) (sqlite-ffi:destructor-transient))))) (vector (cffi:with-foreign-object (array :unsigned-char (length value)) (loop for i from 0 below (length value)