diff --git a/c/xlib/event-types.c b/c/xlib/event-types.c index 4029140..77e454f 100644 --- a/c/xlib/event-types.c +++ b/c/xlib/event-types.c @@ -450,12 +450,15 @@ s48_value scx_enter_event(XEvent* e) { #define EEXTRACT(i, name, f) xe->name = f(S48_RECORD_REF(e, i)) #define EEXTRACT_START(rtype) \ + S48_DECLARE_GC_PROTECT(1); \ + S48_GC_PROTECT_1(e); \ s48_check_record_type(e, rtype); \ EEXTRACT(0, type, scx_extract_event_type); \ EEXTRACT(1, serial, s48_extract_integer); \ EEXTRACT(2, send_event, S48_EXTRACT_BOOLEAN); \ - EEXTRACT(3, display, scx_extract_display); -#define EEXTRACT_END() + EEXTRACT(3, display, scx_extract_display) +#define EEXTRACT_END() \ + S48_GC_UNPROTECT() void scx_extract_key_event(s48_value e, XKeyEvent* xe) { EEXTRACT_START(scx_key_event_binding); @@ -780,7 +783,9 @@ void scx_extract_keymap_event(s48_value e, XKeymapEvent* xe) { } void scx_extract_event(s48_value se, XEvent* e) { - int t = scx_extract_event_type(S48_RECORD_REF(se, 0)); + int t; + S48_DECLARE_GC_PROTECT_1(se); + t = scx_extract_event_type(S48_RECORD_REF(se, 0)); switch (t) { case KeyPress : case KeyRelease : scx_extract_key_event(se, (XKeyEvent*)e); break; @@ -839,6 +844,7 @@ void scx_extract_event(s48_value se, XEvent* e) { case MappingNotify : scx_extract_mapping_event(se, (XMappingEvent*)e); break; } + S48_GC_UNPROTECT(); } void scx_init_event_types() { diff --git a/c/xlib/event.c b/c/xlib/event.c index d78160a..d9a5aad 100644 --- a/c/xlib/event.c +++ b/c/xlib/event.c @@ -6,9 +6,10 @@ s48_value scx_queued_mode_binding = S48_FALSE; #define scx_extract_queued_mode(x) S48_EXTRACT_ENUM(x, scx_queued_mode_binding) s48_value scx_Events_Queued(s48_value display, s48_value mode) { + S48_DECLARE_GC_PROTECT_2(display, mode); int r = XEventsQueued(scx_extract_display(display), scx_extract_queued_mode(mode)); - return s48_enter_integer(r); + S48_GC_RETURN(s48_enter_integer(r)); } s48_value scx_Events_Pending(s48_value display) { @@ -30,24 +31,23 @@ s48_value scx_Peek_Event(s48_value display) { s48_value scx_Get_Motion_Events(s48_value display, s48_value window, s48_value from, s48_value to) { int n,i; - XTimeCoord *p = XGetMotionEvents(scx_extract_display(display), - scx_extract_window(window), - scx_extract_time(from), - scx_extract_time(to), - &n); + XTimeCoord* p; s48_value l = S48_NULL, t = S48_FALSE; - S48_DECLARE_GC_PROTECT(2); + S48_DECLARE_GC_PROTECT_6(display, window, from, to, l, t); + p = XGetMotionEvents(scx_extract_display(display), + scx_extract_window(window), + scx_extract_time(from), + scx_extract_time(to), + &n); - S48_GC_PROTECT_2(l, t); for (i = n-1; i >= 0; i--) { t = s48_cons(s48_enter_fixnum(p[i].x), s48_enter_fixnum(p[i].y)); t = s48_cons(scx_enter_time(p[i].time), t); l = s48_cons(t, l); } XFree((char*)p); - S48_GC_UNPROTECT(); - return l; + S48_GC_RETURN(l); } s48_value scx_Send_Event(s48_value display, s48_value window, @@ -55,6 +55,7 @@ s48_value scx_Send_Event(s48_value display, s48_value window, s48_value event_mask, s48_value event) { XEvent e; Status r; + S48_DECLARE_GC_PROTECT_5(display, window, propagate, event_mask, event); scx_extract_event(event, &e); r = XSendEvent(scx_extract_display(display), @@ -62,18 +63,7 @@ s48_value scx_Send_Event(s48_value display, s48_value window, S48_EXTRACT_BOOLEAN(propagate), scx_extract_event_mask(event_mask), &e); - return r ? S48_TRUE : S48_FALSE; -} - -s48_value scx_add_pending_channel(channel) { - int socket_fd; - S48_CHECK_CHANNEL(channel); - socket_fd = S48_UNSAFE_EXTRACT_FIXNUM(S48_UNSAFE_CHANNEL_OS_INDEX(channel)); - - if (! s48_add_pending_fd(socket_fd, 1)) /* 1 for: yes, is input */ - s48_raise_out_of_memory_error(); - - return S48_UNSPECIFIC; + S48_GC_RETURN(r ? S48_TRUE : S48_FALSE); } void scx_init_event(void) { @@ -85,5 +75,4 @@ void scx_init_event(void) { S48_EXPORT_FUNCTION(scx_Peek_Event); S48_EXPORT_FUNCTION(scx_Get_Motion_Events); S48_EXPORT_FUNCTION(scx_Send_Event); - S48_EXPORT_FUNCTION(scx_add_pending_channel); }