Пример #1
0
void free_obj_index( OBJ_INDEX_DATA *pObj )
{
    EXTRA_DESCR_DATA *pExtra;
    AFFECT_DATA *pAf;

    free_string( pObj->name );
    free_string( pObj->name2 );
    free_string( pObj->name3 );
    free_string( pObj->name4 );
    free_string( pObj->name5 );
    free_string( pObj->name6 );
    free_string( pObj->short_descr );
    free_string( pObj->description );
    free_string( pObj->item_description );
    free_string( pObj->ident_description );
	free_string( pObj->hidden_description );
    free_string( pObj->comments );

    for ( pAf = pObj->affected; pAf; pAf = pAf->next )
    {
        free_affect( pAf );
    }

    for ( pExtra = pObj->extra_descr; pExtra; pExtra = pExtra->next )
    {
        free_extra_descr( pExtra );
    }

    pObj->next              = obj_index_free;
    obj_index_free          = pObj;
    free_prog( pObj->progs );
    return;
}
Пример #2
0
void deallocate_program (program_t * progp)
{
    int i;

    debug(d_flag, ("free_prog: /%s\n", progp->filename));

    total_prog_block_size -= progp->total_size;
    total_num_prog_blocks -= 1;

    /* Free all function names. */
    for (i = 0; i < progp->num_functions_defined; i++)
        if (progp->function_table[i].funcname)
            free_string(progp->function_table[i].funcname);
    /* Free all strings */
    for (i = 0; i < progp->num_strings; i++)
        free_string(progp->strings[i]);
    /* Free all variable names */
    for (i = 0; i < progp->num_variables_defined; i++)
        free_string(progp->variable_table[i]);
    /* Free all inherited objects */
    for (i = 0; i < progp->num_inherited; i++){
    	program_t *tmp = progp->inherit[i].prog;
    	free_prog(&tmp); //don't want to mess up the prog pointer in the inherited ob
    }
    free_string(progp->filename);

    /*
     * We're going away for good, not just being swapped, so free up
     * line_number stuff.
     */
    if (progp->file_info)
        FREE(progp->file_info);

    FREE((char *) progp);
}
Пример #3
0
int main(){
    PROG test_prog = create_forward(160);
    add_node(test_prog, create_left(90));
    add_node(test_prog, create_forward(160));
    PROG rep_prog = create_forward(0.5);
    add_node(rep_prog, create_left(1));
    NODE* rep_node = create_repeat(360, rep_prog);
    add_node(test_prog, rep_node);
    print_logo(test_prog, 0, 2);
    //print_svg(test_prog);
    free_prog(test_prog);
    return 0;
}
Пример #4
0
/*
 * Decrement reference count for a program. If it is 0, then free the prgram.
 * The flag free_sub_strings tells if the propgram plus all used strings
 * should be freed. They normally are, except when objects are swapped,
 * as we want to be able to read the program in again from the swap area.
 * That means that strings are not swapped.
 */
void 
free_prog(struct program *progp)
{
    extern int total_program_size;
    int i;
    
    if (d_flag & DEBUG_PROG_REF)
	(void)printf("free_prog: %s\n", progp->name);
    if (!progp->ref || --progp->ref > 0)
	return;
    if (progp->ref < 0)
	fatal("Negative ref count for prog ref.\n");

    if (progp == prog_list)
	prog_list = progp->next_all;
    
    progp->prev_all->next_all = progp->next_all;
    progp->next_all->prev_all = progp->prev_all;
    if (progp->next_all == progp)
	prog_list = 0;
    
    total_program_size -= progp->exec_size;
    
    total_prog_block_size -= progp->total_size;
    total_num_prog_blocks--;
    
    /* Free all function names. */
    for (i=0; i < (int)progp->num_functions; i++)
	if (progp->functions[i].name)
	    free_sstring(progp->functions[i].name);

    /* Free all variable names */
    for (i=0; i < (int)progp->num_variables; i++)
	free_sstring(progp->variable_names[i].name);

    /* Free all inherited objects */
    for (i=0; i < (int)progp->num_inherited - 1; i++)
    {
	free_prog(progp->inherit[i].prog);
	free_sstring(progp->inherit[i].name);
    }
    free_sstring(progp->inherit[i].name);
    free(progp->name);
    free((char *)progp->program);
    if (progp->line_numbers != 0)
	free((char *)progp->line_numbers);
    free((char *)progp);
}
void deallocate_program P1(struct program *, progp)
{
    int i;

#ifdef DEBUG
    if (d_flag)
	printf("free_prog: %s\n", progp->name);
#endif
    
    total_prog_block_size -= progp->p.i.total_size;
    total_num_prog_blocks -= 1;

    /* Free all function names. */
    for (i = 0; i < (int) progp->p.i.num_functions; i++)
	if (progp->p.i.functions[i].name)
	    free_string(progp->p.i.functions[i].name);
    /* Free all strings */
    for (i = 0; i < (int) progp->p.i.num_strings; i++)
	free_string(progp->p.i.strings[i]);
    /* Free all variable names */
    for (i = 0; i < (int) progp->p.i.num_variables; i++)
	free_string(progp->p.i.variable_names[i].name);
    /* Free all inherited objects */
    for (i = 0; i < (int) progp->p.i.num_inherited; i++)
	free_prog(progp->p.i.inherit[i].prog, 1);
    free_string(progp->name);

    /*
     * We're going away for good, not just being swapped, so free up
     * line_number stuff.
     */
    if (progp->p.i.line_swap_index != -1)
	remove_line_swap(progp);
    if (progp->p.i.file_info)
	FREE(progp->p.i.file_info);
    
#ifdef LPC_TO_C
    /*
     * more stuff for compiled objects; will swapping a compiled object
     * crash?  -Beek
     */
    if (!progp->p.i.program_size)
	FREE(progp->p.i.program);
#endif
    FREE((char *) progp);
}
Пример #6
0
/*
 * Swap out an object. Only the program is swapped, not the 'object_t'.
 *
 * marion - the swap seems to corrupt the function table
 */
int swap(object_t *  ob)
{
    /* the simuls[] table uses pointers to the functions so the simul_efun
     * program cannot be relocated.  locate_in() could be changed to
     * correct this or simuls[] could use offsets, but it doesn't seem
     * worth it just to get the simul_efun object to swap.  Maybe later.
     *
     * Ditto the master object and master_applies[].  Mudlibs that have
     * a period TIME_TO_SWAP between successive master applies must be
     * extremely rare ...
     */
    if (ob == simul_efun_ob || ob == master_ob) return 0;
    if (ob->flags & O_DESTRUCTED)
	return 0;
    debug(d_flag, ("Swap object /%s (ref %d)", ob->name, ob->ref));

    if (ob->prog->line_info)
	swap_line_numbers(ob->prog);	/* not always done before we get here */
    if ((ob->flags & O_HEART_BEAT) || (ob->flags & O_CLONE)) {
	debug(d_flag, ("  object not swapped - heart beat or cloned."));
	return 0;
    }
    if (ob->prog->ref > 1 || ob->interactive) {
	debug(d_flag, ("  object not swapped - inherited or interactive or in apply_low() cache."));

	return 0;
    }
    if (ob->prog->func_ref > 0) {
	debug(d_flag, ("  object not swapped - referenced by functions."));

	return 0;
    }
    locate_out(ob->prog);	/* relocate the internal pointers */
    if (swap_out((char *) ob->prog, ob->prog->total_size, (int *) &ob->swap_num)) {
	num_swapped++;
	free_prog(ob->prog, 0);	/* Do not free the strings */
	ob->prog = 0;
	ob->flags |= O_SWAPPED;
	return 1;
    } else {
	locate_in(ob->prog);
	return 0;
    }
}
Пример #7
0
void free_mob_index( MOB_INDEX_DATA *pMob )
{
    free_string( pMob->player_name );
    free_string( pMob->name2 );
    free_string( pMob->name3 );
    free_string( pMob->name4 );
    free_string( pMob->name5 );
    free_string( pMob->name6 );
    free_string( pMob->short_descr );
    free_string( pMob->long_descr );
    free_string( pMob->description );
    free_prog( pMob->progs );

    free_shop( pMob->pShop );
    free_repair( pMob->pRepair );
    free_bank( pMob->pBank );
    pMob->pShop   = NULL;
    pMob->pBank   = NULL;
    pMob->pRepair = NULL;

    pMob->next              = mob_index_free;
    mob_index_free          = pMob;
    return;
}
Пример #8
0
/*-------------------------------------------------------------------------*/
void
invalidate_simul_efuns (void)

/* Invalidate all simul_efun information - usually because the
 * object is destructed.
 */

{
    simul_efun_table_t *entry;
    ident_t            *id;
    int                 i, j;

    /* Invalidate the simul_efun table */
    for (entry = simul_efun_table, i = SIZE_SEFUN_TABLE; --i >= 0; )
    {
        entry->funstart = NULL;
        entry++;
    }

    /* Remove all sefun shadows for efuns.
     * If they are listed in the table, move then into the inactive list.
     */
    for (id = all_efuns; id; id = id->next_all)
    {
        j = id->u.global.sim_efun;
        if ((size_t)j < SIZE_SEFUN_TABLE)
        {
            simul_efunp[j].offset.next_sefun = all_discarded_simul_efun;
            all_discarded_simul_efun = j;
        }
        id->u.global.sim_efun = I_GLOBAL_SEFUN_OTHER;
    }

    /* Mark all simulefun identifier entries as non-existing
     * and move them into the inactive list.
     */
    while (all_simul_efuns != NULL)
    {
        id = all_simul_efuns;
        j = id->u.global.sim_efun;

        all_simul_efuns = all_simul_efuns->next_all;

        simul_efunp[j].offset.next_sefun = all_discarded_simul_efun;
        all_discarded_simul_efun = j;

        free_shared_identifier(id);
    }

    /* Free the old program and vector, if any */
    if (simul_efun_program)
    {
        free_prog(simul_efun_program, MY_TRUE);
        simul_efun_program = NULL;
    }

    if (simul_efun_vector)
    {
        free_array(simul_efun_vector);
        simul_efun_vector = NULL;
    }
} /* invalidate_simul_efuns() */
Пример #9
0
void replace_programs()
{
    replace_ob_t *r_ob, *r_next;
    int i, num_fewer, offset;
    svalue_t *svp;

#ifdef DEBUG
    if (d_flag)
	debug_message("start of replace_programs\n");
#endif
    for (r_ob = obj_list_replace; r_ob; r_ob = r_next) {
	program_t *old_prog;

	if (r_ob->ob->flags & O_SWAPPED)
	    load_ob_from_swap(r_ob->ob);
	num_fewer = r_ob->ob->prog->num_variables - r_ob->new_prog->num_variables;
#ifdef DEBUG
	if (d_flag)
	    debug_message("%d less variables\n", num_fewer);
#endif
	tot_alloc_object_size -= num_fewer * sizeof(svalue_t[1]);
	if ((offset = r_ob->var_offset)) {
	    svp = r_ob->ob->variables;
	    /* move our variables up to the top */
	    for (i = 0; i < r_ob->new_prog->num_variables; i++) {
		free_svalue(svp, "replace_programs");
		*svp = *(svp + offset);
		*(svp + offset) = const0n;
		svp++;
	    }
	    /* free the rest */
	    for (i = 0; i < num_fewer; i++) {
		free_svalue(svp, "replace_programs");
		*svp++ = const0n;
	    }
	} else {
	    /* We just need to remove the last num_fewer variables */
	    svp = &r_ob->ob->variables[r_ob->new_prog->num_variables];
	    for (i = 0; i < num_fewer; i++) {
		free_svalue(svp, "replace_programs");
		*svp++ = const0n;
	    }
	}
#ifdef DEBUG
	if (d_flag)
	    debug_message("freed.\n");
#endif
	r_ob->new_prog->ref++;
	old_prog = r_ob->ob->prog;
	r_ob->ob->prog = r_ob->new_prog;
	r_next = r_ob->next;
	free_prog(old_prog, 1);
#ifdef DEBUG
	if (d_flag)
	    debug_message("program freed.\n");
#endif
#ifndef NO_SHADOWS
	if (r_ob->ob->shadowing) {
	    /*
	     * The master couldn't decide if it's a legal shadowing before
	     * the program was actually replaced. It is possible that the
	     * blueprint to the replacing program is already destructed, and
	     * it's source changed. On the other hand, if we called the
	     * master now, all kind of volatile data structures could result,
	     * even new entries for obj_list_replace. This would eventually
	     * require to reference it, and all the lrpp's , in
	     * check_a_lot_ref_counts() and garbage_collection() . Being able
	     * to use replace_program() in shadows is hardly worth this
	     * effort. Thus, we simply stop the shadowing.
	     */
	    r_ob->ob->shadowing->shadowed = r_ob->ob->shadowed;
	    if (r_ob->ob->shadowed) {
		r_ob->ob->shadowed->shadowing = r_ob->ob->shadowing;
		r_ob->ob->shadowed = 0;
	    }
	    r_ob->ob->shadowing = 0;
	}
#endif
	FREE((char *) r_ob);
    }
    obj_list_replace = (replace_ob_t *) 0;
#ifdef DEBUG
    if (d_flag)
	debug_message("end of replace_programs\n");
#endif
}