コード例 #1
0
ファイル: torture_url.c プロジェクト: FreeMCU/freemcu
int test_tags(void)
{
  url_t u0[1];
  url_t *u1 = NULL;
  url_t const *u2 = (void *)-1;
  url_t const u3[1] = { URL_INIT_AS(sip) };
  char c0[] = "http://www.nokia.com";
  char const *c1 = "http://goodfeel.nokia.com";
  char *c2 = "http://forum.nokia.com";
  char const c3[] = "http://www.research.nokia.com";
  url_string_t *us0 = NULL;

  tagi_t *lst, *dup;

  tag_value_t value;
  char *s;
  su_home_t home[1] = { SU_HOME_INIT(home) };

  BEGIN();

  TEST(t_scan(urltag_url, home, c0, &value), 0);
  TEST_S(s = url_as_string(home, (url_t *)value), c0);

  TEST(t_scan(urltag_url, home, c3, &value), 0);
  TEST_S(s = url_as_string(home, (url_t *)value), c3);

  TEST_1(url_d(u0, c0) == 0);

  lst = tl_list(URLTAG_URL(u0),
		URLTAG_URL(u1),
		URLTAG_URL(u2),
		URLTAG_URL(u3),
		URLTAG_URL(c0),
		URLTAG_URL(c1),
		URLTAG_URL(c2),
		URLTAG_URL(c3),
		URLTAG_URL(us0),
		TAG_NULL());

  TEST_1(lst);

  dup = tl_adup(home, lst);

  tl_vfree(lst);

  su_free(home, dup);

  su_home_deinit(home);

  END();
}
コード例 #2
0
ファイル: table_man.cpp プロジェクト: PickXu/zero-xum
w_rc_t table_man_t<T>::fetch_table(ss_m* db, lock_mode_t /* alm */)
{
    assert (db);
    assert (_ptable);

    bool eof = false;
    int counter = -1;

    table_row_t* tuple = get_tuple();
    rep_row_t areprow(ts());
    rep_row_t areprow_key(ts());
    areprow.set(_ptable->maxsize());
    areprow_key.set(_ptable->maxsize());
    tuple->_rep = &areprow;
    tuple->_rep_key = &areprow_key;

    W_DO(db->begin_xct());

    // 1. scan the table
    table_scan_iter_impl<T> t_scan(this);
    while(!eof) {
	W_DO(t_scan.next(eof, *tuple));
	counter++;
    }
    TRACE( TRACE_ALWAYS, "%s:%d pages\n", _ptable->name(), counter);

    // 2. scan the indexes
    for (auto index : _ptable->get_indexes()) {
        index_scan_iter_impl<T> i_scan(index, this);
        eof = false;
        counter = -1;
        while(!eof) {
            W_DO(i_scan.next(eof, *tuple));
            counter++;
        }
        TRACE( TRACE_ALWAYS, "\t%s:%d pages\n", index->name().c_str(), counter);
    }

    W_DO(db->commit_xct());
    give_tuple(tuple);

    return RCOK;
}
コード例 #3
0
ファイル: luasofia_tags.c プロジェクト: ichramm/luasofia
tagi_t* luasofia_tags_table_to_taglist(lua_State *L, int index, su_home_t *home)
{
    int i = 0;
    int maxtags = TAGS_LIST_SIZE;
    tagi_t* tags = su_zalloc(home, sizeof(tagi_t) * maxtags);

    if(!lua_istable(L, index)) {
        tags[0].t_tag = NULL;
        tags[0].t_value = 0;
        return tags;
    }

    /* put the tag table at the stack */
    lua_rawgeti(L, LUA_REGISTRYINDEX, tag_table_ref);
    if (lua_isnil(L, -1)) {
        su_free(home, tags);
        luaL_error(L, "Failed to get tag table!");
    }

    if (index < 0)
        index--;

    /* first key */
    lua_pushnil(L);
    while(lua_next(L, index) != 0) {
        /* 'key' at index -2 and 'value' at index -1 */
        tag_type_t t_tag = NULL;
        tag_value_t return_value;
        char const *s = NULL;

        /* if 'value' is nil not use this tag */
        if(lua_isnil(L, -1)) {
            /* remove 'value' and 'key' is used on the next iteration */
            lua_pop(L, 1);
            continue;
        }
        s = lua_tostring(L, -1);

        /* lookup key in the tag table and push tag_type_t */
        lua_pushvalue(L, -2);
        lua_rawget(L, -4);
        t_tag = lua_touserdata(L, -1);
        lua_pop(L, 1);

        if(t_scan(t_tag, home, s, &return_value) == -1) {
            su_free(home, tags);
            luaL_error(L, "Tag '%s' doesn't exist!", lua_tostring(L, -2));
        }

        tags[i].t_tag = t_tag;
        tags[i++].t_value = return_value;

        if(i == maxtags - 1) {
            maxtags *= 2;
            tags = su_realloc(home, tags, sizeof(tagi_t) * maxtags);
        }

        /* remove 'value' and 'key' is used on the next iteration */
        lua_pop(L, 1);
    }
    /* remove tag table from stack */
    lua_pop(L, 1);

    tags[i].t_tag = NULL;
    tags[i].t_value = 0;
    return tags;
}