Skip to content

Commit cdcd38a

Browse files
UDF Wrappers headers made clang-tidy warning-free
Removed some outdated Clang 5 warning suppressions.
1 parent 281e4bf commit cdcd38a

File tree

5 files changed

+68
-66
lines changed

5 files changed

+68
-66
lines changed

include/mysqlpp/udf_context.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class udf_context {
9494
}
9595

9696
void mark_arg_nullable(std::size_t index, bool nullable) noexcept {
97-
args_->maybe_null[index] = (nullable ? 1 : 0);
97+
args_->maybe_null[index] = (nullable ? '\1' : '\0');
9898
}
9999

100100
void mark_result_nullable(bool nullable) noexcept {

include/mysqlpp/udf_context_charset_extension.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,17 @@ class udf_context_charset_extension {
4646
const char *get_return_value_charset(const udf_context &ctx) const {
4747
void *output = nullptr;
4848
if (udf_metadata_service_->result_get(ctx.initid_, charset_attribute_name,
49-
&output))
49+
&output) != 0)
5050
throw std::runtime_error{"cannot get return value character set"};
5151

5252
return static_cast<char *>(output);
5353
}
5454

5555
void set_return_value_charset(udf_context &ctx, const char *charset) const {
56+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
5657
void *cs = const_cast<char *>(charset);
5758
if (udf_metadata_service_->result_set(ctx.initid_, charset_attribute_name,
58-
cs))
59+
cs) != 0)
5960
throw std::runtime_error{"cannot set return value character set"};
6061
}
6162

@@ -66,38 +67,40 @@ class udf_context_charset_extension {
6667
"cannot get character set of a non-string argument"};
6768

6869
if (udf_metadata_service_->argument_get(ctx.args_, charset_attribute_name,
69-
index, &output))
70+
index, &output) != 0)
7071
throw std::runtime_error{"cannot get argument character set"};
7172

7273
return static_cast<char *>(output);
7374
}
7475

7576
void set_arg_value_charset(udf_context &ctx, std::size_t index,
7677
const char *charset) const {
78+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
7779
void *cs = const_cast<char *>(charset);
7880
if (ctx.args_->arg_type[index] != STRING_RESULT)
7981
throw std::runtime_error{
8082
"cannot set character set of a non-string argument"};
8183

8284
if (udf_metadata_service_->argument_set(ctx.args_, charset_attribute_name,
83-
index, cs))
85+
index, cs) != 0)
8486
throw std::runtime_error{"cannot set argument value character set"};
8587
}
8688

8789
const char *get_return_value_collation(const udf_context &ctx) const {
8890
void *output = nullptr;
8991
if (udf_metadata_service_->result_get(ctx.initid_, collation_attribute_name,
90-
&output))
92+
&output) != 0)
9193
throw std::runtime_error{"cannot get return value collation"};
9294

9395
return static_cast<char *>(output);
9496
}
9597

9698
void set_return_value_collation(udf_context &ctx,
9799
const char *collation) const {
100+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
98101
void *cs = const_cast<char *>(collation);
99102
if (udf_metadata_service_->result_set(ctx.initid_, collation_attribute_name,
100-
cs))
103+
cs) != 0)
101104
throw std::runtime_error{"cannot set return value collation"};
102105
}
103106

@@ -108,20 +111,21 @@ class udf_context_charset_extension {
108111
throw std::runtime_error{"cannot get collation of a non-string argument"};
109112

110113
if (udf_metadata_service_->argument_get(ctx.args_, collation_attribute_name,
111-
index, &output))
114+
index, &output) != 0)
112115
throw std::runtime_error{"cannot get argument collation"};
113116

114117
return static_cast<char *>(output);
115118
}
116119

117120
void set_arg_value_collation(udf_context &ctx, std::size_t index,
118121
const char *collation) const {
122+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
119123
void *cs = const_cast<char *>(collation);
120124
if (ctx.args_->arg_type[index] != STRING_RESULT)
121125
throw std::runtime_error{"cannot set collation of a non-string argument"};
122126

123127
if (udf_metadata_service_->argument_set(ctx.args_, collation_attribute_name,
124-
index, cs))
128+
index, cs) != 0)
125129
throw std::runtime_error{"cannot set argument value collation"};
126130
}
127131

include/mysqlpp/udf_registration.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <bitset>
2222
#include <chrono>
2323
#include <cstddef>
24+
#include <memory>
2425
#include <thread>
2526

2627
#include <mysql/components/service.h>
@@ -127,9 +128,11 @@ void unregister_udfs(SERVICE_TYPE(udf_registration) * service,
127128

128129
} // namespace mysqlpp
129130

131+
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
130132
#define DECLARE_UDF_INFO(NAME, TYPE) \
131133
mysqlpp::udf_info { \
132-
#NAME, TYPE, (Udf_func_any)&NAME, &NAME##_init, &NAME##_deinit \
134+
#NAME, TYPE, (Udf_func_any)std::addressof(NAME), \
135+
std::addressof(NAME##_init), std::addressof(NAME##_deinit) \
133136
}
134137

135138
// A simplified version of the DECLARE_UDF_INFO macro that relies on the
@@ -138,5 +141,6 @@ void unregister_udfs(SERVICE_TYPE(udf_registration) * service,
138141
#define DECLARE_UDF_INFO_AUTO(NAME) \
139142
DECLARE_UDF_INFO(NAME, \
140143
::mysqlpp::udf_impl_meta_info<NAME##_impl>::item_result)
144+
// NOLINTEND(cppcoreguidelines-macro-usage)
141145

142146
#endif

include/mysqlpp/udf_traits.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ struct wrapped_t {
3434

3535
template <typename MixinType, typename ImplType>
3636
struct impl_with_mixin : public MixinType {
37-
impl_with_mixin(udf_context &ctx) : MixinType{}, impl{ctx} {}
37+
explicit impl_with_mixin(udf_context &ctx) : MixinType{}, impl{ctx} {}
38+
// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
3839
ImplType impl;
3940
};
4041

include/mysqlpp/udf_wrappers.hpp

Lines changed: 48 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <cassert>
2121
#include <cstring>
2222
#include <exception>
23+
#include <memory>
2324
#include <stdexcept>
2425
#include <string>
2526
#include <type_traits>
@@ -54,7 +55,7 @@ class udf_base {
5455
static const char *get_function_label(std::string &buffer,
5556
const char *meta_name,
5657
item_result_type item_result) noexcept {
57-
const char *res = "<function_name>";
58+
const char *res{nullptr};
5859
try {
5960
buffer = meta_name;
6061
buffer += '<';
@@ -63,6 +64,7 @@ class udf_base {
6364
buffer += '>';
6465
res = buffer.c_str();
6566
} catch (...) {
67+
res = "<function_name>";
6668
}
6769
return res;
6870
}
@@ -72,20 +74,11 @@ class udf_base {
7274
assert(error_reporter != nullptr);
7375
std::string buffer;
7476
try {
75-
// The following suppression is needed exclusively for Clang 5.0 that
76-
// has a bug in noexcept specification diagnostics.
77-
#if defined(__clang__) && (__clang_major__ == 5)
78-
#pragma clang diagnostic push
79-
#pragma clang diagnostic ignored "-Wexceptions"
80-
#endif
8177
// Rethrowing the exception that was previously caught with
8278
// 'catch(...)' in one of the derived classes
8379
// This is done to write the sequence of the catch blocks
8480
// in one place.
8581
throw;
86-
#if defined(__clang__) && (__clang_major__ == 5)
87-
#pragma clang diagnostic pop
88-
#endif
8982
} catch (const udf_exception &e) {
9083
if (e.has_error_code()) {
9184
auto error_code = e.get_error_code();
@@ -116,20 +109,11 @@ class udf_base {
116109
static void handle_init_exception(char *message,
117110
std::size_t message_size) noexcept {
118111
try {
119-
// The following suppression is needed exclusively for Clang 5.0 that
120-
// has a bug in noexcept specification diagnostics
121-
#if defined(__clang__) && (__clang_major__ == 5)
122-
#pragma clang diagnostic push
123-
#pragma clang diagnostic ignored "-Wexceptions"
124-
#endif
125112
// Rethrowing the exception that was previously caught with
126113
// 'catch(...)' in one of the derived classes
127114
// This is done to write the sequence of the catch blocks
128115
// in one place.
129116
throw;
130-
#if defined(__clang__) && (__clang_major__ == 5)
131-
#pragma clang diagnostic pop
132-
#endif
133117
} catch (const std::exception &e) {
134118
std::strncpy(message, e.what(), message_size);
135119
message[message_size - 1] = '\0';
@@ -155,18 +139,21 @@ class generic_udf_base : private udf_base {
155139
udf_context udf_ctx{initid, args};
156140
extended_impl_t *impl = nullptr;
157141
try {
142+
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
158143
impl = new extended_impl_t{udf_ctx};
159144
} catch (...) {
160145
handle_init_exception(message, MYSQL_ERRMSG_SIZE);
161146
return true;
162147
}
163148

149+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
164150
initid->ptr = reinterpret_cast<char *>(impl);
165151

166152
return false;
167153
}
168154

169155
static void deinit(UDF_INIT *initid) noexcept {
156+
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
170157
delete get_extended_impl_from_udf_initid(initid);
171158
}
172159

@@ -175,6 +162,7 @@ class generic_udf_base : private udf_base {
175162

176163
static extended_impl_t *get_extended_impl_from_udf_initid(
177164
UDF_INIT *initid) noexcept {
165+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
178166
return reinterpret_cast<extended_impl_t *>(initid->ptr);
179167
}
180168
};
@@ -207,12 +195,11 @@ class generic_udf<ImplType, STRING_RESULT>
207195
assert(udf_ctx.is_result_nullabale());
208196
*is_null = 1;
209197
return nullptr;
210-
} else {
211-
*is_null = 0;
212-
extended_impl.mixin = std::move(res.value());
213-
*length = extended_impl.mixin.size();
214-
return const_cast<char *>(extended_impl.mixin.c_str());
215198
}
199+
*is_null = 0;
200+
extended_impl.mixin = std::move(*res);
201+
*length = extended_impl.mixin.size();
202+
return const_cast<char *>(extended_impl.mixin.c_str());
216203
}
217204
};
218205

@@ -240,10 +227,9 @@ class generic_udf<ImplType, REAL_RESULT>
240227
assert(udf_ctx.is_result_nullabale());
241228
*is_null = 1;
242229
return 0.0;
243-
} else {
244-
*is_null = 0;
245-
return res.value();
246230
}
231+
*is_null = 0;
232+
return *res;
247233
}
248234
};
249235

@@ -271,15 +257,15 @@ class generic_udf<ImplType, INT_RESULT>
271257
assert(udf_ctx.is_result_nullabale());
272258
*is_null = 1;
273259
return 0;
274-
} else {
275-
*is_null = 0;
276-
return res.value();
277260
}
261+
*is_null = 0;
262+
return *res;
278263
}
279264
};
280265

281266
} // namespace mysqlpp
282267

268+
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
283269
#define DECLARE_UDF_META_INFO(IMPL, RESULT_TYPE, NAME) \
284270
namespace mysqlpp { \
285271
template <> \
@@ -290,40 +276,44 @@ class generic_udf<ImplType, INT_RESULT>
290276
}; \
291277
}
292278

293-
#define DECLARE_UDF_INIT(IMPL, RESULT_TYPE, NAME) \
294-
MYSQLPP_UDF_EXPORT \
295-
bool NAME##_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { \
296-
static_assert(std::is_same_v<decltype(&NAME##_init), Udf_func_init>, \
297-
"Invalid UDF init function signature"); \
298-
return mysqlpp::generic_udf<IMPL, RESULT_TYPE>::init(initid, args, \
299-
message); \
279+
#define DECLARE_UDF_INIT(IMPL, RESULT_TYPE, NAME) \
280+
MYSQLPP_UDF_EXPORT \
281+
bool NAME##_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { \
282+
static_assert( \
283+
std::is_same_v<decltype(std::addressof(NAME##_init)), Udf_func_init>, \
284+
"Invalid UDF init function signature"); \
285+
return mysqlpp::generic_udf<IMPL, RESULT_TYPE>::init(initid, args, \
286+
message); \
300287
}
301288

302-
#define DECLARE_UDF_DEINIT(IMPL, RESULT_TYPE, NAME) \
303-
MYSQLPP_UDF_EXPORT \
304-
void NAME##_deinit(UDF_INIT *initid) { \
305-
static_assert(std::is_same_v<decltype(&NAME##_deinit), Udf_func_deinit>, \
306-
"Invalid UDF deinit function signature"); \
307-
mysqlpp::generic_udf<IMPL, RESULT_TYPE>::deinit(initid); \
289+
#define DECLARE_UDF_DEINIT(IMPL, RESULT_TYPE, NAME) \
290+
MYSQLPP_UDF_EXPORT \
291+
void NAME##_deinit(UDF_INIT *initid) { \
292+
static_assert(std::is_same_v<decltype(std::addressof(NAME##_deinit)), \
293+
Udf_func_deinit>, \
294+
"Invalid UDF deinit function signature"); \
295+
mysqlpp::generic_udf<IMPL, RESULT_TYPE>::deinit(initid); \
308296
}
309297

310-
#define DECLARE_UDF_STRING_FUNC(IMPL, NAME) \
311-
MYSQLPP_UDF_EXPORT \
312-
char *NAME(UDF_INIT *initid, UDF_ARGS *args, char *result, \
313-
unsigned long *length, unsigned char *is_null, \
314-
unsigned char *error) { \
315-
static_assert(std::is_same_v<decltype(&NAME), Udf_func_string>, \
316-
"Invalid string UDF function signature"); \
317-
return mysqlpp::generic_udf<IMPL, STRING_RESULT>::func( \
318-
initid, args, result, length, is_null, error); \
298+
#define DECLARE_UDF_STRING_FUNC(IMPL, NAME) \
299+
MYSQLPP_UDF_EXPORT \
300+
char *NAME(UDF_INIT *initid, UDF_ARGS *args, char *result, \
301+
unsigned long *length, unsigned char *is_null, \
302+
unsigned char *error) { \
303+
static_assert( \
304+
std::is_same_v<decltype(std::addressof(NAME)), Udf_func_string>, \
305+
"Invalid string UDF function signature"); \
306+
return mysqlpp::generic_udf<IMPL, STRING_RESULT>::func( \
307+
initid, args, result, length, is_null, error); \
319308
}
320309

321310
#define DECLARE_UDF_REAL_FUNC(IMPL, NAME) \
322311
MYSQLPP_UDF_EXPORT \
323312
double NAME(UDF_INIT *initid, UDF_ARGS *args, unsigned char *is_null, \
324313
unsigned char *error) { \
325-
static_assert(std::is_same_v<decltype(&NAME), Udf_func_double>, \
326-
"Invalid real UDF function signature"); \
314+
static_assert( \
315+
std::is_same_v<decltype(std::addressof(NAME)), Udf_func_double>, \
316+
"Invalid real UDF function signature"); \
327317
return mysqlpp::generic_udf<IMPL, REAL_RESULT>::func(initid, args, \
328318
is_null, error); \
329319
}
@@ -332,7 +322,8 @@ class generic_udf<ImplType, INT_RESULT>
332322
MYSQLPP_UDF_EXPORT \
333323
long long NAME(UDF_INIT *initid, UDF_ARGS *args, unsigned char *is_null, \
334324
unsigned char *error) { \
335-
static_assert(std::is_same<decltype(&NAME), Udf_func_longlong>::value, \
325+
static_assert(std::is_same<decltype(std::addressof(NAME)), \
326+
Udf_func_longlong>::value, \
336327
"Invalid int UDF function signature"); \
337328
return mysqlpp::generic_udf<IMPL, INT_RESULT>::func(initid, args, is_null, \
338329
error); \
@@ -363,4 +354,6 @@ class generic_udf<ImplType, INT_RESULT>
363354
#define DECLARE_REAL_UDF_AUTO(NAME) DECLARE_REAL_UDF(NAME##_impl, NAME)
364355
#define DECLARE_INT_UDF_AUTO(NAME) DECLARE_INT_UDF(NAME##_impl, NAME)
365356

357+
// NOLINTEND(cppcoreguidelines-macro-usage)
358+
366359
#endif

0 commit comments

Comments
 (0)