summaryrefslogtreecommitdiffstats
path: root/signal.c
Commit message (Collapse)AuthorAgeFilesLines
* nuke trailing newlines from exception messages.Kaz Kylheku2016-10-071-2/+2
| | | | | | | | | * signal.c (set_signal_handler, get_sign_handler): Eliminate newline in exception messages. * stream.c (unimpl, formatv): Likewise. * unwind.c (uw_block_abscond): Likewise.
* Synchronize license comments with LICENSE.Kaz Kylheku2016-10-011-16/+17
| | | | | | | | | | | | | | | | | | | | * Makefile, args.c, args.h, arith.c, arith.h, cadr.c, cadr.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, filter.c, filter.h, ftw.c, ftw.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, jmp.S, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, share/txr/stdlib/awk.tl, share/txr/stdlib/build.tl, share/txr/stdlib/cadr.tl, share/txr/stdlib/conv.tl, share/txr/stdlib/except.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/socket.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/termios.tl, share/txr/stdlib/txr-case.tl, share/txr/stdlib/type.tl, share/txr/stdlib/with-resources.tl, share/txr/stdlib/with-stream.tl, share/txr/stdlib/yield.tl, signal.c, signal.h, socket.c, socket.h, stream.c, stream.h, struct.c, struct.h, sysif.c, sysif.h, syslog.c, syslog.h, termios.c, termios.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Revert to verbatim 2-Clause BSD.
* Replace all stray C style casts with macros.Kaz Kylheku2016-03-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * gc.c (gc_report_copies): C style casts found in this function. * linenoise.c (strip_qual, convert, coerce): Copy and paste the macros here. (record_undo, compare_completions, lino_add_completion, history_search, ab_append, sync_data_to_buf, refresh_singleline, screen_rows, refresh_multiline, find_nearest_paren, paren_jump, yank_sel, edit_move_matching_paren, edit, lino_make, lino_copy, lino_hist_add, lino_hist_set_max_len): C style casts replaced. * mpi/mpi-types.h (MP_DIGIT_BIT, MP_DIGIT_MAX, MP_WORD_BIT, MP_WORD_MAX, RADIX): C style casts replaced. * mpi/mpi.c (convert, coerce): Copy and paste the macros here. (mp_init_size, mp_init_copy, mp_copy, mp_set_int, mp_div_d, mp_bit, mp_to_double, mp_to_signed_bin, mp_to_unsigned_bin, mp_to_unsigned_buf, mp_toradix_case, mp_grow, s_mp_set_bit, s_mp_mod_2d, s_mp_mul_2d, s_mp_div_2d, s_mp_mul_d, s_mp_mul, s_mp_sqr, s_mp_div, s_mp_2expt, s_mp_todigit): C style casts replaced. * mpi/mplogic (convert): Macro copy and pasted here. (mpl_num_set, mpl_num_clear): C style casts replaced. * parser.c (provide_completions): Likewise. * signal.c (small_sigfillset): Likewise. * stream.c (stdio_truncate, test_set_indent_mode, set_indent_mode): Likewise.
* Header file cleanup.Kaz Kylheku2016-01-221-2/+0
| | | | | | | * arith.c, cadr.c, debug.c, eval.c, filter.c, gencadr.txr, glob.c, hash.c, linenoise/linenoise.c, lisplib.c, match.c, parser.c, rand.c, regex.c, signal.c, stream.c, struct.c, sysif.c, syslog.c, txr.c, unwind.c, utf8.c: Remove unncessary header files.
* bugfix: cached sigmask not populated from OS sigmask.Kaz Kylheku2016-01-191-3/+3
| | | | | | | | | | | | | | | This is responsible for behaviors like Ctrl-C being subsequently ignored after the first time a read is interrupted that way. * signal.c (sig_reload_cache): Eliminate the return statement which was making the memcpy expression unreachable! No warning from gcc. Also, since nobody checks the return value of this function and it doesn't provide one, let's make it void. There is no reason the sigprocmask would fail since the arguments are correct, but let's check its return value anyway.
* Fix Valgrind integration breakage.Kaz Kylheku2016-01-071-1/+1
| | | | | | * signal.c (sig_mask): Pass address of real_oldset to VALGRIND_MAKE_MEM_DEFINED, rather than a copy of the object itself.
* Copyright year bump.Kaz Kylheku2015-12-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | * LICENSE, METALICENSE, Makefile, args.c, args.h, arith.c, arith.h, cadr.c, cadr.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, filter.c, filter.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, jmp.S, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, share/txr/stdlib/cadr.tl, share/txr/stdlib/except.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/txr-case.tl, share/txr/stdlib/type.tl, share/txr/stdlib/with-resources.tl, share/txr/stdlib/with-stream.tl, share/txr/stdlib/yield.tl, signal.c, signal.h, stream.c, stream.h, struct.c, struct.h, sysif.c, sysif.h, syslog.c, syslog.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Add 2016 copyright. * linenoise/LICENSE, linenoise/linenoise.c, linenoise/linenoise.h: Bump one principal author's copyright from 2014 to 2015. The code is based on a snapshot of 2015 upstream work.
* Make small_sigset_t narrower.Kaz Kylheku2015-11-051-1/+1
| | | | | | | | | On 64 bit Darwin, sigset_t is 32 bits, sso our small_sigset_t is actually larger. Let's use unsigned int. * signal.h (small_sigset_t): Use unsignd int for set member. * signal.c (small_sigfillset): Change cast to unsigned int.
* Remove no-longer-needed bulk bit operations.Kaz Kylheku2015-10-271-17/+3
| | | | | | | * signal.c (mem_set_bits, mem_clr_bits): Static functions removed. (sig_mask): Operate on set member of small_sigset_t directly rather than as an array of bytes.
* Reduce size of saved/restored signal masks.Kaz Kylheku2015-10-271-9/+23
| | | | | | | | | | | | | | | | | | | | | | | | | On glibc, sigset_t has a ridiculous size: one kilobyte! The kernel doesn't access most of it in the sigprocmask call. Yet it blows up the size of our dynamic frames quite a lot. In this commit, we define a small_sigset_t type and use that instead. We convert to the bloated one when calling the library. * signal.c (sig_blocked_cache): Type changes to small_sigset_t. (sig_reload_cache): Retrieve signal mask with sigprocmask into a local variable, then copy a small portion from that to sig_blocked_cache. (small_sigfillset): New static function. (set_sig_handler): Local variables of sigset_t changed to small_sigset_t. (sig_mask): Arguments are pointers to small_sigset_t. Conversion to sigset_t done around the call to sigprocmask. * signal.h (copy_sigset): Inline funtion removed. (small_sigset_t): New struct type. (extended_jmp_buf): Member blocked changed to small_sigset_t. (extended_setjmp): Cast expression updated with small_sigset_t *. (extended_longjmp): Use assignment instead of copy_sigset. (sig_blocked_cache, sig_mask): Declarations updated.
* Stop using C library setjmp/longjmp.Kaz Kylheku2015-10-251-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | TXR is moving to custom assembly-language routines. This is mainly motivated by a very dubious thing done in the GNU C Library setjmp and longjmp in the name of security. Evidently, glibc's setjmp "mangles" certain pointer values which are stored into the jmp_buf buffer. It's been that way since 2005, evidently. This means that, firstly, all along, the use of setjmp in gc.c to get registers into a buffer so they can be scanned has not actually worked properly. More importantly, this pointer mangling in setjmp and longjmp is very hostile to a stack copying implementation of delimited continuations. The reason is that continuations contain jmp_buf buffers, which get relocated in the process of capturing and reviving a continuation. Any pointers in a jmp_buf which point into the captured stack segment have to be fixed up to point into the relocated location. Mangled pointers make this difficult, requiring hacks which are specific to glibc and the machine architecture. We might as well implement a clean, well-behaved setjmp and longjmp. * Makefile (jmp.o): New object file. (dbg/%.o, opt/%.o): New rules for .S prerequisites. * args.c, arith.c, cadr.c, combi.c, cadr.c, combi.c, debug.c, eval.c, filter.c, glob.c, hash.c, lib.c, match.c, parser.c, rand.c, regex.c, signal.c, stream.c, struct.c, sysif.c, syslog.c, txr.c, unwind.c, utf8.c: Removed <setjmp.h> include. * gc.c: Switch to struct jmp and jmp_save, instead of jmp_buf and setjmp. * jmp.S: New source file. * signal.h (struct jmp): New struct type. (jmp_save, jmp_restore): New function declarations denoting assembly language routines in jmp.S. (extended_jmp_buf): Uses struct jmp instead of setjmp. (extended_setjmp): Use jmp_save instead of setjmp. (extended_longjmp): Use jmp_restore instead of longjmp.
* False positive valgrind error: uninitialized sigset_t.Kaz Kylheku2015-09-151-0/+6
| | | | | | | | | | | | | | | The issue is that sigset_t is 1024 bits wide on Linux, but there aren't actually that many signals. Valgrind knows this and so when sigprocmask returns the old signal set, Valgrind only marks a portion of it as initialized, and not the entire 1024 bits. When this sigset_t is later passed into sig_set again, we do a memcmp on all 1024 bits and Valgrind complains about a use of uninitialized data. Test case: run valgrind ./txr -i and execute a (throw 'foo) expr. * signal.c (sig_mask): If we are compiling with Valgrind support, mark the old signal set defined just before passing it to sigprocmask, so it has no uninitialized bits.
* kill function returns boolean rather than integer.Kaz Kylheku2015-09-071-1/+5
| | | | | | | | * signal.c (kill_wrap): Return boolean indication of success, with compatibility to previous behavior. * txr.1: Document return value of kill, and put in compatibility note.
* Adding raise function.Kaz Kylheku2015-09-071-0/+7
| | | | | | | * signal.c (raise_wrap): New static function (sig_init): Register raise intrinsic. * txr.1: Documented raise.
* Manage intr count in the face of exceptions.Kaz Kylheku2015-09-061-2/+8
| | | | | | * signal.c (sig_handler): Make sure the interrupt_count is restored to the value on entry into the handler if the lambda throws.
* Bugfix: sig_mask not calling into the OS.Kaz Kylheku2015-09-061-1/+10
| | | | | | | | | | | | | | | | | | This is just amazingly broken; sig_mask recurses instead of calling sigprocmask. Also, we need a way to reload the signal mask cache from the kernel, because the kernel can change the signal mask behind our back. * signal.c (sig_reload_cache): New static function. (sig_handler): Call sig_reload_cache to ensure the sig_blocked_cache accurately reflects the currently blocked signal set. (sig_init): Call sig_reload_cache at init time to correctly reflect any blocked signals. (sig_mask): Call sigprocmask instead of recursing. Moreover, the correct op code is SIG_SETMASK, not SIG_BLOCK.
* Switching some globals to lexical and changing some names.Kaz Kylheku2015-08-031-37/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * arith.c (arith-init): Changing *flo-...* from special to lexical, and adding un-earmuffed variants. The earmuffed versions are obsolescent. Adding %pi% and %e% global lexicals. Earmuffed versions are also made global lexical, and obsolescent. * eval.c (lookup_global_var, lookup_global_var_l): New functions. (lookup_var): Uses lookup_global_var. (reg_varl): New function. (reg_var): Uses reg_var. (eval_init): Register global lexicals user-package, system-package and keyword-package. Old symbols with earmuffs are obsoleted, and also turned into global lexicals. (top-vb, top-fb): Changed to lexical. * eval.h (lookup_global_var, lookup_global_var_l, reg_varl): Declared. * genvim.txr: Scan ver.tl so that the lib-version variable is included. Extract reg_varl calls. * glob.c (glob_init): glob-err and other variables made lexical. * lib.c (get_user_package, get_system_package, get_keyword_package): Use lookup_global_var_l to avoid searching dynamic scope for lexicals which cannot be dynamically rebound. * share/txr/stdlib/ver.tl (lib-version): New global lexical variable. (*lib-version*): Turned lexical. Obsolescent. * signal.c (sig-init): sig-* variables turned lexical. * sysif.c (sysif-init): s-*, poll-* and w-* variables turned lexical. * syslog.c (syslog-init): log-* variables turned lexical. * txr.c (sysroot-init): stdlib and *txr-version* variables turned lexical. txr-version variable added, and *txr-version* is obsolescent. (txr-main): self-path variable added. *self-path* turns lexical and is obsolescent. * txr.1: Documentation updated. Lexical variables not referred to as special. Special variables referred to as special.
* Update copyright notices from 2014 to 2015.Kaz Kylheku2015-02-011-1/+1
| | | | | | | | | | | * arith.c, arith.h, combi.c, combi.h, debug.c, debug.h, eval.c, eval.h, filter.c, filter.h, gc.c, gc.h, hash.c, hash.h, lib.c, lib.h, match.c, match.h, parser.h, rand.c, rand.h, regex.c, regex.h, signal.c, signal.h, stream.c, stream.h, sysif.c, sysif.h, syslog.c, syslog.h, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Update. * LICENSE, METALICENSE: Likewise.
* * Makefile: Removing trailing spaces.Kaz Kylheku2014-10-241-1/+1
| | | | | | | | | | (GREP_CHECK): New macro. (enforce): Rewritten using GREP_CHECK, with new checks. * arith.c, combi.c, debug.c, eval.c, filter.c, gc.c, hash.c, lib.c, * lib.h, match.c, parser.l, parser.y, rand.c, regex.c, signal.c, * signal.h, stream.c, syslog.c, txr.c, unwind.c, utf8.c: Remove trailing spaces.
* Converting cast expressions to macros that are retargettedKaz Kylheku2014-10-171-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | to C++ style casts when compiling as C++. * lib.h (strip_qual, convert, coerce): New casting macros. (TAG_MASK, tag, type, wli_noex, auto_str, static_str, litptr, num_fast, chr, lit_noex, nil, nao): Use cast macros. * arith.c (mul, isqrt_fixnum, bit): Use cast macros. * configure (INT_PTR_MAX): Define using cast macro. * debug.c (debug_init): Use cast macro. * eval.c (do_eval, expand_macro, reg_op, reg_mac, eval_init): Use cast macros. * filter.c (filter_init): Use cast macro. * gc.c (more, mark_obj, in_heap, mark, sweep_one, unmark): Use cast macros. * hash.c (hash_double, equal_hash, eql_hash, hash_equal_op, hash_hash_op, hash_print_op, hash_mark, make_hash, make_similar_hash, copy_hash, gethash_c, gethash, gethash_f, gethash_n, remhash, hash_count, get_hash_userdata, set_hash_userdata, hash_iter_destroy, hash_iter_mark, hash_begin, hash_uni, hash_diff, hash_isec): Use cast macros. * lib.c (code2type, chk_malloc, chk_malloc_gc_more, chk_calloc, chk_realloc, chk_strdup, num, c_num, string, mkstring, mkustring, upcase_str, downcase_str, string_extend, sub_str, cat_str, trim_str, c_chr, vector, vec_set_length, copy_vec, sub_vec, cat_vec, cobj_print_op, obj_init): Likewise. * match.c (do_match_line, hv_trampoline, match_files, dir_tables_init): Likewise. * parser.l (grammar): Likewise. * parser.y (parse): Likewise. * rand.c (make_state, make_random_state, random_fixnum, random): Likewise. * regex.c (CHAR_SET_L2_LO, CHAR_SET_L2_HI, CHAR_SET_L1_LO, CHAR_SET_L1_HI, CHAR_SET_L0_LO, CHAR_SET_L0_HI, L0_full, L0_fill_range, L1_full, L1_fill_range, L1_contains, L1_free, L2_full, L2_fill_range, L2_contains, L2_free, L3_fill_range, L3_contains, L3_free, char_set_create, char_set_cobj_destroy, nfa_state_accept, nfa_state_empty, nfa_state_single, nfa_state_wild, nfa_state_set,
* Purge stray occurrences of "void *" from code base.Kaz Kylheku2014-10-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lib.c (cobj_print_op): In the format call, cast the C pointer to val, since the ~p conversion now takes a val rather than void *. (cptr_equal_op, obj_print, obj_pprint): Remove cast to void *, since obj now already has the type that ~p expects. * lib.h (struct any): Use mem_t * instead of void *. * parser.h (yyscan_t): Repeat the definition from inside the Flex-generated lex.yy.c. (yylex_init, yylex_destroy, yyget_extra, yyset_extra): Re-declare using yyscan_t typedef in place of void *. * parser.l (yyget_column, yyerrprepf): Re-declare using yyscan_t. (grammar): Use yyg in place of yyscanner in calls to yyerrprepf. * parser.y (yylex, %lex-param): Use yyscan_t instead of void *. (parse): Use yyscan_t for local variable. * signal.c (stack): Change type from void * to mem_t *. * stream.c (vformat): Conversion specifier p extracts val instead of void *. (run): Use casts that only remove const, not all the way to void *. * txr.1: Documented p conversion specifier of format. * Makefile (OBJS-y): Initialize with := to make sure it is a simple variable, and not a macro. (SRCS): New variable, listing source files. (enforce): New rule for enforcing coding conventions. Currently checks for void * occurrences.
* * signal.c (interrupt_count): New global variable.Kaz Kylheku2014-08-021-1/+5
| | | | | | | (sig_handler): Increment and decrement interrupt count. If the interrupt count is already positive, treat that as if async signals were not enabled: do not invoke handlers.
* * configure (have_sys_time): New variable.Kaz Kylheku2014-08-011-0/+51
| | | | | | | | | | | | | | Added check for setitimer/getitimer which also checks for <sys/time.h>. * signal.c (sig_init): Register itimer-real, itimer-virtual, itimer-prof variables and getitimer and setitimer functions. (tv_to_usec): New static function. (getitimer_wrap, setitimer_wrap): New functions. * signal.h (getitimer_wrap, setitimer_wrap): Declared. * txr.1: Documented itimers.
* * signal.c (set_sig_handler): Don't use SA_ONSTACKKaz Kylheku2014-08-011-2/+3
| | | | | | | | except for signals for which we use alt stack. * signal.h (sig_save_enable): Do sig_check before enabling async signals. This caused the !async_sig_enabled assertion to trip inside make_obj.
* * signal.c (sig_hup, sig_int, sig_quit, sig_ill, sig_trap, sig_abrt,Kaz Kylheku2014-08-011-7/+0
| | | | | | | | | | sig_bus, sig_fpe, sig_kill, sig_usr1, sig_segv, sig_usr2, sig_pipe, sig_alrm, sig_term, sig_chld, sig_cont, sig_stop, sig_tstp, sig_ttin, sig_ttou, sig_urg, sig_xcpu, sig_xfsz, sigtalrm, sig_prof, sig_poll, sig_sys, sig_winch, sig_iot, sig_stkflt, sig_io, sig_lost, sig_pwr): Remove unused global variables variables. * signal.h: Remove declarations thereof.
* * eval.c (getpid_wrap, getppid_wrap): New static functions.Kaz Kylheku2014-07-301-0/+7
| | | | | | | | | (eval_init): Registered getpid and getppid intrinsics. * signal.c (kill_wrap): New static function. (sig-init): Registered kill intrinsic function. * txr.1: Documented getpid, gettpid and kill.
* * Makefile, arith.c, arith.h, combi.c, combi.h, configure, debug.c,Kaz Kylheku2014-07-231-16/+16
| | | | | | | | debug.h, eval.c, eval.h, filter.c, filter.h, gc.c, gc.h, hash.c, hash.h, lib.c, lib.h, match.c, match.h, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, signal.c, signal.h, stream.c, stream.h, syslog.c, syslog.h, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Synchronize license header with LICENSE.
* * signal.c (set_sig_handler): Set up and tear down alternateKaz Kylheku2014-07-201-2/+2
| | | | | | | | stack for SIGBUS also, not only for SIGSEGV. On Linux, when stack growth collides with another memory mapping, it triggers a SIGBUS not SIGSEGV, which occurs when the process limit on stack size is exceeded. In either situation, we need an alternative stack.
* * eval.c, gc.c, rand.c, regex.c, signal.c: Remove inclusion of unneededKaz Kylheku2014-04-131-2/+0
| | | | headers.
* On platforms with sigaltstack, TXR programs can now catch theKaz Kylheku2014-03-131-0/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | segmentation fault that occurs when running out of stack space, and escape by throwing an exception. Also, bugfix: save and restore the gc enable/disable state. Without this, if we are ever running cod in a gc disabled state and it jumps out, gc stays disabled. * configure: added check for sigaltstack. * gc.h (gc_enabled): Declaration added for existing variable. * signal.c (is_cpu_exception): New static function. (sig_handler): For cpu_exception type signals that pertain to the execution of some instruction, turn on async_sig_enabled, so that the signal is not deferred. Otherwise we will just return without calling the user-defined handler, restart the instruction and get into a loop. Also, disable gc around the handler just in case. One issue is that we might be on an alternate stack, which gc won't like. (setup_alt_stack, teardown_alt_stack): New static functions. (set_sig_handler): If we have sigaltstack, and are asked to set up a SEGV handler, then set it up on the alternate stack. * signal.h (extended_jmp_buf): Adding new member, gc. (extended_setjmp, extended_longjmp): use gc member to save and restore the gc_enable state across setjmp and longjmp.
* Change in the design of how special variables work, to fix the brokenKaz Kylheku2014-02-281-34/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | re-binding. C code now has to go through the dynamic environment lookup to access things like *random-state*, or *stdout*. As part of this, I'm moving some intrinsic variable and function initializations out of eval.c and into their respective modules. Macros are are used to make global variables look like ordinary C variables. This is very similar to the errno trick in POSIX threads implementations. * eval.c (looup_var, lookup_var_l): Restructured to eliminate silly goto, the cobjp handling is gone. (reg_fun, reg_var): Internal function becomes external. reg_var registers a simple cons cell binding now, without any C pointer tricks to real C global variables. (c_var_mark): Static function removed. (c_var_ops): Static struct removed. (eval_init): Numerous initializations for streams, syslog, rand, signals and others moved to their respective modules. The new symbol variables user_package_s, keyword_package_s and system_package_s are interned here, and the variables are created in a special way. * eval.h (reg_var, reg_fun): Declared. * gc.c (prot1): Added assert that the loc pointer isn't null. This happened, and blew up during garbage collection. * lib.c (system_package, keyword_package, user_package): Variables removed these become macros. (system_package_var, keyword_package_var, user_package_var): New global variables. (system_package_s, keyword_package_s, user_package_s): New symbol globals. (get_user_package, get_system_package, get_keyword_package): New functions. (obj_init): Protect new variables. Initialization order of modules tweaked: the modules sig_init, stream_init, and rand_init are moved after eval_init because they register variables. * lib.h (keyword_package, system_pckage, user_package): Variables turned into macros. (system_package_var, keyword_package_var, user_package_var): Declared. (system_package_s, keyword_package_s, user_package_s): Declared. (get_user_package, get_system_package, get_keyword_package): Declared. * rand.c (struct random_state): Renamed to struct rand_state to avoid clash with new random_state macro. (random_state): Global variable removed. (random_state_s): New symbol global. (make_state, rand32, make_random_state, random_fixnum, random): Follow rename of struct random_state.
* Mac OSX Upkeep.Kaz Kylheku2014-01-131-0/+2
| | | | | | | | | * configure: (need_svid_source, need_bsd_source): Variables removed. (need_darwin_c_source): New variable. Detect Apple environment and add -D_DARWIN_C_SOURCE, which is needed to reveal some functions in headers. * signal.c (sig_init): Wrap #ifdefs around SIGPOLL; it is not defined on Darwin.
* Merry C++mas!Kaz Kylheku2013-12-251-8/+9
| | | | | | | * configure: Avoid using "new" as identifier in signals test case. * signal.c (set_sig_handler): Fix warning about { 0 } initializer. (sig_mask): Avoid using "new" as identifier.
* Fixing a bug and performance issue.Kaz Kylheku2013-12-201-2/+51
| | | | | | | | | | | | | | | | | | | | | Problem: we are using sigsetjmp but with a jmp_buf structure; it requires sigjmp_buf! Performance issue: sigsetjmp is a dog which makes system calls. Solution: let's roll our own cached version of sigprocmask which only calls the real sigprocmask when the mask changes. Then our extended_setjmp will just use regular setjmp, plus our own custom signal saving and restoring based on the cached version. * signal.c (sig_blocked_cache): New variable. (set_sig_handler): Use our sig_mask instead of sigprocmask. (mem_set_bits, mem_clr_bits): New static functions. (sig_mask): New function. * signal.h (extended_jmp_buf): New member, blocked. (extended_setjmp): save blocked signals by peeking into sig_blocked_cache, and restore using sig_mask. (sig_blocked_cache, sig_mask): Declared.
* * signal.c (sig_handler): Pass two arguments to signalKaz Kylheku2013-12-131-2/+3
| | | | | | | | | | | | | handler rather than 1. The new argument is the value t, telling the handler that it's asynchronously invoked in a real signal context. If the signal handler returns true, then mark it deferred so that it can re-trigger in a synchronous context. (sig_check): Pass nil as a the second argument to signal handlers, indicating that they are synchronously called, not in a signal handler context. * txr.1: Added documentation.
* * signal.c (set_sig_handler): Disable signals around thisKaz Kylheku2013-12-131-0/+6
| | | | | function because it manipulates the mask of deferred signals which can also be manipulated by an async signal.
* * signal.c (set_sig_handler): Clear the deferred flagKaz Kylheku2013-12-131-0/+4
| | | | | | for a signal that is being set to ignored or default. * txr.1: Documented signals.
* * eval.c (eval_init): Registered vars for signal numbers.Kaz Kylheku2013-12-121-0/+54
| | | | | | | | | | | | * signal.c (sig_hup, sig_int, sig_quit, sig_ill, sig_trap, sig_abrt, sig_bus, val sig_fpe, sig_kill, sig_usr1, sig_segv, sig_usr2, sig_pipe, sig_alrm, val sig_term, sig_chld, sig_cont, sig_stop, sig_tstp, sig_ttin, val sig_ttou, sig_urg, sig_xcpu, sig_xfsz, sigtalrm, sig_prof, val sig_poll, sig_sys, sig_winch, sig_iot, sig_stkflt, sig_io, sig_lost, sig_pwr): New variables. (sig_init): New variables initialized. * signal.h: New variables declared.
* First cut at signal handling support.Kaz Kylheku2013-12-121-0/+135
* Makefile (OBJS-y): Include signal.o if have_posix_sigs is "y". * configure (have_posix_sigs): New variable, set by detecting POSIX signal stuff. * dep.mk: Regenerated. * arith.c, debug.c, eval.c, filter.c, hash.c, match.c, parser.y, parser.l, rand.c, regex.c, syslog.c, txr.c, utf8.c: Include new signal.h header, now required by unwind, and the <signal.h> system header. * eval.c (exit_wrap): New function. (eval_init): New functions registered as intrinsics: exit_wrap, set_sig_handler, get_sig_handler, sig_check. * gc.c (release): Unused functions removed. * gc.h (release): Declaration removed. * lib.c (init): Call sig_init. * stream.c (set_putc, se_getc, se_fflush): New static functions. (stdio_put_char_callback, stdio_get_char_callback, stdio_put_byte, stdio_flush, stdio_get_byte): Use new functions to enable signals when blocked on I/O. (tail_strategy): Allow signals across sleep. (pipev_close): Allow signals across waitpid. (se_pclose): New static function. (pipe_close): Use new function to enable signals across pclose. * unwind.c (uw_unwind_to_exit_point): use extended_longjmp instead of longjmp. * unwind.h (struct uw_block, struct uw_catch): jb member changes from jmp_buf to extended_jmp_buf. (uw_block_begin, uw_simple_catch_begin, uw_catch_begin): Use extended_setjmp instead of setjmp. * signal.c: New file. * signal.h: New file.