]> granicus.if.org Git - icu/commitdiff
ICU-11538 Remove gHeapInUse flag.
authorAndy Heninger <andy.heninger@gmail.com>
Fri, 27 Feb 2015 23:01:33 +0000 (23:01 +0000)
committerAndy Heninger <andy.heninger@gmail.com>
Fri, 27 Feb 2015 23:01:33 +0000 (23:01 +0000)
X-SVN-Rev: 37097

icu4c/source/common/cmemory.c
icu4c/source/common/cmemory.h
icu4c/source/common/icuplug.cpp
icu4c/source/test/cintltst/hpmufn.c

index cd3ccac6c9be34a93fcd2a24a7ff7d8534f4b0af..232ac300d0f76d2eba20d25c747f4e063ff7679f 100644 (file)
@@ -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;
-}
-
index ed29b63e8f9f736aa278760809fed571e51dd4e7..d182b5aa7d166930069d52423c7a373e72ceb525 100644 (file)
@@ -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()
index 135eb92597439a7deb25bb0336260dfda36c1640..2764ea5ee0560fb733f01b7471d12e6a5918e7fb 100644 (file)
@@ -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);
 }
index a0e2aa154ce159b7d9b571a6879e01792f892ff0..edb7a989ce67670252cfe9bc2559df779ededfff 100644 (file)
@@ -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;