diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index 1e023d18..4d95ffe2 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -2205,7 +2205,7 @@ int parse_config(const char *opt, const char *optarg, case SHRPX_OPTID_MRUBY_FILE: #ifdef HAVE_MRUBY - mod_config()->mruby_file = strcopy(optarg); + mod_config()->mruby_file = optarg; #else // !HAVE_MRUBY LOG(WARN) << opt << ": ignored because mruby support is disabled at build time."; diff --git a/src/shrpx_config.h b/src/shrpx_config.h index 03b3700b..80f0e06e 100644 --- a/src/shrpx_config.h +++ b/src/shrpx_config.h @@ -584,7 +584,7 @@ struct Config { ImmutableString pid_file; ImmutableString conf_path; ImmutableString user; - std::unique_ptr mruby_file; + ImmutableString mruby_file; char **original_argv; char **argv; char *cwd; diff --git a/src/shrpx_mruby.cc b/src/shrpx_mruby.cc index 5b1b3967..bd57c146 100644 --- a/src/shrpx_mruby.cc +++ b/src/shrpx_mruby.cc @@ -31,7 +31,6 @@ #include "shrpx_config.h" #include "shrpx_mruby_module.h" #include "shrpx_downstream_connection.h" -#include "template.h" namespace shrpx { @@ -146,12 +145,12 @@ mrb_value instantiate_app(mrb_state *mrb, RProc *proc) { // very hard to write these kind of code because mruby has almost no // documentation aobut compiling or generating code, at least at the // time of this writing. -RProc *compile(mrb_state *mrb, const char *filename) { - if (filename == nullptr) { +RProc *compile(mrb_state *mrb, const StringRef &filename) { + if (filename.empty()) { return nullptr; } - auto infile = fopen(filename, "rb"); + auto infile = fopen(filename.c_str(), "rb"); if (infile == nullptr) { return nullptr; } @@ -185,8 +184,8 @@ RProc *compile(mrb_state *mrb, const char *filename) { return proc; } -std::unique_ptr create_mruby_context(const char *filename) { - if (!filename) { +std::unique_ptr create_mruby_context(const StringRef &filename) { + if (filename.empty()) { return make_unique(nullptr, mrb_nil_value(), mrb_nil_value()); } diff --git a/src/shrpx_mruby.h b/src/shrpx_mruby.h index 95f0430c..55a18351 100644 --- a/src/shrpx_mruby.h +++ b/src/shrpx_mruby.h @@ -32,6 +32,8 @@ #include #include +#include "template.h" + using namespace nghttp2; namespace shrpx { @@ -69,9 +71,9 @@ struct MRubyAssocData { bool response_headers_dirty; }; -RProc *compile(mrb_state *mrb, const char *filename); +RProc *compile(mrb_state *mrb, const StringRef &filename); -std::unique_ptr create_mruby_context(const char *filename); +std::unique_ptr create_mruby_context(const StringRef &filename); // Return interned |ptr|. mrb_sym intern_ptr(mrb_state *mrb, void *ptr); diff --git a/src/shrpx_worker.cc b/src/shrpx_worker.cc index 83cfff9b..604f9058 100644 --- a/src/shrpx_worker.cc +++ b/src/shrpx_worker.cc @@ -290,8 +290,7 @@ std::mt19937 &Worker::get_randgen() { return randgen_; } #ifdef HAVE_MRUBY int Worker::create_mruby_context() { - auto mruby_file = get_config()->mruby_file.get(); - mruby_ctx_ = mruby::create_mruby_context(mruby_file); + mruby_ctx_ = mruby::create_mruby_context(StringRef{get_config()->mruby_file}); if (!mruby_ctx_) { return -1; }