diff options
-rw-r--r-- | sal/rtl/alloc_arena.cxx | 78 | ||||
-rw-r--r-- | sal/rtl/alloc_cache.cxx | 147 | ||||
-rw-r--r-- | sal/rtl/alloc_global.cxx | 24 |
3 files changed, 127 insertions, 122 deletions
diff --git a/sal/rtl/alloc_arena.cxx b/sal/rtl/alloc_arena.cxx index 0e4aed5e2a31..7baa46f0cf36 100644 --- a/sal/rtl/alloc_arena.cxx +++ b/sal/rtl/alloc_arena.cxx @@ -100,7 +100,7 @@ bool rtl_arena_segment_populate(rtl_arena_type * arena) span = static_cast< rtl_arena_segment_type * >( rtl_machdep_alloc(gp_machdep_arena, &size)); - if (span != nullptr) + if (span) { rtl_arena_segment_type *first, *last, *head; sal_Size count = size / sizeof(rtl_arena_segment_type); @@ -137,7 +137,7 @@ inline void rtl_arena_segment_get( { rtl_arena_segment_type * head; - assert(*ppSegment == nullptr); + assert(!*ppSegment); head = &(arena->m_segment_reserve_head); if ((head->m_snext != head) || rtl_arena_segment_populate (arena)) @@ -234,7 +234,7 @@ void rtl_arena_hash_rescale( new_bytes = new_size * sizeof(rtl_arena_segment_type*); new_table = static_cast<rtl_arena_segment_type **>(rtl_arena_alloc (gp_arena_arena, &new_bytes)); - if (new_table != nullptr) + if (new_table) { rtl_arena_segment_type ** old_table; sal_Size old_size, i; @@ -253,7 +253,7 @@ void rtl_arena_hash_rescale( for (i = 0; i < old_size; i++) { rtl_arena_segment_type * curr = old_table[i]; - while (curr != nullptr) + while (curr) { rtl_arena_segment_type * next = curr->m_fnext; rtl_arena_segment_type ** head; @@ -310,7 +310,7 @@ rtl_arena_segment_type * rtl_arena_hash_remove( sal_Size lookups = 0; segpp = &(arena->m_hash_table[RTL_ARENA_HASH_INDEX(arena, addr)]); - while ((segment = *segpp) != nullptr) + while ((segment = *segpp)) { if (segment->m_addr == addr) { @@ -324,8 +324,8 @@ rtl_arena_segment_type * rtl_arena_hash_remove( segpp = &(segment->m_fnext); } - assert(segment != nullptr); // bad free - if (segment != nullptr) + assert(segment); // bad free + if (segment) { assert(segment->m_size == size); (void) size; // avoid warnings @@ -371,7 +371,7 @@ bool rtl_arena_segment_alloc( { int index = 0; - assert(*ppSegment == nullptr); + assert(!*ppSegment); if (!RTL_MEMORY_ISP2(size)) { unsigned int msb = highbit(size); @@ -409,7 +409,7 @@ bool rtl_arena_segment_alloc( } dequeue_and_leave: - if (*ppSegment != nullptr) + if (*ppSegment) { /* remove from freelist */ rtl_arena_freelist_remove (arena, (*ppSegment)); @@ -429,15 +429,15 @@ int rtl_arena_segment_create( rtl_arena_segment_type ** ppSegment ) { - assert((*ppSegment) == nullptr); - if (arena->m_source_alloc != nullptr) + assert(!*ppSegment); + if (arena->m_source_alloc) { rtl_arena_segment_get (arena, ppSegment); - if (*ppSegment != nullptr) + if (*ppSegment) { rtl_arena_segment_type * span = nullptr; rtl_arena_segment_get (arena, &span); - if (span != nullptr) + if (span) { /* import new span from source arena */ RTL_MEMORY_LOCK_RELEASE(&(arena->m_lock)); @@ -613,8 +613,8 @@ rtl_arena_type * rtl_arena_activate( void (SAL_CALL * source_free) (rtl_arena_type *, void *, sal_Size) ) { - assert(arena != nullptr); - if (arena != nullptr) + assert(arena); + if (arena) { (void) snprintf (arena->m_name, sizeof(arena->m_name), "%s", name); @@ -674,15 +674,15 @@ void rtl_arena_deactivate(rtl_arena_type * arena) RTL_MEMORY_LOCK_RELEASE(&(g_arena_list.m_lock)); /* cleanup quantum cache(s) */ - if ((arena->m_qcache_max > 0) && (arena->m_qcache_ptr != nullptr)) + if ((arena->m_qcache_max > 0) && (arena->m_qcache_ptr)) { int i, n = (arena->m_qcache_max >> arena->m_quantum_shift); for (i = 1; i <= n; i++) { - if (arena->m_qcache_ptr[i - 1] != nullptr) + if (arena->m_qcache_ptr[i-1]) { - rtl_cache_destroy (arena->m_qcache_ptr[i - 1]); - arena->m_qcache_ptr[i - 1] = nullptr; + rtl_cache_destroy (arena->m_qcache_ptr[i-1]); + arena->m_qcache_ptr[i-1] = nullptr; } } rtl_arena_free ( @@ -701,7 +701,7 @@ void rtl_arena_deactivate(rtl_arena_type * arena) /* cleanup still used segment(s) */ for (i = 0, n = arena->m_hash_size; i < n; i++) { - while ((segment = arena->m_hash_table[i]) != nullptr) + while ((segment = arena->m_hash_table[i])) { /* pop from hash table */ arena->m_hash_table[i] = segment->m_fnext; @@ -791,14 +791,14 @@ rtl_arena_type * SAL_CALL rtl_arena_create( try_alloc: result = static_cast<rtl_arena_type*>(rtl_arena_alloc (gp_arena_arena, &size)); - if (result != nullptr) + if (result) { rtl_arena_type * arena = result; rtl_arena_constructor (arena); if (!source_arena) { - assert(gp_default_arena != nullptr); + assert(gp_default_arena); source_arena = gp_default_arena; } @@ -812,14 +812,14 @@ try_alloc: source_free ); - if (result == nullptr) + if (!result) { rtl_arena_deactivate (arena); rtl_arena_destructor (arena); rtl_arena_free (gp_arena_arena, arena, size); } } - else if (gp_arena_arena == nullptr) + else if (!gp_arena_arena) { ensureArenaSingleton(); if (gp_arena_arena) @@ -833,7 +833,7 @@ try_alloc: void SAL_CALL rtl_arena_destroy(rtl_arena_type * arena) SAL_THROW_EXTERN_C() { - if (arena != nullptr) + if (arena) { rtl_arena_deactivate (arena); rtl_arena_destructor (arena); @@ -848,7 +848,7 @@ void * SAL_CALL rtl_arena_alloc( { void * addr = nullptr; - if ((arena != nullptr) && (pSize != nullptr)) + if (arena && pSize) { sal_Size size; @@ -876,7 +876,7 @@ void * SAL_CALL rtl_arena_alloc( { rtl_arena_segment_type * remainder = nullptr; rtl_arena_segment_get (arena, &remainder); - if (remainder != nullptr) + if (remainder) { segment->m_size = size; @@ -900,10 +900,10 @@ void * SAL_CALL rtl_arena_alloc( { /* allocate from quantum cache(s) */ int index = (size >> arena->m_quantum_shift) - 1; - assert(arena->m_qcache_ptr[index] != nullptr); + assert(arena->m_qcache_ptr[index]); addr = rtl_cache_alloc (arena->m_qcache_ptr[index]); - if (addr != nullptr) + if (addr) (*pSize) = size; } } @@ -916,7 +916,7 @@ void SAL_CALL rtl_arena_free ( sal_Size size ) SAL_THROW_EXTERN_C() { - if (arena != nullptr) + if (arena) { size = RTL_MEMORY_ALIGN(size, arena->m_quantum); if (size > arena->m_qcache_max) @@ -927,7 +927,7 @@ void SAL_CALL rtl_arena_free ( RTL_MEMORY_LOCK_ACQUIRE(&(arena->m_lock)); segment = rtl_arena_hash_remove (arena, reinterpret_cast<sal_uIntPtr>(addr), size); - if (segment != nullptr) + if (segment) { rtl_arena_segment_type *next, *prev; @@ -983,7 +983,7 @@ void SAL_CALL rtl_arena_free ( { /* free to quantum cache(s) */ int index = (size >> arena->m_quantum_shift) - 1; - assert(arena->m_qcache_ptr[index] != nullptr); + assert(arena->m_qcache_ptr[index]); rtl_cache_free (arena->m_qcache_ptr[index], addr); } @@ -1096,7 +1096,7 @@ void rtl_arena_init() /* machdep (pseudo) arena */ static rtl_arena_type g_machdep_arena; - assert(gp_machdep_arena == nullptr); + assert(!gp_machdep_arena); rtl_arena_constructor (&g_machdep_arena); gp_machdep_arena = rtl_arena_activate ( @@ -1106,13 +1106,13 @@ void rtl_arena_init() 0, /* no quantum caching */ nullptr, nullptr, nullptr /* no source */ ); - assert(gp_machdep_arena != nullptr); + assert(gp_machdep_arena); } { /* default arena */ static rtl_arena_type g_default_arena; - assert(gp_default_arena == nullptr); + assert(!gp_default_arena); rtl_arena_constructor (&g_default_arena); gp_default_arena = rtl_arena_activate ( @@ -1124,13 +1124,13 @@ void rtl_arena_init() rtl_machdep_alloc, rtl_machdep_free ); - assert(gp_default_arena != nullptr); + assert(gp_default_arena); } { /* arena internal arena */ static rtl_arena_type g_arena_arena; - assert(gp_arena_arena == nullptr); + assert(!gp_arena_arena); rtl_arena_constructor (&g_arena_arena); gp_arena_arena = rtl_arena_activate( @@ -1142,13 +1142,13 @@ void rtl_arena_init() rtl_arena_alloc, rtl_arena_free ); - assert(gp_arena_arena != nullptr); + assert(gp_arena_arena); } } void rtl_arena_fini() { - if (gp_arena_arena != nullptr) + if (gp_arena_arena) { rtl_arena_type * arena, * head; diff --git a/sal/rtl/alloc_cache.cxx b/sal/rtl/alloc_cache.cxx index 4dfa1eb966c4..04a982d99bc9 100644 --- a/sal/rtl/alloc_cache.cxx +++ b/sal/rtl/alloc_cache.cxx @@ -94,7 +94,7 @@ void rtl_cache_hash_rescale( new_bytes = new_size * sizeof(rtl_cache_bufctl_type*); new_table = static_cast<rtl_cache_bufctl_type**>(rtl_arena_alloc(gp_cache_arena, &new_bytes)); - if (new_table != nullptr) + if (new_table) { rtl_cache_bufctl_type ** old_table; sal_Size old_size, i; @@ -115,7 +115,7 @@ void rtl_cache_hash_rescale( for (i = 0; i < old_size; i++) { rtl_cache_bufctl_type * curr = old_table[i]; - while (curr != nullptr) + while (curr) { rtl_cache_bufctl_type * next = curr->m_next; rtl_cache_bufctl_type ** head; @@ -164,7 +164,7 @@ rtl_cache_bufctl_type * rtl_cache_hash_remove( sal_Size lookups = 0; ppHead = &(cache->m_hash_table[RTL_CACHE_HASH_INDEX(cache, addr)]); - while ((bufctl = *ppHead) != nullptr) + while ((bufctl = *ppHead)) { if (bufctl->m_addr == addr) { @@ -177,7 +177,7 @@ rtl_cache_bufctl_type * rtl_cache_hash_remove( ppHead = &(bufctl->m_next); } - assert(bufctl != nullptr); // bad free + assert(bufctl); // bad free if (lookups > 1) { @@ -235,7 +235,7 @@ rtl_cache_slab_type * rtl_cache_slab_create(rtl_cache_type * cache) size = cache->m_slab_size; addr = rtl_arena_alloc (cache->m_source, &size); - if (SAL_LIKELY(addr != nullptr)) + if (SAL_LIKELY(addr)) { assert(size >= cache->m_slab_size); @@ -251,7 +251,7 @@ rtl_cache_slab_type * rtl_cache_slab_create(rtl_cache_type * cache) slab = RTL_CACHE_SLAB(addr, cache->m_slab_size); (void) rtl_cache_slab_constructor (slab, nullptr); } - if (SAL_LIKELY(slab != nullptr)) + if (SAL_LIKELY(slab)) { slab->m_data = reinterpret_cast<sal_uIntPtr>(addr); @@ -282,7 +282,7 @@ void rtl_cache_slab_destroy( { /* cleanup bufctl(s) for free buffer(s) */ sal_Size ntypes = (slab->m_bp - slab->m_data) / cache->m_type_size; - for (ntypes -= refcnt; slab->m_sp != nullptr; ntypes--) + for (ntypes -= refcnt; slab->m_sp; ntypes--) { rtl_cache_bufctl_type * bufctl = slab->m_sp; @@ -321,7 +321,7 @@ bool rtl_cache_slab_populate(rtl_cache_type * cache) RTL_MEMORY_LOCK_RELEASE(&(cache->m_slab_lock)); slab = rtl_cache_slab_create (cache); RTL_MEMORY_LOCK_ACQUIRE(&(cache->m_slab_lock)); - if (slab != nullptr) + if (slab) { /* update buffer start addr w/ current color */ slab->m_bp += cache->m_ncolor; @@ -359,7 +359,7 @@ void * rtl_cache_slab_alloc (rtl_cache_type * cache) slab = head->m_slab_next; assert(slab->m_ntypes < cache->m_ntypes); - if (slab->m_sp == nullptr) + if (!slab->m_sp) { /* initialize bufctl w/ current 'slab->m_bp' */ assert(slab->m_bp < slab->m_data + cache->m_ntypes * cache->m_type_size + cache->m_ncolor_max); @@ -368,7 +368,7 @@ void * rtl_cache_slab_alloc (rtl_cache_type * cache) /* allocate bufctl */ assert(cache != gp_cache_bufctl_cache); bufctl = static_cast<rtl_cache_bufctl_type*>(rtl_cache_alloc (gp_cache_bufctl_cache)); - if (bufctl == nullptr) + if (!bufctl) { /* out of memory */ RTL_MEMORY_LOCK_RELEASE(&(cache->m_slab_lock)); @@ -446,7 +446,7 @@ void rtl_cache_slab_free( slab = RTL_CACHE_SLAB(addr, cache->m_slab_size); } - if (slab != nullptr) + if (slab) { /* check for full slab */ if (slab->m_ntypes == cache->m_ntypes) @@ -501,7 +501,7 @@ void rtl_cache_magazine_destructor(void * obj, SAL_UNUSED_PARAMETER void *) { rtl_cache_magazine_type * mag = static_cast< rtl_cache_magazine_type * >( obj); - assert(mag->m_mag_next == nullptr); // assure removed from queue(s) + assert(!mag->m_mag_next); // assure removed from queue(s) assert(mag->m_mag_used == 0); // assure no longer referenced (void) mag; // avoid warnings } @@ -513,10 +513,10 @@ void rtl_cache_magazine_clear( { for (; mag->m_mag_used > 0; --mag->m_mag_used) { - void * obj = mag->m_objects[mag->m_mag_used - 1]; - mag->m_objects[mag->m_mag_used - 1] = nullptr; + void * obj = mag->m_objects[mag->m_mag_used-1]; + mag->m_objects[mag->m_mag_used-1] = nullptr; - if (cache->m_destructor != nullptr) + if (cache->m_destructor) { /* destruct object */ (cache->m_destructor)(obj, cache->m_userarg); @@ -554,7 +554,7 @@ inline rtl_cache_magazine_type * rtl_cache_depot_dequeue( if (depot->m_mag_count > 0) { /* dequeue magazine */ - assert(depot->m_mag_next != nullptr); + assert(depot->m_mag_next); mag = depot->m_mag_next; depot->m_mag_next = mag->m_mag_next; @@ -580,17 +580,17 @@ inline rtl_cache_magazine_type * rtl_cache_depot_exchange_alloc( { rtl_cache_magazine_type * full; - assert((empty == nullptr) || (empty->m_mag_used == 0)); + assert((!empty) || (empty->m_mag_used == 0)); /* dequeue full magazine */ full = rtl_cache_depot_dequeue (&(cache->m_depot_full)); - if ((full != nullptr) && (empty != nullptr)) + if (full && empty) { /* enqueue empty magazine */ rtl_cache_depot_enqueue (&(cache->m_depot_empty), empty); } - assert((full == nullptr) || (full->m_mag_used > 0)); + assert(!full || (full->m_mag_used > 0)); return full; } @@ -605,17 +605,17 @@ inline rtl_cache_magazine_type * rtl_cache_depot_exchange_free( { rtl_cache_magazine_type * empty; - assert((full == nullptr) || (full->m_mag_used > 0)); + assert(!full || (full->m_mag_used > 0)); /* dequeue empty magazine */ empty = rtl_cache_depot_dequeue (&(cache->m_depot_empty)); - if ((empty != nullptr) && (full != nullptr)) + if (empty && full) { /* enqueue full magazine */ rtl_cache_depot_enqueue (&(cache->m_depot_full), full); } - assert((empty == nullptr) || (empty->m_mag_used == 0)); + assert(!empty || (empty->m_mag_used == 0)); return empty; } @@ -627,13 +627,13 @@ bool rtl_cache_depot_populate(rtl_cache_type * cache) { rtl_cache_magazine_type * empty = nullptr; - if (cache->m_magazine_cache != nullptr) + if (cache->m_magazine_cache) { /* allocate new empty magazine */ RTL_MEMORY_LOCK_RELEASE(&(cache->m_depot_lock)); empty = static_cast<rtl_cache_magazine_type*>(rtl_cache_alloc (cache->m_magazine_cache)); RTL_MEMORY_LOCK_ACQUIRE(&(cache->m_depot_lock)); - if (empty != nullptr) + if (empty) { /* enqueue (new) empty magazine */ rtl_cache_depot_enqueue (&(cache->m_depot_empty), empty); @@ -700,8 +700,8 @@ rtl_cache_type * rtl_cache_activate( int flags ) { - assert(cache != nullptr); - if (cache != nullptr) + assert(cache); + if (cache) { sal_Size slabsize; @@ -767,8 +767,8 @@ rtl_cache_type * rtl_cache_activate( if (cache->m_slab_size > source->m_quantum) { - assert(gp_cache_slab_cache != nullptr); - assert(gp_cache_bufctl_cache != nullptr); + assert(gp_cache_slab_cache); + assert(gp_cache_bufctl_cache); cache->m_features |= RTL_CACHE_FEATURE_HASH; cache->m_ntypes = cache->m_slab_size / cache->m_type_size; @@ -793,7 +793,7 @@ rtl_cache_type * rtl_cache_activate( /* magazine layer */ if (!(flags & RTL_CACHE_FLAG_NOMAGAZINE)) { - assert(gp_cache_magazine_cache != nullptr); + assert(gp_cache_magazine_cache); cache->m_magazine_cache = gp_cache_magazine_cache; } @@ -817,7 +817,7 @@ void rtl_cache_deactivate(rtl_cache_type * cache) (void)active; /* cleanup magazine layer */ - if (cache->m_magazine_cache != nullptr) + if (cache->m_magazine_cache) { rtl_cache_type * mag_cache; rtl_cache_magazine_type * mag; @@ -827,14 +827,15 @@ void rtl_cache_deactivate(rtl_cache_type * cache) cache->m_magazine_cache = nullptr; /* cleanup cpu layer */ - if ((mag = cache->m_cpu_curr) != nullptr) + if ((mag = cache->m_cpu_curr)) { // coverity[missing_lock] cache->m_cpu_curr = nullptr; rtl_cache_magazine_clear (cache, mag); rtl_cache_free (mag_cache, mag); } - if ((mag = cache->m_cpu_prev) != nullptr) + + if ((mag = cache->m_cpu_prev)) { // coverity[missing_lock] cache->m_cpu_prev = nullptr; @@ -843,12 +844,13 @@ void rtl_cache_deactivate(rtl_cache_type * cache) } /* cleanup depot layer */ - while ((mag = rtl_cache_depot_dequeue(&(cache->m_depot_full))) != nullptr) + while ((mag = rtl_cache_depot_dequeue(&(cache->m_depot_full)))) { rtl_cache_magazine_clear (cache, mag); rtl_cache_free (mag_cache, mag); } - while ((mag = rtl_cache_depot_dequeue(&(cache->m_depot_empty))) != nullptr) + + while ((mag = rtl_cache_depot_dequeue(&(cache->m_depot_empty)))) { rtl_cache_magazine_clear (cache, mag); rtl_cache_free (mag_cache, mag); @@ -865,7 +867,7 @@ void rtl_cache_deactivate(rtl_cache_type * cache) for (i = 0; i < n; i++) { rtl_cache_bufctl_type * bufctl; - while ((bufctl = cache->m_hash_table[i]) != nullptr) + while ((bufctl = cache->m_hash_table[i])) { /* pop from hash table */ cache->m_hash_table[i] = bufctl->m_next; @@ -940,7 +942,7 @@ rtl_cache_type * SAL_CALL rtl_cache_create( try_alloc: result = static_cast<rtl_cache_type*>(rtl_arena_alloc (gp_cache_arena, &size)); - if (result != nullptr) + if (result) { rtl_cache_type * cache = result; (void) rtl_cache_constructor (cache); @@ -948,7 +950,7 @@ try_alloc: if (!source) { /* use default arena */ - assert(gp_default_arena != nullptr); + assert(gp_default_arena); source = gp_default_arena; } @@ -964,7 +966,7 @@ try_alloc: flags ); - if (result == nullptr) + if (!result) { /* activation failed */ rtl_cache_deactivate (cache); @@ -972,7 +974,7 @@ try_alloc: rtl_arena_free (gp_cache_arena, cache, size); } } - else if (gp_cache_arena == nullptr) + else if (!gp_cache_arena) { ensureCacheSingleton(); if (gp_cache_arena) @@ -986,7 +988,7 @@ try_alloc: void SAL_CALL rtl_cache_destroy(rtl_cache_type * cache) SAL_THROW_EXTERN_C() { - if (cache != nullptr) + if (cache) { rtl_cache_deactivate (cache); rtl_cache_destructor (cache); @@ -998,15 +1000,15 @@ void * SAL_CALL rtl_cache_alloc(rtl_cache_type * cache) SAL_THROW_EXTERN_C() { void * obj = nullptr; - if (cache == nullptr) + if (!cache) return nullptr; if (alloc_mode == AllocMode::SYSTEM) { obj = rtl_allocateMemory(cache->m_type_size); - if ((obj != nullptr) && (cache->m_constructor != nullptr)) + if (obj && cache->m_constructor) { - if (!((cache->m_constructor)(obj, cache->m_userarg))) + if (!(cache->m_constructor)(obj, cache->m_userarg)) { /* construction failure */ rtl_freeMemory(obj); @@ -1017,7 +1019,7 @@ void * SAL_CALL rtl_cache_alloc(rtl_cache_type * cache) SAL_THROW_EXTERN_C() } RTL_MEMORY_LOCK_ACQUIRE(&(cache->m_depot_lock)); - if (SAL_LIKELY(cache->m_cpu_curr != nullptr)) + if (SAL_LIKELY(cache->m_cpu_curr)) { for (;;) { @@ -1025,7 +1027,7 @@ void * SAL_CALL rtl_cache_alloc(rtl_cache_type * cache) SAL_THROW_EXTERN_C() rtl_cache_magazine_type *curr, *prev, *temp; curr = cache->m_cpu_curr; - if ((curr != nullptr) && (curr->m_mag_used > 0)) + if (curr && (curr->m_mag_used > 0)) { obj = curr->m_objects[--curr->m_mag_used]; cache->m_cpu_stats.m_alloc += 1; @@ -1035,7 +1037,7 @@ void * SAL_CALL rtl_cache_alloc(rtl_cache_type * cache) SAL_THROW_EXTERN_C() } prev = cache->m_cpu_prev; - if ((prev != nullptr) && (prev->m_mag_used > 0)) + if (prev && (prev->m_mag_used > 0)) { temp = cache->m_cpu_curr; cache->m_cpu_curr = cache->m_cpu_prev; @@ -1045,7 +1047,7 @@ void * SAL_CALL rtl_cache_alloc(rtl_cache_type * cache) SAL_THROW_EXTERN_C() } temp = rtl_cache_depot_exchange_alloc (cache, prev); - if (temp != nullptr) + if (temp) { cache->m_cpu_prev = cache->m_cpu_curr; cache->m_cpu_curr = temp; @@ -1061,10 +1063,10 @@ void * SAL_CALL rtl_cache_alloc(rtl_cache_type * cache) SAL_THROW_EXTERN_C() /* alloc buffer from slab layer */ obj = rtl_cache_slab_alloc (cache); - if ((obj != nullptr) && (cache->m_constructor != nullptr)) + if (obj && (cache->m_constructor)) { /* construct object */ - if (!((cache->m_constructor)(obj, cache->m_userarg))) + if (!(cache->m_constructor)(obj, cache->m_userarg)) { /* construction failure */ rtl_cache_slab_free (cache, obj); @@ -1079,11 +1081,11 @@ void SAL_CALL rtl_cache_free( void * obj ) SAL_THROW_EXTERN_C() { - if ((obj != nullptr) && (cache != nullptr)) + if (obj && cache) { if (alloc_mode == AllocMode::SYSTEM) { - if (cache->m_destructor != nullptr) + if (cache->m_destructor) { /* destruct object */ (cache->m_destructor)(obj, cache->m_userarg); @@ -1100,7 +1102,7 @@ void SAL_CALL rtl_cache_free( rtl_cache_magazine_type *curr, *prev, *temp; curr = cache->m_cpu_curr; - if ((curr != nullptr) && (curr->m_mag_used < curr->m_mag_size)) + if (curr && (curr->m_mag_used < curr->m_mag_size)) { curr->m_objects[curr->m_mag_used++] = obj; cache->m_cpu_stats.m_free += 1; @@ -1110,7 +1112,7 @@ void SAL_CALL rtl_cache_free( } prev = cache->m_cpu_prev; - if ((prev != nullptr) && (prev->m_mag_used == 0)) + if (prev && (prev->m_mag_used == 0)) { temp = cache->m_cpu_curr; cache->m_cpu_curr = cache->m_cpu_prev; @@ -1120,7 +1122,7 @@ void SAL_CALL rtl_cache_free( } temp = rtl_cache_depot_exchange_free (cache, prev); - if (temp != nullptr) + if (temp) { cache->m_cpu_prev = cache->m_cpu_curr; cache->m_cpu_curr = temp; @@ -1140,7 +1142,7 @@ void SAL_CALL rtl_cache_free( RTL_MEMORY_LOCK_RELEASE(&(cache->m_depot_lock)); /* no space for constructed object in magazine layer */ - if (cache->m_destructor != nullptr) + if (cache->m_destructor) { /* destruct object */ (cache->m_destructor)(obj, cache->m_userarg); @@ -1269,7 +1271,7 @@ static void rtl_cache_depot_wsupdate( for (; npurge > 0; npurge--) { rtl_cache_magazine_type * mag = rtl_cache_depot_dequeue (depot); - if (mag != nullptr) + if (mag) { RTL_MEMORY_LOCK_RELEASE(&(cache->m_depot_lock)); rtl_cache_magazine_clear (cache, mag); @@ -1285,7 +1287,7 @@ static void rtl_cache_depot_wsupdate( */ static void rtl_cache_wsupdate(rtl_cache_type * cache) { - if (cache->m_magazine_cache != nullptr) + if (cache->m_magazine_cache) { RTL_MEMORY_LOCK_ACQUIRE(&(cache->m_depot_lock)); @@ -1342,7 +1344,7 @@ void rtl_cache_init() } { /* cache: internal arena */ - assert(gp_cache_arena == nullptr); + assert(!gp_cache_arena); gp_cache_arena = rtl_arena_create ( "rtl_cache_internal_arena", @@ -1353,16 +1355,16 @@ void rtl_cache_init() rtl_arena_free, 0 /* flags */ ); - assert(gp_cache_arena != nullptr); + assert(gp_cache_arena); /* check 'gp_default_arena' initialization */ - assert(gp_default_arena != nullptr); + assert(gp_default_arena); } { /* cache: magazine cache */ static rtl_cache_type g_cache_magazine_cache; - assert(gp_cache_magazine_cache == nullptr); + assert(!gp_cache_magazine_cache); (void) rtl_cache_constructor (&g_cache_magazine_cache); gp_cache_magazine_cache = rtl_cache_activate ( @@ -1376,7 +1378,7 @@ void rtl_cache_init() gp_default_arena, /* source */ RTL_CACHE_FLAG_NOMAGAZINE /* during bootstrap; activated below */ ); - assert(gp_cache_magazine_cache != nullptr); + assert(gp_cache_magazine_cache); /* activate magazine layer */ g_cache_magazine_cache.m_magazine_cache = gp_cache_magazine_cache; @@ -1385,7 +1387,7 @@ void rtl_cache_init() /* cache: slab (struct) cache */ static rtl_cache_type g_cache_slab_cache; - assert(gp_cache_slab_cache == nullptr); + assert(!gp_cache_slab_cache); (void) rtl_cache_constructor (&g_cache_slab_cache); gp_cache_slab_cache = rtl_cache_activate ( @@ -1399,13 +1401,13 @@ void rtl_cache_init() gp_default_arena, /* source */ 0 /* flags: none */ ); - assert(gp_cache_slab_cache != nullptr); + assert(gp_cache_slab_cache); } { /* cache: bufctl cache */ static rtl_cache_type g_cache_bufctl_cache; - assert(gp_cache_bufctl_cache == nullptr); + assert(!gp_cache_bufctl_cache); (void) rtl_cache_constructor (&g_cache_bufctl_cache); gp_cache_bufctl_cache = rtl_cache_activate ( @@ -1419,7 +1421,7 @@ void rtl_cache_init() gp_default_arena, /* source */ 0 /* flags: none */ ); - assert(gp_cache_bufctl_cache != nullptr); + assert(gp_cache_bufctl_cache); } rtl_cache_wsupdate_init(); @@ -1427,34 +1429,37 @@ void rtl_cache_init() void rtl_cache_fini() { - if (gp_cache_arena != nullptr) + if (gp_cache_arena) { rtl_cache_type * cache, * head; rtl_cache_wsupdate_fini(); - if (gp_cache_bufctl_cache != nullptr) + if (gp_cache_bufctl_cache) { cache = gp_cache_bufctl_cache; gp_cache_bufctl_cache = nullptr; rtl_cache_deactivate (cache); rtl_cache_destructor (cache); } - if (gp_cache_slab_cache != nullptr) + + if (gp_cache_slab_cache) { cache = gp_cache_slab_cache; gp_cache_slab_cache = nullptr; rtl_cache_deactivate (cache); rtl_cache_destructor (cache); } - if (gp_cache_magazine_cache != nullptr) + + if (gp_cache_magazine_cache) { cache = gp_cache_magazine_cache; gp_cache_magazine_cache = nullptr; rtl_cache_deactivate (cache); rtl_cache_destructor (cache); } - if (gp_cache_arena != nullptr) + + if (gp_cache_arena) { rtl_arena_destroy (gp_cache_arena); gp_cache_arena = nullptr; diff --git a/sal/rtl/alloc_global.cxx b/sal/rtl/alloc_global.cxx index a16550589960..b0d3adbf928a 100644 --- a/sal/rtl/alloc_global.cxx +++ b/sal/rtl/alloc_global.cxx @@ -93,12 +93,12 @@ try_alloc: else addr = static_cast<char*>(rtl_arena_alloc (gp_alloc_arena, &size)); - if (addr != nullptr) + if (addr) { reinterpret_cast<sal_Size*>(addr)[0] = size; p = addr + RTL_MEMALIGN; } - else if (gp_alloc_arena == nullptr) + else if (!gp_alloc_arena) { ensureMemorySingleton(); if (gp_alloc_arena) @@ -113,7 +113,7 @@ try_alloc: void SAL_CALL rtl_freeMemory_CUSTOM (void * p) SAL_THROW_EXTERN_C() { - if (p != nullptr) + if (p) { char * addr = static_cast<char*>(p) - RTL_MEMALIGN; sal_Size size = reinterpret_cast<sal_Size*>(addr)[0]; @@ -129,13 +129,13 @@ void * SAL_CALL rtl_reallocateMemory_CUSTOM (void * p, sal_Size n) SAL_THROW_EXT { if (n > 0) { - if (p != nullptr) + if (p) { void * p_old = p; sal_Size n_old = reinterpret_cast<sal_Size*>( static_cast<char*>(p) - RTL_MEMALIGN )[0] - RTL_MEMALIGN; p = rtl_allocateMemory (n); - if (p != nullptr) + if (p) { memcpy (p, p_old, (n < n_old) ? n : n_old); rtl_freeMemory (p_old); @@ -146,7 +146,7 @@ void * SAL_CALL rtl_reallocateMemory_CUSTOM (void * p, sal_Size n) SAL_THROW_EXT p = rtl_allocateMemory (n); } } - else if (p != nullptr) + else if (p) { rtl_freeMemory (p); p = nullptr; @@ -161,7 +161,7 @@ void rtl_memory_init() #if !defined(FORCE_SYSALLOC) { /* global memory arena */ - assert(gp_alloc_arena == nullptr); + assert(!gp_alloc_arena); gp_alloc_arena = rtl_arena_create ( "rtl_alloc_arena", @@ -172,7 +172,7 @@ void rtl_memory_init() rtl_arena_free, 0 /* flags */ ); - assert(gp_alloc_arena != nullptr); + assert(gp_alloc_arena); } { sal_Size size; @@ -210,7 +210,7 @@ void rtl_memory_fini() /* cleanup g_alloc_caches */ for (i = 0, n = RTL_MEMORY_CACHED_SIZES; i < n; i++) { - if (g_alloc_caches[i] != nullptr) + if (g_alloc_caches[i]) { rtl_cache_destroy (g_alloc_caches[i]); g_alloc_caches[i] = nullptr; @@ -218,7 +218,7 @@ void rtl_memory_fini() } /* cleanup gp_alloc_arena */ - if (gp_alloc_arena != nullptr) + if (gp_alloc_arena) { rtl_arena_destroy (gp_alloc_arena); gp_alloc_arena = nullptr; @@ -312,14 +312,14 @@ void SAL_CALL rtl_freeMemory(void * p) SAL_THROW_EXTERN_C() void * SAL_CALL rtl_allocateZeroMemory(sal_Size n) SAL_THROW_EXTERN_C() { void * p = rtl_allocateMemory (n); - if (p != nullptr) + if (p) memset (p, 0, n); return p; } void SAL_CALL rtl_freeZeroMemory(void * p, sal_Size n) SAL_THROW_EXTERN_C() { - if (p != nullptr) + if (p) { rtl_secureZeroMemory (p, n); rtl_freeMemory (p); |