summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/lib/pluginlib_exit.h31
1 files changed, 20 insertions, 11 deletions
diff --git a/apps/plugins/lib/pluginlib_exit.h b/apps/plugins/lib/pluginlib_exit.h
index 1bad12aed2..6cded9d56f 100644
--- a/apps/plugins/lib/pluginlib_exit.h
+++ b/apps/plugins/lib/pluginlib_exit.h
@@ -29,17 +29,26 @@
29#include <setjmp.h> 29#include <setjmp.h>
30#endif 30#endif
31 31
32/* PLUGINLIB_EXIT_INIT needs to be placed as the first line in plugin_start */ 32#define _PLUGINLIB_EXIT_INIT(atexit) switch(setjmp(__exit_env)) \
33#define PLUGINLIB_EXIT_INIT switch(setjmp(__exit_env)) \ 33 { \
34 { \ 34 case 1: \
35 case 1: \ 35 atexit \
36 return PLUGIN_OK; \ 36 return PLUGIN_OK; \
37 case 2: \ 37 case 2: \
38 return PLUGIN_ERROR; \ 38 atexit \
39 case 0: \ 39 return PLUGIN_ERROR; \
40 default: \ 40 case 0: \
41 break; \ 41 default: \
42 } 42 break; \
43 }
44
45/* Either PLUGINLIB_EXIT_INIT or PLUGINLIB_EXIT_INIT_ATEXIT needs to be placed
46 * as the first line in plugin_start. The _ATEXIT version will call the named
47 * no-argument function when exit() is called before exiting the plugin, to
48 * allow for cleanup.
49 */
50#define PLUGINLIB_EXIT_INIT _PLUGINLIB_EXIT_INIT()
51#define PLUGINLIB_EXIT_INIT_ATEXIT(atexit) _PLUGINLIB_EXIT_INIT(atexit();)
43 52
44extern jmp_buf __exit_env; 53extern jmp_buf __exit_env;
45#define exit(status) longjmp(__exit_env, status != 0 ? 2 : 1) 54#define exit(status) longjmp(__exit_env, status != 0 ? 2 : 1)