summaryrefslogtreecommitdiffstats
path: root/include/utils
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2013-05-08 16:04:13 -0700
committerAlex Ray <aray@google.com>2013-07-30 13:57:01 -0700
commit4485d0d966d062d1b45b635e2447a2d2f96c3f38 (patch)
tree89a0c95a7a27261e626dbedfd3fcacff01e41b20 /include/utils
parent9eb2a3b1c0cc1ff3082a9283e24c8babc112f56b (diff)
downloadsystem_core-4485d0d966d062d1b45b635e2447a2d2f96c3f38.zip
system_core-4485d0d966d062d1b45b635e2447a2d2f96c3f38.tar.gz
system_core-4485d0d966d062d1b45b635e2447a2d2f96c3f38.tar.bz2
new String8, String16 ctors to initialize empty static strings with static linkage
when libutils is statically linked, the ordering of the static initializer is not guaranteed and therefore it's unsafe to use empty static strings: e.g.: static String8 sThisStaticStringIsNotSafe; instead, this new constructor can be used: static String8 sThisStaticStringIsSafe(kEmptyString); Change-Id: Ia3daf1cab1c97d021c0ee9c2b394b5e27e8d6c0d
Diffstat (limited to 'include/utils')
-rw-r--r--include/utils/String16.h9
-rw-r--r--include/utils/String8.h9
2 files changed, 18 insertions, 0 deletions
diff --git a/include/utils/String16.h b/include/utils/String16.h
index 6d4253d..d131bfc 100644
--- a/include/utils/String16.h
+++ b/include/utils/String16.h
@@ -41,7 +41,16 @@ class TextOutput;
class String16
{
public:
+ /* use String16(StaticLinkage) if you're statically linking against
+ * libutils and declaring an empty static String16, e.g.:
+ *
+ * static String16 sAStaticEmptyString(String16::kEmptyString);
+ * static String16 sAnotherStaticEmptyString(sAStaticEmptyString);
+ */
+ enum StaticLinkage { kEmptyString };
+
String16();
+ explicit String16(StaticLinkage);
String16(const String16& o);
String16(const String16& o,
size_t len,
diff --git a/include/utils/String8.h b/include/utils/String8.h
index 9426fcf..ef59470 100644
--- a/include/utils/String8.h
+++ b/include/utils/String8.h
@@ -37,7 +37,16 @@ class TextOutput;
class String8
{
public:
+ /* use String8(StaticLinkage) if you're statically linking against
+ * libutils and declaring an empty static String8, e.g.:
+ *
+ * static String8 sAStaticEmptyString(String8::kEmptyString);
+ * static String8 sAnotherStaticEmptyString(sAStaticEmptyString);
+ */
+ enum StaticLinkage { kEmptyString };
+
String8();
+ explicit String8(StaticLinkage);
String8(const String8& o);
explicit String8(const char* o);
explicit String8(const char* o, size_t numChars);