chicken-users
[Top][All Lists]
Advanced

[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: Christian Kellermann
Subject: Re: [Chicken-users] how to create a cairo_matrix_t (defined by define-foreign-type) ?
Date: Sun, 15 Jan 2012 15:15:02 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

* 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
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
for this on my cairo branch, it needs some more testing then I will
push this out.

HTH,

Christian

-- 
Who can (make) the muddy water (clear)? Let it be still, and it will
gradually become clear. Who can secure the condition of rest? Let
movement go on, and the condition of rest will gradually arise.
 -- Lao Tse. 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]