all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Cc: jerry.james@xemacs.org
Subject: DSO-style FFI (was: Emacs crypto use cases)
Date: Tue, 08 Oct 2013 12:35:44 -0400	[thread overview]
Message-ID: <jwvzjqj220k.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87siwcxda7.fsf@flea.lifelogs.com> (Ted Zlatanov's message of "Tue, 08 Oct 2013 06:33:36 -0400")

[ Hi Jerry.  We're interested in adding support for dynamically loading
  C code into Emacs, so I added you on the Cc, hoping you might be able
  to give us some pointers to the XEmacs code, and maybe also some
  guidance of things to watch out for.  ]

> I have no idea how that would work.  Is there an example?

As mentioned, there's the XEmacs implementation as an example.

> And is this anywhere close to usable?

Well, it doesn't exist for Emacs, so you won't be able to use until you
write it.  AFAIK it's been usable for a decade in XEmacs.

> The FFI discussion thread hasn't indicated it.

There's no doubt it would work and it should be fairly flexible and
convenient for the implementer of lib<foo> wrapper.  The main
inconvenients are in the area of imposing the use of a C compiler on the
user, and managing precompiled versions of the code, none of which seem
like reasons to make it "unusable".

> If I'm to be the guinea pig, I'm not excited about it.

No, you'd be the implementor, so you get to make it work well for you.
The guy that everyone after that will say "and finally, thanks to Ted,
we can now link to the new snazzy libquantum and solve all the Elisp
performance problems we had".

> I'll see what I can do with FFI, but this is likely to take a lot of my
> time.  Some help getting started would go a long way.

Start as follows:
- take your lib<foo> wrapper.
- try to compile it outside of Emacs.
- for that you'll need a .h file that declares some functions like
  `defsubr' and probably others to build and analyze Lisp data.
  Ideally, this should not really too much on cpp macros and should not
  make too many assumptions about the existing Emacs implementation, so
  that this .h file doesn't need to change if/when we decide to tweak
  the representation of Elisp data.
- write the .c file that should be linked into Emacs that provides the
  functions declared in the magic .h file.

Now you should be able to build your "Emacs + lib<foo>" by simply
compiling your file and linking it into Emacs (i.e. pretty much like
what you have, except your lib-wrapper doesn't include lisp.h and such
but only the special new .h file you created).

That's step 1.  It should be reasonably easy to do in terms of coding.
The design of the .h file is somewhat delicate, to try and avoid version
problems in the future, but we'll be happy to help along once you have
a first version of a .h.

Step 2: Write code that lets Emacs dynamically load the (compiled)
lib-wrapper code into a running Emacs, rather than having to provide
that lib-wrapper right when you link the `temacs' executable.
That shouldn't be hard either.  One issue will be compatibility of
various kinds of dl_open mechanisms on various OSes, but you should find
lots of help for that here, so the first version can focus on supporting
only GNU/Linux.  The other issue will be to make sure the loaded code is
GPL-compliant; we'll need help here anyway to know exactly what the FSF
wants in this regard but I don't foresee any serious issue.

At that point, you can start distributing your libnettle wrapper outside
of Emacs.  Yay!

Step 3: provide helper infrastructure to distribute packages that use
this new functionality, e.g. teach package.el how to run the C compiler
on that code, stash the resulting compiled object somewhere, fetch
precompiled versions when a C compiler is not available, etc...

As you move forward, chances are more and more people will be motivated
to take on some of the work, so you don't have to do it all yourself.


        Stefan



  parent reply	other threads:[~2013-10-08 16:35 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-06  9:15 GNU Emacs-libnettle-libhogweed integration patch v1 Ted Zlatanov
2013-10-06  9:58 ` bignum support in Emacs with libgmp (was: GNU Emacs-libnettle-libhogweed integration patch v1) Ted Zlatanov
2013-10-06 16:09 ` GNU Emacs-libnettle-libhogweed integration patch v1 Eli Zaretskii
2013-10-06 21:07   ` Ted Zlatanov
2013-10-06 16:51 ` Stefan Monnier
2013-10-06 16:58   ` Eli Zaretskii
2013-10-06 21:19   ` Ted Zlatanov
2013-10-07  4:02     ` Stefan Monnier
2013-10-07 11:41       ` Ted Zlatanov
2013-10-07 22:03         ` Ted Zlatanov
2013-10-07 22:58           ` Stefan Monnier
2013-10-07 23:43             ` Emacs crypto use cases (was: GNU Emacs-libnettle-libhogweed integration patch v1) Ted Zlatanov
2013-10-08  3:02               ` Emacs crypto use cases Stefan Monnier
2013-10-08 10:33                 ` Ted Zlatanov
2013-10-08 13:17                   ` Stephen J. Turnbull
2013-10-08 16:35                   ` Stefan Monnier [this message]
2013-10-08 17:32                     ` DSO-style FFI Tom Tromey
2013-10-08 19:42                       ` Ted Zlatanov
2013-10-08 20:43                         ` Tom Tromey
2013-10-09 23:21                           ` Ted Zlatanov
2013-10-10  8:09                             ` Andreas Schwab
2013-10-08 20:47                         ` Davis Herring
2013-10-09 22:26                           ` Ted Zlatanov
2013-10-09 23:52                             ` Davis Herring
2013-10-10  1:25                               ` Ted Zlatanov
2013-10-10  4:36                                 ` DSO-style DSOs (this is NOT an FFI!) Stephen J. Turnbull
2013-10-09  1:48                       ` DSO-style FFI Stephen J. Turnbull
2013-10-09  2:40                       ` Stefan Monnier
2013-10-12 15:34                         ` Michael Welsh Duggan
2013-10-12 18:55                           ` Stefan Monnier
2013-10-18 13:31                             ` Ted Zlatanov
2013-10-19 14:41                               ` Stefan Monnier
2013-10-19 15:08                               ` Stefan Monnier
2013-10-19 17:33                               ` Andy Moreton
2013-10-19 19:44                                 ` Ted Zlatanov
2013-10-12 23:36                           ` Stephen J. Turnbull
2013-10-08 19:50                     ` Ted Zlatanov

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=jwvzjqj220k.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=jerry.james@xemacs.org \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.