From fb24cef93dba5c11296f45ac040e72dffc8a7a98 Mon Sep 17 00:00:00 2001 From: Andy Heninger Date: Fri, 27 Feb 2015 23:01:33 +0000 Subject: [PATCH] ICU-11538 Remove gHeapInUse flag. X-SVN-Rev: 37097 --- icu4c/source/common/cmemory.c | 21 +-------------------- icu4c/source/common/cmemory.h | 9 +-------- icu4c/source/common/icuplug.cpp | 14 ++++++++------ icu4c/source/test/cintltst/hpmufn.c | 10 ++-------- 4 files changed, 12 insertions(+), 42 deletions(-) diff --git a/icu4c/source/common/cmemory.c b/icu4c/source/common/cmemory.c index cd3ccac6c9b..232ac300d0f 100644 --- a/icu4c/source/common/cmemory.c +++ b/icu4c/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. * ****************************************************************************** @@ -78,7 +78,6 @@ uprv_malloc(size_t s) { #endif #endif if (s > 0) { - gHeapInUse = TRUE; if (pAlloc) { return (*pAlloc)(pContext, s); } else { @@ -105,7 +104,6 @@ uprv_realloc(void * buffer, size_t size) { } return (void *)zeroMem; } else { - gHeapInUse = TRUE; if (pRealloc) { return (*pRealloc)(pContext, buffer, size); } else { @@ -150,10 +148,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 +160,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/icu4c/source/common/cmemory.h b/icu4c/source/common/cmemory.h index ed29b63e8f9..d182b5aa7d1 100644 --- a/icu4c/source/common/cmemory.h +++ b/icu4c/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. * ****************************************************************************** @@ -115,13 +115,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() diff --git a/icu4c/source/common/icuplug.cpp b/icu4c/source/common/icuplug.cpp index 135eb925974..2764ea5ee05 100644 --- a/icu4c/source/common/icuplug.cpp +++ b/icu4c/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/icu4c/source/test/cintltst/hpmufn.c b/icu4c/source/test/cintltst/hpmufn.c index a0e2aa154ce..edb7a989ce6 100644 --- a/icu4c/source/test/cintltst/hpmufn.c +++ b/icu4c/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;