Closed GoogleCodeExporter closed 9 years ago
I implemented them as in the attached file. One only needs to define
the variables "on-32-bits-system" and "sizeof-pointer". I see that
the following fails:
(import (rnrs))
(define bv (make-bytevector 1064))
;(bytevector-s32-set! bv 16 (expt 2 31) (native-endianness))
(bytevector-s32-set! bv 16 (- (expt 2 32) 1) (native-endianness))
and IMHO this breaks R6RS because the value to poke should
be acceptable. Are you poking only fixnums? The other
accessors seem to have the same problem.
Original comment by mrc....@gmail.com
on 3 Dec 2008 at 1:37
Attachments:
Thank you for your kind message and code :)
> IMHO this breaks R6RS because the value to poke should
> be acceptable. Are you poking only fixnums? The other
> accessors seem to have the same problem.
Yes, It is a problem and I think about it. According to R6RS,
bytevector-s32-set!
accept x only if (<= INT32_MIN x INT32_MAX) and bytevector-u32-set! accept x
only if
(<= 0 x UINT32_MAX). So, pointer-set-c-int! should be defined as follows:
(define (pointer-set-c-int! pointer position value)
(let ((bv (make-bytevector-mapping
(pointer-value pointer)
(+ 4 position))))
(cond ((<= -2147483648 x 2147483647)
(bytevector-s32-set! bv value (native-endiannes)))
((<= 0 x 4294967295)
(bytevector-u32-set! bv value (native-endiannes)))
(else
(assertion-violation
'pointer-set-c-int!
"value out of range")))))
Because it looks too much for just poking one 32bit value, I conclude I should
implement it in C.
I'm going to take ikarus's API. I like that one too. :)
-- fujita
Original comment by y.fujita...@gmail.com
on 3 Dec 2008 at 4:32
[deleted comment]
I have added new API to ffi and trunk directory is updated to revision 322.
new procedures:
(bytevector-c-void*-ref <bv> <index>)
(bytevector-c-short-ref <bv> <index>)
(bytevector-c-int-ref <bv> <index>)
(bytevector-c-long-ref <bv> <index>)
(bytevector-c-unsigned-int-ref <bv> <index>)
(bytevector-c-unsigned-short-ref <bv> <index>)
(bytevector-c-unsigned-long-ref <bv> <index>)
(bytevector-c-void*-set! <bv> <index> <value>)
(bytevector-c-short-set! <bv> <index> <value>)
(bytevector-c-int-set! <bv> <index> <value>)
(bytevector-c-long-set! <bv> <index> <value>)
new constants:
sizeof:short sizeof:int
sizeof:long sizeof:void*
alignof:short alignof:int
alignof:long alignof:void*
alignof:float alignof:double
alignof:int8_t alignof:int16_t
alignof:int32_t alignof:int64_t
With new procedure bytevector-c-long-set!, you can write pointer-set-c-long! as
follows:
(define (pointer-set-c-long! pointer position value)
(bytevector-c-long-set! (make-bytevector-mapping
(+ pointer position) sizeof:long)
value 0)
It does the same stuff as follows:
(define (pointer-set-c-long! pointer position value)
(if on-32-bits-system
(cond ((<= -2147483648 x 2147483647)
(bytevector-s32-set! (make-bytevector-mapping pointer (+ 4 position))
position value (native-endianness)))
((<= 0 x 4294967295)
(bytevector-u32-set! (make-bytevector-mapping pointer (+ 4 position))
position value (native-endianness)))
(else
(assertion-violation 'pointer-set-c-long! "value out of range")))
(cond ((<= -9223372036854775808 x 9223372036854775807)
(bytevector-s64-set! (make-bytevector-mapping pointer (+ 8 position))
position value (native-endianness)))
((<= 0 x 18446744073709551615)
(bytevector-u64-set! (make-bytevector-mapping pointer (+ 8 position))
position value (native-endianness)))
(else
(assertion-violation 'pointer-set-c-long! "value out of range")))))
Please try. Thank you!
-- fujita
Original comment by y.fujita...@gmail.com
on 16 Dec 2008 at 12:00
New version 0.9.6-update3 has released and I close this issue. Thank you again!
-- fujita
Original comment by y.fujita...@gmail.com
on 23 Dec 2008 at 10:24
Thanks. I have tested the peekers and pokers with my libs[1] and they seem to
work (I
have not yet pushed the code that uses them on the public repository,
refactoring is
taking more time than I had expected).
[1] http://sites.google.com/site/mrcmgg/nausicaa
Original comment by mrc....@gmail.com
on 24 Dec 2008 at 10:27
Original issue reported on code.google.com by
mrc....@gmail.com
on 1 Dec 2008 at 10:27