Ejemplo n.º 1
0
void
__libcpp_db::swap(void* c1, void* c2)
{
    WLock _(mut());
    size_t hc = hash<void*>()(c1) % static_cast<size_t>(__cend_ - __cbeg_);
    __c_node* p1 = __cbeg_[hc];
    _LIBCPP_ASSERT(p1 != nullptr, "debug mode internal logic error swap A");
    while (p1->__c_ != c1)
    {
        p1 = p1->__next_;
        _LIBCPP_ASSERT(p1 != nullptr, "debug mode internal logic error swap B");
    }
    hc = hash<void*>()(c2) % static_cast<size_t>(__cend_ - __cbeg_);
    __c_node* p2 = __cbeg_[hc];
    _LIBCPP_ASSERT(p2 != nullptr, "debug mode internal logic error swap C");
    while (p2->__c_ != c2)
    {
        p2 = p2->__next_;
        _LIBCPP_ASSERT(p2 != nullptr, "debug mode internal logic error swap D");
    }
    std::swap(p1->beg_, p2->beg_);
    std::swap(p1->end_, p2->end_);
    std::swap(p1->cap_, p2->cap_);
    for (__i_node** p = p1->beg_; p != p1->end_; ++p)
        (*p)->__c_ = p1;
    for (__i_node** p = p2->beg_; p != p2->end_; ++p)
        (*p)->__c_ = p2;
}
Ejemplo n.º 2
0
void
__libcpp_db::__erase_c(void* __c)
{
    WLock _(mut());
    size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
    __c_node* p = __cbeg_[hc];
    __c_node* q = nullptr;
    _LIBCPP_ASSERT(p != nullptr, "debug mode internal logic error __erase_c A");
    while (p->__c_ != __c)
    {
        q = p;
        p = p->__next_;
        _LIBCPP_ASSERT(p != nullptr, "debug mode internal logic error __erase_c B");
    }
    if (q == nullptr)
        __cbeg_[hc] = p->__next_;
    else
        q->__next_ = p->__next_;
    while (p->end_ != p->beg_)
    {
        --p->end_;
        (*p->end_)->__c_ = nullptr;
    }
    free(p->beg_);
    free(p);
    --__csz_;
}
Ejemplo n.º 3
0
__c_node*
__libcpp_db::__find_c(void* __c) const
{
    size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
    __c_node* p = __cbeg_[hc];
    _LIBCPP_ASSERT(p != nullptr, "debug mode internal logic error __find_c A");
    while (p->__c_ != __c)
    {
        p = p->__next_;
        _LIBCPP_ASSERT(p != nullptr, "debug mode internal logic error __find_c B");
    }
    return p;
}
Ejemplo n.º 4
0
__c_node*
__libcpp_db::__find_c_and_lock(void* __c) const
{
    mut().lock();
    size_t hc = hash<void*>()(__c) % (__cend_ - __cbeg_);
    __c_node* p = __cbeg_[hc];
    _LIBCPP_ASSERT(p != nullptr, "debug mode internal logic error __find_c_and_lock A");
    while (p->__c_ != __c)
    {
        p = p->__next_;
        _LIBCPP_ASSERT(p != nullptr, "debug mode internal logic error __find_c_and_lock B");
    }
    return p;
}
Ejemplo n.º 5
0
void*
__libcpp_db::__find_c_from_i(void* __i) const
{
    RLock _(mut());
    __i_node* i = __find_iterator(__i);
    _LIBCPP_ASSERT(i != nullptr, "iterator not found in debug database.");
    return i->__c_ != nullptr ? i->__c_->__c_ : nullptr;
}
Ejemplo n.º 6
0
_LIBCPP_HIDDEN
void
__c_node::__remove(__i_node* p)
{
    __i_node** r = find(beg_, end_, p);
    _LIBCPP_ASSERT(r != end_, "debug mode internal logic error __c_node::__remove");
    if (--end_ != r)
        memmove(r, r+1, static_cast<size_t>(end_ - r)*sizeof(__i_node*));
}
Ejemplo n.º 7
0
void
__libcpp_db::__invalidate_all(void* __c)
{
    WLock _(mut());
    size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
    __c_node* p = __cbeg_[hc];
    _LIBCPP_ASSERT(p != nullptr, "debug mode internal logic error __invalidate_all A");
    while (p->__c_ != __c)
    {
        p = p->__next_;
        _LIBCPP_ASSERT(p != nullptr, "debug mode internal logic error __invalidate_all B");
    }
    while (p->end_ != p->beg_)
    {
        --p->end_;
        (*p->end_)->__c_ = nullptr;
    }
}
Ejemplo n.º 8
0
void*
__libcpp_db::__find_c_from_i(void* __i) const
{
    RLock _(mut());
    __i_node* i = __find_iterator(__i);
    _LIBCPP_ASSERT(i != nullptr, "iterator constructed in translation unit with debug mode not enabled."
                   "  #define _LIBCPP_DEBUG2 1 for that translation unit.");
    return i->__c_ != nullptr ? i->__c_->__c_ : nullptr;
}
Ejemplo n.º 9
0
_LIBCPP_CONSTEXPR_AFTER_CXX11 _CharT*
constexpr_char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
{
    _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
    char_type* __r = __s1;
    for (; __n; --__n, ++__s1, ++__s2)
        assign(*__s1, *__s2);
    return __r;
}
Ejemplo n.º 10
0
void
__libcpp_db::__insert_ic(void* __i, const void* __c)
{
    WLock _(mut());
    __i_node* i = __insert_iterator(__i);
    const char* errmsg =
        "Container constructed in a translation unit with debug mode disabled."
        " But it is being used in a translation unit with debug mode enabled."
        " Enable it in the other translation unit with #define _LIBCPP_DEBUG2 1";
    _LIBCPP_ASSERT(__cbeg_ != __cend_, errmsg);
    size_t hc = hash<const void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
    __c_node* c = __cbeg_[hc];
    _LIBCPP_ASSERT(c != nullptr, errmsg);
    while (c->__c_ != __c)
    {
        c = c->__next_;
        _LIBCPP_ASSERT(c != nullptr, errmsg);
    }
    c->__add(i);
    i->__c_ = c;
}
Ejemplo n.º 11
0
int main()
{
  {
    std::__libcpp_debug_function = std::__libcpp_throw_debug_function;
    try {
      _LIBCPP_ASSERT(false, "foo");
    } catch (std::__libcpp_debug_exception const&) {}
  }
  {
    // test that the libc++ exception type derives from std::exception
    static_assert((std::is_base_of<std::exception,
                                  std::__libcpp_debug_exception
                  >::value), "must be an exception");
  }
}
Ejemplo n.º 12
0
strstreambuf::int_type
strstreambuf::overflow(int_type __c)
{
    if (__c == EOF)
        return int_type(0);
    if (pptr() == epptr())
    {
        if ((__strmode_ & __dynamic) == 0 || (__strmode_ & __frozen) != 0)
            return int_type(EOF);
        size_t old_size = static_cast<size_t> ((epptr() ? epptr() : egptr()) - eback());
        size_t new_size = max<size_t>(static_cast<size_t>(__alsize_), 2*old_size);
        if (new_size == 0)
            new_size = __default_alsize;
        char* buf = nullptr;
        if (__palloc_)
            buf = static_cast<char*>(__palloc_(new_size));
        else
            buf = new char[new_size];
        if (buf == nullptr)
            return int_type(EOF);
        if (old_size != 0) {
            _LIBCPP_ASSERT(eback(), "overflow copying from NULL");
            memcpy(buf, eback(), static_cast<size_t>(old_size));
        }
        ptrdiff_t ninp = gptr()  - eback();
        ptrdiff_t einp = egptr() - eback();
        ptrdiff_t nout = pptr()  - pbase();
        if (__strmode_ & __allocated)
        {
            if (__pfree_)
                __pfree_(eback());
            else
                delete [] eback();
        }
        setg(buf, buf + ninp, buf + einp);
        setp(buf + einp, buf + new_size);
        pbump(static_cast<int>(nout));
        __strmode_ |= __allocated;
    }
    *pptr() = static_cast<char>(__c);
    pbump(1);
    return int_type(static_cast<unsigned char>(__c));
}
Ejemplo n.º 13
0
int main()
{
  if (std::signal(SIGABRT, signal_handler) != SIG_ERR)
    _LIBCPP_ASSERT(false, "foo");
  return EXIT_FAILURE;
}
Ejemplo n.º 14
0
void testRuntimeSpan(Span sp)
{
    _LIBCPP_ASSERT(sp.back(), "");
    assert(std::addressof(sp.back()) == sp.data() + sp.size() - 1);
}
Ejemplo n.º 15
0
constexpr bool testConstexprSpan(Span sp)
{
    _LIBCPP_ASSERT(sp.back(), "");
    return std::addressof(sp.back()) == sp.data() + sp.size() - 1;
}