Skip to content

Commit 1909b7c

Browse files
committed
Remove unused argument from got/lost/update socket
Apart from just taking up "space" it also caused problems when building C++ wrapper.
1 parent 11a8e30 commit 1909b7c

File tree

8 files changed

+106
-90
lines changed

8 files changed

+106
-90
lines changed

core/pubnub_assert.h

Lines changed: 82 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* -*- c-file-style:"stroustrup"; indent-tabs-mode: nil -*- */
22
#if !defined INC_PUBNUB_ASSERT
3-
#define INC_PUBNUB_ASSERT
3+
#define INC_PUBNUB_ASSERT
44

55
#include <stdbool.h>
66

77

88
/** The Pubnub ASSERT macros. There are several layers:
9-
- highest (PUBNUB_ASSERT_LEVEL_EX): all checks enabled,
9+
- highest (PUBNUB_ASSERT_LEVEL_EX): all checks enabled,
1010
even the long lasting ones
1111
- regular (PUBNUB_ASSERT_LEVEL): only the long lasting
1212
checks are disabled
@@ -23,30 +23,28 @@
2323
* PUBNUB_ASSERT_LEVEL_NONE is defined.
2424
*/
2525

26-
#if defined(PUBNUB_ASSERT_LEVEL_EX) && ( \
27-
defined(PUBNUB_ASSERT_LEVEL) || defined(PUBNUB_ASSERT_LEVEL_OPT) || \
28-
defined(PUBNUB_ASSERT_LEVEL_NONE) )
29-
#error Cannott define PUBNUB_ASSERT_LEVEL_EX and any lower level (regular, _OPT, _NONE)
26+
#if defined(PUBNUB_ASSERT_LEVEL_EX) \
27+
&& (defined(PUBNUB_ASSERT_LEVEL) || defined(PUBNUB_ASSERT_LEVEL_OPT) \
28+
|| defined(PUBNUB_ASSERT_LEVEL_NONE))
29+
#error Cannot define PUBNUB_ASSERT_LEVEL_EX and any lower level (regular, _OPT, _NONE)
3030
#endif
3131

32-
#if defined(PUBNUB_ASSERT_LEVEL) && ( \
33-
defined(PUBNUB_ASSERT_LEVEL_OPT) || defined(PUBNUB_ASSERT_LEVEL_NONE) )
34-
#error Cannott define PUBNUB_ASSERT_LEVEL and any lower level (_OPT, _NONE)
32+
#if defined(PUBNUB_ASSERT_LEVEL) \
33+
&& (defined(PUBNUB_ASSERT_LEVEL_OPT) || defined(PUBNUB_ASSERT_LEVEL_NONE))
34+
#error Cannot define PUBNUB_ASSERT_LEVEL and any lower level (_OPT, _NONE)
3535
#endif
3636

3737

38-
#if defined(PUBNUB_ASSERT_LEVEL_OPT) && defined(PUBNUB_ASSERT_LEVEL_NONE)
39-
#error Cannott define PUBNUB_ASSERT_LEVEL_OPT and PUBNUB_ASSERT_LEVEL_NONE
38+
#if defined(PUBNUB_ASSERT_LEVEL_OPT) && defined(PUBNUB_ASSERT_LEVEL_NONE)
39+
#error Cannot define PUBNUB_ASSERT_LEVEL_OPT and PUBNUB_ASSERT_LEVEL_NONE
4040
#endif
4141

4242
/* If none of ASSERT level defining macros is defined, let's assume
4343
* the highest level.
4444
*/
4545

46-
#if !defined(PUBNUB_ASSERT_LEVEL_EX) && \
47-
!defined(PUBNUB_ASSERT_LEVEL) && \
48-
!defined(PUBNUB_ASSERT_LEVEL_OPT) && \
49-
!defined(PUBNUB_ASSERT_LEVEL_NONE)
46+
#if !defined(PUBNUB_ASSERT_LEVEL_EX) && !defined(PUBNUB_ASSERT_LEVEL) \
47+
&& !defined(PUBNUB_ASSERT_LEVEL_OPT) && !defined(PUBNUB_ASSERT_LEVEL_NONE)
5048
#define PUBNUB_ASSERT_LEVEL_EX
5149
#endif
5250

@@ -57,15 +55,19 @@
5755
#endif
5856

5957
/** The common ASSERT implementation */
60-
#define PUBNUB_ASSERT_IMPL(X) do { \
61-
PUBNUB_ANALYSIS_ASSUME(X); \
62-
(X) ? (void)0 : pubnub_assert_failed(#X, __FILE__, __LINE__); \
58+
#define PUBNUB_ASSERT_IMPL(X) \
59+
do { \
60+
PUBNUB_ANALYSIS_ASSUME(X); \
61+
(X) ? (void)0 : pubnub_assert_failed(#X, __FILE__, __LINE__); \
6362
} while (false)
6463

6564
/** Should make the compiler not report "unused variable"
6665
warnings.
6766
*/
68-
#define PUBNUB_UNUSED(x) do { (void)sizeof(x); } while (false)
67+
#define PUBNUB_UNUSED(x) \
68+
do { \
69+
(void)sizeof(x); \
70+
} while (false)
6971

7072

7173
/* Define the ASSERT macro for the highest (_EX) level.
@@ -76,10 +78,10 @@
7678
#define PUBNUB_ASSERT_EX(X) PUBNUB_UNUSED(X)
7779
#endif
7880

79-
/* Determine if regular level is to be used.
81+
/* Determine if regular level is to be used.
8082
*/
8183
#if defined(PUBNUB_ASSERT_LEVEL_EX) || defined(PUBNUB_ASSERT_LEVEL)
82-
#define PUBNUB_ASSERT_IS_ACTIVE // also usable directly in client code
84+
#define PUBNUB_ASSERT_IS_ACTIVE // also usable directly in client code
8385
#endif
8486

8587
/* Define the ASSERT macro for the regular level.
@@ -105,34 +107,46 @@
105107
106108
Users should use the "front-ends" for individual types.
107109
*/
108-
#define PUBNUB_ASSERT_RICH_IMPL(T, fmt, a, op, b) do { \
109-
T M_a_ = (a), M_b_ = (b); \
110-
int holds = M_a_ op M_b_; \
111-
PUBNUB_ANALYSIS_ASSUME(holds); \
112-
if (!holds) { \
113-
char s[300]; \
114-
snprintf(s, sizeof s, "`" #a " " #op " " #b "`; `" #a "`=" fmt ", `" #b "`=" fmt, M_a_, M_b_);\
115-
pubnub_assert_failed(s, __FILE__, __LINE__); \
116-
} \
110+
#define PUBNUB_ASSERT_RICH_IMPL(T, fmt, a, op, b) \
111+
do { \
112+
T M_a_ = (a), M_b_ = (b); \
113+
int holds = M_a_ op M_b_; \
114+
PUBNUB_ANALYSIS_ASSUME(holds); \
115+
if (!holds) { \
116+
char s[300]; \
117+
snprintf(s, \
118+
sizeof s, \
119+
"`" #a " " #op " " #b "`; `" #a "`=" fmt ", `" #b \
120+
"`=" fmt, \
121+
M_a_, \
122+
M_b_); \
123+
pubnub_assert_failed(s, __FILE__, __LINE__); \
124+
} \
117125
} while (false)
118126

119-
#define PUBNUB_ASSERT_INT_IMPL(a, op, b) PUBNUB_ASSERT_RICH_IMPL(int, "%d", a, op, b)
120-
#define PUBNUB_ASSERT_UINT_IMPL(a, op, b) PUBNUB_ASSERT_RICH_IMPL(unsigned, "%u", a, op, b)
127+
#define PUBNUB_ASSERT_INT_IMPL(a, op, b) \
128+
PUBNUB_ASSERT_RICH_IMPL(int, "%d", a, op, b)
129+
#define PUBNUB_ASSERT_UINT_IMPL(a, op, b) \
130+
PUBNUB_ASSERT_RICH_IMPL(unsigned, "%u", a, op, b)
121131

122132
/* Define the ASSERT_INT macro for the highest (_EX) level.
123133
*/
124134
#if defined PUBNUB_ASSERT_LEVEL_EX
125135
#define PUBNUB_ASSERT_INT_EX(a, op, b) PUBNUB_ASSERT_INT_IMPL(a, op, b)
126136
#else
127-
#define PUBNUB_ASSERT_INT_EX(a, op, b) PUBNUB_UNUSED(a); PUBNUB_UNUSED(b)
137+
#define PUBNUB_ASSERT_INT_EX(a, op, b) \
138+
PUBNUB_UNUSED(a); \
139+
PUBNUB_UNUSED(b)
128140
#endif
129141

130142
/* Define the ASSERT_INT macro for the regular level.
131143
*/
132144
#if defined(PUBNUB_ASSERT_IS_ACTIVE)
133145
#define PUBNUB_ASSERT_INT(a, op, b) PUBNUB_ASSERT_INT_IMPL(a, op, b)
134146
#else
135-
#define PUBNUB_ASSERT_INT(a, op, b) PUBNUB_UNUSED(a); PUBNUB_UNUSED(b)
147+
#define PUBNUB_ASSERT_INT(a, op, b) \
148+
PUBNUB_UNUSED(a); \
149+
PUBNUB_UNUSED(b)
136150
#endif
137151

138152

@@ -141,7 +155,9 @@
141155
#if !defined(PUBNUB_ASSERT_LEVEL_NONE)
142156
#define PUBNUB_ASSERT_INT_OPT(a, op, b) PUBNUB_ASSERT_INT_IMPL(a, op, b)
143157
#else
144-
#define PUBNUB_ASSERT_INT_OPT(a, op, b) PUBNUB_UNUSED(a); PUBNUB_UNUSED(b)
158+
#define PUBNUB_ASSERT_INT_OPT(a, op, b) \
159+
PUBNUB_UNUSED(a); \
160+
PUBNUB_UNUSED(b)
145161
#endif
146162

147163

@@ -150,15 +166,19 @@
150166
#if defined PUBNUB_ASSERT_LEVEL_EX
151167
#define PUBNUB_ASSERT_UINT_EX(a, op, b) PUBNUB_ASSERT_UINT_IMPL(a, op, b)
152168
#else
153-
#define PUBNUB_ASSERT_UINT_EX(a, op, b) PUBNUB_UNUSED(a); PUBNUB_UNUSED(b)
169+
#define PUBNUB_ASSERT_UINT_EX(a, op, b) \
170+
PUBNUB_UNUSED(a); \
171+
PUBNUB_UNUSED(b)
154172
#endif
155173

156174
/* Define the ASSERT_UINT macro for the regular level.
157175
*/
158176
#if defined(PUBNUB_ASSERT_IS_ACTIVE)
159177
#define PUBNUB_ASSERT_UINT(a, op, b) PUBNUB_ASSERT_UINT_IMPL(a, op, b)
160178
#else
161-
#define PUBNUB_ASSERT_UINT(a, op, b) PUBNUB_UNUSED(a); PUBNUB_UNUSED(b)
179+
#define PUBNUB_ASSERT_UINT(a, op, b) \
180+
PUBNUB_UNUSED(a); \
181+
PUBNUB_UNUSED(b)
162182
#endif
163183

164184

@@ -167,7 +187,9 @@
167187
#if !defined(PUBNUB_ASSERT_LEVEL_NONE)
168188
#define PUBNUB_ASSERT_UINT_OPT(a, op, b) PUBNUB_ASSERT_UINT_IMPL(a, op, b)
169189
#else
170-
#define PUBNUB_ASSERT_UINT_OPT(a, op, b) PUBNUB_UNUSED(a); PUBNUB_UNUSED(b)
190+
#define PUBNUB_ASSERT_UINT_OPT(a, op, b) \
191+
PUBNUB_UNUSED(a); \
192+
PUBNUB_UNUSED(b)
171193
#endif
172194

173195

@@ -182,15 +204,17 @@
182204
/** This will invoke the installed assert handler. The default
183205
behavior is pubnub_assert_handler_abort().
184206
*/
185-
void PUBNUB_NORETURN pubnub_assert_failed(char const *s, char const *file, long line);
207+
void PUBNUB_NORETURN pubnub_assert_failed(char const* s, char const* file, long line);
186208

187209
/** Prototype of a Pubnub assertion failure handler. There are several
188210
standard handlers, but you can also provide your own.
189211
@param s The string that defines the failure condition
190212
@param file The name of the source file with the condition
191213
@param line Number of the line of @c file with the condition
192214
*/
193-
typedef void PUBNUB_NORETURN (*pubnub_assert_handler_t)(char const *s, char const *file, long line);
215+
typedef void PUBNUB_NORETURN (*pubnub_assert_handler_t)(char const* s,
216+
char const* file,
217+
long line);
194218

195219
/** This will install an assert handler. It can be one of the standard
196220
ones, or your own.
@@ -203,12 +227,16 @@ void pubnub_assert_set_handler(pubnub_assert_handler_t handler);
203227
/** This handler will print a message formed from the parameters and
204228
then go to infinite loop. Useful for debugging.
205229
*/
206-
void PUBNUB_NORETURN pubnub_assert_handler_loop(char const *s, char const *file, long line);
230+
void PUBNUB_NORETURN pubnub_assert_handler_loop(char const* s,
231+
char const* file,
232+
long line);
207233

208234
/** This handler will print a message formed from the parameters and
209235
then abort (exit, end) the process. Useful for testing.
210236
*/
211-
void PUBNUB_NORETURN pubnub_assert_handler_abort(char const *s, char const *file, long line);
237+
void PUBNUB_NORETURN pubnub_assert_handler_abort(char const* s,
238+
char const* file,
239+
long line);
212240

213241
/** This handler will print a message formed from the parameters and
214242
that's it. Useful for getting data from a program execution "in
@@ -222,27 +250,28 @@ void PUBNUB_NORETURN pubnub_assert_handler_abort(char const *s, char const *file
222250
"noreturn" attribute (and we know that and use it), you'll get a
223251
warning or error and will need to ignore or disable it.
224252
*/
225-
void pubnub_assert_handler_printf(char const *s, char const *file, long line);
253+
void pubnub_assert_handler_printf(char const* s, char const* file, long line);
226254

227255

228-
#define PUBNUB_CTASRT2(pre,post,lex) pre ## post ## lex
229-
#define PUBNUB_CTASRT(pre,post,lex) PUBNUB_CTASRT2(pre,post,lex)
256+
#define PUBNUB_CTASRT2(pre, post, lex) pre##post##lex
257+
#define PUBNUB_CTASRT(pre, post, lex) PUBNUB_CTASRT2(pre, post, lex)
230258

231259
#if !defined __has_feature
232260
#define __has_feature(x) 0
233261
#endif
234262

235-
#if __has_feature(c_static_assert) || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L))
263+
#if __has_feature(c_static_assert) \
264+
|| (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L))
236265

237266
/* Delegate to C11 static assert */
238-
#define PUBNUB_STATIC_ASSERT(cond,msg) _Static_assert((cond), #msg)
267+
#define PUBNUB_STATIC_ASSERT(cond, msg) _Static_assert((cond), #msg)
239268

240269
#elif (defined(_MSC_VER)) && (_MSC_VER >= 1600)
241270

242271
/* This compiler doesn't implement the standard `_Static_assert`, but
243272
does the `static_assert`, "w/out the middleman".
244273
*/
245-
#define PUBNUB_STATIC_ASSERT(cond,msg) static_assert((cond), #msg)
274+
#define PUBNUB_STATIC_ASSERT(cond, msg) static_assert((cond), #msg)
246275

247276
#else
248277

@@ -254,9 +283,11 @@ void pubnub_assert_handler_printf(char const *s, char const *file, long line);
254283
@param msg A message "disguised" as an identifier. So, instead of
255284
`"unknown value"`, use `unknown_value`
256285
*/
257-
#define PUBNUB_STATIC_ASSERT(cond,msg) \
258-
extern struct { int PUBNUB_CTASRT(static_assert, _failed_, msg) : !!(cond); } \
259-
PUBNUB_CTASRT(static_assert_failed_, msg, __LINE__)
286+
#define PUBNUB_STATIC_ASSERT(cond, msg) \
287+
extern struct PUBNUB_CTASRT(static_assert, _failed_, msg) { \
288+
int PUBNUB_CTASRT(static_assert, _failed_, msg) \
289+
: !!(cond); \
290+
} PUBNUB_CTASRT(static_assert_failed_, msg, __LINE__)
260291

261292
#endif
262293

core/pubnub_internal_common.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,11 @@ void pbntf_trans_outcome(pubnub_t *pb);
318318

319319
int pbntf_init(void);
320320

321-
int pbntf_got_socket(pubnub_t *pb, pb_socket_t socket);
321+
int pbntf_got_socket(pubnub_t *pb);
322322

323-
void pbntf_update_socket(pubnub_t *pb, pb_socket_t socket);
323+
void pbntf_update_socket(pubnub_t *pb);
324324

325-
void pbntf_lost_socket(pubnub_t *pb, pb_socket_t socket);
325+
void pbntf_lost_socket(pubnub_t *pb);
326326

327327
int pbntf_enqueue_for_processing(pubnub_t *pb);
328328

core/pubnub_netcore.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static void outcome_detected(struct pubnub_* pb, enum pubnub_res rslt)
5757
we don't have a way to report to the user that the
5858
connection was lost.
5959
*/
60-
pbntf_lost_socket(pb, pb->pal.socket);
60+
pbntf_lost_socket(pb);
6161
pbntf_trans_outcome(pb);
6262
pb->state = PBS_KEEP_ALIVE_IDLE;
6363
}
@@ -314,7 +314,7 @@ int pbnc_fsm(struct pubnub_* pb)
314314
pbntf_trans_outcome(pb);
315315
return 0;
316316
}
317-
i = pbntf_got_socket(pb, pb->pal.socket);
317+
i = pbntf_got_socket(pb);
318318
if (0 == i) {
319319
goto next_state;
320320
}
@@ -333,12 +333,12 @@ int pbnc_fsm(struct pubnub_* pb)
333333
break;
334334
case pbpal_resolv_sent:
335335
case pbpal_resolv_rcv_wouldblock:
336-
pbntf_update_socket(pb, pb->pal.socket);
336+
pbntf_update_socket(pb);
337337
pb->state = PBS_WAIT_DNS_RCV;
338338
pbntf_watch_in_events(pb);
339339
break;
340340
case pbpal_connect_wouldblock:
341-
pbntf_update_socket(pb, pb->pal.socket);
341+
pbntf_update_socket(pb);
342342
pb->state = PBS_WAIT_CONNECT;
343343
break;
344344
case pbpal_connect_success:
@@ -362,7 +362,7 @@ int pbnc_fsm(struct pubnub_* pb)
362362
case pbpal_resolv_rcv_wouldblock:
363363
break;
364364
case pbpal_connect_wouldblock:
365-
pbntf_update_socket(pb, pb->pal.socket);
365+
pbntf_update_socket(pb);
366366
pb->state = PBS_WAIT_CONNECT;
367367
pbntf_watch_out_events(pb);
368368
break;
@@ -882,7 +882,7 @@ int pbnc_fsm(struct pubnub_* pb)
882882
}
883883
break;
884884
case PBS_KEEP_ALIVE_READY:
885-
i = pbntf_got_socket(pb, pb->pal.socket);
885+
i = pbntf_got_socket(pb);
886886
if (i < 0) {
887887
pb->core.last_result = PNR_CONNECT_FAILED;
888888
pbntf_trans_outcome(pb);
@@ -891,14 +891,14 @@ int pbnc_fsm(struct pubnub_* pb)
891891
#if PUBNUB_ADVANCED_KEEP_ALIVE
892892
if ((++pb->keep_alive.count >= pb->keep_alive.max)
893893
|| ((time(NULL) - pb->keep_alive.t_connect) > pb->keep_alive.timeout)) {
894-
pbntf_lost_socket(pb, pb->pal.socket);
894+
pbntf_lost_socket(pb);
895895
pb->state = PBS_READY;
896896
goto next_state;
897897
}
898898
#endif
899899
i = send_init_GET_or_CONNECT(pb);
900900
if (i < 0) {
901-
pbntf_lost_socket(pb, pb->pal.socket);
901+
pbntf_lost_socket(pb);
902902
pb->state = PBS_READY;
903903
}
904904
else {

core/pubnub_ntf_sync.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,23 @@ int pbntf_init(void)
1515
}
1616

1717

18-
int pbntf_got_socket(pubnub_t *pb, pb_socket_t socket)
18+
int pbntf_got_socket(pubnub_t *pb)
1919
{
20-
PUBNUB_UNUSED(socket);
2120
if (PUBNUB_BLOCKING_IO_SETTABLE) {
2221
pbpal_set_blocking_io(pb);
2322
}
2423
return +1;
2524
}
2625

2726

28-
void pbntf_update_socket(pubnub_t *pb, pb_socket_t socket)
27+
void pbntf_update_socket(pubnub_t *pb)
2928
{
30-
PUBNUB_UNUSED(socket);
3129
PUBNUB_UNUSED(pb);
3230
}
3331

3432

35-
void pbntf_lost_socket(pubnub_t *pb, pb_socket_t socket)
33+
void pbntf_lost_socket(pubnub_t *pb)
3634
{
37-
PUBNUB_UNUSED(socket);
3835
PUBNUB_UNUSED(pb);
3936
}
4037

0 commit comments

Comments
 (0)