[racket] An FFI question

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Sun Sep 7 10:02:04 EDT 2014

Hi All,

While reading the source of draw-lib/racket/draw/unsafe/cairo.rkt
which contains the bindings of Cairo, I noticed the following note:

;; ALLOCATION NOTE: drawing to a Cairo surface might call back to
;; Racket, because a drawing suface might be a PDF or SVG file
;; that is written through a callback to Racket. Consequently,
;; all GC-allocated arguments to Cairo functions must be allocated
;; a 'atomic-interior, so that they do not move in case of a GC.

This explains why _cairo_matrix_t is defined as:

(define-cstruct _cairo_matrix_t ([xx _double*] [yx _double*]  [xy
_double*] [yy _double*] [x0 _double*] [y0 _double*])
   #:malloc-mode 'atomic-interior)

However _cairo_glyph_t is defined as:

(define-cstruct _cairo_glyph_t ([index _long] [x _double*] [y _double*]))

Why is the    #:malloc-mode 'atomic-interior not needed here?

https://github.com/plt/racket/blob/c18f6e8d6dd2afc095be6764c8276b30f7c8da39/pkgs/draw-pkgs/draw-lib/racket/draw/unsafe/cairo.rkt#L16

--
Jens Axel Søgaard


Posted on the users mailing list.