M
mearvk
Running this on Redhat I get a segmentation fault in parseResultData's
for-loop during its second iteration. Anything obviously wrong with my
code?
Thanks.
[CODE main.C ]
#include <string>
#include <iostream>
#include "DDAS_XML_Handler.hpp"
extern "C"
{
#include "lip.h"
}
using namespace std;
int main()
{
DDAS_XML_Handler* handler=new DDAS_XML_Handler();
DDAS_VALIDATION_STRUCT result = handler-
for(unsigned int i=0; i<result.size; i++)
{
cout<<"Result #";
zwrite(result.def_nums);
cout<<" has SSE: "<<result.SSEs<<endl;
}
}
[/CODE]
[CODE DDAS_XML_Handler.C (partial)]
//parse xml document containing boinc result data
DDAS_VALIDATION_STRUCT DDAS_XML_Handler:
arseResultData(const
char* file_path)
{
DDAS_VALIDATION_STRUCT retval;
DOMAttr* sse_attr;
DOMAttr* def_num_attr;
DOMDocument* doc;
DOMNodeList* data_rows;
DOMElement* current;
XercesDOMParser* parser;
try
{
XMLCh* data_row_xmlch =
XMLString::transcode("data_row");
XMLCh* sse_xmlch =
XMLString::transcode("SSE");
XMLCh* def_num_xmlch =
XMLString::transcode("definition_number");
parser = new XercesDOMParser();
parser-
parser->setDoSchema(false);
parser->setLoadExternalDTD(false);
parser->parse(file_path);
doc = parser->getDocument();
data_rows = doc-
retval.size = data_rows->getLength();
retval.SSEs = new double[ retval.size ];
retval.def_nums = new verylong[ retval.size ];
for(unsigned int i=0; i<retval.size; i++)
{
//current data_row
current =
dynamic_cast<DOMElement*> (data_rows->item(i));
//get current's attribute nodes
sse_attr = current-
//convert attribute values from XMLCh*
to char*
char* sse_ch = new
char[128];
char* def_num_ch = new
char[128];
sse_ch =
XMLString::transcode( sse_attr->getValue() );
def_num_ch =
XMLString::transcode( def_num_attr->getValue() );
//convert from char* to numeric
representation
retval.SSEs =
atof( sse_ch );
zsread( def_num_ch ,
&retval.def_nums );
//free dynamic memory
free(sse_ch);
free(def_num_ch);
}
}
catch( xercesc::XMLException& e)
{
char* message =
XMLString::transcode( e.getMessage() );
cout << "Error parsing XML document: " <<
message << endl;
XMLString::release( &message );
}
return retval;
[/CODE]
[CODE DDAS_XML_Handler.hpp]
extern "C"
{
#include "lip.h"
}
struct DDAS_VALIDATION_STRUCT
{
double* SSEs;
unsigned int size;
verylong* def_nums;
};
class DDAS_XML_Handler
{
private:
// char* URL;
public:
//constructor
DDAS_XML_Handler();
//destructor
~DDAS_XML_Handler();
//returns a node list given a URL and a node name
//xercesc:
OMNodeList* getNodeList(char* node_name);
//converts client's result data from XML file to form
appropriate for validation
DDAS_VALIDATION_STRUCT
DDAS_XML_Handler:
arseResultData(const char* file_path);
//prints all matching attributes from a DOMNodeList
//void printNodeListAttrs(xercesc:
OMNodeList*
node_list, char* node_attr);
//prints matching attribute for a given DOMNode
//void printNodeAttr(xercesc:
OMNode* node, char*
node_attr);
};
[/CODE]
[DATA result.xml ]
<DDAS_result_set>
<data_row SSE="138.328873" binary="11101101"
definition_number="237">
<regression_coefficient id="7" value="0.023954"/>
<regression_coefficient id="6" value="0.003977"/>
<regression_coefficient id="5" value="-0.004866"/>
<regression_coefficient id="3" value="0.000086"/>
<regression_coefficient id="2" value="0.004871"/>
<regression_coefficient id="0" value="-0.000803"/>
</data_row>
<data_row SSE="137.649657" binary="11110110"
definition_number="246">
<regression_coefficient id="7" value="0.022691"/>
<regression_coefficient id="6" value="0.003805"/>
<regression_coefficient id="5" value="-0.005100"/>
<regression_coefficient id="4" value="0.000317"/>
<regression_coefficient id="2" value="0.003974"/>
<regression_coefficient id="1" value="0.096372"/>
</data_row>
<data_row SSE="137.549310" binary="11101111"
definition_number="239">
<regression_coefficient id="7" value="0.024656"/>
<regression_coefficient id="6" value="0.003862"/>
<regression_coefficient id="5" value="-0.004905"/>
<regression_coefficient id="3" value="0.000051"/>
<regression_coefficient id="2" value="0.004222"/>
<regression_coefficient id="1" value="0.098256"/>
<regression_coefficient id="0" value="-0.001051"/>
</data_row>
<data_row SSE="137.628296" binary="11101110"
definition_number="238">
<regression_coefficient id="7" value="0.022820"/>
<regression_coefficient id="6" value="0.003741"/>
<regression_coefficient id="5" value="-0.005057"/>
<regression_coefficient id="3" value="0.000065"/>
<regression_coefficient id="2" value="0.004152"/>
<regression_coefficient id="1" value="0.095907"/>
</data_row>
<data_row SSE="137.665670" binary="11100110"
definition_number="230">
<regression_coefficient id="7" value="0.022538"/>
<regression_coefficient id="6" value="0.003791"/>
<regression_coefficient id="5" value="-0.005077"/>
<regression_coefficient id="2" value="0.004172"/>
<regression_coefficient id="1" value="0.098258"/>
</data_row>
<data_row SSE="137.572043" binary="11100111"
definition_number="231">
<regression_coefficient id="7" value="0.024580"/>
<regression_coefficient id="6" value="0.003910"/>
<regression_coefficient id="5" value="-0.004909"/>
<regression_coefficient id="2" value="0.004243"/>
<regression_coefficient id="1" value="0.100252"/>
<regression_coefficient id="0" value="-0.001132"/>
</data_row>
<data_row SSE="138.316077" binary="11111101"
definition_number="253">
<regression_coefficient id="7" value="0.023960"/>
<regression_coefficient id="6" value="0.003998"/>
<regression_coefficient id="5" value="-0.004901"/>
<regression_coefficient id="4" value="0.000313"/>
<regression_coefficient id="3" value="0.000069"/>
<regression_coefficient id="2" value="0.004669"/>
<regression_coefficient id="0" value="-0.000762"/>
</data_row>
<data_row SSE="138.342605" binary="11111011"
definition_number="251">
<regression_coefficient id="7" value="0.024320"/>
<regression_coefficient id="6" value="0.004323"/>
<regression_coefficient id="5" value="-0.004240"/>
<regression_coefficient id="4" value="0.000961"/>
<regression_coefficient id="3" value="0.000008"/>
<regression_coefficient id="1" value="0.109715"/>
<regression_coefficient id="0" value="-0.000738"/>
</data_row>
<data_row SSE="137.565598" binary="11110111"
definition_number="247">
<regression_coefficient id="7" value="0.024595"/>
<regression_coefficient id="6" value="0.003914"/>
<regression_coefficient id="5" value="-0.004930"/>
<regression_coefficient id="4" value="0.000204"/>
<regression_coefficient id="2" value="0.004113"/>
<regression_coefficient id="1" value="0.098959"/>
<regression_coefficient id="0" value="-0.001086"/>
</data_row>
<data_row SSE="137.625804" binary="11111110"
definition_number="254">
<regression_coefficient id="7" value="0.022853"/>
<regression_coefficient id="6" value="0.003753"/>
<regression_coefficient id="5" value="-0.005070"/>
<regression_coefficient id="4" value="0.000138"/>
<regression_coefficient id="3" value="0.000057"/>
<regression_coefficient id="2" value="0.004068"/>
<regression_coefficient id="1" value="0.095368"/>
</data_row>
</DDAS_result_set>
[/DATA]
for-loop during its second iteration. Anything obviously wrong with my
code?
Thanks.
[CODE main.C ]
#include <string>
#include <iostream>
#include "DDAS_XML_Handler.hpp"
extern "C"
{
#include "lip.h"
}
using namespace std;
int main()
{
DDAS_XML_Handler* handler=new DDAS_XML_Handler();
DDAS_VALIDATION_STRUCT result = handler-
parseResultData( "result.xml" );
for(unsigned int i=0; i<result.size; i++)
{
cout<<"Result #";
zwrite(result.def_nums);
cout<<" has SSE: "<<result.SSEs<<endl;
}
}
[/CODE]
[CODE DDAS_XML_Handler.C (partial)]
//parse xml document containing boinc result data
DDAS_VALIDATION_STRUCT DDAS_XML_Handler:
char* file_path)
{
DDAS_VALIDATION_STRUCT retval;
DOMAttr* sse_attr;
DOMAttr* def_num_attr;
DOMDocument* doc;
DOMNodeList* data_rows;
DOMElement* current;
XercesDOMParser* parser;
try
{
XMLCh* data_row_xmlch =
XMLString::transcode("data_row");
XMLCh* sse_xmlch =
XMLString::transcode("SSE");
XMLCh* def_num_xmlch =
XMLString::transcode("definition_number");
parser = new XercesDOMParser();
parser-
parser->setDoNamespaces(false);setValidationScheme(XercesDOMParser::Val_Always);
parser->setDoSchema(false);
parser->setLoadExternalDTD(false);
parser->parse(file_path);
doc = parser->getDocument();
data_rows = doc-
getElementsByTagName(data_row_xmlch);
retval.size = data_rows->getLength();
retval.SSEs = new double[ retval.size ];
retval.def_nums = new verylong[ retval.size ];
for(unsigned int i=0; i<retval.size; i++)
{
//current data_row
current =
dynamic_cast<DOMElement*> (data_rows->item(i));
//get current's attribute nodes
sse_attr = current-
def_num_attr = current-getAttributeNode( sse_xmlch );
getAttributeNode( def_num_xmlch );
//convert attribute values from XMLCh*
to char*
char* sse_ch = new
char[128];
char* def_num_ch = new
char[128];
sse_ch =
XMLString::transcode( sse_attr->getValue() );
def_num_ch =
XMLString::transcode( def_num_attr->getValue() );
//convert from char* to numeric
representation
retval.SSEs =
atof( sse_ch );
zsread( def_num_ch ,
&retval.def_nums );
//free dynamic memory
free(sse_ch);
free(def_num_ch);
}
}
catch( xercesc::XMLException& e)
{
char* message =
XMLString::transcode( e.getMessage() );
cout << "Error parsing XML document: " <<
message << endl;
XMLString::release( &message );
}
return retval;
[/CODE]
[CODE DDAS_XML_Handler.hpp]
extern "C"
{
#include "lip.h"
}
struct DDAS_VALIDATION_STRUCT
{
double* SSEs;
unsigned int size;
verylong* def_nums;
};
class DDAS_XML_Handler
{
private:
// char* URL;
public:
//constructor
DDAS_XML_Handler();
//destructor
~DDAS_XML_Handler();
//returns a node list given a URL and a node name
//xercesc:
//converts client's result data from XML file to form
appropriate for validation
DDAS_VALIDATION_STRUCT
DDAS_XML_Handler:
//prints all matching attributes from a DOMNodeList
//void printNodeListAttrs(xercesc:
node_list, char* node_attr);
//prints matching attribute for a given DOMNode
//void printNodeAttr(xercesc:
node_attr);
};
[/CODE]
[DATA result.xml ]
<DDAS_result_set>
<data_row SSE="138.328873" binary="11101101"
definition_number="237">
<regression_coefficient id="7" value="0.023954"/>
<regression_coefficient id="6" value="0.003977"/>
<regression_coefficient id="5" value="-0.004866"/>
<regression_coefficient id="3" value="0.000086"/>
<regression_coefficient id="2" value="0.004871"/>
<regression_coefficient id="0" value="-0.000803"/>
</data_row>
<data_row SSE="137.649657" binary="11110110"
definition_number="246">
<regression_coefficient id="7" value="0.022691"/>
<regression_coefficient id="6" value="0.003805"/>
<regression_coefficient id="5" value="-0.005100"/>
<regression_coefficient id="4" value="0.000317"/>
<regression_coefficient id="2" value="0.003974"/>
<regression_coefficient id="1" value="0.096372"/>
</data_row>
<data_row SSE="137.549310" binary="11101111"
definition_number="239">
<regression_coefficient id="7" value="0.024656"/>
<regression_coefficient id="6" value="0.003862"/>
<regression_coefficient id="5" value="-0.004905"/>
<regression_coefficient id="3" value="0.000051"/>
<regression_coefficient id="2" value="0.004222"/>
<regression_coefficient id="1" value="0.098256"/>
<regression_coefficient id="0" value="-0.001051"/>
</data_row>
<data_row SSE="137.628296" binary="11101110"
definition_number="238">
<regression_coefficient id="7" value="0.022820"/>
<regression_coefficient id="6" value="0.003741"/>
<regression_coefficient id="5" value="-0.005057"/>
<regression_coefficient id="3" value="0.000065"/>
<regression_coefficient id="2" value="0.004152"/>
<regression_coefficient id="1" value="0.095907"/>
</data_row>
<data_row SSE="137.665670" binary="11100110"
definition_number="230">
<regression_coefficient id="7" value="0.022538"/>
<regression_coefficient id="6" value="0.003791"/>
<regression_coefficient id="5" value="-0.005077"/>
<regression_coefficient id="2" value="0.004172"/>
<regression_coefficient id="1" value="0.098258"/>
</data_row>
<data_row SSE="137.572043" binary="11100111"
definition_number="231">
<regression_coefficient id="7" value="0.024580"/>
<regression_coefficient id="6" value="0.003910"/>
<regression_coefficient id="5" value="-0.004909"/>
<regression_coefficient id="2" value="0.004243"/>
<regression_coefficient id="1" value="0.100252"/>
<regression_coefficient id="0" value="-0.001132"/>
</data_row>
<data_row SSE="138.316077" binary="11111101"
definition_number="253">
<regression_coefficient id="7" value="0.023960"/>
<regression_coefficient id="6" value="0.003998"/>
<regression_coefficient id="5" value="-0.004901"/>
<regression_coefficient id="4" value="0.000313"/>
<regression_coefficient id="3" value="0.000069"/>
<regression_coefficient id="2" value="0.004669"/>
<regression_coefficient id="0" value="-0.000762"/>
</data_row>
<data_row SSE="138.342605" binary="11111011"
definition_number="251">
<regression_coefficient id="7" value="0.024320"/>
<regression_coefficient id="6" value="0.004323"/>
<regression_coefficient id="5" value="-0.004240"/>
<regression_coefficient id="4" value="0.000961"/>
<regression_coefficient id="3" value="0.000008"/>
<regression_coefficient id="1" value="0.109715"/>
<regression_coefficient id="0" value="-0.000738"/>
</data_row>
<data_row SSE="137.565598" binary="11110111"
definition_number="247">
<regression_coefficient id="7" value="0.024595"/>
<regression_coefficient id="6" value="0.003914"/>
<regression_coefficient id="5" value="-0.004930"/>
<regression_coefficient id="4" value="0.000204"/>
<regression_coefficient id="2" value="0.004113"/>
<regression_coefficient id="1" value="0.098959"/>
<regression_coefficient id="0" value="-0.001086"/>
</data_row>
<data_row SSE="137.625804" binary="11111110"
definition_number="254">
<regression_coefficient id="7" value="0.022853"/>
<regression_coefficient id="6" value="0.003753"/>
<regression_coefficient id="5" value="-0.005070"/>
<regression_coefficient id="4" value="0.000138"/>
<regression_coefficient id="3" value="0.000057"/>
<regression_coefficient id="2" value="0.004068"/>
<regression_coefficient id="1" value="0.095368"/>
</data_row>
</DDAS_result_set>
[/DATA]