Commit 87076046 authored by Daniel Veillard's avatar Daniel Veillard
Browse files

adding a --maxmem option to check memory used. Daniel

* xmllint.c: adding a --maxmem option to check memory used.
Daniel
parent 656ce948
Tue May 4 00:52:16 CEST 2004 Daniel Veillard <daniel@veillard.com>
* xmllint.c: adding a --maxmem option to check memory used.
Sat May 1 01:08:44 CEST 2004 Daniel Veillard <daniel@veillard.com>
 
* xmllint.c xmlsave.c python/generator.py python/libxml.c: Fixed
......
......@@ -102,6 +102,7 @@ static int shell = 0;
static int debugent = 0;
#endif
static int debug = 0;
static int maxmem = 0;
#ifdef LIBXML_TREE_ENABLED
static int copy = 0;
#endif /* LIBXML_TREE_ENABLED */
......@@ -170,10 +171,66 @@ static xmlPatternPtr patternc = NULL;
#endif
static int options = 0;
/*
* Internal timing routines to remove the necessity to have unix-specific
* function calls
*/
/************************************************************************
* *
* Memory allocation consumption debugging *
* *
************************************************************************/
static void OOM(void) {
fprintf(stderr, "Ran out of memory needs > %d bytes\n", maxmem);
progresult = 9;
}
static void myFreeFunc(void *mem) {
xmlMemFree(mem);
}
static void *myMallocFunc(size_t size) {
void *ret;
ret = xmlMemMalloc(size);
if (ret != NULL) {
if (xmlMemUsed() > maxmem) {
OOM();
xmlMemFree(ret);
return(NULL);
}
}
return(ret);
}
static void *myReallocFunc(void *mem, size_t size) {
void *ret;
ret = xmlMemRealloc(mem, size);
if (ret != NULL) {
if (xmlMemUsed() > maxmem) {
OOM();
xmlMemFree(ret);
return(NULL);
}
}
return(ret);
}
static char *myStrdupFunc(const char *str) {
char *ret;
ret = xmlMemoryStrdup(str);
if (ret != NULL) {
if (xmlMemUsed() > maxmem) {
OOM();
xmlFree(ret);
return(NULL);
}
}
return(ret);
}
/************************************************************************
* *
* Internal timing routines to remove the necessity to have *
* unix-specific function calls. *
* *
************************************************************************/
#ifndef HAVE_GETTIMEOFDAY
#ifdef HAVE_SYS_TIMEB_H
......@@ -1476,6 +1533,7 @@ static void usage(const char *name) {
#ifdef HAVE_SYS_MMAN_H
printf("\t--memory : parse from memory\n");
#endif
printf("\t--maxmem nbbytes : limits memory allocation to nbbytes bytes\n");
printf("\t--nowarning : do not emit warnings from parser/validator\n");
printf("\t--noblanks : drop (ignorable?) blanks spaces\n");
printf("\t--nocdata : replace cdata section with text nodes\n");
......@@ -1734,6 +1792,16 @@ main(int argc, char **argv) {
noblanks++;
xmlKeepBlanksDefault(0);
}
else if ((!strcmp(argv[i], "-maxmem")) ||
(!strcmp(argv[i], "--maxmem"))) {
i++;
if (sscanf(argv[i], "%d", &maxmem) == 1) {
xmlMemSetup(myFreeFunc, myMallocFunc, myReallocFunc,
myStrdupFunc);
} else {
maxmem = 0;
}
}
else if ((!strcmp(argv[i], "-format")) ||
(!strcmp(argv[i], "--format"))) {
noblanks++;
......@@ -1943,6 +2011,11 @@ main(int argc, char **argv) {
i++;
continue;
}
if ((!strcmp(argv[i], "-maxmem")) ||
(!strcmp(argv[i], "--maxmem"))) {
i++;
continue;
}
if ((!strcmp(argv[i], "-schema")) ||
(!strcmp(argv[i], "--schema"))) {
i++;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment