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:
|
case SHRPX_OPTID_MRUBY_FILE:
|
||||||
#ifdef HAVE_MRUBY
|
#ifdef HAVE_MRUBY
|
||||||
mod_config()->mruby_file = strcopy(optarg);
|
mod_config()->mruby_file = optarg;
|
||||||
#else // !HAVE_MRUBY
|
#else // !HAVE_MRUBY
|
||||||
LOG(WARN) << opt
|
LOG(WARN) << opt
|
||||||
<< ": ignored because mruby support is disabled at build time.";
|
<< ": ignored because mruby support is disabled at build time.";
|
||||||
|
|
|
@ -584,7 +584,7 @@ struct Config {
|
||||||
ImmutableString pid_file;
|
ImmutableString pid_file;
|
||||||
ImmutableString conf_path;
|
ImmutableString conf_path;
|
||||||
ImmutableString user;
|
ImmutableString user;
|
||||||
std::unique_ptr<char[]> mruby_file;
|
ImmutableString mruby_file;
|
||||||
char **original_argv;
|
char **original_argv;
|
||||||
char **argv;
|
char **argv;
|
||||||
char *cwd;
|
char *cwd;
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
#include "shrpx_config.h"
|
#include "shrpx_config.h"
|
||||||
#include "shrpx_mruby_module.h"
|
#include "shrpx_mruby_module.h"
|
||||||
#include "shrpx_downstream_connection.h"
|
#include "shrpx_downstream_connection.h"
|
||||||
#include "template.h"
|
|
||||||
|
|
||||||
namespace shrpx {
|
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
|
// very hard to write these kind of code because mruby has almost no
|
||||||
// documentation aobut compiling or generating code, at least at the
|
// documentation aobut compiling or generating code, at least at the
|
||||||
// time of this writing.
|
// time of this writing.
|
||||||
RProc *compile(mrb_state *mrb, const char *filename) {
|
RProc *compile(mrb_state *mrb, const StringRef &filename) {
|
||||||
if (filename == nullptr) {
|
if (filename.empty()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto infile = fopen(filename, "rb");
|
auto infile = fopen(filename.c_str(), "rb");
|
||||||
if (infile == nullptr) {
|
if (infile == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -185,8 +184,8 @@ RProc *compile(mrb_state *mrb, const char *filename) {
|
||||||
return proc;
|
return proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<MRubyContext> create_mruby_context(const char *filename) {
|
std::unique_ptr<MRubyContext> create_mruby_context(const StringRef &filename) {
|
||||||
if (!filename) {
|
if (filename.empty()) {
|
||||||
return make_unique<MRubyContext>(nullptr, mrb_nil_value(), mrb_nil_value());
|
return make_unique<MRubyContext>(nullptr, mrb_nil_value(), mrb_nil_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
#include <mruby.h>
|
#include <mruby.h>
|
||||||
#include <mruby/proc.h>
|
#include <mruby/proc.h>
|
||||||
|
|
||||||
|
#include "template.h"
|
||||||
|
|
||||||
using namespace nghttp2;
|
using namespace nghttp2;
|
||||||
|
|
||||||
namespace shrpx {
|
namespace shrpx {
|
||||||
|
@ -69,9 +71,9 @@ struct MRubyAssocData {
|
||||||
bool response_headers_dirty;
|
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|.
|
// Return interned |ptr|.
|
||||||
mrb_sym intern_ptr(mrb_state *mrb, void *ptr);
|
mrb_sym intern_ptr(mrb_state *mrb, void *ptr);
|
||||||
|
|
|
@ -290,8 +290,7 @@ std::mt19937 &Worker::get_randgen() { return randgen_; }
|
||||||
|
|
||||||
#ifdef HAVE_MRUBY
|
#ifdef HAVE_MRUBY
|
||||||
int Worker::create_mruby_context() {
|
int Worker::create_mruby_context() {
|
||||||
auto mruby_file = get_config()->mruby_file.get();
|
mruby_ctx_ = mruby::create_mruby_context(StringRef{get_config()->mruby_file});
|
||||||
mruby_ctx_ = mruby::create_mruby_context(mruby_file);
|
|
||||||
if (!mruby_ctx_) {
|
if (!mruby_ctx_) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue