From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sunjoong Lee Newsgroups: gmane.lisp.guile.user Subject: Re: crash in guile-sqlite3 Date: Sun, 29 Apr 2012 10:58:20 +0900 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=f46d041825823ef0df04bec7ad15 X-Trace: dough.gmane.org 1335664735 10902 80.91.229.3 (29 Apr 2012 01:58:55 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 29 Apr 2012 01:58:55 +0000 (UTC) Cc: guile-user@gnu.org, David Pirotte To: =?UTF-8?Q?Joonas_Saraj=C3=A4rvi?= Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Apr 29 03:58:54 2012 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SOJPX-0003S4-P3 for guile-user@m.gmane.org; Sun, 29 Apr 2012 03:58:51 +0200 Original-Received: from localhost ([::1]:50612 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SOJPX-00021D-2m for guile-user@m.gmane.org; Sat, 28 Apr 2012 21:58:51 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:39065) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SOJPS-00020o-3i for guile-user@gnu.org; Sat, 28 Apr 2012 21:58:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SOJPP-0002Zq-SP for guile-user@gnu.org; Sat, 28 Apr 2012 21:58:45 -0400 Original-Received: from mail-wi0-f177.google.com ([209.85.212.177]:61011) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SOJPP-0002Zh-Fw for guile-user@gnu.org; Sat, 28 Apr 2012 21:58:43 -0400 Original-Received: by wibhj13 with SMTP id hj13so1400870wib.12 for ; Sat, 28 Apr 2012 18:58:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=hd93myCejQJdeZ9bwN9qX4ZBiFTcC2sjmNLuKSIt7j8=; b=aM64JMbzFrR5FF4KDPWTjHyrY6uKFsWuZvfaCPMA91wbFvS1/0/W3SiAKMWmcXaNyH iSasORoSYfvCYa/gvcsVrgiz4IYNn8fc5fAeXsLfvferHW1hhi0CReuY65RAW7XR/FLG WH/+V93UnuWiLhd/w0xNuMkA4clSp1JYSLhL/NUfJV3uqU7hwFyWkFe6NMOt83o/g5vZ W/K2yFKqo5+ODVoNQbHXeQhD1wXHY1O8PVD6Vb6aB6U9hvus4OOFYxq8K3jb0H2bGe06 RTzuKYIPxzT57ug/uBMzdqNDvdYX//z9549wF5etdrLV1WVyk4NOl67mnhn49oXvVkUX bS1A== Original-Received: by 10.180.105.194 with SMTP id go2mr9500694wib.22.1335664721195; Sat, 28 Apr 2012 18:58:41 -0700 (PDT) Original-Received: by 10.223.93.206 with HTTP; Sat, 28 Apr 2012 18:58:20 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.212.177 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:9422 Archived-At: --f46d041825823ef0df04bec7ad15 Content-Type: text/plain; charset=UTF-8 Hi, Joonas; Yesterday, David said simple solution of yours. I think I found the case of segfault. ########## cut here ########## --- sqlite3.scm.old 2012-01-24 00:22:10.000000000 +0900 +++ sqlite3.scm 2012-04-29 10:37:37.999722092 +0900 @@ -284,11 +284,11 @@ (let ((bind-blob (pointer->procedure int (dynamic-func "sqlite3_bind_blob" libsqlite3) - (list '* int '* int '*))) + (list '* int '* int int))) (bind-text (pointer->procedure int (dynamic-func "sqlite3_bind_text" libsqlite3) - (list '* int '* int '*))) + (list '* int '* int int))) (bind-int64 (pointer->procedure int (dynamic-func "sqlite3_bind_int64" libsqlite3) @@ -301,8 +301,7 @@ int (dynamic-func "sqlite3_bind_null" libsqlite3) (list '* int))) - (sqlite-transient (bytevector->pointer - (make-bytevector (sizeof '*) #xff)))) + (sqlite-transient -1)) (lambda (stmt key val) (assert-live-stmt! stmt) (let ((idx (key->index stmt key)) ########## cut here ########## 2012/4/27 Sunjoong Lee > > Same crash on Guile 2.0.5. It looks like string encoding problem. Suppose > name be an integer not a string like 10, it would not crash. sqlite-bind > of Guile-SQLite3 will deliver this 10 to sqlite3_bind_int64 of libsqlite3. > If a string, it will use sqlite3_bind_text of libsqlite3. Before > delivering, it will encoding this string to utf-8 string pointer because > sqlite3_bind_text need to know string pointer and it's length. I think you > or Andy may look around that. > In the http://www.sqlite.org/c3ref/c_static.html , #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) I.e, SQLITE_TRANSIENT is actually -1, not some position of memory. sqlite-bind of Guile-SQLite3 had treated it as a pointer, an address of memory position. Oh, another one; your test code ex0.scm has a bug. --- ex0.scm.old 2012-04-29 10:57:09.717398060 +0900 +++ ex0.scm 2012-04-29 10:39:20.051261614 +0900 @@ -34,7 +34,7 @@ ;; This finalize call in particular seems to break things (sqlite-finalize stmt) ;; This seems to be never reached. - (display "finalized\n"))) + (display "finalized\n")) (display "closing\n") (sqlite-close db) \ No newline at end of file --f46d041825823ef0df04bec7ad15 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi,=C2=A0Joonas;

Yesterday,=C2=A0David said simple solut= ion of yours. I think I found the case of=C2=A0segfault.

########## cut here ##########
--- sqlite3.scm.old 2012-01-24 00= :22:10.000000000 +0900
+++ sqlite3.scm 2012-04-29 10:37:37.999722092 +0900
@@ -284,11 +284,11 = @@
=C2=A0 =C2=A0(let ((bind-blob (pointer->procedure
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0int
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(dynamic-func "sqlite3_bind_blob" libsqlite3)
- = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(list = '* int '* int '*)))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(list '* int '* int int)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(bind-text (pointer->procedure
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0int
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0(dynamic-func "sqlite3_bind_text" libs= qlite3)
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0(list '* int '* int '*)))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0(list '* int '* int int)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0(bind-int64 (pointer->procedure
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 int
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (= dynamic-func "sqlite3_bind_int64" libsqlite3)
@@ -301,8 +301,7 @@
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0int
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(dynamic-func "= sqlite3_bind_null" libsqlite3)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(list '* int)))
- =C2=A0 =C2=A0 =C2=A0 =C2=A0(sqlite-transient (bytevector->pointer
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 (make-bytevector (sizeof '*) #xff))))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0(sqlite-transient -1))
=C2=A0 =C2= =A0 =C2=A0(lambda (stmt key val)
=C2=A0 =C2=A0 =C2=A0 =C2=A0(asse= rt-live-stmt! stmt)
=C2=A0 =C2=A0 =C2=A0 =C2=A0(let ((idx (key-&g= t;index stmt key))
########## cut here ##########

2012/4/27 Sunjoong Lee <sunjoong@gmail.com>
Same crash on Guile 2.0.5. It looks li= ke string encoding problem. Suppose name be an integer not a string like 10= , it would not crash.=C2=A0sqlite-bind of=C2=A0Guile-SQLite3 will deliver t= his 10 to=C2=A0sqlite3_bind_int64 of=C2=A0libsqlite3. If a string, it will = use=C2=A0sqlite3_bind_text of=C2=A0libsqlite3. Before delivering, it will e= ncoding this string to utf-8 string pointer because sqlite3_bind_text need = to know string pointer and it's length. I think you or Andy may look ar= ound that.

#define SQLITE_TRANSIENT =C2=A0 ((sqlite3_destruct= or_type)-1)

I.e,=C2=A0SQLITE_TRANSIENT is actually -1, not some pos= ition of memory.=C2=A0sqlite-bind of=C2=A0Guile-SQLite3 had treated it as a= pointer, an address of=C2=A0memory=C2=A0position.

Oh, another one; your test code ex0.scm has a bug.=C2=A0

--- ex0.scm.old 2012-04-29 10:57:09.717398060 +0900
+++ ex0.scm 2012-04-29 10:39:20.051261614 +0900
@@ -34,7 +34,7 @@
=C2=A0 =C2=A0;; This finalize call in part= icular seems to break things
=C2=A0 =C2=A0(sqlite-finalize stmt)<= /div>
=C2=A0 =C2=A0;; This seems to be never reached.
- =C2= =A0(display "finalized\n")))
+ =C2=A0(display "finalized\n"))
=C2=A0
= =C2=A0(display "closing\n")
=C2=A0(sqlite-close db)
\ No newline at end of file

--f46d041825823ef0df04bec7ad15--