Skip to content

Commit 7c67e29

Browse files
committed
inline constexpr in protocol
+ fix warnings, and add noexcept
1 parent a56c631 commit 7c67e29

File tree

2 files changed

+80
-83
lines changed

2 files changed

+80
-83
lines changed

src/remote/protocol.cpp

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,29 @@ inline void DEBUG_XDR_FREE(RemoteXdr* xdrs, const void* xdrvar, const void* addr
6969
xdr_debug_memory(xdrs, XDR_DECODE, xdrvar, addr, len);
7070
}
7171
#else
72-
inline bool_t P_TRUE(RemoteXdr*, PACKET*)
72+
inline bool_t P_TRUE(RemoteXdr*, PACKET*) noexcept
7373
{
7474
return TRUE;
7575
}
76-
inline bool_t P_FALSE(RemoteXdr* xdrs, PACKET*)
76+
inline bool_t P_FALSE(RemoteXdr* xdrs, PACKET*) noexcept
7777
{
7878
return FALSE;
7979
}
80-
inline void DEBUG_XDR_PACKET(RemoteXdr*, PACKET*)
80+
inline void DEBUG_XDR_PACKET(RemoteXdr*, PACKET*) noexcept
8181
{
8282
}
83-
inline void DEBUG_XDR_ALLOC(RemoteXdr*, const void*, const void*, ULONG)
83+
inline void DEBUG_XDR_ALLOC(RemoteXdr*, const void*, const void*, ULONG) noexcept
8484
{
8585
}
86-
inline void DEBUG_XDR_FREE(RemoteXdr*, const void*, const void*, ULONG)
86+
inline void DEBUG_XDR_FREE(RemoteXdr*, const void*, const void*, ULONG) noexcept
8787
{
8888
}
8989
#endif // DEBUG_XDR_MEMORY
9090

9191
#define P_CHECK(xdr, p, st) if (st.getState() & IStatus::STATE_ERRORS) return P_FALSE(xdr, p)
9292

9393
#define MAP(routine, ptr) if (!routine (xdrs, &ptr)) return P_FALSE(xdrs, p);
94-
const ULONG MAX_OPAQUE = 32768;
94+
constexpr ULONG MAX_OPAQUE = 32768;
9595

9696
enum SQL_STMT_TYPE
9797
{
@@ -125,22 +125,22 @@ static Rsr* getStatement(RemoteXdr*, USHORT);
125125
static Rtr* getTransaction(RemoteXdr*, USHORT);
126126

127127

128-
inline void fixupLength(const RemoteXdr* xdrs, ULONG& length)
128+
inline void fixupLength(const RemoteXdr* xdrs, ULONG& length) noexcept
129129
{
130130
// If the short (16-bit) value >= 32KB is being transmitted,
131131
// it gets expanded to long (32-bit) with a sign bit propagated.
132132
// In order to avoid troubles when reading such a value as long,
133133
// let's detect and fix unexpected overflows. Here we assume
134134
// that real longs will never have the highest 16 bits set.
135135

136-
if (xdrs->x_op == XDR_DECODE && length >> 16 == (ULONG) 0xFFFF)
137-
length &= (ULONG) 0xFFFF;
136+
if (xdrs->x_op == XDR_DECODE && length >> 16 == ULONG{ 0xFFFF })
137+
length &= ULONG{ 0xFFFF };
138138
}
139139

140140

141141
#ifdef DEBUG
142142
static ULONG xdr_save_size = 0;
143-
inline void DEBUG_PRINTSIZE(RemoteXdr* xdrs, P_OP p)
143+
inline void DEBUG_PRINTSIZE(RemoteXdr* xdrs, P_OP p) noexcept
144144
{
145145
fprintf (stderr, "xdr_protocol: %s op %d size %lu\n",
146146
((xdrs->x_op == XDR_FREE) ? "free" :
@@ -150,7 +150,7 @@ inline void DEBUG_PRINTSIZE(RemoteXdr* xdrs, P_OP p)
150150
(xdrs->x_handy - xdr_save_size) : (xdr_save_size - xdrs->x_handy)));
151151
}
152152
#else
153-
inline void DEBUG_PRINTSIZE(RemoteXdr*, P_OP)
153+
inline void DEBUG_PRINTSIZE(RemoteXdr*, P_OP) noexcept
154154
{
155155
}
156156
#endif
@@ -467,7 +467,7 @@ bool_t xdr_protocol(RemoteXdr* xdrs, PACKET* p)
467467
case op_create_blob2:
468468
blob = &p->p_blob;
469469
MAP(xdr_cstring_const, blob->p_blob_bpb);
470-
// fall into:
470+
[[fallthrough]];
471471

472472
case op_open_blob:
473473
case op_create_blob:
@@ -702,7 +702,7 @@ bool_t xdr_protocol(RemoteXdr* xdrs, PACKET* p)
702702
if (port->port_protocol >= PROTOCOL_INLINE_BLOB)
703703
MAP(xdr_u_long, prep_stmt->p_sqlst_inline_blob_size);
704704

705-
// Fall into ...
705+
[[fallthrough]];
706706

707707
case op_exec_immediate:
708708
case op_prepare_statement:
@@ -882,7 +882,7 @@ bool_t xdr_protocol(RemoteXdr* xdrs, PACKET* p)
882882
return P_TRUE(xdrs, p);
883883
}
884884

885-
SSHORT statement_id = b->p_batch_statement;
885+
const SSHORT statement_id = b->p_batch_statement;
886886
Rsr* statement;
887887
if (statement_id >= 0)
888888
{
@@ -960,7 +960,7 @@ bool_t xdr_protocol(RemoteXdr* xdrs, PACKET* p)
960960
if (xdrs->x_op == XDR_FREE)
961961
return P_TRUE(xdrs, p);
962962

963-
SSHORT statement_id = b->p_batch_statement;
963+
const SSHORT statement_id = b->p_batch_statement;
964964
DEB_RBATCH(fprintf(stderr, "BatRem: xdr CS %d\n", statement_id));
965965
Rsr* statement;
966966

@@ -1195,17 +1195,14 @@ static bool_t xdr_bytes(RemoteXdr* xdrs, void* bytes, ULONG size)
11951195
switch (xdrs->x_op)
11961196
{
11971197
case XDR_ENCODE:
1198-
if (!xdrs->x_putbytes(reinterpret_cast<const SCHAR*>(bytes), size))
1199-
return FALSE;
1200-
break;
1198+
return xdrs->x_putbytes(static_cast<const SCHAR*>(bytes), size);
12011199

12021200
case XDR_DECODE:
1203-
if (!xdrs->x_getbytes(reinterpret_cast<SCHAR*>(bytes), size))
1204-
return FALSE;
1205-
break;
1206-
}
1201+
return xdrs->x_getbytes(static_cast<SCHAR*>(bytes), size);
12071202

1208-
return TRUE;
1203+
default:
1204+
return TRUE;
1205+
}
12091206
}
12101207

12111208

@@ -1338,7 +1335,7 @@ void CSTRING::free(RemoteXdr* xdrs)
13381335
}
13391336

13401337

1341-
static bool xdr_is_client(RemoteXdr* xdrs)
1338+
static bool xdr_is_client(RemoteXdr* xdrs) noexcept
13421339
{
13431340
const rem_port* port = xdrs->x_public;
13441341
return !(port->port_flags & PORT_server);
@@ -1376,7 +1373,7 @@ static inline bool_t xdr_response(RemoteXdr* xdrs, CSTRING* cstring)
13761373
{
13771374
if (xdr_is_client(xdrs) && xdrs->x_op == XDR_DECODE && cstring->cstr_allocated)
13781375
{
1379-
ULONG limit = cstring->cstr_allocated;
1376+
const ULONG limit = cstring->cstr_allocated;
13801377
cstring->cstr_allocated = 0;
13811378
return xdr_cstring_with_limit(xdrs, cstring, limit);
13821379
}
@@ -1641,17 +1638,17 @@ static bool_t xdr_packed_message( RemoteXdr* xdrs, RMessage* message, const rem_
16411638
resize(size);
16421639
}
16431640

1644-
void setNull(USHORT id)
1641+
void setNull(USHORT id) noexcept
16451642
{
16461643
data[id >> 3] |= (1 << (id & 7));
16471644
}
16481645

1649-
bool isNull(USHORT id) const
1646+
bool isNull(USHORT id) const noexcept
16501647
{
16511648
return data[id >> 3] & (1 << (id & 7));
16521649
}
16531650

1654-
UCHAR* getData()
1651+
UCHAR* getData() noexcept
16551652
{
16561653
return data;
16571654
}
@@ -2355,37 +2352,37 @@ static bool_t xdr_blob_stream(RemoteXdr* xdrs, SSHORT statement_id, CSTRING* str
23552352
ULONG& bpbSize;
23562353
ULONG& segSize;
23572354

2358-
BlobFlow(Rsr::BatchStream* bs)
2355+
BlobFlow(Rsr::BatchStream* bs) noexcept
23592356
: remains(0), streamPtr(NULL),
23602357
blobSize(bs->blobRemaining), bpbSize(bs->bpbRemaining), segSize(bs->segRemaining)
23612358
{ }
23622359

2363-
void newBlob(ULONG totalSize, ULONG parSize)
2360+
void newBlob(ULONG totalSize, ULONG parSize) noexcept
23642361
{
23652362
blobSize = totalSize;
23662363
bpbSize = parSize;
23672364
segSize = 0;
23682365
}
23692366

2370-
void move(ULONG step)
2367+
void move(ULONG step) noexcept
23712368
{
23722369
move2(step);
23732370
blobSize -= step;
23742371
}
23752372

2376-
void moveBpb(ULONG step)
2373+
void moveBpb(ULONG step) noexcept
23772374
{
23782375
move(step);
23792376
bpbSize -= step;
23802377
}
23812378

2382-
void moveSeg(ULONG step)
2379+
void moveSeg(ULONG step) noexcept
23832380
{
23842381
move(step);
23852382
segSize -= step;
23862383
}
23872384

2388-
bool align(ULONG alignment)
2385+
bool align(ULONG alignment) noexcept
23892386
{
23902387
ULONG a = IPTR(streamPtr) % alignment;
23912388
if (a)
@@ -2399,7 +2396,7 @@ static bool_t xdr_blob_stream(RemoteXdr* xdrs, SSHORT statement_id, CSTRING* str
23992396
}
24002397

24012398
private:
2402-
void move2(ULONG step)
2399+
void move2(ULONG step) noexcept
24032400
{
24042401
streamPtr += step;
24052402
remains -= step;
@@ -2491,7 +2488,7 @@ static bool_t xdr_blob_stream(RemoteXdr* xdrs, SSHORT statement_id, CSTRING* str
24912488
// process BPB
24922489
if (flow.bpbSize)
24932490
{
2494-
ULONG size = MIN(flow.bpbSize, flow.remains);
2491+
const ULONG size = std::min(flow.bpbSize, flow.remains);
24952492
if (!xdr_bytes(xdrs, flow.streamPtr, size))
24962493
return FALSE;
24972494
localStrm.curBpb.add(flow.streamPtr, size);

0 commit comments

Comments
 (0)