[libcxx] r307749 - Remove <__refstring> header; Move it into source directory.

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 11 18:38:35 PDT 2017


Author: ericwf
Date: Tue Jul 11 18:38:35 2017
New Revision: 307749

URL: http://llvm.org/viewvc/llvm-project?rev=307749&view=rev
Log:
Remove <__refstring> header; Move it into source directory.

The libc++ <__refstring> headers has no real reason why it should
be a public header that libc++ ships. The only reason it was in the include
directory was because libc++abi needed it to build the library.

However keeping <__refstring> a header had other problems, like requiring its
dependancies to also be in the headers. For that reason this patch
moves it into the source directory.

To work around libc++abi's need for this header a duplicated copy was added
to libc++abi in r307748. While duplicating the code is an unfortunate solution
it's the best solution that's currently possible.

In the future I would like to start a discussion on the mailing lists about
making libc++abi build as a sub-project of libc++, requiring the libc++ sources
always be present.

Added:
    libcxx/trunk/src/include/refstring.h
      - copied, changed from r307746, libcxx/trunk/include/__refstring
Removed:
    libcxx/trunk/include/__refstring
Modified:
    libcxx/trunk/src/stdexcept.cpp

Removed: libcxx/trunk/include/__refstring
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__refstring?rev=307748&view=auto
==============================================================================
--- libcxx/trunk/include/__refstring (original)
+++ libcxx/trunk/include/__refstring (removed)
@@ -1,127 +0,0 @@
-//===------------------------ __refstring ---------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP___REFSTRING
-#define _LIBCPP___REFSTRING
-
-#include <__config>
-#include <stdexcept>
-#include <cstddef>
-#include <cstring>
-#ifdef __APPLE__
-#include <dlfcn.h>
-#include <mach-o/dyld.h>
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-namespace __refstring_imp { namespace {
-typedef int count_t;
-
-struct _Rep_base {
-    std::size_t len;
-    std::size_t cap;
-    count_t     count;
-};
-
-inline _Rep_base* rep_from_data(const char *data_) noexcept {
-    char *data = const_cast<char *>(data_);
-    return reinterpret_cast<_Rep_base *>(data - sizeof(_Rep_base));
-}
-
-inline char * data_from_rep(_Rep_base *rep) noexcept {
-    char *data = reinterpret_cast<char *>(rep);
-    return data + sizeof(*rep);
-}
-
-#if defined(__APPLE__)
-inline
-const char* compute_gcc_empty_string_storage() _NOEXCEPT
-{
-    void* handle = dlopen("/usr/lib/libstdc++.6.dylib", RTLD_NOLOAD);
-    if (handle == nullptr)
-        return nullptr;
-    void* sym = dlsym(handle, "_ZNSs4_Rep20_S_empty_rep_storageE");
-    if (sym == nullptr)
-        return nullptr;
-    return data_from_rep(reinterpret_cast<_Rep_base *>(sym));
-}
-
-inline
-const char*
-get_gcc_empty_string_storage() _NOEXCEPT
-{
-    static const char* p = compute_gcc_empty_string_storage();
-    return p;
-}
-#endif
-
-}} // namespace __refstring_imp
-
-using namespace __refstring_imp;
-
-inline
-__libcpp_refstring::__libcpp_refstring(const char* msg) {
-    std::size_t len = strlen(msg);
-    _Rep_base* rep = static_cast<_Rep_base *>(::operator new(sizeof(*rep) + len + 1));
-    rep->len = len;
-    rep->cap = len;
-    rep->count = 0;
-    char *data = data_from_rep(rep);
-    std::memcpy(data, msg, len + 1);
-    __imp_ = data;
-}
-
-inline
-__libcpp_refstring::__libcpp_refstring(const __libcpp_refstring &s) _NOEXCEPT
-    : __imp_(s.__imp_)
-{
-    if (__uses_refcount())
-        __sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
-}
-
-inline
-__libcpp_refstring& __libcpp_refstring::operator=(__libcpp_refstring const& s) _NOEXCEPT {
-    bool adjust_old_count = __uses_refcount();
-    struct _Rep_base *old_rep = rep_from_data(__imp_);
-    __imp_ = s.__imp_;
-    if (__uses_refcount())
-        __sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
-    if (adjust_old_count)
-    {
-        if (__sync_add_and_fetch(&old_rep->count, count_t(-1)) < 0)
-        {
-            ::operator delete(old_rep);
-        }
-    }
-    return *this;
-}
-
-inline
-__libcpp_refstring::~__libcpp_refstring() {
-    if (__uses_refcount()) {
-        _Rep_base* rep = rep_from_data(__imp_);
-        if (__sync_add_and_fetch(&rep->count, count_t(-1)) < 0) {
-            ::operator delete(rep);
-        }
-    }
-}
-
-inline
-bool __libcpp_refstring::__uses_refcount() const {
-#ifdef __APPLE__
-    return __imp_ != get_gcc_empty_string_storage();
-#else
-    return true;
-#endif
-}
-
-_LIBCPP_END_NAMESPACE_STD
-
-#endif //_LIBCPP___REFSTRING

Copied: libcxx/trunk/src/include/refstring.h (from r307746, libcxx/trunk/include/__refstring)
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/include/refstring.h?p2=libcxx/trunk/src/include/refstring.h&p1=libcxx/trunk/include/__refstring&r1=307746&r2=307749&rev=307749&view=diff
==============================================================================
--- libcxx/trunk/include/__refstring (original)
+++ libcxx/trunk/src/include/refstring.h Tue Jul 11 18:38:35 2017
@@ -7,8 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _LIBCPP___REFSTRING
-#define _LIBCPP___REFSTRING
+#ifndef _LIBCPP_REFSTRING_H
+#define _LIBCPP_REFSTRING_H
 
 #include <__config>
 #include <stdexcept>
@@ -124,4 +124,4 @@ bool __libcpp_refstring::__uses_refcount
 
 _LIBCPP_END_NAMESPACE_STD
 
-#endif //_LIBCPP___REFSTRING
+#endif //_LIBCPP_REFSTRING_H

Modified: libcxx/trunk/src/stdexcept.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/stdexcept.cpp?rev=307749&r1=307748&r2=307749&view=diff
==============================================================================
--- libcxx/trunk/src/stdexcept.cpp (original)
+++ libcxx/trunk/src/stdexcept.cpp Tue Jul 11 18:38:35 2017
@@ -11,7 +11,7 @@
 #include "new"
 #include "string"
 #include "system_error"
-#include "__refstring"
+#include "include/refstring.h"
 
 /* For _LIBCPPABI_VERSION */
 #if !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) && \




More information about the cfe-commits mailing list