コード例 #1
0
ファイル: parse.c プロジェクト: Cabriter/abelkhan
PARSE * parse_make(
    int      type,
    PARSE  * left,
    PARSE  * right,
    PARSE  * third,
    OBJECT * string,
    OBJECT * string1,
    int      num )
{
    PARSE * p = (PARSE *)BJAM_MALLOC( sizeof( PARSE ) );

    p->type = type;
    p->left = left;
    p->right = right;
    p->third = third;
    p->string = string;
    p->string1 = string1;
    p->num = num;
    p->refs = 1;
    p->rulename = 0;

    if ( left )
    {
        p->file = object_copy( left->file );
        p->line = left->line;
    }
    else
    {
        yyinput_last_read_token( &p->file, &p->line );
        p->file = object_copy( p->file );
    }

    return p;
}
コード例 #2
0
ファイル: property-set.c プロジェクト: Kirija/XPIR
static void ps_map_rehash( struct ps_map * map )
{
    struct ps_map old = *map;
    size_t i;
    map->table = BJAM_MALLOC( map->table_size * 2 * sizeof( struct ps_map_entry * ) );
    map->table_size *= 2;
    for ( i = 0; i < map->table_size; ++i )
    {
        map->table[ i ] = NULL;
    }
    for ( i = 0; i < old.table_size; ++i )
    {
        struct ps_map_entry * pos;
        for ( pos = old.table[ i ]; pos; )
        {
            struct ps_map_entry * tmp = pos->next;

            unsigned hash_val = list_hash( pos->key );
            unsigned bucket = hash_val % map->table_size;
            pos->next = map->table[ bucket ];
            map->table[ bucket ] = pos;

            pos = tmp;
        }
    }
    BJAM_FREE( old.table );
}
コード例 #3
0
ファイル: object.c プロジェクト: TuZZiX/ROS_IDE_inc
static void string_set_init( string_set * set )
{
    set->size = 0;
    set->num = 4;
    set->data = (struct hash_item * *)BJAM_MALLOC( set->num * sizeof( struct hash_item * ) );
    memset( set->data, 0, set->num * sizeof( struct hash_item * ) );
}
コード例 #4
0
argument_list * args_new()
{
    argument_list * r = (argument_list *)BJAM_MALLOC( sizeof(argument_list) );
    r->reference_count = 0;
    lol_init( r->data );
    return r;
}
コード例 #5
0
ファイル: lists.c プロジェクト: DieselPowerKOR/quakeslash
LIST *
list_sort(
    LIST *l)
{
    int len, ii;
    char** strings;
    LIST* listp;
    LIST* result = 0;

    if (!l)
        return L0;

    len = list_length(l);
    strings = (char**)BJAM_MALLOC( len * sizeof(char*) );

    listp = l;
    for (ii = 0; ii < len; ++ii) {
        strings[ii] = listp->string;
        listp = listp->next;
    }

    qsort(strings, len, sizeof(char*), str_ptr_compare);

    for (ii = 0; ii < len; ++ii) {
        result = list_append( result, list_new(0, strings[ii]) );
    }

    BJAM_FREE(strings);

    return result;
}
コード例 #6
0
ファイル: command.c プロジェクト: Kirija/XPIR
CMD * cmd_new( RULE * rule, LIST * targets, LIST * sources, LIST * shell )
{
    CMD * cmd = (CMD *)BJAM_MALLOC( sizeof( CMD ) );
    FRAME frame[ 1 ];

    assert( cmd );
    cmd->rule = rule;
    cmd->shell = shell;
    cmd->next = 0;
    cmd->noop = 0;

    lol_init( &cmd->args );
    lol_add( &cmd->args, targets );
    lol_add( &cmd->args, sources );
    string_new( cmd->buf );

    frame_init( frame );
    frame->module = rule->module;
    lol_init( frame->args );
    lol_add( frame->args, list_copy( targets ) );
    lol_add( frame->args, list_copy( sources ) );
    function_run_actions( rule->actions->command, frame, stack_global(),
        cmd->buf );
    frame_free( frame );

    return cmd;
}
コード例 #7
0
ファイル: order.c プロジェクト: Kirija/XPIR
LIST * order( FRAME * frame, int flags )
{
    LIST * arg = lol_get( frame->args, 0 );
    LIST * result = L0;
    int src;
    LISTITER iter = list_begin( arg );
    LISTITER const end = list_end( arg );

    /* We need to create a graph of order dependencies between the passed
     * objects. We assume there are no duplicates passed to 'add_pair'.
     */
    int length = list_length( arg );
    int * * graph = ( int * * )BJAM_CALLOC( length, sizeof( int * ) );
    int * order = ( int * )BJAM_MALLOC( ( length + 1 ) * sizeof( int ) );

    for ( src = 0; iter != end; iter = list_next( iter ), ++src )
    {
        /* For all objects this one depends upon, add elements to 'graph'. */
        LIST * dependencies = var_get( frame->module, list_item( iter ) );
        int index = 0;
        LISTITER dep_iter = list_begin( dependencies );
        LISTITER const dep_end = list_end( dependencies );

        graph[ src ] = ( int * )BJAM_CALLOC( list_length( dependencies ) + 1,
            sizeof( int ) );
        for ( ; dep_iter != dep_end; dep_iter = list_next( dep_iter ) )
        {
            int const dst = list_index( arg, list_item( dep_iter ) );
            if ( dst != -1 )
                graph[ src ][ index++ ] = dst;
        }
        graph[ src ][ index ] = -1;
    }

    topological_sort( graph, length, order );

    {
        int index = length - 1;
        for ( ; index >= 0; --index )
        {
            int i;
            LISTITER iter = list_begin( arg );
            LISTITER const end = list_end( arg );
            for ( i = 0; i < order[ index ]; ++i, iter = list_next( iter ) );
            result = list_push_back( result, object_copy( list_item( iter ) ) );
        }
    }

    /* Clean up */
    {
        int i;
        for ( i = 0; i < length; ++i )
            BJAM_FREE( graph[ i ] );
        BJAM_FREE( graph );
        BJAM_FREE( order );
    }

    return result;
}
コード例 #8
0
ファイル: command.c プロジェクト: OggYiu/rag-engine
CMDLIST * cmdlist_append_target( CMDLIST * l, TARGET * t )
{
    CMDLIST * result = (CMDLIST *)BJAM_MALLOC( sizeof( CMDLIST ) );
    result->iscmd = 0;
    result->next = l;
    result->impl.t = t;
    return result;
}
コード例 #9
0
ファイル: command.c プロジェクト: OggYiu/rag-engine
/*
 * cmdlist_append_cmd
 */
CMDLIST * cmdlist_append_cmd( CMDLIST * l, CMD * cmd )
{
    CMDLIST * result = (CMDLIST *)BJAM_MALLOC( sizeof( CMDLIST ) );
    result->iscmd = 1;
    result->next = l;
    result->impl.cmd = cmd;
    return result;
}
コード例 #10
0
static rule_actions * actions_new( FUNCTION * command, LIST * bindlist, int flags )
{
    rule_actions * result = (rule_actions *)BJAM_MALLOC( sizeof( rule_actions ) );
    function_refer( command );
    result->command = command;
    result->bindlist = bindlist;
    result->flags = flags;
    result->reference_count = 0;
    return result;
}
コード例 #11
0
ファイル: property-set.c プロジェクト: Kirija/XPIR
static void ps_map_init( struct ps_map * map )
{
    size_t i;
    map->table_size = 2;
    map->num_elems = 0;
    map->table = BJAM_MALLOC( map->table_size * sizeof( struct ps_map_entry * ) );
    for ( i = 0; i < map->table_size; ++i )
    {
        map->table[ i ] = NULL;
    }
}
コード例 #12
0
TARGET * copytarget( const TARGET * ot )
{
    TARGET * t = (TARGET *)BJAM_MALLOC( sizeof( *t ) );
    memset( (char *)t, '\0', sizeof( *t ) );
    t->name = object_copy( ot->name );
    t->boundname = object_copy( t->name );

    t->flags |= T_FLAG_NOTFILE | T_FLAG_INTERNAL;

    return t;
}
コード例 #13
0
ファイル: filesys.c プロジェクト: LocutusOfBorg/poedit
FILELIST * filelist_new( OBJECT * path )
{
    FILELIST * list = (FILELIST *)BJAM_MALLOC( sizeof( FILELIST ) );

    memset( list, 0, sizeof( *list ) );
    list->size = 0;
    list->head = 0;
    list->tail = 0;

    return filelist_push_back( list, path );
}
コード例 #14
0
ファイル: make1.c プロジェクト: CarterTsai/clasp
static state * alloc_state()
{
    if ( state_freelist )
    {
        state * const pState = state_freelist;
        state_freelist = pState->prev;
        memset( pState, 0, sizeof( state ) );
        return pState;
    }
    return (state *)BJAM_MALLOC( sizeof( state ) );
}
コード例 #15
0
ファイル: hash.c プロジェクト: romanzenka/myrimatch
static void * hash_mem_alloc(size_t datalen, size_t size)
{
    if (sizeof(HASHDATA) == datalen)
    {
        return BJAM_MALLOC_RAW(size);
    }
    else
    {
        return BJAM_MALLOC(size);
    }
}
コード例 #16
0
ファイル: lists.c プロジェクト: TuZZiX/ROS_IDE_inc
static LIST * list_alloc( unsigned const size )
{
    unsigned const bucket = get_bucket( size );
    if ( freelist[ bucket ] )
    {
        LIST * result = freelist[ bucket ];
        freelist[ bucket ] = result->impl.next;
        return result;
    }
    return (LIST *)BJAM_MALLOC( sizeof( LIST ) + ( 1u << bucket ) *
        sizeof( OBJECT * ) );
}
コード例 #17
0
ファイル: order.c プロジェクト: CambrianTech/boost-build
LIST *order( PARSE *parse, FRAME *frame )
{
    LIST* arg = lol_get( frame->args, 0 );
    LIST* tmp;
    LIST* result = 0;
    int src;

    /* We need to create a graph of order dependencies between
       the passed objects. We assume that there are no duplicates
       passed to 'add_pair'.
    */
    int length = list_length(arg);
    int** graph = (int**)BJAM_CALLOC(length, sizeof(int*));
    int* order = (int*)BJAM_MALLOC((length+1)*sizeof(int));

    for(tmp = arg, src = 0; tmp; tmp = tmp->next, ++src) {
        /* For all object this one depend upon, add elements
           to 'graph' */
        LIST* dependencies = var_get(tmp->string);
        int index = 0;

        graph[src] = (int*)BJAM_CALLOC(list_length(dependencies)+1, sizeof(int));
        for(; dependencies; dependencies = dependencies->next) {
            int dst = list_index(arg, dependencies->string);
            if (dst != -1)
                graph[src][index++] = dst;
        }
        graph[src][index] = -1;
    }

    topological_sort(graph, length, order);

    {
        int index = length-1;
        for(; index >= 0; --index) {
            int i;
            tmp = arg;
            for (i = 0; i < order[index]; ++i, tmp = tmp->next);
            result = list_new(result, tmp->string);
        }
    }

    /* Clean up */
    {
        int i;
        for(i = 0; i < length; ++i)
            BJAM_FREE(graph[i]);
        BJAM_FREE(graph);
        BJAM_FREE(order);
    }

    return result;
}
コード例 #18
0
TARGETS * targetentry( TARGETS * chain, TARGET * target )
{
    TARGETS * c = (TARGETS *)BJAM_MALLOC( sizeof( TARGETS ) );
    c->target = target;

    if ( !chain ) chain = c;
    else chain->tail->next = c;
    chain->tail = c;
    c->next = 0;

    return chain;
}
コード例 #19
0
ファイル: hash.c プロジェクト: TuZZiX/ROS_IDE_inc
static void hashrehash( struct hash * hp )
{
    int i = ++hp->items.list;
    hp->items.more = i ? 2 * hp->items.nel : hp->inel;
    hp->items.next = (char *)BJAM_MALLOC( hp->items.more * hp->items.size );
    hp->items.free = 0;

    hp->items.lists[ i ].nel = hp->items.more;
    hp->items.lists[ i ].base = hp->items.next;
    hp->items.nel += hp->items.more;

    if ( hp->tab.base )
        BJAM_FREE( (char *)hp->tab.base );

    hp->tab.nel = hp->items.nel * hp->bloat;
    hp->tab.base = (ITEM * *)BJAM_MALLOC( hp->tab.nel * sizeof( ITEM * * ) );

    memset( (char *)hp->tab.base, '\0', hp->tab.nel * sizeof( ITEM * ) );

    for ( i = 0; i < hp->items.list; ++i )
    {
        int nel = hp->items.lists[ i ].nel;
        char * next = hp->items.lists[ i ].base;

        for ( ; nel--; next += hp->items.size )
        {
            ITEM * i = (ITEM *)next;
            ITEM * * ip = hp->tab.base + object_hash( hash_item_key( i ) ) %
                hp->tab.nel;
            /* code currently assumes rehashing only when there are no free
             * items
             */
            assert( hash_item_key( i ) );

            i->next = *ip;
            *ip = i;
        }
    }
}
コード例 #20
0
ファイル: object.c プロジェクト: TuZZiX/ROS_IDE_inc
static char * allocate( size_t n )
{
#ifdef BJAM_NEWSTR_NO_ALLOCATE
    return (char *)BJAM_MALLOC( n );
#else
    /* See if we can grab storage from an existing block. */
    size_t remaining = storage_finish - storage_start;
    n = ( ( n + ALLOC_ALIGNMENT - 1 ) / ALLOC_ALIGNMENT ) * ALLOC_ALIGNMENT;
    if ( remaining >= n )
    {
        char * result = storage_start;
        storage_start += n;
        return result;
    }
    else  /* Must allocate a new block. */
    {
        strblock * new_block;
        size_t nalloc = n;
        if ( nalloc < STRING_BLOCK )
            nalloc = STRING_BLOCK;

        /* Allocate a new block and link into the chain. */
        new_block = (strblock *)BJAM_MALLOC( offsetof( strblock, data[ 0 ] ) +
            nalloc * sizeof( new_block->data[ 0 ] ) );
        if ( new_block == 0 )
            return 0;
        new_block->next = strblock_chain;
        strblock_chain = new_block;

        /* Take future allocations out of the larger remaining space. */
        if ( remaining < nalloc - n )
        {
            storage_start = new_block->data + n;
            storage_finish = new_block->data + nalloc;
        }
        return new_block->data;
    }
#endif
}
コード例 #21
0
ACTIONS * actionlist( ACTIONS * chain, ACTION * action )
{
    ACTIONS * actions = (ACTIONS *)BJAM_MALLOC( sizeof( ACTIONS ) );

    actions->action = action;

    ++action->refs;
    if ( !chain ) chain = actions;
    else chain->tail->next = actions;
    chain->tail = actions;
    actions->next = 0;

    return chain;
}
コード例 #22
0
ファイル: filesys.c プロジェクト: LocutusOfBorg/poedit
FILELIST * filelist_push_front( FILELIST * list, OBJECT * path )
{
    FILEITEM * item;
    file_info_t * file;

    /* Lazy initialization
     */
    if ( filelist_empty( list ) )
    {
        list = filelist_new( path );
        return list;
    }


    item = (FILEITEM *)BJAM_MALLOC( sizeof( FILEITEM ) );
    memset( item, 0, sizeof( *item ) );
    item->value = (file_info_t *)BJAM_MALLOC( sizeof( file_info_t ) );

    file = item->value;
    memset( file, 0, sizeof( *file ) );

    file->name = path;
    file->files = L0;

    if ( list->head )
    {
        item->next = list->head;
    }
    else
    {
        list->tail = item;
    }
    list->head = item;
    list->size++;

    return list;
}
コード例 #23
0
ファイル: make1.c プロジェクト: DieselPowerKOR/quakeslash
static state *alloc_state()
{
	if(state_freelist != NULL)
	{
		state *pState;

		pState = state_freelist;
		state_freelist = pState->prev;
		memset(pState, 0, sizeof(state));
		return pState;
	}
	else
	{
		return (state *)BJAM_MALLOC(sizeof(state));
	}
}
コード例 #24
0
ファイル: hash.c プロジェクト: TuZZiX/ROS_IDE_inc
struct hash * hashinit( int datalen, char const * name )
{
    struct hash * hp = (struct hash *)BJAM_MALLOC( sizeof( *hp ) );

    hp->bloat = 3;
    hp->tab.nel = 0;
    hp->tab.base = 0;
    hp->items.more = 0;
    hp->items.free = 0;
    hp->items.size = sizeof( ITEM ) + ALIGNED( datalen );
    hp->items.list = -1;
    hp->items.nel = 0;
    hp->inel = 11;  /* 47 */
    hp->name = name;

    return hp;
}
コード例 #25
0
ファイル: scan.c プロジェクト: 0xDEC0DE8/mcsema
void yyfparse( OBJECT * s )
{
    struct include * i = (struct include *)BJAM_MALLOC( sizeof( *i ) );

    /* Push this onto the incp chain. */
    i->string = "";
    i->strings = 0;
    i->file = 0;
    i->fname = object_copy( s );
    i->line = 0;
    i->next = incp;
    incp = i;

    /* If the filename is "+", it means use the internal jambase. */
    if ( !strcmp( object_str( s ), "+" ) )
        i->strings = jambase;
}
コード例 #26
0
ファイル: object.c プロジェクト: 0xDEC0DE8/mcsema
OBJECT * object_new( const char * string )
{
#ifdef BJAM_NO_MEM_CACHE
    int l = strlen( string );
    struct hash_item * m = (struct hash_item *)BJAM_MALLOC( sizeof(struct hash_header) + l + 1 );

    strtotal += l + 1;
    memcpy( m->data, string, l + 1 );
    m->header.magic = OBJECT_MAGIC;
    return (OBJECT *)m->data;
#else
    if ( ! strhash.data )
        string_set_init( &strhash );

    strcount_in += 1;

    return (OBJECT *)string_set_insert( &strhash, string );
#endif
}
コード例 #27
0
SETTINGS * addsettings( SETTINGS * head, int flag, OBJECT * symbol, LIST * value )
{
    SETTINGS * v;

    /* Look for previous settings. */
    for ( v = head; v; v = v->next )
        if ( object_equal( v->symbol, symbol ) )
            break;

    /* If not previously set, alloc a new. */
    /* If appending, do so. */
    /* Else free old and set new. */
    if ( !v )
    {
        v = settings_freelist;

        if ( v )
            settings_freelist = v->next;
        else
            v = (SETTINGS *)BJAM_MALLOC( sizeof( *v ) );

        v->symbol = object_copy( symbol );
        v->value = value;
        v->next = head;
        v->multiple = 0;
        head = v;
    }
    else if ( flag == VAR_APPEND )
    {
        v->value = list_append( v->value, value );
    }
    else if ( flag != VAR_DEFAULT )
    {
        list_free( v->value );
        v->value = value;
    }
    else
        list_free( value );

    /* Return (new) head of list. */
    return head;
}
コード例 #28
0
ファイル: object.c プロジェクト: TuZZiX/ROS_IDE_inc
OBJECT * object_new_range( char const * const string, int const size )
{
    ++strcount_in;

#ifdef BJAM_NO_MEM_CACHE
    {
        struct hash_item * const m = (struct hash_item *)BJAM_MALLOC( sizeof(
            struct hash_header ) + size + 1 );
        strtotal += size + 1;
        memcpy( m->data, string, size );
        m->data[ size ] = '\0';
        m->header.magic = OBJECT_MAGIC;
        return (OBJECT *)m->data;
    }
#else
    if ( !strhash.data )
        string_set_init( &strhash );
    return (OBJECT *)string_set_insert( &strhash, string, size );
#endif
}
コード例 #29
0
ファイル: object.c プロジェクト: 0xDEC0DE8/mcsema
static void string_set_resize(string_set *set)
{
    unsigned i;
    string_set new_set;
    new_set.num = set->num * 2;
    new_set.size = set->size;
    new_set.data = (struct hash_item * *)BJAM_MALLOC( sizeof( struct hash_item * ) * new_set.num );
    memset(new_set.data, 0, sizeof(struct hash_item *) * new_set.num);
    for ( i = 0; i < set->num; ++i )
    {
        while ( set->data[i] )
        {
            struct hash_item * temp = set->data[i];
            unsigned pos = temp->header.hash % new_set.num;
            set->data[i] = temp->header.next;
            temp->header.next = new_set.data[pos];
            new_set.data[pos] = temp;
        }
    }
    BJAM_FREE( set->data );
    *set = new_set;
}
コード例 #30
0
ファイル: lists.c プロジェクト: DieselPowerKOR/quakeslash
LIST *
list_new(
	LIST	*head,
	char	*string )
{
	LIST *l;

	if( DEBUG_LISTS )
	    printf( "list > %s <\n", string );

	/* Get list struct from freelist, if one available.  */
	/* Otherwise allocate. */
	/* If from freelist, must free string first */

	if( freelist )
	{
	    l = freelist;
	    freestr( l->string );
	    freelist = freelist->next;
	}
	else
	{
        l = (LIST *)BJAM_MALLOC( sizeof( LIST ) );
	}

	/* If first on chain, head points here. */
	/* If adding to chain, tack us on. */
	/* Tail must point to this new, last element. */

	if( !head ) head = l;
	else head->tail->next = l;
	head->tail = l;
	l->next = 0;

	l->string = string;

	return head;
}