diff --git a/src/http/ngx_http_mruby_async.c b/src/http/ngx_http_mruby_async.c index a56bc03b..aca111ef 100644 --- a/src/http/ngx_http_mruby_async.c +++ b/src/http/ngx_http_mruby_async.c @@ -45,7 +45,9 @@ mrb_value ngx_mrb_start_fiber(ngx_http_request_t *r, mrb_state *mrb, struct RPro ctx = ngx_mrb_http_get_module_ctx(mrb, r); ctx->async_handler_result = result; - handler_proc = mrb_closure_new(mrb, rproc->body.irep); + handler_proc = rproc; + handler_proc->upper = NULL; + handler_proc->e.target_class = mrb->object_class; fiber_proc = (mrb_value *)ngx_palloc(r->pool, sizeof(mrb_value)); *fiber_proc = mrb_fiber_new(mrb, rproc); if (mrb->exc) { diff --git a/src/http/ngx_http_mruby_module.c b/src/http/ngx_http_mruby_module.c index 77bafddb..17b2ae31 100644 --- a/src/http/ngx_http_mruby_module.c +++ b/src/http/ngx_http_mruby_module.c @@ -11,6 +11,7 @@ #include "ngx_http_mruby_init.h" #include "ngx_http_mruby_request.h" +#include #include #define ON 1 @@ -910,7 +911,7 @@ ngx_int_t ngx_mrb_run(ngx_http_request_t *r, ngx_mrb_state_t *state, ngx_mrb_cod static ngx_int_t ngx_http_mruby_state_reinit_from_file(ngx_mrb_state_t *state, ngx_mrb_code_t *code) { FILE *mrb_file; - struct mrb_parser_state *p; + mrb_value proc; if ((mrb_file = fopen((char *)code->code.file, "r")) == NULL) { return NGX_ERROR; @@ -919,18 +920,15 @@ static ngx_int_t ngx_http_mruby_state_reinit_from_file(ngx_mrb_state_t *state, n NGX_MRUBY_CODE_MRBC_CONTEXT_FREE(state->mrb, code); code->ctx = mrbc_context_new(state->mrb); mrbc_filename(state->mrb, code->ctx, (char *)code->code.file); - p = mrb_parse_file(state->mrb, mrb_file, code->ctx); + code->ctx->no_exec = TRUE; + proc = mrb_load_file_cxt(state->mrb, mrb_file, code->ctx); fclose(mrb_file); - if (p == NULL || (0 < p->nerr)) { + if (!mrb_proc_p(proc)) { return NGX_ERROR; } - code->proc = mrb_generate_code(state->mrb, p); - mrb_pool_close(p->pool); - if (code->proc == NULL) { - return NGX_ERROR; - } + code->proc = mrb_proc_ptr(proc); return NGX_OK; } @@ -994,10 +992,11 @@ static ngx_int_t ngx_http_mruby_shared_state_init(ngx_mrb_state_t *state) static ngx_int_t ngx_http_mruby_shared_state_compile(ngx_conf_t *cf, ngx_mrb_state_t *state, ngx_mrb_code_t *code) { FILE *mrb_file; - struct mrb_parser_state *p; + mrb_value proc; NGX_MRUBY_CODE_MRBC_CONTEXT_FREE(state->mrb, code); code->ctx = mrbc_context_new(state->mrb); + code->ctx->no_exec = TRUE; #ifdef NGX_MRUBY_IREP_DEBUG code->ctx->dump_result = TRUE; #endif @@ -1007,23 +1006,18 @@ static ngx_int_t ngx_http_mruby_shared_state_compile(ngx_conf_t *cf, ngx_mrb_sta return NGX_ERROR; } mrbc_filename(state->mrb, code->ctx, (char *)code->code.file); - p = mrb_parse_file(state->mrb, mrb_file, code->ctx); + proc = mrb_load_file_cxt(state->mrb, mrb_file, code->ctx); fclose(mrb_file); } else { mrbc_filename(state->mrb, code->ctx, "INLINE CODE"); - p = mrb_parse_string(state->mrb, (char *)code->code.string, code->ctx); - } - - if (p == NULL || (0 < p->nerr)) { - return NGX_ERROR; + proc = mrb_load_string_cxt(state->mrb, (char *)code->code.string, code->ctx); } - code->proc = mrb_generate_code(state->mrb, p); - mrb_pool_close(p->pool); - if (code->proc == NULL) { + if (!mrb_proc_p(proc)) { return NGX_ERROR; } + code->proc = mrb_proc_ptr(proc); #ifdef NGX_MRUBY_IREP_DEBUG /* mrb_codedump_all() is not declared in mruby headers. So just follows the mruby way. See mruby/src/load.c. */ void mrb_codedump_all(mrb_state *, struct RProc *); diff --git a/src/stream/ngx_stream_mruby_async.c b/src/stream/ngx_stream_mruby_async.c index 5f0213bd..cec7b2f2 100644 --- a/src/stream/ngx_stream_mruby_async.c +++ b/src/stream/ngx_stream_mruby_async.c @@ -57,7 +57,9 @@ mrb_value ngx_stream_mrb_start_fiber(ngx_stream_session_t *s, mrb_state *mrb, st ctx = ngx_stream_mrb_get_module_ctx(mrb, s); ctx->async_handler_result = result; - handler_proc = mrb_closure_new(mrb, rproc->body.irep); + handler_proc = rproc; + handler_proc->upper = NULL; + handler_proc->e.target_class = mrb->object_class; fiber_proc = (mrb_value *)ngx_palloc(s->connection->pool, sizeof(mrb_value)); *fiber_proc = mrb_fiber_new(mrb, rproc); if (mrb->exc) { diff --git a/src/stream/ngx_stream_mruby_module.c b/src/stream/ngx_stream_mruby_module.c index 4ea28350..3a64e009 100644 --- a/src/stream/ngx_stream_mruby_module.c +++ b/src/stream/ngx_stream_mruby_module.c @@ -10,6 +10,7 @@ #include "ngx_stream_mruby_init.h" +#include #include "mruby/string.h" #define NGX_MRUBY_CODE_MRBC_CONTEXT_FREE(mrb, code) \ @@ -361,7 +362,7 @@ static ngx_mrb_code_t *ngx_stream_mruby_mrb_code_from_string(ngx_pool_t *pool, n static ngx_int_t ngx_stream_mruby_shared_state_compile(ngx_conf_t *cf, mrb_state *mrb, ngx_mrb_code_t *code) { FILE *mrb_file; - struct mrb_parser_state *p; + mrb_value proc; if (code->code_type == NGX_MRB_CODE_TYPE_FILE) { if ((mrb_file = fopen((char *)code->code.file, "r")) == NULL) { @@ -370,24 +371,22 @@ static ngx_int_t ngx_stream_mruby_shared_state_compile(ngx_conf_t *cf, mrb_state NGX_MRUBY_CODE_MRBC_CONTEXT_FREE(mrb, code); code->ctx = mrbc_context_new(mrb); mrbc_filename(mrb, code->ctx, (char *)code->code.file); - p = mrb_parse_file(mrb, mrb_file, code->ctx); + code->ctx->no_exec = TRUE; + proc = mrb_load_file_cxt(mrb, mrb_file, code->ctx); fclose(mrb_file); } else { NGX_MRUBY_CODE_MRBC_CONTEXT_FREE(mrb, code); code->ctx = mrbc_context_new(mrb); mrbc_filename(mrb, code->ctx, "INLINE CODE"); - p = mrb_parse_string(mrb, (char *)code->code.string, code->ctx); + code->ctx->no_exec = TRUE; + proc = mrb_load_string_cxt(mrb, (char *)code->code.string, code->ctx); } - if (p == NULL || (0 < p->nerr)) { + if (!mrb_proc_p(proc)) { return NGX_ERROR; } - code->proc = mrb_generate_code(mrb, p); - mrb_pool_close(p->pool); - if (code->proc == NULL) { - return NGX_ERROR; - } + code->proc = mrb_proc_ptr(proc); if (code->code_type == NGX_MRB_CODE_TYPE_FILE) { ngx_conf_log_error(NGX_LOG_NOTICE, cf, 0, "%s NOTICE %s:%d: compile info: code->code.file=(%s)", MODULE_NAME,