summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTreehugger Robot2018-03-08 15:16:56 -0600
committerGerrit Code Review2018-03-08 15:16:56 -0600
commit929112bcd19e92c9b9f647d8a227ba55c743239d (patch)
tree89cea7dcf6db98eec0cb1a22837ec483b59a1d04
parent2b49abe4476587e8ec1a24472449514bbeee6245 (diff)
parent241b93cfd3ffadd3e8b4342d8ec869ca197fb575 (diff)
downloadplatform-system-core-929112bcd19e92c9b9f647d8a227ba55c743239d.tar.gz
platform-system-core-929112bcd19e92c9b9f647d8a227ba55c743239d.tar.xz
platform-system-core-929112bcd19e92c9b9f647d8a227ba55c743239d.zip
Merge "libutils: Remove Static.cpp and darwin hacks."
-rw-r--r--libutils/Android.bp1
-rw-r--r--libutils/Static.cpp49
-rw-r--r--libutils/String16.cpp29
-rw-r--r--libutils/String8.cpp40
4 files changed, 16 insertions, 103 deletions
diff --git a/libutils/Android.bp b/libutils/Android.bp
index 80dcdcbe9..32caa69bb 100644
--- a/libutils/Android.bp
+++ b/libutils/Android.bp
@@ -129,7 +129,6 @@ cc_library {
129 "PropertyMap.cpp", 129 "PropertyMap.cpp",
130 "RefBase.cpp", 130 "RefBase.cpp",
131 "SharedBuffer.cpp", 131 "SharedBuffer.cpp",
132 "Static.cpp",
133 "StopWatch.cpp", 132 "StopWatch.cpp",
134 "String8.cpp", 133 "String8.cpp",
135 "String16.cpp", 134 "String16.cpp",
diff --git a/libutils/Static.cpp b/libutils/Static.cpp
deleted file mode 100644
index 3ed07a10c..000000000
--- a/libutils/Static.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17// All static variables go here, to control initialization and
18// destruction order in the library.
19
20namespace android {
21
22// For String8.cpp
23extern void initialize_string8();
24extern void terminate_string8();
25
26// For String16.cpp
27extern void initialize_string16();
28extern void terminate_string16();
29
30class LibUtilsFirstStatics
31{
32public:
33 LibUtilsFirstStatics()
34 {
35 initialize_string8();
36 initialize_string16();
37 }
38
39 ~LibUtilsFirstStatics()
40 {
41 terminate_string16();
42 terminate_string8();
43 }
44};
45
46static LibUtilsFirstStatics gFirstStatics;
47int gDarwinCantLoadAllObjects = 1;
48
49} // namespace android
diff --git a/libutils/String16.cpp b/libutils/String16.cpp
index ad335c399..84d53dd76 100644
--- a/libutils/String16.cpp
+++ b/libutils/String16.cpp
@@ -24,29 +24,16 @@
24 24
25namespace android { 25namespace android {
26 26
27static SharedBuffer* gEmptyStringBuf = NULL; 27static inline char16_t* getEmptyString() {
28static char16_t* gEmptyString = NULL; 28 static SharedBuffer* gEmptyStringBuf = [] {
29 SharedBuffer* buf = SharedBuffer::alloc(sizeof(char16_t));
30 char16_t* str = static_cast<char16_t*>(buf->data());
31 *str = 0;
32 return buf;
33 }();
29 34
30static inline char16_t* getEmptyString()
31{
32 gEmptyStringBuf->acquire(); 35 gEmptyStringBuf->acquire();
33 return gEmptyString; 36 return static_cast<char16_t*>(gEmptyStringBuf->data());
34}
35
36void initialize_string16()
37{
38 SharedBuffer* buf = SharedBuffer::alloc(sizeof(char16_t));
39 char16_t* str = (char16_t*)buf->data();
40 *str = 0;
41 gEmptyStringBuf = buf;
42 gEmptyString = str;
43}
44
45void terminate_string16()
46{
47 SharedBuffer::bufferFromData(gEmptyString)->release();
48 gEmptyStringBuf = NULL;
49 gEmptyString = NULL;
50} 37}
51 38
52// --------------------------------------------------------------------------- 39// ---------------------------------------------------------------------------
diff --git a/libutils/String8.cpp b/libutils/String8.cpp
index ad0e72ec1..580e870c7 100644
--- a/libutils/String8.cpp
+++ b/libutils/String8.cpp
@@ -40,40 +40,16 @@ namespace android {
40// to OS_PATH_SEPARATOR. 40// to OS_PATH_SEPARATOR.
41#define RES_PATH_SEPARATOR '/' 41#define RES_PATH_SEPARATOR '/'
42 42
43static SharedBuffer* gEmptyStringBuf = NULL; 43static inline char* getEmptyString() {
44static char* gEmptyString = NULL; 44 static SharedBuffer* gEmptyStringBuf = [] {
45 SharedBuffer* buf = SharedBuffer::alloc(1);
46 char* str = static_cast<char*>(buf->data());
47 *str = 0;
48 return buf;
49 }();
45 50
46extern int gDarwinCantLoadAllObjects;
47int gDarwinIsReallyAnnoying;
48
49void initialize_string8();
50
51static inline char* getEmptyString()
52{
53 gEmptyStringBuf->acquire(); 51 gEmptyStringBuf->acquire();
54 return gEmptyString; 52 return static_cast<char*>(gEmptyStringBuf->data());
55}
56
57void initialize_string8()
58{
59 // HACK: This dummy dependency forces linking libutils Static.cpp,
60 // which is needed to initialize String8/String16 classes.
61 // These variables are named for Darwin, but are needed elsewhere too,
62 // including static linking on any platform.
63 gDarwinIsReallyAnnoying = gDarwinCantLoadAllObjects;
64
65 SharedBuffer* buf = SharedBuffer::alloc(1);
66 char* str = (char*)buf->data();
67 *str = 0;
68 gEmptyStringBuf = buf;
69 gEmptyString = str;
70}
71
72void terminate_string8()
73{
74 SharedBuffer::bufferFromData(gEmptyString)->release();
75 gEmptyStringBuf = NULL;
76 gEmptyString = NULL;
77} 53}
78 54
79// --------------------------------------------------------------------------- 55// ---------------------------------------------------------------------------