MovableAllocTestType::~MovableAllocTestType()
{
    d_allocator_p->deallocate(d_data_p);

    BSLS_ASSERT_OPT(!!d_data_p ==
                               (bsltf::MoveState::e_NOT_MOVED == d_movedFrom));

    // Ensure that this objects has not been bitwise moved.

    BSLS_ASSERT_OPT(this == d_self_p);
}
Beispiel #2
0
void *BufferImpUtil::allocateFromBufferRaw(int                       *cursor,
                                           char                      *buffer,
                                           int                        size,
                                           bsls::Alignment::Strategy  strategy)
{
    BSLS_ASSERT(cursor);
    BSLS_ASSERT(buffer);
    BSLS_ASSERT(0 < size);
    BSLS_ASSERT(0 <= *cursor);

    void *result = 0;

    switch (strategy) {
      case bsls::Alignment::BSLS_MAXIMUM: {
        result = BufferImpUtil::allocateMaximallyAlignedFromBufferRaw(cursor,
                                                                      buffer,
                                                                      size);
      } break;
      case bsls::Alignment::BSLS_NATURAL: {
        result = BufferImpUtil::allocateNaturallyAlignedFromBufferRaw(cursor,
                                                                      buffer,
                                                                      size);
      } break;
      case bsls::Alignment::BSLS_BYTEALIGNED: {
        result = BufferImpUtil::allocateOneByteAlignedFromBufferRaw(cursor,
                                                                    buffer,
                                                                    size);
      } break;
      default: {
        BSLS_ASSERT_OPT(0 && "Invalid alignment 'strategy' value.");
      } break;
    }

    return result;
}
double PeriodDayCountUtil::yearsDiff(
                                 const bdlt::Date&              beginDate,
                                 const bdlt::Date&              endDate,
                                 const bsl::vector<bdlt::Date>& periodDate,
                                 double                         periodYearDiff,
                                 DayCountConvention::Enum       convention)
{
    BSLS_ASSERT(periodDate.size() >= 2);
    BSLS_ASSERT(periodDate.front() <= beginDate);
    BSLS_ASSERT(                      beginDate <= periodDate.back());
    BSLS_ASSERT(periodDate.front() <= endDate);
    BSLS_ASSERT(                      endDate   <= periodDate.back());

    BSLS_ASSERT_SAFE(isSortedAndUnique(periodDate.begin(), periodDate.end()));

    double numYears;

    switch (convention) {
      case DayCountConvention::e_PERIOD_ICMA_ACTUAL_ACTUAL: {
        numYears = bbldc::PeriodIcmaActualActual::yearsDiff(beginDate,
                                                            endDate,
                                                            periodDate,
                                                            periodYearDiff);
      } break;
      default: {
        BSLS_ASSERT_OPT(0 && "Unrecognized convention");
        numYears = 0.0;
      } break;
    }

    return numYears;
}
void GuardingAllocator::deallocate(void *address)
{
    if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(0 == address)) {
        BSLS_PERFORMANCEHINT_UNLIKELY_HINT;
        return;                                                       // RETURN
    }

    const int pageSize = getSystemPageSize();

    void *firstPage;  // address of the first page of the allocation
    void *guardPage;  // address of the guard page

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

        firstPage = static_cast<char *>(address) - pageSize;
        guardPage = firstPage;
    }
    else {
        // The memory page after the block returned to the user is protected.

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

    // Unprotect the guard page and free the memory.

    const int rc = systemUnprotect(guardPage, pageSize);
    (void)rc;

    BSLS_ASSERT_OPT(0 == rc);

    systemFree(firstPage);
}
StackTraceTestAllocator::StackTraceTestAllocator(
                                           int               numRecordedFrames,
                                           bslma::Allocator *basicAllocator)
: d_magic(k_STACK_TRACE_TEST_ALLOCATOR_MAGIC)
, d_numBlocksInUse(0)
, d_blocks(0)
, d_mutex()
, d_name("<unnamed>")
, d_failureHandler(bsl::allocator_arg_t(),
                   bsl::allocator<FailureHandler>(basicAllocator
                                   ? basicAllocator
                                   : &bslma::MallocFreeAllocator::singleton()))
, d_maxRecordedFrames(numRecordedFrames + k_IGNORE_FRAMES)
, d_traceBufferLength(getTraceBufferLength(numRecordedFrames))
, d_ostream(&bsl::cerr)
, d_demangleFlag(true)
, d_allocator_p(basicAllocator ? basicAllocator
                               : &bslma::MallocFreeAllocator::singleton())
{
    BSLS_ASSERT_OPT(numRecordedFrames >= 2);
    BSLS_ASSERT(d_maxRecordedFrames >= numRecordedFrames);
    BSLS_ASSERT(d_traceBufferLength >= d_maxRecordedFrames);

    // This must be assigned in a statement in the body of the c'tor rather
    // than in the initializer list to work around a microsoft bug with
    // function pointers.

    d_failureHandler = &failAbort;
}
void StdTestAllocatorConfiguration::setDelegateAllocatorRaw(
                                              bslma::Allocator *basicAllocator)
{
    BSLS_ASSERT_OPT(basicAllocator);

    s_StdTestAllocatorConfiguration_allocator_p = basicAllocator;
}
Beispiel #7
0
AllocTestType::~AllocTestType()
{
    d_allocator_p->deallocate(d_data_p);

    // Ensure that this objects has not been bitwise moved.

    BSLS_ASSERT_OPT(this == d_self_p);
}
// CLASS METHODS
int PeriodDayCountUtil::daysDiff(const bdlt::Date&        beginDate,
                                 const bdlt::Date&        endDate,
                                 DayCountConvention::Enum convention)
{
    int numDays;

    switch (convention) {
      case DayCountConvention::e_PERIOD_ICMA_ACTUAL_ACTUAL: {
        numDays = bbldc::PeriodIcmaActualActual::daysDiff(beginDate, endDate);
      } break;
      default: {
        BSLS_ASSERT_OPT(0 && "Unrecognized convention");
        numDays = 0;
      } break;
    }

    return numDays;
}
Beispiel #9
0
FixedThreadPool::FixedThreadPool(int               numThreads,
                                 int               maxNumPendingJobs,
                                 bslma::Allocator *basicAllocator)
: d_queue(maxNumPendingJobs, basicAllocator)
, d_control(e_STOP)
, d_gateCount(0)
, d_numThreadsReady(0)
, d_threadGroup(basicAllocator)
, d_numThreads(numThreads)
{
    BSLS_ASSERT_OPT(0 != d_numThreads);

    disable();

#if defined(BSLS_PLATFORM_OS_UNIX)
    initBlockSet(&d_blockSet);
#endif
}
double BasicDayCountUtil::yearsDiff(const bdlt::Date&        beginDate,
                                    const bdlt::Date&        endDate,
                                    DayCountConvention::Enum convention)
{
    double numYears;

    switch (convention) {
      case DayCountConvention::e_ACTUAL_360: {
        numYears = bbldc::BasicActual360::yearsDiff(beginDate, endDate);
      } break;
      case DayCountConvention::e_ACTUAL_365_FIXED: {
        numYears = bbldc::BasicActual365Fixed::yearsDiff(beginDate, endDate);
      } break;
      case DayCountConvention::e_ISDA_ACTUAL_ACTUAL: {
        numYears = bbldc::BasicIsdaActualActual::yearsDiff(beginDate, endDate);
      } break;
      case DayCountConvention::e_ISMA_30_360: {
        numYears = bbldc::BasicIsma30360::yearsDiff(beginDate, endDate);
      } break;
      case DayCountConvention::e_PSA_30_360_EOM: {
        numYears = bbldc::BasicPsa30360Eom::yearsDiff(beginDate, endDate);
      } break;
      case DayCountConvention::e_SIA_30_360_EOM: {
        numYears = bbldc::BasicSia30360Eom::yearsDiff(beginDate, endDate);
      } break;
      case DayCountConvention::e_SIA_30_360_NEOM: {
        numYears = bbldc::BasicSia30360Neom::yearsDiff(beginDate, endDate);
      } break;
      default: {
        BSLS_ASSERT_OPT(0 && "Unrecognized convention");
        numYears = 0.0;
      } break;
    }

    return numYears;
}
Beispiel #11
0
int SocketImpUtil_Util::mapErrorCode(int errorNumber)
{
    switch (
#if defined(BTLSO_PLATFORM_WIN_SOCKETS)
            errorNumber
#else
            BSLS_PERFORMANCEHINT_PREDICT_EXPECT(errorNumber, EAGAIN)
#endif
                                                                    ) {
#if defined(BTLSO_PLATFORM_WIN_SOCKETS)
      // Windows (WINSOCK) specific socket error codes
      // WSAEWOULDBLOCK is the most likely error for common use.

      case WSAEWOULDBLOCK:                                      // FALL THROUGH
      case WSAEINPROGRESS: {
        return btlso::SocketHandle::e_ERROR_WOULDBLOCK;               // RETURN
      }
      case WSAECONNABORTED:                                     // FALL THROUGH
      case WSAECONNREFUSED:                                     // FALL THROUGH
      case WSAECONNRESET:                                       // FALL THROUGH
      case WSAEDISCON:                                          // FALL THROUGH
      case WSAEHOSTDOWN:                                        // FALL THROUGH
      case WSAEHOSTUNREACH:                                     // FALL THROUGH
      case WSAENETDOWN:                                         // FALL THROUGH
      case WSAENETRESET:                                        // FALL THROUGH
      case WSAENETUNREACH:                                      // FALL THROUGH
      case WSAENOTCONN:                                         // FALL THROUGH
      case WSAEREFUSED:                                         // FALL THROUGH
      case WSAETIMEDOUT: {
        return btlso::SocketHandle::e_ERROR_CONNDEAD;                 // RETURN
      }
      case WSAEINTR: {
        return btlso::SocketHandle::e_ERROR_INTERRUPTED;              // RETURN
      }
      case WSAEACCES:                                           // FALL THROUGH
      case WSAEADDRINUSE:                                       // FALL THROUGH
      case WSAEADDRNOTAVAIL:                                    // FALL THROUGH
      case WSAEISCONN:                                          // FALL THROUGH
      case WSAELOOP:                                            // FALL THROUGH
      case WSAEMFILE:                                           // FALL THROUGH
      case WSAEMSGSIZE:                                         // FALL THROUGH
      case WSAENOTSOCK:                                         // FALL THROUGH
      case WSAESTALE:                                           // FALL THROUGH
      case WSANOTINITIALISED:                                   // FALL THROUGH
      case WSASYSNOTREADY: {
        return btlso::SocketHandle::e_ERROR_NORESOURCES;              // RETURN
      }
      case WSAEAFNOSUPPORT:                                     // FALL THROUGH
      case WSAEALREADY:                                         // FALL THROUGH
      case WSAEBADF:                                            // FALL THROUGH
      case WSAECANCELLED:                                       // FALL THROUGH
      case WSAEDESTADDRREQ:                                     // FALL THROUGH
      case WSAEDQUOT:                                           // FALL THROUGH
      case WSAEFAULT:                                           // FALL THROUGH
      case WSAEINVAL:                                           // FALL THROUGH
      case WSAEINVALIDPROCTABLE:                                // FALL THROUGH
      case WSAEINVALIDPROVIDER:                                 // FALL THROUGH
      case WSAENAMETOOLONG:                                     // FALL THROUGH
      case WSAENOBUFS:                                          // FALL THROUGH
      case WSAENOMORE:                                          // FALL THROUGH
      case WSAENOPROTOOPT:                                      // FALL THROUGH
      case WSAENOTEMPTY:                                        // FALL THROUGH
      case WSAEOPNOTSUPP:                                       // FALL THROUGH
      case WSAEPFNOSUPPORT:                                     // FALL THROUGH
      case WSAEPROCLIM:                                         // FALL THROUGH
      case WSAEPROTONOSUPPORT:                                  // FALL THROUGH
      case WSAEPROTOTYPE:                                       // FALL THROUGH
      case WSAEPROVIDERFAILEDINIT:                              // FALL THROUGH
      case WSAEREMOTE:                                          // FALL THROUGH
      case WSAESHUTDOWN:                                        // FALL THROUGH
      case WSAESOCKTNOSUPPORT:                                  // FALL THROUGH
      case WSAETOOMANYREFS:                                     // FALL THROUGH
      case WSAEUSERS:                                           // FALL THROUGH
      case WSASERVICE_NOT_FOUND:                                // FALL THROUGH
      case WSASYSCALLFAILURE:                                   // FALL THROUGH
      case WSATYPE_NOT_FOUND:                                   // FALL THROUGH
      case WSAVERNOTSUPPORTED:                                  // FALL THROUGH
      case WSA_E_CANCELLED:                                     // FALL THROUGH
      case WSA_E_NO_MORE: {
        return btlso::SocketHandle::e_ERROR_UNCLASSIFIED;             // RETURN
      }
#else
#if EAGAIN!=EWOULDBLOCK
      case EAGAIN:
#endif
      case EWOULDBLOCK: {
        return btlso::SocketHandle::e_ERROR_WOULDBLOCK;               // RETURN
      }
#ifdef EACCES
      case EACCES: {
        // Search permission is denied for a component of the path prefix of
        // the pathname in name.

        return btlso::SocketHandle::e_ERROR_NORESOURCES;              // RETURN
      }
#endif

#ifdef EADDRINUSE
      case EADDRINUSE: {
         // The address is already in use.

        return btlso::SocketHandle::e_ERROR_NORESOURCES;              // RETURN
      }
#endif

#ifdef EADDRNOTAVAIL
      case EADDRNOTAVAIL: {
         // The specified address is not available on the remote
         // machine.

        return btlso::SocketHandle::e_ERROR_NORESOURCES;              // RETURN
      }
#endif

#ifdef EAFNOSUPPORT
      case EAFNOSUPPORT: {
         // Addresses in the specified address family cannot be
         // used with this socket.

        return btlso::SocketHandle::e_ERROR_UNCLASSIFIED;             // RETURN
      }
#endif

#ifdef EALREADY
      case EALREADY: {
         // The socket is non-blocking and a previous connection
         // attempt has not yet been completed.

        return btlso::SocketHandle::e_ERROR_NORESOURCES;              // RETURN
      }
#endif

#ifdef EBADF
      case EBADF: {
         // The descriptor is invalid.

        return btlso::SocketHandle::e_ERROR_UNCLASSIFIED;             // RETURN
      }
#endif

#ifdef ECONNREFUSED
      case ECONNREFUSED: {
         // The attempt to connect was forcefully rejected.

        return btlso::SocketHandle::e_ERROR_CONNDEAD;                 // RETURN
      }
#endif

#ifdef EINPROGRESS
      case EINPROGRESS: {
         // The socket is non-blocking and the connection cannot be completed
         // immediately.

        return btlso::SocketHandle::e_ERROR_WOULDBLOCK;               // RETURN
      }
#endif

      case EINTR: {
         // The operation was interrupted by the delivery of a signal.

        return btlso::SocketHandle::e_ERROR_INTERRUPTED;              // RETURN
      }
#ifdef EIO
      case EIO: {
         // An I/O error occurred while reading from or writing to the file
         // system.

        return btlso::SocketHandle::e_ERROR_NORESOURCES;              // RETURN
      }
#endif

#ifdef EINVAL
      case EINVAL: {
         // tolen is not the size of a valid address for the specified
         // address family.

        return btlso::SocketHandle::e_ERROR_UNCLASSIFIED;             // RETURN
      }
#endif

#ifdef EISCONN
      case EISCONN: {
         // The socket is already connected.

        return btlso::SocketHandle::e_ERROR_NORESOURCES;              // RETURN
      }
#endif

#ifdef ELOOP
      case ELOOP: {
         // Too many symbolic links were encountered in translating the
         // pathname in name.

        return btlso::SocketHandle::e_ERROR_NORESOURCES;              // RETURN
      }
#endif

#ifdef ENETUNREACH
      case ENETUNREACH: {
         // The network is not reachable from this host.

        return btlso::SocketHandle::e_ERROR_CONNDEAD;                 // RETURN
      }
#endif

#ifdef EMSGSIZE
      case EMSGSIZE: {
         // The socket requires that message be sent atomically, and the
         // message was too long.

        return btlso::SocketHandle::e_ERROR_NORESOURCES;              // RETURN
      }
#endif

#ifdef EMFILE
      case EMFILE: {
         // The per-process descriptor table is full.

        return btlso::SocketHandle::e_ERROR_NORESOURCES;              // RETURN
      }
#endif

#ifdef ENFILE
      case ENFILE: {
         // The maximum number of file descriptors in the system are already
         // open.

        return btlso::SocketHandle::e_ERROR_NORESOURCES;              // RETURN
      }
#endif

#ifdef ENODEV
      case ENODEV: {
         // The protocol family and type corresponding to s could not be
         // found in the netconfig file.

        return btlso::SocketHandle::e_ERROR_UNCLASSIFIED;             // RETURN
      }
#endif

#ifdef ENOMEM
      case ENOMEM: {
         // There was insufficient user memory available to complete the
         // operation.

        return btlso::SocketHandle::e_ERROR_NORESOURCES;              // RETURN
      }
#endif

#ifdef ENOSR
      case ENOSR: {
         // There were insufficient STREAMS resources available to complete
         // the operation.

        return btlso::SocketHandle::e_ERROR_NORESOURCES;              // RETURN
      }
#endif

#ifdef ENOENT
      case ENOENT: {
         // A component of the path prefix of the pathname in name does not
         // exist.

        return btlso::SocketHandle::e_ERROR_NORESOURCES;              // RETURN
      }
#endif

#ifdef ENXIO
      case ENXIO: {
         //  The server exited before the connection was complete.

        return btlso::SocketHandle::e_ERROR_NORESOURCES;              // RETURN
      }
#endif
      case ETIMEDOUT: {
         // Connection establishment timed out without establishing a
         // connection.

         return btlso::SocketHandle::e_ERROR_CONNDEAD;                // RETURN
      }

#ifdef ENOTSOCK
      case ENOTSOCK: {
         // The descriptor does not reference a socket.

        return btlso::SocketHandle::e_ERROR_NORESOURCES;              // RETURN
      }
#endif

#ifdef EOPNOTSUPP
      case EOPNOTSUPP: {
         // The referenced socket is not of type SOCK_STREAM.

        return btlso::SocketHandle::e_ERROR_UNCLASSIFIED;             // RETURN
      }
#endif

#ifdef EOPNOSUPPORT
      case EOPNOSUPPORT: {
         // The specified protocol does not support creation of socket
         // pairs.

        return btlso::SocketHandle::e_ERROR_UNCLASSIFIED;             // RETURN
      }
#endif

#ifdef EPIPE
      case EPIPE: {
        // An attempt is made to write to a socket that is not open for
        // reading, or that has only one end open or that is no longer
        // connected to a peer endpoint.  A SIGPIPE signal will also be sent
        // to the process.  The process dies unless special provisions were
        // taken to catch or ignore the signal.

        return btlso::SocketHandle::e_ERROR_CONNDEAD;                 // RETURN
      }
#endif

#ifdef EPROTONOSUPPORT
      case EPROTONOSUPPORT: {
        // The specified protocol is not supported on this machine.

        return btlso::SocketHandle::e_ERROR_UNCLASSIFIED;             // RETURN
      }
#endif

#ifdef EPROTO
      case EPROTO: {
         // A protocol error has occurred;

        return btlso::SocketHandle::e_ERROR_UNCLASSIFIED;             // RETURN
      }
#endif

#ifdef ECONNABORTED
      case ECONNABORTED: {
         // Software caused connection abort

        return btlso::SocketHandle::e_ERROR_CONNDEAD;                 // RETURN
      }
#endif

#ifdef ECONNRESET
      case ECONNRESET: {
         // Connection reset by peer

        return btlso::SocketHandle::e_ERROR_CONNDEAD;                 // RETURN
      }
#endif

#ifdef EDESTADDRREQ
      case EDESTADDRREQ: {
        // Destination address required

        return btlso::SocketHandle::e_ERROR_UNCLASSIFIED;             // RETURN
      }
#endif

#ifdef EHOSTDOWN
      case EHOSTDOWN: {
        // Host is down

        return btlso::SocketHandle::e_ERROR_CONNDEAD;                 // RETURN
      }
#endif

#ifdef EHOSTUNREACH
      case EHOSTUNREACH: {
        // No route to host

        return btlso::SocketHandle::e_ERROR_CONNDEAD;                 // RETURN
      }
#endif

#ifdef ENETDOWN
      case ENETDOWN: {
        // Network is down

        return btlso::SocketHandle::e_ERROR_CONNDEAD;                 // RETURN
      }
#endif

#ifdef ENETRESET
      case ENETRESET: {
        // Network dropped connection because

        return btlso::SocketHandle::e_ERROR_CONNDEAD;                 // RETURN
      }
#endif

#ifdef ENOBUFS
      case ENOBUFS: {
        // No buffer space available

        return btlso::SocketHandle::e_ERROR_UNCLASSIFIED;             // RETURN
      }
#endif

#ifdef ENOPROTOOPT
      case ENOPROTOOPT: {
        // Protocol not available

        return  btlso::SocketHandle::e_ERROR_UNCLASSIFIED;            // RETURN
      }
#endif

#ifdef ENOTCONN
      case ENOTCONN: {
        // Socket is not connected

        return btlso::SocketHandle::e_ERROR_CONNDEAD;                 // RETURN
      }
#endif

#ifdef EPFNOSUPPORT
      case EPFNOSUPPORT: {
        // Protocol family not supported

        return btlso::SocketHandle::e_ERROR_UNCLASSIFIED;             // RETURN
      }
#endif

#ifdef EPROTOTYPE
      case EPROTOTYPE: {
        // Protocol wrong type for socket

        return btlso::SocketHandle::e_ERROR_UNCLASSIFIED;             // RETURN
      }
#endif

#ifdef ESHUTDOWN
      case ESHUTDOWN: {
        // Cant send after socket shutdown

        return btlso::SocketHandle::e_ERROR_UNCLASSIFIED;             // RETURN
      }
#endif

#ifdef ESOCKTNOSUPPORT
      case ESOCKTNOSUPPORT: {
        // Socket type not supported

        return btlso::SocketHandle::e_ERROR_UNCLASSIFIED;             // RETURN
      }
#endif

#ifdef ETOOMANYREFS
      case ETOOMANYREFS: {
        // Too many references: cant splice

        return btlso::SocketHandle::e_ERROR_UNCLASSIFIED;             // RETURN
      }
#endif

#ifdef ESTALE
      case ESTALE: {
        // A stale NFS file handle exists.

        return btlso::SocketHandle::e_ERROR_NORESOURCES;              // RETURN
      }
#endif

#endif

      case 0: {
        return 0;                                                     // RETURN
      }

      default: {
        return btlso::SocketHandle::e_ERROR_UNCLASSIFIED;             // RETURN
      }
    }

    BSLS_ASSERT_OPT("Unreachable" && 0);

    return 0;
}