From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.devel Subject: Re: make-c-struct and pointer->string Date: Fri, 29 Mar 2019 19:08:08 +0000 Message-ID: References: <20190326101419.340081fc@capac> <20190329054840.363e42a0@capac> <20190329064617.41fadbcd@capac> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000f37dc8058540646f" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="13342"; mail-complaints-to="usenet@blaine.gmane.org" Cc: guile-devel To: David Pirotte Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Mar 29 20:10:18 2019 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h9wtM-0003Ks-4m for guile-devel@m.gmane.org; Fri, 29 Mar 2019 20:10:16 +0100 Original-Received: from localhost ([127.0.0.1]:41751 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9wtL-0002rr-1v for guile-devel@m.gmane.org; Fri, 29 Mar 2019 15:10:15 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:58591) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9wt3-0002rY-FB for guile-devel@gnu.org; Fri, 29 Mar 2019 15:09:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9wsu-00011K-FO for guile-devel@gnu.org; Fri, 29 Mar 2019 15:09:53 -0400 Original-Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]:45534) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h9wsf-0000bq-UX for guile-devel@gnu.org; Fri, 29 Mar 2019 15:09:35 -0400 Original-Received: by mail-lf1-x12e.google.com with SMTP id 5so2153076lft.12 for ; Fri, 29 Mar 2019 12:08:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nJ9o+CnB5glBFwPYEqXU319Szkz+jBuUS6ZF+u9eY7Q=; b=EKsug7zBCy8I8WDjHsjOa9MvoQIPEjVYPQ+/yX9OkEqbMkMJw66vJhmvNz+uaUVTEU UTcsZDJsdd2ftmBscxQTAkRoGKUhMG4aTWjwWTc+UpM8BegduqFHV5zRlXETrv2RqcuA NQQgn679752r+MKOivRxkQ6kYuzKdy+BS5JIAAlZpQBBzftJbcIiKDeqy3g3COyXWrvG Oa8xtMzjfp+os35kjTcSgp6mhEE9p5aZzvetCl5OHdPKOtLkEDQmRFTvICf+h2YALRCs oO6ysYJd+0BNXkSaMVQQxYgjdBD4UG/zXtajgR6wjfzwajUilZnV0jSFE8aMdYCF49mC 8zTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nJ9o+CnB5glBFwPYEqXU319Szkz+jBuUS6ZF+u9eY7Q=; b=mHu+yrDM1zNDUiBKNbNxgpBYxLeQzmY2pF7csrFfs3u4It6+wBv46QuK371OiZm4Nm +W2DAAruLWOzFjtHhadChIfkaL8A2XGr1hO9kaq7TPi+JlB+SoSKcemZeHsiBaoGaAQT bDh6uaIzcA36AK57K5EkxTeYl/PGhOIsQrh9g1uXqPs7FE13Yj99HC1fUsnBjD/i8qzy WSU478s39XHwA5h7hreWdelvdeRbk2tInB45L1KcJMQrrBHqbMSvGQLc1ioa7KqWw4Ow nquyWxRjKqmTjc2bShEzSkExm4WvcVvp6zIq2mE7f2HvmVWl5Mq0lTnYIka/uo1yqqJE X3ig== X-Gm-Message-State: APjAAAVectnZLw/Qp+dY8q6fnnBcYxBxsDOFgdRqE+8YUrDlj8WUNi3a XY4kvnp1Lq8jxSDeEKUrJHdRPVXNPT/DrRRcQdc= X-Google-Smtp-Source: APXvYqzklddnz1nSMTUXXv3Gbv/2NynJztuM7FbYXcSa4fZJjO+llcFNT3OBKU2kgYbSuB8tPNd2MngghQUJGo4xAUo= X-Received: by 2002:a19:974f:: with SMTP id z76mr25642362lfd.89.1553886501632; Fri, 29 Mar 2019 12:08:21 -0700 (PDT) In-Reply-To: <20190329064617.41fadbcd@capac> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::12e X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:19869 Archived-At: --000000000000f37dc8058540646f Content-Type: text/plain; charset="UTF-8" On Fri, 29 Mar 2019, 09:46 David Pirotte, wrote: > Hi again, > > > ... > > Following your explanation and example, I tried this and thought it > would work > > then, but it also failed: > > > GNU Guile 2.2.4.1-cdb19 > > > Enter `,help' for help. > > scheme@(guile-user)> ,use (system foreign) > > scheme@(guile-user)> (define str-1 "Hello") > > scheme@(guile-user)> (define str-2 "there!") > > scheme@(guile-user)> (make-c-struct (list '* '*) (list > (string->pointer str-1) > > (string->pointer str-2))) $2 = # > > scheme@(guile-user)> (parse-c-struct $2 (list '* '*)) > > $3 = (# #) > > scheme@(guile-user)> (map pointer->string $3) > > $4 = ("" "`\v?\x02?U") > > Here are another couple of examples: > > scheme@(guile-user)> ,use (system foreign) > scheme@(guile-user)> (define str-1 "Hello") > scheme@(guile-user)> (define str-2 "there!") > scheme@(guile-user)> (make-c-struct (list '* '*) (list (string->pointer > str-1) (string->pointer str-2))) > $2 = # > scheme@(guile-user)> (parse-c-struct $2 (list '* '*)) > $3 = (# #) > scheme@(guile-user)> (map pointer->string $3) > $4 = ("Hello" "there!") > > But then: > > scheme@(guile-user)> str-1 > $5 = "Hello" > scheme@(guile-user)> str-2 > $6 = "there!" > scheme@(guile-user)> (map pointer->string $3) > $7 = ("?\\?q\x7f" " ??E?U") > scheme@(guile-user)> (map pointer->string $3) > $8 = ("?\\?q\x7f" " ??E?U") > > I guess that what the GC recollected are the pointers, or even $3, the list > Let's hold on it then: > > scheme@(guile-user)> (define c-struct (make-c-struct (list '* '*) (list > (string->pointer str-1) (string->pointer str-2)))) > scheme@(guile-user)> (parse-c-struct c-struct (list '* '*)) > $9 = (# #) > scheme@(guile-user)> (map pointer->string $9) > $10 = ("\x02" "0??E?U") > > Not good either. Let's hold on the parse-c-struct to then: > > scheme@(guile-user)> (define parsed (parse-c-struct c-struct (list '* > '*))) > scheme@(guile-user)> parsed > $16 = (# #) > scheme@(guile-user)> (map pointer->string $16) > $17 = ("0??E?U" "?\x01?F?U") > scheme@(guile-user)> (map pointer->string parsed) > $18 = ("\x03" "?\x01?F?U") > > Didn't do it either > Ok, let's hold-on to the pointers (which I thought would not be necessary > after > holding-on c-struct and/or parsed): > > scheme@(guile-user)> (define p1 (string->pointer str-1)) > scheme@(guile-user)> (define p2 (string->pointer str-2)) > scheme@(guile-user)> (make-c-struct (list '* '*) (list p1 p2)) > $19 = # > scheme@(guile-user)> (parse-c-struct $19 (list '* '*)) > $20 = (# #) > scheme@(guile-user)> p1 > $21 = # > scheme@(guile-user)> p2 > $22 = # > scheme@(guile-user)> (map pointer->string $20) > $23 = ("Hello" "there!") > > That worked, but I wonder if this is what is expected from us (users)? > Yes, that would seem very odd to me, as I thought that a 'pointer' really was just an address. (Hopefully some more light will be thrown when the maintainers are back around again!) Best wishes, Neil > Cheers, > David > --000000000000f37dc8058540646f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Fri, 29 Mar 2019, 09:46 David Pirotte, <david@altosw.be> wrote:
Hi again,

> ...
> Following your explanation and example, I tried this and thought it wo= uld work
> then, but it also failed:

> GNU Guile 2.2.4.1-cdb19

> Enter `,help' for help.
> scheme@(guile-user)> ,use (system foreign)
> scheme@(guile-user)> (define str-1 "Hello")
> scheme@(guile-user)> (define str-2 "there!")
> scheme@(guile-user)>=C2=A0 (make-c-struct (list '* '*) (lis= t (string->pointer str-1)
> (string->pointer str-2))) $2 =3D #<pointer 0x55ae02e57830> > scheme@(guile-user)> (parse-c-struct $2 (list '* '*))
> $3 =3D (#<pointer 0x55ae02f9e3c0> #<pointer 0x55ae02f8b050>= ;)
> scheme@(guile-user)> (map pointer->string $3)
> $4 =3D ("" "`\v?\x02?U")

Here are another couple of examples:

scheme@(guile-user)> ,use (system foreign)
scheme@(guile-user)> (define str-1 "Hello")
scheme@(guile-user)> (define str-2 "there!")
scheme@(guile-user)>=C2=A0 (make-c-struct (list '* '*) (list (st= ring->pointer str-1) (string->pointer str-2)))
$2 =3D #<pointer 0x55844635a0b0>
scheme@(guile-user)> (parse-c-struct $2 (list '* '*))
$3 =3D (#<pointer 0x558445edf610> #<pointer 0x558445edf630>) scheme@(guile-user)> (map pointer->string $3)
$4 =3D ("Hello" "there!")

But then:

scheme@(guile-user)> str-1
$5 =3D "Hello"
scheme@(guile-user)> str-2
$6 =3D "there!"
scheme@(guile-user)> (map pointer->string $3)
$7 =3D ("?\\?q\x7f" " ??E?U")
scheme@(guile-user)> (map pointer->string $3)
$8 =3D ("?\\?q\x7f" " ??E?U")

I guess that what the GC recollected are the pointers, or even $3, the list=
Let's hold on it then:

scheme@(guile-user)> (define c-struct (make-c-struct (list '* '*= ) (list (string->pointer str-1) (string->pointer str-2))))
scheme@(guile-user)> (parse-c-struct c-struct (list '* '*))
$9 =3D (#<pointer 0x558445edf400> #<pointer0x558445ef8df0>)
scheme@(guile-user)> (map pointer->string $9)
$10 =3D ("\x02" "0??E?U")

Not good either. Let's hold on the parse-c-struct to then:

scheme@(guile-user)> (define parsed (parse-c-struct c-struct (list '= * '*)))
scheme@(guile-user)> parsed
$16 =3D (#<pointer 0x558445edf400> #<pointer 0x558445ef8df0>) scheme@(guile-user)> (map pointer->string $16)
$17 =3D ("0??E?U" "?\x01?F?U")
scheme@(guile-user)> (map pointer->string parsed)
$18 =3D ("\x03" "?\x01?F?U")

Didn't do it either
Ok, let's hold-on to the pointers (which I thought would not be necessa= ry after
holding-on c-struct and/or parsed):

scheme@(guile-user)> (define p1 (string->pointer str-1))
scheme@(guile-user)> (define p2 (string->pointer str-2))
scheme@(guile-user)> (make-c-struct (list '* '*) (list p1 p2)) $19 =3D #<pointer 0x5584467a5d70>
scheme@(guile-user)> (parse-c-struct $19 (list '* '*))
$20 =3D (#<pointer 0x5584468b0190> #<pointer 0x5584468b4430>) scheme@(guile-user)> p1
$21 =3D #<pointer 0x5584468b0190>
scheme@(guile-user)> p2
$22 =3D #<pointer 0x5584468b4430>
scheme@(guile-user)> (map pointer->string $20)
$23 =3D ("Hello" "there!")

That worked, but I wonder if this is what is expected from us (users)?
<= /blockquote>

Yes, = that would seem very odd to me, as I thought that a 'pointer' reall= y was just an address.

(= Hopefully some more light will be thrown when the maintainers are back arou= nd again!)

Best wishes,<= /div>
=C2=A0 =C2=A0 =C2=A0Neil

=

Cheers,
David
--000000000000f37dc8058540646f--