Skip to content

Commit 9f7f753

Browse files
committed
resolve comments
1 parent d4aea18 commit 9f7f753

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

js/node/src/inference_session_wrap.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Napi::Value InferenceSessionWrap::LoadModel(const Napi::CallbackInfo& info) {
7777
Napi::String value = info[0].As<Napi::String>();
7878

7979
ParseSessionOptions(info[1].As<Napi::Object>(), sessionOptions);
80-
this->session_.reset(new Ort::Session(*OrtSingletonData::Env(),
80+
this->session_.reset(new Ort::Session(OrtSingletonData::Env(),
8181
#ifdef _WIN32
8282
reinterpret_cast<const wchar_t*>(value.Utf16Value().c_str()),
8383
#else
@@ -92,7 +92,7 @@ Napi::Value InferenceSessionWrap::LoadModel(const Napi::CallbackInfo& info) {
9292
int64_t bytesLength = info[2].As<Napi::Number>().Int64Value();
9393

9494
ParseSessionOptions(info[3].As<Napi::Object>(), sessionOptions);
95-
this->session_.reset(new Ort::Session(*OrtSingletonData::Env(),
95+
this->session_.reset(new Ort::Session(OrtSingletonData::Env(),
9696
reinterpret_cast<char*>(buffer) + bytesOffset, bytesLength,
9797
sessionOptions));
9898
} else {
@@ -212,7 +212,7 @@ Napi::Value InferenceSessionWrap::Run(const Napi::CallbackInfo& info) {
212212
ParseRunOptions(info[2].As<Napi::Object>(), runOptions);
213213
}
214214
if (preferredOutputLocations_.size() == 0) {
215-
session_->Run(runOptions == nullptr ? *OrtSingletonData::DefaultRunOptions() : runOptions,
215+
session_->Run(runOptions == nullptr ? OrtSingletonData::DefaultRunOptions() : runOptions,
216216
inputIndex == 0 ? nullptr : &inputNames_cstr[0], inputIndex == 0 ? nullptr : &inputValues[0],
217217
inputIndex, outputIndex == 0 ? nullptr : &outputNames_cstr[0],
218218
outputIndex == 0 ? nullptr : &outputValues[0], outputIndex);
@@ -241,7 +241,7 @@ Napi::Value InferenceSessionWrap::Run(const Napi::CallbackInfo& info) {
241241
}
242242
}
243243

244-
session_->Run(runOptions == nullptr ? *OrtSingletonData::DefaultRunOptions() : runOptions, *ioBinding_);
244+
session_->Run(runOptions == nullptr ? OrtSingletonData::DefaultRunOptions() : runOptions, *ioBinding_);
245245

246246
auto outputs = ioBinding_->GetOutputValues();
247247
ORT_NAPI_THROW_ERROR_IF(outputs.size() != outputIndex, env, "Output count mismatch.");

js/node/src/ort_singleton_data.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
#include "ort_singleton_data.h"
55

66
OrtSingletonData::OrtObjects::OrtObjects(int log_level)
7-
: env(new Ort::Env{OrtLoggingLevel(log_level), "onnxruntime-node"}),
8-
default_run_options(new Ort::RunOptions{}) {
7+
: env{OrtLoggingLevel(log_level), "onnxruntime-node"},
8+
default_run_options{} {
99
}
1010

1111
OrtSingletonData::OrtObjects& OrtSingletonData::GetOrCreateOrtObjects(int log_level) {
1212
static OrtObjects ort_objects(log_level);
1313
return ort_objects;
1414
}
1515

16-
const Ort::Env* OrtSingletonData::Env() {
17-
return GetOrCreateOrtObjects().env.get();
16+
const Ort::Env& OrtSingletonData::Env() {
17+
return GetOrCreateOrtObjects().env;
1818
}
1919

20-
const Ort::RunOptions* OrtSingletonData::DefaultRunOptions() {
21-
return GetOrCreateOrtObjects().default_run_options.get();
20+
const Ort::RunOptions& OrtSingletonData::DefaultRunOptions() {
21+
return GetOrCreateOrtObjects().default_run_options;
2222
}

js/node/src/ort_singleton_data.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
*/
2222
struct OrtSingletonData {
2323
struct OrtObjects {
24-
std::unique_ptr<Ort::Env> env;
25-
std::unique_ptr<Ort::RunOptions> default_run_options;
24+
Ort::Env env;
25+
Ort::RunOptions default_run_options;
2626

2727
private:
2828
// The following pattern ensures that OrtObjects can only be created by OrtSingletonData
@@ -33,8 +33,8 @@ struct OrtSingletonData {
3333
static OrtObjects& GetOrCreateOrtObjects(int log_level = ORT_LOGGING_LEVEL_WARNING);
3434

3535
// Get the global Ort::Env
36-
static const Ort::Env* Env();
36+
static const Ort::Env& Env();
3737

3838
// Get the default Ort::RunOptions
39-
static const Ort::RunOptions* DefaultRunOptions();
39+
static const Ort::RunOptions& DefaultRunOptions();
4040
};

0 commit comments

Comments
 (0)