]> git.siccegge.de Git - frida/frida.git/blob - src/gui/widgets/ScriptingDock.cxx
Properly handle errors in sceme
[frida/frida.git] / src / gui / widgets / ScriptingDock.cxx
1 #include "ScriptingDock.hxx"
2
3 namespace {
4 SCM handler (void *data, SCM tag, SCM throw_args) {
5 scm_handle_by_message_noexit ((void*)"foo", tag, throw_args);
6 return SCM_BOOL_F;
7 }
8 }
9
10 void ScriptingDock::doEvaluate() {
11 QString text = line->text();
12 line->clear();
13 LOG4CXX_INFO(logger, "Evaluating String \"" << text.toStdString() << "\"");
14 browser->append(QString("> ") + text);
15
16 SCM result_obj = scm_internal_catch(SCM_BOOL_T,
17 (SCM (*)(void *))scm_c_eval_string,
18 (void*)text.toStdString().c_str(),
19 handler, NULL);
20 SCM result_str = scm_object_to_string(result_obj, SCM_UNDEFINED);
21
22 SCM output = scm_get_output_string(guile_output_port);
23 QString output_q = scm_to_locale_string(output);
24 if (output_q.endsWith("\n")) output_q.chop(1);
25 if (output_q != "") browser->append(output_q);
26
27 output = scm_get_output_string(guile_error_port);
28 output_q = scm_to_locale_string(output);
29 if (output_q.endsWith("\n")) output_q.chop(1);
30 if (output_q != "") browser->append(output_q);
31
32 scm_truncate_file(guile_output_port, scm_from_uint16(0));
33 scm_truncate_file(guile_error_port, scm_from_uint16(0));
34
35 browser->append(scm_to_locale_string(result_str));
36 }