Mesa (main): util: Convert util/u_printf.cpp to util/u_printf.c
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Apr 11 03:57:57 UTC 2022
Module: Mesa
Branch: main
Commit: 6d263ff5a3ec3352bd5e0b1750d38b173d50a1dc
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=6d263ff5a3ec3352bd5e0b1750d38b173d50a1dc
Author: Yonggang Luo <luoyonggang at gmail.com>
Date: Wed Mar 30 06:54:45 2022 +0800
util: Convert util/u_printf.cpp to util/u_printf.c
By doing this to remove the need of C++ runtime when not using llvmpipe
Signed-off-by: Yonggang Luo <luoyonggang at gmail.com>
Reviewed-by: Mihai Preda <mhpreda at gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15659>
---
src/gallium/frontends/clover/core/printf.cpp | 4 +--
src/util/meson.build | 2 +-
src/util/{u_printf.cpp => u_printf.c} | 44 ++++++++++++++--------------
src/util/u_printf.h | 6 ----
4 files changed, 25 insertions(+), 31 deletions(-)
diff --git a/src/gallium/frontends/clover/core/printf.cpp b/src/gallium/frontends/clover/core/printf.cpp
index bf131c6416c..c6231f19d83 100644
--- a/src/gallium/frontends/clover/core/printf.cpp
+++ b/src/gallium/frontends/clover/core/printf.cpp
@@ -63,9 +63,9 @@ namespace {
size_t fmt_last_pos = 0;
size_t fmt_pos = 0;
for (int arg_size : fmt.arg_sizes) {
- const size_t spec_pos = util_printf_next_spec_pos(format, fmt_pos);
+ const size_t spec_pos = util_printf_next_spec_pos(format.c_str(), fmt_pos);
const size_t cur_tok = format.rfind('%', spec_pos);
- const size_t next_spec = util_printf_next_spec_pos(format, spec_pos);
+ const size_t next_spec = util_printf_next_spec_pos(format.c_str(), spec_pos);
const size_t next_tok = next_spec == std::string::npos ? std::string::npos :
format.rfind('%', next_spec);
diff --git a/src/util/meson.build b/src/util/meson.build
index b3c7188bab6..2a1028f0d3a 100644
--- a/src/util/meson.build
+++ b/src/util/meson.build
@@ -144,7 +144,7 @@ files_mesa_util = files(
'u_debug_memory.c',
'u_cpu_detect.c',
'u_cpu_detect.h',
- 'u_printf.cpp',
+ 'u_printf.c',
'u_printf.h',
'vl_vlc.h',
'vl_rbsp.h',
diff --git a/src/util/u_printf.cpp b/src/util/u_printf.c
similarity index 78%
rename from src/util/u_printf.cpp
rename to src/util/u_printf.c
index c23265fec96..ff579988adf 100644
--- a/src/util/u_printf.cpp
+++ b/src/util/u_printf.c
@@ -23,8 +23,10 @@
#include <assert.h>
#include <stdarg.h>
+#include <string.h>
+
+#include "macros.h"
#include "u_printf.h"
-#include "util/macros.h"
/* Some versions of MinGW are missing _vscprintf's declaration, although they
* still provide the symbol in the import library. */
@@ -40,37 +42,35 @@ _CRTIMP int _vscprintf(const char *format, va_list argptr);
#endif
#endif
-size_t util_printf_next_spec_pos(const std::string &s, size_t pos)
+size_t util_printf_next_spec_pos(const char *str, size_t pos)
{
- size_t next_tok, spec_pos;
- do {
- pos = s.find_first_of('%', pos);
+ if (str == NULL)
+ return -1;
- if (pos == std::string::npos)
+ const char *str_found = str + pos;
+ do {
+ str_found = strchr(str_found, '%');
+ if (str_found == NULL)
return -1;
- if (s[pos + 1] == '%') {
- pos += 2;
+ ++str_found;
+ if (*str_found == '%') {
+ ++str_found;
continue;
}
- next_tok = s.find_first_of('%', pos + 1);
- spec_pos = s.find_first_of("cdieEfFgGaAosuxXp", pos + 1);
- if (spec_pos != std::string::npos)
- if (spec_pos < next_tok)
- return spec_pos;
-
- pos++;
+ char *spec_pos = strpbrk(str_found, "cdieEfFgGaAosuxXp%");
+ if (spec_pos == NULL) {
+ return -1;
+ } else if (*spec_pos == '%') {
+ str_found = spec_pos;
+ } else {
+ return spec_pos - str;
+ }
} while (1);
}
-size_t util_printf_next_spec_pos(const char *str, size_t pos)
-{
- return util_printf_next_spec_pos(std::string(str), pos);
-}
-
-size_t
-u_printf_length(const char *fmt, va_list untouched_args)
+size_t u_printf_length(const char *fmt, va_list untouched_args)
{
int size;
char junk;
diff --git a/src/util/u_printf.h b/src/util/u_printf.h
index d378b13f78f..63c212e63f3 100644
--- a/src/util/u_printf.h
+++ b/src/util/u_printf.h
@@ -26,12 +26,6 @@
#include <stddef.h>
#ifdef __cplusplus
-
-#include <string>
-
-/* find next valid printf specifier in a C++ std::string */
-size_t util_printf_next_spec_pos(const std::string &s, size_t pos);
-
extern "C" {
#endif
More information about the mesa-commit
mailing list