[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: modifying pointers
From: |
Ludovic Courtès |
Subject: |
Re: modifying pointers |
Date: |
Fri, 09 Apr 2010 21:46:15 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
Hello,
Andy Wingo <address@hidden> writes:
> On Fri 09 Apr 2010 18:30, address@hidden (Ludovic Courtès) writes:
>
>> Andy Wingo <address@hidden> 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’.