caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Marcin 'Qrczak' Kowalczyk" <qrczak@knm.org.pl>
To: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Re: Common IO structure
Date: Wed, 05 May 2004 17:48:18 +0200	[thread overview]
Message-ID: <1083772098.5228.32.camel@qrnik> (raw)
In-Reply-To: <1083744695.20722.1056.camel@pelican.wigram>

W liście z śro, 05-05-2004, godz. 18:11 +1000, skaller napisał:

> has been built into Felix as an initial step
> in Felix being able to process C library header
> files *directly* without binding specifications
> or use of an external tool like SWIG."

I don't believe it's possible to automatically generate a reasonable
binding to a C library, given only its headers. Except very simple
libraries.

I've recently make a binding between my language and Python. I'm very
happy with the result, objects are automatically wrapped or unwrapped or
converted, but it would not be impossible to generate this automatically,
treating Python as a C library (which it is).

One thing which is enough to prevent this is Python objects' reference
counts. Of course a good binding must integrate this with garbage
collection. Each Python API function is documented whether it steals
a reference to arguments (rare) or not, and whether it returns a new
reference or not (it often doesn't return a new reference when it always
returns a subobject of another object). This is only explained in the
documentation, so no automatic tool will handle that.

Other than that, it's a non-trivial work to match the conventions, e.g.
let Python sequences fulfil sequence protocols in my language and vice
versa.

Even the simpler thing, converting types, is not easy. A tool will not
guess that I want to automatically convert Python ints and longs into
INTs in my language, and vice versa; they use entirely different
representation of bignums, so a meaningful conversion must be
implemented manually. And it will not guess how to match mixed
ISO-8859-1 / UTF-32 strings in my language with mixed local byte
encoding / UTF-16-or-32 strings in Python. It will not create a Python
type which wraps arbitrary objects of my language, nor vice versa.
Especially when the objects should translate arguments when they are
applied, and translate attribute access. And a tool will not handle
translation of exceptions, such thatthey are automatically propagated
with appropriate wrapping and unwrapping.

But when I finally manually did all this (it took a couple of days;
well, it's not completely finished yet), I got a Gtk+ interface for my
language completely for free, because someone once wrapped Gtk+ for
Python. And similarly many other Python libraries are now directly
usable.

An API expressed in Python, as opposed to an API in C, is possible to
be translated into another language quite well even with no hand-written
description. Perhaps many libraries would be somewhat simpler to bind to
than the Python API, but I don't believe in an automatic tool for C
libraries. Too many issues are visible only in the documentation; it's
not possible to know how to map a void* argument.

> It took 4 hours ONLY to complete the repackaging
> and Cil's frontc parsed the (huge and arcane)
> gtk+2.0 header without an error, pretty printing
> the parse tree in a neat format.

Ok, parsed. Then what?

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak@knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2004-05-05 15:48 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-03  6:12 Vladimir N. Silyaev
2004-05-04 21:31 ` Benjamin Geer
2004-05-04 22:59   ` Yamagata Yoriyuki
2004-05-05  8:11     ` skaller
2004-05-05 15:48       ` Marcin 'Qrczak' Kowalczyk [this message]
2004-05-05 19:28         ` skaller
2004-05-05 17:33     ` Vladimir N. Silyaev
2004-05-05 17:31   ` Vladimir N. Silyaev
2004-05-07 22:11     ` Benjamin Geer
2004-05-08  7:29       ` Vladimir N. Silyaev
2004-05-09 17:35         ` Benjamin Geer
  -- strict thread matches above, loose matches on Subject: below --
2004-04-24  9:28 [Caml-list] [ANN] The Missing Library Nicolas Cannasse
2004-04-25  8:56 ` Common IO structure (was Re: [Caml-list] [ANN] The Missing Library) Yamagata Yoriyuki
2004-04-25 11:54   ` Gerd Stolpmann
2004-04-26 14:53     ` [Caml-list] Re: Common IO structure Yamagata Yoriyuki
2004-04-26 21:02       ` Gerd Stolpmann
2004-04-25 19:42   ` Common IO structure (was Re: [Caml-list] [ANN] The Missing Library) Nicolas Cannasse
2004-04-26 13:16     ` [Caml-list] Re: Common IO structure Yamagata Yoriyuki
2004-04-26 13:53       ` Jacques GARRIGUE
2004-04-26 14:26         ` Nicolas Cannasse
2004-04-28  6:52           ` Jacques GARRIGUE
2004-04-26 14:23       ` Nicolas Cannasse
2004-04-26 14:55         ` skaller
2004-04-26 15:26         ` Yamagata Yoriyuki
2004-04-26 19:28           ` Nicolas Cannasse
2004-04-26 20:56             ` Gerd Stolpmann
2004-04-26 21:14               ` John Goerzen
2004-04-26 22:32                 ` Gerd Stolpmann
2004-04-26 21:52               ` Benjamin Geer
2004-04-27 16:00               ` Yamagata Yoriyuki
2004-04-27 21:51                 ` Gerd Stolpmann
2004-04-27 19:08               ` Nicolas Cannasse
2004-04-27 22:22                 ` Gerd Stolpmann
2004-04-28  7:42                   ` Nicolas Cannasse
2004-04-29 10:13                 ` Yamagata Yoriyuki
2004-04-27 15:43             ` Yamagata Yoriyuki
2004-04-27 16:17               ` Nicolas Cannasse
2004-04-27 16:58                 ` Yamagata Yoriyuki
2004-04-27 23:35                   ` Benjamin Geer
2004-04-28  3:44                     ` John Goerzen
2004-04-28 13:01                       ` Richard Jones
2004-04-28 21:30                       ` Benjamin Geer
2004-04-28 21:44                         ` John Goerzen
2004-04-28 22:41                           ` Richard Jones
2004-04-29 11:51                             ` Benjamin Geer
2004-04-29 12:03                               ` Richard Jones
2004-04-29 15:16                                 ` Benjamin Geer
2004-04-29 10:27                           ` Yamagata Yoriyuki
2004-04-29 13:03                             ` John Goerzen
2004-04-29 13:40                               ` Yamagata Yoriyuki
2004-04-29 14:02                                 ` John Goerzen
2004-04-29 15:31                                   ` Yamagata Yoriyuki
2004-04-29 17:31                                     ` james woodyatt
2004-04-29 23:53                                       ` Benjamin Geer
2004-04-30  4:10                                         ` james woodyatt
2004-04-29 11:23                           ` Benjamin Geer
2004-04-29 12:23                             ` Richard Jones
2004-04-29 15:10                               ` Benjamin Geer
2004-04-29 15:35                                 ` John Goerzen
2004-04-29 15:46                                   ` Benjamin Geer
2004-04-29 15:58                                     ` Richard Jones
2004-04-29 20:41                                     ` John Goerzen
2004-04-29 22:35                                       ` Benjamin Geer
2004-05-01 14:37                               ` Brian Hurt
2004-04-29 13:23                             ` John Goerzen
2004-04-29 14:12                               ` John Goerzen
2004-04-29 15:37                               ` Benjamin Geer
2004-04-28  7:05                     ` Nicolas Cannasse
2004-04-28  0:20                   ` skaller
2004-04-28  3:39                   ` John Goerzen
2004-04-28 13:04                   ` Richard Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1083772098.5228.32.camel@qrnik \
    --to=qrczak@knm.org.pl \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).