FFI and immovable pointers for input/output (featuring automatic cropping for picts)

21 views
Skip to first unread message

Jens Axel Søgaard

unread,
Sep 19, 2019, 10:54:05 AM9/19/19
to Racket list
Hi All,

I am working on automatic cropping for picts. Here automatic means the 
pict will be cropped (or extended) to include what will be inked when the pict is drawn.

The function crop/inked seems to work fine (see attached file), but the 
functions in draw/unsage/cairo uses the following for outputs:

(define-fun-syntax _ptr/immobile
  (syntax-id-rules (_ptr/immobile o)
    [(_ptr/immobile o t) (type: _pointer
                                pre:  (malloc t 'atomic-interior)
                                post: (x => (ptr-ref x t)))]))

Since I need both input and output I have used

(_ptr io _double)

but maybe I need to use a version of  _ptr/immobile that also handles io arguments?

If so how can I change the definition of _ptr/immobile.

See attached file for `crop/inked`.

/Jens Axel

crop-and-crop-inked.rkt

Matthew Flatt

unread,
Sep 19, 2019, 11:05:54 AM9/19/19
to Jens Axel Søgaard, Racket list
I don't think you need immobile memory. There are no callbacks to
Racket involved with `cairo_recording_surface_ink_extents`, and you're
not using `#:blocking? #t`, so no memory-moving GC will happen during
the foreign call. That means `_ptr` is fine.

Jens Axel Søgaard

unread,
Sep 19, 2019, 11:12:16 AM9/19/19
to Matthew Flatt, Racket list
Den tor. 19. sep. 2019 kl. 17.05 skrev Matthew Flatt <mfl...@cs.utah.edu>:
I don't think you need immobile memory. There are no callbacks to
Racket involved with `cairo_recording_surface_ink_extents`, and you're
not using `#:blocking? #t`, so no memory-moving GC will happen during
the foreign call. That means `_ptr` is fine.

Great. 

Thanks,
Jens Axel
 
Reply all
Reply to author
Forward
0 new messages