diff --git a/OMNotebook/OMNotebookGUI/cellapplication.cpp b/OMNotebook/OMNotebookGUI/cellapplication.cpp index 0391c64c426..6315ff4be75 100644 --- a/OMNotebook/OMNotebookGUI/cellapplication.cpp +++ b/OMNotebook/OMNotebookGUI/cellapplication.cpp @@ -49,8 +49,6 @@ #include -#include "omc_config.h" - namespace IAEX { /*! @@ -111,7 +109,7 @@ namespace IAEX } }; - CellApplication::CellApplication( int &argc, char *argv[] ) + CellApplication::CellApplication(int &argc, char *argv[], threadData_t *threadData) : QObject() { app_ = new MyApp(argc, argv, this); @@ -151,6 +149,11 @@ namespace IAEX /* Force C-style doubles */ setlocale(LC_NUMERIC, "C"); + /* Don't move this line + * Is importat for threadData initialization + */ + OmcInteractiveEnvironment *env = OmcInteractiveEnvironment::getInstance(threadData); + // 2006-04-10 AF, use environment variable to find xml files QString openmodelica = OmcInteractiveEnvironment::OpenModelicaHome(); @@ -161,7 +164,6 @@ namespace IAEX } // Avoid cluttering the whole disk with omc temp-files - OmcInteractiveEnvironment *env = OmcInteractiveEnvironment::getInstance(); env->evalExpression("setCommandLineOptions(\"+d=shortOutput\")"); QString cmdLine = env->getResult(); //cout << "Set shortOutput flag: " << cmdLine.toStdString() << std::endl; diff --git a/OMNotebook/OMNotebookGUI/cellapplication.h b/OMNotebook/OMNotebookGUI/cellapplication.h index a29ad59022e..25e04714fd6 100644 --- a/OMNotebook/OMNotebookGUI/cellapplication.h +++ b/OMNotebook/OMNotebookGUI/cellapplication.h @@ -59,6 +59,12 @@ #include "documentview.h" #include "xmlnodename.h" +extern "C" { +#include "meta/meta_modelica.h" +#include "omc_config.h" +#include "gc.h" +} + namespace IAEX { @@ -66,7 +72,7 @@ namespace IAEX { Q_OBJECT public: - CellApplication(int &argc, char *argv[]); + CellApplication(int &argc, char *argv[], threadData_t *threadData); virtual ~CellApplication(); virtual CommandCenter *commandCenter(); diff --git a/OMNotebook/OMNotebookGUI/omcinteractiveenvironment.cpp b/OMNotebook/OMNotebookGUI/omcinteractiveenvironment.cpp index 546f996a73a..59e755c8109 100644 --- a/OMNotebook/OMNotebookGUI/omcinteractiveenvironment.cpp +++ b/OMNotebook/OMNotebookGUI/omcinteractiveenvironment.cpp @@ -62,6 +62,7 @@ void (*omc_terminate)(FILE_INFO info,const char *msg,...) = omc_terminate_functi void (*omc_throw)(threadData_t*) __attribute__ ((noreturn)) = omc_throw_function; int omc_Main_handleCommand(void *threadData, void *imsg, void **omsg); void* omc_Main_init(void *threadData, void *args); +void omc_System_initGarbageCollector(void *threadData); #ifdef WIN32 void omc_Main_setWindowsPaths(threadData_t *threadData, void* _inOMHome); #endif @@ -72,11 +73,11 @@ using namespace std; namespace IAEX { OmcInteractiveEnvironment* OmcInteractiveEnvironment::selfInstance = NULL; - OmcInteractiveEnvironment* OmcInteractiveEnvironment::getInstance() + OmcInteractiveEnvironment* OmcInteractiveEnvironment::getInstance(threadData_t *threadData) { if (selfInstance == NULL) { - selfInstance = new OmcInteractiveEnvironment(); + selfInstance = new OmcInteractiveEnvironment(threadData); } return selfInstance; } @@ -85,7 +86,7 @@ namespace IAEX * * \brief Implements evaluation for modelica code. */ - OmcInteractiveEnvironment::OmcInteractiveEnvironment():result_(""),error_("") + OmcInteractiveEnvironment::OmcInteractiveEnvironment(threadData_t *threadData):threadData_(threadData),result_(""),error_("") { // set the language by reading the OMEdit settings file. QSettings settings(QSettings::IniFormat, QSettings::UserScope, "openmodelica", "omedit"); @@ -94,14 +95,13 @@ namespace IAEX void *args = mmc_mk_nil(); QString locale = "+locale=" + settingsLocale.name(); args = mmc_mk_cons(mmc_mk_scon(locale.toStdString().c_str()), args); - // initialize threadData - threadData_t *threadData = (threadData_t *) GC_malloc_uncollectable(sizeof(threadData_t)); + // initialize garbage collector + omc_System_initGarbageCollector(NULL); MMC_TRY_TOP_INTERNAL() omc_Main_init(threadData, args); - MMC_CATCH_TOP() - threadData_ = threadData; threadData_->plotClassPointer = 0; threadData_->plotCB = 0; + MMC_CATCH_TOP() // set the +d=initialization flag default. evalExpression(QString("setCommandLineOptions(\"+d=initialization\")")); #ifdef WIN32 diff --git a/OMNotebook/OMNotebookGUI/omcinteractiveenvironment.h b/OMNotebook/OMNotebookGUI/omcinteractiveenvironment.h index 513335db5f6..c6b9aadea8c 100644 --- a/OMNotebook/OMNotebookGUI/omcinteractiveenvironment.h +++ b/OMNotebook/OMNotebookGUI/omcinteractiveenvironment.h @@ -43,13 +43,13 @@ namespace IAEX class OmcInteractiveEnvironment : public InputCellDelegate { private: - OmcInteractiveEnvironment(); + OmcInteractiveEnvironment(threadData_t *threadData); virtual ~OmcInteractiveEnvironment(); public: threadData_t *threadData_; - static OmcInteractiveEnvironment* getInstance(); + static OmcInteractiveEnvironment* getInstance(threadData_t *threadData = 0); virtual QString getResult(); virtual QString getError(); virtual int getErrorLevel(); diff --git a/OMNotebook/OMNotebookGUI/qtapp.cpp b/OMNotebook/OMNotebookGUI/qtapp.cpp index b0dec782afb..ca8d9a69391 100644 --- a/OMNotebook/OMNotebookGUI/qtapp.cpp +++ b/OMNotebook/OMNotebookGUI/qtapp.cpp @@ -60,7 +60,12 @@ #include #endif +#define GC_THREADS + +extern "C" { #include "meta/meta_modelica.h" +} + #include using namespace std; @@ -81,10 +86,11 @@ int main(int argc, char *argv[]) #endif MMC_INIT(); + MMC_TRY_TOP() try { - CellApplication a(argc, argv); + CellApplication a(argc, argv, threadData); return a.exec(); } catch(exception &e) @@ -95,5 +101,7 @@ int main(int argc, char *argv[]) } return 0; + + MMC_CATCH_TOP(); }