I have a program that loads the macros written by users and execute them. If a macro has a faulty code that crashes (e.g. null pointer use) the whole program crashes when call ProcessLine.
Is there a way to avoid that and run the macro in “isolation” ?
The problem I have is that I have to pass parameters to the macro and these parameters are pointers. I don’t think it is possible in the case they have their own instance of root interpreter.
For records the macro looks like
[code]#include #include #include #include
using namespace std;
void crash(map<string, float>* lastValues)
{
cout << “HELLO FROM MACRO” << endl;
cout << "macro : last value test : " << (*lastValues)[“test”] << endl;
int *i = 0 ;
(*i) = 1000;
}
[/code]
And the code to call it is :
map<string, float> lastValues;
lastValues["test"] = 10.;
gROOT->LoadMacro("crash.C"); // ok
char* s = Form("crash((map<string, float>*)%p)", &lastValues);
gROOT->ProcessLine(s); // crash
yes, this is a problem. The only “hack” I can come up with would be to build another wrapper:
On the top level you have your application with the test data. The test data gets written to a temporary file. The wrapper loads the data from the file and executes the macro as you did before. If you call the wrapper via gSystem->Exec(), the whole wrapper/macro thing will die, but your main application keeps running.
Cheers,
Jochen
EDIT: You might want to have a look at TMapFile to exchange data between two processes. Although it appears TMapFile is specific to TObjects…