mesa|mapi: replace _mesa_[v]snprintf with [v]snprintf

MSVC 2015 and newer has perfectly valid snprintf and vsnprintf
implementations, let's just use those.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3024>
This commit is contained in:
Dylan Baker 2019-12-09 10:54:16 -08:00
parent c495c3af26
commit bf188f3494
18 changed files with 44 additions and 78 deletions

View file

@ -50,6 +50,7 @@ class PrintGlEnums(gl_XML.gl_print_base):
def printRealHeader(self):
print('#include <stdio.h>')
print('#include "main/glheader.h"')
print('#include "main/enums.h"')
print('#include "util/imports.h"')
@ -103,7 +104,7 @@ _mesa_enum_to_string(int nr)
}
else {
/* this is not re-entrant safe, no big deal here */
_mesa_snprintf(token_tmp, sizeof(token_tmp) - 1, "0x%x", nr);
snprintf(token_tmp, sizeof(token_tmp) - 1, "0x%x", nr);
token_tmp[sizeof(token_tmp) - 1] = '\\0';
return token_tmp;
}

View file

@ -2095,7 +2095,7 @@ init_draw_stencil_pixels(struct gl_context *ctx)
texTarget = "RECT";
else
texTarget = "2D";
_mesa_snprintf(program2, sizeof(program2), program, texTarget);
snprintf(program2, sizeof(program2), program, texTarget);
_mesa_GenProgramsARB(1, &drawpix->StencilFP);
_mesa_BindProgramARB(GL_FRAGMENT_PROGRAM_ARB, drawpix->StencilFP);
@ -2129,7 +2129,7 @@ init_draw_depth_pixels(struct gl_context *ctx)
texTarget = "RECT";
else
texTarget = "2D";
_mesa_snprintf(program2, sizeof(program2), program, texTarget);
snprintf(program2, sizeof(program2), program, texTarget);
_mesa_GenProgramsARB(1, &drawpix->DepthFP);
_mesa_BindProgramARB(GL_FRAGMENT_PROGRAM_ARB, drawpix->DepthFP);

View file

@ -284,7 +284,7 @@ write_texture_image(struct gl_texture_object *texObj,
GL_RGBA, GL_UNSIGNED_BYTE, buffer, img);
/* make filename */
_mesa_snprintf(s, sizeof(s), "/tmp/tex%u.l%u.f%u.ppm", texObj->Name, level, face);
snprintf(s, sizeof(s), "/tmp/tex%u.l%u.f%u.ppm", texObj->Name, level, face);
printf(" Writing image level %u to %s\n", level, s);
write_ppm(s, buffer, img->Width, img->Height, 4, 0, 1, 2, GL_FALSE);
@ -330,8 +330,8 @@ _mesa_write_renderbuffer_image(const struct gl_renderbuffer *rb)
format, type, &ctx->DefaultPacking, buffer);
/* make filename */
_mesa_snprintf(s, sizeof(s), "/tmp/renderbuffer%u.ppm", rb->Name);
_mesa_snprintf(s, sizeof(s), "C:\\renderbuffer%u.ppm", rb->Name);
snprintf(s, sizeof(s), "/tmp/renderbuffer%u.ppm", rb->Name);
snprintf(s, sizeof(s), "C:\\renderbuffer%u.ppm", rb->Name);
printf(" Writing renderbuffer image to %s\n", s);

View file

@ -13548,7 +13548,7 @@ execute_list(struct gl_context *ctx, GLuint list)
default:
{
char msg[1000];
_mesa_snprintf(msg, sizeof(msg), "Error in execute_list: opcode=%d",
snprintf(msg, sizeof(msg), "Error in execute_list: opcode=%d",
(int) opcode);
_mesa_problem(ctx, "%s", msg);
}

View file

@ -86,7 +86,7 @@ output_if_debug(const char *prefixString, const char *outputString,
* visible, so communicate with the debugger instead */
{
char buf[4096];
_mesa_snprintf(buf, sizeof(buf), "%s: %s%s", prefixString, outputString, newline ? "\n" : "");
snprintf(buf, sizeof(buf), "%s: %s%s", prefixString, outputString, newline ? "\n" : "");
OutputDebugStringA(buf);
}
#endif
@ -116,7 +116,7 @@ flush_delayed_errors( struct gl_context *ctx )
char s[MAX_DEBUG_MESSAGE_LENGTH];
if (ctx->ErrorDebugCount) {
_mesa_snprintf(s, MAX_DEBUG_MESSAGE_LENGTH, "%d similar %s errors",
snprintf(s, MAX_DEBUG_MESSAGE_LENGTH, "%d similar %s errors",
ctx->ErrorDebugCount,
_mesa_enum_to_string(ctx->ErrorValue));
@ -140,7 +140,7 @@ _mesa_warning( struct gl_context *ctx, const char *fmtString, ... )
char str[MAX_DEBUG_MESSAGE_LENGTH];
va_list args;
va_start( args, fmtString );
(void) _mesa_vsnprintf( str, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args );
(void) vsnprintf( str, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args );
va_end( args );
if (ctx)
@ -170,7 +170,7 @@ _mesa_problem( const struct gl_context *ctx, const char *fmtString, ... )
numCalls++;
va_start( args, fmtString );
_mesa_vsnprintf( str, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args );
vsnprintf( str, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args );
va_end( args );
fprintf(stderr, "Mesa " PACKAGE_VERSION " implementation error: %s\n",
str);
@ -230,7 +230,7 @@ _mesa_gl_vdebugf(struct gl_context *ctx,
_mesa_debug_get_id(id);
len = _mesa_vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
len = vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
if (len >= MAX_DEBUG_MESSAGE_LENGTH)
/* message was truncated */
len = MAX_DEBUG_MESSAGE_LENGTH - 1;
@ -325,7 +325,7 @@ _mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... )
va_list args;
va_start(args, fmtString);
len = _mesa_vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
len = vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
va_end(args);
if (len >= MAX_DEBUG_MESSAGE_LENGTH) {
@ -336,7 +336,7 @@ _mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... )
return;
}
len = _mesa_snprintf(s2, MAX_DEBUG_MESSAGE_LENGTH, "%s in %s",
len = snprintf(s2, MAX_DEBUG_MESSAGE_LENGTH, "%s in %s",
_mesa_enum_to_string(error), s);
if (len >= MAX_DEBUG_MESSAGE_LENGTH) {
/* Same as above. */
@ -382,7 +382,7 @@ _mesa_debug( const struct gl_context *ctx, const char *fmtString, ... )
char s[MAX_DEBUG_MESSAGE_LENGTH];
va_list args;
va_start(args, fmtString);
_mesa_vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
va_end(args);
output_if_debug("Mesa", s, GL_FALSE);
#endif /* DEBUG */
@ -397,7 +397,7 @@ _mesa_log(const char *fmtString, ...)
char s[MAX_DEBUG_MESSAGE_LENGTH];
va_list args;
va_start(args, fmtString);
_mesa_vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
va_end(args);
output_if_debug("", s, GL_FALSE);
}

View file

@ -787,4 +787,13 @@ DIFFERENT_SIGNS(GLfloat x, GLfloat y)
/* Stringify */
#define STRINGIFY(x) #x
/*
* For GL_ARB_vertex_buffer_object we need to treat vertex array pointers
* as offsets into buffer stores. Since the vertex array pointer and
* buffer store pointer are both pointers and we need to add them, we use
* this macro.
* Both pointers/offsets are expressed in bytes.
*/
#define ADD_POINTERS(A, B) ( (GLubyte *) (A) + (uintptr_t) (B) )
#endif

View file

@ -36,8 +36,8 @@
#include "bufferobj.h"
#include "glformats.h"
#include "image.h"
#include "util/imports.h"
#include "mtypes.h"
#include "macros.h"
#include "pbo.h"

View file

@ -63,6 +63,7 @@
#include "util/crc32.h"
#include "util/os_file.h"
#include "util/simple_list.h"
#include "util/u_string.h"
/**
* Return mask of GLSL_x flags by examining the MESA_GLSL env var.

View file

@ -1892,7 +1892,7 @@ texture_error_check( struct gl_context *ctx,
* requires GL_OES_texture_float) are filtered elsewhere.
*/
char bufCallerName[20];
_mesa_snprintf(bufCallerName, 20, "glTexImage%dD", dimensions);
snprintf(bufCallerName, 20, "glTexImage%dD", dimensions);
if (_mesa_is_gles(ctx) &&
texture_format_error_check_gles(ctx, format, type,
internalFormat, bufCallerName)) {
@ -1921,7 +1921,7 @@ texture_error_check( struct gl_context *ctx,
if (type != GL_UNSIGNED_SHORT_8_8_MESA &&
type != GL_UNSIGNED_SHORT_8_8_REV_MESA) {
char message[100];
_mesa_snprintf(message, sizeof(message),
snprintf(message, sizeof(message),
"glTexImage%dD(format/type YCBCR mismatch)",
dimensions);
_mesa_error(ctx, GL_INVALID_ENUM, "%s", message);
@ -1938,7 +1938,7 @@ texture_error_check( struct gl_context *ctx,
}
if (border != 0) {
char message[100];
_mesa_snprintf(message, sizeof(message),
snprintf(message, sizeof(message),
"glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
dimensions, border);
_mesa_error(ctx, GL_INVALID_VALUE, "%s", message);

View file

@ -1594,7 +1594,7 @@ _mesa_sampler_uniforms_are_valid(const struct gl_shader_program *shProg,
return true;
if (!shProg->SamplersValidated) {
_mesa_snprintf(errMsg, errMsgLength,
snprintf(errMsg, errMsgLength,
"active samplers with a different type "
"refer to the same texture image unit");
return false;

View file

@ -120,7 +120,7 @@ create_version_string(struct gl_context *ctx, const char *prefix)
ctx->VersionString = malloc(max);
if (ctx->VersionString) {
_mesa_snprintf(ctx->VersionString, max,
snprintf(ctx->VersionString, max,
"%s%u.%u%s Mesa " PACKAGE_VERSION MESA_GIT_SHA1,
prefix,
ctx->Version / 10, ctx->Version % 10,

View file

@ -250,7 +250,7 @@ _mesa_opcode_string(enum prog_opcode opcode)
return InstInfo[opcode].Name;
else {
static char s[20];
_mesa_snprintf(s, sizeof(s), "OP%u", opcode);
snprintf(s, sizeof(s), "OP%u", opcode);
return s;
}
}

View file

@ -83,7 +83,7 @@ _mesa_register_file_name(gl_register_file f)
default:
{
static char s[20];
_mesa_snprintf(s, sizeof(s), "FILE%u", f);
snprintf(s, sizeof(s), "FILE%u", f);
return s;
}
}
@ -988,7 +988,7 @@ _mesa_write_shader_to_file(const struct gl_shader *shader)
break;
}
_mesa_snprintf(filename, sizeof(filename), "shader_%u.%s", shader->Name, type);
snprintf(filename, sizeof(filename), "shader_%u.%s", shader->Name, type);
f = fopen(filename, "w");
if (!f) {
fprintf(stderr, "Unable to open %s for writing\n", filename);
@ -1031,7 +1031,7 @@ _mesa_append_uniforms_to_file(const struct gl_program *prog)
else
type = "vert";
_mesa_snprintf(filename, sizeof(filename), "shader.%s", type);
snprintf(filename, sizeof(filename), "shader.%s", type);
f = fopen(filename, "a"); /* append */
if (!f) {
fprintf(stderr, "Unable to open %s for appending\n", filename);

View file

@ -890,7 +890,7 @@ addrRegPosOffset: INTEGER
{
if (($1 < 0) || ($1 > (state->limits->MaxAddressOffset - 1))) {
char s[100];
_mesa_snprintf(s, sizeof(s),
snprintf(s, sizeof(s),
"relative address offset too large (%d)", $1);
yyerror(& @1, state, s);
YYERROR;
@ -904,7 +904,7 @@ addrRegNegOffset: INTEGER
{
if (($1 < 0) || ($1 > state->limits->MaxAddressOffset)) {
char s[100];
_mesa_snprintf(s, sizeof(s),
snprintf(s, sizeof(s),
"relative address offset too large (%d)", $1);
yyerror(& @1, state, s);
YYERROR;
@ -1121,7 +1121,7 @@ optArraySize:
{
if (($1 < 1) || ((unsigned) $1 > state->limits->MaxParameters)) {
char msg[100];
_mesa_snprintf(msg, sizeof(msg),
snprintf(msg, sizeof(msg),
"invalid parameter array size (size=%d max=%u)",
$1, state->limits->MaxParameters);
yyerror(& @1, state, msg);
@ -2034,7 +2034,7 @@ ALIAS_statement: ALIAS IDENTIFIER '=' USED_IDENTIFIER
if (exist != NULL) {
char m[1000];
_mesa_snprintf(m, sizeof(m), "redeclared identifier: %s", $2);
snprintf(m, sizeof(m), "redeclared identifier: %s", $2);
free($2);
yyerror(& @2, state, m);
YYERROR;

View file

@ -50,7 +50,7 @@
#include "main/bufferobj.h"
#include "main/errors.h"
#include "main/glheader.h"
#include "util/imports.h"
#include "main/macros.h"
#include "main/mtypes.h"
#include "vbo/vbo.h"

View file

@ -36,6 +36,7 @@
#include "vbo/vbo_exec.h"
#include "vbo/vbo_save.h"
#include "main/varray.h"
#include "main/macros.h"
struct _glapi_table;

View file

@ -1,7 +1,7 @@
/**
* \file imports.c
* Standard C library function wrappers.
*
*
* Imports are services which the device driver or window system or
* operating system provides to the core renderer. The core renderer (Mesa)
* will call these functions in order to do memory allocation, simple I/O,
@ -60,25 +60,3 @@
#elif defined(__IBMC__) || defined(__IBMCPP__)
extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
#endif
/** Needed due to #ifdef's, above. */
int
_mesa_vsnprintf(char *str, size_t size, const char *fmt, va_list args)
{
return vsnprintf( str, size, fmt, args);
}
/** Wrapper around vsnprintf() */
int
_mesa_snprintf( char *str, size_t size, const char *fmt, ... )
{
int r;
va_list args;
va_start( args, fmt );
r = vsnprintf( str, size, fmt, args );
va_end( args );
return r;
}

View file

@ -47,15 +47,6 @@
extern "C" {
#endif
/*
* For GL_ARB_vertex_buffer_object we need to treat vertex array pointers
* as offsets into buffer stores. Since the vertex array pointer and
* buffer store pointer are both pointers and we need to add them, we use
* this macro.
* Both pointers/offsets are expressed in bytes.
*/
#define ADD_POINTERS(A, B) ( (uint8_t *) (A) + (uintptr_t) (B) )
/**
* Sometimes we treat floats as ints. On x86 systems, moving a float
@ -68,21 +59,6 @@ extern "C" {
typedef union { float f; int i; unsigned u; } fi_type;
/*@}*/
/**********************************************************************
* Functions
*/
extern int
_mesa_snprintf( char *str, size_t size, const char *fmt, ... ) PRINTFLIKE(3, 4);
extern int
_mesa_vsnprintf(char *str, size_t size, const char *fmt, va_list arg);
#ifdef __cplusplus
}
#endif