[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] how to create a cairo_matrix_t (defined by define-fo
From: |
Markus Klotzbuecher |
Subject: |
Re: [Chicken-users] how to create a cairo_matrix_t (defined by define-foreign-type) ? |
Date: |
Sun, 15 Jan 2012 18:02:14 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Sun, Jan 15, 2012 at 03:15:02PM +0100, Christian Kellermann wrote:
> * Markus Klotzbuecher <address@hidden> [120113 21:01]:
> > Dear All,
> >
> > For my small visualization project I need the functions
> > cairo-get-matrix and cairo-set-matrix. The cairo_matrix_t type is
> > defined in cairo.sdl as shown below:
> >
> > (define-foreign-type cairo_matrix_t (c-pointer "cairo_matrix_t")
> > values
> > (cut tag-pointer <> 'cairo-matrix))
> >
> > cairo-get-matrix expects a cairo_matrix_t pointer as shown below, but
> > I couldn't figure out how to create such a type. Is it correct that
> > define-foreign-type registers the type with CHICKEN's type system, but
> > does not create a constructor?
> >
> > (define cairo-get-matrix
> > (foreign-lambda void "cairo_get_matrix" cairo_t cairo_matrix_t))
> >
> > For now I worked around it by using the code below. Is this correct
> > chickenwise? Is there a better solution?
> >
> > (define cairo-get-matrix
> > (foreign-lambda* cairo_matrix_t ((cairo_t ct))
> > "cairo_matrix_t cmt;
> > cairo_get_matrix(ct, &cmt);
> > C_return(&cmt);"))
>
> Does that really work? You are allocating this on the stack and
It does work, but it didn't seem right...
> that location might be gone after the function returns. You can use
> malloc there and set a finalizer on the chicken object. I have code
Ok, thanks for clarifying.
> for this on my cairo branch, it needs some more testing then I will
> push this out.
Is this branch available somewhere? I would prefer a correct but
untested version to my wrong but coincidentally working one :-)
Best regards
Markus