From bf188f3494b85f550a39dddbf059669c2a9ee324 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Dec 2019 10:54:16 -0800 Subject: [PATCH 1/1] mesa|mapi: replace _mesa_[v]snprintf with [v]snprintf MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit MSVC 2015 and newer has perfectly valid snprintf and vsnprintf implementations, let's just use those. Reviewed-by: Marek Olšák Reviewed-by: Kristian H. Kristensen Reviewed-by: Matt Turner Part-of: --- src/mapi/glapi/gen/gl_enums.py | 3 ++- src/mesa/drivers/common/meta.c | 4 ++-- src/mesa/main/debug.c | 6 +++--- src/mesa/main/dlist.c | 2 +- src/mesa/main/errors.c | 18 +++++++++--------- src/mesa/main/macros.h | 9 +++++++++ src/mesa/main/pbo.c | 2 +- src/mesa/main/shaderapi.c | 1 + src/mesa/main/teximage.c | 6 +++--- src/mesa/main/uniform_query.cpp | 2 +- src/mesa/main/version.c | 2 +- src/mesa/program/prog_instruction.c | 2 +- src/mesa/program/prog_print.c | 6 +++--- src/mesa/program/program_parse.y | 8 ++++---- src/mesa/tnl/t_rebase.c | 2 +- src/mesa/vbo/vbo_private.h | 1 + src/util/imports.c | 24 +----------------------- src/util/imports.h | 24 ------------------------ 18 files changed, 44 insertions(+), 78 deletions(-) diff --git a/src/mapi/glapi/gen/gl_enums.py b/src/mapi/glapi/gen/gl_enums.py index 53987813642..255b1adfbed 100644 --- a/src/mapi/glapi/gen/gl_enums.py +++ b/src/mapi/glapi/gen/gl_enums.py @@ -50,6 +50,7 @@ class PrintGlEnums(gl_XML.gl_print_base): def printRealHeader(self): + print('#include ') 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; } diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c index ea096d585fd..0ea6d5efadb 100644 --- a/src/mesa/drivers/common/meta.c +++ b/src/mesa/drivers/common/meta.c @@ -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); diff --git a/src/mesa/main/debug.c b/src/mesa/main/debug.c index 66ee2841b03..a646d4426ef 100644 --- a/src/mesa/main/debug.c +++ b/src/mesa/main/debug.c @@ -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); diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c index 89d2e8a12a0..bd2ce8f5053 100644 --- a/src/mesa/main/dlist.c +++ b/src/mesa/main/dlist.c @@ -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); } diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c index 7c8cb3886d9..b3487efb522 100644 --- a/src/mesa/main/errors.c +++ b/src/mesa/main/errors.c @@ -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); } diff --git a/src/mesa/main/macros.h b/src/mesa/main/macros.h index a4c5ec67a4a..3e1227328e1 100644 --- a/src/mesa/main/macros.h +++ b/src/mesa/main/macros.h @@ -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 diff --git a/src/mesa/main/pbo.c b/src/mesa/main/pbo.c index 8ab782f3a33..7cb463d93fc 100644 --- a/src/mesa/main/pbo.c +++ b/src/mesa/main/pbo.c @@ -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" diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c index 0aa05475247..19d7a3ab440 100644 --- a/src/mesa/main/shaderapi.c +++ b/src/mesa/main/shaderapi.c @@ -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. diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index 986ee614915..ea93ac2f3b2 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -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); diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp index de594fcc3d7..db2f173dd2f 100644 --- a/src/mesa/main/uniform_query.cpp +++ b/src/mesa/main/uniform_query.cpp @@ -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; diff --git a/src/mesa/main/version.c b/src/mesa/main/version.c index cacf22e7950..0cb0aabb896 100644 --- a/src/mesa/main/version.c +++ b/src/mesa/main/version.c @@ -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, diff --git a/src/mesa/program/prog_instruction.c b/src/mesa/program/prog_instruction.c index a999fd516a1..4673dd59a24 100644 --- a/src/mesa/program/prog_instruction.c +++ b/src/mesa/program/prog_instruction.c @@ -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; } } diff --git a/src/mesa/program/prog_print.c b/src/mesa/program/prog_print.c index c34e6cf308a..0b280828341 100644 --- a/src/mesa/program/prog_print.c +++ b/src/mesa/program/prog_print.c @@ -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); diff --git a/src/mesa/program/program_parse.y b/src/mesa/program/program_parse.y index 5e79bf7fcd4..53489410253 100644 --- a/src/mesa/program/program_parse.y +++ b/src/mesa/program/program_parse.y @@ -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; diff --git a/src/mesa/tnl/t_rebase.c b/src/mesa/tnl/t_rebase.c index 3d5a1a1c4c8..6f600e39068 100644 --- a/src/mesa/tnl/t_rebase.c +++ b/src/mesa/tnl/t_rebase.c @@ -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" diff --git a/src/mesa/vbo/vbo_private.h b/src/mesa/vbo/vbo_private.h index 9f169fd7675..a70ba0a032c 100644 --- a/src/mesa/vbo/vbo_private.h +++ b/src/mesa/vbo/vbo_private.h @@ -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; diff --git a/src/util/imports.c b/src/util/imports.c index 2744ee988d3..776e86efb7a 100644 --- a/src/util/imports.c +++ b/src/util/imports.c @@ -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; -} - - diff --git a/src/util/imports.h b/src/util/imports.h index 4d7405dbf55..345e9114aa3 100644 --- a/src/util/imports.h +++ b/src/util/imports.h @@ -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 -- 2.30.2