Skip to content

Commit ca8fd7e

Browse files
committed
Deprecate 'ulib_struct_init' in favor of 'ulib_zero_init'
1 parent 280c5b3 commit ca8fd7e

7 files changed

Lines changed: 23 additions & 16 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ list(APPEND ULIB_PRIVATE_DEFINES
9696
if(MSVC)
9797
set(ULIB_WARNING_OPTIONS /W4 /wd4200 /wd4996)
9898
else()
99-
set(ULIB_WARNING_OPTIONS -Wall -Wextra)
99+
set(ULIB_WARNING_OPTIONS -Wall -Wextra -Wpedantic)
100100
if(ULIB_SANITIZERS)
101101
set(ULIB_SANITIZER_OPTIONS "-fsanitize=address,undefined")
102102
endif()

include/uhash.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ ULIB_CONST ULIB_INLINE ulib_uint p_uhash_upper_bound_default(ulib_uint buckets)
286286
\
287287
ATTRS ULIB_INLINE UHash_##T uhash_move_##T(UHash_##T *h) { \
288288
UHash_##T temp = *h; \
289-
UHash_##T zero = ulib_struct_init; \
289+
UHash_##T zero = ulib_zero_init; \
290290
*h = zero; \
291291
return temp; \
292292
} \
@@ -321,7 +321,7 @@ ULIB_CONST ULIB_INLINE ulib_uint p_uhash_upper_bound_default(ulib_uint buckets)
321321
} \
322322
\
323323
ATTRS UHash_##T uhset_##T(void) { \
324-
UHash_##T h = ulib_struct_init; \
324+
UHash_##T h = ulib_zero_init; \
325325
return h; \
326326
}
327327

@@ -351,15 +351,15 @@ ULIB_CONST ULIB_INLINE ulib_uint p_uhash_upper_bound_default(ulib_uint buckets)
351351
} \
352352
\
353353
ATTRS UHash_##T uhset_##T(void) { \
354-
UHash_##T h = ulib_struct_init; \
354+
UHash_##T h = ulib_zero_init; \
355355
h._hfunc = default_hfunc; \
356356
h._efunc = default_efunc; \
357357
return h; \
358358
} \
359359
\
360360
ATTRS UHash_##T uhset_pi_##T(ulib_uint (*hash_func)(uh_key key), \
361361
bool (*equal_func)(uh_key lhs, uh_key rhs)) { \
362-
UHash_##T h = ulib_struct_init; \
362+
UHash_##T h = ulib_zero_init; \
363363
h._hfunc = hash_func; \
364364
h._efunc = equal_func; \
365365
return h; \
@@ -399,7 +399,7 @@ ULIB_CONST ULIB_INLINE ulib_uint p_uhash_upper_bound_default(ulib_uint buckets)
399399
ulib_free((void *)h->_keys); \
400400
ulib_free((void *)h->_vals); \
401401
ulib_free(h->_flags); \
402-
UHash_##T zero = ulib_struct_init; \
402+
UHash_##T zero = ulib_zero_init; \
403403
*h = zero; \
404404
} \
405405
\

include/ulog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ ULIB_CONST
459459
ULIB_INLINE
460460
ULogEvent p_ulog_event_f(ulog_level level, void const *data, char const *file_name,
461461
char const *func, int line) {
462-
ULogEvent event = ulib_struct_init;
462+
ULogEvent event = ulib_zero_init;
463463
event.data = data;
464464
event.level = level;
465465
event.loc.file = file_name;

include/uutils.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,22 @@
3939
*/
4040
#define ulib_array_count(array) (sizeof(array) / sizeof(*(array)))
4141

42-
/// C and C++ compatible struct initializer.
42+
/// C and C++ compatible zero initializer.
4343
// clang-format off
4444
#ifdef __cplusplus
45-
#define ulib_struct_init {}
45+
#define ulib_zero_init {}
4646
#else
47-
#define ulib_struct_init { 0 }
47+
#define ulib_zero_init { 0 }
4848
#endif
4949
// clang-format on
5050

51+
/**
52+
* C and C++ compatible struct initializer.
53+
*
54+
* @deprecated Use @val{ulib_zero_init} instead.
55+
*/
56+
#define ulib_struct_init ULIB_DEPRECATED_MACRO ulib_zero_init
57+
5158
/**
5259
* Concatenates the `a` and `b` tokens, allowing `a` and `b` to be macro-expanded.
5360
*

include/uvec.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ typedef enum uvec_ret {
202202
/* NOLINTBEGIN(clang-analyzer-unix.Malloc) */ \
203203
\
204204
ATTRS ULIB_CONST ULIB_INLINE UVec(T) uvec_##T(void) { \
205-
UVec(T) vec = ulib_struct_init; \
205+
UVec(T) vec = ulib_zero_init; \
206206
return vec; \
207207
} \
208208
\
@@ -263,13 +263,13 @@ typedef enum uvec_ret {
263263
return; \
264264
} \
265265
ulib_free((void *)vec->_l._data); \
266-
struct p_uvec_large_##T zero = ulib_struct_init; \
266+
struct p_uvec_large_##T zero = ulib_zero_init; \
267267
vec->_l = zero; \
268268
} \
269269
\
270270
ATTRS ULIB_INLINE UVec(T) uvec_move_##T(UVec(T) *vec) { \
271271
UVec(T) temp = *vec; \
272-
UVec(T) zero = ulib_struct_init; \
272+
UVec(T) zero = ulib_zero_init; \
273273
*vec = zero; \
274274
return temp; \
275275
} \

src/ulog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ ulib_ret ulog_write_newline(ULog *log) {
123123
}
124124

125125
ULog *p_ulog_main(void) {
126-
static ULog log = ulib_struct_init;
126+
static ULog log = ulib_zero_init;
127127
if (ulib_unlikely(!log.stream)) log = ulog_default();
128128
return &log;
129129
}

test/src/ustream_tests.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ void ustream_varint_test(void) {
249249
ulib_uint const max_value = ulib_min(ULIB_UINT_MAX >> 1U, 1000000);
250250
ulib_uint const increment = 999;
251251
ulib_uint value = 0;
252-
ulib_byte buffer[sizeof(value) + 1] = {};
252+
ulib_byte buffer[sizeof(value) + 1] = ulib_zero_init;
253253
size_t written = 0;
254254
size_t read = 0;
255255

@@ -275,7 +275,7 @@ void ustream_svarint_test(void) {
275275
int32_t const max_value = ulib_min(ULIB_UINT_MAX >> 2U, 500000);
276276
int32_t const increment = 999;
277277
ulib_int value = 0;
278-
ulib_byte buffer[sizeof(value) + 1] = {};
278+
ulib_byte buffer[sizeof(value) + 1] = ulib_zero_init;
279279
size_t written = 0;
280280
size_t read = 0;
281281

0 commit comments

Comments
 (0)