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@gmail.com> Reviewed-by: Mihai Preda <mhpreda@gmail.com> Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15659>
This commit is contained in:
parent
1dca31cda6
commit
6d263ff5a3
|
@ -63,9 +63,9 @@ namespace {
|
||||||
size_t fmt_last_pos = 0;
|
size_t fmt_last_pos = 0;
|
||||||
size_t fmt_pos = 0;
|
size_t fmt_pos = 0;
|
||||||
for (int arg_size : fmt.arg_sizes) {
|
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 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 :
|
const size_t next_tok = next_spec == std::string::npos ? std::string::npos :
|
||||||
format.rfind('%', next_spec);
|
format.rfind('%', next_spec);
|
||||||
|
|
||||||
|
|
|
@ -144,7 +144,7 @@ files_mesa_util = files(
|
||||||
'u_debug_memory.c',
|
'u_debug_memory.c',
|
||||||
'u_cpu_detect.c',
|
'u_cpu_detect.c',
|
||||||
'u_cpu_detect.h',
|
'u_cpu_detect.h',
|
||||||
'u_printf.cpp',
|
'u_printf.c',
|
||||||
'u_printf.h',
|
'u_printf.h',
|
||||||
'vl_vlc.h',
|
'vl_vlc.h',
|
||||||
'vl_rbsp.h',
|
'vl_rbsp.h',
|
||||||
|
|
|
@ -23,8 +23,10 @@
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "macros.h"
|
||||||
#include "u_printf.h"
|
#include "u_printf.h"
|
||||||
#include "util/macros.h"
|
|
||||||
|
|
||||||
/* Some versions of MinGW are missing _vscprintf's declaration, although they
|
/* Some versions of MinGW are missing _vscprintf's declaration, although they
|
||||||
* still provide the symbol in the import library. */
|
* still provide the symbol in the import library. */
|
||||||
|
@ -40,37 +42,35 @@ _CRTIMP int _vscprintf(const char *format, va_list argptr);
|
||||||
#endif
|
#endif
|
||||||
#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;
|
if (str == NULL)
|
||||||
do {
|
return -1;
|
||||||
pos = s.find_first_of('%', pos);
|
|
||||||
|
|
||||||
if (pos == std::string::npos)
|
const char *str_found = str + pos;
|
||||||
|
do {
|
||||||
|
str_found = strchr(str_found, '%');
|
||||||
|
if (str_found == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (s[pos + 1] == '%') {
|
++str_found;
|
||||||
pos += 2;
|
if (*str_found == '%') {
|
||||||
|
++str_found;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
next_tok = s.find_first_of('%', pos + 1);
|
char *spec_pos = strpbrk(str_found, "cdieEfFgGaAosuxXp%");
|
||||||
spec_pos = s.find_first_of("cdieEfFgGaAosuxXp", pos + 1);
|
if (spec_pos == NULL) {
|
||||||
if (spec_pos != std::string::npos)
|
return -1;
|
||||||
if (spec_pos < next_tok)
|
} else if (*spec_pos == '%') {
|
||||||
return spec_pos;
|
str_found = spec_pos;
|
||||||
|
} else {
|
||||||
pos++;
|
return spec_pos - str;
|
||||||
|
}
|
||||||
} while (1);
|
} while (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t util_printf_next_spec_pos(const char *str, size_t pos)
|
size_t u_printf_length(const char *fmt, va_list untouched_args)
|
||||||
{
|
|
||||||
return util_printf_next_spec_pos(std::string(str), pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t
|
|
||||||
u_printf_length(const char *fmt, va_list untouched_args)
|
|
||||||
{
|
{
|
||||||
int size;
|
int size;
|
||||||
char junk;
|
char junk;
|
|
@ -26,12 +26,6 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#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" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue