示例#1
0
static int static_file_write_content(request_t *req, response_t *resp, handler_ctx_t *ctx) {
    int fd;
    size_t size, offset;

    size = context_pop(ctx)->as_long;
    offset = context_pop(ctx)->as_long;
    fd = context_peek(ctx)->as_int;
    debug("writing file");
    if (response_send_file(resp, fd, offset, size, static_file_cleanup) < 0) {
        error("Error sending file");
        return response_send_status(resp, STATUS_NOT_FOUND);
    }
    return HANDLER_UNFISHED;
}
示例#2
0
Func_def::Func_def() {
    Context * con_temp = context;
    context_push();
    ret_var = new Var_def();
    eat(tok_punc_lparen);
    if (lookahead(0).tok != tok_punc_rparen) {
        while (1) {
            args.push_back(new Var_def());
            if (lookahead(0).tok == tok_punc_rparen) {
                break;
            }
            eat(tok_punc_comma);
        }
    }
    eat(tok_punc_rparen);
    if (context->func_tbl.count(get_name())) {
        error("duplicated function definition");
    }
    Context * con_temp2 = context;
    context = con_temp;
    context->func_tbl.insert(std::pair<std::string, Func_def*>(get_name(), this));
    context = con_temp2;
    eat(tok_punc_lbrace);
    stmts = new Statements();
    eat(tok_punc_rbrace);
    context_pop();
};
示例#3
0
static int static_file_cleanup(request_t *req, response_t *resp, handler_ctx_t *ctx) {
    int fd;

    debug("cleaning up");
    fd = context_pop(ctx)->as_int;
    close(fd);
    return HANDLER_DONE;
}
示例#4
0
文件: yajl_tree.c 项目: ludocode/yajl
yajl_val yajl_tree_parse_options (const char *input,
                                   char *error_buffer, size_t error_buffer_size,
                                   yajl_tree_option options)
{
    static const yajl_callbacks callbacks =
        {
            /* null        = */ handle_null,
            /* boolean     = */ handle_boolean,
            /* integer     = */ NULL,
            /* double      = */ NULL,
            /* number      = */ handle_number,
            /* string      = */ handle_string,
            /* start map   = */ handle_start_map,
            /* map key     = */ handle_string,
            /* end map     = */ handle_end_map,
            /* start array = */ handle_start_array,
            /* end array   = */ handle_end_array
        };

    yajl_handle handle;
    yajl_status status;
    char * internal_err_str;
	context_t ctx = { NULL, NULL, NULL, 0 };

	ctx.errbuf = error_buffer;
	ctx.errbuf_size = error_buffer_size;

    if (error_buffer != NULL)
        memset (error_buffer, 0, error_buffer_size);

    handle = yajl_alloc (&callbacks, NULL, &ctx);
    yajl_config(handle, yajl_allow_comments,
            (options & yajl_tree_option_dont_allow_comments) ? 0 : 1);
    yajl_config(handle, yajl_allow_trailing_separator,
            (options & yajl_tree_option_allow_trailing_separator) ? 1 : 0);

    status = yajl_parse(handle,
                        (unsigned char *) input,
                        strlen (input));
    status = yajl_complete_parse (handle);
    if (status != yajl_status_ok) {
        if (error_buffer != NULL && error_buffer_size > 0) {
               internal_err_str = (char *) yajl_get_error(handle, 1,
                     (const unsigned char *) input,
                     strlen(input));
             snprintf(error_buffer, error_buffer_size, "%s", internal_err_str);
             YA_FREE(&(handle->alloc), internal_err_str);
        }
        while (ctx.stack) {
            yajl_tree_free(context_pop(&ctx));
        }
        yajl_free (handle);
        return NULL;
    }

    yajl_free (handle);
    return (ctx.root);
}
示例#5
0
static int handle_end_array (void *ctx)
{
    yajl_val v;

    v = context_pop (ctx);
    if (v == NULL)
        return (STATUS_ABORT);

    return ((context_add_value (ctx, v) == 0) ? STATUS_CONTINUE : STATUS_ABORT);
}
示例#6
0
term* normalize_fuel_pi(context *Sigma, typing_context* Delta, term* t, int fuel) {
  term* B = NULL;
  term* A = normalize_fuel(Sigma, Delta, t->left, fuel-1);
  if (!A) goto error;
  context* extend = context_add(variable_dup(t->var), NULL, Sigma);
  B = normalize_fuel(extend, Delta, t->right, fuel-1);
  context_pop(extend);
  if (!B) goto error;
  return make_pi(variable_dup(t->var), A, B);
 error:
  free_term(A);
  free_term(B);
  return NULL;
}
示例#7
0
term* normalize_fuel_lambda(context *Sigma, typing_context* Delta, term* t, int fuel) {
  term* b = NULL;
  term* A = normalize_fuel(Sigma, Delta, t->left, fuel-1);

  context* extend = context_add(variable_dup(t->var), NULL, Sigma);
  b = normalize_fuel(extend, Delta, t->right, fuel-1);
  context_pop(extend);
  if (!b) goto error;
  return make_lambda(variable_dup(t->var), A, b);
 error:
  free_term(A);
  free_term(b);
  return NULL;
}
示例#8
0
文件: oostruct.c 项目: barak/lush
static object_t *oostruct_dispose(object_t *obj)
{
   /* oostruct gets called only once */
   assert(!ZOMBIEP(obj->backptr));

   obj->next_unreachable = NULL;

   int oldready = error_doc.ready_to_an_error;
   error_doc.ready_to_an_error = true;
   struct lush_context mycontext;
   context_push(&mycontext);
   
   int errflag = sigsetjmp(context->error_jump,1);
   if (errflag==0) {
      /* call all destructors for interpreted part */
      /* destructors for compiled part are called  */
      /* by finalizer for compiled part            */
      at *f = NIL;
      class_t *cl = Class(obj->backptr);
      while (cl) {
         struct hashelem *hx = _getmethod(cl, at_destroy);
         cl = cl->super;
         if (! hx)
            break;
         else if (hx->function == f)
            continue;
         else if (classof(hx->function) == dh_class)
            break;
         call_method(obj->backptr, hx, NIL);
         f = hx->function;
      }
   }
   
   context_pop();
   error_doc.ready_to_an_error = oldready;
   if (obj->cptr)
      obj->cptr->__lptr = NULL;
   zombify(obj->backptr);
   
   if (errflag)
      siglongjmp(context->error_jump, -1L);

   return obj;
}
示例#9
0
Top::Top() {
    context_push();
    while (1) {
        switch (lookahead(0).tok) {
        case tok_identifier:
            if (lookahead(1).tok == tok_identifier) {
                if (lookahead(2).tok == tok_punc_lparen) {
                    funcs.push_back(new Func_def());
                } else {
                    vars.push_back(new Var_def());
                }
            } else {
                error("definition expected!");
            }
            break;
        default:
            goto _out;
        }
    }
_out:
    context_pop();
};