nghttpx: Use ImmutableString for mruby_file
This commit is contained in:
parent
7aabc6b125
commit
aa3373a107
|
@ -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.";
|
||||
|
|
|
@ -584,7 +584,7 @@ struct Config {
|
|||
ImmutableString pid_file;
|
||||
ImmutableString conf_path;
|
||||
ImmutableString user;
|
||||
std::unique_ptr<char[]> mruby_file;
|
||||
ImmutableString mruby_file;
|
||||
char **original_argv;
|
||||
char **argv;
|
||||
char *cwd;
|
||||
|
|
|
@ -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<MRubyContext> create_mruby_context(const char *filename) {
|
||||
if (!filename) {
|
||||
std::unique_ptr<MRubyContext> create_mruby_context(const StringRef &filename) {
|
||||
if (filename.empty()) {
|
||||
return make_unique<MRubyContext>(nullptr, mrb_nil_value(), mrb_nil_value());
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
#include <mruby.h>
|
||||
#include <mruby/proc.h>
|
||||
|
||||
#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<MRubyContext> create_mruby_context(const char *filename);
|
||||
std::unique_ptr<MRubyContext> create_mruby_context(const StringRef &filename);
|
||||
|
||||
// Return interned |ptr|.
|
||||
mrb_sym intern_ptr(mrb_state *mrb, void *ptr);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue