void pair_free(pair_t * pair) {
    if (pair) {
        if (pair->first)  object_free(pair->first);
        if (pair->second) object_free(pair->second);
        free(pair);
    }
}
Example #2
0
File: search.c Project: Kirija/XPIR
void call_bind_rule( OBJECT * target_, OBJECT * boundname_ )
{
    LIST * const bind_rule = var_get( root_module(), constant_BINDRULE );
    if ( !list_empty( bind_rule ) )
    {
        OBJECT * target = object_copy( target_ );
        OBJECT * boundname = object_copy( boundname_ );
        if ( boundname && target )
        {
            /* Prepare the argument list. */
            FRAME frame[ 1 ];
            frame_init( frame );

            /* First argument is the target name. */
            lol_add( frame->args, list_new( target ) );

            lol_add( frame->args, list_new( boundname ) );
            if ( lol_get( frame->args, 1 ) )
            {
                OBJECT * rulename = list_front( bind_rule );
                list_free( evaluate_rule( bindrule( rulename, root_module() ), rulename, frame ) );
            }

            /* Clean up */
            frame_free( frame );
        }
        else
        {
            if ( boundname )
                object_free( boundname );
            if ( target )
                object_free( target );
        }
    }
}
Example #3
0
RULE * lookup_rule( OBJECT * rulename, module_t * m, int local_only )
{
    RULE       rule;
    RULE     * r = &rule;
    RULE     * result = 0;
    module_t * original_module = m;

    r->name = rulename;

    if ( m->class_module )
        m = m->class_module;

    if ( m->rules && hashcheck( m->rules, (HASHDATA * *)&r ) )
        result = r;
    else if ( !local_only && m->imported_modules )
    {
        /* Try splitting the name into module and rule. */
        char *p = strchr( object_str( r->name ), '.' ) ;
        if ( p )
        {
            string buf[1];
            OBJECT * module_part;
            OBJECT * rule_part;
            string_new( buf );
            string_append_range( buf, object_str( r->name ), p );
            module_part = object_new( buf->value );
            rule_part = object_new( p + 1 );
            r->name = module_part;
            /* Now, r->name keeps the module name, and p+1 keeps the rule name.
             */
            if ( hashcheck( m->imported_modules, (HASHDATA * *)&r ) )
                result = lookup_rule( rule_part, bindmodule( module_part ), 1 );
            object_free( rule_part );
            object_free( module_part );
            string_free( buf );
        }
    }

    if ( result )
    {
        if ( local_only && !result->exported )
            result = 0;
        else
        {
            /* Lookup started in class module. We have found a rule in class
             * module, which is marked for execution in that module, or in some
             * instances. Mark it for execution in the instance where we started
             * the lookup.
             */
            int execute_in_class = ( result->module == m );
            int execute_in_some_instance = ( result->module->class_module &&
                ( result->module->class_module == m ) );
            if ( ( original_module != m ) &&
                ( execute_in_class || execute_in_some_instance ) )
                result->module = original_module;
        }
    }

    return result;
}
Example #4
0
static const char * cache_name( void )
{
    static OBJECT * name = 0;
    if ( !name )
    {
        OBJECT * hcachename = object_new( "HCACHEFILE" );
        LIST * hcachevar = var_get( hcachename );
        object_free( hcachename );

        if ( hcachevar )
        {
            TARGET * t = bindtarget( hcachevar->value );

            pushsettings( t->settings );
            /* Do not expect the cache file to be generated, so pass 0 as the
             * third argument to search. Expect the location to be specified via
             * LOCATE, so pass 0 as the fourth arugment.
             */
            object_free( t->boundname );
            t->boundname = search( t->name, &t->time, 0, 0 );
            popsettings( t->settings );

            if ( hcachevar )
                name = object_copy( t->boundname );
        }
    }
    return name ? object_str( name ) : 0;
}
Example #5
0
File: server.c Project: kaye64/gem
/**
 * Cleans up a client for exit
 */
void server_client_cleanup(server_t* server, client_t* client)
{
	ev_io_stop(server->io_loop, &client->io_read);
	list_erase(&server->client_list, &client->node);
	object_free(&client->read_buffer);
	object_free(&client->write_buffer);
	server->drop_cb(client, server);
	close(client->fd);
}
Example #6
0
void melee_free(scene *scene) {
    melee_local *local = scene_get_userdata(scene);
    game_player *player2 = game_state_get_player(scene->gs, 1);

    surface_free(&local->feh);
    surface_free(&local->bleh);
    surface_free(&local->select_hilight);
    for(int i = 0; i < 2; i++) {
        component_free(local->bar_power[i]);
        component_free(local->bar_agility[i]);
        component_free(local->bar_endurance[i]);
    }

    for(int i = 0; i < 10; i++) {
        object_free(&local->pilots[i]);
        object_free(&local->harportraits_player1[i]);
        object_free(&local->har_player1[i]);
        if (player2->selectable) {
            object_free(&local->harportraits_player2[i]);
            object_free(&local->har_player2[i]);
        }
    }

    object_free(&local->player2_placeholder);
    object_free(&local->unselected_har_portraits);
    object_free(&local->bigportrait1);
    if (player2->selectable) {
        object_free(&local->bigportrait2);
    }
    free(local);
}
Example #7
0
void sal_gui_entry_set(vm_t *vm)
{
    obj_t *obj = (obj_t *)sal_stack_pop(vm->stack); /* widget */
    obj_t *str = (obj_t *)sal_stack_pop(vm->stack); /* string */

    gtk_entry_set_text(
        GTK_ENTRY(pointer_get_value(obj)),
        string_get_value(str));

    object_free(obj);
    object_free(str);
}
Example #8
0
void mechlab_free(scene *scene) {
    mechlab_local *local = scene_get_userdata(scene);

    for(int i = 0; i < sizeof(local->bg_obj)/sizeof(object); i++) {
        object_free(&local->bg_obj[i]);
    }

    guiframe_free(local->frame);
    guiframe_free(local->dashboard);
    object_free(local->mech);
    free(local->mech);
    free(local);
}
Example #9
0
void paramui_free(t_paramui *x)
{
	jbox_free(&x->box);

	qelem_free(x->menu_qelem);
	x->menu_qelem = NULL;
	object_free(x->menu_items);
	object_detach_byptr(x, x->obj_parameter);
	if(x->layout_value)
		jtextlayout_destroy(x->layout_value);
	if(x->layout_unit)
		jtextlayout_destroy(x->layout_unit);
	object_free(x->obj_parameter);
}
void cmgrainlabs_free(t_cmgrainlabs *x) {
	dsp_free((t_pxobject *)x); // free memory allocated for the object
	object_free(x->buffer); // free the buffer reference
	object_free(x->w_buffer); // free the window buffer reference
	
	sysmem_freeptr(x->busy); // free memory allocated to the busy array
	sysmem_freeptr(x->grainpos); // free memory allocated to the grainpos array
	sysmem_freeptr(x->start); // free memory allocated to the start array
	sysmem_freeptr(x->t_length); // free memory allocated to the t_length array
	sysmem_freeptr(x->gr_length); // free memory allocated to the t_length array
	sysmem_freeptr(x->pan_left); // free memory allocated to the pan_left array
	sysmem_freeptr(x->pan_right); // free memory allocated to the pan_right array
	sysmem_freeptr(x->gain); // free memory allocated to the gain array
}
Example #11
0
/**
 * Opens a cache fs from memory (ie. client cached index + data files)
 */
void cache_open_fs(cache_t* cache, int num_indices, const char** index_files, const char* data_file)
{
	cache->num_indices = num_indices;

	codec_t* data_indices;
	codec_t data_blocks;
	int num_blocks;

	/* Read the data file into memory */
	FILE *data_fd = fopen(data_file, "r");
	fseek(data_fd, 0, SEEK_END);
	int data_size = ftell(data_fd);

	object_init(codec, &data_blocks);
	codec_resize(&data_blocks, data_size);
	num_blocks = data_size / DATA_BLOCK_SIZE;

	fseek(data_fd, 0, SEEK_SET);
	fread(data_blocks.data, DATA_BLOCK_SIZE, num_blocks, data_fd);
	fclose(data_fd);

	/* Read the indices into memory */
	cache->num_files = (int*)calloc(sizeof(int), num_indices);
	cache->files = (file_t**)malloc(sizeof(file_t*)*num_indices);
	data_indices = (codec_t*)malloc(sizeof(codec_t)*num_indices);
	for (int i = 0; i < num_indices; i++) {
		FILE* index_fd = fopen(index_files[i], "r");
		fseek(index_fd, 0, SEEK_END);
		int index_size = ftell(index_fd);

		object_init(codec, &data_indices[i]);
		codec_resize(&data_indices[i], index_size);
		cache->num_files[i] = index_size / INDEX_ENTRY_SIZE;
		cache->files[i] = (file_t*)malloc(sizeof(file_t)*cache->num_files[i]);

		fseek(index_fd, 0, SEEK_SET);
		fread(data_indices[i].data, INDEX_ENTRY_SIZE, cache->num_files[i], index_fd);
		fclose(index_fd);

		for (int x = 0; x < cache->num_files[i]; x++) {
			cache_fs_get(&data_indices[i], &data_blocks, i, x, &cache->files[i][x]);
		}

		object_free(&data_indices[i]);
	}

	object_free(&data_blocks);
}
Example #12
0
// Load an external for internal use
// returns true if successful
bool jamoma_loadextern(t_symbol *objectname, long argc, t_atom *argv, t_object **object)
{
	t_class 	*c = NULL;
	t_object	*p = NULL;
    
	c = class_findbyname(jps_box, objectname);
	if (!c) {
		p = (t_object *)newinstance(objectname, 0, NULL);
		if (p) {
			c = class_findbyname(jps_box, objectname);
			freeobject(p);
			p = NULL;
		}
		else {
			error("jamoma: could not load extern (%s) within the core", objectname->s_name);
			return false;
		}
	}
    
	if (*object != NULL) {			// if there was an object set previously, free it first...
		object_free(*object);
		*object = NULL;
	}
    
	*object = (t_object *)object_new_typed(CLASS_BOX, objectname, argc, argv);
	return true;
}
Example #13
0
file_info_t * file_info( OBJECT * filename )
{
    file_info_t *finfo = &filecache_finfo;
    int found;

    if ( !filecache_hash )
        filecache_hash = hashinit( sizeof( file_info_t ), "file_info" );

    filename = path_as_key( filename );

    finfo = (file_info_t *)hash_insert( filecache_hash, filename, &found );
    if ( !found )
    {
        /* printf( "file_info: %s\n", filename ); */
        finfo->name = object_copy( filename );
        finfo->is_file = 0;
        finfo->is_dir = 0;
        finfo->size = 0;
        finfo->time = 0;
        finfo->files = L0;
    }

    object_free( filename );

    return finfo;
}
Example #14
0
void pwd_done( void )
{
    if( pwd_result )
    {
        object_free( pwd_result );
    }
}
Example #15
0
static void delete_module_( void * xmodule, void * data )
{
    module_t *m = (module_t *)xmodule;

    delete_module( m );
    object_free( m->name );
}
Example #16
0
void path_add_key( OBJECT * path )
{
    struct path_key_entry * result;
    int found;

    if ( ! path_key_cache )
        path_key_cache = hashinit( sizeof( struct path_key_entry ), "path to key" );

    result = (struct path_key_entry *)hash_insert( path_key_cache, path, &found );
    if ( !found )
    {
        string buf[1];
        OBJECT * normalized;
        struct path_key_entry * nresult;
        result->path = path;
        string_copy( buf, object_str( path ) );
        normalize_path( buf );
        normalized = object_new( buf->value );
        string_free( buf );
        nresult = (struct path_key_entry *)hash_insert( path_key_cache, normalized, &found );
        if ( !found || nresult == result )
        {
            nresult->path = object_copy( normalized );
            nresult->key = object_copy( path );
        }
        object_free( normalized );
        if ( nresult != result )
        {
            result->path = object_copy( path );
            result->key = object_copy( nresult->key );
        }
    }
}
Example #17
0
void *jojo_new (t_symbol *s, long argc, t_atom *argv)
{
    t_jojo *x = NULL;
    
    if ((x = (t_jojo *)object_alloc (jojo_class))) {
    //
    ulong err = (x->error_ = JOJO_GOOD);
    
    try {
        new (x) t_jojo;
    }
    
    catch (...) {
        err = (x->error_ = JOJO_ERROR);
    }

    if (err) {
        object_free (x);
        x = NULL;
    }
    //
    }
    
    return x;
}
Example #18
0
file_info_t * file_info( OBJECT * filename )
{
    file_info_t *finfo = &filecache_finfo;

    if ( !filecache_hash )
        filecache_hash = hashinit( sizeof( file_info_t ), "file_info" );

    filename = path_as_key( filename );

    finfo->name = filename;
    finfo->is_file = 0;
    finfo->is_dir = 0;
    finfo->size = 0;
    finfo->time = 0;
    finfo->files = 0;
    if ( hashenter( filecache_hash, (HASHDATA**)&finfo ) )
    {
        /* printf( "file_info: %s\n", filename ); */
        finfo->name = object_copy( finfo->name );
    }

    object_free( filename );

    return finfo;
}
Example #19
0
static void time_enter( void * closure, OBJECT * target, int const found,
    timestamp const * const time )
{
    int item_found;
    BINDING * b;
    struct hash * const bindhash = (struct hash *)closure;

    target = path_as_key( target );

    b = (BINDING *)hash_insert( bindhash, target, &item_found );
    if ( !item_found )
    {
        b->name = object_copy( target );
        b->flags = 0;
    }

    timestamp_copy( &b->time, time );
    b->progress = found ? BIND_FOUND : BIND_SPOTTED;

    if ( DEBUG_BINDSCAN )
        out_printf( "time ( %s ) : %s\n", object_str( target ), time_progress[
            b->progress ] );

    object_free( target );
}
Example #20
0
int yyline()
{
    struct include * i = incp;

    if ( !incp )
        return EOF;

    /* Once we start reading from the input stream, we reset the include
     * insertion point so that the next include file becomes the head of the
     * list.
     */

    /* If there is more data in this line, return it. */
    if ( *i->string )
        return *i->string++;

    /* If we are reading from an internal string list, go to the next string. */
    if ( i->strings )
    {
        if ( *i->strings )
        {
            ++i->line;
            i->string = *(i->strings++);
            return *i->string++;
        }
    }
    else
    {
        /* If necessary, open the file. */
        if ( !i->file )
        {
            FILE * f = stdin;
            if ( strcmp( object_str( i->fname ), "-" ) && !( f = fopen( object_str( i->fname ), "r" ) ) )
                perror( object_str( i->fname ) );
            i->file = f;
        }

        /* If there is another line in this file, start it. */
        if ( i->file && fgets( i->buf, sizeof( i->buf ), i->file ) )
        {
            ++i->line;
            i->string = i->buf;
            return *i->string++;
        }
    }

    /* This include is done. Free it up and return EOF so yyparse() returns to
     * parse_file().
     */

    incp = i->next;

    /* Close file, free name. */
    if ( i->file && ( i->file != stdin ) )
        fclose( i->file );
    object_free( i->fname );
    BJAM_FREE( (char *)i );

    return EOF;
}
Example #21
0
/* Deletes all handles owned by owner with a context == 'context',
   (all handles if owner is -1, all contexts if context is -1)
   Traverses seperately to find each handle because the tree could
   be rearranged by deletion
*/
int r_handle_cleanup(struct handlenode *n,int owner,int context,
		     handle group) {
  struct handlenode ncopy;

  if ((!n) || (n==NIL)) return 0;

  if ( ((owner<0) || (owner==n->owner)) && 
       ((context)<0 || (n->context==context)) &&
       ((!group) || group==n->group)) {

    /* Same sequence as handle_free()
       Remove from the handle tree BEFORE deleting the object itself */

#ifdef DEBUG_MEMORY
     printf("   handle cleanup 0x%08X: grp 0x%08X own %d ctx %d\n",
	    n->id,group,owner,context);
#endif
     
    ncopy = *n;
    htree_delete(n);
    object_free(&ncopy);

    /* See if this node had any group members that need to be expunged */
    while (r_handle_cleanup(htree,-1,-1,ncopy.id));

    return 1;
  }

  if (r_handle_cleanup(n->left,owner,context,group)) return 1;
  if (r_handle_cleanup(n->right,owner,context,group)) return 1;
  return 0;
}
Example #22
0
static void import_base_rule( void * r_, void * d_ )
{
    RULE * r = (RULE *)r_;
    RULE * ir1;
    RULE * ir2;
    struct import_base_data * d = (struct import_base_data *)d_;
    string qualified_name[ 1 ];
    OBJECT * qname;

    string_new      ( qualified_name               );
    string_append   ( qualified_name, object_str( d->base_name ) );
    string_push_back( qualified_name, '.'          );
    string_append   ( qualified_name, object_str( r->name ) );

    qname = object_new( qualified_name->value );

    ir1 = import_rule( r, d->class_module, r->name );
    ir2 = import_rule( r, d->class_module, qname );

    object_free( qname );

    /* Copy 'exported' flag. */
    ir1->exported = ir2->exported = r->exported;

    /* If we are importing a class method, localize it. */
    if ( ( r->module == d->base_module ) || ( r->module->class_module &&
        ( r->module->class_module == d->base_module ) ) )
        ir1->module = ir2->module = d->class_module;

    string_free( qualified_name );
}
Example #23
0
void jit_field_sphere_free(t_jit_field_sphere *x)
{
	if(x->field) {
		object_free(x->field);
		x->field = NULL;
	}
}
Example #24
0
void declare_native_rule( const char * module, const char * rule, const char * * args,
                          LIST * (*f)( FRAME *, int ), int version )
{
    OBJECT * module_obj = 0;
    module_t * m;
    if ( module )
    {
        module_obj = object_new( module );
    }
    m = bindmodule( module_obj );
    if ( module_obj )
    {
        object_free( module_obj );
    }
    if (m->native_rules == 0) {
        m->native_rules = hashinit( sizeof( native_rule_t ), "native rules");
    }

    {
        native_rule_t n, *np = &n;
        n.name = object_new( rule );
        if (args)
        {
            n.arguments = args_new();
            lol_build( n.arguments->data, args );
        }
        else
        {
            n.arguments = 0;
        }
        n.procedure = function_builtin( f, 0 );
        n.version = version;
        hashenter(m->native_rules, (HASHDATA**)&np);
    }
}
Example #25
0
/* Deletes the handle, and if HFLAG_NFREE is not set it frees the object */
g_error handle_free(int owner,handle h) {
  struct handlenode *n = htree_find(h);
  struct handlenode ncopy;

#ifdef DEBUG_MEMORY
  printf("handle_free(%d,0x%08X): node=%p\n",owner,h,n);
#endif

  /* Already gone - don't complain */
  if (!h) return success;
  if (!n) return success;

  if (owner>=0 && n->owner != owner) 
    return mkerror(PG_ERRT_HANDLE,27);

  /* Remove from the handle tree BEFORE deleting the object itself */
  ncopy = *n;
  htree_delete(n);
  object_free(&ncopy);

  /* See if this node had any group members that need to be expunged */
  while (r_handle_cleanup(htree,-1,-1,ncopy.id));

  return success;
}
Example #26
0
void howbigisyourp_dump(t_howbigisyourp *x)
{
	t_an_item *item;
	t_atom a;
	t_linklist *list = linklist_new();
	linklist_flags(list, OBJ_FLAG_MEMORY);	// will use sysmem_freeptr on the objects

	// first item of list contains the totalnumberofobjects
	item = an_item_new(gensym("totalnumberofobjects"), 0);
	linklist_append(list, item);

	// copy the hash table to a linklist, and count the total number of object
	hashtab_funall(x->hash, (method)howbigisyourp_cp_to_linklist, list);

	// get the first item totalnumberofobjects which now contains the total number of objects
	item = linklist_getindex(list, 0);
	post("The total number of objects is %d", item->val);
	linklist_deleteindex(list, 0);	// remove it so we can proceed

	// sorting is nicer
	linklist_sort(list, linklist_ascending);

	// iterate through the linklist and output {name, instances} out the outlet.
	item = linklist_getindex(list, 0);
	while (item) {
		atom_setlong(&a, item->val);
		outlet_anything(x->out, item->name, 1, &a);
		linklist_next(list, item, (void **)&item);
	}

	// free the linklist items, the hashtab items are not removed).
	if (list)
		object_free(list);
}
Example #27
0
File: animation.c Project: roa/thea
bool
animation_animate(Animation animation, int frame, bool moved)
{
    bool finished = false;
    ObjectList local_list = animation->objlist;
    Coord  coord = local_list->coord;
    Object obj = object_init(local_list->objects[local_list->slide]);
    for (int j = 0; j < obj->size; ++j)
    {
        if (point_get_content(obj->object[j]) == '\n')
        {
            coord.y += 1;
            coord.x  = local_list->coord.x;
            continue;
        }
        mvprintw(coord.y, coord.x, "%c", point_get_content(obj->object[j]));
        coord.x += 1;
    }

    if ( moved && local_list->slide < local_list->used - 1)
        animation->objlist->slide += 1;
    else
    {
        animation->objlist->slide = 0;
        finished = true;
    }

    object_free(obj);

    return finished;
}
Example #28
0
// Load an external for internal use
t_max_err loadextern(t_symbol *objectname, long argc, t_atom *argv, t_object **object)
{
	t_class 	*c = NULL;
	t_object	*p = NULL;
	
	c = class_findbyname(_sym_box, objectname);
	if (!c) {
		p = (t_object*)newinstance(objectname, 0, NULL);
		if(p){
			c = class_findbyname(_sym_box, objectname);
			freeobject(p);
			p = NULL;
		}
		else{
			error("could not load extern (%s) within the oscar extension", objectname->s_name);
			return MAX_ERR_GENERIC;
		}
	}
	
	if (*object != NULL) {			// if there was an object set previously, free it first...
		object_free(*object);
		*object = NULL;
	}
	
	*object = (t_object*)object_new_typed(_sym_box, objectname, argc, argv);
	return MAX_ERR_NONE;
}
Example #29
0
void vs_free(scene *scene) {
    vs_local *local = scene_get_userdata(scene);
    game_player *player2 = game_state_get_player(scene->gs, 1);

    dialog_free(&local->quit_dialog);
    dialog_free(&local->too_pathetic_dialog);
    surface_free(&local->arena_select_bg);
    object_free(&local->player1_portrait);
    object_free(&local->player2_portrait);
    object_free(&local->player1_har);
    object_free(&local->player2_har);
    if (player2->selectable) {
        object_free(&local->arena_select);
    }
    free(local);
}
Example #30
0
int main(){
	Object *o = object_ini();
	char name[] = "TestingName";
	char desc[] = "TestingDesc";
	char *nameret, *descret;
	
	object_set_name(o, name);
	object_set_desc(o, desc);
	object_set_spaceid(o, 1);
	object_set_id(o, 2);
	object_pick(o);
	nameret = object_return_name(o);
	descret = object_return_desc(o);
	if (strcmp(nameret, name) == 0)
		printf("set and return name: OK\n");
	if (strcmp(descret, desc) == 0)
		printf("set and return desc: OK\n");
	if (object_return_spaceid(o) == 1)
		printf("set and return spaceid: OK\n");
	if (object_return_id(o) == 2)
		printf("set and return id: OK\n");
	if (object_return_has(o) == TRUE)
		printf("pick and return has: OK\n");
	object_drop(o);
	if (object_return_has(o) == FALSE)
		printf("drop: OK\n");
	object_free(o);
	return 1;
}