(ikarus system $foreign) pointers bugs

Bug #269971 reported by Derick Eddington
4
Affects Status Importance Assigned to Milestone
Ikarus Scheme
Fix Committed
Medium
Abdulaziz Ghuloum

Bug Description

Ikarus Scheme version 0.0.3+ (revision 1597, build 2008-09-13)
Copyright (c) 2006-2008 Abdulaziz Ghuloum

> (import (ikarus system $foreign))
> (define p (malloc 4))
> (pointer-set-long p 0 #xffffffff)
> (pointer-ref-ulong p 0)
-1 ;; should be #xffffffff
> (pointer-ref-long p 0)
-1
> (pointer-set-int p 0 #xffffffff)
> (pointer-ref-uint p 0)
-1 ;; should be #xffffffff
> (pointer-ref-int p 0)
-1
> (pointer-set-short p 0 #xffff)
> (pointer-ref-ushort p 0)
65535
> (pointer-ref-short p 0)
-1
> (pointer-set-char p 0 #xff)
> (pointer-ref-uchar p 0)
255
> (pointer-ref-char p 0)
-1
>

Offsets are wrong because (((long)ref(p, off_pointer_data)) + unfix(off)) is doing integer addition:

> (pointer-set-char p 0 #x12)
> (pointer-set-char p 1 #x34)
> (pointer-set-char p 2 #x56)
> (pointer-set-char p 3 #x78)
> (pointer-ref-ushort p 1)
22068 ;; should be 30806 (#x7856)
> (number->string 22068 16)
"5634"
>

Related branches

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote : Re: [Bug 269971] [NEW] (ikarus system $foreign) pointers bugs

On Sep 13, 2008, at 3:57 PM, Derick Eddington wrote:

> Offsets are wrong because (((long)ref(p, off_pointer_data)) + unfix
> (off)) is doing integer addition:

The offsets are intended to be in bytes, not in multiples
of the sizeof the char/short/int/long. The pointer is not
assumed to be homogeneous. It might be a struct containing
bytes, shorts, longs, etc.

I'll investigate the other issue later.

Thanks.

Revision history for this message
Derick Eddington (derick-eddington) wrote :

On Sat, 2008-09-13 at 17:54 -0700, Abdulaziz Ghuloum wrote:
> The offsets are intended to be in bytes, not in multiples
> of the sizeof the char/short/int/long. The pointer is not
> assumed to be homogeneous. It might be a struct containing
> bytes, shorts, longs, etc.

Ah, of course. Sorry.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Fixed in 1599. I appreciate you checking on these experimental features so quickly. It makes my life much easier.

Changed in ikarus:
assignee: nobody → aghuloum
importance: Undecided → Medium
status: New → Fix Committed
Revision history for this message
leppie (leppie) wrote :

Hi

Excuse the ignorance, but does these pointer operations not duplicate the (rnrs bytevectors) library?

Regards

leppie

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote : Re: [Bug 269971] Re: (ikarus system $foreign) pointers bugs

On Sep 14, 2008, at 10:04 AM, leppie wrote:

> Excuse the ignorance, but does these pointer operations not duplicate
> the (rnrs bytevectors) library?

These procedures operate on unmanaged memory (i.e., chunks that you
malloc and free), are unsafe, and will be used mostly internally.
Bytevector operations are safe and good, but they operate on Ikarus-
managed bytevectors whose addresses may change due to GC between any
two operations. I guess one could provide conversion procedures
between bytevectors and these blobs as an alternative to providing
all of these procedures.

These are still in early stages of development, and their interface
will change many times before becoming stable.

Aziz,,,

Revision history for this message
leppie (leppie) wrote :

Seems my mail never got here, perhaps it is pointing to an incorrect email.

> These procedures operate on unmanaged memory (i.e., chunks that you
> malloc and free), are unsafe, and will be used mostly internally.
> Bytevector operations are safe and good, but they operate on Ikarus-
> managed bytevectors whose addresses may change due to GC between any
> two operations.

You have a good point there! I never do much FFI on .NET either, but the
same rules apply ;)

Thanks

leppie

Changed in ikarus:
milestone: none → 0.0.4
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.