guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: make-c-struct and pointer->string


From: Neil Jerram
Subject: Re: make-c-struct and pointer->string
Date: Fri, 29 Mar 2019 19:08:08 +0000

On Fri, 29 Mar 2019, 09:46 David Pirotte, <address@hidden> 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 = #<pointer 0x55ae02e57830>
> scheme@(guile-user)> (parse-c-struct $2 (list '* '*))
> $3 = (#<pointer 0x55ae02f9e3c0> #<pointer 0x55ae02f8b050>)
> 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 = #<pointer 0x55844635a0b0>
scheme@(guile-user)> (parse-c-struct $2 (list '* '*))
$3 = (#<pointer 0x558445edf610> #<pointer 0x558445edf630>)
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 = (#<pointer 0x558445edf400> #<pointer0x558445ef8df0>)
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 = (#<pointer 0x558445edf400> #<pointer 0x558445ef8df0>)
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 = #<pointer 0x5584467a5d70>
scheme@(guile-user)> (parse-c-struct $19 (list '* '*))
$20 = (#<pointer 0x5584468b0190> #<pointer 0x5584468b4430>)
scheme@(guile-user)> p1
$21 = #<pointer 0x5584468b0190>
scheme@(guile-user)> p2
$22 = #<pointer 0x5584468b4430>
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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]