diff libinterp/corefcn/interpreter.cc @ 23511:232c8d69d934

manage interpreter instance in interpreter object Currently it is only possible to have one application or interpreter object. Enforce that restriction. * octave.h, octave.cc (application::the_interpreter): Delete. (application::application): Ensure only one application is created at once. * interpreter.cc, interpreter.h (interpreter::instance): New static variable. (interpreter::interpreter): Ensure only one is created at once. (interpreter::~interpreter): Set instance to nullptr. (interpreter::the_interpreter): New function. * interpreter-private.cc, interpreter-private.cc (__get_interpreter__): Delete. Replace all uses with octave::interpreter::the_interpreter.
author John W. Eaton <jwe@octave.org>
date Thu, 18 May 2017 10:53:24 -0400
parents 5da300c55e89
children 084245f9bd03
line wrap: on
line diff
--- a/libinterp/corefcn/interpreter.cc	Wed May 17 22:13:28 2017 -0700
+++ b/libinterp/corefcn/interpreter.cc	Thu May 18 10:53:24 2017 -0400
@@ -374,6 +374,12 @@
       m_inhibit_startup_message (false), m_load_path_initialized (false),
       m_history_initialized (false), m_initialized (false)
   {
+    if (instance)
+      throw std::runtime_error
+        ("only one Octave interpreter object may be active");
+
+    instance = this;
+
     current_evaluator = m_evaluator;
 
     // Matlab uses "C" locale for LC_NUMERIC class regardless of local setting
@@ -498,10 +504,13 @@
     octave_interpreter_ready = true;
   }
 
+  interpreter *interpreter::instance = nullptr;
+
   interpreter::~interpreter (void)
   {
     cleanup ();
 
+    instance = 0;
     current_evaluator = 0;
 
     delete m_evaluator;
@@ -934,7 +943,7 @@
               {
                 if (parser.stmt_list)
                   {
-                    parser.stmt_list->accept (*current_evaluator);
+                    parser.stmt_list->accept (*m_evaluator);
 
                     octave_quit ();