unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Stephen J. Turnbull" <stephen@xemacs.org>
To: emacs-devel@gnu.org
Subject: Re: DSO-style DSOs (this is NOT an FFI!)
Date: Thu, 10 Oct 2013 13:36:25 +0900	[thread overview]
Message-ID: <87pprdivxy.fsf@uwakimon.sk.tsukuba.ac.jp> (raw)
In-Reply-To: <87wqllsyr0.fsf@flea.lifelogs.com>

Ted Zlatanov writes:

 > DH> As for accidental corruption, you can at least protect your Lisp_Objects
 > DH> by controlling how you copy data into and out of them.

DSOs are no different from any other C code as far as data corruption
goes.  You can't do anything more, and shouldn't do less, than you
could do if the code were linked into Emacs at build time.  The advice
is "be a good Emacs C-level programmer, and you'll be OK."

The only reasonable restrictions are:

(1) Initialize the module with

    if (this_module_max_gpl < this_emacs_min_gpl) launch_lawyers();

(if this_module_max_gpl is undefined, the link will fail, which is the
desired outcome :-).

(2)  callbacks into Emacs must refer to symbols obtained from
     intern().  You can't call extern functions or reference extern
     variables directly.

The marshalling and unmarshalling implied by (2) needs to be done
anyway because these DSOs are intended to provide Lisp-level
functionality.  (If not, there's no problem.  Ask Eli Z about how
Windows does its "if-available" DLL loading.)  It may as well be done
in the DSO so that intern() is the only rendezvous point needed
between Emacs and the DSO.

 > Moreover, I was wondering whether the risk is acceptable.

If it's not, the implications for using any Emacs coded in C are,
well, *severe*. ;-)  (The "maybe we're loading non-GPL 3d-party code
unknowingly" risk is an exception, of course.  That's irrelevant to
language though -- I've always wondered why non-GPL DSOs are a risk
and non-GPL Lisp isn't.  But let's not go there.... :-)

 > The other extreme is to have some protocol to externally executed
 > modules so there's no chance of corruption; it's very inefficient
 > but also much less risky.

That may as well be a true FFI (ie, a way to bind Lisp symbols to
external objects from Lisp).  If it's not, then the module programmer
is writing C, so: GOTO "DSOs are no different...."[1]

Footnotes: 
[1]  Emacs programmers are hardly exempt from the dictum "premature
optimization is the root of all error".  The temptation to short cut
the protocol when writing C will be unbearable for some.




  reply	other threads:[~2013-10-10  4:36 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                   ` DSO-style FFI (was: Emacs crypto use cases) Stefan Monnier
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                                 ` Stephen J. Turnbull [this message]
2013-10-09  1:48                       ` 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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87pprdivxy.fsf@uwakimon.sk.tsukuba.ac.jp \
    --to=stephen@xemacs.org \
    --cc=emacs-devel@gnu.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 public inbox

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

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 read-only IMAP folder(s) and NNTP newsgroup(s).