1 From c657a1973e274b16db0631dc3862e276ab354564 Mon Sep 17 00:00:00 2001
2 From: Ruoyu Zhong <zhongruoyu@outlook.com>
3 Date: Sat, 19 Aug 2023 22:48:16 +0800
4 Subject: [PATCH 1/2] MDEV-31963 cmake: fix libfmt usage
6 `fmt::detail::make_arg` does not accept temporaries, so the code snippet
7 checking system libfmt needs to be adjusted.
9 Signed-off-by: Ruoyu Zhong <zhongruoyu@outlook.com>
11 cmake/libfmt.cmake | 3 ++-
12 1 file changed, 2 insertions(+), 1 deletion(-)
14 --- a/cmake/libfmt.cmake
15 +++ b/cmake/libfmt.cmake
16 @@ -33,8 +33,9 @@ MACRO (CHECK_LIBFMT)
17 #include <fmt/format-inl.h>
21 fmt::format_args::format_arg arg=
22 - fmt::detail::make_arg<fmt::format_context>(42);
23 + fmt::detail::make_arg<fmt::format_context>(answer);
24 std::cout << fmt::vformat(\"The answer is {}.\",
25 fmt::format_args(&arg, 1));
26 }" HAVE_SYSTEM_LIBFMT)
27 --- a/sql/item_strfunc.cc
28 +++ b/sql/item_strfunc.cc
29 @@ -1382,11 +1382,24 @@ namespace fmt {
31 String *Item_func_sformat::val_str(String *res)
34 + A union that stores a numeric format arg value.
35 + fmt::detail::make_arg does not accept temporaries, so all of its numeric
36 + args are temporarily stored in the fmt_args array.
37 + See: https://github.com/fmtlib/fmt/issues/3596
39 + union Format_arg_store {
46 - using ctx= fmt::format_context;
47 - String *fmt_arg= NULL;
49 - fmt::format_args::format_arg *vargs= NULL;
50 + using ctx= fmt::format_context;
51 + String *fmt_arg= NULL;
53 + fmt::format_args::format_arg *vargs= NULL;
54 + Format_arg_store *fmt_args= NULL;
57 if (!(fmt_arg= args[0]->val_str(res)))
58 @@ -1395,25 +1408,39 @@ String *Item_func_sformat::val_str(Strin
59 if (!(vargs= new fmt::format_args::format_arg[arg_count - 1]))
62 + if (!(fmt_args= new Format_arg_store[arg_count - 1]))
68 /* Creates the array of arguments for vformat */
69 for (uint carg= 1; carg < arg_count; carg++)
71 switch (args[carg]->result_type())
74 - vargs[carg-1]= fmt::detail::make_arg<ctx>(args[carg]->val_int());
75 + fmt_args[carg-1].val_int= args[carg]->val_int();
76 + vargs[carg-1]= fmt::detail::make_arg<ctx>(fmt_args[carg-1].val_int);
78 case DECIMAL_RESULT: // TODO
80 if (args[carg]->field_type() == MYSQL_TYPE_FLOAT)
81 - vargs[carg-1]= fmt::detail::make_arg<ctx>((float)args[carg]->val_real());
83 + fmt_args[carg-1].val_float= (float)args[carg]->val_real();
84 + vargs[carg-1]= fmt::detail::make_arg<ctx>(fmt_args[carg-1].val_float);
87 - vargs[carg-1]= fmt::detail::make_arg<ctx>(args[carg]->val_real());
89 + fmt_args[carg-1].val_double= args[carg]->val_real();
90 + vargs[carg-1]= fmt::detail::make_arg<ctx>(fmt_args[carg-1].val_double);
94 if (!(parg= args[carg]->val_str(&val_arg[carg-1])))
100 vargs[carg-1]= fmt::detail::make_arg<ctx>(*parg);
101 @@ -1423,6 +1450,7 @@ String *Item_func_sformat::val_str(Strin
105 + delete [] fmt_args;
109 @@ -1446,6 +1474,7 @@ String *Item_func_sformat::val_str(Strin
113 + delete [] fmt_args;
114 return null_value ? NULL : res;