[2016-07-18 21:41] Amirouche Boubekki <amirou...@hypermove.net>
>
> On 2016-07-18 17:17, kact...@gnu.org wrote:
> > From: Dmitry Bogatov <kact...@gnu.org>
> >
> > Document '<foreign-type>' record type and 'define-foreign-type'
> > procedure.
>
> Can you compare this 'foreign-type' library with scheme-bytestructures
> [0]. How
> can both libraries help each other? Work hand in hand?

Seems that 'scheme-bytestructures' can be used to implement something like
`define-foreign-struct', but since it is not currently part of Guile, I, sure,
can't depend on it.

Also, 'parse-c-struct' provides similiar functionality.

> Tell me if I'm wrong but it looks like you have to define validate,
> encode and decode proc for every single structure with no
> helpers.

Not true. Sure, if your conversion is somewhat unusual, you have to
invoke `(define-foreign-type)', but if it conventional, you can use

  - define-foreign-bitmask
  (in future)
  - define-foreign-struct (did not extracted from guile-bash)
  - define-foreign-enumeration
  - define-foreign-opaque
  (last two are really trivial, just I did not needed them for xattr library)

> It seems to me that it's some kind of framework for doing validation
> of static typed procedures which also handles automatic conversion
> between C land and scheme land.  Honestly this is not the kind of
> library I would use, I seldom do input validation when the client of
> my program is a developer. Maybe I'm wrong but IMO dynamic languages
> help that.

Our opinions on validation differs. I think, that foreign function
binding, created by (system foreign declarative) should be as good, as
if written in C. By this I mean, I want to get error message out of
function itself, not from some guts of (system foreign declarative).

> Also based on my small experience of ffi, there is not much
> conversion to do between scheme and C and what's best is to avoid
> any copy which is what does scheme-bytestructures.

(system foreign declarative) provide a way to work with memory with no copy:

        (with-pointer ((memory *--> 1024))
             (foreign-call memory)
          (work-with-bytevector memory))

But take a look at (ice9 xattr) (patches 21-25).

Conversion from Scheme string to `const char *' have O(n) price, but I
prefered natural interface to perfomance. But again, (system foreign
declarative) does not force such choice.

It seems to me, that I responded to every point, but feel free to
refine your question.

-- 
Accept: text/plain, text/x-diff
Accept-Language: eo,en,ru
X-Web-Site: sinsekvu.github.io

Reply via email to