From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Philipp Stephani
These macros need more extensive documentation wrt when each one is
needed and why.
I tried to "reverse-engineer" that information from its current u= sage,
and my best hypothesis is that they should be used if a functions
calls some Emacs function that could potentially signal an error or
throw.=C2=A0 For example, module_make_function calls list4, module_funcall<= br> calls Ffuncall, module_copy_string_contents calls ENCODE_UTF_8, etc.
Is that correct?
If it is, then I have a few questions:
=C2=A0 . Why don't some functions use any of these macros, although the= y do
=C2=A0 =C2=A0 call Emacs functions?=C2=A0 Examples include module_make_inte= ger (calls
=C2=A0 =C2=A0 make_number), and module_make_user_ptr (calls make_user_ptr).=
=C2=A0 . It seems like emacs-module.c assumes something about certain Emacs=
=C2=A0 =C2=A0 functions, and based on that decides not to use these macros = even
=C2=A0 =C2=A0 when calling those Emacs functions.=C2=A0 For example, module= _vec_get
=C2=A0 =C2=A0 calls ASIZE and AREF, but doesn't use the MODULE_HANDLE_*= macros.
=C2=A0 =C2=A0 Evidently, it assumes that neither ASIZE nor AREF will ever s= ignal
=C2=A0 =C2=A0 or throw.=C2=A0 But isn't that a fragile assumption?=C2= =A0 The
=C2=A0 =C2=A0 implementation of internal Emacs functions is subject to chan= ge
=C2=A0 =C2=A0 without notice, and it would be a maintenance burden to have = to
=C2=A0 =C2=A0 analyze upon each such change whether emacs-module.c needs so= me
=C2=A0 =C2=A0 augmentation.
=C2=A0 . How to decide whether to use MODULE_HANDLE_SIGNAL or
=C2=A0 =C2=A0 MODULE_HANDLE_THROW (or both)?=C2=A0 Again, it looks like the= current
=C2=A0 =C2=A0 code simply assumes specific knowledge about certain Emacs
=C2=A0 =C2=A0 functions, knowledge which again can become outdated a year o= r a
=C2=A0 =C2=A0 month or a day from now.
So bottom line (again assuming my guesses above are correct), I'd
suggest to use these macros in all the emacs-module.c functions,Yes, your thinking is correct. I used these macros ba= sed on the current implementation. If this is too brittle, then these macro= s should indeed be added to all environment functions (i.e. those functions= that gets directly called from module code).I left them out pur= ely for performance reasons: these macros both call setjmp and possibly mal= loc, which can incur a significant penalty, especially for environment func= tions that are very small otherwise (e.g. eq or is_not_nil).=C2= =A0and
in fact come up with a wrapper around calls to Emacs functions and
macros that will catch signals and throws, and make a point of calling
each such function/macro through that wrapper.
My first approach was to create such a= wrapper function, but I quickly realized that it's too much of a hassl= e. Existing wrapper functions are e.g. internal_condition_case in eval.c, b= ut you'd need one wrapper function for each signature, which quickly re= sults in excessive code duplication. Therefore I used the macros.