[GB.XML]
* BUG: Parsing errors are now correctly thrown. * BUG: Fixed some memory leaks when an error is raised. git-svn-id: svn://localhost/gambas/trunk@6711 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
2138336e8f
commit
a213747294
8 changed files with 55 additions and 71 deletions
|
@ -76,6 +76,7 @@ catch(XMLParseException &e)
|
|||
{
|
||||
GB.Error(e.errorWhat);
|
||||
GB.ReturnNull();
|
||||
XMLParseException_Cleanup(&e);
|
||||
}
|
||||
|
||||
END_METHOD
|
||||
|
@ -95,6 +96,7 @@ try
|
|||
catch(XMLParseException &e)
|
||||
{
|
||||
GB.Error(e.errorWhat);
|
||||
XMLParseException_Cleanup(&e);
|
||||
}
|
||||
|
||||
END_METHOD
|
||||
|
@ -129,6 +131,7 @@ else
|
|||
catch(XMLParseException &e)
|
||||
{
|
||||
GB.Error(e.errorWhat);
|
||||
XMLParseException_Cleanup(&e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,6 +159,7 @@ try
|
|||
catch(XMLParseException &e)
|
||||
{
|
||||
GB.Error(e.errorWhat);
|
||||
XMLParseException_Cleanup(&e);
|
||||
}
|
||||
|
||||
END_METHOD
|
||||
|
|
|
@ -140,6 +140,7 @@ try
|
|||
catch(XMLParseException &e)
|
||||
{
|
||||
GB.Error(e.errorWhat);
|
||||
XMLParseException_Cleanup(&e);
|
||||
}
|
||||
END_METHOD
|
||||
|
||||
|
@ -254,6 +255,7 @@ try
|
|||
catch(XMLParseException &e)
|
||||
{
|
||||
GB.Error(e.errorWhat);
|
||||
XMLParseException_Cleanup(&e);
|
||||
}
|
||||
GB.ReturnObject(array);
|
||||
|
||||
|
|
|
@ -88,6 +88,7 @@ try
|
|||
catch(XMLParseException &e)
|
||||
{
|
||||
GB.Error(e.errorWhat);
|
||||
XMLParseException_Cleanup(&e);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ try
|
|||
catch(XMLParseException &e)
|
||||
{
|
||||
GB.Error(e.errorWhat);
|
||||
XMLParseException_Cleanup(&e);
|
||||
}
|
||||
|
||||
END_METHOD
|
||||
|
|
|
@ -184,33 +184,6 @@ HtmlDocument_AddScriptIfIE(THIS, STRING(path), LENGTH(path), STRINGOPT(cond, "IE
|
|||
|
||||
END_METHOD
|
||||
|
||||
/*BEGIN_METHOD(CDocument_forceSetContent, GB_STRING data)
|
||||
|
||||
try
|
||||
{
|
||||
THIS->setContent(STRING(data), true);
|
||||
}
|
||||
catch(HTMLParseException &e)
|
||||
{
|
||||
GB.Error(e.what());
|
||||
}
|
||||
|
||||
END_METHOD*/
|
||||
/*
|
||||
BEGIN_METHOD(CDocument_fromString, GB_STRING content)
|
||||
|
||||
try
|
||||
{
|
||||
(STRING(content), LENGTH(content));
|
||||
}
|
||||
catch(XMLParseException &e)
|
||||
{
|
||||
GB.Error(e.what());
|
||||
}
|
||||
|
||||
END_METHOD*/
|
||||
|
||||
|
||||
GB_DESC CDocumentStyleSheetsDesc[] =
|
||||
{
|
||||
GB_DECLARE(".HtmlDocumentStyleSheets", 0), GB_VIRTUAL_CLASS(),
|
||||
|
|
|
@ -64,6 +64,13 @@ else \
|
|||
XMLNode_appendChild(curElement, _elmt); \
|
||||
}
|
||||
|
||||
#define THROW(_ex) for(size_t i = 0; i < *nodeCount; i++)\
|
||||
{\
|
||||
XMLNode_Free(elements[i]);\
|
||||
}\
|
||||
free(elements);\
|
||||
throw(_ex)
|
||||
|
||||
Node** parseXML(char const *data, const size_t lendata, size_t *nodeCount) throw(XMLParseException)
|
||||
{
|
||||
*nodeCount = 0;
|
||||
|
@ -129,21 +136,21 @@ Node** parseXML(char const *data, const size_t lendata, size_t *nodeCount) throw
|
|||
if(!curElement)//Pas d'élément courant
|
||||
{
|
||||
//ERREUR : CLOSING TAG WHEREAS NONE IS OPEN
|
||||
throw(XMLParseException_New("Closing tag whereas none is open",
|
||||
THROW(XMLParseException_New("Closing tag whereas none is open",
|
||||
data, lendata, pos - 1));
|
||||
|
||||
}
|
||||
if((endData) < pos + curElement->lenTagName)//Impossible que les tags correspondent
|
||||
{
|
||||
//ERREUR : TAG MISMATCH
|
||||
throw(XMLParseException_New("Tag mismatch",
|
||||
THROW(XMLParseException_New("Tag mismatch",
|
||||
data, lendata, pos - 1));
|
||||
}
|
||||
//Les tags ne correspondent pas
|
||||
else if(memcmp(pos, curElement->tagName, curElement->lenTagName) != 0)
|
||||
{
|
||||
//ERREUR : TAG MISMATCH
|
||||
throw(XMLParseException_New("Tag mismatch",
|
||||
THROW(XMLParseException_New("Tag mismatch",
|
||||
data, lendata, pos - 1));
|
||||
}
|
||||
else//Les tags correspondent, on remonte
|
||||
|
@ -165,7 +172,7 @@ Node** parseXML(char const *data, const size_t lendata, size_t *nodeCount) throw
|
|||
if(!tag)//Commentaire sans fin
|
||||
{
|
||||
//ERREUR : NEVER-ENDING COMMENT
|
||||
throw(XMLParseException_New("Never-ending comment",
|
||||
THROW(XMLParseException_New("Never-ending comment",
|
||||
data, lendata, pos - 1));
|
||||
}
|
||||
|
||||
|
@ -182,7 +189,7 @@ Node** parseXML(char const *data, const size_t lendata, size_t *nodeCount) throw
|
|||
if(!tag)//Cdata sans fin
|
||||
{
|
||||
//ERREUR : UNENDED CDATA
|
||||
throw(XMLParseException_New("Never-ending CDATA",
|
||||
THROW(XMLParseException_New("Never-ending CDATA",
|
||||
data, lendata, pos - 1));
|
||||
}
|
||||
|
||||
|
@ -198,7 +205,7 @@ Node** parseXML(char const *data, const size_t lendata, size_t *nodeCount) throw
|
|||
tag = (char*)memchr(pos, '>', endData - pos);
|
||||
if(!tag)//Doctype sans fin
|
||||
{
|
||||
throw(XMLParseException_New("Never-ending DOCTYPE",
|
||||
THROW(XMLParseException_New("Never-ending DOCTYPE",
|
||||
data, lendata, pos - 1));
|
||||
}
|
||||
|
||||
|
@ -208,7 +215,7 @@ Node** parseXML(char const *data, const size_t lendata, size_t *nodeCount) throw
|
|||
else// ... ?
|
||||
{
|
||||
//ERREUR : INVALID TAG
|
||||
throw(XMLParseException_New("Invalid Tag",
|
||||
THROW(XMLParseException_New("Invalid Tag",
|
||||
data, lendata, pos - 1));
|
||||
}
|
||||
}
|
||||
|
@ -217,7 +224,7 @@ Node** parseXML(char const *data, const size_t lendata, size_t *nodeCount) throw
|
|||
tag = (char*)memchrs(pos, endData - pos, "?>", 2);//Looking for the end of the PI
|
||||
if(!tag)//Endless PI
|
||||
{
|
||||
throw(XMLParseException_New("Never-ending Processing instruction",
|
||||
THROW(XMLParseException_New("Never-ending Processing instruction",
|
||||
data, lendata, pos - 1));
|
||||
}
|
||||
|
||||
|
@ -228,7 +235,7 @@ Node** parseXML(char const *data, const size_t lendata, size_t *nodeCount) throw
|
|||
else// ... ?
|
||||
{
|
||||
//ERREUR : INVALID TAG
|
||||
throw(XMLParseException_New("Invalid Tag",
|
||||
THROW(XMLParseException_New("Invalid Tag",
|
||||
data, lendata, pos - 1));
|
||||
}
|
||||
}//Si tout va bien, on a un nouvel élément
|
||||
|
@ -239,7 +246,7 @@ Node** parseXML(char const *data, const size_t lendata, size_t *nodeCount) throw
|
|||
if(pos > endData)
|
||||
{
|
||||
//ERREUR : NEVER-ENDING TAG
|
||||
throw(XMLParseException_New("Never-ending tag",
|
||||
THROW(XMLParseException_New("Never-ending tag",
|
||||
data, lendata, pos - 1));
|
||||
}
|
||||
}
|
||||
|
@ -282,7 +289,7 @@ Node** parseXML(char const *data, const size_t lendata, size_t *nodeCount) throw
|
|||
else
|
||||
{
|
||||
//ERREUR : INVALID TAG
|
||||
throw(XMLParseException_New("Invalid tag",
|
||||
THROW(XMLParseException_New("Invalid tag",
|
||||
data, lendata, pos - 1));
|
||||
}
|
||||
}
|
||||
|
@ -295,7 +302,7 @@ Node** parseXML(char const *data, const size_t lendata, size_t *nodeCount) throw
|
|||
if(delimiter != '"' && delimiter != '\'')
|
||||
{
|
||||
//ERREUR : EXPECTED ATTRIBUTE DELIMITER
|
||||
throw(XMLParseException_New("Expected attribute delimiter",
|
||||
THROW(XMLParseException_New("Expected attribute delimiter",
|
||||
data, lendata, pos - 1));
|
||||
}
|
||||
pos++;
|
||||
|
|
|
@ -287,18 +287,18 @@ void ThrowXMLParseException(const char* nerror, const char *text, const size_t l
|
|||
throw XMLParseException_New(nerror, text, lenText, posFailed);
|
||||
}
|
||||
|
||||
XMLParseException* XMLParseException_New()//Void initializer
|
||||
XMLParseException XMLParseException_New()//Void initializer
|
||||
{
|
||||
XMLParseException *exception = new XMLParseException;
|
||||
memset(exception, 0, sizeof(XMLParseException));
|
||||
exception->line = 1;
|
||||
exception->column = 1;
|
||||
XMLParseException exception;
|
||||
memset(&exception, 0, sizeof(XMLParseException));
|
||||
exception.line = 1;
|
||||
exception.column = 1;
|
||||
return exception;
|
||||
}
|
||||
|
||||
XMLParseException* XMLParseException_New(const char *nerror, size_t posFailed)
|
||||
XMLParseException XMLParseException_New(const char *nerror, size_t posFailed)
|
||||
{
|
||||
XMLParseException *exception = XMLParseException_New();
|
||||
XMLParseException exception = XMLParseException_New();
|
||||
size_t lenError;
|
||||
char *error;
|
||||
|
||||
|
@ -306,60 +306,55 @@ XMLParseException* XMLParseException_New(const char *nerror, size_t posFailed)
|
|||
error = (char*) malloc(lenError);
|
||||
memcpy(error, nerror, lenError);
|
||||
|
||||
exception->errorWhat = (char*)malloc(37 + lenError);
|
||||
sprintf(exception->errorWhat, "Parse error : %s !\n Position %zu", error, (size_t)posFailed);
|
||||
exception->errorWhat[36 + lenError] = 0;
|
||||
exception.errorWhat = (char*)malloc(37 + lenError);
|
||||
sprintf(exception.errorWhat, "Parse error : %s !\n Position %zu", error, (size_t)posFailed);
|
||||
exception.errorWhat[36 + lenError] = 0;
|
||||
|
||||
free(error);
|
||||
|
||||
return exception;
|
||||
}
|
||||
|
||||
XMLParseException* XMLParseException_New(const char *nerror, const char *data, const size_t lenData, const char *posFailed) throw()
|
||||
XMLParseException XMLParseException_New(const char *nerror, const char *data, const size_t lenData, const char *posFailed) throw()
|
||||
{
|
||||
XMLParseException *exception = XMLParseException_New();
|
||||
XMLParseException exception = XMLParseException_New();
|
||||
size_t lenError;
|
||||
char *error;
|
||||
|
||||
lenError = strlen(nerror) + 1;
|
||||
error = (char*) malloc(lenError);
|
||||
memcpy(error, nerror, lenError);
|
||||
|
||||
//Parse error : (errorText) !\n Line 123456789 , Column 123456789 : \n (near)
|
||||
|
||||
if(posFailed == 0)
|
||||
{
|
||||
exception->errorWhat = (char*)malloc(17 + lenError);
|
||||
sprintf(exception->errorWhat, "Parse error : %s !", error);
|
||||
exception->errorWhat[16 + lenError] = 0;
|
||||
exception.errorWhat = (char*)malloc(17 + lenError);
|
||||
sprintf(exception.errorWhat, "Parse error : %s !", nerror);
|
||||
exception.errorWhat[16 + lenError] = 0;
|
||||
return exception;
|
||||
}
|
||||
else if(!data || !lenData)
|
||||
{
|
||||
exception->errorWhat = (char*)malloc(37 + lenError);
|
||||
sprintf(exception->errorWhat, "Parse error : %s !\n Position %zu", error, (size_t)posFailed);
|
||||
exception->errorWhat[36 + lenError] = 0;
|
||||
exception.errorWhat = (char*)malloc(37 + lenError);
|
||||
sprintf(exception.errorWhat, "Parse error : %s !\n Position %zu", nerror, (size_t)posFailed);
|
||||
exception.errorWhat[36 + lenError] = 0;
|
||||
return exception;
|
||||
}
|
||||
|
||||
if(posFailed > data + lenData || posFailed < data) return exception;
|
||||
XMLParseException_AnalyzeText(exception, data, lenData, posFailed);
|
||||
XMLParseException_AnalyzeText(&exception, data, lenData, posFailed);
|
||||
|
||||
|
||||
exception->errorWhat = (char*)malloc(61 + lenError + exception->lenNear);
|
||||
memset(exception->errorWhat, 0, 61 + lenError + exception->lenNear);
|
||||
sprintf(exception->errorWhat, "Parse error : %s !\n Line %zu , Column %zu : \n %s", error, exception->line, exception->column, exception->near);
|
||||
exception->errorWhat[60 + lenError + exception->lenNear] = 0;
|
||||
exception.errorWhat = (char*)malloc(61 + lenError + exception.lenNear);
|
||||
memset(exception.errorWhat, 0, 61 + lenError + exception.lenNear);
|
||||
sprintf(exception.errorWhat, "Parse error : %s !\n Line %zu , Column %zu : \n %s", nerror, exception.line, exception.column, exception.near);
|
||||
exception.errorWhat[60 + lenError + exception.lenNear] = 0;
|
||||
|
||||
return exception;
|
||||
}
|
||||
|
||||
|
||||
void XMLParseException_Free(XMLParseException* &ex) throw()
|
||||
void XMLParseException_Cleanup(XMLParseException *ex)
|
||||
{
|
||||
if(ex->errorWhat) free(ex->errorWhat);
|
||||
if(ex->near) free(ex->near);
|
||||
free(ex);
|
||||
ex = 0;
|
||||
}
|
||||
|
||||
void XMLParseException_AnalyzeText(XMLParseException *ex, const char *text, const size_t lenText, const char *posFailed) throw()
|
||||
|
|
|
@ -46,8 +46,9 @@ void insertString(char *&src, size_t &lenSrc, const char *insert, size_t lenInse
|
|||
|
||||
bool GB_MatchString(const char *str, size_t lenStr, const char *pattern, size_t lenPattern, int mode = GB_STRCOMP_BINARY);
|
||||
|
||||
XMLParseException* XMLParseException_New(const char *nerror, size_t posFailed);
|
||||
XMLParseException* XMLParseException_New(const char *nerror, const char *data, const size_t lenData, const char *posFailed) throw();
|
||||
XMLParseException XMLParseException_New(const char *nerror, size_t posFailed);
|
||||
XMLParseException XMLParseException_New(const char *nerror, const char *data, const size_t lenData, const char *posFailed) throw();
|
||||
void XMLParseException_Cleanup(XMLParseException *ex);
|
||||
void ThrowXMLParseException(const char* nerror, const char *text, const size_t lenText, const char *posFailed);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue