Re: [racket-users] Using ffi/unsafe/alloc

2018-01-25 Thread Konrad Hinsen
Hi Dmitry and Matthew, Thanks for your suggestions, which, although quite different, turned out to be both useful for me. As you can imagine, my real C API is a lot more complicated. There are dependencies between allocated memory blocks, i.e. freeing one can invalidate another one. More fine-grai

Re: [racket-users] Using ffi/unsafe/alloc

2018-01-24 Thread Matthew Flatt
I think I haven't run into this because `r` and `foo` are usually combined into one value that's more Rackety. Maybe `allocator` should have a `get-result` optional argument similar to `deallocator`. Meanwhile: ;; Not exported: (define-fooapi make_foo (_fun (foo : (_ptr o _foo)) ->

Re: [racket-users] Using ffi/unsafe/alloc

2018-01-24 Thread Dmitry Pavlov
Konrad, I would create a wrapper like this: (define-fooapi make-foo (_fun (foo : (_ptr o _foo)     -> (r : _int)     -> (if r (begin (register-finalizer-and-custodian-shutdown foo destroy-foo) foo)     (error "can not make foo"))) Regards, Dmitry On 01/2