Problem executing a script twice

Hello all,
I have a problem when I execute a specific Root script twice.
In order to illustrate it, I have made a very minimalistic piece of code which reproduce the problem:

[code]#include “TGraph.h”
#include

void vectors()
{
Int_t Npoints = 10;
vector<Float_t> x(Npoints);
vector<Float_t> y(Npoints);

TGraph *g = new TGraph();
for(Int_t i=0;i<Npoints;i++) {
g->Set(i+1);
x[i] = i+1;
y[i] = x[i]*x[i];
g->SetPoint(i,x[i],y[i]);
}

g->Draw(“APC”);
}
[/code]

If one runs it once from CINT it works like a charm, plotting this nice parabola, but if you execute it again, it crashes miserably.

Any clues?
Thanks in advance.

[code]#include “TInterpreter.h”
#include “TGraph.h”

#if !defined(CINT)
#include
#endif /* !defined(CINT) */

void vectors()
{
#if defined(CINT)
if ( ! (gInterpreter->IsLoaded(“vector”)) ) {
#if 1 /* 0 or 1 /
gInterpreter->ProcessLine("#include ");
#else /
0 or 1 /
gInterpreter->Load(“vector”);
#endif /
0 or 1 /
}
#endif /
defined(CINT) */

Int_t Npoints = 10;
vector<Float_t> x(Npoints);
vector<Float_t> y(Npoints);

TGraph *g = new TGraph();
for(Int_t i=0;i<Npoints;i++) {
g->Set(i+1);
x[i] = i+1;
y[i] = x[i]*x[i];
g->SetPoint(i,x[i],y[i]);
}

g->Draw(“APC”);
}[/code]
BTW. You can execute “.x vectors.cxx” many times without any problems. There is still a problem (i.e. a “segmentation violation”) if one first does “.x vectors.cxx+” (one plus) and then “.x vectors.cxx++” (two pluses). No problems if one first does “.x vectors.cxx++” (two pluses) - then the next “.x vectors.cxx+” (one plus) and/or “.x vectors.cxx++” (two pluses) are fine.

[code]root [0] .x vectors.cxx+
Info in TCanvas::MakeDefCanvas: created default TCanvas with name c1
root [1] .x vectors.cxx++
Info in : unmodified script has already been compiled and loaded
Info in : it will be regenerated and reloaded!
Info in TUnixSystem::ACLiC: creating shared library /…/./vectors_cxx.so

*** Break *** segmentation violation

===========================================================
There was a crash (#7 0xb72a616d in SigHandler(ESignals) ()).
This is the entire stack trace of all threads:

#0 0xb77e1430 in __kernel_vsyscall ()
#1 0xb662f7d3 in __waitpid_nocancel ()
at …/sysdeps/unix/syscall-template.S:82
#2 0xb65d0de3 in do_system (line=)
at …/sysdeps/posix/system.c:149
#3 0xb670027d in system (
line=0x8416730 “/…/v5-30-00-patches/etc/gdb-backtrace.sh 13814 1>&2”) at pt-system.c:29
#4 0xb72a016d in TUnixSystem::Exec(char const*) ()
from /…/v5-30-00-patches/lib/libCore.so.5.30

#38 0xb687ca8b in TRint::Run(bool) ()
from /…/v5-30-00-patches/lib/libRint.so.5.30
#39 0x08048edf in main ()

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#12 0xb71a1a0a in TApplication::IsCmdThread() ()
from /…/v5-30-00-patches/lib/libCore.so.5.30

Root > !!!Dictionary position not recovered because G__unloadfile() is used in a macro!!!

*** Break *** segmentation violation

===========================================================
There was a crash (#7 0xb72a616d in SigHandler(ESignals) ()).
This is the entire stack trace of all threads:

#0 0xb77e1430 in __kernel_vsyscall ()
#1 0xb662f7d3 in __waitpid_nocancel ()
at …/sysdeps/unix/syscall-template.S:82
#2 0xb65d0de3 in do_system (line=)
at …/sysdeps/posix/system.c:149
#3 0xb670027d in system (
line=0x84d7358 “/…/v5-30-00-patches/etc/gdb-backtrace.sh 13814 1>&2”) at pt-system.c:29
#4 0xb72a016d in TUnixSystem::Exec(char const*) ()
from /…/v5-30-00-patches/lib/libCore.so.5.30
…[/code]

Dear Pepe Le Pew,
If I use either “.x vectors.C++” or “.x vectors.C+”, the script works in its original version, in any possible combination of “+” and “++”. There is no need to add these “CINT” lines you proposed.
The problem I have is when not using the “+” : “.x vectors.C”.

Nevertheless, if we slightly modify the script to get the number of points in the parabola as an argument, it doesn’t work anymore after the first execution. Try this code, please:

[code]#include “TGraph.h”
#include

void vectors(Int_t Npoints = 10)
{
vector<Float_t> x(Npoints);
vector<Float_t> y(Npoints);

TGraph *g = new TGraph();
for(Int_t i=0;i<Npoints;i++) {
g->Set(i+1);
x[i] = i+1;
y[i] = x[i]*x[i];
g->SetPoint(i,x[i],y[i]);
}

g->Draw(“APC”);
}
[/code]

Then execute it modifying the argument:
".x vectors.C(20)+" will crash immediately.
".x vectors.C(20)++" will work the first time, but it won’t a second.

Thanks!

.x vectors.C+(20)
.x vectors.C++(20)

Use my proposed modifications (i.e. my “brutal fix”) in order to “overcome” the interpreted code problems (i.e. when you try “.x vectors.C(20)”).

[code]#include “TInterpreter.h”
#include “TGraph.h”

#if !defined(CINT)
#include
#endif /* !defined(CINT) */

void vectors(Int_t Npoints = 10)
{
#if defined(CINT)
if ( ! (gInterpreter->IsLoaded(“vector”)) ) {
#if 1 /* 0 or 1 /
gInterpreter->ProcessLine("#include ");
#else /
0 or 1 /
gInterpreter->Load(“vector”);
#endif /
0 or 1 /
}
#endif /
defined(CINT) */

vector<Float_t> x(Npoints);
vector<Float_t> y(Npoints);

TGraph *g = new TGraph();
for(Int_t i=0;i<Npoints;i++) {
g->Set(i+1);
x[i] = i+1;
y[i] = x[i]*x[i];
g->SetPoint(i,x[i],y[i]);
}

g->Draw(“APC”);
}[/code]

Oh! Sorry, I did a mistake. When running the script with the arguments and the pluses the syntax is like you wrote: “.x vectors.C++(20)”, and not “.x vectors.C(20)++” as I tried…
In such a way the script works without any modification. Your “brutal fix” is not needed.
At least in ROOT 5.32.
Thanks a lot.

Hi Pepe and others,
This issue is still causing me a lot of troubles.
It is true that in this simple example, re-executions of the script inside the same CINT session are working if one uses the “+” and/or the “++”, but it doesn’t with other scripts more complicated.

There is something here which I don’t understand.
How is possible that a program which works with no problem once gets broken when it is called multiple times?
Everything seems to be due to multiple calls to #include .
In my other scripts I got warning messages of this type, when I re-execute them:

Warning: template pair duplicate definition /Users/delaossa/Programs/root_v5.32.00/cint/cint/stl/_pair.h:31: Warning: template reverse_iterator duplicate definition /Users/delaossa/Programs/root_v5.32.00/cint/cint/stl/_iterator.h:269: Warning: template allocator duplicate definition /Users/delaossa/Programs/root_v5.32.00/cint/cint/stl/defalloc.h:134: Warning: template vector duplicate definition /Users/delaossa/Programs/root_v5.32.00/cint/cint/stl/_vector.h:44: ...

Besides, If I compile a program which does multiple calls to these macros in a loop of this type:

// Time looper for(Int_t i=iStart; i<iEnd+1; i+=iStep) { // Run macros for plots TString command; command = Form(".x PlotPhase1D.C(%i)",time); gROOT->ProcessLine(command); }
I get segmentation faults although the script PlotPhase1D.C is working good in CINT (even with multiple calls) and the program itself works when it only loops once. Crazy…

Cheers!

Try my “brutal fix” (I implemented it precisely for the interpreted code).

.x vector.cxx(20)
vector(30)[/code]without problem.

Cheers,
Philippe.

PS. The original problem seems to be fixed in v5.34 (it ‘just’ prints harmless warning message).