diff options
| author | Philipp Stephani | 2017-06-04 19:34:22 +0200 |
|---|---|---|
| committer | Philipp Stephani | 2017-06-04 19:50:52 +0200 |
| commit | 66da3f4afa53e5c5cfab17ca03a13a0d65083ffb (patch) | |
| tree | b045d1aa2009d66502f83ef5d599d0d94294acb9 | |
| parent | d37201722e2151df1f6b6fa1e2f33b5f91e27e03 (diff) | |
| download | emacs-66da3f4afa53e5c5cfab17ca03a13a0d65083ffb.tar.gz emacs-66da3f4afa53e5c5cfab17ca03a13a0d65083ffb.zip | |
Support quitting in modules
The idea is that modules should call env->should_quit from time to
time and return as quickly as possible if it returns true.
* src/emacs-module.c (module_should_quit): New module function.
(initialize_environment): Use it.
(funcall_module): Process potential pending quit.
* src/eval.c (maybe_quit): Add reference to module_should_quit.
| -rw-r--r-- | src/emacs-module.c | 15 | ||||
| -rw-r--r-- | src/emacs-module.h | 3 | ||||
| -rw-r--r-- | src/eval.c | 5 |
3 files changed, 22 insertions, 1 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c index f2efc83d257..e6a109b1962 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c | |||
| @@ -28,6 +28,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 28 | #include "lisp.h" | 28 | #include "lisp.h" |
| 29 | #include "dynlib.h" | 29 | #include "dynlib.h" |
| 30 | #include "coding.h" | 30 | #include "coding.h" |
| 31 | #include "keyboard.h" | ||
| 31 | #include "syssignal.h" | 32 | #include "syssignal.h" |
| 32 | 33 | ||
| 33 | #include <intprops.h> | 34 | #include <intprops.h> |
| @@ -612,6 +613,15 @@ module_vec_size (emacs_env *env, emacs_value vec) | |||
| 612 | return ASIZE (lvec); | 613 | return ASIZE (lvec); |
| 613 | } | 614 | } |
| 614 | 615 | ||
| 616 | /* This function should return true if and only if maybe_quit would do | ||
| 617 | anything. */ | ||
| 618 | static bool | ||
| 619 | module_should_quit (emacs_env *env) | ||
| 620 | { | ||
| 621 | MODULE_FUNCTION_BEGIN_NO_CATCH (false); | ||
| 622 | return (! NILP (Vquit_flag) && NILP (Vinhibit_quit)) || pending_signals; | ||
| 623 | } | ||
| 624 | |||
| 615 | 625 | ||
| 616 | /* Subroutines. */ | 626 | /* Subroutines. */ |
| 617 | 627 | ||
| @@ -687,6 +697,10 @@ funcall_module (Lisp_Object function, ptrdiff_t nargs, Lisp_Object *arglist) | |||
| 687 | 697 | ||
| 688 | eassert (&priv == pub.private_members); | 698 | eassert (&priv == pub.private_members); |
| 689 | 699 | ||
| 700 | /* Process the quit flag first, so that quitting doesn't get | ||
| 701 | overridden by other non-local exits. */ | ||
| 702 | maybe_quit (); | ||
| 703 | |||
| 690 | switch (priv.pending_non_local_exit) | 704 | switch (priv.pending_non_local_exit) |
| 691 | { | 705 | { |
| 692 | case emacs_funcall_exit_return: | 706 | case emacs_funcall_exit_return: |
| @@ -916,6 +930,7 @@ initialize_environment (emacs_env *env, struct emacs_env_private *priv) | |||
| 916 | env->vec_set = module_vec_set; | 930 | env->vec_set = module_vec_set; |
| 917 | env->vec_get = module_vec_get; | 931 | env->vec_get = module_vec_get; |
| 918 | env->vec_size = module_vec_size; | 932 | env->vec_size = module_vec_size; |
| 933 | env->should_quit = module_should_quit; | ||
| 919 | Vmodule_environments = Fcons (make_save_ptr (env), Vmodule_environments); | 934 | Vmodule_environments = Fcons (make_save_ptr (env), Vmodule_environments); |
| 920 | } | 935 | } |
| 921 | 936 | ||
diff --git a/src/emacs-module.h b/src/emacs-module.h index d9eeeabec3f..b8bf2ed2d5f 100644 --- a/src/emacs-module.h +++ b/src/emacs-module.h | |||
| @@ -185,6 +185,9 @@ struct emacs_env_25 | |||
| 185 | emacs_value val); | 185 | emacs_value val); |
| 186 | 186 | ||
| 187 | ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vec); | 187 | ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vec); |
| 188 | |||
| 189 | /* Returns whether a quit is pending. */ | ||
| 190 | bool (*should_quit) (emacs_env *env); | ||
| 188 | }; | 191 | }; |
| 189 | 192 | ||
| 190 | /* Every module should define a function as follows. */ | 193 | /* Every module should define a function as follows. */ |
diff --git a/src/eval.c b/src/eval.c index 8aa33a11282..ef961046bcf 100644 --- a/src/eval.c +++ b/src/eval.c | |||
| @@ -1474,7 +1474,10 @@ process_quit_flag (void) | |||
| 1474 | If quit-flag is set to `kill-emacs' the SIGINT handler has received | 1474 | If quit-flag is set to `kill-emacs' the SIGINT handler has received |
| 1475 | a request to exit Emacs when it is safe to do. | 1475 | a request to exit Emacs when it is safe to do. |
| 1476 | 1476 | ||
| 1477 | When not quitting, process any pending signals. */ | 1477 | When not quitting, process any pending signals. |
| 1478 | |||
| 1479 | If you change this function, also adapt module_should_quit in | ||
| 1480 | emacs-module.c. */ | ||
| 1478 | 1481 | ||
| 1479 | void | 1482 | void |
| 1480 | maybe_quit (void) | 1483 | maybe_quit (void) |