summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKnut Petter Svendsen <knut@altuma.no>2019-12-11 11:30:31 +0100
committerKnut Petter Svendsen <knut@altuma.no>2019-12-11 11:30:31 +0100
commit6166895e4fab04b76525a5a1401ec294a73ed52b (patch)
treee2488fd21b78a39d068d43782125d19eab7d215b
parent8e2a713e66eb6f7bfb76e78db5ae20dda6294acd (diff)
downloadATCD-6166895e4fab04b76525a5a1401ec294a73ed52b.tar.gz
Improve exception safety for IDL_GlobalData::eval()
If eval() parses code which causes an exception, then the output won't be re-enabled. Fixed by using a helper class that re-enables in the dtor.
-rw-r--r--TAO/TAO_IDL/util/utl_global.cpp65
1 files changed, 31 insertions, 34 deletions
diff --git a/TAO/TAO_IDL/util/utl_global.cpp b/TAO/TAO_IDL/util/utl_global.cpp
index 8ea1a3f8c58..7713e3d1b18 100644
--- a/TAO/TAO_IDL/util/utl_global.cpp
+++ b/TAO/TAO_IDL/util/utl_global.cpp
@@ -1936,15 +1936,15 @@ namespace
{
public:
OldState(IDL_GlobalData* the_idl_global, bool the_disable_output = false)
- : idl_global(the_idl_global),
- old_filename(idl_global->filename ()),
- old_lineno(idl_global->lineno ()),
- old_idl_src_file(idl_global->idl_src_file ()),
- disable_output(the_disable_output),
- flags(ACE_LOG_MSG->flags ())
+ : idl_global_(the_idl_global),
+ old_filename_(idl_global_->filename ()),
+ old_lineno_(idl_global_->lineno ()),
+ old_idl_src_file_(idl_global_->idl_src_file ()),
+ disable_output_(the_disable_output),
+ flags_(ACE_LOG_MSG->flags ())
{
- idl_global->set_lineno (1);
- idl_global->set_filename(0);
+ idl_global_->set_lineno (1);
+ idl_global_->set_filename(0);
// Name this pseudo-file "builtin-N"
#define BUILTIN_NAME_BUFFER_SIZE 64
@@ -1953,13 +1953,13 @@ namespace
ACE_OS::snprintf (&buffer[0], BUILTIN_NAME_BUFFER_SIZE, "builtin-%u", n++);
#undef BUILTIN_NAME_BUFFER_SIZE
UTL_String utl_string (&buffer[0], true);
- idl_global->idl_src_file (new UTL_String (&utl_string, true));
- idl_global->set_filename (new UTL_String (&utl_string, true));
+ idl_global_->idl_src_file (new UTL_String (&utl_string, true));
+ idl_global_->set_filename (new UTL_String (&utl_string, true));
// Disable Output
- if (disable_output)
+ if (disable_output_)
{
- default_streambuf = ACE_DEFAULT_LOG_STREAM->rdbuf ();
+ default_streambuf_ = ACE_DEFAULT_LOG_STREAM->rdbuf ();
ACE_DEFAULT_LOG_STREAM->rdbuf (0);
ACE_LOG_MSG->clr_flags (ACE_Log_Msg::STDERR);
}
@@ -1967,42 +1967,42 @@ namespace
~OldState()
{
- idl_global->set_lineno (old_lineno);
+ idl_global_->set_lineno (old_lineno_);
// Restore IDL_Global Context
- idl_global->set_filename (old_filename);
- idl_global->idl_src_file()->destroy ();
- delete idl_global->idl_src_file ();
- idl_global->idl_src_file (old_idl_src_file);
- idl_global->reset_flag_seen ();
+ idl_global_->set_filename (old_filename_);
+ idl_global_->idl_src_file()->destroy ();
+ delete idl_global_->idl_src_file ();
+ idl_global_->idl_src_file (old_idl_src_file_);
+ idl_global_->reset_flag_seen ();
// Renable Output
- if (disable_output)
+ if (disable_output_)
{
- ACE_DEFAULT_LOG_STREAM->rdbuf (default_streambuf);
- ACE_LOG_MSG->set_flags (flags);
+ ACE_DEFAULT_LOG_STREAM->rdbuf (default_streambuf_);
+ ACE_LOG_MSG->set_flags (flags_);
}
+
+ // Have Flex Cleanup
+ tao_yylex_destroy ();
}
private:
- IDL_GlobalData* idl_global;
- UTL_String *old_filename;
- long old_lineno;
- UTL_String *old_idl_src_file;
- bool disable_output;
- std::streambuf *default_streambuf;
- const unsigned long flags;
+ IDL_GlobalData* idl_global_;
+ UTL_String *old_filename_;
+ long old_lineno_;
+ UTL_String *old_idl_src_file_;
+ bool disable_output_;
+ std::streambuf *default_streambuf_;
+ const unsigned long flags_;
};
}
void
IDL_GlobalData::eval (const char *string, bool disable_output)
{
- exit(0);
OldState old(this, disable_output);
- in_eval_ = true;
-
// Set up Flex to read from string
tao_yy_scan_string (string);
@@ -2011,9 +2011,6 @@ IDL_GlobalData::eval (const char *string, bool disable_output)
idl_global->check_primary_keys ();
AST_check_fwd_decls ();
- // Have Flex Cleanup
- tao_yylex_destroy ();
-
in_eval_ = false;
}