blob: f4a13498fb75b08e86cef96521feaa2ccb7f0b20 [file] [log] [blame]
diff --git a/source/common/cmemory.c b/source/common/cmemory.c
index cd3ccac..42885f2 100644
--- a/source/common/cmemory.c
+++ b/source/common/cmemory.c
@@ -1,7 +1,7 @@
/*
******************************************************************************
*
-* Copyright (C) 2002-2012, International Business Machines
+* Copyright (C) 2002-2015, International Business Machines
* Corporation and others. All Rights Reserved.
*
******************************************************************************
@@ -33,10 +33,6 @@ static UMemAllocFn *pAlloc;
static UMemReallocFn *pRealloc;
static UMemFreeFn *pFree;
-/* Flag indicating whether any heap allocations have happened.
- * Used to prevent changing out the heap functions after allocations have been made */
-static UBool gHeapInUse;
-
#if U_DEBUG && defined(UPRV_MALLOC_COUNT)
#include <stdio.h>
static int n=0;
@@ -78,7 +74,6 @@ uprv_malloc(size_t s) {
#endif
#endif
if (s > 0) {
- gHeapInUse = TRUE;
if (pAlloc) {
return (*pAlloc)(pContext, s);
} else {
@@ -105,7 +100,6 @@ uprv_realloc(void * buffer, size_t size) {
}
return (void *)zeroMem;
} else {
- gHeapInUse = TRUE;
if (pRealloc) {
return (*pRealloc)(pContext, buffer, size);
} else {
@@ -150,10 +144,6 @@ u_setMemoryFunctions(const void *context, UMemAllocFn *a, UMemReallocFn *r, UMem
*status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
- if (gHeapInUse) {
- *status = U_INVALID_STATE_ERROR;
- return;
- }
pContext = context;
pAlloc = a;
pRealloc = r;
@@ -166,18 +156,5 @@ U_CFUNC UBool cmemory_cleanup(void) {
pAlloc = NULL;
pRealloc = NULL;
pFree = NULL;
- gHeapInUse = FALSE;
return TRUE;
}
-
-
-/*
- * gHeapInUse
- * Return True if ICU has allocated any memory.
- * Used by u_SetMutexFunctions() and similar to verify that ICU has not
- * been used, that it is in a pristine initial state.
- */
-U_CFUNC UBool cmemory_inUse() {
- return gHeapInUse;
-}
-
diff --git a/source/common/cmemory.h b/source/common/cmemory.h
index ed29b63..d182b5a 100644
--- a/source/common/cmemory.h
+++ b/source/common/cmemory.h
@@ -1,7 +1,7 @@
/*
******************************************************************************
*
-* Copyright (C) 1997-2014, International Business Machines
+* Copyright (C) 1997-2015, International Business Machines
* Corporation and others. All Rights Reserved.
*
******************************************************************************
@@ -116,13 +116,6 @@ typedef union {
#define U_ALIGNMENT_OFFSET_UP(ptr) (sizeof(UAlignedMemory) - U_ALIGNMENT_OFFSET(ptr))
/**
- * Indicate whether the ICU allocation functions have been used.
- * This is used to determine whether ICU is in an initial, unused state.
- */
-U_CFUNC UBool
-cmemory_inUse(void);
-
-/**
* Heap clean up function, called from u_cleanup()
* Clears any user heap functions from u_setMemoryFunctions()
* Does NOT deallocate any remaining allocated memory.
diff --git a/source/common/icuplug.cpp b/source/common/icuplug.cpp
index 135eb92..2764ea5 100644
--- a/source/common/icuplug.cpp
+++ b/source/common/icuplug.cpp
@@ -1,7 +1,7 @@
/*
******************************************************************************
*
-* Copyright (C) 2009-2014, International Business Machines
+* Copyright (C) 2009-2015, International Business Machines
* Corporation and others. All Rights Reserved.
*
******************************************************************************
@@ -618,12 +618,10 @@ uplug_loadPlugFromLibrary(const char *libName, const char *sym, const char *conf
#endif
+static UPlugLevel gCurrentLevel = UPLUG_LEVEL_LOW;
+
U_CAPI UPlugLevel U_EXPORT2 uplug_getCurrentLevel() {
- if(cmemory_inUse()) {
- return UPLUG_LEVEL_HIGH;
- } else {
- return UPLUG_LEVEL_LOW;
- }
+ return gCurrentLevel;
}
static UBool U_CALLCONV uplug_cleanup(void)
@@ -639,6 +637,7 @@ static UBool U_CALLCONV uplug_cleanup(void)
uplug_doUnloadPlug(pluginToRemove, &subStatus);
}
/* close other held libs? */
+ gCurrentLevel = UPLUG_LEVEL_LOW;
return TRUE;
}
@@ -710,6 +709,8 @@ uplug_getPluginFile() {
}
+// uplug_init() is called first thing from u_init().
+
U_CAPI void U_EXPORT2
uplug_init(UErrorCode *status) {
#if !U_ENABLE_DYLOAD
@@ -866,5 +867,6 @@ uplug_init(UErrorCode *status) {
}
uplug_loadWaitingPlugs(status);
#endif /* U_ENABLE_DYLOAD */
+ gCurrentLevel = UPLUG_LEVEL_HIGH;
ucln_registerCleanup(UCLN_UPLUG, uplug_cleanup);
}
diff --git a/source/test/cintltst/hpmufn.c b/source/test/cintltst/hpmufn.c
index a0e2aa1..edb7a98 100644
--- a/source/test/cintltst/hpmufn.c
+++ b/source/test/cintltst/hpmufn.c
@@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
- * Copyright (c) 2003-2013, International Business Machines Corporation and
+ * Copyright (c) 2003-2015, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/*
@@ -129,10 +129,6 @@ static void TestHeapFunctions() {
* probably because some earlier test accidently left something open. */
ctest_resetICU();
- /* Can not set memory functions if ICU is already initialized */
- u_setMemoryFunctions(&gContext, myMemAlloc, myMemRealloc, myMemFree, &status);
- TEST_STATUS(status, U_INVALID_STATE_ERROR);
-
/* Un-initialize ICU */
u_cleanup();
@@ -155,13 +151,11 @@ static void TestHeapFunctions() {
TEST_STATUS(status, U_ZERO_ERROR);
- /* After reinitializing ICU, we should not be able to set the memory funcs again. */
+ /* After reinitializing ICU, we can not set the memory funcs again. */
status = U_ZERO_ERROR;
u_setDataDirectory(icuDataDir);
u_init(&status);
TEST_STATUS(status, U_ZERO_ERROR);
- u_setMemoryFunctions(NULL, myMemAlloc, myMemRealloc, myMemFree, &status);
- TEST_STATUS(status, U_INVALID_STATE_ERROR);
/* Doing ICU operations should cause allocations to come through our test heap */
gBlockCount = 0;