Re: [AD] mzscheme bindings in svn |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: Coordination of admins/developers of the game programming library Allegro <alleg-developers@xxxxxxxxxx>
- Subject: Re: [AD] mzscheme bindings in svn
- From: Jon Rafkind <workmin@xxxxxxxxxx>
- Date: Sat, 28 Apr 2007 12:50:32 -0400
Attached is a patch that more or less does this. Calling
enable_signal_handlers/disable_signal_handlers() will result in
calling enable_signals() for each driver listed in the system_list if
system_driver has not been initialized, otherwise it just calls
system_driver->enable_signals(). This is done because you need to
enable/disable signal handlers before the system driver init() method
is called so there is no way to know which system driver is being used
until allegro_init() finds the right driver.
forgot to initialize system_none with a dummy function. or should I be
checking for NULL?
Index: src/beos/bsystem.c
===================================================================
--- src/beos/bsystem.c (revision 7850)
+++ src/beos/bsystem.c (working copy)
@@ -64,5 +64,7 @@
NULL, // AL_METHOD(_DRIVER_INFO *, keyboard_drivers, (void));
NULL, // AL_METHOD(_DRIVER_INFO *, mouse_drivers, (void));
NULL, // AL_METHOD(_DRIVER_INFO *, joystick_drivers, (void));
- NULL // AL_METHOD(_DRIVER_INFO *, timer_drivers, (void));
+ NULL, // AL_METHOD(_DRIVER_INFO *, timer_drivers, (void));
+ NULL, // AL_METHOD(void, enable_signals, (void));
+ NULL // AL_METHOD(void, disable_signals, (void));
};
Index: src/dos/dsystem.c
===================================================================
--- src/dos/dsystem.c (revision 7850)
+++ src/dos/dsystem.c (working copy)
@@ -67,7 +67,6 @@
static int console_virgin = TRUE;
-
/* previous signal handlers */
static void *old_sig_abrt = NULL;
static void *old_sig_fpe = NULL;
@@ -99,6 +98,8 @@
static void sys_dos_set_palette(AL_CONST struct RGB *p, int from, int to, int vsync);
static void sys_dos_get_gfx_safe_mode(int *driver, struct GFX_MODE *mode);
static void sys_dos_yield_timeslice(void);
+static void sys_dos_enable_signal_handlers(void);
+static void sys_dos_disable_signal_handlers(void);
#ifdef ALLEGRO_DJGPP
static void sys_dos_assert(AL_CONST char *msg);
@@ -148,11 +149,15 @@
NULL, /* keyboard_drivers */
NULL, /* mouse_drivers */
NULL, /* joystick_drivers */
- NULL /* timer_drivers */
+ NULL, /* timer_drivers */
+ sys_dos_enable_signal_handlers,
+ sys_dos_disable_signal_handlers
};
+/* install signal handlers by default */
+static int _al_dos_install_signal_handlers = 1;
+
-
/* list of available system drivers */
_DRIVER_INFO _system_driver_list[] =
{
@@ -162,7 +167,16 @@
};
+static void sys_dos_enable_signal_handlers(void)
+{
+ _al_dos_install_signal_handlers = 1;
+}
+static void sys_dos_disable_signal_handlers(void)
+{
+ _al_dos_install_signal_handlers = 0;
+}
+
/* signal_handler:
* Used to trap various signals, to make sure things get shut down cleanly.
*/
@@ -323,13 +337,14 @@
/* detect CRTC register address */
_vga_regs_init();
- /* install emergency-exit signal handlers */
- old_sig_abrt = signal(SIGABRT, signal_handler);
- old_sig_fpe = signal(SIGFPE, signal_handler);
- old_sig_ill = signal(SIGILL, signal_handler);
- old_sig_segv = signal(SIGSEGV, signal_handler);
- old_sig_term = signal(SIGTERM, signal_handler);
- old_sig_int = signal(SIGINT, signal_handler);
+ if ( _al_dos_install_signal_handlers ){
+ /* install emergency-exit signal handlers */
+ old_sig_abrt = signal(SIGABRT, signal_handler);
+ old_sig_fpe = signal(SIGFPE, signal_handler);
+ old_sig_ill = signal(SIGILL, signal_handler);
+ old_sig_segv = signal(SIGSEGV, signal_handler);
+ old_sig_term = signal(SIGTERM, signal_handler);
+ old_sig_int = signal(SIGINT, signal_handler);
#ifdef SIGKILL
old_sig_kill = signal(SIGKILL, signal_handler);
@@ -342,6 +357,7 @@
#ifdef SIGTRAP
old_sig_trap = signal(SIGTRAP, signal_handler);
#endif
+ }
return 0;
}
@@ -355,12 +371,13 @@
{
_dos_irq_exit();
- signal(SIGABRT, old_sig_abrt);
- signal(SIGFPE, old_sig_fpe);
- signal(SIGILL, old_sig_ill);
- signal(SIGSEGV, old_sig_segv);
- signal(SIGTERM, old_sig_term);
- signal(SIGINT, old_sig_int);
+ if ( _al_dos_install_signal_handlers ){
+ signal(SIGABRT, old_sig_abrt);
+ signal(SIGFPE, old_sig_fpe);
+ signal(SIGILL, old_sig_ill);
+ signal(SIGSEGV, old_sig_segv);
+ signal(SIGTERM, old_sig_term);
+ signal(SIGINT, old_sig_int);
#ifdef SIGKILL
signal(SIGKILL, old_sig_kill);
@@ -373,6 +390,7 @@
#ifdef SIGTRAP
signal(SIGTRAP, old_sig_trap);
#endif
+ }
}
Index: src/linux/lsystem.c
===================================================================
--- src/linux/lsystem.c (revision 7850)
+++ src/linux/lsystem.c (working copy)
@@ -47,6 +47,8 @@
static void sys_linux_message (AL_CONST char *msg);
static void sys_linux_save_console_state(void);
static void sys_linux_restore_console_state(void);
+static void sys_linux_enable_signal_handlers(void);
+static void sys_linux_disable_signal_handlers(void);
/* driver list getters */
@@ -114,13 +116,26 @@
get_keyboard_driver_list,
get_mouse_driver_list,
get_joystick_driver_list,
- get_timer_driver_list
+ get_timer_driver_list,
+ sys_linux_enable_signal_handlers,
+ sys_linux_disable_signal_handlers
};
-
int __al_linux_have_ioperms = 0;
+/* install signal handlers by default */
+static int _al_linux_install_signal_handlers = 1;
+static void sys_linux_disable_signal_handlers(void)
+{
+ _al_linux_install_signal_handlers = 0;
+}
+
+static void sys_linux_enable_signal_handlers(void)
+{
+ _al_linux_install_signal_handlers = 1;
+}
+
typedef RETSIGTYPE (*temp_sighandler_t)(int);
static temp_sighandler_t old_sig_abrt, old_sig_fpe, old_sig_ill, old_sig_segv, old_sig_term, old_sig_int, old_sig_quit;
@@ -199,16 +214,19 @@
if (__al_linux_init_vga_helpers()) return -1;
#endif
- /* Install emergency-exit signal handlers */
- old_sig_abrt = signal(SIGABRT, signal_handler);
- old_sig_fpe = signal(SIGFPE, signal_handler);
- old_sig_ill = signal(SIGILL, signal_handler);
- old_sig_segv = signal(SIGSEGV, signal_handler);
- old_sig_term = signal(SIGTERM, signal_handler);
- old_sig_int = signal(SIGINT, signal_handler);
+
+ if ( _al_linux_install_signal_handlers ){
+ /* Install emergency-exit signal handlers */
+ old_sig_abrt = signal(SIGABRT, signal_handler);
+ old_sig_fpe = signal(SIGFPE, signal_handler);
+ old_sig_ill = signal(SIGILL, signal_handler);
+ old_sig_segv = signal(SIGSEGV, signal_handler);
+ old_sig_term = signal(SIGTERM, signal_handler);
+ old_sig_int = signal(SIGINT, signal_handler);
#ifdef SIGQUIT
- old_sig_quit = signal(SIGQUIT, signal_handler);
+ old_sig_quit = signal(SIGQUIT, signal_handler);
#endif
+ }
/* Initialise async event processing */
if (__al_linux_bgman_init()) {
@@ -230,16 +248,18 @@
/* shut down asynchronous event processing */
__al_linux_bgman_exit();
- /* remove emergency exit signal handlers */
- signal(SIGABRT, old_sig_abrt);
- signal(SIGFPE, old_sig_fpe);
- signal(SIGILL, old_sig_ill);
- signal(SIGSEGV, old_sig_segv);
- signal(SIGTERM, old_sig_term);
- signal(SIGINT, old_sig_int);
+ if ( _al_linux_install_signal_handlers ){
+ /* remove emergency exit signal handlers */
+ signal(SIGABRT, old_sig_abrt);
+ signal(SIGFPE, old_sig_fpe);
+ signal(SIGILL, old_sig_ill);
+ signal(SIGSEGV, old_sig_segv);
+ signal(SIGTERM, old_sig_term);
+ signal(SIGINT, old_sig_int);
#ifdef SIGQUIT
- signal(SIGQUIT, old_sig_quit);
+ signal(SIGQUIT, old_sig_quit);
#endif
+ }
/* shut down VGA helpers */
#ifdef ALLEGRO_LINUX_VGA
Index: src/qnx/qsystem.c
===================================================================
--- src/qnx/qsystem.c (revision 7850)
+++ src/qnx/qsystem.c (working copy)
@@ -46,8 +46,9 @@
static void qnx_sys_yield_timeslice(void);
static int qnx_sys_desktop_color_depth(void);
static int qnx_sys_get_desktop_resolution(int *width, int *height);
+static void qnx_sys_enable_signal_handlers(void);
+static void qnx_sys_disable_signal_handlers(void);
-
SYSTEM_DRIVER system_qnx =
{
SYSTEM_QNX,
@@ -89,15 +90,19 @@
NULL, /* AL_METHOD(_DRIVER_INFO *, mouse_drivers, (void)); */
NULL, /* AL_METHOD(_DRIVER_INFO *, joystick_drivers, (void)); */
NULL, /* AL_METHOD(_DRIVER_INFO *, timer_drivers, (void)); */
+ qnx_sys_enable_signal_handlers,
+ qnx_sys_disable_signal_handlers
};
-
/* system globals */
PtWidget_t *ph_window = NULL;
pthread_mutex_t qnx_event_mutex;
pthread_mutex_t qnx_gfx_mutex;
+/* use signal handlers by default */
+static int _al_qnx_install_signal_handlers = 1;
+
#define EVENT_SIZE (sizeof(PhEvent_t) + 1000)
static PhEvent_t *ph_event = NULL;
@@ -120,14 +125,22 @@
static RETSIGTYPE (*old_sig_quit)(int num);
#endif
+static void qnx_sys_enable_signal_handlers(void)
+{
+ _al_qnx_install_signal_handlers = 1;
+}
+static void qnx_sys_disable_signal_handlers(void)
+{
+ _al_qnx_install_signal_handlers = 0;
+}
/* qnx_signal_handler:
* Used to trap various signals, to make sure things get shut down cleanly.
*/
static RETSIGTYPE qnx_signal_handler(int num)
{
- if (_unix_bg_man->interrupts_disabled()) {
+ if (_al_qnx_install_signal_handlers && _unix_bg_man->interrupts_disabled()) {
/* Can not shutdown X-Windows, restore old signal handlers and slam the door. */
signal(SIGABRT, old_sig_abrt);
signal(SIGFPE, old_sig_fpe);
@@ -340,17 +353,19 @@
_unix_guess_file_encoding();
- /* install emergency-exit signal handlers */
- old_sig_abrt = signal(SIGABRT, qnx_signal_handler);
- old_sig_fpe = signal(SIGFPE, qnx_signal_handler);
- old_sig_ill = signal(SIGILL, qnx_signal_handler);
- old_sig_segv = signal(SIGSEGV, qnx_signal_handler);
- old_sig_term = signal(SIGTERM, qnx_signal_handler);
- old_sig_int = signal(SIGINT, qnx_signal_handler);
+ if (_al_qnx_install_signal_handlers){
+ /* install emergency-exit signal handlers */
+ old_sig_abrt = signal(SIGABRT, qnx_signal_handler);
+ old_sig_fpe = signal(SIGFPE, qnx_signal_handler);
+ old_sig_ill = signal(SIGILL, qnx_signal_handler);
+ old_sig_segv = signal(SIGSEGV, qnx_signal_handler);
+ old_sig_term = signal(SIGTERM, qnx_signal_handler);
+ old_sig_int = signal(SIGINT, qnx_signal_handler);
#ifdef SIGQUIT
- old_sig_quit = signal(SIGQUIT, qnx_signal_handler);
+ old_sig_quit = signal(SIGQUIT, qnx_signal_handler);
#endif
+ }
dim.w = 1;
dim.h = 1;
@@ -421,16 +436,18 @@
_unix_bg_man->exit();
- signal(SIGABRT, old_sig_abrt);
- signal(SIGFPE, old_sig_fpe);
- signal(SIGILL, old_sig_ill);
- signal(SIGSEGV, old_sig_segv);
- signal(SIGTERM, old_sig_term);
- signal(SIGINT, old_sig_int);
+ if ( _al_qnx_install_signal_handlers ){
+ signal(SIGABRT, old_sig_abrt);
+ signal(SIGFPE, old_sig_fpe);
+ signal(SIGILL, old_sig_ill);
+ signal(SIGSEGV, old_sig_segv);
+ signal(SIGTERM, old_sig_term);
+ signal(SIGINT, old_sig_int);
#ifdef SIGQUIT
- signal(SIGQUIT, old_sig_quit);
+ signal(SIGQUIT, old_sig_quit);
#endif
+ }
pthread_mutex_destroy(&qnx_event_mutex);
pthread_mutex_destroy(&qnx_gfx_mutex);
Index: src/allegro.c
===================================================================
--- src/allegro.c (revision 7850)
+++ src/allegro.c (working copy)
@@ -487,7 +487,36 @@
}
}
+/* disables the usage of signals that some underlying systems install
+ */
+void disable_signal_handlers()
+{
+ /* if a system driver was already init'ed just use that */
+ if ( system_driver != NULL ){
+ system_driver->disable_signals();
+ } else {
+ int i;
+ for (i=0; _system_driver_list[i].driver; i++) {
+ SYSTEM_DRIVER * driver = _system_driver_list[i].driver;
+ driver->disable_signals();
+ }
+ }
+}
+/* enables the usage of signals that some underlying systems install */
+void enable_signal_handlers()
+{
+ /* if a system driver was already init'ed just use that */
+ if ( system_driver != NULL ){
+ system_driver->enable_signals();
+ } else {
+ int i;
+ for (i=0; _system_driver_list[i].driver; i++) {
+ SYSTEM_DRIVER * driver = _system_driver_list[i].driver;
+ driver->enable_signals();
+ }
+ }
+}
/* allegro_message:
* Displays a message in whatever form the current platform requires.
@@ -730,6 +759,7 @@
/* a simple system driver for platform-independent code */
static int sys_none_init(void) { return 0; }
static void sys_none_exit(void) { }
+static void sys_none_signal(void){ }
static _DRIVER_INFO no_drivers[] = {{ 0, NULL, 0 }};
static _DRIVER_INFO *sys_no_driver(void) { return no_drivers; }
@@ -747,6 +777,7 @@
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
sys_no_driver, sys_no_driver, sys_no_driver, sys_no_driver,
- sys_no_driver, sys_no_driver, sys_no_driver
+ sys_no_driver, sys_no_driver, sys_no_driver,
+ sys_none_signal, sys_none_signal
};
Index: src/macosx/system.m
===================================================================
--- src/macosx/system.m (revision 7850)
+++ src/macosx/system.m (working copy)
@@ -54,8 +54,9 @@
static void osx_sys_get_gfx_safe_mode(int *driver, struct GFX_MODE *mode);
static int osx_sys_desktop_color_depth(void);
static int osx_sys_get_desktop_resolution(int *width, int *height);
+static void osx_sys_disable_signal_handlers(void);
+static void osx_sys_enable_signal_handlers(void);
-
/* Global variables */
int __crt0_argc;
char **__crt0_argv;
@@ -84,6 +85,8 @@
static NSImage *cursor_image = NULL;
static int skip_events_processing = FALSE;
+/* use signal handlers by default */
+static int _al_osx_install_signal_handlers = 1;
SYSTEM_DRIVER system_macosx =
{
@@ -126,9 +129,19 @@
NULL, /* AL_METHOD(_DRIVER_INFO *, mouse_drivers, (void)); */
NULL, /* AL_METHOD(_DRIVER_INFO *, joystick_drivers, (void)); */
NULL, /* AL_METHOD(_DRIVER_INFO *, timer_drivers, (void)); */
+ osx_sys_enable_signal_handlers,
+ osx_sys_disable_signal_handlers
};
+static void osx_sys_disable_signal_handlers(void)
+{
+ _al_osx_install_signal_handlers = 0;
+}
+static void osx_sys_enable_signal_handlers(void)
+{
+ _al_osx_install_signal_handlers = 1;
+}
/* osx_signal_handler:
* Used to trap various signals, to make sure things get shut down cleanly.
@@ -413,16 +426,16 @@
_unix_guess_file_encoding();
- /* Install emergency-exit signal handlers */
- old_sig_abrt = signal(SIGABRT, osx_signal_handler);
- old_sig_fpe = signal(SIGFPE, osx_signal_handler);
- old_sig_ill = signal(SIGILL, osx_signal_handler);
- old_sig_segv = signal(SIGSEGV, osx_signal_handler);
- old_sig_term = signal(SIGTERM, osx_signal_handler);
- old_sig_int = signal(SIGINT, osx_signal_handler);
- old_sig_quit = signal(SIGQUIT, osx_signal_handler);
-
-
+ if ( _al_osx_install_signal_handlers ){
+ /* Install emergency-exit signal handlers */
+ old_sig_abrt = signal(SIGABRT, osx_signal_handler);
+ old_sig_fpe = signal(SIGFPE, osx_signal_handler);
+ old_sig_ill = signal(SIGILL, osx_signal_handler);
+ old_sig_segv = signal(SIGSEGV, osx_signal_handler);
+ old_sig_term = signal(SIGTERM, osx_signal_handler);
+ old_sig_int = signal(SIGINT, osx_signal_handler);
+ old_sig_quit = signal(SIGQUIT, osx_signal_handler);
+ }
if (osx_bundle == NULL) {
/* If in a bundle, the dock will recognise us automatically */
@@ -469,13 +482,15 @@
*/
static void osx_sys_exit(void)
{
- signal(SIGABRT, old_sig_abrt);
- signal(SIGFPE, old_sig_fpe);
- signal(SIGILL, old_sig_ill);
- signal(SIGSEGV, old_sig_segv);
- signal(SIGTERM, old_sig_term);
- signal(SIGINT, old_sig_int);
- signal(SIGQUIT, old_sig_quit);
+ if ( _al_osx_install_signal_handlers ){
+ signal(SIGABRT, old_sig_abrt);
+ signal(SIGFPE, old_sig_fpe);
+ signal(SIGILL, old_sig_ill);
+ signal(SIGSEGV, old_sig_segv);
+ signal(SIGTERM, old_sig_term);
+ signal(SIGINT, old_sig_int);
+ signal(SIGQUIT, old_sig_quit);
+ }
if (osx_blank_cursor)
[osx_blank_cursor release];
Index: src/x/xsystem.c
===================================================================
--- src/x/xsystem.c (revision 7850)
+++ src/x/xsystem.c (working copy)
@@ -53,7 +53,11 @@
static _DRIVER_INFO *_xwin_sysdrv_joystick_drivers(void);
#endif
static _DRIVER_INFO *_xwin_sysdrv_timer_drivers(void);
+static void _xwin_disable_signal_handlers(void);
+static void _xwin_enable_signal_handlers(void);
+/* install signal handlers by default */
+static int _al_xwin_install_signal_handlers = 1;
/* the main system driver for running under X-Windows */
SYSTEM_DRIVER system_xwin =
@@ -107,10 +111,11 @@
#else
NULL, /* joystick_driver_list */
#endif
- _xwin_sysdrv_timer_drivers
+ _xwin_sysdrv_timer_drivers,
+ _xwin_enable_signal_handlers,
+ _xwin_disable_signal_handlers
};
-
static RETSIGTYPE (*old_sig_abrt)(int num);
static RETSIGTYPE (*old_sig_fpe)(int num);
static RETSIGTYPE (*old_sig_ill)(int num);
@@ -121,12 +126,22 @@
static RETSIGTYPE (*old_sig_quit)(int num);
#endif
+static void _xwin_enable_signal_handlers(void)
+{
+ _al_xwin_install_signal_handlers = 1;
+}
+
+static void _xwin_disable_signal_handlers(void)
+{
+ _al_xwin_install_signal_handlers = 0;
+}
+
/* _xwin_signal_handler:
* Used to trap various signals, to make sure things get shut down cleanly.
*/
static RETSIGTYPE _xwin_signal_handler(int num)
{
- if (_unix_bg_man->interrupts_disabled() || _xwin.lock_count) {
+ if ( _al_xwin_install_signal_handlers && (_unix_bg_man->interrupts_disabled() || _xwin.lock_count)) {
/* Can not shutdown X-Windows, restore old signal handlers and slam the door. */
signal(SIGABRT, old_sig_abrt);
signal(SIGFPE, old_sig_fpe);
@@ -169,17 +184,19 @@
_unix_guess_file_encoding();
- /* install emergency-exit signal handlers */
- old_sig_abrt = signal(SIGABRT, _xwin_signal_handler);
- old_sig_fpe = signal(SIGFPE, _xwin_signal_handler);
- old_sig_ill = signal(SIGILL, _xwin_signal_handler);
- old_sig_segv = signal(SIGSEGV, _xwin_signal_handler);
- old_sig_term = signal(SIGTERM, _xwin_signal_handler);
- old_sig_int = signal(SIGINT, _xwin_signal_handler);
+ if ( _al_xwin_install_signal_handlers ){
+ /* install emergency-exit signal handlers */
+ old_sig_abrt = signal(SIGABRT, _xwin_signal_handler);
+ old_sig_fpe = signal(SIGFPE, _xwin_signal_handler);
+ old_sig_ill = signal(SIGILL, _xwin_signal_handler);
+ old_sig_segv = signal(SIGSEGV, _xwin_signal_handler);
+ old_sig_term = signal(SIGTERM, _xwin_signal_handler);
+ old_sig_int = signal(SIGINT, _xwin_signal_handler);
#ifdef SIGQUIT
- old_sig_quit = signal(SIGQUIT, _xwin_signal_handler);
+ old_sig_quit = signal(SIGQUIT, _xwin_signal_handler);
#endif
+ }
/* Initialise dynamic driver lists and load modules */
_unix_driver_lists_init();
@@ -244,12 +261,14 @@
_unix_unload_modules();
_unix_driver_lists_shutdown();
- signal(SIGABRT, old_sig_abrt);
- signal(SIGFPE, old_sig_fpe);
- signal(SIGILL, old_sig_ill);
- signal(SIGSEGV, old_sig_segv);
- signal(SIGTERM, old_sig_term);
- signal(SIGINT, old_sig_int);
+ if ( _al_xwin_install_signal_handlers ){
+ signal(SIGABRT, old_sig_abrt);
+ signal(SIGFPE, old_sig_fpe);
+ signal(SIGILL, old_sig_ill);
+ signal(SIGSEGV, old_sig_segv);
+ signal(SIGTERM, old_sig_term);
+ signal(SIGINT, old_sig_int);
+ }
#ifdef SIGQUIT
signal(SIGQUIT, old_sig_quit);
Index: include/allegro/system.h
===================================================================
--- include/allegro/system.h (revision 7850)
+++ include/allegro/system.h (working copy)
@@ -231,6 +231,8 @@
AL_METHOD(_DRIVER_INFO *, mouse_drivers, (void));
AL_METHOD(_DRIVER_INFO *, joystick_drivers, (void));
AL_METHOD(_DRIVER_INFO *, timer_drivers, (void));
+ AL_METHOD(void, enable_signals, (void));
+ AL_METHOD(void, disable_signals, (void));
} SYSTEM_DRIVER;