[libcxx-commits] [PATCH] D76171: Upstream Bionic definitions of ctype_base/regex.

Dan Albert via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Mar 13 18:22:13 PDT 2020

danalbert created this revision.
danalbert added a reviewer: EricWF.
danalbert added a project: libc++.
Herald added a reviewer: libc++.

This is a patch that Android has been carrying in its tree for several
years. This patch upstreams the existing ABI.

There's some historical cruft here. __regex_word used to be a part of
regex_traits rather than ctype_base. Bionic also used to use its own
ctype implementation because the libc++ builtin one wasn't available
yet. Bionic's ctype masks were 8 bits wide and already saturated, so a
wider type needed to be used for the regex mask, and the existing
value was already used so Android needed to specify its own.

Since then Android has migrated to the builtin ctype implementation
and this patch probably should have been dropped then. Unfortunately
that was not noticed at the time, so now we need to keep this to
maintain the current ABI.

  rG LLVM Github Monorepo



Index: libcxx/include/regex
--- libcxx/include/regex
+++ libcxx/include/regex
@@ -1000,7 +1000,19 @@
     typedef _CharT                  char_type;
     typedef basic_string<char_type> string_type;
     typedef locale                  locale_type;
+#ifdef __BIONIC__
+    // Originally bionic's ctype_base used its own ctype masks because the
+    // builtin ctype implementation wasn't in libc++ yet. Bionic's ctype mask
+    // was only 8 bits wide and already saturated, so it used a wider type here
+    // to make room for __regex_word (then a part of this class rather than
+    // ctype_base). Bionic has since moved to the builtin ctype_base
+    // implementation, but this was not updated to match. Since then Android has
+    // needed to maintain a stable libc++ ABI, and this can't be changed without
+    // an ABI break.
+    typedef uint16_t char_class_type;
     typedef ctype_base::mask        char_class_type;
     static const char_class_type __regex_word = ctype_base::__regex_word;
Index: libcxx/include/__locale
--- libcxx/include/__locale
+++ libcxx/include/__locale
@@ -496,7 +496,13 @@
     static const mask punct  = 1<<7;
     static const mask xdigit = 1<<8;
     static const mask blank  = 1<<9;
+#if defined(__BIONIC__)
+    // Historically this was a part of regex_traits rather than ctype_base. The
+    // historical value of the constant is preserved for ABI compatibility.
+    static const mask __regex_word = 0x8000;
     static const mask __regex_word = 1<<10;
+#endif // defined(__BIONIC__)
     static const mask alnum  = alpha | digit;
     static const mask graph  = alnum | punct;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76171.250335.patch
Type: text/x-patch
Size: 1804 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200314/6477a0c1/attachment.bin>

More information about the libcxx-commits mailing list