1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-31 06:50:06 +03:00

some updates with memory debugging facilities while messing with libxslt

* xmlmemory.c python/libxml.c python/libxml2-python-api.xml:
  some updates with memory debugging facilities while messing
  with libxslt python bindings
Daniel
This commit is contained in:
Daniel Veillard 2004-07-02 12:23:44 +00:00
parent f93a866079
commit 529233ccdd
5 changed files with 51 additions and 4 deletions

View File

@ -1,3 +1,9 @@
Fri Jul 2 14:22:14 CEST 2004 Daniel Veillard <daniel@veillard.com>
* xmlmemory.c python/libxml.c python/libxml2-python-api.xml:
some updates with memory debugging facilities while messing
with libxslt python bindings
Thu Jul 1 14:53:36 CEST 2004 Daniel Veillard <daniel@veillard.com>
* python/libxml.c python/generator.py python/libxml.py

View File

@ -78,6 +78,18 @@ static xmlStrdupFunc strdupFunc = NULL;
static void
libxml_xmlErrorInitialize(void); /* forward declare */
PyObject *
libxml_xmlMemoryUsed(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
{
long ret;
PyObject *py_retval;
ret = xmlMemUsed();
py_retval = libxml_longWrap(ret);
return (py_retval);
}
PyObject *
libxml_xmlDebugMemory(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
{

View File

@ -310,5 +310,9 @@
<info>Cleanup function for the XML library. It tries to reclaim all parsing related global memory allocated for the library processing. It doesn't deallocate any document related memory. Calling this function should not prevent reusing the library but one should call xmlCleanupParser() only when the process has finished using the library or XML document built with it.</info>
<return type='void'/>
</function>
<function name='xmlMemoryUsed' file='python'>
<info>Returns the total amount of memory allocated by libxml2</info>
<return type='int' info='number of bytes allocated'/>
</function>
</symbols>
</api>

View File

@ -149,6 +149,7 @@ debugMemory()
dumpMemory()
htmlCreatePushParser()
htmlSAXParseFile()
memoryUsed()
newNode()
pythonCleanupParser()
setEntityLoader()

View File

@ -310,6 +310,9 @@ xmlReallocLoc(void *ptr,size_t size, const char * file, int line)
{
MEMHDR *p;
unsigned long number;
#ifdef DEBUG_MEMORY
size_t oldsize;
#endif
if (ptr == NULL)
return(xmlMallocLoc(size, file, line));
@ -326,6 +329,9 @@ xmlReallocLoc(void *ptr,size_t size, const char * file, int line)
p->mh_tag = ~MEMTAG;
xmlMutexLock(xmlMemMutex);
debugMemSize -= p->mh_size;
#ifdef DEBUG_MEMORY
oldsize = p->mh_size;
#endif
#ifdef MEM_LIST
debugmem_list_delete(p);
#endif
@ -357,6 +363,10 @@ xmlReallocLoc(void *ptr,size_t size, const char * file, int line)
TEST_POINT
#ifdef DEBUG_MEMORY
xmlGenericError(xmlGenericErrorContext,
"Realloced(%d to %d) Ok\n", oldsize, size);
#endif
return(HDR_2_CLIENT(p));
error:
@ -389,6 +399,9 @@ xmlMemFree(void *ptr)
{
MEMHDR *p;
char *target;
#ifdef DEBUG_MEMORY
size_t size;
#endif
if (ptr == (void *) -1) {
xmlGenericError(xmlGenericErrorContext,
@ -415,6 +428,9 @@ xmlMemFree(void *ptr)
memset(target, -1, p->mh_size);
xmlMutexLock(xmlMemMutex);
debugMemSize -= p->mh_size;
#ifdef DEBUG_MEMORY
size = p->mh_size;
#endif
#ifdef MEM_LIST
debugmem_list_delete(p);
#endif
@ -424,6 +440,11 @@ xmlMemFree(void *ptr)
TEST_POINT
#ifdef DEBUG_MEMORY
xmlGenericError(xmlGenericErrorContext,
"Freed(%d) Ok\n", size);
#endif
return;
error:
@ -619,12 +640,15 @@ xmlMemDisplay(FILE *fp)
switch (p->mh_type) {
case STRDUP_TYPE:fprintf(fp,"strdup() in ");break;
case MALLOC_TYPE:fprintf(fp,"malloc() in ");break;
case REALLOC_TYPE:fprintf(fp,"realloc() in ");break;
case REALLOC_TYPE:fprintf(fp,"realloc() in ");break;
case MALLOC_ATOMIC_TYPE:fprintf(fp,"atomicmalloc() in ");break;
case REALLOC_ATOMIC_TYPE:fprintf(fp,"atomicrealloc() in ");break;
default:fprintf(fp," ??? in ");break;
case REALLOC_ATOMIC_TYPE:fprintf(fp,"atomicrealloc() in ");break;
default:
fprintf(fp,"Unknow memory block, corruped maybe");
xmlMutexUnlock(xmlMemMutex);
return;
}
if (p->mh_file != NULL) fprintf(fp,"%s(%d)", p->mh_file, p->mh_line);
if (p->mh_file != NULL) fprintf(fp,"%s(%d)", p->mh_file, p->mh_line);
if (p->mh_tag != MEMTAG)
fprintf(fp," INVALID");
nb++;