* modifying pointers
@ 2010-04-09 9:05 Andy Wingo
2010-04-09 16:30 ` Ludovic Courtès
0 siblings, 1 reply; 5+ messages in thread
From: Andy Wingo @ 2010-04-09 9:05 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guile-devel
Hi Ludo,
You added a change to foreign-set! for %null-pointer. Would it not make
sense instead to make foreign pointers of type "void" unsettable?
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: modifying pointers
2010-04-09 9:05 modifying pointers Andy Wingo
@ 2010-04-09 16:30 ` Ludovic Courtès
2010-04-09 16:59 ` Andy Wingo
0 siblings, 1 reply; 5+ messages in thread
From: Ludovic Courtès @ 2010-04-09 16:30 UTC (permalink / raw)
To: Andy Wingo; +Cc: guile-devel
Hi,
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:
--8<---------------cut here---------------start------------->8---
(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))))))
--8<---------------cut here---------------end--------------->8---
Here a ((void *) 777) pointer is created.
However, this is not allowed for ‘%null-pointer’ because (1) that would
change its semantics, and (2) it’s defined as ‘const’ anyway, so
modifying it leads to a segfault.
Thanks,
Ludo’.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: modifying pointers
2010-04-09 16:30 ` Ludovic Courtès
@ 2010-04-09 16:59 ` Andy Wingo
2010-04-09 19:46 ` Ludovic Courtès
0 siblings, 1 reply; 5+ messages in thread
From: Andy Wingo @ 2010-04-09 16:59 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guile-devel
Hi,
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?
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?
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: modifying pointers
2010-04-09 16:59 ` Andy Wingo
@ 2010-04-09 19:46 ` Ludovic Courtès
2010-04-09 20:15 ` Andy Wingo
0 siblings, 1 reply; 5+ messages in thread
From: Ludovic Courtès @ 2010-04-09 19:46 UTC (permalink / raw)
To: Andy Wingo; +Cc: guile-devel
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’.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: modifying pointers
2010-04-09 19:46 ` Ludovic Courtès
@ 2010-04-09 20:15 ` Andy Wingo
0 siblings, 0 replies; 5+ messages in thread
From: Andy Wingo @ 2010-04-09 20:15 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guile-devel
Hi!
On Fri 09 Apr 2010 21:46, ludo@gnu.org (Ludovic Courtès) writes:
> Andy Wingo <wingo@pobox.com> writes:
>
>> I'm just wondering if it is valid to create a ((void*) 777) pointer.
>> Under what condition is that useful?
>
[...]
> It opens the door to all sorts of crazy things. :-)
Cool :)
FWIW, let's kick that door off its hinges :-)))
>> 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.
Perhaps we should define one then. It would be more expressive. Also it
avoids all kinds of shared-state problems.
> (Besides, ‘foreign-set!’ exists and has always been defined for all
> types of foreign pointer objects.)
Sure, but this might be an accident. In every case except `void',
foreign-set! modifies the pointed-to memory. Perhaps we need a
foreign-pointer accessor instead, which would work on pointers to values
as well. And a constructor of course.
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-04-09 20:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2010-04-09 20:15 ` Andy Wingo
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).