/**
 * Tests that we are recieveing messages in first-in-first-out, even if there's an error while reading once.
 * @return [description]
 */
int fifo_even_if_errors() {
    pid_t parent = getpid(), child = fork();

    if (child) {
        // in parent
        usleep(50000);

        pid_t sender;
        int msg, len, i, error;
        error = RcvMsg(NULL, NULL, NULL, BLOCK);
        expect_true(error == MSG_ARG_ERROR);

        for (i = 0; i < 32; i++) {
            error = RcvMsg(&sender,&msg,&len,BLOCK);
            expect_true(error == 0);
            expect_true(len == sizeof(int));
            //printf("expected %d, got %d\n", i, msg);
            expect_true(msg == i);
        }
    } else {
        // in child
        int i;
        for (i = 0; i < 32; i++) {
            SendMsg(parent, &i, sizeof(int), NO_BLOCK);
        }
        exit(0);
    }
}
void
exit_handler_intel_x64::unittest_1008_containers_priority_queue() const
{
    int myints[] = {0, 1, 2, 3};

    auto myqueue = std::priority_queue<int>(myints, myints + 4);
    auto myqueue2 = std::priority_queue<int>(myints, myints + 4);

    expect_true(myqueue.size() == 4);
    expect_false(myqueue.empty());

    expect_true(myqueue.top() == 3);

    myqueue.emplace();
    myqueue.push(1);
    myqueue.push(2);
    myqueue.push(3);

    myqueue.pop();
    myqueue.pop();
    myqueue.pop();
    myqueue.pop();

    myqueue.swap(myqueue2);
    std::swap(myqueue, myqueue2);
}
void
exit_handler_intel_x64::unittest_1006_containers_stack() const
{
    std::stack<int> mystack{{0, 1, 2, 3}};
    std::stack<int> mystack2{{0, 1, 2, 3}};

    expect_true(mystack.size() == 4);
    expect_false(mystack.empty());

    expect_true(mystack.top() == 3);

    mystack.push(4);
    mystack.pop();

    mystack.emplace();
    mystack.pop();

    mystack.swap(mystack2);
    std::swap(mystack, mystack2);

    expect_true(mystack == mystack2);
    expect_false(mystack != mystack2);
    expect_false(mystack < mystack2);
    expect_false(mystack > mystack2);
    expect_true(mystack <= mystack2);
    expect_true(mystack >= mystack2);
}
Пример #4
0
static void
epoll_modify (EV_P_ int fd, int oev, int nev)
{
  struct epoll_event ev;
  unsigned char oldmask;

  /*
   * we handle EPOLL_CTL_DEL by ignoring it here
   * on the assumption that the fd is gone anyways
   * if that is wrong, we have to handle the spurious
   * event in epoll_poll.
   * if the fd is added again, we try to ADD it, and, if that
   * fails, we assume it still has the same eventmask.
   */
  if (!nev)
    return;

  oldmask = anfds [fd].emask;
  anfds [fd].emask = nev;

  /* store the generation counter in the upper 32 bits, the fd in the lower 32 bits */
  ev.data.u64 = (uint64_t)(uint32_t)fd
              | ((uint64_t)(uint32_t)++anfds [fd].egen << 32);
  ev.events   = (nev & EV_READ  ? EPOLLIN  : 0)
              | (nev & EV_WRITE ? EPOLLOUT : 0);

  if (expect_true (!epoll_ctl (backend_fd, oev && oldmask != nev ? EPOLL_CTL_MOD : EPOLL_CTL_ADD, fd, &ev)))
    return;

  if (expect_true (errno == ENOENT))
    {
      /* if ENOENT then the fd went away, so try to do the right thing */
      if (!nev)
        goto dec_egen;

      if (!epoll_ctl (backend_fd, EPOLL_CTL_ADD, fd, &ev))
        return;
    }
  else if (expect_true (errno == EEXIST))
    {
      /* EEXIST means we ignored a previous DEL, but the fd is still active */
      /* if the kernel mask is the same as the new mask, we assume it hasn't changed */
      if (oldmask == nev)
        goto dec_egen;

      if (!epoll_ctl (backend_fd, EPOLL_CTL_MOD, fd, &ev))
        return;
    }
  else if (expect_true (errno == EPERM))
    {
      /* EPERM means the fd is always ready, but epoll is too snobbish */
      /* to handle it, unlike select or poll. */
      anfds [fd].emask = EV_EMASK_EPERM;

      /* add fd to epoll_eperms, if not already inside */
      if (!(oldmask & EV_EMASK_EPERM))
        {
          array_needsize (int, epoll_eperms, epoll_epermmax, epoll_epermcnt + 1, EMPTY2);
          epoll_eperms [epoll_epermcnt++] = fd;
        }
void
exit_handler_intel_x64::unittest_1009_containers_set() const
{
    auto myset = std::set<int>({0, 1, 2, 3});
    auto myset2 = std::set<int>({0, 1, 2, 3});

    auto total = 0;
    for (auto iter = myset.begin(); iter != myset.end(); iter++)
        total += *iter;

    auto rtotal = 0;
    for (auto iter = myset.rbegin(); iter != myset.rend(); iter++)
        rtotal += *iter;

    auto ctotal = 0;
    for (auto iter = myset.cbegin(); iter != myset.cend(); iter++)
        ctotal += *iter;

    auto crtotal = 0;
    for (auto iter = myset.crbegin(); iter != myset.crend(); iter++)
        crtotal += *iter;

    expect_true(total == 6);
    expect_true(rtotal == 6);
    expect_true(ctotal == 6);
    expect_true(crtotal == 6);

    expect_true(myset.size() == 4);
    expect_true(myset.max_size() >= 4);
    expect_false(myset.empty());

    myset.insert(myset.begin(), 0);
    myset.erase(myset.begin());
    myset = myset2;

    myset.swap(myset2);
    myset.swap(myset2);

    myset.emplace();
    myset.emplace_hint(myset.begin());
    myset = myset2;

    myset.key_comp();
    myset.value_comp();

    expect_true(myset.find(0) != myset.end());
    expect_true(myset.count(0) == 1);
    expect_true(myset.lower_bound(0) != myset.end());
    expect_true(myset.upper_bound(0) != myset.end());
    myset.equal_range(0);

    myset.get_allocator();
    myset.clear();
}
int closing_thread_does_not_stop_or_destroy_mailbox() {
    pthread_t thread;
    int error, count;

    error = SendMsg(getpid(), "Hello", 6, NO_BLOCK);
    expect_true(error == 0);
    pthread_create(&thread, NULL, useless_thread, NULL);
    pthread_join(thread, NULL);

    ManageMailbox(false, &count);
    expect_true(count == 1);

    return true;
}
Пример #7
0
SRL_STATIC_INLINE void
srl_fill_header(pTHX_ srl_merger_t *mrg, const char *user_header, STRLEN user_header_len)
{
    /* 4 byte magic string + proto version
     * + potentially uncompressed size varint
     * +  1 byte varint that indicates zero-length header */
    GROW_BUF(&mrg->obuf, 128);

    if (expect_true(mrg->protocol_version > 2)) {
        srl_buf_cat_str_s_nocheck(&mrg->obuf, SRL_MAGIC_STRING_HIGHBIT);
    } else {
        srl_buf_cat_str_s_nocheck(&mrg->obuf, SRL_MAGIC_STRING);
    }

    srl_buf_cat_char_nocheck(&mrg->obuf, (U8) mrg->protocol_version);

    if (user_header == NULL) {
        srl_buf_cat_char_nocheck(&mrg->obuf, '\0');
    } else {
        if (expect_false(mrg->protocol_version < 2))
            croak("Cannot serialize user header data in Sereal protocol V1 mode!"); // TODO

        srl_buf_cat_varint_nocheck(aTHX_ &mrg->obuf, 0, (UV) (user_header_len + 1)); /* Encode header length, +1 for bit field */
        srl_buf_cat_char_nocheck(&mrg->obuf, '\1');                                  /* Encode bitfield */
        Copy(user_header, mrg->obuf.pos, user_header_len, char);                     /* Copy user header data */
        mrg->obuf.pos += user_header_len;
    }

    SRL_UPDATE_BODY_POS(&mrg->obuf, mrg->protocol_version);
}
Пример #8
0
/* 发送数据
 * * 返回: < 0 错误,0 成功,1 需要重读,2 需要重写
 */
int32 ssl_io::send()
{
    assert( "io send fd invalid",_fd > 0 );

    if ( !_handshake ) return do_handshake();

    size_t bytes = _send->data_size();
    assert( "io send without data",bytes > 0 );
    int32 len = SSL_write( X_SSL( _ssl_ctx ),_send->data_pointer(),bytes );
    if ( expect_true(len > 0) )
    {
        _send->subtract( len );
        return ((size_t)len) == bytes ? 0 : 2;
    }

    int32 ecode = SSL_get_error( X_SSL( _ssl_ctx ),len );
    if ( SSL_ERROR_WANT_WRITE == ecode ) return 2;

    // 非主动断开,打印错误日志
    if ( (SSL_ERROR_ZERO_RETURN == ecode)
        || (SSL_ERROR_SYSCALL == ecode && 0 == errno) )
    {
        return -1;
    }

    SSL_ERROR( "ssl io send" );
    return -1;
}
Пример #9
0
/*
 * connect回调
 * man connect
 * It is possible to select(2) or poll(2) for completion by selecting the socket
 * for writing.  After select(2) indicates  writability,  use getsockopt(2)  to
 * read the SO_ERROR option at level SOL_SOCKET to determine whether connect()
 * completed successfully (SO_ERROR is zero) or unsuccessfully (SO_ERROR is one
 * of  the  usual  error  codes  listed  here,explaining the reason for the failure)
 * 1)连接成功建立时,socket 描述字变为可写。(连接建立时,写缓冲区空闲,所以可写)
 * 2)连接建立失败时,socket 描述字既可读又可写。 (由于有未决的错误,从而可读又可写)
 */
void socket::connect_cb ()
{
    int32 ecode = socket::validate();

    if ( 0 == ecode )
    {
        KEEP_ALIVE( socket::fd() );
        USER_TIMEOUT( socket::fd() );

        socket::start();
    }

    /* 连接失败或回调脚本失败,都会被connect_new删除 */
    static class lnetwork_mgr *network_mgr = lnetwork_mgr::instance();
    bool is_ok = network_mgr->connect_new( _conn_id,ecode );

    if ( expect_true( is_ok && 0 == ecode ) )
    {
        init_connect();
    }
    else
    {
        socket::stop ();
    }
}
Пример #10
0
void
srl_iterator_next_until_depth_and_idx(pTHX_ srl_iterator_t *iter, UV expected_depth, U32 expected_idx) {
    U32 current_idx;
    srl_stack_t *stack = iter->stack;
    IV current_depth = SRL_STACK_DEPTH(stack);

    DEBUG_ASSERT_RDR_SANE(iter->pbuf);
    SRL_ITER_TRACE("expected_depth=%"UVuf" expected_idx=%u",
                   expected_depth, expected_idx);

    SRL_ITER_ASSERT_STACK(iter);
    if (expect_false((IV) expected_depth > current_depth)) {
        SRL_ITER_ERRORf2("srl_iterator_next_until_depth() can only go forward, "
                         "so expected_depth=%"UVuf" should not be greater then current_depth=%"IVdf,
                         expected_depth, current_depth);
    }

    current_idx = stack->ptr->idx;
    if (expect_false((IV) expected_depth == current_depth && expected_idx == current_idx))
        return;

    while (expect_true(!srl_stack_empty(stack))) {
        srl_iterator_wrap_stack(aTHX_ iter, expected_depth);

        current_depth = SRL_STACK_DEPTH(stack);
        if (expect_false(srl_stack_empty(stack)))
            break;

        current_idx  = stack->ptr->idx;
        if (current_depth == (IV) expected_depth && current_idx == expected_idx)
            break;

        if (expect_false(current_depth == (IV) expected_depth && expected_idx > current_idx)) {
            SRL_ITER_ERRORf2("srl_iterator_next_until_depth() can only go forward, "
                             "so expected_idx=%d should not be greater then current_idx=%d",
                             expected_idx, current_idx);
        }

        srl_iterator_step_internal(aTHX_ iter);
    }

    if (expect_false(current_depth != (IV) expected_depth)) {
        SRL_ITER_ERRORf2("func led to wrong stack depth, expected=%"IVdf", actual=%"IVdf,
                          expected_depth, current_depth);
    }

    if (expect_false(current_idx != expected_idx)) {
        SRL_ITER_ERRORf2("func led to wrong stack index, expected=%u, actual=%u",
                          expected_idx, current_idx);
    }

    SRL_ITER_TRACE("Reached expected stack depth: %"UVuf " and idx: %u",
                   expected_depth, expected_idx);
    DEBUG_ASSERT_RDR_SANE(iter->pbuf);
}
void
exit_handler_intel_x64::unittest_1007_containers_queue() const
{
    std::queue<int> myqueue{{0, 1, 2, 3}};
    std::queue<int> myqueue2{{0, 1, 2, 3}};

    expect_true(myqueue.size() == 4);
    expect_false(myqueue.empty());

    expect_true(myqueue.front() == 0);
    expect_true(myqueue.back() == 3);

    myqueue.emplace();
    myqueue.push(1);
    myqueue.push(2);
    myqueue.push(3);

    myqueue.pop();
    myqueue.pop();
    myqueue.pop();
    myqueue.pop();

    myqueue.swap(myqueue2);
    std::swap(myqueue, myqueue2);

    expect_true(myqueue == myqueue2);
    expect_false(myqueue != myqueue2);
    expect_false(myqueue < myqueue2);
    expect_false(myqueue > myqueue2);
    expect_true(myqueue <= myqueue2);
    expect_true(myqueue >= myqueue2);
}
int msg_arg_error_invoke() {
    int error1 = ManageMailbox(false, NULL); // can't write to NULL, fail
    expect_true(error1 == MSG_ARG_ERROR);

    int error1_5 = ManageMailbox(true, NULL); // can't write to NULL, fail. Malformed command does not stop mailbox
    expect_true(error1_5 == MSG_ARG_ERROR);

    int error2 = SendMsg(getpid(),NULL, 6, NO_BLOCK); //can't read 6 from null, fail
    expect_true(error2 == MSG_ARG_ERROR);

    int error3 = SendMsg(getpid(),NULL,0,NO_BLOCK); // can read 0 from null, pass
    expect_true(error3 == 0);

    int error4 = RcvMsg(NULL, NULL, NULL, NO_BLOCK);    // can't send null to null, fail
    expect_true(error4 == MSG_ARG_ERROR);

    pid_t sender;
    char msg[MAX_MSG_SIZE];
    int len;
    int error5 = RcvMsg(NULL, msg, &len, NO_BLOCK); // can't read to null, fail
    expect_true(error5 == MSG_ARG_ERROR);

    int error6 = RcvMsg(&sender, msg, NULL, NO_BLOCK);  // can't read to null, fail
    expect_true(error6 == MSG_ARG_ERROR);

    int error7 = RcvMsg(&sender, msg, &len, NO_BLOCK);  // can read to all, pass
    expect_true(error7 == 0);
    expect_true(len == 0);

    int len2;
    SendMsg(getpid(),"Hello",6,NO_BLOCK);
    int error8 = RcvMsg(&sender, NULL, &len2, NO_BLOCK);    // can't read to null, len isn't 0, fail
    expect_true(error8 == MSG_ARG_ERROR);

    return true;
}
Пример #13
0
			/**
			 * input method
			 *
			 * @return bool if alignment input was successfull and a new alignment was stored
			 **/
			virtual bool readAlignmentInternal(bool const delayPutRank = false)
			{
				while ( true )
				{
					if ( expect_false(! decoder) )
					{
						if ( static_cast<uint64_t>(++fileid) == infos.size() )
						{
							return false;
						}
						else
						{
							if ( Pwrappers.get() )
							{
								decoder = &((*Pwrappers)[fileid]->getDecoder());
							}
							else
							{
								libmaus::bambam::BamAlignmentDecoderWrapper::unique_ptr_type tptr ( libmaus::bambam::BamAlignmentDecoderFactory::construct(infos[fileid]) );
								wrapper = UNIQUE_PTR_MOVE(tptr);
								decoder = &(wrapper->getDecoder());
							}
							algnptr = &(decoder->getAlignment());
						}
					}
					
					bool const ok = decoder->readAlignment();
					
					if ( expect_true(ok) )
					{
						alignment.swap(*algnptr);

						if ( ! delayPutRank )
							putRank();
							
						header.updateAlignment(fileid,alignment);
						return true;
					}
					else
					{
						wrapper.reset();
						decoder = 0;
						algnptr = 0;
					}
				}
			}
int recieve_messages_even_after_stopped() {
    pid_t me = getpid(), you;
    int i = 15, j, k, len, error;

    error = SendMsg(me, &i, sizeof(int), NO_BLOCK);
    expect_true(error == 0);

    error = ManageMailbox(true, &j);
    expect_true(error == 0);
    expect_true(j == 1);

    error = RcvMsg(&you, &k, &len, NO_BLOCK);
    expect_true(error == 0);
    expect_true(k == i);
    expect_true(len == sizeof(int));
    expect_true(me == you);

    error = RcvMsg(&you, &k, &len, NO_BLOCK);
    expect_true(error == MAILBOX_STOPPED);

    return true;
}
Пример #15
0
static gboolean
_compare_key_value(KVScanner *scanner, const gchar *key, const gchar *value, gboolean *expect_more)
{
  g_assert(value);

  gboolean ok = kv_scanner_scan_next(scanner);
  if (ok)
    {
      _assert_current_key_is(scanner, key);
      _assert_current_value_is(scanner, value);
      return TRUE;
    }
  else
    {
      *expect_more = FALSE;
      expect_true(ok, "kv_scanner is expected to return TRUE for scan_next(), "
                  "first unconsumed pair: [%s/%s]",
                  key, value);
      return FALSE;
    }
}
Пример #16
0
/* 接收数据
 * * 返回: < 0 错误,0 成功,1 需要重读,2 需要重写
 */
int32 ssl_io::recv()
{
    assert( "io recv fd invalid",_fd > 0 );

    if ( !_handshake ) return do_handshake();

    if ( !_recv->reserved() ) return -1; /* no more memory */

    // ERR_clear_error
    uint32 size = _recv->buff_size();
    int32 len = SSL_read( X_SSL( _ssl_ctx ),_recv->buff_pointer(),size );
    if ( expect_true(len > 0) )
    {
        _recv->increase( len );
        return 0;
    }

    int32 ecode = SSL_get_error( X_SSL( _ssl_ctx ),len );
    if ( SSL_ERROR_WANT_READ == ecode ) return 1;

    /* https://www.openssl.org/docs/manmaster/man3/SSL_read.html
     * SSL连接关闭时,要先关闭SSL协议,再关闭socket。当一个连接直接关闭时,SSL并不能明确
     * 区分开来。SSL_ERROR_ZERO_RETURN仅仅是表示SSL协议层关闭,连接并没有关闭(你可以把一
     * 个SSL连接转化为一个非SSL连接,参考SSL_shutdown)。正常关闭下,SSL_read先收到一个
     * SSL_ERROR_ZERO_RETURN转换为普通连接,然后read再收到一个0。如果直接关闭,则SSL返回
     * 0,SSL_get_error检测到syscall错误(即read返回0),这时errno为0,SSL_get_error并返
     * 回0。
     */

    // 非主动断开,打印错误日志
    // 在实际测试中,chrome会直接断开链接,而firefox则会关闭SSL */
    if ( (SSL_ERROR_ZERO_RETURN == ecode)
        || (SSL_ERROR_SYSCALL == ecode && 0 == errno) )
    {
        return -1;
    }

    SSL_ERROR( "ssl io recv" );
    return -1;
}
Пример #17
0
void socket::listen_cb()
{
    static class lnetwork_mgr *network_mgr = lnetwork_mgr::instance();
    while ( socket::active() )
    {
        int32 new_fd = ::accept(_w.fd,NULL,NULL);
        if ( new_fd < 0 )
        {
            if ( EAGAIN != errno && EWOULDBLOCK != errno )
            {
                ERROR( "socket::accept:%s\n",strerror(errno) );
                return;
            }

            break;  /* 所有等待的连接已处理完 */
        }

        socket::non_block( new_fd );
        KEEP_ALIVE( new_fd );
        USER_TIMEOUT( new_fd );

        uint32 conn_id = network_mgr->new_connect_id();
        class socket *new_sk = new class socket( conn_id,_conn_ty );
        new_sk->start( new_fd );

        // 初始完socket后才触发脚本,因为脚本那边中能要对socket进行处理了
        bool is_ok = network_mgr->accept_new( _conn_id,new_sk );
        if ( expect_true( is_ok ) )
        {
            new_sk->init_accept();
        }
        else
        {
            new_sk->stop();
        }
    }
}
Пример #18
0
void
srl_iterator_step_in(pTHX_ srl_iterator_t *iter, UV n)
{
    srl_stack_t *stack = iter->stack;

    DEBUG_ASSERT_RDR_SANE(iter->pbuf);
    SRL_ITER_TRACE("n=%"UVuf, n);

    SRL_ITER_ASSERT_STACK(iter);
    if (expect_false(n == 0)) return;

    while (expect_true(!srl_stack_empty(stack))) {
        if (n == 0) break;
        srl_iterator_step_internal(aTHX_ iter);
        n--;
    }

    if (expect_false(n != 0)) {
        SRL_ITER_ERRORf1("Failed to do %"UVuf" steps. Likely EOF was reached", n);
    }

    SRL_ITER_TRACE("Did expected number of steps");
    DEBUG_ASSERT_RDR_SANE(iter->pbuf);
}
Пример #19
0
static void
poll_modify (EV_P_ int fd, int oev, int nev)
{
  int idx;

  if (oev == nev)
    return;

  array_needsize (int, pollidxs, pollidxmax, fd + 1, pollidx_init);

  idx = pollidxs [fd];

  if (idx < 0) /* need to allocate a new pollfd */
    {
      pollidxs [fd] = idx = pollcnt++;
      array_needsize (struct pollfd, polls, pollmax, pollcnt, EMPTY2);
      polls [idx].fd = fd;
    }

  assert (polls [idx].fd == fd);

  if (nev)
    polls [idx].events =
        (nev & EV_READ ? POLLIN : 0)
        | (nev & EV_WRITE ? POLLOUT : 0);
  else /* remove pollfd */
    {
      pollidxs [fd] = -1;

      if (expect_true (idx < --pollcnt))
        {
          polls [idx] = polls [pollcnt];
          pollidxs [polls [idx].fd] = idx;
        }
    }
}
Пример #20
0
void
srl_iterator_next(pTHX_ srl_iterator_t *iter, UV n)
{
    srl_stack_t *stack = iter->stack;
    IV expected_depth = SRL_STACK_DEPTH(stack);

    DEBUG_ASSERT_RDR_SANE(iter->pbuf);
    SRL_ITER_TRACE("n=%"UVuf, n);

    SRL_ITER_ASSERT_STACK(iter);
    if (expect_false(n == 0)) return;
    if (expect_false(stack->ptr->idx == 0))
        SRL_ITER_ERROR("Nothing to parse at this depth");

    while (expect_true(!srl_stack_empty(stack))) {
        if (SRL_STACK_DEPTH(stack) == expected_depth) {
            if (n == 0) break;
            else n--;
        }

        srl_iterator_step_internal(aTHX_ iter);
        srl_iterator_wrap_stack(aTHX_ iter, expected_depth);
    }

    if (expect_false(n != 0)) {
        SRL_ITER_ERRORf1("Failed to do %"UVuf" next steps. Likely EOF was reached", n);
    }

    if (expect_false(SRL_STACK_DEPTH(stack) != expected_depth)) {
        SRL_ITER_ERRORf2("next() led to wrong stack depth, expected=%"IVdf", actual=%"IVdf,
                          expected_depth, SRL_STACK_DEPTH(stack));
    }

    SRL_ITER_TRACE("Did expected number of steps at depth %"IVdf, expected_depth);
    DEBUG_ASSERT_RDR_SANE(iter->pbuf);
}
Пример #21
0
Файл: lzf_c.c Проект: Abioy/ardb
unsigned int
lzf_compress (const void * in_data, unsigned int in_len,
	      void *out_data, unsigned int out_len
#if LZF_STATE_ARG
              , LZF_STATE htab
#endif
              )
{
#if !LZF_STATE_ARG
  LZF_STATE htab;
#endif
  const u8 **hslot;
  const u8 *ip = (const u8 *)in_data;
        u8 *op = (u8 *)out_data;
  const u8 *in_end  = ip + in_len;
        u8 *out_end = op + out_len;
  const u8 *ref;

  /* off requires a type wide enough to hold a general pointer difference.
   * ISO C doesn't have that (size_t might not be enough and ptrdiff_t only
   * works for differences within a single object). We also assume that no
   * no bit pattern traps. Since the only platform that is both non-POSIX
   * and fails to support both assumptions is windows 64 bit, we make a
   * special workaround for it.
   */
#if defined (WIN32) && defined (_M_X64)
  unsigned _int64 off; /* workaround for missing POSIX compliance */
#else
  unsigned long off;
#endif
  unsigned int hval;
  int lit;

  if (!in_len || !out_len)
    return 0;

#if INIT_HTAB
  memset (htab, 0, sizeof (htab));
# if 0
  for (hslot = htab; hslot < htab + HSIZE; hslot++)
    *hslot++ = ip;
# endif
#endif

  lit = 0; op++; /* start run */

  hval = FRST (ip);
  while (ip < in_end - 2)
    {
      hval = NEXT (hval, ip);
      hslot = htab + IDX (hval);
      ref = *hslot; *hslot = ip;

      if (1
#if INIT_HTAB
          && ref < ip /* the next test will actually take care of this, but this is faster */
#endif
          && (off = ip - ref - 1) < MAX_OFF
          && ip + 4 < in_end
          && ref > (u8 *)in_data
#if STRICT_ALIGN
          && ref[0] == ip[0]
          && ref[1] == ip[1]
          && ref[2] == ip[2]
#else
          && *(u16 *)ref == *(u16 *)ip
          && ref[2] == ip[2]
#endif
        )
        {
          /* match found at *ref++ */
          unsigned int len = 2;
          unsigned int maxlen = in_end - ip - len;
          maxlen = maxlen > MAX_REF ? MAX_REF : maxlen;

          op [- lit - 1] = lit - 1; /* stop run */
          op -= !lit; /* undo run if length is zero */

          if (expect_false (op + 3 + 1 >= out_end))
            return 0;

          for (;;)
            {
              if (expect_true (maxlen > 16))
                {
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;

                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;

                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;

                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                }

              do
                len++;
              while (len < maxlen && ref[len] == ip[len]);

              break;
            }

          len -= 2; /* len is now #octets - 1 */
          ip++;

          if (len < 7)
            {
              *op++ = (off >> 8) + (len << 5);
            }
          else
            {
Пример #22
0
static void
select_poll (EV_P_ ev_tstamp timeout)
{
  struct timeval tv;
  int res;
  int fd_setsize;

  EV_RELEASE_CB;
  EV_TV_SET (tv, timeout);

#if EV_SELECT_USE_FD_SET
  fd_setsize = sizeof (fd_set);
#else
  fd_setsize = vec_max * NFDBYTES;
#endif

  memcpy (vec_ro, vec_ri, fd_setsize);
  memcpy (vec_wo, vec_wi, fd_setsize);

#ifdef _WIN32
  /* pass in the write set as except set.
   * the idea behind this is to work around a windows bug that causes
   * errors to be reported as an exception and not by setting
   * the writable bit. this is so uncontrollably lame.
   */
  memcpy (vec_eo, vec_wi, fd_setsize);
  res = select (vec_max * NFDBITS, (fd_set *)vec_ro, (fd_set *)vec_wo, (fd_set *)vec_eo, &tv);
#elif EV_SELECT_USE_FD_SET
  fd_setsize = anfdmax < FD_SETSIZE ? anfdmax : FD_SETSIZE;
  res = select (fd_setsize, (fd_set *)vec_ro, (fd_set *)vec_wo, 0, &tv);
#else
  res = select (vec_max * NFDBITS, (fd_set *)vec_ro, (fd_set *)vec_wo, 0, &tv);
#endif
  EV_ACQUIRE_CB;

  if (expect_false (res < 0))
    {
      #if EV_SELECT_IS_WINSOCKET
      errno = WSAGetLastError ();
      #endif
      #ifdef WSABASEERR
      /* on windows, select returns incompatible error codes, fix this */
      if (errno >= WSABASEERR && errno < WSABASEERR + 1000)
        if (errno == WSAENOTSOCK)
          errno = EBADF;
        else
          errno -= WSABASEERR;
      #endif

      #ifdef _WIN32
      /* select on windows erroneously returns EINVAL when no fd sets have been
       * provided (this is documented). what microsoft doesn't tell you that this bug
       * exists even when the fd sets _are_ provided, so we have to check for this bug
       * here and emulate by sleeping manually.
       * we also get EINVAL when the timeout is invalid, but we ignore this case here
       * and assume that EINVAL always means: you have to wait manually.
       */
      if (errno == EINVAL)
        {
          if (timeout)
            {
              unsigned long ms = timeout * 1e3;
              Sleep (ms ? ms : 1);
            }

          return;
        }
      #endif

      if (errno == EBADF)
        fd_ebadf (EV_A);
      else if (errno == ENOMEM && !syserr_cb)
        fd_enomem (EV_A);
      else if (errno != EINTR)
        ev_syserr ("(libev) select");

      return;
    }

#if EV_SELECT_USE_FD_SET

  {
    int fd;

    for (fd = 0; fd < anfdmax; ++fd)
      if (anfds [fd].events)
        {
          int events = 0;
          #if EV_SELECT_IS_WINSOCKET
          SOCKET handle = anfds [fd].handle;
          #else
          int handle = fd;
          #endif

          if (FD_ISSET (handle, (fd_set *)vec_ro)) events |= EV_READ;
          if (FD_ISSET (handle, (fd_set *)vec_wo)) events |= EV_WRITE;
          #ifdef _WIN32
          if (FD_ISSET (handle, (fd_set *)vec_eo)) events |= EV_WRITE;
          #endif

          if (expect_true (events))
            fd_event (EV_A_ fd, events);
        }
  }

#else

  {
    int word, bit;
    for (word = vec_max; word--; )
      {
        fd_mask word_r = ((fd_mask *)vec_ro) [word];
        fd_mask word_w = ((fd_mask *)vec_wo) [word];
        #ifdef _WIN32
        word_w |= ((fd_mask *)vec_eo) [word];
        #endif

        if (word_r || word_w)
          for (bit = NFDBITS; bit--; )
            {
              fd_mask mask = 1UL << bit;
              int events = 0;

              events |= word_r & mask ? EV_READ  : 0;
              events |= word_w & mask ? EV_WRITE : 0;

              if (expect_true (events))
                fd_event (EV_A_ word * NFDBITS + bit, events);
            }
      }
  }

#endif
}
void
exit_handler_intel_x64::unittest_1005_containers_list() const
{
    std::list<int> mylist = {{0, 1, 2, 3}};
    std::list<int> mylist2 = {{0, 1, 2, 3}};

    auto total = 0;
    for (auto iter = mylist.begin(); iter != mylist.end(); iter++)
        total += *iter;

    auto rtotal = 0;
    for (auto iter = mylist.rbegin(); iter != mylist.rend(); iter++)
        rtotal += *iter;

    auto ctotal = 0;
    for (auto iter = mylist.cbegin(); iter != mylist.cend(); iter++)
        ctotal += *iter;

    auto crtotal = 0;
    for (auto iter = mylist.crbegin(); iter != mylist.crend(); iter++)
        crtotal += *iter;

    expect_true(total == 6);
    expect_true(rtotal == 6);
    expect_true(ctotal == 6);
    expect_true(crtotal == 6);

    expect_true(mylist.size() == 4);
    expect_true(mylist.max_size() >= 4);
    expect_false(mylist.empty());
    mylist.resize(4);

    expect_true(mylist.front() == 0);
    expect_true(mylist.back() == 3);

    mylist.assign(4, 0);
    mylist = mylist2;

    mylist.push_back(4);
    mylist.pop_back();
    mylist = mylist2;

    mylist.push_front(4);
    mylist.pop_front();
    mylist = mylist2;

    mylist.insert(mylist.begin(), 0);
    mylist.erase(mylist.begin());
    mylist = mylist2;

    mylist.swap(mylist2);
    std::swap(mylist, mylist2);

    mylist.emplace(mylist.begin());
    mylist.emplace_back();
    mylist.emplace_front();
    mylist = mylist2;

    expect_true(mylist == mylist2);
    expect_false(mylist != mylist2);
    expect_false(mylist < mylist2);
    expect_false(mylist > mylist2);
    expect_true(mylist <= mylist2);
    expect_true(mylist >= mylist2);
    mylist = mylist2;

    mylist.splice(mylist.begin(), mylist2);
    mylist.remove(0);
    mylist.unique();
    mylist.merge(mylist2, std::greater<int>());
    mylist.sort(std::greater<int>());
    mylist.reverse();
    mylist = mylist2;

    mylist.get_allocator();
    mylist.clear();
}
void
exit_handler_intel_x64::unittest_1002_containers_vector() const
{
    auto myvector = std::vector<int>({0, 1, 2, 3});
    auto myvector2 = std::vector<int>({0, 1, 2, 3});

    auto total = 0;
    for (auto iter = myvector.begin(); iter != myvector.end(); iter++)
        total += *iter;

    auto rtotal = 0;
    for (auto iter = myvector.rbegin(); iter != myvector.rend(); iter++)
        rtotal += *iter;

    auto ctotal = 0;
    for (auto iter = myvector.cbegin(); iter != myvector.cend(); iter++)
        ctotal += *iter;

    auto crtotal = 0;
    for (auto iter = myvector.crbegin(); iter != myvector.crend(); iter++)
        crtotal += *iter;

    expect_true(total == 6);
    expect_true(rtotal == 6);
    expect_true(ctotal == 6);
    expect_true(crtotal == 6);

    expect_true(myvector.size() == 4);
    expect_true(myvector.max_size() >= 4);
    myvector.resize(4);
    expect_true(myvector.capacity() >= 4);
    expect_false(myvector.empty());
    myvector.reserve(4);
    myvector.shrink_to_fit();

    expect_true(myvector.at(0) == 0);
    expect_true(myvector.at(3) == 3);
    expect_true(myvector.front() == 0);
    expect_true(myvector.back() == 3);
    expect_true(myvector.data() != nullptr);

    myvector.assign(4, 0);
    myvector = myvector2;

    myvector.push_back(4);
    myvector.pop_back();
    myvector = myvector2;

    myvector.insert(myvector.begin(), 0);
    myvector.erase(myvector.begin());
    myvector = myvector2;

    myvector.swap(myvector2);
    std::swap(myvector, myvector2);

    myvector.emplace(myvector.begin());
    myvector.emplace_back();
    myvector = myvector2;

    expect_true(myvector == myvector2);
    expect_false(myvector != myvector2);
    expect_false(myvector < myvector2);
    expect_false(myvector > myvector2);
    expect_true(myvector <= myvector2);
    expect_true(myvector >= myvector2);
    myvector = myvector2;

    myvector.get_allocator();
    myvector.clear();
}
Пример #25
0
static void
select_poll (EV_P_ ev_tstamp timeout)
{
  struct timeval tv;
  int res;

#if EV_SELECT_USE_FD_SET
  memcpy (vec_ro, vec_ri, sizeof (fd_set));
  memcpy (vec_wo, vec_wi, sizeof (fd_set));
#else
  memcpy (vec_ro, vec_ri, vec_max * NFDBYTES);
  memcpy (vec_wo, vec_wi, vec_max * NFDBYTES);
#endif

  tv.tv_sec  = (long)timeout;
  tv.tv_usec = (long)((timeout - (ev_tstamp)tv.tv_sec) * 1e6);

  res = select (vec_max * NFDBITS, (fd_set *)vec_ro, (fd_set *)vec_wo, 0, &tv);

  if (expect_false (res < 0))
    {
      #if EV_SELECT_IS_WINSOCKET
      errno = WSAGetLastError ();
      #endif

      if (errno == EBADF)
        fd_ebadf (EV_A);
      else if (errno == ENOMEM && !syserr_cb)
        fd_enomem (EV_A);
      else if (errno != EINTR)
        syserr ("(libev) select");

      return;
    }

#if EV_SELECT_USE_FD_SET

  {
    int fd;

    for (fd = 0; fd < anfdmax; ++fd)
      if (anfds [fd].events)
        {
          int events = 0;
          #if EV_SELECT_IS_WINSOCKET
          SOCKET handle = anfds [fd].handle;
          #else
          int handle = fd;
          #endif

          if (FD_ISSET (handle, (fd_set *)vec_ro)) events |= EV_READ;
          if (FD_ISSET (handle, (fd_set *)vec_wo)) events |= EV_WRITE;

          if (expect_true (events))
            fd_event (EV_A_ fd, events);
        }
  }

#else

  {
    int word, bit;
    for (word = vec_max; word--; )
      {
        fd_mask word_r = ((fd_mask *)vec_ro) [word];
        fd_mask word_w = ((fd_mask *)vec_wo) [word];

        if (word_r || word_w)
          for (bit = NFDBITS; bit--; )
            {
              fd_mask mask = 1UL << bit;
              int events = 0;

              events |= word_r & mask ? EV_READ  : 0;
              events |= word_w & mask ? EV_WRITE : 0;

              if (expect_true (events))
                fd_event (EV_A_ word * NFDBITS + bit, events);
            }
      }
  }

#endif
}
Пример #26
0
/* This is the main routine to deserialize a structure.
 * It rolls up all the other "top level" routines into one
 */
SV *
srl_decode_into(pTHX_ srl_decoder_t *dec, SV *src, SV* into, UV start_offset)
{
    assert(dec != NULL);
    if (SvUTF8(src))
        sv_utf8_downgrade(src, 0);
    srl_begin_decoding(aTHX_ dec, src, start_offset);
    srl_read_header(aTHX_ dec);
    if (SRL_DEC_HAVE_OPTION(dec, SRL_F_DECODER_DECOMPRESS_SNAPPY)) {
        /* uncompress */
        uint32_t dest_len;
        SV *buf_sv;
        unsigned char *buf;
        unsigned char *old_pos;
        const ptrdiff_t sereal_header_len = dec->pos - dec->buf_start;
        const STRLEN compressed_packet_len =
                ( dec->proto_version_and_flags & SRL_PROTOCOL_ENCODING_MASK ) == SRL_PROTOCOL_ENCODING_SNAPPY_INCREMENTAL
                ? (STRLEN)srl_read_varint_uv_length(aTHX_ dec, " while reading compressed packet size")
                : (STRLEN)(dec->buf_end - dec->pos);
        int decompress_ok;
        int header_len;

        /* all decl's above here, or we break C89 compilers */

        dec->bytes_consumed= compressed_packet_len + (dec->pos - dec->buf_start);

        header_len = csnappy_get_uncompressed_length(
                            (char *)dec->pos,
                            compressed_packet_len,
                            &dest_len
                         );
        if (header_len == CSNAPPY_E_HEADER_BAD)
            SRL_ERROR("Invalid Snappy header in Snappy-compressed Sereal packet");

        /* Let perl clean this up. Yes, it's not the most efficient thing
         * ever, but it's just one mortal per full decompression, so not
         * a bottle-neck. */
        buf_sv = sv_2mortal( newSV(sereal_header_len + dest_len + 1 ));
        buf = (unsigned char *)SvPVX(buf_sv);

        /* FIXME probably unnecessary to copy the Sereal header! */
        Copy(dec->buf_start, buf, sereal_header_len, unsigned char);

        old_pos = dec->pos;
        dec->buf_start = buf;
        dec->pos = buf + sereal_header_len;
        dec->buf_end = dec->pos + dest_len;
        dec->buf_len = dest_len + sereal_header_len;

        decompress_ok = csnappy_decompress_noheader((char *)(old_pos + header_len),
                                                    compressed_packet_len - header_len,
                                                    (char *)dec->pos,
                                                    &dest_len);
        if (expect_false( decompress_ok != 0 ))
        {
            SRL_ERRORf1("Snappy decompression of Sereal packet payload failed with error %i!", decompress_ok);
        }
    }

    if (expect_true(!into)) {
        into= sv_2mortal(newSV_type(SVt_NULL));
    }
    srl_read_single_value(aTHX_ dec, into);
    /* assert(dec->pos == dec->buf_end); For now we disable this */
    if (expect_false(SRL_DEC_HAVE_OPTION(dec, SRL_F_DECODER_NEEDS_FINALIZE))) {
        srl_finalize_structure(aTHX_ dec);
    }

    /* If we aren't reading from a decompressed buffer we have to remember the number
     * of bytes used for the user to query. */
    if (dec->bytes_consumed == 0)
        dec->bytes_consumed = dec->pos - dec->buf_start;

    if (SRL_DEC_HAVE_OPTION(dec, SRL_F_DECODER_DESTRUCTIVE_INCREMENTAL)) {
        STRLEN len;
        char *pv= SvPV(src,len);
        /* check the length here? do something different if the string is now exhausted? */
        sv_chop(src, pv + dec->bytes_consumed);
    }

    srl_clear_decoder(aTHX_ dec);
    return into;
}
Пример #27
0
Файл: lzf_c.c Проект: malaise/c
unsigned int
lzf_compress (const void *const in_data, unsigned int in_len,
	      void *out_data, unsigned int out_len
#if LZF_STATE_ARG
              , LZF_STATE htab
#endif
              )
{
#if !LZF_STATE_ARG
  LZF_STATE htab;
#endif
  const u8 *ip = (const u8 *)in_data;
        u8 *op = (u8 *)out_data;
  const u8 *in_end  = ip + in_len;
        u8 *out_end = op + out_len;
  const u8 *ref;

  /* off requires a type wide enough to hold a general pointer difference.
   * ISO C doesn't have that (size_t might not be enough and ptrdiff_t only
   * works for differences within a single object). We also assume that no
   * no bit pattern traps. Since the only platform that is both non-POSIX
   * and fails to support both assumptions is windows 64 bit, we make a
   * special workaround for it.
   */
#if defined (WIN32) && defined (_M_X64)
  unsigned _int64 off; /* workaround for missing POSIX compliance */
#else
  unsigned long off;
#endif
  unsigned int hval;
  int lit;

  if (!in_len || !out_len)
    return 0;

#if INIT_HTAB
  memset (htab, 0, sizeof (htab));
#endif

  lit = 0; op++; /* start run */

  hval = FRST (ip);
  while (ip < in_end - 2)
    {
      LZF_HSLOT *hslot;

      hval = NEXT (hval, ip);
        LOG ("Index %02X future %08X hash %X\n",
             (int) (ip - (u8*)in_data), hval, IDX(hval));
      hslot = htab + IDX (hval);
      ref = *hslot + LZF_HSLOT_BIAS; *hslot = ip - LZF_HSLOT_BIAS;

      LOG ("Off read %02X\n", (int)(ref-(u8*)in_data));
      if ( (ref >= (u8*)in_data) && (ref < in_end) ) {
        LOG ("Bytes at ref %02X %02X %02X\n", (int)ref[0], (int)ref[1],
                                              (int)ref[2]);
        LOG ("Ip-Ref %02X\n", ip-ref);
      }
      LOG ("Bytes here   %02X %02X %02X\n", (int)ip[0], (int)ip[1], (int)ip[2]);

      if (1
#if INIT_HTAB
          && ref < ip /* the next test will actually take care of this, but this is faster */
#endif
          && (off = ip - ref - 1) < MAX_OFF
          && ref > (u8 *)in_data
          && ref[2] == ip[2]
#if STRICT_ALIGN
          && ((ref[1] << 8) | ref[0]) == ((ip[1] << 8) | ip[0])
#else
          && *(u16 *)ref == *(u16 *)ip
#endif
        )
        {
          /* match found at *ref++ */
          unsigned int len = 2;
          unsigned int maxlen = in_end - ip - len;
          maxlen = maxlen > MAX_REF ? MAX_REF : maxlen;
          LOG ("Match\n");

          if (expect_false (op + 3 + 1 >= out_end)) /* first a faster conservative test */
            if (op - !lit + 3 + 1 >= out_end) /* second the exact but rare test */
              return 0;

          op [- lit - 1] = lit - 1; /* stop run */
          op -= !lit; /* undo run if length is zero */

          for (;;)
            {
              if (expect_true (maxlen > 16))
                {
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;

                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;

                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;

                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                }

              do
                len++;
              while (len < maxlen && ref[len] == ip[len]);

              break;
            }

          len -= 2; /* len is now #octets - 1 */
          ip++;

          if (len < 7)
            {
              *op++ = (off >> 8) + (len << 5);
            }
          else
            {
void
exit_handler_intel_x64::unittest_1001_containers_array() const
{
    std::array<int, 4> myarray = {{0, 1, 2, 3}};
    std::array<int, 4> myarray2 = {{0, 1, 2, 3}};

    auto total = 0;
    for (auto iter = myarray.begin(); iter != myarray.end(); iter++)
        total += *iter;

    auto rtotal = 0;
    for (auto iter = myarray.rbegin(); iter != myarray.rend(); iter++)
        rtotal += *iter;

    auto ctotal = 0;
    for (auto iter = myarray.cbegin(); iter != myarray.cend(); iter++)
        ctotal += *iter;

    auto crtotal = 0;
    for (auto iter = myarray.crbegin(); iter != myarray.crend(); iter++)
        crtotal += *iter;

    expect_true(total == 6);
    expect_true(rtotal == 6);
    expect_true(ctotal == 6);
    expect_true(crtotal == 6);

    expect_true(myarray.size() == 4);
    expect_true(myarray.max_size() == 4);
    expect_false(myarray.empty());

    expect_true(myarray.at(0) == 0);
    expect_true(myarray.at(3) == 3);
    expect_true(myarray.front() == 0);
    expect_true(myarray.back() == 3);
    expect_true(myarray.data() != nullptr);

    myarray.fill(0);
    myarray.swap(myarray2);

    expect_true(std::get<0>(myarray) == 0);
    expect_true(std::get<3>(myarray) == 3);

    expect_false(myarray == myarray2);
    expect_true(myarray != myarray2);
    expect_false(myarray < myarray2);
    expect_true(myarray > myarray2);
    expect_false(myarray <= myarray2);
    expect_true(myarray >= myarray2);
}
Пример #29
0
static void
select_poll (EV_P_ ev_tstamp timeout)
{
  struct timeval tv;
  int res;

#if EV_SELECT_USE_FD_SET
  memcpy (vec_ro, vec_ri, sizeof (fd_set));
  memcpy (vec_wo, vec_wi, sizeof (fd_set));
#else
  memcpy (vec_ro, vec_ri, vec_max * NFDBYTES);
  memcpy (vec_wo, vec_wi, vec_max * NFDBYTES);
#endif

  tv.tv_sec  = (long)timeout;
  tv.tv_usec = (long)((timeout - (ev_tstamp)tv.tv_sec) * 1e6);

  res = select (vec_max * NFDBITS, (fd_set *)vec_ro, (fd_set *)vec_wo, 0, &tv);

  if (expect_false (res < 0))
    {
      #if EV_SELECT_IS_WINSOCKET
      errno = WSAGetLastError ();
      #endif
      #ifdef WSABASEERR
      /* on windows, select returns incompatible error codes, fix this */
      if (errno >= WSABASEERR && errno < WSABASEERR + 1000)
        if (errno == WSAENOTSOCK)
          errno = EBADF;
        else
          errno -= WSABASEERR;
      #endif

      #ifdef _WIN32
      /* select on windows errornously returns EINVAL when no fd sets have been
       * provided (this is documented). what microsoft doesn't tell you that this bug
       * exists even when the fd sets are provided, so we have to check for this bug
       * here and emulate by sleeping manually.
       * we also get EINVAL when the timeout is invalid, but we ignore this case here
       * and assume that EINVAL always means: you have to wait manually.
       */
      if (errno == EINVAL)
        {
          ev_sleep (timeout);
          return;
        }
      #endif

      if (errno == EBADF)
        fd_ebadf (EV_A);
      else if (errno == ENOMEM && !syserr_cb)
        fd_enomem (EV_A);
      else if (errno != EINTR)
        syserr ("(libev) select");

      return;
    }

#if EV_SELECT_USE_FD_SET

  {
    int fd;

    for (fd = 0; fd < anfdmax; ++fd)
      if (anfds [fd].events)
        {
          int events = 0;
          #if EV_SELECT_IS_WINSOCKET
          SOCKET handle = anfds [fd].handle;
          #else
          int handle = fd;
          #endif

          if (FD_ISSET (handle, (fd_set *)vec_ro)) events |= EV_READ;
          if (FD_ISSET (handle, (fd_set *)vec_wo)) events |= EV_WRITE;

          if (expect_true (events))
            fd_event (EV_A_ fd, events);
        }
  }

#else

  {
    int word, bit;
    for (word = vec_max; word--; )
      {
        fd_mask word_r = ((fd_mask *)vec_ro) [word];
        fd_mask word_w = ((fd_mask *)vec_wo) [word];

        if (word_r || word_w)
          for (bit = NFDBITS; bit--; )
            {
              fd_mask mask = 1UL << bit;
              int events = 0;

              events |= word_r & mask ? EV_READ  : 0;
              events |= word_w & mask ? EV_WRITE : 0;

              if (expect_true (events))
                fd_event (EV_A_ word * NFDBITS + bit, events);
            }
      }
  }

#endif
}
void
exit_handler_intel_x64::unittest_100A_containers_map() const
{
    auto mymap = std::map<int, int>();
    auto mymap2 = std::map<int, int>();

    mymap2[0] = 0;
    mymap2[1] = 1;
    mymap2[2] = 2;
    mymap2[3] = 3;

    mymap = mymap2;

    auto total = 0;
    for (auto iter = mymap.begin(); iter != mymap.end(); iter++)
        total += iter->second;

    auto rtotal = 0;
    for (auto iter = mymap.rbegin(); iter != mymap.rend(); iter++)
        rtotal += iter->second;

    auto ctotal = 0;
    for (auto iter = mymap.cbegin(); iter != mymap.cend(); iter++)
        ctotal += iter->second;

    auto crtotal = 0;
    for (auto iter = mymap.crbegin(); iter != mymap.crend(); iter++)
        crtotal += iter->second;

    expect_true(total == 6);
    expect_true(rtotal == 6);
    expect_true(ctotal == 6);
    expect_true(crtotal == 6);

    expect_true(mymap.size() == 4);
    expect_true(mymap.max_size() >= 4);
    expect_false(mymap.empty());

    expect_true(mymap.at(0) == 0);
    expect_true(mymap.at(3) == 3);

    mymap.insert(std::pair<int, int>(4, 4));
    mymap.erase(4);
    mymap = mymap2;

    mymap.swap(mymap2);
    mymap.swap(mymap2);

    mymap.emplace();
    mymap.emplace_hint(mymap.begin(), std::pair<int, int>(4, 4));
    mymap = mymap2;

    mymap.key_comp();
    mymap.value_comp();

    expect_true(mymap.find(0) != mymap.end());
    expect_true(mymap.count(0) == 1);
    expect_true(mymap.lower_bound(0) != mymap.end());
    expect_true(mymap.upper_bound(0) != mymap.end());
    mymap.equal_range(0);

    mymap.get_allocator();
    mymap.clear();
}