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);
}
示例#2
0
void socket::command_cb()
{
    static class lnetwork_mgr *network_mgr = lnetwork_mgr::instance();

    /* 在脚本报错的情况下,可能无法设置 io和packet */
    if ( !_io || !_packet )
    {
        socket::stop();
        network_mgr->connect_del( _conn_id );
        ERROR( "socket command no io or packet set,socket disconnect" );
        return;
    }

    // 返回:返回值: < 0 错误,0 成功,1 需要重读,2 需要重写
    int32 ret = socket::recv();
    if ( expect_false(0 != ret) ) return;  /* 出错,包括对方主动断开或者需要重试 */

    /* 在回调脚本时,可能被脚本关闭当前socket(fd < 0),这时就不要再处理数据了 */
    do
    {
        if ( (ret = _packet->unpack()) <= 0 ) return;
    }while ( fd() > 0 );

    // 解析过程中错误,断开链接
    if ( expect_false( ret < 0 ) )
    {
        socket::stop();
        network_mgr->connect_del( _conn_id );
        ERROR( "socket command unpack data fail" );
        return;
    }
}
示例#3
0
文件: ev_poll.c 项目: capotej/bloggy
static void
poll_poll (EV_P_ ev_tstamp timeout)
{
  struct pollfd *p;
  int res = poll (polls, pollcnt, (int)ceil (timeout * 1000.));

  if (expect_false (res < 0))
    {
      if (errno == EBADF)
        fd_ebadf (EV_A);
      else if (errno == ENOMEM && !syserr_cb)
        fd_enomem (EV_A);
      else if (errno != EINTR)
        syserr ("(libev) poll");
    }
  else
    for (p = polls; res; ++p)
      if (expect_false (p->revents)) /* this expect is debatable */
        {
          --res;

          if (expect_false (p->revents & POLLNVAL))
            fd_kill (EV_A_ p->fd);
          else
            fd_event (
              EV_A_
              p->fd,
              (p->revents & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0)
              | (p->revents & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0)
            );
        }
}
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);
}
示例#5
0
int main(int argc, char *argv[])
{
	if(argc < 4) {
		printf("need input\n");
		exit(1);
	}

	FILE *fr = fopen(argv[1], "r");
	FILE *fw = fopen(argv[2], "w");
	char *line = NULL;
	ssize_t read = 0;
	size_t len = 0;
	int hash = atoi(argv[3]);

	unsigned long user_id, pos_id = 0;
	double x = 0, y = 0;
	char time[32] = {0};
	char hash_id[64] = {0};

	array_needsize(false, POOL, id_pool, pool_num, 10240, array_zero_init);

	while((read = getline(&line, &len, fr)) != -1) {
		if(hash == 0) {
			sscanf(line, "%ld %s %lf %lf %ld", &user_id, time, &x, &y, &pos_id);
			if(expect_false(x == 0 || y == 0 || pos_id == 0))
				goto RESET;

			pos_id = id_get(pos_id);
		}
		else {
			sscanf(line, "%ld %s %lf %lf %s", &user_id, time, &x, &y, hash_id);
			if(expect_false(x == 0 || y == 0 || hash_id[0] == 0))
				goto RESET;

			pos_id = id_get(BKDRHash(hash_id));
		}
		
		fprintf(fw, "%ld,%lf,%lf,%s,%ld\r\n", user_id, x, y, time, pos_id);
RESET:
		x = 0;
		y = 0;
		time[0] = 0;
		hash_id[0] = 0;
		pos_id = 0;
	}

	fclose(fr);
	fclose(fw);
	free(id_pool);
	id_pool = NULL;

	return 0;
}
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);
}
示例#7
0
  bool 
  Reader::decodeString (Token &token, std::string &decoded)
  {
    Location current = token.start_ + 1; // skip '"'
    Location end = token.end_ - 1;       // do not include '"'
    decoded.reserve (long (end - current));

    while (current != end)
      {
	char c = *current++;
	if (expect_false (c == '"'))
	  break;
	else if (expect_false (c == '\\'))
	  {
	    if (expect_false (current == end))
	      return addError ("Empty escape sequence in string", token, current);
	    char escape = *current++;
	    switch (escape)
	      {
	      case '"':
	      case '/':
	      case '\\': decoded += escape; break;

	      case 'b': decoded += '\010'; break;
	      case 't': decoded += '\011'; break;
	      case 'n': decoded += '\012'; break;
	      case 'f': decoded += '\014'; break;
	      case 'r': decoded += '\015'; break;
	      case 'u':
		{
		  unsigned unicode;
		  if (!decodeUnicodeEscapeSequence (token, current, end, unicode))
		    return false;
		  // @todo encode unicode as utf8.
		  // @todo remember to alter the writer too.
		}
		break;
	      default:
		return addError ("Bad escape sequence in string", token, current);
	      }
	  }
	else
	  {
	    decoded += c;
	  }
      }

    return true;
  }
示例#8
0
void
srl_iterator_next_until_depth_and_idx(pTHX_ srl_iterator_t *iter, UV expected_depth, U32 expected_idx) {
    IV current_depth = iter->stack.depth;
    srl_iterator_stack_ptr stack_ptr = iter->stack.ptr;

    DEBUG_ASSERT_RDR_SANE(iter->pbuf);
    SRL_ITER_ASSERT_STACK(iter);

    SRL_ITER_TRACE("expected_depth=%"UVuf" expected_idx=%u", expected_depth, expected_idx);
    SRL_ITER_REPORT_STACK_STATE(iter);

    if (expect_false((IV) expected_depth == current_depth && (IV) expected_idx == stack_ptr->idx))
        return;

    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);
    }

    stack_ptr = iter->stack.begin + expected_depth;
    if (expect_false((IV) expected_idx > stack_ptr->idx)) {
        SRL_ITER_ERRORf3("srl_iterator_next_until_depth() can only go forward, "
                         "so expected_idx=%u should not be greater then current "
                         "index (%u) at expected_depth=%"IVdf,
                         expected_idx, stack_ptr->idx, expected_depth);
    }

    stack_ptr = iter->stack.ptr;

    while (1) {
        srl_iterator_wrap_stack(iter, expected_depth, stack_ptr);

        if (iter->stack.depth == (IV) expected_depth) {
            if (stack_ptr->idx == (IV) expected_idx)  break;
            assert(((IV) expected_idx > stack_ptr->idx) == 0);
        }

        srl_iterator_step_internal(iter, stack_ptr);
    }

    assert(stack_ptr->idx == (IV) expected_idx);
    assert(iter->stack.depth == (IV) expected_depth);
    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_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);
}
示例#10
0
void
srl_iterator_unite(pTHX_ srl_iterator_t *iter)
{
    UV offset;
    srl_stack_t *stack = iter->pstack;
    SRL_ITER_TRACE("--------------------------");

    if (expect_false(SRL_STACK_DEPTH(stack) <= 0))
        SRL_ITER_ERROR("There is nothing to unite. Please call disjoin first.");

    while (!SRL_ITER_STACK_ON_ROOT(stack)) {
        srl_stack_pop(stack);
    }

    offset = stack->ptr->offset;
    srl_stack_pop(stack); // remove SRL_ITER_STACK_ROOT_TAG

    SRL_ITER_ASSERT_STACK(iter);
    iter->buf.pos = iter->buf.body_pos + offset;

    SRL_ITER_REPORT_STACK_STATE(iter);
    SRL_ITER_TRACE("ofs %"UVuf" body_ofs %"UVuf,
                   (UV) SRL_RDR_POS_OFS((iter)->pbuf),
                   (UV) SRL_RDR_BODY_POS_OFS((iter)->pbuf));

    DEBUG_ASSERT_RDR_SANE(iter->pbuf);
}
示例#11
0
SRL_STATIC_INLINE srl_merger_t *
srl_empty_merger_struct(pTHX)
{
    srl_merger_t *mrg = NULL;
    Newx(mrg, 1, srl_merger_t);
    if (mrg == NULL)
        croak("Out of memory");

    /* Init buffer struct */
    if (expect_false(srl_buf_init_buffer(aTHX_ &mrg->obuf, INITIALIZATION_SIZE) != 0)) {
        Safefree(mrg);
        croak("Out of memory");
    }

    SRL_RDR_CLEAR(&mrg->ibuf);
    mrg->pibuf = &mrg->ibuf;

    mrg->recursion_depth = 0;
    mrg->max_recursion_depth = DEFAULT_MAX_RECUR_DEPTH;

    /* Zero fields */
    mrg->cnt_of_merged_elements = 0;
    mrg->obuf_padding_bytes_offset = 0;
    mrg->obuf_last_successfull_offset = 0;
    mrg->protocol_version = SRL_PROTOCOL_VERSION;
    mrg->classname_deduper_tbl = NULL;
    mrg->string_deduper_tbl = NULL;
    mrg->tracked_offsets_tbl = NULL;
    mrg->tracked_offsets = NULL;
    mrg->snappy_workmem = NULL;
    mrg->flags = 0;
    return mrg;
}
示例#12
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);
}
示例#13
0
void
srl_iterator_step_out(pTHX_ srl_iterator_t *iter, UV n)
{
    UV offset;
    srl_stack_t *stack = iter->stack;

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

    SRL_ITER_ASSERT_STACK(iter);
    // SRL_ITER_ASSERT_EOF(iter, "serialized object"); XXX need ability to go back on last element
    // if (expect_false(n == 0)) return; XXX keep it as a feature?

    while (n--) {
        srl_stack_pop_nocheck(stack);
        if (expect_false(srl_stack_empty(stack))) {
            SRL_ITER_ERROR("It was last object on stack, no more parents");
        }
    }

    offset = stack->ptr->offset; 
    iter->buf.pos = iter->buf.body_pos + offset;
    stack->ptr->idx = stack->ptr->count;

    DEBUG_ASSERT_RDR_SANE(iter->pbuf);
}
示例#14
0
SRL_STATIC_INLINE srl_stack_t *
srl_init_tracked_offsets(pTHX_ srl_merger_t *mrg)
{
    mrg->tracked_offsets = NULL;
    Newx(mrg->tracked_offsets, 1, srl_stack_t);

    if (expect_false(mrg->tracked_offsets == NULL))
        croak("Out of memory");

    if (expect_false(srl_stack_init(aTHX_ mrg->tracked_offsets, 16) != 0)) {
        Safefree(mrg->tracked_offsets);
        mrg->tracked_offsets = NULL;
        croak("Out of memory");
    }

    return mrg->tracked_offsets;
}
示例#15
0
			void pushBump(element_type const & entry)
			{
				if ( expect_false(full()) )
				{
					ensureSize(std::max(2*f,static_cast<size_t>(1)));
					assert ( ! full() );
				}
				push(entry);
			}
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();
}
示例#17
0
static void
select_modify (EV_P_ int fd, int oev, int nev)
{
  if (oev == nev)
    return;

  {
#if EV_SELECT_USE_FD_SET

    #if EV_SELECT_IS_WINSOCKET
    SOCKET handle = anfds [fd].handle;
    #else
    int handle = fd;
    #endif

    if (nev & EV_READ)
      FD_SET (handle, (fd_set *)vec_ri);
    else
      FD_CLR (handle, (fd_set *)vec_ri);

    if (nev & EV_WRITE)
      FD_SET (handle, (fd_set *)vec_wi);
    else
      FD_CLR (handle, (fd_set *)vec_wi);

#else

    int     word = fd / NFDBITS;
    fd_mask mask = 1UL << (fd % NFDBITS);

    if (expect_false (vec_max <= word))
      {
        int new_max = word + 1;

        vec_ri = ev_realloc (vec_ri, new_max * NFDBYTES);
        vec_ro = ev_realloc (vec_ro, new_max * NFDBYTES); /* could free/malloc */
        vec_wi = ev_realloc (vec_wi, new_max * NFDBYTES);
        vec_wo = ev_realloc (vec_wo, new_max * NFDBYTES); /* could free/malloc */

        for (; vec_max < new_max; ++vec_max)
          ((fd_mask *)vec_ri) [vec_max] =
          ((fd_mask *)vec_wi) [vec_max] = 0;
      }

    ((fd_mask *)vec_ri) [word] |= mask;
    if (!(nev & EV_READ))
      ((fd_mask *)vec_ri) [word] &= ~mask;

    ((fd_mask *)vec_wi) [word] |= mask;
    if (!(nev & EV_WRITE))
      ((fd_mask *)vec_wi) [word] &= ~mask;
#endif
  }
}
示例#18
0
int32 socket::recv()
{
    assert( "socket recv without io control",_io );
    static class lnetwork_mgr *network_mgr = lnetwork_mgr::instance();

    // 返回值: < 0 错误,0 成功,1 需要重读,2 需要重写
    int32 ret = _io->recv();
    if ( expect_false(ret < 0) )
    {
        socket::stop();
        network_mgr->connect_del( _conn_id );

        return -1;
    }

    // SSL握手成功,有数据待发送则会出现这种情况
    if ( expect_false(2 == ret) ) pending_send();

    return ret;
}
示例#19
0
SRL_STATIC_INLINE void
srl_read_header(pTHX_ srl_decoder_t *dec)
{
    UV header_len;

    /* 4 byte magic string + version/flags + hdr len at least */
    ASSERT_BUF_SPACE(dec, 4 + 1 + 1," while reading header");
    if (strnEQ((char*)dec->pos, SRL_MAGIC_STRING, 4)) {
        dec->pos += 4;
        dec->proto_version_and_flags = *dec->pos++;

        if (expect_false( (dec->proto_version_and_flags & SRL_PROTOCOL_VERSION_MASK) != 1 ))
            SRL_ERRORf1("Unsupported Sereal protocol version %u",
                    dec->proto_version_and_flags & SRL_PROTOCOL_VERSION_MASK);
        if ((dec->proto_version_and_flags & SRL_PROTOCOL_ENCODING_MASK) == SRL_PROTOCOL_ENCODING_RAW) {
            /* no op */
        }
        else
        if (
                ( dec->proto_version_and_flags & SRL_PROTOCOL_ENCODING_MASK ) == SRL_PROTOCOL_ENCODING_SNAPPY
                ||
                ( dec->proto_version_and_flags & SRL_PROTOCOL_ENCODING_MASK ) == SRL_PROTOCOL_ENCODING_SNAPPY_INCREMENTAL
        ) {
            if (expect_false( SRL_DEC_HAVE_OPTION(dec, SRL_F_DECODER_REFUSE_SNAPPY) )) {
                SRL_ERROR("Sereal document is compressed with Snappy, "
                      "but this decoder is configured to refuse Snappy-compressed input.");
            }
            dec->flags |= SRL_F_DECODER_DECOMPRESS_SNAPPY;
        }
        else
        {
            SRL_ERRORf1( "Sereal document encoded in an unknown format '%d'",
                     (dec->proto_version_and_flags & SRL_PROTOCOL_ENCODING_MASK) >> 4 );
        }

        /* Must do this via a temporary as it modifes dec->pos itself */
        header_len= srl_read_varint_uv_length(aTHX_ dec, " while reading header");
        /* Skip header since we don't have any defined header-content in this
         * protocol version. */
        dec->pos += header_len;
    } else {
示例#20
0
SRL_STATIC_INLINE void
srl_set_input_buffer(pTHX_ srl_merger_t *mrg, SV *src)
{
    STRLEN len;
    UV header_len;
    U8 encoding_flags;
    U8 protocol_version;
    srl_buffer_char *tmp;
    IV proto_version_and_encoding_flags_int;

    SRL_RDR_CLEAR(&mrg->ibuf);

    tmp = (srl_buffer_char*) SvPV(src, len);
    mrg->ibuf.start = mrg->ibuf.pos = tmp;
    mrg->ibuf.end = mrg->ibuf.start + len;

    proto_version_and_encoding_flags_int = srl_validate_header_version(aTHX_ (srl_reader_char_ptr) mrg->ibuf.start, len);

    if (proto_version_and_encoding_flags_int < 1) {
        if (proto_version_and_encoding_flags_int == 0)
            SRL_RDR_ERROR(mrg->pibuf, "Bad Sereal header: It seems your document was accidentally UTF-8 encoded");
        else
            SRL_RDR_ERROR(mrg->pibuf, "Bad Sereal header: Not a valid Sereal document.");
    }

    mrg->ibuf.pos += 5;
    encoding_flags = (U8) (proto_version_and_encoding_flags_int & SRL_PROTOCOL_ENCODING_MASK);
    protocol_version = (U8) (proto_version_and_encoding_flags_int & SRL_PROTOCOL_VERSION_MASK);

    if (expect_false(protocol_version > 3 || protocol_version < 1)) {
        SRL_RDR_ERRORf1(mrg->pibuf, "Unsupported Sereal protocol version %u", (unsigned int) protocol_version);
    }

    // skip header in any case
    header_len = srl_read_varint_uv_length(aTHX_ mrg->pibuf, " while reading header");
    mrg->ibuf.pos += header_len;

    if (encoding_flags == SRL_PROTOCOL_ENCODING_RAW) {
        /* no op */
    } else if (   encoding_flags == SRL_PROTOCOL_ENCODING_SNAPPY
               || encoding_flags == SRL_PROTOCOL_ENCODING_SNAPPY_INCREMENTAL)
    {
        srl_decompress_body_snappy(aTHX_ mrg->pibuf, encoding_flags, NULL);
    } else if (encoding_flags == SRL_PROTOCOL_ENCODING_ZLIB) {
        srl_decompress_body_zlib(aTHX_ mrg->pibuf, NULL);
    } else {
        SRL_RDR_ERROR(mrg->pibuf, "Sereal document encoded in an unknown format");
    }

    /* this functions *MUST* be called after srl_decompress_body* */
    SRL_RDR_UPDATE_BODY_POS(mrg->pibuf, protocol_version);
    DEBUG_ASSERT_RDR_SANE(mrg->pibuf);
}
示例#21
0
static void
poll_poll (EV_P_ ev_tstamp timeout)
{
  struct pollfd *p;
  int res;
  
  EV_RELEASE_CB;
  res = poll (polls, pollcnt, timeout * 1e3);
  EV_ACQUIRE_CB;

  if (expect_false (res < 0))
    {
      if (errno == EBADF)
        fd_ebadf (EV_A);
      else if (errno == ENOMEM && !syserr_cb)
        fd_enomem (EV_A);
      else if (errno != EINTR)
        ev_syserr ("(libev) poll");
    }
  else
    for (p = polls; res; ++p)
      {
        assert (("libev: poll() returned illegal result, broken BSD kernel?", p < polls + pollcnt));

        if (expect_false (p->revents)) /* this expect is debatable */
          {
            --res;

            if (expect_false (p->revents & POLLNVAL))
              fd_kill (EV_A_ p->fd);
            else
              fd_event (
                EV_A_
                p->fd,
                (p->revents & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0)
                | (p->revents & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0)
              );
          }
      }
}
示例#22
0
void
srl_iterator_next(pTHX_ srl_iterator_t *iter, UV n)
{
    IV expected_depth = iter->stack.depth;
    srl_iterator_stack_ptr stack_ptr = iter->stack.ptr;

    DEBUG_ASSERT_RDR_SANE(iter->pbuf);
    SRL_ITER_ASSERT_STACK(iter);

    SRL_ITER_TRACE("n=%"UVuf, n);
    SRL_ITER_REPORT_STACK_STATE(iter);

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

    while (1) {
        srl_iterator_wrap_stack(iter, expected_depth, stack_ptr);

        if (iter->stack.depth == expected_depth) {
            if (n == 0) break;
            else n--;
        }

        srl_iterator_step_internal(iter, stack_ptr);
    }

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

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

    SRL_ITER_TRACE("Did expected number of steps at depth %"IVdf, expected_depth);
    DEBUG_ASSERT_RDR_SANE(iter->pbuf);
}
示例#23
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);
}
示例#24
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);
}
示例#25
0
SRL_STATIC_INLINE void
srl_iterator_wrap_stack(pTHX_ srl_iterator_t *iter, IV expected_depth)
{
    srl_stack_t *stack = iter->stack;
    if (expect_false(SRL_STACK_DEPTH(stack) < expected_depth))
        SRL_ITER_ERRORf2("expected depth %"IVdf" is higher than current depth %"IVdf,
                         expected_depth, SRL_STACK_DEPTH(stack));

    while (!srl_stack_empty(stack) && stack->ptr->idx == 0) {
        if (SRL_STACK_DEPTH(stack) == expected_depth) break;
        srl_stack_pop_nocheck(stack);
        if (srl_stack_empty(stack))
            SRL_ITER_TRACE("end of stack reached");
    }
}
示例#26
0
void
srl_merger_append_all(pTHX_ srl_merger_t *mrg, AV *src)
{
    SSize_t i;
    SV **svptr;
    STRLEN size = 0;
    SSize_t tidx = av_len(src);

    if (mrg->obuf_last_successfull_offset) {
        /* If obuf_last_successfull_offset is true then last merge
         * operation has failed. It means that some cleanup operation needs to
         * be done. */

        SRL_MERGER_TRACE("last merge operation has failed, need to do some cleanup (offset %"UVuf")",
                          mrg->obuf_last_successfull_offset);

        mrg->obuf.pos = mrg->obuf.body_pos + mrg->obuf_last_successfull_offset;
        srl_cleanup_dedup_tlbs(aTHX_ mrg, mrg->obuf_last_successfull_offset);
        DEBUG_ASSERT_BUF_SANE(&mrg->obuf);
    }

    for (i = 0; i <= tidx; ++i) {
        svptr = av_fetch(src, i, 0);
        if (expect_false(svptr == NULL))
            croak("av_fetch returned NULL");

        size += SvLEN(*svptr);
    }

    /* preallocate space in obuf in one go,
     * of course this's is very rough estimation */
    GROW_BUF(&mrg->obuf, size);

    for (i = 0; i <= tidx; ++i) {
        srl_set_input_buffer(aTHX_ mrg, *av_fetch(src, i, 0));
        srl_build_track_table(aTHX_ mrg);

        /* save current offset as last successfull */
        mrg->obuf_last_successfull_offset = BODY_POS_OFS(&mrg->obuf);

        mrg->recursion_depth = 0;
        mrg->ibuf.pos = mrg->ibuf.body_pos + 1;
        srl_merge_single_value(aTHX_ mrg);

        mrg->cnt_of_merged_elements++;
        mrg->obuf_last_successfull_offset = 0;
    }
}
示例#27
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);
}
示例#28
0
文件: BamCat.hpp 项目: dkj/libmaus
			/**
			 * 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;
					}
				}
			}
示例#29
0
static void
port_poll (EV_P_ ev_tstamp timeout)
{
  int res, i;
  struct timespec ts;
  uint_t nget = 1;

  EV_RELEASE_CB;
  ts.tv_sec  = (time_t)timeout;
  ts.tv_nsec = (long)(timeout - (ev_tstamp)ts.tv_sec) * 1e9;
  res = port_getn (backend_fd, port_events, port_eventmax, &nget, &ts);
  EV_ACQUIRE_CB;

  if (res == -1)
    { 
      if (errno != EINTR && errno != ETIME)
        ev_syserr ("(libev) port_getn");

      return;
    } 

  for (i = 0; i < nget; ++i)
    {
      if (port_events [i].portev_source == PORT_SOURCE_FD)
        {
          int fd = port_events [i].portev_object;

          fd_event (
            EV_A_
            fd,
            (port_events [i].portev_events & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0)
            | (port_events [i].portev_events & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0)
          );

          port_associate_and_check (EV_A_ fd, anfds [fd].events);
        }
    }

  if (expect_false (nget == port_eventmax))
    {
      ev_free (port_events);
      port_eventmax = array_nextsize (sizeof (port_event_t), port_eventmax, port_eventmax + 1);
      port_events = (port_event_t *)ev_malloc (sizeof (port_event_t) * port_eventmax);
    }
}
示例#30
0
static unsigned long id_get(unsigned int hash_id)
{
	POOL key, *res;
	key.hash_id = hash_id;
	res = bsearch(&key, id_pool, pool_p, sizeof(POOL), cmp_id);
	if(res)
		return res->id;

	if(expect_false(pool_p == pool_num))
		array_needsize(false, POOL, id_pool, pool_num, pool_num + 128, array_zero_init);

	id_pool[pool_p].hash_id = hash_id;
	id_pool[pool_p].id = pool_p++;

	qsort(id_pool, pool_p, sizeof(POOL), cmp_id);

	return (pool_p - 1);
}