From: ludo@gnu.org (Ludovic Courtès)
To: Andy Wingo <wingo@pobox.com>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: modifying pointers
Date: Fri, 09 Apr 2010 21:46:15 +0200 [thread overview]
Message-ID: <87fx34mmt4.fsf@gnu.org> (raw)
In-Reply-To: <m3wrwgr28r.fsf@pobox.com> (Andy Wingo's message of "Fri, 09 Apr 2010 18:59:16 +0200")
Hello,
Andy Wingo <wingo@pobox.com> writes:
> On Fri 09 Apr 2010 18:30, ludo@gnu.org (Ludovic Courtès) writes:
>
>> Andy Wingo <wingo@pobox.com> writes:
>>
>>> You added a change to foreign-set! for %null-pointer. Would it not make
>>> sense instead to make foreign pointers of type "void" unsettable?
>>
>> Not necessarily. See the test that was added:
>>
>> (pass-if "foreign-set! other-null-pointer"
>> (let ((f (bytevector->foreign (make-bytevector 2))))
>> (and (not (= 0 (foreign-ref f)))
>> (begin
>> (foreign-set! f 0)
>> (= 0 (foreign-ref f)))
>> (begin
>> ;; Here changing the pointer value of F is perfectly valid.
>> (foreign-set! f 777)
>> (= 777 (foreign-ref f))))))
>>
>> Here a ((void *) 777) pointer is created.
>
> I'm just wondering if it is valid to create a ((void*) 777) pointer.
> Under what condition is that useful?
Under unusual scenarios where the program is communicated a pointer
value at the Scheme level, e.g., via ‘object-address’:
--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (object-address "sdf")
$1 = 43230400
scheme@(guile-user)> (define f (bytevector->foreign #vu8(10)))
scheme@(guile-user)> f
$2 = #<foreign pointer 43814744>
scheme@(guile-user)> (foreign-ref f)
$3 = 43814744
scheme@(guile-user)> (foreign-set! f $1)
scheme@(guile-user)> (foreign->bytevector f 'u32 0 1)
$4 = #u32(21) ;; scm_tc7_string
--8<---------------cut here---------------end--------------->8---
It opens the door to all sorts of crazy things. :-)
> If that is useful, OK; but under what condition is it useful to mutate
> the pointer in a foreign pointer object? Why not create a new foreign
> pointer object?
There’s currently no procedure to create a foreign object from a bignum.
(Besides, ‘foreign-set!’ exists and has always been defined for all
types of foreign pointer objects.)
Thanks,
Ludo’.
next prev parent reply other threads:[~2010-04-09 19:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-09 9:05 modifying pointers Andy Wingo
2010-04-09 16:30 ` Ludovic Courtès
2010-04-09 16:59 ` Andy Wingo
2010-04-09 19:46 ` Ludovic Courtès [this message]
2010-04-09 20:15 ` Andy Wingo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fx34mmt4.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=guile-devel@gnu.org \
--cc=wingo@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).