Beispiel #1
0
int Athena_ParseEngineMessage(struct Athena_MessageList *to, const char *(*read_function)(void *arg, uint32_t len), void(*free_function)(void *arg, const char *z), void *arg){
    /* end is the ending position in msg, as will be passed to TurboJSON */
    const char *const head = read_function(arg, 4), *msg = NULL, *end = NULL;

    if(!head)
        return -1;

    if(memcmp(head, "HTTP", 4)==0 || memcmp(head, "http", 4)==0){
        return -3; /* Not implemented yet. */
    }
    else if(memcmp(head, "Athe", 4)==0){
        const char *const head2 = read_function(arg, 10);
        char c;
        int x = 0;
        if(!head2 || memcmp(head2, "na Message", 10)!=0)
            return -8; /* Bad Athena header. */
        
        if(free_function){
            free_function(arg, head);
            free_function(arg, head2);
        }

        do{ /* Burn through the rest of the line. Normally this will be a single space, to pad the first line to 16 bytes. */
            const char *ch = read_function(arg, 1);
            if(!ch || ++x > 33)
                return -8;
            c = ch[0];
            if(free_function)
                free_function(arg, ch);
        }while(c!='\n');
    }
    
    return msg!=end;
}
Beispiel #2
0
int		sudoki_bi()
{
  char		***tab;
  t_list	*list;
  t_present	*present;
  int		i;

  if ((tab = get_all_tab()) == NULL)
    return (-1);
  i = -1;
  while (++i < my_tablen(tab))
    {
      if ((present = get_present(tab[i])) == NULL ||
	  (list = get_list(tab[i])) == NULL)
	return (-1);
      filler(tab[i], list, present);
      if (check_valid(tab[i]) == 1)
        error_aff_tab();
      else
        aff_table(tab[i]);
      if (i < (my_tablen(tab) - 1))
        write(1, "####################\n", 21);
      free_function_bis(list, present);
    }
  free_function(tab);
  return (0);
}
Beispiel #3
0
rpc_mempool::~rpc_mempool()
{
#if MEMPOOL_DEBUG
    SMBLogInfo("destroying rpc_mempool at %p", ASL_LEVEL_DEBUG, this);
#endif
    std::for_each(ptrs.begin(), ptrs.end(), free_function());
}
/*
 * Frees data stores in priority queue using free function.
 */
void free_priority_queue_data( priority_queue **pq, void (*free_function)( void * ) )
{
        int i;
        for ( i = 1; i <= (*pq)->heap_size; i++ )
        {
                free_function( (*pq)->heap_array[ i ] );
        }
        (*pq)->heap_size = 0;
}
Beispiel #5
0
/*
 * Destroy all the elements blow us in the tree
 * only useful as part of a complete tree destroy.
 */
static void rb_destroy(struct rbnode *x,void (*free_function)(void *)) {
  if (x!=RBNULL) {
    if (x->left!=RBNULL)
      rb_destroy(x->left,free_function);
    if (x->right!=RBNULL)
      rb_destroy(x->right,free_function);
    if (free_function!=NULL)
      free_function(x->object);
    rb_free(x);
  }
}
Beispiel #6
0
struct task_s *
run (struct task_s *task)
{
  switch ( task->t )
    {
    case TASK_EVAL:
      return eval (task->d.task_eval_v.expr, task->d.task_eval_v.cont);
    case TASK_APP1:
      {
	if ( task->d.task_app1_v.erator->t == FUNCTION_D )
	  {
	    struct function_s *val = new_function ();
	    struct task_s *ntask;

	    val->t = FUNCTION_D1;
	    init_ptr (&val->d.function_d1_v, task->d.task_app1_v.rand);
	    ntask = invoke (task->d.task_app1_v.cont, val);
	    free_function (val);
	    return ntask;
	  }
	else
	  {
	    struct continuation_s *ncont = new_continuation ();
	    struct task_s *ntask;

	    ncont->t = CONTINUATION_APP;
	    init_ptr (&ncont->d.continuation_app_v.erator,
		      task->d.task_app1_v.erator);
	    init_ptr (&ncont->d.continuation_app_v.cont,
		      task->d.task_app1_v.cont);
	    ntask = eval (task->d.task_app1_v.rand, ncont);
	    free_continuation (ncont);
	    return ntask;
	  }
      }
    case TASK_APP:
      return apply (task->d.task_app_v.erator, task->d.task_app_v.erand,
		    task->d.task_app_v.cont);
    case TASK_INVOKE:
      return invoke (task->d.task_invoke_v.cont, task->d.task_invoke_v.val);
    case TASK_FINAL:
      /* Should not happen */;
    }
  fprintf (stderr, "INTERNAL ERROR: run() surprised!\n");
  return NULL;
}
Beispiel #7
0
void bas_release_object(Object* object)
{
    object->ref_count --;
    if (object->ref_count == 0)
    {
        if (object->type == kTypeArray)
            free_array((Array*)object);
        else if (object->type == kTypeFunction)
            free_function((Function*)object);
        else if (object->type == kTypeString)
            free_string((String*)object);
        else
        {
            ASSERT(0); // object destructor not implemented!
        }
    }

    mem_free(object);
}
 void operator()(T* object) {
   if (object) {
     free_function(object);
   }
 }
Beispiel #9
0
int main() {
  printf("%d\n", free_function(36));
  return 0;
}
Beispiel #10
0
struct expression_s *
parse (FILE *input)
{
  int ch;
  do {
    ch = getc (input);
    if ( ch == '#' )
      while ( ch != '\n' && ch != EOF )
	ch = getc (input);
  } while ( ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' );
  if ( ch == '`' )
    {
      struct expression_s *rator = parse (input);
      struct expression_s *rand = parse (input);
      struct expression_s *expr = new_expression ();

      expr->t = EXPRESSION_APPLICATION;
      init_ptr (&expr->d.expression_application_v.rator, rator);
      init_ptr (&expr->d.expression_application_v.rand, rand);
#if 0  /* Harmless but not necessary */
      free_expression (rator);
      free_expression (rand);
#endif
      return expr;
    }
  else if ( ch == 'i' || ch == 'I' )
    {
      struct function_s *fun = new_function ();
      struct expression_s *expr = new_expression ();

      fun->t = FUNCTION_I;
      expr->t = EXPRESSION_FUNCTION;
      init_ptr (&expr->d.expression_function_v, fun);
#if 0  /* Harmless but not necessary */
      free_function (fun);
#endif
      return expr;
    }
  else if ( ch == 'k' || ch == 'K' )
    {
      struct function_s *fun = new_function ();
      struct expression_s *expr = new_expression ();

      fun->t = FUNCTION_K;
      expr->t = EXPRESSION_FUNCTION;
      init_ptr (&expr->d.expression_function_v, fun);
#if 0  /* Harmless but not necessary */
      free_function (fun);
#endif
      return expr;
    }
  else if ( ch == 's' || ch == 'S' )
    {
      struct function_s *fun = new_function ();
      struct expression_s *expr = new_expression ();

      fun->t = FUNCTION_S;
      expr->t = EXPRESSION_FUNCTION;
      init_ptr (&expr->d.expression_function_v, fun);
#if 0  /* Harmless but not necessary */
      free_function (fun);
#endif
      return expr;
    }
  else if ( ch == 'v' || ch == 'V' )
    {
      struct function_s *fun = new_function ();
      struct expression_s *expr = new_expression ();

      fun->t = FUNCTION_V;
      expr->t = EXPRESSION_FUNCTION;
      init_ptr (&expr->d.expression_function_v, fun);
#if 0  /* Harmless but not necessary */
      free_function (fun);
#endif
      return expr;
    }
  else if ( ch == 'd' || ch == 'D' )
    {
      struct function_s *fun = new_function ();
      struct expression_s *expr = new_expression ();

      fun->t = FUNCTION_D;
      expr->t = EXPRESSION_FUNCTION;
      init_ptr (&expr->d.expression_function_v, fun);
#if 0  /* Harmless but not necessary */
      free_function (fun);
#endif
      return expr;
    }
  else if ( ch == 'e' || ch == 'E' )
    {
      struct function_s *fun = new_function ();
      struct expression_s *expr = new_expression ();

      fun->t = FUNCTION_E;
      expr->t = EXPRESSION_FUNCTION;
      init_ptr (&expr->d.expression_function_v, fun);
#if 0  /* Harmless but not necessary */
      free_function (fun);
#endif
      return expr;
    }
  else if ( ch == 'p' || ch == 'P' )
    {
      struct function_s *fun = new_function ();
      struct expression_s *expr = new_expression ();

      fun->t = FUNCTION_P;
      expr->t = EXPRESSION_FUNCTION;
      init_ptr (&expr->d.expression_function_v, fun);
#if 0  /* Harmless but not necessary */
      free_function (fun);
#endif
      return expr;
    }
  else if ( ch == 'f' || ch == 'F' )
    {
      struct function_s *fun = new_function ();
      struct expression_s *expr = new_expression ();

      fun->t = FUNCTION_F;
      expr->t = EXPRESSION_FUNCTION;
      init_ptr (&expr->d.expression_function_v, fun);
#if 0  /* Harmless but not necessary */
      free_function (fun);
#endif
      return expr;
    }
  else if ( ch == 'r' )
    {
      struct function_s *fun = new_function ();
      struct expression_s *expr = new_expression ();

      fun->t = FUNCTION_DOT;
      fun->d.function_dot_v = '\n';
      expr->t = EXPRESSION_FUNCTION;
      init_ptr (&expr->d.expression_function_v, fun);
#if 0  /* Harmless but not necessary */
      free_function (fun);
#endif
      return expr;
    }
  else if ( ch == '.' )
    {
      struct function_s *fun = new_function ();
      struct expression_s *expr = new_expression ();
      int ch2;

      fun->t = FUNCTION_DOT;
      ch2 = getc (input);
      if ( ch2 == EOF )
	goto ueof;
      fun->d.function_dot_v = ch2;
      expr->t = EXPRESSION_FUNCTION;
      init_ptr (&expr->d.expression_function_v, fun);
#if 0  /* Harmless but not necessary */
      free_function (fun);
#endif
      return expr;
    }
  else if ( ch == '@' )
    {
      struct function_s *fun = new_function ();
      struct expression_s *expr = new_expression ();

      fun->t = FUNCTION_AT;
      expr->t = EXPRESSION_FUNCTION;
      init_ptr (&expr->d.expression_function_v, fun);
#if 0  /* Harmless but not necessary */
      free_function (fun);
#endif
      return expr;
    }
  else if ( ch == '?' )
    {
      struct function_s *fun = new_function ();
      struct expression_s *expr = new_expression ();
      int ch2;

      fun->t = FUNCTION_QUES;
      ch2 = getc (input);
      if ( ch2 == EOF )
	goto ueof;
      fun->d.function_ques_v = ch2;
      expr->t = EXPRESSION_FUNCTION;
      init_ptr (&expr->d.expression_function_v, fun);
#if 0  /* Harmless but not necessary */
      free_function (fun);
#endif
      return expr;
    }
  else if ( ch == '|' )
    {
      struct function_s *fun = new_function ();
      struct expression_s *expr = new_expression ();

      fun->t = FUNCTION_PIPE;
      expr->t = EXPRESSION_FUNCTION;
      init_ptr (&expr->d.expression_function_v, fun);
#if 0  /* Harmless but not necessary */
      free_function (fun);
#endif
      return expr;
    }
  else if ( ch == EOF )
    {
    ueof:
      fprintf (stderr, "Unexpected end of file\n");
      exit (1);
    }
  else
    {
      fprintf (stderr, "Character not recognized: %c\n", ch);
      exit (1);
    }
  return NULL;
}
Beispiel #11
0
struct task_s *
apply (struct function_s *rator, struct function_s *rand,
       struct continuation_s *cont)
{
  switch ( rator->t )
    {
    case FUNCTION_I:
      return invoke (cont, rand);
    case FUNCTION_DOT:
      putchar (rator->d.function_dot_v);
      return invoke (cont, rand);
    case FUNCTION_K1:
      return invoke (cont, rator->d.function_k1_v);
    case FUNCTION_K:
      {
	struct function_s *val = new_function ();
	struct task_s *task;

	val->t = FUNCTION_K1;
	init_ptr (&val->d.function_k1_v, rand);
	task = invoke (cont, val);
	free_function (val);
	return task;
      }
    case FUNCTION_S2:
      {
	struct expression_s *e_x = new_expression ();
	struct expression_s *e_y = new_expression ();
	struct expression_s *e_z = new_expression ();
	struct expression_s *e1 = new_expression ();
	struct expression_s *e2 = new_expression ();
	struct expression_s *e = new_expression ();
	struct task_s *task = new_task ();

	e_x->t = EXPRESSION_FUNCTION;
	init_ptr (&e_x->d.expression_function_v, rator->d.function_s2_v.x);
	e_y->t = EXPRESSION_FUNCTION;
	init_ptr (&e_y->d.expression_function_v, rator->d.function_s2_v.y);
	e_z->t = EXPRESSION_FUNCTION;
	init_ptr (&e_z->d.expression_function_v, rand);
	e1->t = EXPRESSION_APPLICATION;
	init_ptr (&e1->d.expression_application_v.rator, e_x);
	init_ptr (&e1->d.expression_application_v.rand, e_z);
	e2->t = EXPRESSION_APPLICATION;
	init_ptr (&e2->d.expression_application_v.rator, e_y);
	init_ptr (&e2->d.expression_application_v.rand, e_z);
	e->t = EXPRESSION_APPLICATION;
	init_ptr (&e->d.expression_application_v.rator, e1);
	init_ptr (&e->d.expression_application_v.rand, e2);
	task->t = TASK_EVAL;
	init_ptr (&task->d.task_eval_v.expr, e);
	init_ptr (&task->d.task_eval_v.cont, cont);
#if 0  /* Harmless but not necessary */
	free_expression (e_x);
	free_expression (e_y);
	free_expression (e_z);
	free_expression (e1);
	free_expression (e2);
	free_expression (e);
#endif
	return task;
      }
    case FUNCTION_S1:
      {
	struct function_s *val = new_function ();
	struct task_s *task;

	val->t = FUNCTION_S2;
	init_ptr (&val->d.function_s2_v.x, rator->d.function_s1_v);
	init_ptr (&val->d.function_s2_v.y, rand);
	task = invoke (cont, val);
	free_function (val);
	return task;
      }
    case FUNCTION_S:
      {
	struct function_s *val = new_function ();
	struct task_s *task;

	val->t = FUNCTION_S1;
	init_ptr (&val->d.function_s1_v, rand);
	task = invoke (cont, val);
	free_function (val);
	return task;
      }
    case FUNCTION_V:
      return invoke (cont, rator);
    case FUNCTION_D1:
      {
	struct continuation_s *ncont = new_continuation ();
	struct task_s *task = new_task ();

	ncont->t = CONTINUATION_DEL;
	init_ptr (&ncont->d.continuation_del_v.erand, rand);
	init_ptr (&ncont->d.continuation_del_v.cont, cont);
	task->t = TASK_EVAL;
	init_ptr (&task->d.task_eval_v.expr, rator->d.function_d1_v);
	init_ptr (&task->d.task_eval_v.cont, ncont);
#if 0  /* Harmless but not necessary */
	free_continuation (ncont);
#endif
	return task;
      }
    case FUNCTION_D:
      {
	struct expression_s *promise = new_expression ();
	struct function_s *val = new_function ();
	struct task_s *task;

	promise->t = EXPRESSION_FUNCTION;
	init_ptr (&promise->d.expression_function_v, rand);
	val->t = FUNCTION_D1;
	init_ptr (&val->d.function_d1_v, promise);
	task = invoke (cont, val);
	free_continuation (cont);
	free_function (val);
	return task;
      }
    case FUNCTION_CONT:
      return invoke (rator->d.function_cont_v, rand);
    case FUNCTION_DCONT:
      {
	struct function_s *val = new_function ();
	struct task_s *task = new_task ();
	struct continuation_s *ncont = new_continuation ();

	push_cont (cont);
	val->t = FUNCTION_CONT;
	init_ptr (&val->d.function_cont_v, rator->d.function_cont_v);
	task->t = TASK_APP;
	ncont->t = CONTINUATION_ABORT;
	init_ptr (&task->d.task_app_v.erator, val);
	init_ptr (&task->d.task_app_v.erand, rand);
	init_ptr (&task->d.task_app_v.cont, ncont);
	return task;
      }
    case FUNCTION_P:
      {
	struct function_s *val = new_function ();
	struct task_s *task = new_task ();
	struct continuation_s *ncont = new_continuation ();

	push_cont (cont);
	val->t = FUNCTION_I;
	task->t = TASK_APP;
	ncont->t = CONTINUATION_ABORT;
	init_ptr (&task->d.task_app_v.erator, rand);
	init_ptr (&task->d.task_app_v.erand, val);
	init_ptr (&task->d.task_app_v.cont, ncont);
	return task;
      }
    case FUNCTION_F:
      {
	struct function_s *val = new_function ();
	struct task_s *task = new_task ();
	struct continuation_s *ncont = new_continuation ();

	val->t = FUNCTION_DCONT;
	init_ptr (&val->d.function_cont_v, cont);
	task->t = TASK_APP;
	ncont->t = CONTINUATION_ABORT;
	init_ptr (&task->d.task_app_v.erator, rand);
	init_ptr (&task->d.task_app_v.erand, val);
	init_ptr (&task->d.task_app_v.cont, ncont);
	return task;
      }
    case FUNCTION_E:
      {
	struct task_s *task = new_task ();

	task->t = TASK_FINAL;
	return task;
      }
    case FUNCTION_AT:
      {
	struct function_s *val = new_function ();
	struct task_s *task = new_task ();

	current_ch = getchar ();
	val->t = (current_ch != EOF ? FUNCTION_I : FUNCTION_V);
	task->t = TASK_APP;
	init_ptr (&task->d.task_app_v.erator, rand);
	init_ptr (&task->d.task_app_v.erand, val);
	init_ptr (&task->d.task_app_v.cont, cont);
#if 0  /* Harmless but not necessary */
	free_function (val);
#endif
	return task;
      }
    case FUNCTION_QUES:
      {
	struct function_s *val = new_function ();
	struct task_s *task = new_task ();

	val->t = (current_ch == rator->d.function_ques_v
		  ? FUNCTION_I : FUNCTION_V);
	task->t = TASK_APP;
	init_ptr (&task->d.task_app_v.erator, rand);
	init_ptr (&task->d.task_app_v.erand, val);
	init_ptr (&task->d.task_app_v.cont, cont);
#if 0  /* Harmless but not necessary */
	free_function (val);
#endif
	return task;
      }
    case FUNCTION_PIPE:
      {
	struct function_s *val = new_function ();
	struct task_s *task = new_task ();

	if ( current_ch != EOF )
	  {
	    val->t = FUNCTION_DOT;
	    val->d.function_dot_v = current_ch;
	  }
	else
	  val->t = FUNCTION_V;
	task->t = TASK_APP;
	init_ptr (&task->d.task_app_v.erator, rand);
	init_ptr (&task->d.task_app_v.erand, val);
	init_ptr (&task->d.task_app_v.cont, cont);
#if 0  /* Harmless but not necessary */
	free_function (val);
#endif
	return task;
      }
    }
  fprintf (stderr, "INTERNAL ERROR: apply() surprised!\n");
  return NULL;
}
Beispiel #12
0
void
release_function (struct function_s *fun)
{
  fun->refcnt --;
  free_function (fun);
}