am 3fd34002: Merge commit \'78be0498\' into manualmerge
* commit '3fd340028fc24198edb23ddf5eb5a0a100bab745':
Fix issues that will be present in C++11
diff --git a/include/androidfw/ResourceTypes.h b/include/androidfw/ResourceTypes.h
index 051d554..6b84494 100644
--- a/include/androidfw/ResourceTypes.h
+++ b/include/androidfw/ResourceTypes.h
@@ -36,6 +36,17 @@
namespace android {
+/**
+ * In C++11, char16_t is defined as *at least* 16 bits. We do a lot of
+ * casting on raw data and expect char16_t to be exactly 16 bits.
+ */
+#if __cplusplus >= 201103L
+struct __assertChar16Size {
+ static_assert(sizeof(char16_t) == sizeof(uint16_t), "char16_t is not 16 bits");
+ static_assert(alignof(char16_t) == alignof(uint16_t), "char16_t is not 16-bit aligned");
+};
+#endif
+
/** ********************************************************************
* PNG Extensions
*
@@ -845,7 +856,7 @@
uint32_t id;
// Actual name of this package, \0-terminated.
- char16_t name[128];
+ uint16_t name[128];
// Offset to a ResStringPool_header defining the resource
// type symbol table. If zero, this package is inheriting from
@@ -1450,7 +1461,7 @@
uint32_t packageId;
// The package name of the shared library. \0 terminated.
- char16_t packageName[128];
+ uint16_t packageName[128];
};
/**
diff --git a/libs/androidfw/Android.mk b/libs/androidfw/Android.mk
index 376b101..e21647b 100644
--- a/libs/androidfw/Android.mk
+++ b/libs/androidfw/Android.mk
@@ -14,7 +14,7 @@
LOCAL_PATH:= $(call my-dir)
-# libandroidfw is partially built for the host (used by obbtool and others)
+# libandroidfw is partially built for the host (used by obbtool, aapt, and others)
# These files are common to host and target builds.
commonSources := \
@@ -35,27 +35,18 @@
BackupHelpers.cpp \
CursorWindow.cpp
-hostSources := \
- $(commonSources)
+hostSources := $(commonSources)
# For the host
# =====================================================
-
include $(CLEAR_VARS)
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_SRC_FILES:= $(hostSources)
-
LOCAL_MODULE:= libandroidfw
-
LOCAL_MODULE_TAGS := optional
-
LOCAL_CFLAGS += -DSTATIC_ANDROIDFW_FOR_TOOLS
-
-LOCAL_C_INCLUDES := \
- external/zlib
-
-LOCAL_STATIC_LIBRARIES := liblog libziparchive-host libutils
+LOCAL_SRC_FILES:= $(hostSources)
+LOCAL_C_INCLUDES := external/zlib
include $(BUILD_HOST_STATIC_LIBRARY)
@@ -66,8 +57,13 @@
include $(CLEAR_VARS)
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
+LOCAL_MODULE:= libandroidfw
+LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES:= $(deviceSources)
-
+LOCAL_C_INCLUDES := \
+ external/zlib \
+ system/core/include
+LOCAL_STATIC_LIBRARIES := libziparchive
LOCAL_SHARED_LIBRARIES := \
libbinder \
liblog \
@@ -75,16 +71,6 @@
libutils \
libz
-LOCAL_STATIC_LIBRARIES := libziparchive
-
-LOCAL_C_INCLUDES := \
- external/zlib \
- system/core/include
-
-LOCAL_MODULE:= libandroidfw
-
-LOCAL_MODULE_TAGS := optional
-
include $(BUILD_SHARED_LIBRARY)
diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp
index 2a7af0d..7568c0b 100644
--- a/libs/androidfw/ResourceTypes.cpp
+++ b/libs/androidfw/ResourceTypes.cpp
@@ -87,11 +87,11 @@
// range checked; guaranteed to NUL-terminate within the stated number of available slots
// NOTE: if this truncates the dst string due to running out of space, no attempt is
// made to avoid splitting surrogate pairs.
-static void strcpy16_dtoh(char16_t* dst, const char16_t* src, size_t avail)
+static void strcpy16_dtoh(char16_t* dst, const uint16_t* src, size_t avail)
{
char16_t* last = dst + avail - 1;
while (*src && (dst < last)) {
- char16_t s = dtohs(*src);
+ char16_t s = dtohs(static_cast<char16_t>(*src));
*dst++ = s;
src++;
}
@@ -501,7 +501,7 @@
if (mHeader->flags&ResStringPool_header::UTF8_FLAG) {
charSize = sizeof(uint8_t);
} else {
- charSize = sizeof(char16_t);
+ charSize = sizeof(uint16_t);
}
// There should be at least space for the smallest string
@@ -547,8 +547,8 @@
e[i] = dtohl(mEntries[i]);
}
if (!(mHeader->flags&ResStringPool_header::UTF8_FLAG)) {
- const char16_t* strings = (const char16_t*)mStrings;
- char16_t* s = const_cast<char16_t*>(strings);
+ const uint16_t* strings = (const uint16_t*)mStrings;
+ uint16_t* s = const_cast<uint16_t*>(strings);
for (i=0; i<mStringPoolSize; i++) {
s[i] = dtohs(strings[i]);
}
@@ -558,7 +558,7 @@
if ((mHeader->flags&ResStringPool_header::UTF8_FLAG &&
((uint8_t*)mStrings)[mStringPoolSize-1] != 0) ||
(!mHeader->flags&ResStringPool_header::UTF8_FLAG &&
- ((char16_t*)mStrings)[mStringPoolSize-1] != 0)) {
+ ((uint16_t*)mStrings)[mStringPoolSize-1] != 0)) {
ALOGW("Bad string block: last string is not 0-terminated\n");
return (mError=BAD_TYPE);
}
@@ -656,7 +656,7 @@
* add it together with the next character.
*/
static inline size_t
-decodeLength(const char16_t** str)
+decodeLength(const uint16_t** str)
{
size_t len = **str;
if ((len & 0x8000) != 0) {
@@ -693,15 +693,15 @@
{
if (mError == NO_ERROR && idx < mHeader->stringCount) {
const bool isUTF8 = (mHeader->flags&ResStringPool_header::UTF8_FLAG) != 0;
- const uint32_t off = mEntries[idx]/(isUTF8?sizeof(char):sizeof(char16_t));
+ const uint32_t off = mEntries[idx]/(isUTF8?sizeof(uint8_t):sizeof(uint16_t));
if (off < (mStringPoolSize-1)) {
if (!isUTF8) {
- const char16_t* strings = (char16_t*)mStrings;
- const char16_t* str = strings+off;
+ const uint16_t* strings = (uint16_t*)mStrings;
+ const uint16_t* str = strings+off;
*u16len = decodeLength(&str);
if ((uint32_t)(str+*u16len-strings) < mStringPoolSize) {
- return str;
+ return reinterpret_cast<const char16_t*>(str);
} else {
ALOGW("Bad string block: string #%d extends to %d, past end at %d\n",
(int)idx, (int)(str+*u16len-strings), (int)mStringPoolSize);
@@ -5665,8 +5665,8 @@
if (idx == 0) {
idx = mPackageGroups.size() + 1;
- char16_t tmpName[sizeof(pkg->name)/sizeof(char16_t)];
- strcpy16_dtoh(tmpName, pkg->name, sizeof(pkg->name)/sizeof(char16_t));
+ char16_t tmpName[sizeof(pkg->name)/sizeof(pkg->name[0])];
+ strcpy16_dtoh(tmpName, pkg->name, sizeof(pkg->name)/sizeof(pkg->name[0]));
group = new PackageGroup(this, String16(tmpName), id);
if (group == NULL) {
delete package;
@@ -6036,7 +6036,10 @@
*outSize += 2 * sizeof(uint16_t);
// overlay packages are assumed to contain only one package group
- const String16 overlayPackage(overlay.mPackageGroups[0]->packages[0]->package->name);
+ const ResTable_package* overlayPackageStruct = overlay.mPackageGroups[0]->packages[0]->package;
+ char16_t tmpName[sizeof(overlayPackageStruct->name)/sizeof(overlayPackageStruct->name[0])];
+ strcpy16_dtoh(tmpName, overlayPackageStruct->name, sizeof(overlayPackageStruct->name)/sizeof(overlayPackageStruct->name[0]));
+ const String16 overlayPackage(tmpName);
for (size_t typeIndex = 0; typeIndex < pg->types.size(); ++typeIndex) {
const TypeList& typeList = pg->types[typeIndex];
@@ -6345,8 +6348,10 @@
// Use a package's real ID, since the ID may have been assigned
// if this package is a shared library.
packageId = pkg->package->id;
+ char16_t tmpName[sizeof(pkg->package->name)/sizeof(pkg->package->name[0])];
+ strcpy16_dtoh(tmpName, pkg->package->name, sizeof(pkg->package->name)/sizeof(pkg->package->name[0]));
printf(" Package %d id=0x%02x name=%s\n", (int)pkgIndex,
- pkg->package->id, String8(String16(pkg->package->name)).string());
+ pkg->package->id, String8(tmpName).string());
}
for (size_t typeIndex=0; typeIndex < pg->types.size(); typeIndex++) {
diff --git a/libs/androidfw/misc.cpp b/libs/androidfw/misc.cpp
index 29686ef..ea54cc5 100644
--- a/libs/androidfw/misc.cpp
+++ b/libs/androidfw/misc.cpp
@@ -22,9 +22,9 @@
#include <androidfw/misc.h>
#include <sys/stat.h>
-#include <string.h>
+#include <cstring>
#include <errno.h>
-#include <stdio.h>
+#include <cstdio>
using namespace android;
diff --git a/libs/androidfw/tests/Android.mk b/libs/androidfw/tests/Android.mk
index a0442e4..d802a6b 100644
--- a/libs/androidfw/tests/Android.mk
+++ b/libs/androidfw/tests/Android.mk
@@ -37,7 +37,6 @@
include $(CLEAR_VARS)
LOCAL_MODULE := libandroidfw_tests
-
LOCAL_SRC_FILES := $(testFiles)
LOCAL_STATIC_LIBRARIES := \
libandroidfw \
@@ -55,11 +54,9 @@
include $(CLEAR_VARS)
LOCAL_MODULE := libandroidfw_tests
-
LOCAL_SRC_FILES := $(testFiles) \
BackupData_test.cpp \
ObbFile_test.cpp
-
LOCAL_SHARED_LIBRARIES := \
libandroidfw \
libcutils \
diff --git a/tools/aapt/AaptXml.cpp b/tools/aapt/AaptXml.cpp
index 708e405..b04a55d 100644
--- a/tools/aapt/AaptXml.cpp
+++ b/tools/aapt/AaptXml.cpp
@@ -41,7 +41,7 @@
}
size_t len;
- const uint16_t* str = tree.getAttributeStringValue(attrIndex, &len);
+ const char16_t* str = tree.getAttributeStringValue(attrIndex, &len);
return str ? String8(str, len) : String8();
}
@@ -103,7 +103,7 @@
if (tree.getAttributeValue(idx, &value) != NO_ERROR) {
if (value.dataType == Res_value::TYPE_STRING) {
size_t len;
- const uint16_t* str = tree.getAttributeStringValue(idx, &len);
+ const char16_t* str = tree.getAttributeStringValue(idx, &len);
return str ? String8(str, len) : String8();
}
resTable.resolveReference(&value, 0);
diff --git a/tools/aapt/Android.mk b/tools/aapt/Android.mk
index 0ccf0f5..2eb7424 100644
--- a/tools/aapt/Android.mk
+++ b/tools/aapt/Android.mk
@@ -33,19 +33,20 @@
Command.cpp \
CrunchCache.cpp \
FileFinder.cpp \
+ Images.cpp \
Package.cpp \
- StringPool.cpp \
- XMLNode.cpp \
+ pseudolocalize.cpp \
+ qsort_r_compat.c \
+ Resource.cpp \
ResourceFilter.cpp \
ResourceIdCache.cpp \
ResourceTable.cpp \
- Images.cpp \
- Resource.cpp \
- pseudolocalize.cpp \
SourcePos.cpp \
+ StringPool.cpp \
WorkQueue.cpp \
+ XMLNode.cpp \
ZipEntry.cpp \
- ZipFile.cpp \
+ ZipFile.cpp
aaptTests := \
tests/AaptConfig_test.cpp \
@@ -88,16 +89,13 @@
include $(CLEAR_VARS)
LOCAL_MODULE := libaapt
-
-LOCAL_SRC_FILES := $(aaptSources)
-LOCAL_C_INCLUDES += $(aaptCIncludes)
-
-LOCAL_CFLAGS += -Wno-format-y2k
-LOCAL_CFLAGS += -DSTATIC_ANDROIDFW_FOR_TOOLS
-LOCAL_CFLAGS += $(aaptCFlags)
+LOCAL_CFLAGS += -Wno-format-y2k -DSTATIC_ANDROIDFW_FOR_TOOLS $(aaptCFlags)
+LOCAL_CPPFLAGS += $(aaptCppFlags)
ifeq (darwin,$(HOST_OS))
LOCAL_CFLAGS += -D_DARWIN_UNLIMITED_STREAMS
endif
+LOCAL_C_INCLUDES += $(aaptCIncludes)
+LOCAL_SRC_FILES := $(aaptSources)
include $(BUILD_HOST_STATIC_LIBRARY)
@@ -108,15 +106,11 @@
include $(CLEAR_VARS)
LOCAL_MODULE := aapt
-
-LOCAL_SRC_FILES := $(aaptMain)
-
-LOCAL_STATIC_LIBRARIES += \
- libaapt \
- $(aaptHostStaticLibs)
-
-LOCAL_LDLIBS += $(aaptHostLdLibs)
LOCAL_CFLAGS += $(aaptCFlags)
+LOCAL_CPPFLAGS += $(aaptCppFlags)
+LOCAL_LDLIBS += $(aaptHostLdLibs)
+LOCAL_SRC_FILES := $(aaptMain)
+LOCAL_STATIC_LIBRARIES += libaapt $(aaptHostStaticLibs)
include $(BUILD_HOST_EXECUTABLE)
@@ -128,16 +122,12 @@
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
LOCAL_MODULE := libaapt_tests
-
+LOCAL_CFLAGS += $(aaptCFlags)
+LOCAL_CPPFLAGS += $(aaptCppFlags)
+LOCAL_LDLIBS += $(aaptHostLdLibs)
LOCAL_SRC_FILES += $(aaptTests)
LOCAL_C_INCLUDES += $(LOCAL_PATH)
-
-LOCAL_STATIC_LIBRARIES += \
- libaapt \
- $(aaptHostStaticLibs)
-
-LOCAL_LDLIBS += $(aaptHostLdLibs)
-LOCAL_CFLAGS += $(aaptCFlags)
+LOCAL_STATIC_LIBRARIES += libaapt $(aaptHostStaticLibs)
include $(BUILD_HOST_NATIVE_TEST)
@@ -149,11 +139,9 @@
include $(CLEAR_VARS)
LOCAL_MODULE := aapt
-
+LOCAL_CFLAGS += $(aaptCFlags)
LOCAL_SRC_FILES := $(aaptSources) $(aaptMain)
-LOCAL_C_INCLUDES += \
- $(aaptCIncludes) \
-
+LOCAL_C_INCLUDES += $(aaptCIncludes)
LOCAL_SHARED_LIBRARIES := \
libandroidfw \
libutils \
@@ -161,13 +149,9 @@
libpng \
liblog \
libz
-
LOCAL_STATIC_LIBRARIES := \
libexpat_static
-LOCAL_CFLAGS += $(aaptCFlags)
-LOCAL_CPPFLAGS += -Wno-non-virtual-dtor
-
include external/stlport/libstlport.mk
include $(BUILD_EXECUTABLE)
diff --git a/tools/aapt/CacheUpdater.h b/tools/aapt/CacheUpdater.h
index cacab03..7ddc826 100644
--- a/tools/aapt/CacheUpdater.h
+++ b/tools/aapt/CacheUpdater.h
@@ -30,6 +30,8 @@
*/
class CacheUpdater {
public:
+ virtual ~CacheUpdater() {}
+
// Make sure all the directories along this path exist
virtual void ensureDirectoriesExist(String8 path) = 0;
diff --git a/tools/aapt/Main.cpp b/tools/aapt/Main.cpp
index 2857b59..18b8e1e 100644
--- a/tools/aapt/Main.cpp
+++ b/tools/aapt/Main.cpp
@@ -11,9 +11,9 @@
#include <utils/List.h>
#include <utils/Errors.h>
-#include <stdlib.h>
+#include <cstdlib>
#include <getopt.h>
-#include <assert.h>
+#include <cassert>
using namespace android;
diff --git a/tools/aapt/Resource.cpp b/tools/aapt/Resource.cpp
index b559002..a4f4dd1 100644
--- a/tools/aapt/Resource.cpp
+++ b/tools/aapt/Resource.cpp
@@ -523,7 +523,7 @@
}
if (validChars) {
for (size_t i=0; i<len; i++) {
- uint16_t c = str[i];
+ char16_t c = str[i];
const char* p = validChars;
bool okay = false;
while (*p) {
diff --git a/tools/aapt/StringPool.cpp b/tools/aapt/StringPool.cpp
index e3ec0ae..a18e9f1 100644
--- a/tools/aapt/StringPool.cpp
+++ b/tools/aapt/StringPool.cpp
@@ -26,6 +26,7 @@
// Set to true for noisy debug output.
static const bool kIsDebug = false;
+#if __cplusplus >= 201103L
void strcpy16_htod(char16_t* dst, const char16_t* src)
{
while (*src) {
@@ -35,6 +36,17 @@
}
*dst = 0;
}
+#endif
+
+void strcpy16_htod(uint16_t* dst, const char16_t* src)
+{
+ while (*src) {
+ uint16_t s = htods(static_cast<uint16_t>(*src));
+ *dst++ = s;
+ src++;
+ }
+ *dst = 0;
+}
void printStringPool(const ResStringPool* pool)
{
@@ -434,7 +446,7 @@
return NO_MEMORY;
}
- const size_t charSize = mUTF8 ? sizeof(uint8_t) : sizeof(char16_t);
+ const size_t charSize = mUTF8 ? sizeof(uint8_t) : sizeof(uint16_t);
size_t strPos = 0;
for (i=0; i<STRINGS; i++) {
diff --git a/tools/aapt/StringPool.h b/tools/aapt/StringPool.h
index 0b26538..dbe8c85 100644
--- a/tools/aapt/StringPool.h
+++ b/tools/aapt/StringPool.h
@@ -26,7 +26,10 @@
#define PRINT_STRING_METRICS 0
+#if __cplusplus >= 201103L
void strcpy16_htod(char16_t* dst, const char16_t* src);
+#endif
+void strcpy16_htod(uint16_t* dst, const char16_t* src);
void printStringPool(const ResStringPool* pool);