diff --git a/ChangeLog b/ChangeLog index e367c613..10a13f5c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,15 @@ +Mon Mar 20 14:05:26 CET 2000 Daniel Veillard + + * xmlmemory.[ch] : seems I forgot to actually update the files in + the last commit :-) + * doc/xml.html doc/html/* : updated and uploaded the docs + Mon Mar 20 12:33:51 CET 2000 Daniel Veillard * test/valid/dtds/xhtml*: removed RCS infos (pain with CVS) * TODO: updated * xmlmemory.[ch] : added xmlMemSetup() and xmlMemGet() to override - libxml defaul allocation function with another set (like gmalloc/ + libxml default allocation function with another set (like gmalloc/ gfree). * Makefile.am, uri.c, uri.h: added a set of functions to do exact (litteraly copied from the RFC 2396 productions) parsing diff --git a/doc/gnome-xml.sgml b/doc/gnome-xml.sgml index 1a08f31d..29e30983 100644 --- a/doc/gnome-xml.sgml +++ b/doc/gnome-xml.sgml @@ -9,6 +9,7 @@ + @@ -78,6 +79,7 @@ &tree; &entities; &valid; + &uri; &error; &HTMLparser; &HTMLtree; diff --git a/doc/html/book1.html b/doc/html/book1.html index c5097bff..e066da65 100644 --- a/doc/html/book1.html +++ b/doc/html/book1.html @@ -138,6 +138,11 @@ HREF="gnome-xml-valid.html" > —
uri
xml-error

Name

Synopsis

Description

Details















Name

Synopsis

Description

Details













Name

Synopsis

Description

Details



























Name

Synopsis

Description

Details








Name

Synopsis

Description

Details























Name

Synopsis

Description

Details










Name

Synopsis

Description

Details























































































xml-erroruri

Name

Synopsis

Description

Details







validuri

Name

Synopsis

Description

Details











Name

Synopsis

#define NO_DEBUG_MEMORYDEBUG_MEMORY -void MEM_LIST +void (*xmlFreeFunc) (void*); +void* (*xmlMallocFunc) (...); +void* (*xmlReallocFunc) (void*, + ...); +char* (*xmlStrdupFunc) (const char*); +extern xmlFreeFunc xmlFree (void *ptr); -void* ; +extern xmlMallocFunc xmlMalloc (int size); -void* ; +extern xmlReallocFunc xmlRealloc (void *ptr, - int size); -char* ; +extern xmlStrdupFunc xmlMemStrdup (const char *str); +>; +int xmlMemSetup (xmlFreeFunc freeFunc, + xmlMallocFunc mallocFunc, + xmlReallocFunc reallocFunc, + xmlStrdupFunc strdupFunc); +int xmlMemGet (xmlFreeFunc *freeFunc, + xmlMallocFunc *mallocFunc, + xmlReallocFunc *reallocFunc, + xmlStrdupFunc *strdupFunc); int xmlInitMemoryxmlMemUsed (void); void xmlMemoryDump (void); -void xmlMemDisplay (FILE *fp, int nr); -#define DEBUG_MEMORY_LOCATION -#define DEBUG_MEMORY -#define MEM_LIST +void xmlMemoryDump (void); void* xmlMallocLoc

Description

Details

NO_DEBUG_MEMORY

DEBUG_MEMORY

#define NO_DEBUG_MEMORY
#define DEBUG_MEMORY

xmlFree ()

MEM_LIST

void        xmlFree                         (void *ptr);
#define MEM_LIST /* keep a list of all the allocated memory blocks */

a free() equivalent, with error checking.


xmlFreeFunc ()

void        (*xmlFreeFunc)                  (void*);

ptrParam1 : the memory block pointer 


xmlMalloc ()

xmlMallocFunc ()

void*       xmlMalloc                       (int size);
void* (*xmlMallocFunc) (...);

a malloc() equivalent, with logging of the allocation info.

size... : an int specifying the size in byte to allocate. 


xmlRealloc ()

xmlReallocFunc ()

void*       xmlRealloc                      (void *ptr,
-                                             int size);
void* (*xmlReallocFunc) (void*, + ...);

a realloc() equivalent, with logging of the allocation info.

ptrParam1 : the initial memory block pointer size... : an int specifying the size in byte to allocate. 


xmlMemStrdup ()

xmlStrdupFunc ()

char*       xmlMemStrdup                    (const char *str);
char* (*xmlStrdupFunc) (const char*);

a strdup() equivalent, with logging of the allocation info.

strParam1 :a pointer to the new string or NULL if allocation error occured. 


xmlFree

extern xmlFreeFunc xmlFree;


xmlMalloc

extern xmlMallocFunc xmlMalloc;


xmlRealloc

extern xmlReallocFunc xmlRealloc;


xmlMemStrdup

extern xmlStrdupFunc xmlMemStrdup;


xmlMemSetup ()

int         xmlMemSetup                     (xmlFreeFunc freeFunc,
+                                             xmlMallocFunc mallocFunc,
+                                             xmlReallocFunc reallocFunc,
+                                             xmlStrdupFunc strdupFunc);

Override the default memory access functions with a new set +This has to be called before any other libxml routines !

Should this be blocked if there was already some allocations +done ?

freeFunc : the free() function to use
mallocFunc : the malloc() function to use
reallocFunc : the realloc() function to use
strdupFunc : the strdup() function to use
Returns :0 on success


xmlMemGet ()

int         xmlMemGet                       (xmlFreeFunc *freeFunc,
+                                             xmlMallocFunc *mallocFunc,
+                                             xmlReallocFunc *reallocFunc,
+                                             xmlStrdupFunc *strdupFunc);

Return the memory access functions set currently in use

freeFunc : the free() function in use
mallocFunc : the malloc() function in use
reallocFunc : the realloc() function in use
strdupFunc : the strdup() function in use
Returns :0 on success




xmlMemoryDump ()

void        xmlMemoryDump                   (void);

Dump in-extenso the memory blocks allocated to the file .memorylist




DEBUG_MEMORY_LOCATION

xmlMemoryDump ()

#define DEBUG_MEMORY_LOCATION
void xmlMemoryDump (void);

Dump in-extenso the memory blocks allocated to the file .memorylist


DEBUG_MEMORY

#define DEBUG_MEMORY


MEM_LIST

#define MEM_LIST /* keep a list of all the allocated memory blocks */




Name

Synopsis

Description

Details


































+ + + + + @@ -617,19 +622,23 @@ - + + + + + + + + - - - - + diff --git a/doc/html/libxml-lib.html b/doc/html/libxml-lib.html index 20f46d75..a896ee1e 100644 --- a/doc/html/libxml-lib.html +++ b/doc/html/libxml-lib.html @@ -139,6 +139,11 @@ HREF="gnome-xml-valid.html" > —
uri
xml-error
  • working on HTML and XML links recognition layers, get in touch with me if you want to test those.
  • +
  • a new URI module for parsing URIs and following strictly RFC 2396
  • +
  • the memory allocation routines used by libxml can now be overloaded + dynamically by using xmlMemSetup()
  • +
  • So far the feedback on the libxml2 beta is positive

2.0.0beta: Mar 14 2000

@@ -1078,6 +1082,6 @@ base under gnome-xml/example

Daniel Veillard

-

$Id: xml.html,v 1.28 2000/03/06 07:41:49 veillard Exp $

+

$Id: xml.html,v 1.29 2000/03/14 19:59:03 veillard Exp $

diff --git a/include/libxml/xmlmemory.h b/include/libxml/xmlmemory.h index 64477a1c..43a92b01 100644 --- a/include/libxml/xmlmemory.h +++ b/include/libxml/xmlmemory.h @@ -8,30 +8,13 @@ #ifndef _DEBUG_MEMORY_ALLOC_ #define _DEBUG_MEMORY_ALLOC_ -#define NO_DEBUG_MEMORY - -#ifdef NO_DEBUG_MEMORY -#ifdef HAVE_MALLOC_H -#include -#endif - -#define xmlFree(x) free((x)) -#define xmlMalloc(x) malloc(x) -#define xmlRealloc(p, x) realloc((p), (x)) -#define xmlMemStrdup(x) strdup((x)) -#define xmlInitMemory() -#define xmlMemUsed() -#define xmlInitMemory() -#define xmlMemoryDump() -#define xmlMemDisplay(x) -#define xmlMemShow(x, d) - -#else /* ! NO_DEBUG_MEMORY */ #include -/* #define DEBUG_MEMORY */ /* */ - -#define DEBUG_MEMORY_LOCATION +/* + * DEBUG_MEMORY_LOCATION should be activated only done when debugging + * libxml. + */ +/* #define DEBUG_MEMORY_LOCATION */ #ifdef DEBUG #ifndef DEBUG_MEMORY @@ -39,17 +22,50 @@ #endif #endif +#ifdef DEBUG_MEMORY_LOCATION #define MEM_LIST /* keep a list of all the allocated memory blocks */ +#endif #ifdef __cplusplus extern "C" { #endif + +/* + * The XML memory wrapper support 4 basic overloadable functions + */ +typedef void (*xmlFreeFunc)(void *); +typedef void *(*xmlMallocFunc)(int); +typedef void *(*xmlReallocFunc)(void *, int); +typedef char *(*xmlStrdupFunc)(const char *); + +/* + * The 4 interfaces used for all memory handling within libxml + */ +extern xmlFreeFunc xmlFree; +extern xmlMallocFunc xmlMalloc; +extern xmlReallocFunc xmlRealloc; +extern xmlStrdupFunc xmlMemStrdup; + +/* + * The way to overload the existing functions + */ +int xmlMemSetup (xmlFreeFunc freeFunc, + xmlMallocFunc mallocFunc, + xmlReallocFunc reallocFunc, + xmlStrdupFunc strdupFunc); +int xmlMemGet (xmlFreeFunc *freeFunc, + xmlMallocFunc *mallocFunc, + xmlReallocFunc *reallocFunc, + xmlStrdupFunc *strdupFunc); + +/* + * Initialization of the memory layer + */ int xmlInitMemory (void); -void * xmlMalloc (int size); -void * xmlRealloc (void *ptr, - int size); -void xmlFree (void *ptr); -char * xmlMemStrdup (const char *str); + +/* + * Those are specific to the XML debug memory wrapper + */ int xmlMemUsed (void); void xmlMemDisplay (FILE *fp); void xmlMemShow (FILE *fp, int nr); @@ -64,11 +80,11 @@ int xmlInitMemory (void); extern void * xmlMallocLoc(int size, const char *file, int line); extern void * xmlReallocLoc(void *ptr,int size, const char *file, int line); extern char * xmlMemStrdupLoc(const char *str, const char *file, int line); +#endif /* DEBUG_MEMORY_LOCATION */ + #ifdef __cplusplus } -#endif -#endif /* DEBUG_MEMORY_LOCATION */ -#endif /* ! NO_DEBUG_MEMORY */ +#endif /* __cplusplus */ #endif /* _DEBUG_MEMORY_ALLOC_ */ diff --git a/xmlmemory.c b/xmlmemory.c index 1013e7e6..24bb97a7 100644 --- a/xmlmemory.c +++ b/xmlmemory.c @@ -32,7 +32,6 @@ #include "xmlmemory.h" -#ifndef NO_DEBUG_MEMORY #ifdef xmlMalloc #undef xmlMalloc #endif @@ -43,7 +42,6 @@ #undef xmlMemStrdup #endif -extern void xmlMemoryDump(void); /* * Each of the blocks allocated begin with a header containing informations @@ -170,7 +168,7 @@ xmlMallocLoc(int size, const char * file, int line) } /** - * xmlMalloc: + * xmlMemMalloc: * @size: an int specifying the size in byte to allocate. * * a malloc() equivalent, with logging of the allocation info. @@ -179,7 +177,7 @@ xmlMallocLoc(int size, const char * file, int line) */ void * -xmlMalloc(int size) +xmlMemMalloc(int size) { return(xmlMallocLoc(size, "none", 0)); } @@ -242,7 +240,7 @@ error: } /** - * xmlRealloc: + * xmlMemRealloc: * @ptr: the initial memory block pointer * @size: an int specifying the size in byte to allocate. * @@ -252,18 +250,18 @@ error: */ void * -xmlRealloc(void *ptr,int size) { +xmlMemRealloc(void *ptr,int size) { return(xmlReallocLoc(ptr, size, "none", 0)); } /** - * xmlFree: + * xmlMemFree: * @ptr: the memory block pointer * * a free() equivalent, with error checking. */ void -xmlFree(void *ptr) +xmlMemFree(void *ptr) { MEMHDR *p; @@ -345,7 +343,7 @@ error: } /** - * xmlMemStrdup: + * xmlMemoryStrdup: * @ptr: the initial string pointer * * a strdup() equivalent, with logging of the allocation info. @@ -354,7 +352,7 @@ error: */ char * -xmlMemStrdup(const char *str) { +xmlMemoryStrdup(const char *str) { return(xmlMemStrdupLoc(str, "none", 0)); } @@ -573,6 +571,7 @@ FILE *xmlMemoryDumpFile = NULL; void xmlMemoryDump(void) { +#if defined(DEBUG_MEMORY_LOCATION) | defined(DEBUG_MEMORY) FILE *dump; dump = fopen(".memdump", "w"); @@ -582,6 +581,7 @@ xmlMemoryDump(void) xmlMemDisplay(xmlMemoryDumpFile); if (dump != NULL) fclose(dump); +#endif } @@ -591,6 +591,18 @@ xmlMemoryDump(void) * * ****************************************************************/ +#if defined(DEBUG_MEMORY_LOCATION) | defined(DEBUG_MEMORY) +xmlFreeFunc xmlFree = (xmlFreeFunc) xmlMemFree; +xmlMallocFunc xmlMalloc = (xmlMallocFunc) xmlMemMalloc; +xmlReallocFunc xmlRealloc = (xmlReallocFunc) xmlMemRealloc; +xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) xmlMemoryStrdup; +#else +xmlFreeFunc xmlFree = (xmlFreeFunc) free; +xmlMallocFunc xmlMalloc = (xmlMallocFunc) malloc; +xmlReallocFunc xmlRealloc = (xmlReallocFunc) realloc; +xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) strdup; +#endif + /** * xmlInitMemory: * @@ -599,6 +611,7 @@ xmlMemoryDump(void) * Returns 0 on success */ +static int xmlInitMemoryDone = 0; int xmlInitMemory(void) @@ -607,7 +620,11 @@ xmlInitMemory(void) #ifdef HAVE_STDLIB_H char *breakpoint; +#endif + if (xmlInitMemoryDone) return(-1); + +#ifdef HAVE_STDLIB_H breakpoint = getenv("XML_MEM_BREAKPOINT"); if (breakpoint != NULL) { sscanf(breakpoint, "%d", &xmlMemStopAtBlock); @@ -621,4 +638,57 @@ xmlInitMemory(void) return(ret); } -#endif /* ! NO_DEBUG_MEMORY */ +/** + * xmlMemSetup: + * @freeFunc: the free() function to use + * @mallocFunc: the malloc() function to use + * @reallocFunc: the realloc() function to use + * @strdupFunc: the strdup() function to use + * + * Override the default memory access functions with a new set + * This has to be called before any other libxml routines ! + * + * Should this be blocked if there was already some allocations + * done ? + * + * Returns 0 on success + */ +int +xmlMemSetup(xmlFreeFunc freeFunc, xmlMallocFunc mallocFunc, + xmlReallocFunc reallocFunc, xmlStrdupFunc strdupFunc) { + if (freeFunc != NULL) + return(-1); + if (mallocFunc != NULL) + return(-1); + if (reallocFunc != NULL) + return(-1); + if (strdupFunc != NULL) + return(-1); + xmlFree = freeFunc; + xmlMalloc = mallocFunc; + xmlRealloc = reallocFunc; + xmlMemStrdup = strdupFunc; + return(0); +} + +/** + * xmlMemGet: + * @freeFunc: the free() function in use + * @mallocFunc: the malloc() function in use + * @reallocFunc: the realloc() function in use + * @strdupFunc: the strdup() function in use + * + * Return the memory access functions set currently in use + * + * Returns 0 on success + */ +int +xmlMemGet(xmlFreeFunc *freeFunc, xmlMallocFunc *mallocFunc, + xmlReallocFunc *reallocFunc, xmlStrdupFunc *strdupFunc) { + if (freeFunc != NULL) *freeFunc = xmlFree; + if (mallocFunc != NULL) *mallocFunc = xmlMalloc; + if (reallocFunc != NULL) *reallocFunc = xmlRealloc; + if (strdupFunc != NULL) *strdupFunc = xmlMemStrdup; + return(0); +} + diff --git a/xmlmemory.h b/xmlmemory.h index 64477a1c..43a92b01 100644 --- a/xmlmemory.h +++ b/xmlmemory.h @@ -8,30 +8,13 @@ #ifndef _DEBUG_MEMORY_ALLOC_ #define _DEBUG_MEMORY_ALLOC_ -#define NO_DEBUG_MEMORY - -#ifdef NO_DEBUG_MEMORY -#ifdef HAVE_MALLOC_H -#include -#endif - -#define xmlFree(x) free((x)) -#define xmlMalloc(x) malloc(x) -#define xmlRealloc(p, x) realloc((p), (x)) -#define xmlMemStrdup(x) strdup((x)) -#define xmlInitMemory() -#define xmlMemUsed() -#define xmlInitMemory() -#define xmlMemoryDump() -#define xmlMemDisplay(x) -#define xmlMemShow(x, d) - -#else /* ! NO_DEBUG_MEMORY */ #include -/* #define DEBUG_MEMORY */ /* */ - -#define DEBUG_MEMORY_LOCATION +/* + * DEBUG_MEMORY_LOCATION should be activated only done when debugging + * libxml. + */ +/* #define DEBUG_MEMORY_LOCATION */ #ifdef DEBUG #ifndef DEBUG_MEMORY @@ -39,17 +22,50 @@ #endif #endif +#ifdef DEBUG_MEMORY_LOCATION #define MEM_LIST /* keep a list of all the allocated memory blocks */ +#endif #ifdef __cplusplus extern "C" { #endif + +/* + * The XML memory wrapper support 4 basic overloadable functions + */ +typedef void (*xmlFreeFunc)(void *); +typedef void *(*xmlMallocFunc)(int); +typedef void *(*xmlReallocFunc)(void *, int); +typedef char *(*xmlStrdupFunc)(const char *); + +/* + * The 4 interfaces used for all memory handling within libxml + */ +extern xmlFreeFunc xmlFree; +extern xmlMallocFunc xmlMalloc; +extern xmlReallocFunc xmlRealloc; +extern xmlStrdupFunc xmlMemStrdup; + +/* + * The way to overload the existing functions + */ +int xmlMemSetup (xmlFreeFunc freeFunc, + xmlMallocFunc mallocFunc, + xmlReallocFunc reallocFunc, + xmlStrdupFunc strdupFunc); +int xmlMemGet (xmlFreeFunc *freeFunc, + xmlMallocFunc *mallocFunc, + xmlReallocFunc *reallocFunc, + xmlStrdupFunc *strdupFunc); + +/* + * Initialization of the memory layer + */ int xmlInitMemory (void); -void * xmlMalloc (int size); -void * xmlRealloc (void *ptr, - int size); -void xmlFree (void *ptr); -char * xmlMemStrdup (const char *str); + +/* + * Those are specific to the XML debug memory wrapper + */ int xmlMemUsed (void); void xmlMemDisplay (FILE *fp); void xmlMemShow (FILE *fp, int nr); @@ -64,11 +80,11 @@ int xmlInitMemory (void); extern void * xmlMallocLoc(int size, const char *file, int line); extern void * xmlReallocLoc(void *ptr,int size, const char *file, int line); extern char * xmlMemStrdupLoc(const char *str, const char *file, int line); +#endif /* DEBUG_MEMORY_LOCATION */ + #ifdef __cplusplus } -#endif -#endif /* DEBUG_MEMORY_LOCATION */ -#endif /* ! NO_DEBUG_MEMORY */ +#endif /* __cplusplus */ #endif /* _DEBUG_MEMORY_ALLOC_ */