emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dynamic loading progress


From: Davis Herring
Subject: Re: Dynamic loading progress
Date: Tue, 29 Sep 2015 15:04:35 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110717 Lanikai/3.1.11

> I don't see what else can possibly work, since if you set a condition
> case in the API calling into the module (ie, in [main Lisp]), you've
> already hosed the called code by the time you handle it.

What if we avoid the longjmp call rather than catching it?  Define a
(thread-local) signal-raising hook which is also a specpdl barrier.

A C++ client, for example, could write (perhaps with some added 'extern
"C"')

namespace {
  struct emacs_exception : std::exception {
    emacs_exception(emacs_value e,emacs_value d) : error(e),data(d) {}
    emacs_value error,data;
  };

  void die(emacs_value error,emacs_value data) {
    throw emacs_exception(error,data);
  }

  emacs_value my_subr(emacs_env *env,int nargs,emacs_value args[]) {
    env->error_handle(env,die);  // creates barrier
    try {
      std::vector</*...*/> data; // to be cleaned up
      env->funcall(env,/*...*/);
    } catch(const emacs_exception &e) {
      // various variables assumed to be already obtained elsewhere
      if(eq(e.error,Qfile_error)) {
        /* handle file-not-found */;
        return Qnil;
      } else env->error_signal(env,e.error,e.data);
    }
    return Qt;
  }
}

Then Fsignal/Fthrow can do its cleanup down to the barrier, then call
the hook.  The exception unwinds the stack back into the C++ module,
does appropriate destructor things, and then is caught before the module
returns to Emacs.  There, the module can choose to return normally (thus
acting like condition-case) or propagate the error (thus having its
destructors act like unwind-protect).

Here we have the overhead of error_handle only once per call from Emacs
into the module rather than on each call from the module into Emacs
(probably larger).  We might be able to avoid even that by putting the
handler into the emacs_env, but that would lose the flexible barrier
placement and presumably Fsignal still has to consult a how-to-signal
variable that would have to be set at least once per Emacs->module call.

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]