[plt-scheme] FFI: problem with define-cpointer-type

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Sep 25 15:59:54 EDT 2008

On Sep 25, Sam Phillips wrote:
> On Thu, Sep 25, 2008 at 12:11 PM, Eli Barzilay <eli at barzilay.org> wrote:
> > I don't see anything wrong here offhand, but it looks like some
> > context is missing.  Specifically, the question is what exactly does
> > `my-type-maker' return -- what's the contents of it's `ptr' field.
> > You can also just add a printf to the Scheme->C part of your
> > definition to see that it gets to run, and check out its input/output.
> 
> (my-type-maker) returns a my-type struct the ptr field is an
> #<cpointer:my-type-ptr>.

This sounds suspicious.  I'd expect it to return a `my-type' struct
with a plain cpointer.  Sounds like you have a `my-type' that is
holding a `my-type'.  You might want to add a test:

(define-cpointer-type _my-type-ptr #f
  (lambda (v)
    (if (my-type? v)
      (my-type-ptr v)  ; <<--- here
      (error "cannot coerce to _my-type-ptr")))
  ...)

that checks that the result is a plain pointer.


> I placed a printf in the scheme->C lambda checking on what kind of value
> is being returned and it is a #<cpointer:my-type-ptr>.
> 
> I'm trying to come up with a more concrete simple test (that could
> actually just be run), that should expose the behavior.  Just need to find
> a simple libc func to use...

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.