You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by kn...@apache.org on 2003/04/30 18:54:41 UTC
cvs commit: xml-xerces/c/src/xercesc/util PlatformUtils.hpp PlatformUtils.cpp
knoaman 2003/04/30 09:54:38
Modified: c/src/xercesc/util PlatformUtils.hpp PlatformUtils.cpp
Log:
Initialize xerces with a default memory manager if none is provided.
Revision Changes Path
1.13 +32 -7 xml-xerces/c/src/xercesc/util/PlatformUtils.hpp
Index: PlatformUtils.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/PlatformUtils.hpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- PlatformUtils.hpp 24 Apr 2003 02:49:36 -0000 1.12
+++ PlatformUtils.hpp 30 Apr 2003 16:54:37 -0000 1.13
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -62,7 +62,6 @@
#if !defined(PLATFORMUTILS_HPP)
#define PLATFORMUTILS_HPP
-#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/util/XMLException.hpp>
#include <xercesc/util/PanicHandler.hpp>
@@ -71,6 +70,7 @@
class XMLMsgLoader;
class XMLNetAccessor;
class XMLTransService;
+class MemoryManager;
//
// For internal use only
@@ -144,6 +144,13 @@
* This is the default panic handler.
*/
static PanicHandler* fgDefaultPanicHandler;
+
+ /** The configurable memory manager
+ *
+ * This is the pluggable memory manager. If it is not provided by an
+ * application, a default implementation is used.
+ */
+ static MemoryManager* fgMemoryManager;
//@}
@@ -176,10 +183,15 @@
* Application shall make sure that the plugged panic handler persists
* through the call to XMLPlatformUtils::terminate().
*
- */
- static void Initialize(const char* const locale = XMLUni::fgXercescDefaultLocale
- , const char* const nlsHome = 0
- , PanicHandler* const panicHandler = 0);
+ * memoryManager: plugged-in memory manager which is owned by user
+ * applications. Applications must make sure that the
+ * plugged-in memory manager persisit through the call to
+ * XMLPlatformUtils::terminate()
+ */
+ static void Initialize(const char* const locale = XMLUni::fgXercescDefaultLocale
+ , const char* const nlsHome = 0
+ , PanicHandler* const panicHandler = 0
+ , MemoryManager* const memoryManager = 0);
/** Perform per-process parser termination
*
@@ -732,6 +744,19 @@
* -1 if no such sequence is found
*/
static int searchSlashDotDotSlash(XMLCh* const srcPath);
+
+ //@}
+
+ /** @name Private static methods */
+ //@{
+
+ /**
+ * Indicates whether the memory manager was supplied by the user
+ * or not. Users own the memory manager, and if none is supplied,
+ * Xerces uses a default one that it owns and is responsible for
+ * deleting in Terminate().
+ */
+ static bool fgMemMgrAdopted;
//@}
};
1.9 +37 -6 xml-xerces/c/src/xercesc/util/PlatformUtils.cpp
Index: PlatformUtils.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/PlatformUtils.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- PlatformUtils.cpp 9 Mar 2003 16:40:47 -0000 1.8
+++ PlatformUtils.cpp 30 Apr 2003 16:54:38 -0000 1.9
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.9 2003/04/30 16:54:38 knoaman
+ * Initialize xerces with a default memory manager if none is provided.
+ *
* Revision 1.8 2003/03/09 16:40:47 peiyongz
* PanicHandler
*
@@ -162,6 +165,7 @@
#include <xercesc/util/RuntimeException.hpp>
#include <xercesc/util/XMLRegisterCleanup.hpp>
#include <xercesc/util/DefaultPanicHandler.hpp>
+#include <xercesc/internal/MemoryManagerImpl.hpp>
#include <limits.h>
@@ -190,7 +194,7 @@
// static data cleanup list
// ---------------------------------------------------------------------------
XMLRegisterCleanup* gXMLCleanupList = 0;
-XMLMutex* gXMLCleanupListMutex = 0;
+XMLMutex* gXMLCleanupListMutex = 0;
// ---------------------------------------------------------------------------
@@ -200,13 +204,16 @@
XMLTransService* XMLPlatformUtils::fgTransService = 0;
PanicHandler* XMLPlatformUtils::fgUserPanicHandler = 0;
PanicHandler* XMLPlatformUtils::fgDefaultPanicHandler = 0;
+MemoryManager* XMLPlatformUtils::fgMemoryManager = 0;
+bool XMLPlatformUtils::fgMemMgrAdopted = true;
// ---------------------------------------------------------------------------
// XMLPlatformUtils: Init/term methods
// ---------------------------------------------------------------------------
-void XMLPlatformUtils::Initialize(const char* const locale
- , const char* const nlsHome
- , PanicHandler* const panicHandler)
+void XMLPlatformUtils::Initialize(const char* const locale
+ , const char* const nlsHome
+ , PanicHandler* const panicHandler
+ , MemoryManager* const memoryManager)
{
//
// Effects of overflow:
@@ -220,6 +227,20 @@
if (gInitFlag == LONG_MAX)
return;
+ // Set pluggable memory manager
+ if (!fgMemoryManager)
+ {
+ if (memoryManager)
+ {
+ fgMemoryManager = memoryManager;
+ fgMemMgrAdopted = false;
+ }
+ else
+ {
+ fgMemoryManager = new MemoryManagerImpl();
+ }
+ }
+
//
// Make sure we haven't already been initialized. Note that this is not
// thread safe and is not intended for that. Its more for those COM
@@ -372,9 +393,19 @@
delete fgDefaultPanicHandler;
}
+ // de-allocate default memory manager
+ if (fgMemMgrAdopted)
+ {
+ delete fgMemoryManager;
+ fgMemoryManager = 0;
+ }
+ else
+ {
+ fgMemMgrAdopted = true;
+ }
+
// And say we are no longer initialized
gInitFlag = 0;
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org