Skip to content

Commit df7aa7a

Browse files
author
Gabriel Schulhof
committed
squash! whitespace fixes
1 parent 005cbc9 commit df7aa7a

File tree

3 files changed

+117
-115
lines changed

3 files changed

+117
-115
lines changed

src/env-inl.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,10 @@ inline uv_loop_t* Environment::event_loop() const {
396396
return isolate_data()->event_loop();
397397
}
398398

399-
inline void Environment::TryLoadAddon(const char* filename,
400-
int flags,
401-
std::function<bool(binding::DLib*)> was_loaded) {
399+
inline void Environment::TryLoadAddon(
400+
const char* filename,
401+
int flags,
402+
std::function<bool(binding::DLib*)> was_loaded) {
402403
loaded_addons_.emplace_back(filename, flags);
403404
if (!was_loaded(&loaded_addons_.back())) {
404405
loaded_addons_.pop_back();

src/node_binding-inl.h

+39-39
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,49 @@ namespace node {
77

88
namespace binding {
99

10-
inline DLib::DLib(const char* filename, int flags):
11-
filename_(filename), flags_(flags), handle_(nullptr) {}
10+
inline DLib::DLib(const char* filename, int flags)
11+
: filename_(filename), flags_(flags), handle_(nullptr) {}
1212

1313
#ifdef __POSIX__
14-
inline bool DLib::Open() {
15-
handle_ = dlopen(filename_.c_str(), flags_);
16-
if (handle_ != nullptr) return true;
17-
errmsg_ = dlerror();
18-
return false;
19-
}
20-
21-
inline void DLib::Close() {
22-
if (handle_ == nullptr) return;
23-
dlclose(handle_);
24-
handle_ = nullptr;
25-
}
26-
27-
inline void* DLib::GetSymbolAddress(const char* name) {
28-
return dlsym(handle_, name);
29-
}
14+
inline bool DLib::Open() {
15+
handle_ = dlopen(filename_.c_str(), flags_);
16+
if (handle_ != nullptr) return true;
17+
errmsg_ = dlerror();
18+
return false;
19+
}
20+
21+
inline void DLib::Close() {
22+
if (handle_ == nullptr) return;
23+
dlclose(handle_);
24+
handle_ = nullptr;
25+
}
26+
27+
inline void* DLib::GetSymbolAddress(const char* name) {
28+
return dlsym(handle_, name);
29+
}
3030
#else // !__POSIX__
31-
inline bool DLib::Open() {
32-
int ret = uv_dlopen(filename_.c_str(), &lib_);
33-
if (ret == 0) {
34-
handle_ = static_cast<void*>(lib_.handle);
35-
return true;
36-
}
37-
errmsg_ = uv_dlerror(&lib_);
38-
uv_dlclose(&lib_);
39-
return false;
40-
}
41-
42-
inline void DLib::Close() {
43-
if (handle_ == nullptr) return;
44-
uv_dlclose(&lib_);
45-
handle_ = nullptr;
46-
}
47-
48-
inline void* DLib::GetSymbolAddress(const char* name) {
49-
void* address;
50-
if (0 == uv_dlsym(&lib_, name, &address)) return address;
51-
return nullptr;
31+
inline bool DLib::Open() {
32+
int ret = uv_dlopen(filename_.c_str(), &lib_);
33+
if (ret == 0) {
34+
handle_ = static_cast<void*>(lib_.handle);
35+
return true;
5236
}
37+
errmsg_ = uv_dlerror(&lib_);
38+
uv_dlclose(&lib_);
39+
return false;
40+
}
41+
42+
inline void DLib::Close() {
43+
if (handle_ == nullptr) return;
44+
uv_dlclose(&lib_);
45+
handle_ = nullptr;
46+
}
47+
48+
inline void* DLib::GetSymbolAddress(const char* name) {
49+
void* address;
50+
if (0 == uv_dlsym(&lib_, name, &address)) return address;
51+
return nullptr;
52+
}
5353
#endif // !__POSIX__
5454

5555
} // end of namespace binding

src/node_binding.cc

+74-73
Original file line numberDiff line numberDiff line change
@@ -176,89 +176,90 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
176176

177177
node::Utf8Value filename(env->isolate(), args[1]); // Cast
178178
env->TryLoadAddon(*filename, flags, [&](DLib* dlib) {
179-
const bool is_opened = dlib->Open();
180-
181-
// Objects containing v14 or later modules will have registered themselves
182-
// on the pending list. Activate all of them now. At present, only one
183-
// module per object is supported.
184-
node_module* const mp =
185-
static_cast<node_module*>(uv_key_get(&thread_local_modpending));
186-
uv_key_set(&thread_local_modpending, nullptr);
187-
188-
if (!is_opened) {
189-
Local<String> errmsg = OneByteString(env->isolate(), dlib->errmsg_.c_str());
190-
dlib->Close();
179+
const bool is_opened = dlib->Open();
180+
181+
// Objects containing v14 or later modules will have registered themselves
182+
// on the pending list. Activate all of them now. At present, only one
183+
// module per object is supported.
184+
node_module* const mp =
185+
static_cast<node_module*>(uv_key_get(&thread_local_modpending));
186+
uv_key_set(&thread_local_modpending, nullptr);
187+
188+
if (!is_opened) {
189+
Local<String> errmsg =
190+
OneByteString(env->isolate(), dlib->errmsg_.c_str());
191+
dlib->Close();
191192
#ifdef _WIN32
192-
// Windows needs to add the filename into the error message
193-
errmsg = String::Concat(
194-
env->isolate(), errmsg, args[1]->ToString(context).ToLocalChecked());
193+
// Windows needs to add the filename into the error message
194+
errmsg = String::Concat(
195+
env->isolate(), errmsg, args[1]->ToString(context).ToLocalChecked());
195196
#endif // _WIN32
196-
env->isolate()->ThrowException(Exception::Error(errmsg));
197-
return false;
198-
}
199-
200-
if (mp == nullptr) {
201-
if (auto callback = GetInitializerCallback(dlib)) {
202-
callback(exports, module, context);
203-
} else if (auto napi_callback = GetNapiInitializerCallback(dlib)) {
204-
napi_module_register_by_symbol(exports, module, context, napi_callback);
205-
} else {
206-
dlib->Close();
207-
env->ThrowError("Module did not self-register.");
197+
env->isolate()->ThrowException(Exception::Error(errmsg));
208198
return false;
209199
}
210-
return true;
211-
}
212200

213-
// -1 is used for N-API modules
214-
if ((mp->nm_version != -1) && (mp->nm_version != NODE_MODULE_VERSION)) {
215-
// Even if the module did self-register, it may have done so with the wrong
216-
// version. We must only give up after having checked to see if it has an
217-
// appropriate initializer callback.
218-
if (auto callback = GetInitializerCallback(dlib)) {
219-
callback(exports, module, context);
201+
if (mp == nullptr) {
202+
if (auto callback = GetInitializerCallback(dlib)) {
203+
callback(exports, module, context);
204+
} else if (auto napi_callback = GetNapiInitializerCallback(dlib)) {
205+
napi_module_register_by_symbol(exports, module, context, napi_callback);
206+
} else {
207+
dlib->Close();
208+
env->ThrowError("Module did not self-register.");
209+
return false;
210+
}
220211
return true;
221212
}
222-
char errmsg[1024];
223-
snprintf(errmsg,
224-
sizeof(errmsg),
225-
"The module '%s'"
226-
"\nwas compiled against a different Node.js version using"
227-
"\nNODE_MODULE_VERSION %d. This version of Node.js requires"
228-
"\nNODE_MODULE_VERSION %d. Please try re-compiling or "
229-
"re-installing\nthe module (for instance, using `npm rebuild` "
230-
"or `npm install`).",
231-
*filename,
232-
mp->nm_version,
233-
NODE_MODULE_VERSION);
234-
235-
// NOTE: `mp` is allocated inside of the shared library's memory, calling
236-
// `dlclose` will deallocate it
237-
dlib->Close();
238-
env->ThrowError(errmsg);
239-
return false;
240-
}
241-
if (mp->nm_flags & NM_F_BUILTIN) {
242-
dlib->Close();
243-
env->ThrowError("Built-in module self-registered.");
244-
return false;
245-
}
246213

247-
mp->nm_dso_handle = dlib->handle_;
248-
mp->nm_link = modlist_addon;
249-
modlist_addon = mp;
214+
// -1 is used for N-API modules
215+
if ((mp->nm_version != -1) && (mp->nm_version != NODE_MODULE_VERSION)) {
216+
// Even if the module did self-register, it may have done so with the
217+
// wrong version. We must only give up after having checked to see if it
218+
// has an appropriate initializer callback.
219+
if (auto callback = GetInitializerCallback(dlib)) {
220+
callback(exports, module, context);
221+
return true;
222+
}
223+
char errmsg[1024];
224+
snprintf(errmsg,
225+
sizeof(errmsg),
226+
"The module '%s'"
227+
"\nwas compiled against a different Node.js version using"
228+
"\nNODE_MODULE_VERSION %d. This version of Node.js requires"
229+
"\nNODE_MODULE_VERSION %d. Please try re-compiling or "
230+
"re-installing\nthe module (for instance, using `npm rebuild` "
231+
"or `npm install`).",
232+
*filename,
233+
mp->nm_version,
234+
NODE_MODULE_VERSION);
235+
236+
// NOTE: `mp` is allocated inside of the shared library's memory, calling
237+
// `dlclose` will deallocate it
238+
dlib->Close();
239+
env->ThrowError(errmsg);
240+
return false;
241+
}
242+
if (mp->nm_flags & NM_F_BUILTIN) {
243+
dlib->Close();
244+
env->ThrowError("Built-in module self-registered.");
245+
return false;
246+
}
250247

251-
if (mp->nm_context_register_func != nullptr) {
252-
mp->nm_context_register_func(exports, module, context, mp->nm_priv);
253-
} else if (mp->nm_register_func != nullptr) {
254-
mp->nm_register_func(exports, module, mp->nm_priv);
255-
} else {
256-
dlib->Close();
257-
env->ThrowError("Module has no declared entry point.");
258-
return false;
259-
}
248+
mp->nm_dso_handle = dlib->handle_;
249+
mp->nm_link = modlist_addon;
250+
modlist_addon = mp;
260251

261-
return true;
252+
if (mp->nm_context_register_func != nullptr) {
253+
mp->nm_context_register_func(exports, module, context, mp->nm_priv);
254+
} else if (mp->nm_register_func != nullptr) {
255+
mp->nm_register_func(exports, module, mp->nm_priv);
256+
} else {
257+
dlib->Close();
258+
env->ThrowError("Module has no declared entry point.");
259+
return false;
260+
}
261+
262+
return true;
262263
});
263264

264265
// Tell coverity that 'handle' should not be freed when we return.

0 commit comments

Comments
 (0)