示例#1
0
LIST * list_append( LIST * l, LIST * nl )
{
    if ( list_empty( l ) )
        return nl;
    if ( !list_empty( nl ) )
    {
        int const l_size = list_length( l );
        int const nl_size = list_length( nl );
        int const size = l_size + nl_size;
        unsigned const bucket = get_bucket( size );

        /* Do we need to reallocate? */
        if ( l_size <= ( 1u << ( bucket - 1 ) ) )
        {
            LIST * result = list_alloc( size );
            memcpy( list_begin( result ), list_begin( l ), l_size * sizeof(
                OBJECT * ) );
            list_dealloc( l );
            l = result;
        }

        l->impl.size = size;
        memcpy( list_begin( l ) + l_size, list_begin( nl ), nl_size * sizeof(
            OBJECT * ) );
        list_dealloc( nl );
    }
    return l;
}
示例#2
0
文件: hfdb_cfg.c 项目: hailongz/c
void FDBConfigDelete(FDBConfig * config){
    hint32 i;
    InvokeTickBegin
    FDBConfigInternal * cfg = (FDBConfigInternal *) config;
    FDBClassConfig * cls;
    FDBIndexConfig * index;
    
    for(i=0;i< cfg->base.classCount;i++){
        cls = (FDBClassConfig *) list_get(cfg->dbClasss, i);
        free(cls->dbClass);
        free(cls);
    }
    
    list_dealloc(cfg->dbClasss);
    
    
    for(i=0;i< cfg->base.indexCount;i++){
        index = (FDBIndexConfig *) list_get(cfg->indexs, i);
        if(index->sortPropertys){
            free(index->sortPropertys);
        }
        free(index->index);
        free(index);
    }
    
    list_dealloc(cfg->indexs);
    
    map_dealloc(cfg->dbClassMap);
    map_dealloc(cfg->indexMap);
    
    free(cfg);
}
示例#3
0
LIST * list_pop_front( LIST * l )
{
    unsigned size = list_length( l );
    assert( size );
    --size;
    object_free( list_front( l ) );

    if ( size == 0 )
    {
        list_dealloc( l );
        return L0;
    }

    if ( ( ( size - 1 ) & size ) == 0 )
    {
        LIST * const nl = list_alloc( size );
        nl->impl.size = size;
        memcpy( list_begin( nl ), list_begin( l ) + 1, size * sizeof( OBJECT * )
            );
        list_dealloc( l );
        return nl;
    }

    l->impl.size = size;
    memmove( list_begin( l ), list_begin( l ) + 1, size * sizeof( OBJECT * ) );
    return l;
}
示例#4
0
文件: hdata_xml.c 项目: hailongz/c
static void hdata_xpath_selctor(data_xpath_t * xpath,data_xpath_selector_t * selector,hlist_t result, hcchar * selector_name,hcchar * exp,hbool r,InvokeTickDeclare){
	data_xpath_tag_t * tag = NULL;
	hint32 i,c ;
	hlist_t filters = list_alloc( 10, 10);
	hint32 index = data_xpath_tag_filter_parse( filters, exp,InvokeTickArg);
	
	if(r ){
		tag = data_xpath_search_tag(selector,selector_name,index<0?filters:NULL,InvokeTickArg);
	}
	else{
		tag = data_xpath_find_tag(selector,selector_name,index<0?filters:NULL,InvokeTickArg);
	}
	
	if(tag){
		if(index <0){
			data_xpath_tag_filter_handle( tag, result, filters,InvokeTickArg);
		}
		else if(index < list_count(tag->selectors)){
			list_add(result, list_get(tag->selectors, index));
		}
	}
	
	c = list_count(filters);
	for(i=0;i<c;i++){
		data_xpath_tag_filter_dealloc( list_get(filters, i),InvokeTickArg);
	}
	
	list_dealloc(filters);
}
示例#5
0
文件: hdata_set.c 项目: hailongz/c
static void ext_obj_data_set_destroy(hext_obj_t obj,hint32 size,InvokeTickDeclare){
	data_set_t * s = (data_set_t *)obj;
	ext_data_release(s->data);
	data_set_tree_item_dealloc(s->tree_root,InvokeTickArg);
	list_dealloc(s->items);
	map_dealloc(s->tree_cache);
}
示例#6
0
LIST * list_push_back( LIST * head, OBJECT * value )
{
    unsigned int size = list_length( head );
    unsigned int i;

    if ( DEBUG_LISTS )
        out_printf( "list > %s <\n", object_str( value ) );

    /* If the size is a power of 2, reallocate. */
    if ( size == 0 )
    {
        head = list_alloc( 1 );
    }
    else if ( ( ( size - 1 ) & size ) == 0 )
    {
        LIST * l = list_alloc( size + 1 );
        memcpy( l, head, sizeof( LIST ) + size * sizeof( OBJECT * ) );
        list_dealloc( head );
        head = l;
    }

    list_begin( head )[ size ] = value;
    head->impl.size = size + 1;

    return head;
}
示例#7
0
文件: hdata_xml.c 项目: hailongz/c
static void data_xpath_tag_dealloc(data_xpath_tag_t * tag,InvokeTickDeclare){
	if(tag){
		hint32 i,c;
		c = list_count(tag->selectors);
		for(i=0;i<c;i++){
			data_xpath_selector_dealloc((data_xpath_selector_t *)list_get(tag->selectors, i),InvokeTickArg);
		}
		list_dealloc(tag->selectors);
		mem_free( tag);
	}
}
示例#8
0
void list_free( LIST * head )
{
    if ( !list_empty( head ) )
    {
        LISTITER iter = list_begin( head );
        LISTITER const end = list_end( head );
        for ( ; iter != end; iter = list_next( iter ) )
            object_free( list_item( iter ) );
        list_dealloc( head );
    }
}
示例#9
0
文件: hdata_xml.c 项目: hailongz/c
hdata_xpath_selector_t hdata_xpath_single(hdata_xpath_t data_xpath, hcchar * path,hdata_xpath_selector_t parent_selector,InvokeTickDeclare){
	if(data_xpath && path){
		hlist_t  selectors = list_alloc( 20, 20);
		data_xpath_selector_t * s = NULL;
		hdata_xpath(data_xpath,path,selectors,parent_selector,InvokeTickArg);
		if(list_count(selectors) >0){
			s = list_get(selectors, 0);
		}
		list_dealloc(selectors);
		return (hdata_xpath_selector_t)s;
	}
	return NULL;
}
示例#10
0
static void test_list()
{
  size_t i;
  SizeList alist;
  list_alloc(&alist, 8);

  list_append(&alist, 1);
  list_append(&alist, 2);
  list_append(&alist, 3);

  assert(list_len(&alist) == 3);

  list_pop(&alist, NULL, 1);
  list_pop(&alist, NULL, 1);
  list_pop(&alist, NULL, 1);

  assert(list_len(&alist) == 0);

  list_prepend(&alist, 1);
  list_prepend(&alist, 2);
  list_prepend(&alist, 3);

  assert(list_len(&alist) == 3);

  list_shift(&alist, NULL, 1);
  list_shift(&alist, NULL, 1);
  list_shift(&alist, NULL, 1);

  assert(list_len(&alist) == 0);

  list_append(&alist, 14);
  list_append(&alist, 15);
  list_append(&alist, 16);
  list_prepend(&alist, 13);
  list_prepend(&alist, 12);
  list_prepend(&alist, 11);

  assert(list_len(&alist) == 6);

  for(i = 0; i < 6; i++) assert(list_get(&alist, i) == i+11);

  list_dealloc(&alist);
}
示例#11
0
文件: hdata_alloc.c 项目: hailongz/c
void hdata_dealloc(hdata_t data,InvokeTickDeclare){
	if(DATA_STRUCT_ASSET(data)){
		data_t * d = (data_t *)data;
		hint32 i,c;
		if(d->type == HDATA_TYPE_STRING){
			mem_free( d->value.string_value);
		}
		else if(d->type == HDATA_TYPE_ARRAY){
			c = list_count(d->value.array_value);
			for(i=0;i<c;i++){
				hdata_dealloc((hdata_t)list_get(d->value.array_value, i),InvokeTickArg);
			}
			list_dealloc(d->value.array_value);
		}
		else if(d->type == HDATA_TYPE_OBJECT){
			map_each(d->value.object_value, hdata_object_dealloc_each, NULL, NULL);
			map_dealloc(d->value.object_value);
		}
        else if(d->type == HDATA_TYPE_BYTES){
            ext_obj_release(d->value.binary_value);
        }
		mem_free( d);
	}
}
示例#12
0
文件: hdata_xml.c 项目: hailongz/c
void hdata_xpath(hdata_xpath_t data_xpath, hcchar * path,hlist_t result,hdata_xpath_selector_t parent_selector,InvokeTickDeclare){
	if(data_xpath && path){
		data_xpath_t * xpath = (data_xpath_t *)data_xpath;
		hchar * p = (hchar *)path,s = 0,r = 1;
		hbuffer_t selector_name = buffer_alloc(128,  128);
		hbuffer_t selector_exp = buffer_alloc(128,  128);
		
		data_xpath_selector_t * selector = parent_selector?(data_xpath_selector_t * )parent_selector:xpath->root;
		hlist_t selector_list = list_alloc( 10, 20);
		hint32 i,c;
		
		while(*p != '\0'){
			if(s ==0){
				if(SPACE_CHAR(*p)){
				}
				else if(*p == '/'){
					if(buffer_length(selector_name) >0){
						list_clear(selector_list);
						hdata_xpath_selctor(xpath,selector,selector_list,buffer_to_str(selector_name),buffer_to_str(selector_exp),r,InvokeTickArg);
						if(list_count(selector_list) ==0){
							break;
						}
						else{
							selector = list_get(selector_list, 0);
						}
						buffer_clear(selector_name);
						buffer_clear(selector_exp);
						r = !r;
					}
					else{
						r = !r;
					}
				}
				else if(*p == '['){
					s = 1;
				}
				else{
					buffer_append(selector_name, p, 1);
				}
			}
			else if(s == 1){
				if(*p == ']'){
					s = 0;
				}
				else{
					buffer_append(selector_exp,p,1);
				}
			}
			p++;
		}
		if(buffer_length(selector_name) >0){
			list_clear(selector_list);
			hdata_xpath_selctor(xpath,selector,selector_list,buffer_to_str(selector_name),buffer_to_str(selector_exp),r,InvokeTickArg);
			if(list_count(selector_list) !=0){
				selector = list_get(selector_list, 0);
			}
		}
		buffer_dealloc(selector_name);
		buffer_dealloc(selector_exp);
		c = list_count(selector_list);
		for(i=0;i<c;i++){
			selector = list_get(selector_list, i);
			list_add(result, selector);
		}
		list_dealloc(selector_list);
	}
}
示例#13
0
文件: hjson.c 项目: hailongz/c
hany hjson_decode(hjson_t * json,hcchar * str,InvokeTickDeclare){
    hany data = NULL;
	hchar * p=(hchar *)str;
	hlist_t data_stack = list_alloc(20,20);
	hlist_t state_stack =list_alloc(20,20);
	hbuffer_t value_buffer = buffer_alloc(128,  256);
	hbuffer_t name_buffer = buffer_alloc(128,  256);
    hbuffer_t base64_buffer= buffer_alloc(1024,1024);
	hintptr s;
    hwchar wchar;
    hint32 iwchar;
    hchar wchbuf[8];
	//hint32 object_level=0;
	//hint32 array_level =0;
	list_add(state_stack, (hany) 0);
	
	
	while (p && *p != '\0') {
		s = (hintptr)list_last(state_stack);
		if(s == 0x00){
			if(SPACE_CHAR(*p)){
			}
			else if( *p == '{'){
				list_add(state_stack, (hany)0x10);
				data = (*json->object_new)(json,InvokeTickArg);
				list_add(data_stack, data);
				list_add(data_stack, data);
				//hlog("object begin %ld\n",object_level++);
			}
			else if( *p == '['){
				list_add(state_stack, (hany)0x20);
				data = (*json->array_new)(json,InvokeTickArg);
				list_add(data_stack, data);
				list_add(data_stack, data);
				//hlog("array begin %ld\n",array_level++);
			}
			else if( *p == '\"'){
				list_add(state_stack, (hany)0x01);
				list_add(state_stack, (hany)0x30);
			}
			else if( TRUE_EQUAL(p)){
				data = (*json->booleanValue)(json,hbool_true,InvokeTickArg);
				list_add(data_stack, data);
				break;
			}
			else if( FALSE_EQUAL(p)){
				data = (*json->booleanValue)(json,hbool_false,InvokeTickArg);
				list_add(data_stack, data);
				break;
			}
			else if( NULL_EQUAL(p)){
				data = (*json->nullValue)(json,InvokeTickArg);
				list_add(data_stack, data);
				break;
			}
			else{
				list_add(state_stack, (hany)0x02);
				list_add(state_stack, (hany)0x40);
				continue;
			}
		}
		else if(s == 0x01){
			// string value end
			data = (*json->stringValue)(json,buffer_to_str(value_buffer),base64_buffer,InvokeTickArg);
			list_add(data_stack, data);
			break;
		}
		else if(s == 0x02){
			// number value end
			data = (*json->numberValue)(json,buffer_to_str(value_buffer),InvokeTickArg);
			list_add(data_stack, data);
			break;
		}
		else if(s ==0x10) {
			// object
			if(SPACE_CHAR(*p) || *p ==','){
			}
			else if(*p == '\"'){
				list_add(state_stack, (hany)0x11);
			}
			else if(*p == ':'){
				list_add(state_stack, (hany)0x12);
			}
			else if(*p == '}'){
				list_pop(state_stack);
				list_pop(data_stack);
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				//hlog("object end %ld\n",--object_level);
                
			}
			else{
				buffer_append(name_buffer,p,1);
				list_add(state_stack, (hany)0x11);
			}
		}
		else if(s == 0x11){
			// object value key
			if(*p == '\\' && p[1] == '"'){
				p++;
				buffer_append(name_buffer, p, 1);
			}
			else if( *p == '"'){
				list_pop(state_stack);
			}
			else if( *p == ':'){
				list_pop(state_stack);
				list_add(state_stack, (hany)0x12);
			}
			else{
				buffer_append(name_buffer, p, 1);
			}
		}
		else if(s == 0x12){
			// object value
			if(SPACE_CHAR(*p)){
			}
			else if( *p == '{'){
				list_pop(state_stack);
				list_add(state_stack, (hany)0x10);
				data = (*json->object_new)(json,InvokeTickArg);
                (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
				list_add(data_stack, data);
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				//hlog("object begin %ld\n",object_level++);
                
			}
			else if( *p == '['){
				list_pop(state_stack);
				list_add(state_stack, (hany)0x20);
				data = (*json->array_new)(json,InvokeTickArg);
				(*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
				list_add(data_stack, data);
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				//hlog("array begin %ld\n",array_level++);
			}
			else if( *p =='"'){
				// string value
				list_pop(state_stack);
				list_add(state_stack, (hany)0x13);
				list_add(state_stack, (hany)0x30);
			}
			else if( TRUE_EQUAL(p)){
				list_pop(state_stack);
                
                data = (*json->booleanValue)(json,hbool_true,InvokeTickArg);
                (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
                
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				p += 3;
			}
			else if( FALSE_EQUAL(p)){
				list_pop(state_stack);
                data = (*json->booleanValue)(json,hbool_false,InvokeTickArg);
                (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
                
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				p += 4;
			}
			else if( NULL_EQUAL(p)){
				list_pop(state_stack);
                data = (*json->nullValue)(json,InvokeTickArg);
                (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
                
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				p += 3;
			}
			else {
				list_pop(state_stack);
				list_add(state_stack, (hany)0x14);
				list_add(state_stack, (hany)0x40);
				continue;
			}
		}
		else if(s == 0x13){
			// string value end
            data = (*json->stringValue)(json,buffer_to_str(value_buffer),base64_buffer,InvokeTickArg);
            (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
			buffer_clear(name_buffer);
			buffer_clear(value_buffer);
			list_pop(state_stack);
			continue;
		}
		else if(s == 0x14){
			// number value end
			data = (*json->numberValue)(json,buffer_to_str(value_buffer),InvokeTickArg);
            (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
			buffer_clear(name_buffer);
			buffer_clear(value_buffer);
			list_pop(state_stack);
			continue;
		}
		else if(s ==0x20){
			// array value
			if(SPACE_CHAR(*p) || *p ==','){
			}
			else if( *p ==']'){
				list_pop(state_stack);
				list_pop(data_stack);
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				//hlog("array end %ld\n",--array_level);
			}
			else if( *p == '{'){
				list_add(state_stack, (hany)0x23);
				list_add(state_stack, (hany)0x10);
				data = (*json->object_new)(json,InvokeTickArg);
                (*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
				list_add(data_stack, data);
				//hlog("object begin %ld\n",object_level++);
                
			}
			else if( *p == '['){
				list_add(state_stack, (hany)0x23);
				list_add(state_stack, (hany)0x20);
                data = (*json->array_new)(json,InvokeTickArg);
				(*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
				list_add(data_stack, data);
				//hlog("array begin %ld\n",array_level++);
			}
			else if( *p =='"'){
				// string value
				list_add(state_stack, (hany)0x21);
				list_add(state_stack, (hany)0x30);
			}
			else if( TRUE_EQUAL(p)){
                data = (*json->booleanValue)(json,hbool_true,InvokeTickArg);
				(*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
				p += 3;
			}
			else if( FALSE_EQUAL(p)){
                data = (*json->booleanValue)(json,hbool_false,InvokeTickArg);
				(*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
				p += 4;
			}
			else if( NULL_EQUAL(p)){
                data = (*json->nullValue)(json,InvokeTickArg);
				(*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
				p += 3;
			}
			else {
				list_add(state_stack, (hany)0x22);
				list_add(state_stack, (hany)0x40);
				continue;
			}
		}
		else if(s == 0x21){
			// string value end
            
            data = (*json->stringValue)(json,buffer_to_str(value_buffer),base64_buffer,InvokeTickArg);
            (*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
            
			buffer_clear(name_buffer);
			buffer_clear(value_buffer);
			list_pop(state_stack);
			continue;
		}
		else if(s == 0x22){
			// number value end
            data = (*json->numberValue)(json,buffer_to_str(value_buffer),InvokeTickArg);
            (*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
            
			buffer_clear(name_buffer);
			buffer_clear(value_buffer);
			list_pop(state_stack);
			continue;
		}
		else if(s == 0x23){
			// object || array value end
			/*
             data = list_pop(data_stack);
             if(data ){
             hdata_array_add((hdata_t)list_last(data_stack), data);
             }
			 */
			buffer_clear(name_buffer);
			buffer_clear(value_buffer);
			list_pop(state_stack);
			continue;
		}
		else if(s ==0x30){
			// string value
			if( *p == '\\'){
				if( p[1] == 'n'){
					buffer_append_str(value_buffer,"\n");
				}
				else if( p[1] == 'r'){
					buffer_append_str(value_buffer,"\r");
				}
				else if( p[1] == 't'){
					buffer_append_str(value_buffer,"\t");
				}
				else if( p[1] == '\\'){
					buffer_append_str(value_buffer,"\\");
				}
				else if( p[1] == '\"'){
					buffer_append_str(value_buffer,"\"");
				}
				else if( p[1] == '\''){
					buffer_append_str(value_buffer,"\'");
				}
                else if( p[1] == 'u' ||  p[1] == 'U'){
                    iwchar = 0;
					sscanf(p + 2, "%04x",&iwchar);
                    wchar = iwchar;
                    strcpy(wchbuf, "");
                    buffer_append(value_buffer, wchbuf,wstr_to_str(&wchar, 1, wchbuf));
                    p+= 4;
				}
				else{
					buffer_append(value_buffer,p+1,1);
				}
				p++;
			}
			else if( *p == '\"'){
				list_pop(state_stack);
			}
			else{
				buffer_append(value_buffer,p,1);
			}
		}
		else if(s == 0x40){
			// number value
			if(NUMBER_CHAR(*p)){
				buffer_append(value_buffer, p, 1);
			}
			else{
				list_pop(state_stack);
				continue;
			}
		}
		
		p++;
	}
	
	while((data = list_pop(data_stack))){
        if(list_count(data_stack) ==0){
            break;
        }
        (*json->object_dealloc)(json,data,InvokeTickArg);
	}
	
	buffer_dealloc(value_buffer);
	buffer_dealloc(name_buffer);
    buffer_dealloc(base64_buffer);
	list_dealloc(data_stack);
	list_dealloc(state_stack);
    
    return data;
}