C-FFI, results, conditions

Bruce Mitchener <[email protected]>
Newsgroups gmane.comp.lang.dylan.gwydion.devel
Message-ID <CA+esKjM=pV9T3c5HQgwCsfCo78pLLfmm1AX0itEtmgcZEtZXKA@mail.gmail.com>
Hello all (and especially housel),

When wrapping an API with C-FFI (either directly or via melange generating
C-FFI), I often run into a situation where I have a function that returns 0
or an error code.

I'd like to be able to have the C-FFI know how to pass the result to a
mapping function which would check for non-zero and then signal a condition
as appropriate.  This function would probably be inline-only in many cases,
but that's probably immaterial.

The alternative is that I effectively do:

    define c-function %bar
      ...
      c-name: "bar";
    end;

    define inline-only function bar (...)
      libfoo-raise-or-return(%bar(...))
    end;

And that's pretty verbose and annoying, when I could instead do something
like:

    define c-function bar
      result-handler: libfoo-raise-or-return;
    end;

I'm not sure how to actually implement this entirely yet
in sources/dfmc/c-ffi/c-function-macro.dylan ...

Looking at C-FFI and UFFI for Common Lisp as well as SWIG, none of them
appear to support this.

Thoughts? Worthwhile or not?

 - Bruce

_______________________________________________
hackers mailing list
[email protected]
https://lists.opendylan.org/mailman/listinfo/hackers
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.