From d56bdd224e7ce1b366c6546003d9e1c951c24ae1 Mon Sep 17 00:00:00 2001 From: unknown_lamer Date: Tue, 28 Jun 2005 10:08:45 +0000 Subject: [PATCH] [project @ 2005-06-28 10:08:45 by unknown_lamer] Merged error handling patch from Dale Smith --- ChangeLog | 16 ++++++++++- NEWS | 11 +++++--- bobot++.info | 17 +++++++++--- source/BotInterp.C | 22 +++++++-------- source/BotInterp.H | 2 +- source/Interp.C | 69 +++++++++++++++++++++++++++++++++++----------- source/Interp.H | 3 +- source/Main.C | 1 + source/Parser.C | 5 ++-- 9 files changed, 105 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index e76f0e3..52aa3f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2005-06-28 Clinton Ebadi + * source/Main.C: Merged error handling patch from dsmith + + * source/Parser.C: Merged error handling + patch from dsmith + + * source/Interp.H: Merged error handling patch from dsmith + + * source/Interp.C (lazy_handler): Merged error handling patch from + dsmith + + * source/BotInterp.H: Merged error handling patch from dsmith + + * source/BotInterp.C: Merged error handling patch from dsmith + * bobot++.texinfo (Low Level Message Functions): Documented bot:send-ctcp-reply @@ -14,7 +28,7 @@ * source/Interp.C (interp_init_helper): Renamed bot:send-CTCP to bot:send-ctcp - * source/ScriptCommands.H: Uncommended sendCTCPReply prototype + * source/ScriptCommands.H: Uncommented sendCTCPReply prototype * source/ScriptCommands.C (sendCTCP): Convert to use Commands::CTCP (sendCTCPReply): Added diff --git a/NEWS b/NEWS index eea086b..79ad6fd 100644 --- a/NEWS +++ b/NEWS @@ -22,15 +22,18 @@ Version 2.1.8: etc.) + Message Sending * Implemented bot:notice - + Misc - * Added (bobotpp bot) module that modules may use to gain access - to the bobot++ functions * bot:msg and bot:say may both send to channels and users (instead of bot:msg for users and bot:say for channels) * Renamed bot:send-CTCP to bot:send-ctcp * Added bot:send-ctcp-reply to send a ctcp-reply + + Misc + * Added (bobotpp bot) module that modules may use to gain access + to the bobot++ functions + Debugging - * The debugging evaluator is now enabled when --debug is passed to the bot + * The debugging evaluator is now enabled when --debug is passed to + the bot + * Merged error handling patch from Dale Smith. This adds detailed + errors and backtraces when --debug is passed to Bobot++. - Documentation + Merged documentation patch from Dale Smith (thanks) - Misc diff --git a/bobot++.info b/bobot++.info index 79bcf70..80866fb 100644 --- a/bobot++.info +++ b/bobot++.info @@ -770,6 +770,13 @@ before using these. If you have no idea what these do, read rfc 2812 command, and `message' is the message (or arguments) of the command. Make sure to `bot:ctcp-quote' the message! + -- Function: bot:send-ctcp-reply to command message + `to' is the target of your CTCP reply, `command' is the CTCP + command, and `message' is the message (or arguments) of the + command. Make sure to `bot:ctcp-quote' the message! + + This is used to reply to a ctcp that the bot has received. +  File: bobot++.info, Node: Misc Scripting Stuff, Prev: Sending Messages, Up: Scripting @@ -1095,6 +1102,8 @@ Function Index (line 7) * bot:send-ctcp: Low Level Message Functions. (line 13) +* bot:send-ctcp-reply: Low Level Message Functions. + (line 18) * bot:sent-to-me?: Misc Scripting Stuff. (line 198) * bot:server: Misc Scripting Stuff. @@ -1186,9 +1195,9 @@ Node: Scheme User Levels25525 Node: Sending Messages26659 Node: High Level Message Functions27275 Node: Low Level Message Functions28055 -Node: Misc Scripting Stuff28823 -Node: Concept Index35399 -Node: Function Index35618 -Node: Variable Index45606 +Node: Misc Scripting Stuff29130 +Node: Concept Index35706 +Node: Function Index35925 +Node: Variable Index46056  End Tag Table diff --git a/source/BotInterp.C b/source/BotInterp.C index 43724c8..01ba996 100644 --- a/source/BotInterp.C +++ b/source/BotInterp.C @@ -52,13 +52,10 @@ BotInterp::LoadScript(String filename) Interp::LoadScript(bot, filename); } -void -BotInterp::ScriptLog(SCM throw_args) +SCM +BotInterp::ScriptLog() { - scm_display_error_message(SCM_CADR (throw_args), - SCM_CADDR (throw_args), - logPort); - scm_flush(logPort); + return logPort; } namespace @@ -117,10 +114,10 @@ BotInterp::RunHooks(int hooktype, String match, SCM args) SCM_UNDEFINED, SCM_UNDEFINED) != SCM_BOOL_F) { wd.func = (*it)->function; - result = gh_catch(SCM_BOOL_T, - (scm_t_catch_body) scm_apply_wrapper, - static_cast (&wd), - (scm_t_catch_handler) Interp::ErrorHandler, 0); + result = scm_internal_catch(SCM_BOOL_T, + (scm_t_catch_body) lazy_apply_wrapper, + static_cast (&wd), + (scm_t_catch_handler) empty_handler, 0); if (! (*it)->fallthru) break; } @@ -170,8 +167,9 @@ BotInterp::RunTimers(int now) while (it != it2) { if ((*it)->when <= now) { wd.func = (*it)->function; - gh_catch(SCM_BOOL_T, (scm_t_catch_body) scm_apply_wrapper, - (void *)&wd, (scm_t_catch_handler) Interp::ErrorHandler, 0); + scm_internal_catch(SCM_BOOL_T, + (scm_t_catch_body) lazy_apply_wrapper, (void *)&wd, + (scm_t_catch_handler) empty_handler, 0); scm_gc_unprotect_object(wd.func); it3 = it; ++it3; diff --git a/source/BotInterp.H b/source/BotInterp.H index 7f061ba..85644aa 100644 --- a/source/BotInterp.H +++ b/source/BotInterp.H @@ -105,7 +105,7 @@ class BotInterp { public: BotInterp(Bot *, String); - void ScriptLog(SCM); + SCM ScriptLog(); void Execute(String); void LoadScript(String); diff --git a/source/Interp.C b/source/Interp.C index 94c5045..1107f57 100644 --- a/source/Interp.C +++ b/source/Interp.C @@ -56,6 +56,53 @@ scm_apply_wrapper(void *data) return SCM_BOOL_T; } +static SCM +lazy_handler(void *data, SCM tag, SCM throw_args) +{ + SCM log_port = Interp::bot->botInterp->ScriptLog(); + SCM eport = scm_set_current_error_port(log_port); + + scm_handle_by_message_noexit((void *)"bobot++", tag, throw_args); + scm_force_output(log_port); + scm_set_current_error_port(eport); + scm_ithrow(tag, throw_args, 1); + return SCM_UNSPECIFIED; /* never returns */ +} + +SCM +empty_handler(void *data, SCM tag, SCM args) +{ + return SCM_UNSPECIFIED; +} + + +SCM +lazy_apply_wrapper(void *data) +{ + return scm_internal_lazy_catch(SCM_BOOL_T, + (scm_t_catch_body) scm_apply_wrapper, data, + (scm_t_catch_handler) lazy_handler, 0); +} + + +static SCM +lazy_eval_file(char *filename) +{ + return scm_internal_lazy_catch(SCM_BOOL_T, + (scm_t_catch_body) scm_c_primitive_load, filename, + (scm_t_catch_handler) lazy_handler, 0); +} + +static SCM +lazy_eval_string(char *str) +{ + return scm_internal_lazy_catch(SCM_BOOL_T, + (scm_t_catch_body) scm_c_eval_string, str, + (scm_t_catch_handler) lazy_handler, 0); +} + + + #define bot_new_procedure(a, b, c, d, e) scm_c_define_gsubr (a, c, d, e, b); scm_c_export (a, 0) #define scm_c_define_gsubr(a, b, c, d, e) scm_c_define_gsubr (a, b, c, d, e); scm_c_export (a, 0) #define scm_c_define(a, b) scm_c_define (a, b); scm_c_export (a, 0) @@ -251,7 +298,9 @@ Interp::Execute(Bot *b, String command) #endif bot = b; - gh_eval_str_with_catch (command, ErrorHandler); + scm_internal_catch(SCM_BOOL_T, + (scm_t_catch_body) lazy_eval_string, (void *) static_cast (command), + (scm_t_catch_handler) empty_handler, 0); #ifdef MULTITHREAD // We release the lock @@ -259,12 +308,6 @@ Interp::Execute(Bot *b, String command) #endif } -void load_script_helper (void* file) -{ - String filename = *static_cast (file); - scm_c_use_module ("guile-user"); - gh_eval_file_with_catch(filename, Interp::ErrorHandler); -} void Interp::LoadScript(Bot *b, String filename) @@ -274,19 +317,13 @@ Interp::LoadScript(Bot *b, String filename) pthread_mutex_lock(&mutex); #endif bot = b; - //scm_c_define_module ("", load_script_helper, &filename); - gh_eval_file_with_catch(filename, ErrorHandler); + scm_internal_catch(SCM_BOOL_T, + (scm_t_catch_body) lazy_eval_file, (void *)static_cast(filename), + (scm_t_catch_handler) empty_handler, 0); #ifdef MULTITHREAD // We release the lock pthread_mutex_unlock(&mutex); #endif } -SCM -Interp::ErrorHandler(void *data, SCM tag, SCM throw_args) -{ - bot->botInterp->ScriptLog(throw_args); - return SCM_BOOL_F; -} - #endif diff --git a/source/Interp.H b/source/Interp.H index 9cdea09..2708d97 100644 --- a/source/Interp.H +++ b/source/Interp.H @@ -38,7 +38,8 @@ struct wrapper_data { SCM args; }; -SCM scm_apply_wrapper(void *); +SCM lazy_apply_wrapper(void *); +SCM empty_handler(void *, SCM, SCM); class Interp { public: diff --git a/source/Main.C b/source/Main.C index d119a74..6bc48df 100644 --- a/source/Main.C +++ b/source/Main.C @@ -246,6 +246,7 @@ namespace { SCM_DEVAL_P = 1; SCM_RECORD_POSITIONS_P = 1; + SCM_BACKTRACE_P = 1; SCM_RESET_DEBUG_MODE; } #endif diff --git a/source/Parser.C b/source/Parser.C index b8eafa3..813813b 100644 --- a/source/Parser.C +++ b/source/Parser.C @@ -1051,7 +1051,8 @@ Parser::parseScriptFunction (ServerConnection * cnx, struct wrapper_data wd; wd.func = scmFunc; wd.args = args_list; - gh_catch (SCM_BOOL_T, (scm_t_catch_body) scm_apply_wrapper, - (void *) &wd, (scm_t_catch_handler) Interp::ErrorHandler, 0); + scm_internal_catch (SCM_BOOL_T, + (scm_t_catch_body) lazy_apply_wrapper, (void *) &wd, + (scm_t_catch_handler) empty_handler, 0); } #endif -- 2.20.1