diff options
Diffstat (limited to 'libutils')
-rw-r--r-- | libutils/BlobCache.cpp | 27 | ||||
-rw-r--r-- | libutils/FileMap.cpp | 80 | ||||
-rw-r--r-- | libutils/RefBase.cpp | 4 | ||||
-rw-r--r-- | libutils/Timers.cpp | 6 | ||||
-rw-r--r-- | libutils/tests/BasicHashtable_test.cpp | 2 | ||||
-rw-r--r-- | libutils/tests/LruCache_test.cpp | 2 |
6 files changed, 58 insertions, 63 deletions
diff --git a/libutils/BlobCache.cpp b/libutils/BlobCache.cpp index 0fb1d8e..660917b 100644 --- a/libutils/BlobCache.cpp +++ b/libutils/BlobCache.cpp @@ -17,6 +17,7 @@ #define LOG_TAG "BlobCache" //#define LOG_NDEBUG 0 +#include <inttypes.h> #include <stdlib.h> #include <string.h> @@ -54,18 +55,18 @@ BlobCache::BlobCache(size_t maxKeySize, size_t maxValueSize, size_t maxTotalSize void BlobCache::set(const void* key, size_t keySize, const void* value, size_t valueSize) { if (mMaxKeySize < keySize) { - ALOGV("set: not caching because the key is too large: %d (limit: %d)", + ALOGV("set: not caching because the key is too large: %zu (limit: %zu)", keySize, mMaxKeySize); return; } if (mMaxValueSize < valueSize) { - ALOGV("set: not caching because the value is too large: %d (limit: %d)", + ALOGV("set: not caching because the value is too large: %zu (limit: %zu)", valueSize, mMaxValueSize); return; } if (mMaxTotalSize < keySize + valueSize) { ALOGV("set: not caching because the combined key/value size is too " - "large: %d (limit: %d)", keySize + valueSize, mMaxTotalSize); + "large: %zu (limit: %zu)", keySize + valueSize, mMaxTotalSize); return; } if (keySize == 0) { @@ -94,15 +95,15 @@ void BlobCache::set(const void* key, size_t keySize, const void* value, continue; } else { ALOGV("set: not caching new key/value pair because the " - "total cache size limit would be exceeded: %d " - "(limit: %d)", + "total cache size limit would be exceeded: %zu " + "(limit: %zu)", keySize + valueSize, mMaxTotalSize); break; } } mCacheEntries.add(CacheEntry(keyBlob, valueBlob)); mTotalSize = newTotalSize; - ALOGV("set: created new cache entry with %d byte key and %d byte value", + ALOGV("set: created new cache entry with %zu byte key and %zu byte value", keySize, valueSize); } else { // Update the existing cache entry. @@ -116,14 +117,14 @@ void BlobCache::set(const void* key, size_t keySize, const void* value, continue; } else { ALOGV("set: not caching new value because the total cache " - "size limit would be exceeded: %d (limit: %d)", + "size limit would be exceeded: %zu (limit: %zu)", keySize + valueSize, mMaxTotalSize); break; } } mCacheEntries.editItemAt(index).setValue(valueBlob); mTotalSize = newTotalSize; - ALOGV("set: updated existing cache entry with %d byte key and %d byte " + ALOGV("set: updated existing cache entry with %zu byte key and %zu byte " "value", keySize, valueSize); } break; @@ -133,7 +134,7 @@ void BlobCache::set(const void* key, size_t keySize, const void* value, size_t BlobCache::get(const void* key, size_t keySize, void* value, size_t valueSize) { if (mMaxKeySize < keySize) { - ALOGV("get: not searching because the key is too large: %d (limit %d)", + ALOGV("get: not searching because the key is too large: %zu (limit %zu)", keySize, mMaxKeySize); return 0; } @@ -141,7 +142,7 @@ size_t BlobCache::get(const void* key, size_t keySize, void* value, CacheEntry dummyEntry(dummyKey, NULL); ssize_t index = mCacheEntries.indexOf(dummyEntry); if (index < 0) { - ALOGV("get: no cache entry found for key of size %d", keySize); + ALOGV("get: no cache entry found for key of size %zu", keySize); return 0; } @@ -150,10 +151,10 @@ size_t BlobCache::get(const void* key, size_t keySize, void* value, sp<Blob> valueBlob(mCacheEntries[index].getValue()); size_t valueBlobSize = valueBlob->getSize(); if (valueBlobSize <= valueSize) { - ALOGV("get: copying %d bytes to caller's buffer", valueBlobSize); + ALOGV("get: copying %zu bytes to caller's buffer", valueBlobSize); memcpy(value, valueBlob->getData(), valueBlobSize); } else { - ALOGV("get: caller's buffer is too small for value: %d (needs %d)", + ALOGV("get: caller's buffer is too small for value: %zu (needs %zu)", valueSize, valueBlobSize); } return valueBlobSize; @@ -229,7 +230,7 @@ status_t BlobCache::unflatten(void const* buffer, size_t size) { } const Header* header = reinterpret_cast<const Header*>(buffer); if (header->mMagicNumber != blobCacheMagic) { - ALOGE("unflatten: bad magic number: %d", header->mMagicNumber); + ALOGE("unflatten: bad magic number: %" PRIu32, header->mMagicNumber); return BAD_VALUE; } if (header->mBlobCacheVersion != blobCacheVersion || diff --git a/libutils/FileMap.cpp b/libutils/FileMap.cpp index 9ce370e..933e7aa 100644 --- a/libutils/FileMap.cpp +++ b/libutils/FileMap.cpp @@ -23,6 +23,7 @@ #include <utils/FileMap.h> #include <utils/Log.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> @@ -39,37 +40,32 @@ using namespace android; /*static*/ long FileMap::mPageSize = -1; - -/* - * Constructor. Create an empty object. - */ +// Constructor. Create an empty object. FileMap::FileMap(void) : mRefCount(1), mFileName(NULL), mBasePtr(NULL), mBaseLength(0), mDataPtr(NULL), mDataLength(0) { } -/* - * Destructor. - */ +// Destructor. FileMap::~FileMap(void) { assert(mRefCount == 0); - //printf("+++ removing FileMap %p %u\n", mDataPtr, mDataLength); + //printf("+++ removing FileMap %p %zu\n", mDataPtr, mDataLength); mRefCount = -100; // help catch double-free if (mFileName != NULL) { free(mFileName); } -#ifdef HAVE_POSIX_FILEMAP +#ifdef HAVE_POSIX_FILEMAP if (mBasePtr && munmap(mBasePtr, mBaseLength) != 0) { - ALOGD("munmap(%p, %d) failed\n", mBasePtr, (int) mBaseLength); + ALOGD("munmap(%p, %zu) failed\n", mBasePtr, mBaseLength); } #endif #ifdef HAVE_WIN32_FILEMAP if (mBasePtr && UnmapViewOfFile(mBasePtr) == 0) { - ALOGD("UnmapViewOfFile(%p) failed, error = %ld\n", mBasePtr, + ALOGD("UnmapViewOfFile(%p) failed, error = %" PRId32 "\n", mBasePtr, GetLastError() ); } if (mFileMapping != INVALID_HANDLE_VALUE) { @@ -80,14 +76,12 @@ FileMap::~FileMap(void) } -/* - * Create a new mapping on an open file. - * - * Closing the file descriptor does not unmap the pages, so we don't - * claim ownership of the fd. - * - * Returns "false" on failure. - */ +// Create a new mapping on an open file. +// +// Closing the file descriptor does not unmap the pages, so we don't +// claim ownership of the fd. +// +// Returns "false" on failure. bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t length, bool readOnly) { @@ -98,32 +92,32 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le if (mPageSize == -1) { SYSTEM_INFO si; - + GetSystemInfo( &si ); mPageSize = si.dwAllocationGranularity; } DWORD protect = readOnly ? PAGE_READONLY : PAGE_READWRITE; - + mFileHandle = (HANDLE) _get_osfhandle(fd); mFileMapping = CreateFileMapping( mFileHandle, NULL, protect, 0, 0, NULL); if (mFileMapping == NULL) { - ALOGE("CreateFileMapping(%p, %lx) failed with error %ld\n", + ALOGE("CreateFileMapping(%p, %" PRIx32 ") failed with error %" PRId32 "\n", mFileHandle, protect, GetLastError() ); return false; } - + adjust = offset % mPageSize; adjOffset = offset - adjust; adjLength = length + adjust; - - mBasePtr = MapViewOfFile( mFileMapping, + + mBasePtr = MapViewOfFile( mFileMapping, readOnly ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS, 0, (DWORD)(adjOffset), adjLength ); if (mBasePtr == NULL) { - ALOGE("MapViewOfFile(%ld, %ld) failed with error %ld\n", + ALOGE("MapViewOfFile(%" PRId64 ", %zu) failed with error %" PRId32 "\n", adjOffset, adjLength, GetLastError() ); CloseHandle(mFileMapping); mFileMapping = INVALID_HANDLE_VALUE; @@ -142,7 +136,7 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le assert(offset >= 0); assert(length > 0); - /* init on first use */ + // init on first use if (mPageSize == -1) { #if NOT_USING_KLIBC mPageSize = sysconf(_SC_PAGESIZE); @@ -151,7 +145,7 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le return false; } #else - /* this holds for Linux, Darwin, Cygwin, and doesn't pain the ARM */ + // this holds for Linux, Darwin, Cygwin, and doesn't pain the ARM mPageSize = 4096; #endif } @@ -168,19 +162,19 @@ try_again: ptr = mmap(NULL, adjLength, prot, flags, fd, adjOffset); if (ptr == MAP_FAILED) { - // Cygwin does not seem to like file mapping files from an offset. - // So if we fail, try again with offset zero - if (adjOffset > 0) { - adjust = offset; - goto try_again; - } - - ALOGE("mmap(%ld,%ld) failed: %s\n", - (long) adjOffset, (long) adjLength, strerror(errno)); + // Cygwin does not seem to like file mapping files from an offset. + // So if we fail, try again with offset zero + if (adjOffset > 0) { + adjust = offset; + goto try_again; + } + + ALOGE("mmap(%" PRId64 ",%zu) failed: %s\n", + adjOffset, adjLength, strerror(errno)); return false; } mBasePtr = ptr; -#endif /* HAVE_POSIX_FILEMAP */ +#endif // HAVE_POSIX_FILEMAP mFileName = origFileName != NULL ? strdup(origFileName) : NULL; mBaseLength = adjLength; @@ -190,15 +184,13 @@ try_again: assert(mBasePtr != NULL); - ALOGV("MAP: base %p/%d data %p/%d\n", - mBasePtr, (int) mBaseLength, mDataPtr, (int) mDataLength); + ALOGV("MAP: base %p/%zu data %p/%zu\n", + mBasePtr, mBaseLength, mDataPtr, mDataLength); return true; } -/* - * Provide guidance to the system. - */ +// Provide guidance to the system. int FileMap::advise(MapAdvice advice) { #if HAVE_MADVISE @@ -220,6 +212,6 @@ int FileMap::advise(MapAdvice advice) ALOGW("madvise(%d) failed: %s\n", sysAdvice, strerror(errno)); return cc; #else - return -1; + return -1; #endif // HAVE_MADVISE } diff --git a/libutils/RefBase.cpp b/libutils/RefBase.cpp index f398a82..385c226 100644 --- a/libutils/RefBase.cpp +++ b/libutils/RefBase.cpp @@ -109,7 +109,7 @@ public: char inc = refs->ref >= 0 ? '+' : '-'; ALOGD("\t%c ID %p (ref %d):", inc, refs->id, refs->ref); #if DEBUG_REFS_CALLSTACK_ENABLED - refs->stack.dump(LOG_TAG); + refs->stack.log(LOG_TAG); #endif refs = refs->next; } @@ -123,7 +123,7 @@ public: char inc = refs->ref >= 0 ? '+' : '-'; ALOGD("\t%c ID %p (ref %d):", inc, refs->id, refs->ref); #if DEBUG_REFS_CALLSTACK_ENABLED - refs->stack.dump(LOG_TAG); + refs->stack.log(LOG_TAG); #endif refs = refs->next; } diff --git a/libutils/Timers.cpp b/libutils/Timers.cpp index 5293cd2..a431e92 100644 --- a/libutils/Timers.cpp +++ b/libutils/Timers.cpp @@ -34,7 +34,7 @@ nsecs_t systemTime(int clock) { -#if defined(HAVE_POSIX_CLOCKS) +#if defined(HAVE_ANDROID_OS) static const clockid_t clocks[] = { CLOCK_REALTIME, CLOCK_MONOTONIC, @@ -47,7 +47,9 @@ nsecs_t systemTime(int clock) clock_gettime(clocks[clock], &t); return nsecs_t(t.tv_sec)*1000000000LL + t.tv_nsec; #else - // we don't support the clocks here. + // Clock support varies widely across hosts. Mac OS doesn't support + // posix clocks, older glibcs don't support CLOCK_BOOTTIME and Windows + // is windows. struct timeval t; t.tv_sec = t.tv_usec = 0; gettimeofday(&t, NULL); diff --git a/libutils/tests/BasicHashtable_test.cpp b/libutils/tests/BasicHashtable_test.cpp index 7dcf750..a61b1e1 100644 --- a/libutils/tests/BasicHashtable_test.cpp +++ b/libutils/tests/BasicHashtable_test.cpp @@ -397,7 +397,7 @@ TEST_F(BasicHashtableTest, Next_WhenNonEmpty_IteratesOverAllEntries) { const SimpleEntry& entry = h.entryAt(index); ASSERT_GE(entry.key, 0); ASSERT_LT(entry.key, N); - ASSERT_EQ(false, set[entry.key]); + ASSERT_FALSE(set[entry.key]); ASSERT_EQ(entry.key * 10, entry.value); set[entry.key] = true; diff --git a/libutils/tests/LruCache_test.cpp b/libutils/tests/LruCache_test.cpp index e573952..bcbea32 100644 --- a/libutils/tests/LruCache_test.cpp +++ b/libutils/tests/LruCache_test.cpp @@ -184,7 +184,7 @@ TEST_F(LruCacheTest, StressTest) { for (size_t i = 0; i < kNumKeys; i++) { strings[i] = (char *)malloc(16); - sprintf(strings[i], "%d", i); + sprintf(strings[i], "%zu", i); } srandom(12345); |