[Larceny-users] error peeking short values from raw memory

Marco Maggi marco.maggi-ipsu at poste.it
Fri Jul 3 10:13:59 EDT 2009


Ciao,

  Running the following program on a i686-pc-linux-gnu under
Larceny revision 6303 (Larceny  v0.97a4 (alpha test) (Jun 26
2009 16:14:03, precise:Linux:unified)):

(import (rnrs)
  (primitives
   foreign-procedure
   %peek8 %peek8u %peek16 %peek16u %peek32 %peek32u %peek-pointer
   %poke8 %poke8u %poke16 %poke16u %poke32 %poke32u %poke-pointer
   void*-double-set! void*-double-ref void*-float-set! void*-float-ref
   void*? void*-rt record-constructor void*->address))

(define platform-malloc
  (foreign-procedure "malloc" '(unsigned) 'void*))

(define p (platform-malloc 4096))
(define a (void*->address p))

(let ((v (- (expt 2 7) 1)))
  (%poke8 a v)
  (write (list v (%peek8 a)))
  (newline))

(let ((v (- (expt 2 15) 1)))
  (%poke16 a v)
  (write (list v (%peek16 a)))
  (newline))

(let ((v (- (expt 2 31) 1)))
  (%poke32 a v)
  (write (list v (%peek32 a)))
  (newline))

(newline)

(let ((v (- (expt 2 8) 1)))
  (%poke8u a v)
  (write (list v (%peek8u a)))
  (newline))

(let ((v (- (expt 2 16) 1)))
  (%poke16u a v)
  (write (list v (%peek16u a)))
  (newline))

(let ((v (- (expt 2 32) 1)))
  (%poke32u a v)
  (write (list v (%peek32u a)))
  (newline))

(newline)

(let ((v (- (expt 2 15) 2)))
  (%poke16 a v)
  (write (list v (%peek16 a)))
  (newline))

prints:

(127 127)
(32767 -32769)
(2147483647 2147483647)

(255 255)
(65535 65535)
(4294967295 4294967295)

(32766 32766)

while  I expected (32767  32767) as  output for  %peek16 and
%poke16.   This  gives  me   a  feeling  of  deja  vu,  but,
unfortunately, right now I  cannot access the archive of the
mailing  list (no  answer from  server) to  verify if  I had
reported it before.  However, searching the tickets database
for "peek" or "poke" shows nothing relevant.
--
Marco Maggi



More information about the Larceny-users mailing list