コード例 #1
0
ファイル: bslma_allocator.cpp プロジェクト: PeterMartini/bsl
// CLASS METHODS
void Allocator::throwBadAlloc()
{
    BSLS_THROW(std::bad_alloc());
}
コード例 #2
0
BSLS_BSLEXCEPTIONUTIL_NORETURN
void BslExceptionUtil::throwException()
{
    BSLS_THROW(std::exception());
}
コード例 #3
0
void SharedPtrUtil::throwBadWeakPtr()
{
    BSLS_THROW(bsl::bad_weak_ptr());
}
コード例 #4
0
BSLS_BSLEXCEPTIONUTIL_NORETURN
void BslExceptionUtil::throwBadCast()
{
    BSLS_THROW(std::bad_cast());
}
コード例 #5
0
BSLS_BSLEXCEPTIONUTIL_NORETURN
void BslExceptionUtil::throwBadTypeid()
{
    BSLS_THROW(std::bad_typeid());
}
コード例 #6
0
ファイル: bslstl_stdexceptutil.cpp プロジェクト: RMGiroux/bde
BSLSTL_STDEXCEPTUTIL_NORETURN
void StdExceptUtil::throwUnderflowError(const char *message)
{
    BSLS_THROW(std::underflow_error(message));
}
コード例 #7
0
// MANIPULATORS
void *GuardingAllocator::allocate(size_type size)
{
    if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(0 == size)) {
        BSLS_PERFORMANCEHINT_UNLIKELY_HINT;
        return 0;                                                     // RETURN
    }

    const size_type paddedSize =
                          bsls::AlignmentUtil::roundUpToMaximalAlignment(size);

    // Adjust for additional memory needed to stash reference addresses when
    // 'e_AFTER_USER_BLOCK' is in use.

    const int adjustedSize = e_AFTER_USER_BLOCK == d_guardPageLocation
                             ? paddedSize + OFFSET * 2
                             : paddedSize;

    // Calculate the number of pages to allocate, *not* counting the guard
    // page.

    const int pageSize = getSystemPageSize();
    const int numPages = (adjustedSize + pageSize - 1) / pageSize;

    const size_type totalSize = (numPages + 1) * pageSize;  // add 1 for guard

    void *firstPage = systemAlloc(totalSize);

    if (!firstPage) {
#ifdef BDE_BUILD_TARGET_EXC
        BSLS_THROW(bsl::bad_alloc());
#else
        return 0;                                                     // RETURN
#endif
    }

    void *userAddress;  // address to return to the caller
    void *guardPage;    // address of the guard page for this allocation

    if (e_BEFORE_USER_BLOCK == d_guardPageLocation) {
        // Protect the memory page before the block returned to the user.

        guardPage   = firstPage;
        userAddress = static_cast<char *>(firstPage) + pageSize;
    }
    else {
        // Protect the memory page after the block returned to the user.

        guardPage   = static_cast<char *>(firstPage) + (numPages * pageSize);
        userAddress = static_cast<char *>(guardPage) - paddedSize;

        // Stash the reference addresses required by 'deallocate'.

        *(void **)(static_cast<char *>(userAddress) - OFFSET)     = firstPage;
        *(void **)(static_cast<char *>(userAddress) - OFFSET * 2) = guardPage;
    }

    // Protect the guard page from read/write access.

    if (0 != systemProtect(guardPage, pageSize)) {
        systemFree(firstPage);
#ifdef BDE_BUILD_TARGET_EXC
        BSLS_THROW(bsl::bad_alloc());
#else
        return 0;                                                     // RETURN
#endif
    }

    return userAddress;
}
コード例 #8
0
ファイル: bslstl_stdexceptutil.cpp プロジェクト: RMGiroux/bde
BSLSTL_STDEXCEPTUTIL_NORETURN
void StdExceptUtil::throwRangeError(const char *message)
{
    BSLS_THROW(std::range_error(message));
}
コード例 #9
0
ファイル: bslstl_stdexceptutil.cpp プロジェクト: RMGiroux/bde
BSLSTL_STDEXCEPTUTIL_NORETURN
void StdExceptUtil::throwOutOfRange(const char *message)
{
    BSLS_THROW(std::out_of_range(message));
}
コード例 #10
0
ファイル: bslstl_stdexceptutil.cpp プロジェクト: RMGiroux/bde
BSLSTL_STDEXCEPTUTIL_NORETURN
void StdExceptUtil::throwLengthError(const char *message)
{
    BSLS_THROW(std::length_error(message));
}
コード例 #11
0
ファイル: bslstl_stdexceptutil.cpp プロジェクト: RMGiroux/bde
BSLSTL_STDEXCEPTUTIL_NORETURN
void StdExceptUtil::throwInvalidArgument(const char *message)
{
    BSLS_THROW(std::invalid_argument(message));
}
コード例 #12
0
ファイル: bslstl_stdexceptutil.cpp プロジェクト: RMGiroux/bde
BSLSTL_STDEXCEPTUTIL_NORETURN
void StdExceptUtil::throwDomainError(const char *message)
{
    BSLS_THROW(std::domain_error(message));
}