Program compiles standalone but not interpreted

Hi all. I’ve attached a small set of files (300 lines total) to illustrate a difficulty I’m having. I have a class XMLInterface (which doesn’t use any ROOT classes) in XMLInterface.cc/h and a program in test_xml_interface.cc (this same program in macro form is in macro_test_xml_interface.cc). The Makefile will compile XMLInterface which properly runs

[code]mwoods 231 13:23:49 for_roottalk$ ./XMLInterface
//////////////////////////////////////
The original xml
//////////////////////////////////////


<level3.1>1</level3.1>
<level3.2>2</level3.2>
<level3.3>3</level3.3>


<level3.1>11</level3.1>
<level3.2>12</level3.2>
<level3.3>13</level3.3>

//////////////////////////////////////
The parsed xml in a new box
//////////////////////////////////////

    <level3.1>1</level3.1>
    <level3.2>2</level3.2>
    <level3.3>3</level3.3>

    <level3.1>11</level3.1>
    <level3.2>12</level3.2>
    <level3.3>13</level3.3>

//////////////////////////////////////
Another go at parsing
//////////////////////////////////////[/code]

All the code did here was pick out every the contents of any tags. All is fine and dandy.

When I try to run test_xml_interface.cc or macro_test_xml_interface.cc through ROOT (root test_xml_interface.cc) I get a Seg Fault early on:

[code]mwoods 221 13:19:16 for_roottalk$ root macro_test_xml_interface.cc
root [0]
Processing macro_test_xml_interface.cc…
//////////////////////////////////////
The original xml
//////////////////////////////////////

*** Break *** segmentation violation

===========================================================
There was a crash.
This is the entire stack trace of all threads:

Thread 1 (process 23660):
#0 0x00007fff84211b28 in wait4 ()
#1 0x00007fff842260e6 in system ()
#2 0x000000010011bcc5 in TUnixSystem::StackTrace ()
#3 0x0000000100119421 in TUnixSystem::DispatchSignals ()
#4
#5 0x000000010023fd51 in G__G__Base2_344_0_6 ()
#6 0x0000000100882f16 in Cint::G__ExceptionWrapper ()
#7 0x00000001008a5e29 in G__exec_asm ()
#8 0x0000000100977e25 in G__exec_loop ()
#9 0x0000000100972752 in G__exec_statement ()
#10 0x000000010091d3b3 in G__interpret_func ()
#11 0x0000000100909992 in G__getfunction ()
#12 0x00000001009fd2a0 in G__getstructmem ()
#13 0x00000001009f3748 in G__getvariable ()
#14 0x00000001008dafc9 in G__getitem ()
#15 0x00000001008ebed9 in G__getexpr ()
#16 0x000000010096ad10 in G__exec_statement ()
#17 0x00000001008c702d in G__exec_tempfile_core ()
#18 0x00000001008c7323 in G__exec_tempfile ()
#19 0x000000010098288f in G__process_cmd ()
#20 0x000000010002bd2e in TCint::ProcessLine ()
#21 0x00000001000f1483 in TCint::ProcessLineSynch ()
#22 0x0000000100075bdf in TApplication::ExecuteFile ()
#23 0x000000010007362b in TApplication::ProcessLine ()
#24 0x00000001012465d0 in TRint::Run ()
#25 0x00000001000019a0 in main ()

The crash is most likely caused by a problem in your script.
Try to compile it (.L myscript.C+g) and fix any errors.
If that does not help 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.

Root > Function GetXMLString() busy flag cleared
.q
[/code]

I wasn’t able to find anything fishy using valgrind (granted I’m not keen on that program) and would really appreciate some help figuring out if this is a CINT bug or something I can’t catch in the XMLInterface class. Thanks.
XML_Interface.tar (12 KB)

Hi,

The code in XMLInterface.cc is triggering issue with CINT management of temporary variable (they are not quite deleted when they should). To work around the problem, you can compile your script at run-time by using ACLiC: gROOT->ProcessLine(".L XMLInterface.cc+");

Cheers,
Philippe.

Philippe,

Thanks for the work around. I just found another one as well. I tracked down the issue to the operator+=() of the string:

string XMLInterface::GetXMLString() { concatenated_xml = ""; for(size_t i=0; i<the_xml.size(); i++){ concatenated_xml += the_xml[i]; //concatenated_xml.append(the_xml[i]); } return concatenated_xml; }

Commenting out the += line and replacing it with the append method allows it to execute without issue.