コード例 #1
0
// MEMBER FUNCTION
void Trick::MemoryManager::reset_memory() {

    ALLOC_INFO_MAP::iterator pos;
    ALLOC_INFO* alloc_info;
    std::vector<void*> deletion_list;
    int ii, n_addrs;

    pthread_mutex_lock(&mm_mutex);
    for (pos=alloc_info_map.begin() ; pos!=alloc_info_map.end() ; pos++ ) {
        alloc_info = pos->second;

        if (alloc_info->stcl == TRICK_LOCAL) {
            deletion_list.push_back( alloc_info->start);
        }
    }
    pthread_mutex_unlock(&mm_mutex);

    n_addrs = deletion_list.size();
    for (ii = 0 ; ii < n_addrs ; ii ++) {
        delete_var( deletion_list[ii], false);
    }

    // reset counter to 100mil.  This (hopefully) ensures all alloc'ed ids are after external variables.
    alloc_info_map_counter = 100000000 ;
}
コード例 #2
0
ファイル: var.c プロジェクト: aharri/base
/* Delete global variable.
 */
void
Var_Deletei(const char *name, const char *ename)
{
	Var *v;
	uint32_t k;
	unsigned int slot;
	int idx;

	idx = classify_var(name, &ename, &k);
	if (idx != GLOBAL_INDEX) {
		Parse_Error(PARSE_FATAL,
		    "Trying to delete dynamic variable $%s", varnames[idx]);
		return;
	}
	slot = ohash_lookup_interval(&global_variables, name, ename, k);
	v = ohash_find(&global_variables, slot);

	if (v == NULL)
		return;

	if (checkEnvFirst && (v->flags & VAR_FROM_ENV))
		return;

	if (v->flags & VAR_FROM_CMD)
		return;

	ohash_remove(&global_variables, slot);
	delete_var(v);
}
コード例 #3
0
ファイル: config.c プロジェクト: MP2E/mupen64plus-ae
EXPORT m64p_error CALL ConfigSetDefaultString(m64p_handle ConfigSectionHandle, const char *ParamName, const char * ParamValue, const char *ParamHelp)
{
    config_section *section;
    config_var *var;

    /* check input conditions */
    if (!l_ConfigInit)
        return M64ERR_NOT_INIT;
    if (ConfigSectionHandle == NULL || ParamName == NULL || ParamValue == NULL)
        return M64ERR_INPUT_ASSERT;

    section = (config_section *) ConfigSectionHandle;
    if (section->magic != SECTION_MAGIC)
        return M64ERR_INPUT_INVALID;

    /* if this parameter already exists, then just return successfully */
    var = find_section_var(section, ParamName);
    if (var != NULL)
        return M64ERR_SUCCESS;

    /* otherwise create a new config_var object and add it to this section */
    var = config_var_create(ParamName, ParamHelp);
    if (var == NULL)
        return M64ERR_NO_MEMORY;
    var->type = M64TYPE_STRING;
    var->val.string = strdup(ParamValue);
    if (var->val.string == NULL)
    {
        delete_var(var);
        return M64ERR_NO_MEMORY;
    }
    append_var_to_section(section, var);

    return M64ERR_SUCCESS;
}
コード例 #4
0
ファイル: var.c プロジェクト: aharri/base
void
SymTable_Destroy(SymTable *ctxt)
{
	int i;

	for (i = 0; i < LOCAL_SIZE; i++)
		if (ctxt->locals[i] != NULL)
			delete_var(ctxt->locals[i]);
}
コード例 #5
0
ファイル: var.c プロジェクト: aharri/base
void
Var_End(void)
{
	Var *v;
	unsigned int i;

	for (v = ohash_first(&global_variables, &i); v != NULL;
	    v = ohash_next(&global_variables, &i))
		delete_var(v);
}
コード例 #6
0
ファイル: session-env.c プロジェクト: Distrotech/gnupg
/* Same as session_env_putenv but with name and value given as distict
   values.  */
gpg_error_t
session_env_setenv (session_env_t se, const char *name, const char *value)
{
  if (!name || !*name)
    return gpg_error (GPG_ERR_INV_VALUE);
  if (!value)
    return delete_var (se, name);
  else
    return update_var (se, name, strlen (name), value, 0);
}
コード例 #7
0
ファイル: subfield.c プロジェクト: BENGMN/soen490
static GEN
subfieldsall(GEN nf)
{
  pari_sp av = avma;
  long N, ld, i, v0;
  GEN G, pol, dg, LSB, NLSB;
  poldata PD;
  primedata S;
  blockdata B;

  /* much easier if nf is Galois (WSS) */
  G = galoisconj4(nf, NULL, 1);
  if (typ(G) != t_INT)
  {
    GEN L, S, p;
    long l;

    pol = get_nfpol(nf, &nf);
    L = lift_intern( galoissubfields(G, 0, varn(pol)) );
    l = lg(L);
    S = cgetg(l, t_VECSMALL);
    for (i=1; i<l; i++) S[i] = lg(gmael(L,i,1));
    p = vecsmall_indexsort(S);
    return gerepilecopy(av,  vecpermute(L, p));
  }

  subfields_poldata(nf, &PD);
  pol = PD.pol;

  v0 = varn(pol); N = degpol(pol);
  dg = divisors(utoipos(N)); ld = lg(dg)-1;
  if (DEBUGLEVEL) fprintferr("\n***** Entering subfields\n\npol = %Z\n",pol);

  LSB = _subfield(pol, pol_x[0]);
  if (ld > 2)
  {
    B.PD = &PD;
    B.S  = &S;
    B.N  = N;
    choose_prime(&S, PD.pol, PD.dis);
    for (i=2; i<ld; i++)
    {
      B.size  = itos(gel(dg,i));
      B.d = N / B.size;
      NLSB = subfields_of_given_degree(&B);
      if (NLSB) { LSB = concat(LSB, NLSB); gunclone(NLSB); }
    }
    (void)delete_var(); /* from choose_prime */
  }
  LSB = shallowconcat(LSB, _subfield(pol_x[0], pol));
  if (DEBUGLEVEL) fprintferr("\n***** Leaving subfields\n\n");
  return fix_var(gerepilecopy(av, LSB), v0);
}
コード例 #8
0
ファイル: subfield.c プロジェクト: BENGMN/soen490
GEN
subfields(GEN nf, GEN d0)
{
  pari_sp av = avma;
  long N, v0, d = itos(d0);
  GEN LSB, pol, G;
  poldata PD;
  primedata S;
  blockdata B;

  pol = get_nfpol(nf, &nf); /* in order to treat trivial cases */
  v0 = varn(pol); N = degpol(pol);
  if (d == N) return gerepilecopy(av, _subfield(pol, pol_x[v0]));
  if (d == 1) return gerepilecopy(av, _subfield(pol_x[v0], pol));
  if (d < 1 || d > N || N % d) return cgetg(1,t_VEC);

  /* much easier if nf is Galois (WSS) */
  G = galoisconj4(nf? nf: pol, NULL, 1);
  if (typ(G) != t_INT)
  { /* Bingo */
    GEN L = galoissubgroups(G), F;
    long k,i, l = lg(L), o = N/d;
    F = cgetg(l, t_VEC);
    k = 1;
    for (i=1; i<l; i++)
    {
      GEN H = gel(L,i);
      if (group_order(H) == o)
        gel(F,k++) = lift_intern(galoisfixedfield(G, gel(H,1), 0, v0));
    }
    setlg(F, k);
    return gerepilecopy(av, F);
  }

  subfields_poldata(nf? nf: pol, &PD);

  B.PD = &PD;
  B.S  = &S;
  B.N  = N;
  B.d  = d;
  B.size = N/d;

  choose_prime(&S, PD.pol, PD.dis);
  LSB = subfields_of_given_degree(&B);
  (void)delete_var(); /* from choose_prime */
  avma = av;
  if (!LSB) return cgetg(1, t_VEC);
  G = gcopy(LSB); gunclone(LSB);
  return fix_var(G, v0);
}
コード例 #9
0
ファイル: session-env.c プロジェクト: Distrotech/gnupg
/* Set or update an environment variable of the session environment.
   String is similar to the putval(3) function but it is reentrant and
   takes a copy.  In particular it exhibits this behaviour:

          <NAME>            Delete envvar NAME
          <KEY>=            Set envvar NAME to the empty string
          <KEY>=<VALUE>     Set envvar NAME to VALUE

   On success 0 is returned; on error an gpg-error code.  */
gpg_error_t
session_env_putenv (session_env_t se, const char *string)
{
  const char *s;

  if (!string || !*string)
    return gpg_error (GPG_ERR_INV_VALUE);
  s = strchr (string, '=');
  if (s == string)
    return gpg_error (GPG_ERR_INV_VALUE);
  if (!s)
    return delete_var (se, string);
  else
    return update_var (se, string, s - string, NULL, 0);
}
コード例 #10
0
ファイル: config.c プロジェクト: MP2E/mupen64plus-ae
static void delete_section(config_section *pSection)
{
    config_var *curr_var;

    if (pSection == NULL)
        return;

    curr_var = pSection->first_var;
    while (curr_var != NULL)
    {
        config_var *next_var = curr_var->next;
        delete_var(curr_var);
        curr_var = next_var;
    }

    free(pSection->name);
    free(pSection);
}
コード例 #11
0
ファイル: config.c プロジェクト: Gillou68310/mupen64plus-core
static config_section * section_deepcopy(config_section *orig_section)
{
    config_section *new_section;
    config_var *orig_var, *last_new_var;

    /* Input validation */
    if (orig_section == NULL)
        return NULL;

    /* create and copy section struct */
    new_section = config_section_create(orig_section->name);
    if (new_section == NULL)
        return NULL;

    /* create and copy all section variables */
    orig_var = orig_section->first_var;
    last_new_var = NULL;
    while (orig_var != NULL)
    {
        config_var *new_var = config_var_create(orig_var->name, orig_var->comment);
        if (new_var == NULL)
        {
            delete_section(new_section);
            return NULL;
        }

        new_var->type = orig_var->type;
        switch (orig_var->type)
        {
            case M64TYPE_INT:
            case M64TYPE_BOOL:
                new_var->val.integer = orig_var->val.integer;
                break;

            case M64TYPE_FLOAT:
                new_var->val.number = orig_var->val.number;
                break;

            case M64TYPE_STRING:
                if (orig_var->val.string != NULL)
                {
                    new_var->val.string = strdup(orig_var->val.string);
                    if (new_var->val.string == NULL)
                    {
                        delete_section(new_section);
                        delete_var(new_var);
                        return NULL;
                    }
                }
                else
                    new_var->val.string = NULL;

                break;
        }

        /* add the new variable to the new section */
        if (last_new_var == NULL)
            new_section->first_var = new_var;
        else
            last_new_var->next = new_var;
        last_new_var = new_var;
        /* advance variable pointer in original section variable list */
        orig_var = orig_var->next;
    }

    return new_section;
}
コード例 #12
0
ファイル: task2.c プロジェクト: liranr23/C
int main (int argc , char* argv[]){
  char dir[PATH_MAX];
  char BUFFER[LINE_LENGTH];
  int commands_counter = 0;
  linked_list *head = 0;
  var_list *var_head = 0;
  cmdLine *command;
  while(1){
    getcwd(dir, PATH_MAX);
    printf("The current dir is: %s \n", dir);
    fgets(BUFFER, LINE_LENGTH, stdin);
    command = parseCmdLines(BUFFER);
    if(strncmp(command->arguments[0], "!", 1) == 0){
      int place = atoi(&command->arguments[0][1]);
      if(place < 0 || place > commands_counter){
	perror("Error, out of bounds");
      }else{
	freeCmdLines(command);
	char *repeat = getCommand(head, place);
	command = parseCmdLines(repeat);
	strcpy(BUFFER, repeat);
      }
    }
    int i;
    for(i = 0; i<command->argCount; i++){
      if(strncmp(command->arguments[i], "$", 1) == 0){
	char *change = &command->arguments[i][1];
	char *fut_change = getArgu(var_head, change);
	replaceCmdArg(command, i, fut_change);
      }
    }
    if(strcmp(command->arguments[0], "set") == 0){
      var_list *newVar = malloc(sizeof(var_list));
      char *str1 = calloc(strlen(command->arguments[1])+1, sizeof(char));
      char *str2 = calloc(strlen(command->arguments[2])+1, sizeof(char));
      strcpy(str1, command->arguments[1]);
      strcpy(str2, command->arguments[2]);
      newVar->name = str1;
      newVar->value = str2;
      newVar->next = 0;
      var_head = setValue(var_head, newVar);
    }
    else if(strcmp(command->arguments[0], "delete") == 0){
      var_head = delete_var(var_head, command->arguments[1]);
    }
    else if((choose_action(command, head, var_head)) == 1){
      freeCmdLines(command);
      break;
    }
    linked_list *newNode = malloc(sizeof(linked_list));
    char *str = calloc(strlen(BUFFER)+1, sizeof(char));
    strcpy(str, BUFFER);
    newNode->command = str;
    newNode->next = 0;
    head = list_append(head, newNode);
    freeCmdLines(command);
    commands_counter++;
  }
  list_free(head);
  var_free(var_head);
  return 0;
}
コード例 #13
0
int             main(int argc, char **argv, char **env)
{
    char   buffer[200], *errp;
    size_t          sbuf;
    size_t          retcnt;
    var_store       value;
    var_store_ptr   value_list;
    numeric_ptr     nval;
    unsigned        compute,
           jj,
           yrE,
           monthE,
           dayE,
           yrI,
           monthI,
           dayI;
    struct tm      *times_E,
            *times_I;
    void           *parse_env;
    amort_sched     amortsched;
    financial_info  fininfo;

    /* check dynamic storage allocation
     */
    /*  	mtrace();	*/
    set_default(&fininfo);
    set_fin_vars();
    parse_env = init_parser(predefined_fin_vars,
                            '.',
                            ',',
                            trans_numeric,
                            numeric_ops,
                            negate_numeric,
                            free_numeric);

    npp  = fininfo.npp;
    ir   = fininfo.ir;
    pv   = fininfo.pv;
    pmt  = fininfo.pmt;
    fv   = fininfo.fv;
    CF   = fininfo.CF;
    PF   = fininfo.PF;
    disc = fininfo.disc;
    bep  = fininfo.bep;

    fininfo.prec = prec;

    printf("Single Letter Commands:\na -- amortization schedule\nc -- compute financial variable\nd -- delete variable\ns -- output financial variable status\nq -- quit\nv -- list defined variables\n");
    for (;;)
{
        printf("<>");
        retcnt = strlen(fgets(buffer, 190, stdin));
        if ( (retcnt == 2) && (strchr(sl_commands, buffer[0]) != NULL) )
        {
            if ( buffer[0] == 'q' ) break;
            amortsched.prec = fininfo.prec;
            switch ( buffer[0] )
            {
            case 'a':
                if ( amortsched.Eff_Date_jdn && amortsched.Init_Date_jdn )
                {
                    printf("Current Effective  year: %u\nCurrent Effective month: %u\nCurrent Effective   day: %u\nCurrent Initial    year: %u\nCurrent Initial   month: %u\nCurrent Initial     day %u\n",
                           amortsched.year_E,
                           amortsched.month_E,
                           amortsched.day_E,
                           amortsched.year_I,
                           amortsched.month_I,
                           amortsched.day_I);
                    printf("Change dates ? (y/n) ");
                    fgets(buffer, 190, stdin);
                }
                else
                {
                    buffer[0] = 'y';
                } /* endif */
                if ( buffer[0] == 'y' )
                {
                    printf("Enter Effective Date - year: ");
                    fgets(buffer, 190, stdin);
                    if ( (errp = parse_string(&value, buffer, parse_env)) == NULL )
                    {
                        nval = (numeric_ptr)(value.value);
                        switch ( nval->type )
                        {
                        case INT_TYPE:
                            amortsched.year_E = nval->value.int_value;
                            break;
                        case DBL_TYPE:
                            amortsched.year_E = (unsigned)(nval->value.dbl_value);
                            break;
                        } /* endswitch */
                        if ( !value.variable_name ) free_numeric(value.value);
                    }
                    else
                    {
                        parse_error(get_parse_error(parse_env), buffer, errp);
                    } /* endif */
                    printf("Enter Effective Date - month: ");
                    fgets(buffer, 190, stdin);
                    if ( (errp = parse_string(&value, buffer, parse_env)) == NULL )
                    {
                        nval = (numeric_ptr)(value.value);
                        switch ( nval->type )
                        {
                        case INT_TYPE:
                            amortsched.month_E = nval->value.int_value;
                            break;
                        case DBL_TYPE:
                            amortsched.month_E = (unsigned)(nval->value.dbl_value);
                            break;
                        } /* endswitch */
                        if ( !value.variable_name ) free_numeric(value.value);
                    }
                    else
                    {
                        parse_error(get_parse_error(parse_env), buffer, errp);
                    } /* endif */
                    printf("Enter Effective Date - day: ");
                    fgets(buffer, 190, stdin);
                    if ( (errp = parse_string(&value, buffer, parse_env)) == NULL )
                    {
                        nval = (numeric_ptr)(value.value);
                        switch ( nval->type )
                        {
                        case INT_TYPE:
                            amortsched.day_E = nval->value.int_value;
                            break;
                        case DBL_TYPE:
                            amortsched.day_E = (unsigned)(nval->value.dbl_value);
                            break;
                        } /* endswitch */
                        if ( !value.variable_name ) free_numeric(value.value);
                    }
                    else
                    {
                        parse_error(get_parse_error(parse_env), buffer, errp);
                    } /* endif */
                    printf("Enter Initial Payment Date - year: ");
                    fgets(buffer, 190, stdin);
                    if ( (errp = parse_string(&value, buffer, parse_env)) == NULL )
                    {
                        nval = (numeric_ptr)(value.value);
                        switch ( nval->type )
                        {
                        case INT_TYPE:
                            amortsched.year_I = nval->value.int_value;
                            break;
                        case DBL_TYPE:
                            amortsched.year_I = (unsigned)(nval->value.dbl_value);
                            break;
                        } /* endswitch */
                        if ( !value.variable_name ) free_numeric(value.value);
                    }
                    else
                    {
                        parse_error(get_parse_error(parse_env), buffer, errp);
                    } /* endif */
                    printf("Enter Initial Payment Date - month: ");
                    fgets(buffer, 190, stdin);
                    if ( (errp = parse_string(&value, buffer, parse_env)) == NULL )
                    {
                        nval = (numeric_ptr)(value.value);
                        switch ( nval->type )
                        {
                        case INT_TYPE:
                            amortsched.month_I = nval->value.int_value;
                            break;
                        case DBL_TYPE:
                            amortsched.month_I = (unsigned)(nval->value.dbl_value);
                            break;
                        } /* endswitch */
                        if ( !value.variable_name ) free_numeric(value.value);
                    }
                    else
                    {
                        parse_error(get_parse_error(parse_env), buffer, errp);
                    } /* endif */
                    printf("Enter Initial Payment Date - day: ");
                    fgets(buffer, 190, stdin);
                    if ( (errp = parse_string(&value, buffer, parse_env)) == NULL )
                    {
                        nval = (numeric_ptr)(value.value);
                        switch ( nval->type )
                        {
                        case INT_TYPE:
                            amortsched.day_I = nval->value.int_value;
                            break;
                        case DBL_TYPE:
                            amortsched.day_I = (unsigned)(nval->value.dbl_value);
                            break;
                        } /* endswitch */
                        if ( !value.variable_name ) free_numeric(value.value);
                    }
                    else
                    {
                        parse_error(get_parse_error(parse_env), buffer, errp);
                    } /* endif */
                } /* endif */

                amortsched.n     = npp;
                amortsched.nint  = ir;
                amortsched.pv    = pv;
                amortsched.pmt   = pmt;
                amortsched.fv    = fv;
                amortsched.CF    = CF;
                amortsched.PF    = PF;
                amortsched.disc  = disc;
                amortsched.bep   = bep;

                Amortization_init(&amortsched);
                amort_opt(&amortsched, parse_env);

                (void)Amortization_Schedule(&amortsched);
                prt_amortization_schedule(&amortsched, stdout);
                Amortization_free(&amortsched);
                break;
            case 'c':

                printf("Compute:\nn   - 1\ni   - 2\npv  - 3\npmt - 4\nfv  - 5\n1, 2, 3, 4 or 5: ");
                retcnt = strlen(fgets(buffer, 190, stdin));
                compute = buffer[0] - '0';

                switch ( compute-- )
                {
                case 0: /* all values specified nothing to compute */
                    break;
                case 1: /* compute number of periods, npp */
                    printf("Computing numbor of periods\n");
                    npp = fi_calc_num_payments(&fininfo);
                    printf("Number of Periods: %u\n", npp);
                    nval = (numeric_ptr)(predefined_fin_vars[compute].value);
                    nval->value.int_value = npp;
                    break;
                case 2: /* compute interest, ir */
                    printf("Computing interest rate\n");
                    ir = fi_calc_interest(&fininfo);
                    printf("Nominal Interest Rate: %.*f\n", prec, ir);
                    nval = (numeric_ptr)(predefined_fin_vars[compute].value);
                    nval->value.dbl_value = ir;
                    break;
                case 3: /* compute present value, pv */
                    printf("Computing Present Value\n");
                    pv = fi_calc_present_value(&fininfo);
                    printf("Present Value: %.*f\n", prec, pv);
                    nval = (numeric_ptr)(predefined_fin_vars[compute].value);
                    nval->value.dbl_value = pv;
                    break;
                case 4: /* compute periodic payment, pmt */
                    printf("Computing periodic payment\n");
                    pmt = fi_calc_payment(&fininfo);
                    printf("Periodic Payment: %.*f\n", prec, pmt);
                    nval = (numeric_ptr)(predefined_fin_vars[compute].value);
                    nval->value.dbl_value = pmt;
                    break;
                case 5: /* compute future value, fv */
                    printf("Computing Future Value\n");
                    fv = fi_calc_future_value(&fininfo);
                    printf("Future Value: %.*f\n", prec, fv);
                    nval = (numeric_ptr)(predefined_fin_vars[compute].value);
                    nval->value.dbl_value = fv;
                    break;
                default:    /* whoops */
                    break;
                } /* endswitch */
                break;
            case 'd':
                printf("Enter name of variable to delete: ");
                retcnt = strlen(fgets(buffer, 190, stdin));
                buffer[retcnt - 1] = EOS;
                if ( !delete_var(buffer, parse_env) )
                {
                    printf("Unable to delete specified variable\n");
                } /* endif */
                break;
            case 's':
                prt_status(&fininfo,
                           stdout);
                break;
            case 'v':
                for ( value_list = parser_get_vars(parse_env) ; value_list ; value_list = value_list->next_var )
                {
                    printf("%s: ", value_list->variable_name);
                    nval = (numeric_ptr)(value_list->value);
                    switch ( nval->type )
                    {
                    case INT_TYPE:
                        printf("%i\n", nval->value.int_value);
                        break;
                    case DBL_TYPE:
                        printf("%.*f\n", prec, nval->value.dbl_value);
                        break;
                    } /* endswitch */
                } /* endfor */
                break;
            } /* endswitch */
        }
        else if ( retcnt > 1 )
        {
            buffer[retcnt - 1] = EOS;

            if ( (errp = parse_string(&value, buffer, parse_env)) == NULL )
            {
                if ( value.variable_name ) printf("Variable: %s\n", value.variable_name);
                nval = (numeric_ptr)(value.value);
                switch ( nval->type )
                {
                case INT_TYPE:
                    printf("Evaluated Value: %i\n", nval->value.int_value);
                    break;
                case DBL_TYPE:
                    printf("Evaluated Value: %.*f\n", prec, nval->value.dbl_value);
                    break;
                } /* endswitch */
                if ( !value.variable_name ) free_numeric(value.value);
                chk_vars(predefined_fin_vars, fin_vars, fin_type, PREDEFINED_FIN_VARS);
                fininfo.npp = npp;
                fininfo.ir = ir;
                fininfo.pv = pv;
                fininfo.pmt = pmt;
                fininfo.fv = fv;
                fininfo.CF = CF;
                fininfo.PF = PF;
                fininfo.disc = disc;
                fininfo.bep = bep;
            }
            else
            {
                parse_error(get_parse_error(parse_env), buffer, errp);
            } /* endif */
        } /* endif */
    } /* endfor */
    exit_parser(parse_env);
    unset_fin_vars();
} /* main */