Commit graph

35 commits

Author SHA1 Message Date
Treehugger Robot
dcd1cacbbb Merge "String16 is moveable (noexcept)" am: 3551e457ca am: 32ceaa1299
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1749261

Change-Id: Ia658a7b6ad2c21c83ef109230a4c5f0a7d02068a
2021-06-30 01:48:14 +00:00
Jooyung Han
98b396e785 String16 is moveable (noexcept)
String16 is still in use by AIDL compiler. Because String16 is not
noexcept-move-constructible, the C++ compiler will complain when it is
used with non-copyable types (such as ParcelFileDescriptor).

For example, when vector<Foo> is resized, copy-ctor of Foo is called,
which is not available.

  parcelable Foo {
    String s;
    ParcelFileDescriptor[] pfds;
  }

By providing noexcept move-ctor for String16, vector<Foo> can be resized
with no problem.

Btw, copy from StaticString16 is specialized for efficiency and move
from StaticString16 don't need to be different from copy.

Bug: 192136980
Test: libutils_test
Change-Id: I13744a2ceebf5781c3ef7f3a04237a6750b0db0a
2021-06-29 10:18:23 +09:00
Elliott Hughes
a6be6f0acb Check for overflow in String16::append and String16::insert.
Bug: http://b/178802681
Bug: http://b/178821065
Test: new tests
Change-Id: I2352ea4c65e3f29e44e2ad6cad20ad610ceace1f
2021-06-10 17:06:26 -07:00
Elliott Hughes
2cf0411910 Remove String16::remove.
This function, ironically, is being removed.

Even more amusing, it was never "remove" anyway --- it literally did
the opposite, and removed everything *except* the range you passed to
it, and should probably have been called "keep"!

I'm looking at reimplementing much of libutils, but first I'm improving
test coverage, and literally every test I wrote for this failed. And
then when I fixed the "obvious bugs" in the implementation, I found
there actually were a couple of existing unit tests --- that mostly
served to demonstrate just how counter-intuitive this function was.

Bug: http://b/156999009
Test: treehugger
Change-Id: I41fd85f7c0988070f4039f607d2e57523d862ed9
2021-05-12 20:24:26 +00:00
Elliott Hughes
016beb8559 Remove String16::makeLower().
If you need to do a case transformation for a Unicode string, you need
to use icu4c. This only worked for ASCII, which is just silly. Luckily
it doesn't seem to be used anywhere.

Test: treehugger
Change-Id: I4a864823ec35a0b57b50909587cc3efac3f531a7
Merged-In: I4a864823ec35a0b57b50909587cc3efac3f531a7
2021-04-07 22:38:20 +00:00
Steven Moreland
80c46b0541 String16::remove - avoid overflow am: 4048e49956 am: 107f18cb61 am: 9be245c3f0 am: 64fb5012b8 am: 4e27b6992b am: 26b81f59d2 am: 8367a666b5
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/core/+/11619802

Change-Id: Ic25dca55b553b062edc4ced44ddef68b96428906
2020-07-14 17:24:42 +00:00
Steven Moreland
8367a666b5 String16::remove - avoid overflow am: 4048e49956 am: 107f18cb61 am: 9be245c3f0 am: 64fb5012b8 am: 4e27b6992b am: 26b81f59d2
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/core/+/11619802

Change-Id: Ib4704bc8a733ace56e7998b7bad5a6c5638900ad
2020-07-14 17:03:30 +00:00
Steven Moreland
4e27b6992b String16::remove - avoid overflow am: 4048e49956 am: 107f18cb61 am: 9be245c3f0 am: 64fb5012b8
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/core/+/11619802

Change-Id: I03057c052a24f205c78ee600178d45e0cd51a3c1
2020-07-14 16:29:09 +00:00
Steven Moreland
4048e49956 String16::remove - avoid overflow
Bug: 156999009
Test: libutils_test (cases added)
Change-Id: Iad46d95d9848928ba81000090b2fe9aec1e5eaac
Merged-In: Iad46d95d9848928ba81000090b2fe9aec1e5eaac
(cherry picked from commit f251c1c581)
(cherry picked from commit 9a9c8910e9296c9dc8d79c37f589895f5a2a836c)
2020-05-28 20:45:55 +00:00
Steven Moreland
727a6dd5f5 String*: remove 'StaticLinkage' constructor
Unneeded.

Bug: N/A
Test: N/A
Change-Id: I3ff473d1e2fec98e47abd8abb45dd36e0a808170
2020-02-10 13:56:44 -08:00
Vic Yang
5a141424e6 Fix memory leak in String16
Newly allocated SharedBuffer already has reference count 1, so we
should not call acquire().

Bug: 141764153
Test: Run String16Test.* with ASan that was able to detect the leak
      without this change.
Change-Id: Ib8b1b707b028386d717414d8c5ec5ea7b4b59464
2019-09-27 21:07:00 -07:00
Vic Yang
9fb93edd5b Reland "libutils: Introduce StaticString16""
This reverts commit 1270e4fbf1.

Bug: 138856262
Test: Run unit tests.
Change-Id: I37be01d7d4f98a83078870cb0917275336fa2bbd
Merged-In: I8da93f2c9b95183e32d4a2ea895f90c449abbe4d
2019-09-05 13:19:14 -07:00
Kevin Han
1270e4fbf1 Revert "Reland "libutils: Introduce StaticString16"""
This reverts commit c55ac92bd6.

Reason for revert: Breaks down-stream branches. See b/140315617

Change-Id: I4937fdf4bdcc7a44d5f10700ecf2d5e96aef7d27
Merged-In: I8da93f2c9b95183e32d4a2ea895f90c449abbe4d
2019-08-30 23:50:38 +00:00
Vic Yang
c55ac92bd6 Reland "libutils: Introduce StaticString16""
This time with old branches excluded.

Bug: 138856262
Test: Run unit tests.
Change-Id: Id0bb1d54b71e38244d64f1b684db1fda81de854c
Merged-In: I8da93f2c9b95183e32d4a2ea895f90c449abbe4d
2019-08-30 11:01:27 -07:00
Vic Yang
86eaa8de78 Revert "libutils: Introduce StaticString16"
This reverts commit d4cb489434.

Reason for revert: Breaking aosp_bonito-userdebug

Change-Id: Iea72f39d40f476002ce0ad6b5ce3b4e1ca570de7
2019-08-29 22:47:07 +00:00
Vic Yang
d4cb489434 libutils: Introduce StaticString16
This is a backward compatible implementation of compile time
constructed String16 support.

As much as we'd like a regular constexpr constructor for String16, we
want to make sure the regular non-static String16 does not regress.
We also need to make sure prebuilts built with previous version of
String16 still works with new libutils.  This means we cannot change
the size of String16 objects and we cannot make anything virtual.

To add a flag to indicate whether a String16 is static without
increasing the size of non-static String16 objects, we repurpose a
reserved field in SharedBuffer as "for client use".  With this, we can
tag every String16 and perform memory operation differently based on
how the underlying buffers are allocated.

By using StaticString16, we are able to eliminate the runtime
construction of a String16 and move it out of .bss section.

Bug: 138856262
Test: Run newly added unit tests.
Change-Id: I72bb8dc27a59b9ef34e0d934bc1e00b0f675855a
2019-08-09 11:01:37 -07:00
Elliott Hughes
643268f325 Move system/core/ off NO_ERROR.
It causes trouble for Windows, and OK already exists.

Bug: N/A
Test: builds
Change-Id: Ida22fd658b0ebb259c710ba39049b07c9e495d9c
2018-10-08 11:15:52 -07:00
Yi Kong
2a6a58a818 Merge "[libutils] Modernize codebase by replacing NULL with nullptr"
am: ab3203f383

Change-Id: I5c2aaaea705a3ab82a5ad999f813e4cc22e63401
2018-07-17 10:06:10 -07:00
Yi Kong
e1731a4f2e [libutils] Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.

Test: m
Bug: 68236239
Change-Id: I5e89ec8c42151875439d2656475a8739ab9cb7dc
2018-07-16 18:11:34 -07:00
Steven Moreland
d6c3476582 Merge "libutils: Remove Static.cpp and darwin hacks." am: 929112bcd1
am: 41a294981b

Change-Id: Iebe132eaca4f9034a8e011881f1514f864529fc5
2018-03-08 21:44:42 +00:00
Steven Moreland
241b93cfd3 libutils: Remove Static.cpp and darwin hacks.
Bug: N/A
Test: in internal master, the only libraries that reference this
  symbol are:
./prebuilts/sdk/tools/linux/bin/split-select android::gDarwinIsReallyAnnoying
./prebuilts/sdk/tools/linux/bin/aapt android::gDarwinIsReallyAnnoying
./prebuilts/sdk/tools/linux/bin/aapt2 android::gDarwinIsReallyAnnoying
./prebuilts/sdk/tools/linux/lib64/libaapt2_jni.so android::gDarwinIsReallyAnnoying
./prebuilts/sdk/tools/linux/lib64/libaapt2_jni.so android::gDarwinIsReallyAnnoying
+ VNDK libraries
Test: libutils_test

Change-Id: Id39e5ef6438e48fa225ba06dbb59902ca5b60f70
2018-03-06 17:44:08 +00:00
Steven Moreland
0e5fbea01c String16: remove integer overflows
Bug: 73826242
Test: manual
Change-Id: I32e13d61b944c1a527cf2d95473552d246e322be
2018-03-02 20:16:28 +00:00
Steven Moreland
977f72f9bc String16: remove integer overflows
Bug: 73826242
Test: manual
Change-Id: I32e13d61b944c1a527cf2d95473552d246e322be
2018-03-01 11:04:08 -08:00
Steven Moreland
d21cfab244 Add missing includes.
Includes are transitively imported by <string> in String8.h + String16.h
but that include is being removed.

Test: pass
Change-Id: Ide5c011b40b4a4f031dd26ead08b5c8d5d299693
2017-03-10 09:05:30 -08:00
Mathias Agopian
22dbf3947f clean-up libutils includes
moved Foo.h as first include of Foo.cpp, and
removed redundant includes.

Made NativeHandle non virtual.


Test: run & compile
Bug: n/a

Change-Id: I37fa746cd42c9ba23aba181f84cb6c619386406a
2017-03-03 14:47:47 -08:00
Sergio Giro
1dcc0c8239 Unicode: specify destination length in utf8_to_utf16 methods
String16(const char *utf8) now returns the empty string in case
a string ends halfway throw a utf8 character.

Bug: 29267949

Change-Id: I5223caa7d42f4582a982609a898a02043265c6d3
2016-08-02 18:47:53 +00:00
Michael Wright
2a9a993af9 Merge commit '8b452b876b90dcfff1dab9012b65b5e67c4531a4' into manual_merge_8b452b8
Change-Id: Iacdc2d521f669661b4979c03b0476512abdb37c7
2016-05-16 15:06:22 +01:00
Michael Wright
5bacef33c9 Add String16#contains and strstr16 methods.
These are needed for aapt to find javadoc comments that contain
"@removed" in order to skip them when printing styleable docs.

Bug: 28663748
Change-Id: I8866d2167c41e11d6c2586da369560d5815fd13e
2016-05-09 19:45:07 +01:00
Samuel Tan
9ac4e005b4 libutils: add String8 and String16 std_string utility methods
Add utility methods that convert String16 and String8 into
std::string.

Also, remove a repeated include of <utils/Unicode.h> in
String16.h, since it is not used in that header file,
and is already included in String16.cpp.

BUG: 27200800
Change-Id: I5238aeb70689499763060a99dff9950fbb7adb3e
TEST: libutils builds successfully.
2016-02-18 17:04:23 -08:00
Samuel Tan
f9d16ef106 libutils: remove whitespaces in String16.cpp and String16.h
Remove trailing whitespaces in both these files.

BUG: None
Change-Id: I18eca5162871b5b2bf7757a7ef36a4e80073798c
2016-02-16 15:21:34 -08:00
Sergio Giro
282efae9c3 system/core: remove methods returning SharedBuffer in String8, String16
Towards deprecation of SharedBuffer

Change-Id: I3069837db32837bcc0f5d8f1118ccd502c9070dc
2015-09-30 15:42:02 +01:00
Sergio Giro
d2529f2830 libutils: hide SharedBuffer by moving SharedBuffer.h to the implementation directory
Some methods in header files of classes using SharedBuffer need
to be moved to the implementation files accordingly

Change-Id: I891f3ace2b940ab219e4e449040bfed71c0547db
2015-09-23 16:22:59 +01:00
Mark Salyzyn
5bed803664 libutils: turn on -Werror
- Deal with some -Wunused issues
- Override PRI macros (windows)
- Revert use of PRI macros on off64_t (linux)
- Deal with a gnu++11 complaince issue

Change-Id: Ie66751293bd84477a5a6dfd8a57e700a16e36964
2014-06-02 15:57:50 -07:00
Mark Salyzyn
6443033f6d String16.cpp rm unused utils/Debug.h
Change-Id: Ie7e3695770f20be33738a0f0a868cc914248d91a
2014-05-29 13:14:35 -07:00
Alex Ray
d98e07fdf9 move libs/utils to libutils
Change-Id: I6cf4268599460791414882f91eeb88a992fbd29d
2013-08-02 14:40:08 -07:00
Renamed from libs/utils/String16.cpp (Browse further)