Skip to content

Commit 8eb8359

Browse files
committed
fix: avoid sign conversion for options/errors/timeout
1 parent 32d7ba0 commit 8eb8359

File tree

9 files changed

+145
-109
lines changed

9 files changed

+145
-109
lines changed

src/context.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void Context::Close() {
6666
termination may block depending on ZMQ_BLOCKY/ZMQ_LINGER. This
6767
should definitely be avoided during GC and may only be acceptable
6868
at process exit. */
69-
[[maybe_unused]] auto err =zmq_ctx_shutdown(context);
69+
[[maybe_unused]] auto err = zmq_ctx_shutdown(context);
7070
assert(err == 0);
7171

7272
/* Pass the ZMQ context on to terminator for cleanup at exit. */
@@ -88,7 +88,7 @@ Napi::Value Context::GetCtxOpt<bool>(const Napi::CallbackInfo& info) {
8888
return Env().Undefined();
8989
}
9090

91-
uint32_t const option = info[0].As<Napi::Number>();
91+
const auto option = info[0].As<Napi::Number>();
9292

9393
int32_t const value = zmq_ctx_get(context, option);
9494
if (value < 0) {
@@ -110,7 +110,7 @@ void Context::SetCtxOpt<bool>(const Napi::CallbackInfo& info) {
110110
return;
111111
}
112112

113-
uint32_t const option = info[0].As<Napi::Number>();
113+
const auto option = info[0].As<Napi::Number>();
114114

115115
int32_t const value = static_cast<int32_t>(info[1].As<Napi::Boolean>());
116116
if (zmq_ctx_set(context, option, value) < 0) {
@@ -129,7 +129,7 @@ Napi::Value Context::GetCtxOpt(const Napi::CallbackInfo& info) {
129129
return Env().Undefined();
130130
}
131131

132-
uint32_t const option = info[0].As<Napi::Number>();
132+
const auto option = info[0].As<Napi::Number>();
133133

134134
T value = zmq_ctx_get(context, option);
135135
if (value < 0) {
@@ -151,7 +151,7 @@ void Context::SetCtxOpt(const Napi::CallbackInfo& info) {
151151
return;
152152
}
153153

154-
uint32_t const option = info[0].As<Napi::Number>();
154+
const auto option = info[0].As<Napi::Number>();
155155

156156
T value = info[1].As<Napi::Number>();
157157
if (zmq_ctx_set(context, option, value) < 0) {

src/incoming_msg.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "./incoming_msg.h"
33

44
#include <cassert>
5+
#include <cstdint>
56

67
#include "util/electron_helper.h"
78
#include "util/error.h"
@@ -41,7 +42,7 @@ Napi::Value IncomingMsg::IntoBuffer(const Napi::Env& env) {
4142
Napi::MemoryManagement::AdjustExternalMemory(env, length);
4243

4344
auto release = [](const Napi::Env& env, uint8_t*, Reference* ref) {
44-
ptrdiff_t const length = zmq_msg_size(*ref);
45+
const auto length = static_cast<int64_t>(zmq_msg_size(*ref));
4546
Napi::MemoryManagement::AdjustExternalMemory(env, -length);
4647
delete ref;
4748
};
@@ -58,12 +59,12 @@ Napi::Value IncomingMsg::IntoBuffer(const Napi::Env& env) {
5859
}
5960

6061
IncomingMsg::Reference::Reference() {
61-
[[maybe_unused]] auto err =zmq_msg_init(&msg);
62+
[[maybe_unused]] auto err = zmq_msg_init(&msg);
6263
assert(err == 0);
6364
}
6465

6566
IncomingMsg::Reference::~Reference() {
66-
[[maybe_unused]] auto err =zmq_msg_close(&msg);
67+
[[maybe_unused]] auto err = zmq_msg_close(&msg);
6768
assert(err == 0);
6869
}
6970
} // namespace zmq

src/module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct Terminator {
2727
/* Start termination asynchronously so we can detect if it takes long
2828
and should warn the user about this default blocking behaviour. */
2929
auto terminate = std::async(std::launch::async, [&] {
30-
[[maybe_unused]] auto err =zmq_ctx_term(context);
30+
[[maybe_unused]] auto err = zmq_ctx_term(context);
3131
assert(err == 0);
3232
});
3333

src/observer.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ Observer::Observer(const Napi::CallbackInfo& info)
179179
return;
180180

181181
error:
182-
[[maybe_unused]] auto err =zmq_close(socket);
182+
[[maybe_unused]] auto err = zmq_close(socket);
183183
assert(err == 0);
184184

185185
socket = nullptr;
@@ -219,7 +219,7 @@ void Observer::Close() {
219219
Napi::HandleScope const scope(Env());
220220

221221
/* Close succeeds unless socket is invalid. */
222-
[[maybe_unused]] auto err =zmq_close(socket);
222+
[[maybe_unused]] auto err = zmq_close(socket);
223223
assert(err == 0);
224224

225225
/* Reset pointer to avoid double close. */

src/outgoing_msg.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,15 @@ OutgoingMsg::OutgoingMsg(Napi::Value value, Module& module) {
8181
}
8282
/* Fall through */
8383

84-
[[fallthrough]]; default:
84+
[[fallthrough]];
85+
default:
8586
string_send(new std::string(value.ToString()));
8687
}
8788
}
8889
}
8990

9091
OutgoingMsg::~OutgoingMsg() {
91-
[[maybe_unused]] auto err =zmq_msg_close(&msg);
92+
[[maybe_unused]] auto err = zmq_msg_close(&msg);
9293
assert(err == 0);
9394
}
9495

src/poller.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <cstdint>
34
#include <utility>
45

56
#include "util/uvhandle.h"
@@ -70,20 +71,20 @@ class Poller {
7071
assert((events & UV_READABLE) == 0);
7172

7273
if (timeout > 0) {
73-
[[maybe_unused]] auto err =uv_timer_start(
74+
[[maybe_unused]] auto err = uv_timer_start(
7475
readable_timer,
7576
[](uv_timer_t* timer) {
7677
auto& poller = *reinterpret_cast<Poller*>(timer->data);
7778
poller.Trigger(UV_READABLE);
7879
},
79-
timeout, 0);
80+
static_cast<uint64_t>(timeout), 0);
8081

8182
assert(err == 0);
8283
}
8384

8485
if (events == 0) {
8586
/* Only start polling if we were not polling already. */
86-
[[maybe_unused]] auto err =uv_poll_start(poll, UV_READABLE, Callback);
87+
[[maybe_unused]] auto err = uv_poll_start(poll, UV_READABLE, Callback);
8788
assert(err == 0);
8889
}
8990

@@ -94,13 +95,13 @@ class Poller {
9495
assert((events & UV_WRITABLE) == 0);
9596

9697
if (timeout > 0) {
97-
[[maybe_unused]] auto err =uv_timer_start(
98+
[[maybe_unused]] auto err = uv_timer_start(
9899
writable_timer,
99100
[](uv_timer_t* timer) {
100101
auto& poller = *reinterpret_cast<Poller*>(timer->data);
101102
poller.Trigger(UV_WRITABLE);
102103
},
103-
timeout, 0);
104+
static_cast<uint64_t>(timeout), 0);
104105

105106
assert(err == 0);
106107
}
@@ -109,7 +110,7 @@ class Poller {
109110
events on the socket in an edge-triggered fashion by making the
110111
file descriptor become ready for READING." */
111112
if (events == 0) {
112-
[[maybe_unused]] auto err =uv_poll_start(poll, UV_READABLE, Callback);
113+
[[maybe_unused]] auto err = uv_poll_start(poll, UV_READABLE, Callback);
113114
assert(err == 0);
114115
}
115116

@@ -141,18 +142,18 @@ class Poller {
141142
void Trigger(int32_t triggered) {
142143
events &= ~triggered;
143144
if (events == 0) {
144-
[[maybe_unused]] auto err =uv_poll_stop(poll);
145+
[[maybe_unused]] auto err = uv_poll_stop(poll);
145146
assert(err == 0);
146147
}
147148

148149
if ((triggered & UV_READABLE) != 0) {
149-
[[maybe_unused]] auto err =uv_timer_stop(readable_timer);
150+
[[maybe_unused]] auto err = uv_timer_stop(readable_timer);
150151
assert(err == 0);
151152
static_cast<T*>(this)->ReadableCallback();
152153
}
153154

154155
if ((triggered & UV_WRITABLE) != 0) {
155-
[[maybe_unused]] auto err =uv_timer_stop(writable_timer);
156+
[[maybe_unused]] auto err = uv_timer_stop(writable_timer);
156157
assert(err == 0);
157158
static_cast<T*>(this)->WritableCallback();
158159
}

src/proxy.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
#include "./proxy.h"
33

4+
#include <cstdint>
5+
46
#include "./context.h"
57
#include "./module.h"
68
#include "./socket.h"
@@ -116,12 +118,12 @@ Napi::Value Proxy::Run(const Napi::CallbackInfo& info) {
116118
[this, run_ctx, front_ptr, back_ptr]() {
117119
/* Don't access V8 internals here! Executed in worker thread. */
118120
if (zmq_bind(control_sub, run_ctx->address.c_str()) < 0) {
119-
run_ctx->error = zmq_errno();
121+
run_ctx->error = static_cast<uint32_t>(zmq_errno());
120122
return;
121123
}
122124

123125
if (zmq_proxy_steerable(front_ptr, back_ptr, nullptr, control_sub) < 0) {
124-
run_ctx->error = zmq_errno();
126+
run_ctx->error = static_cast<uint32_t>(zmq_errno());
125127
return;
126128
}
127129
},
@@ -141,7 +143,8 @@ Napi::Value Proxy::Run(const Napi::CallbackInfo& info) {
141143
control_sub = nullptr;
142144

143145
if (run_ctx->error != 0) {
144-
res.Reject(ErrnoException(Env(), run_ctx->error).Value());
146+
res.Reject(
147+
ErrnoException(Env(), static_cast<int32_t>(run_ctx->error)).Value());
145148
return;
146149
}
147150

0 commit comments

Comments
 (0)