On Sat, Sep 12, 2015 at 10:=
42 PM, Stefan Monnier
<monnier@i=
ro.umontreal.ca> wrote:
> Can you give us more details about you mean by the above.
> Are you talking about how to handle things like calls to Fsignal, or t=
o
> Fthrow, or how to provide access to unwind-protect and condition-case =
in
> to the module's?
The case where a module calls an emacs function that ends up calling
signal/error. I don't know enough about how signaling and
unwind-protect work. It's just black stack magic for me right now :)
They use longjmp, which doesn't wo=
rk in modules. Your implementation needs to make sure that no longjmp ever =
escapes to module code, i.e. that none of the stackframes skipped by longjm=
p can lie inside a module. See what Daniel wrote above:
"When Emacs calls a module function, the current thread's pe=
nding-error
flag will be clear.=C2=A0 When that module returns to=
Emacs, if the
thread's pending-error flag is set, Emacs sign=
als the condition
corresponding to the current thread's error=
information.
When the module calls an Emacs routi=
ne that would ordinarily signal,
Emacs catches the signal at the =
stack frame just before control flow
would return to the module, =
sets the pending-error flag, and returns
to the module normally.&=
quot;
=C2=A0
I think we just need to implement funcall (from the module API) like this:<=
br>
=C2=A0 =C2=A0 global error =3D 0
=C2=A0 =C2=A0 module_funcall(fun, args):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 // wrap (protect?) this with the right code
=C2=A0 =C2=A0 =C2=A0 =C2=A0 // - to keep the control
=C2=A0 =C2=A0 =C2=A0 =C2=A0 // - set ret to nil and error to 1 in case of e=
rror
Here you probably need to call bot=
h internal_catch and internal_condition_case.
=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D Ffuncall(fun, args)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return ret
The error is accessible via error_get(), error_clear() and
error_check() in the module API. error_get() is currently redundant
with error_check() unless we decide to return detailed errors.
What do you mean with 'detailed er=
rors'? At a minimum users need access to the handler type (condition-ca=
se or catch), the catch tag, the error symbol, and the error data. Most lik=
ely the stacktrace should also be provided.
=C2=A0
I didn't think about the case where a module calls Fthrow but my guess<=
br>
is it will just work.
It uses a differe=
nt handler type and therefore will probably not work out of the box unless =
you call internal_catch.
=C2=A0
> Indeed it's not guaranteed at all.=C2=A0 It's not even guarant=
eed that when you
> call the GC, all dead objects will be collected.
Ok. Finalizers are better than nothing I guess.
Why would you need finalizers at all? =
There are usually wrong and useless in languages with nondeterministic garb=
age collection.=C2=A0