From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: David Pirotte Newsgroups: gmane.lisp.guile.devel Subject: Re: make-c-struct and pointer->string Date: Fri, 29 Mar 2019 06:46:17 -0300 Message-ID: <20190329064617.41fadbcd@capac> References: <20190326101419.340081fc@capac> <20190329054840.363e42a0@capac> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; boundary="Sig_/Pxgmtlv=N2pN6/xAZfuQY0A"; protocol="application/pgp-signature" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="165034"; mail-complaints-to="usenet@blaine.gmane.org" Cc: guile-devel To: Neil Jerram Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Mar 29 10:46:48 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 1h9o63-000gqK-Jo for guile-devel@m.gmane.org; Fri, 29 Mar 2019 10:46:47 +0100 Original-Received: from localhost ([127.0.0.1]:49667 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9o61-0005Mp-U9 for guile-devel@m.gmane.org; Fri, 29 Mar 2019 05:46:45 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:60263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9o5i-0005MZ-8y for guile-devel@gnu.org; Fri, 29 Mar 2019 05:46:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9o5h-0006uw-6k for guile-devel@gnu.org; Fri, 29 Mar 2019 05:46:26 -0400 Original-Received: from maximusconfessor.all2all.org ([79.99.200.102]:50134) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9o5g-0006uT-QD for guile-devel@gnu.org; Fri, 29 Mar 2019 05:46:25 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by maximusconfessor.all2all.org (Postfix) with ESMTP id 31C3A1BE0120; Fri, 29 Mar 2019 10:46:23 +0100 (CET) Original-Received: from maximusconfessor.all2all.org ([127.0.0.1]) by localhost (maximusconfessor.all2all.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qzd9NySaXDM1; Fri, 29 Mar 2019 10:46:23 +0100 (CET) Original-Received: from capac (unknown [179.210.18.152]) by maximusconfessor.all2all.org (Postfix) with ESMTPSA id 4AB9F1BE011D; Fri, 29 Mar 2019 10:46:22 +0100 (CET) In-Reply-To: <20190329054840.363e42a0@capac> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 79.99.200.102 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:19868 Archived-At: --Sig_/Pxgmtlv=N2pN6/xAZfuQY0A Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable 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 =20 > 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 =3D # > scheme@(guile-user)> (parse-c-struct $2 (list '* '*)) > $3 =3D (# #) > 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)> (make-c-struct (list '* '*) (list (string->pointer st= r-1) (string->pointer str-2))) $2 =3D # scheme@(guile-user)> (parse-c-struct $2 (list '* '*)) $3 =3D (# #) 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 (st= ring->pointer str-1) (string->pointer str-2)))) scheme@(guile-user)> (parse-c-struct c-struct (list '* '*)) $9 =3D (# #) 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 (# #) 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 necessary a= fter 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 # scheme@(guile-user)> (parse-c-struct $19 (list '* '*)) $20 =3D (# #) scheme@(guile-user)> p1 $21 =3D # scheme@(guile-user)> p2 $22 =3D # 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)? Cheers, David --Sig_/Pxgmtlv=N2pN6/xAZfuQY0A Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEhCJlRZtBM3furJHe83T9k6MFetcFAlyd6WkACgkQ83T9k6MF etfhPwgAm2h+axSTnQwIvACvypKjvSnfSjPa2gN+K3kH2WdCLmt87SvbWDTT4tuq y9rEAI/FuiAsAp2uCRUJodjyMtXRdpKOfoGt1MNtB9Pe226SOHr7UqnCgrwBZ3dZ O/AdS+E0HIseorDKUP0CZRnv38DtUhQGKatSTJSznyFE1vvYmfhgDk93CUvGn+TL JePv/CC89tDXYg6rfDG1J8pFcF06raSngZeZabpFMx9fsFtxatGhSWtS+ecAFaW9 ZnoLmZbB0MzXihOKr9dnBA8b6XybwdxocXmI6vF/uJKJdBc3mGV6gatzJTI34R7J EYxFpYeFu1CW8Fa6najLbF1mv7XFcw== =qcDv -----END PGP SIGNATURE----- --Sig_/Pxgmtlv=N2pN6/xAZfuQY0A--