Commit 4e9676fb authored by Brian Paul's avatar Brian Paul
Browse files

Applied Matt Sealey's patch to remove/isolate all stdio.h function calls.

Instead of mstdio.[ch], use imports.[ch] to isolate these functions.
parent f1ad5516
/* $Id: glapi.c,v 1.62 2002/05/29 15:23:16 brianp Exp $ */
/* $Id: glapi.c,v 1.63 2002/06/29 19:48:16 brianp Exp $ */
/*
* Mesa 3-D graphics library
......@@ -37,11 +37,12 @@
* flexible enough to be reused in several places: XFree86, DRI-
* based libGL.so, and perhaps the SGI SI.
*
* There are no dependencies on Mesa in this code.
* NOTE: There are no dependencies on Mesa in this code.
*
* Versions (API changes):
* 2000/02/23 - original version for Mesa 3.3 and XFree86 4.0
* 2001/01/16 - added dispatch override feature for Mesa 3.5
* 2002/06/28 - added _glapi_set_warning_func(), Mesa 4.1.
*/
......@@ -55,20 +56,37 @@
/***** BEGIN NO-OP DISPATCH *****/
static GLboolean WarnFlag = GL_FALSE;
static _glapi_warning_func warning_func;
/*
* Enable/disable printing of warning messages.
*/
void
_glapi_noop_enable_warnings(GLboolean enable)
{
WarnFlag = enable;
}
/*
* Register a callback function for reporting errors.
*/
void
_glapi_set_warning_func( _glapi_warning_func func )
{
warning_func = func;
}
static GLboolean
warn(void)
{
if (WarnFlag || getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG"))
if ((WarnFlag || getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG"))
&& warning_func) {
return GL_TRUE;
else
}
else {
return GL_FALSE;
}
}
......@@ -76,21 +94,19 @@ warn(void)
#define KEYWORD2
#define NAME(func) NoOp##func
#define F stderr
#define F NULL
#define DISPATCH(func, args, msg) \
if (warn()) { \
fprintf(stderr, "GL User Error: calling "); \
fprintf msg; \
fprintf(stderr, " without a current context\n"); \
#define DISPATCH(func, args, msg) \
if (warn()) { \
warning_func(NULL, "GL User Error: called without context:"); \
warning_func msg; \
}
#define RETURN_DISPATCH(func, args, msg) \
if (warn()) { \
fprintf(stderr, "GL User Error: calling "); \
fprintf msg; \
fprintf(stderr, " without a current context\n"); \
} \
#define RETURN_DISPATCH(func, args, msg) \
if (warn()) { \
warning_func(NULL, "GL User Error: called without context:"); \
warning_func msg; \
} \
return 0
#define DISPATCH_TABLE_NAME __glapi_noop_table
......@@ -101,7 +117,7 @@ warn(void)
static int NoOpUnused(void)
{
if (warn()) {
fprintf(stderr, "GL User Error: calling extension function without a current context\n");
warning_func(NULL, "GL User Error: calling extension function without a current context\n");
}
return 0;
}
......@@ -442,7 +458,7 @@ _glapi_get_dispatch_table_size(void)
const char *
_glapi_get_version(void)
{
return "20010116"; /* YYYYMMDD */
return "20020628"; /* YYYYMMDD */
}
......
/* $Id: glapi.h,v 1.19 2001/03/28 17:20:20 brianp Exp $ */
/* $Id: glapi.h,v 1.20 2002/06/29 19:48:16 brianp Exp $ */
/*
* Mesa 3-D graphics library
......@@ -33,6 +33,8 @@
struct _glapi_table;
typedef void (*_glapi_warning_func)(void *ctx, const char *str, ...);
extern void *_glapi_Context;
......@@ -42,6 +44,8 @@ extern struct _glapi_table *_glapi_Dispatch;
extern void
_glapi_noop_enable_warnings(GLboolean enable);
extern void
_glapi_set_warning_func(_glapi_warning_func func);
extern void
_glapi_check_multithread(void);
......
/* $Id: colortab.c,v 1.43 2002/06/08 12:39:18 brianp Exp $ */
/* $Id: colortab.c,v 1.44 2002/06/29 19:48:15 brianp Exp $ */
/*
* Mesa 3-D graphics library
......@@ -322,9 +322,7 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
table->Format = (GLenum) 0;
}
else {
char msg[100];
sprintf(msg, "glColorTable(width=%d)", width);
_mesa_error(ctx, GL_INVALID_VALUE, msg);
_mesa_error(ctx, GL_INVALID_VALUE, "glColorTable(width=%d)", width);
}
return;
}
......
/* $Id: context.c,v 1.173 2002/06/23 02:53:22 brianp Exp $ */
/* $Id: context.c,v 1.174 2002/06/29 19:48:15 brianp Exp $ */
/*
* Mesa 3-D graphics library
......@@ -579,13 +579,14 @@ one_time_init( GLcontext *ctx )
#endif
if (ctx->imports.getenv(ctx, "MESA_DEBUG")) {
_glapi_noop_enable_warnings(GL_TRUE);
_glapi_set_warning_func( (_glapi_warning_func) _mesa_warning );
}
else {
_glapi_noop_enable_warnings(GL_FALSE);
}
#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
_mesa_debug(ctx, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
#endif
alreadyCalled = GL_TRUE;
......@@ -1480,7 +1481,7 @@ init_attrib_groups( GLcontext *ctx )
ctx->NoDither = ctx->imports.getenv(ctx, "MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
if (ctx->NoDither) {
if (ctx->imports.getenv(ctx, "MESA_DEBUG")) {
fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
_mesa_debug(ctx, "MESA_NO_DITHER set - dithering disabled\n");
}
ctx->Color.DitherFlag = GL_FALSE;
}
......@@ -2089,28 +2090,28 @@ _mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
static void print_info( void )
{
fprintf(stderr, "Mesa GL_VERSION = %s\n",
_mesa_debug(NULL, "Mesa GL_VERSION = %s\n",
(char *) _mesa_GetString(GL_VERSION));
fprintf(stderr, "Mesa GL_RENDERER = %s\n",
_mesa_debug(NULL, "Mesa GL_RENDERER = %s\n",
(char *) _mesa_GetString(GL_RENDERER));
fprintf(stderr, "Mesa GL_VENDOR = %s\n",
_mesa_debug(NULL, "Mesa GL_VENDOR = %s\n",
(char *) _mesa_GetString(GL_VENDOR));
fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n",
_mesa_debug(NULL, "Mesa GL_EXTENSIONS = %s\n",
(char *) _mesa_GetString(GL_EXTENSIONS));
#if defined(THREADS)
fprintf(stderr, "Mesa thread-safe: YES\n");
_mesa_debug(NULL, "Mesa thread-safe: YES\n");
#else
fprintf(stderr, "Mesa thread-safe: NO\n");
_mesa_debug(NULL, "Mesa thread-safe: NO\n");
#endif
#if defined(USE_X86_ASM)
fprintf(stderr, "Mesa x86-optimized: YES\n");
_mesa_debug(NULL, "Mesa x86-optimized: YES\n");
#else
fprintf(stderr, "Mesa x86-optimized: NO\n");
_mesa_debug(NULL, "Mesa x86-optimized: NO\n");
#endif
#if defined(USE_SPARC_ASM)
fprintf(stderr, "Mesa sparc-optimized: YES\n");
_mesa_debug(NULL, "Mesa sparc-optimized: YES\n");
#else
fprintf(stderr, "Mesa sparc-optimized: NO\n");
_mesa_debug(NULL, "Mesa sparc-optimized: NO\n");
#endif
}
......@@ -2270,112 +2271,12 @@ _mesa_get_dispatch(GLcontext *ctx)
/*
* This function is called when the Mesa user has stumbled into a code
* path which may not be implemented fully or correctly.
*/
void _mesa_problem( const GLcontext *ctx, const char *s )
{
if (ctx) {
ctx->imports.fprintf((GLcontext *) ctx, stderr, "Mesa implementation error: %s\n", s);
#ifdef XF86DRI
ctx->imports.fprintf((GLcontext *) ctx, stderr, "Please report to the DRI bug database at dri.sourceforge.net\n");
#else
ctx->imports.fprintf((GLcontext *) ctx, stderr, "Please report to the Mesa bug database at www.mesa3d.org\n" );
#endif
}
else {
/* what can we do if we don't have a context???? */
fprintf( stderr, "Mesa implementation error: %s\n", s );
#ifdef XF86DRI
fprintf( stderr, "Please report to the DRI bug database at dri.sourceforge.net\n");
#else
fprintf( stderr, "Please report to the Mesa bug database at www.mesa3d.org\n" );
#endif
}
}
/*
* This is called to inform the user that he or she has tried to do
* something illogical or if there's likely a bug in their program
* (like enabled depth testing without a depth buffer).
*/
void
_mesa_warning( const GLcontext *ctx, const char *s )
{
(*ctx->imports.warning)((__GLcontext *) ctx, (char *) s);
}
/*
* This is Mesa's error handler. Normally, all that's done is the updating
* of the current error value. If Mesa is compiled with -DDEBUG or if the
* environment variable "MESA_DEBUG" is defined then a real error message
* is printed to stderr.
* Input: ctx - the GL context
* error - the error value
* where - usually the name of function where error was detected
* Record the given error code and call the driver's Error function if defined.
* This is called via _mesa_error().
*/
void
_mesa_error( GLcontext *ctx, GLenum error, const char *where )
_mesa_record_error( GLcontext *ctx, GLenum error )
{
const char *debugEnv;
GLboolean debug;
if (ctx)
debugEnv = ctx->imports.getenv(ctx, "MESA_DEBUG");
else
/* what can we do??? */
debugEnv = "";
#ifdef DEBUG
if (debugEnv && strstr(debugEnv, "silent"))
debug = GL_FALSE;
else
debug = GL_TRUE;
#else
if (debugEnv)
debug = GL_TRUE;
else
debug = GL_FALSE;
#endif
if (debug) {
const char *errstr;
switch (error) {
case GL_NO_ERROR:
errstr = "GL_NO_ERROR";
break;
case GL_INVALID_VALUE:
errstr = "GL_INVALID_VALUE";
break;
case GL_INVALID_ENUM:
errstr = "GL_INVALID_ENUM";
break;
case GL_INVALID_OPERATION:
errstr = "GL_INVALID_OPERATION";
break;
case GL_STACK_OVERFLOW:
errstr = "GL_STACK_OVERFLOW";
break;
case GL_STACK_UNDERFLOW:
errstr = "GL_STACK_UNDERFLOW";
break;
case GL_OUT_OF_MEMORY:
errstr = "GL_OUT_OF_MEMORY";
break;
case GL_TABLE_TOO_LARGE:
errstr = "GL_TABLE_TOO_LARGE";
break;
default:
errstr = "unknown";
break;
}
fprintf(stderr, "Mesa user error: %s in %s\n", errstr, where);
}
if (!ctx)
return;
......@@ -2390,37 +2291,6 @@ _mesa_error( GLcontext *ctx, GLenum error, const char *where )
}
/*
* Call this to report debug information. Uses stderr.
*/
void
_mesa_debug( const GLcontext *ctx, const char *fmtString, ... )
{
char s[1000];
va_list args;
va_start( args, fmtString );
vsprintf(s, fmtString, args);
(void) ctx->imports.fprintf( (__GLcontext *) ctx, stderr, s );
va_end( args );
}
/*
* A wrapper for printf. Uses stdout.
*/
void
_mesa_printf( const GLcontext *ctx, const char *fmtString, ... )
{
char s[1000];
va_list args;
va_start( args, fmtString );
vsprintf(s, fmtString, args);
(void) ctx->imports.fprintf( (__GLcontext *) ctx, stdout, s );
va_end( args );
}
void
_mesa_Finish( void )
{
......
/* $Id: context.h,v 1.32 2002/06/15 02:38:15 brianp Exp $ */
/* $Id: context.h,v 1.33 2002/06/29 19:48:15 brianp Exp $ */
/*
* Mesa 3-D graphics library
......@@ -31,6 +31,7 @@
#include "glapi.h"
#include "mtypes.h"
#include "imports.h"
/*
......@@ -229,20 +230,7 @@ _mesa_get_dispatch(GLcontext *ctx);
*/
extern void
_mesa_problem( const GLcontext *ctx, const char *s );
extern void
_mesa_warning( const GLcontext *ctx, const char *s );
extern void
_mesa_error( GLcontext *ctx, GLenum error, const char *s );
extern void
_mesa_debug( const GLcontext *ctx, const char *fmtString, ... );
extern void
_mesa_printf( const GLcontext *ctx, const char *fmtString, ... );
_mesa_record_error( GLcontext *ctx, GLenum error );
extern void
......
/* $Id: debug.c,v 1.12 2001/03/29 21:16:25 keithw Exp $ */
/* $Id: debug.c,v 1.13 2002/06/29 19:48:15 brianp Exp $ */
/*
* Mesa 3-D graphics library
......@@ -25,11 +25,12 @@
*/
#include "mtypes.h"
#include "context.h"
#include "debug.h"
void _mesa_print_state( const char *msg, GLuint state )
{
fprintf(stderr,
_mesa_debug(NULL,
"%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
msg,
state,
......@@ -63,7 +64,7 @@ void _mesa_print_state( const char *msg, GLuint state )
void _mesa_print_tri_caps( const char *name, GLuint flags )
{
fprintf(stderr,
_mesa_debug(NULL,
"%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
name,
flags,
......
/* $Id: dispatch.c,v 1.26 2001/12/15 16:42:59 brianp Exp $ */
/* $Id: dispatch.c,v 1.27 2002/06/29 19:48:15 brianp Exp $ */
/*
* Mesa 3-D graphics library
......@@ -62,7 +62,7 @@
#endif
#if 0 /* Use this to log GL calls to stdout */
#if 0 /* Use this to log GL calls to stdout (for DEBUG only!) */
#define F stdout
#define DISPATCH(FUNC, ARGS, MESSAGE) \
......
/* $Id: dlist.c,v 1.90 2002/06/15 02:38:15 brianp Exp $ */
/* $Id: dlist.c,v 1.91 2002/06/29 19:48:15 brianp Exp $ */
/*
* Mesa 3-D graphics library
......@@ -4817,7 +4817,7 @@ execute_list( GLcontext *ctx, GLuint list )
default:
{
char msg[1000];
sprintf(msg, "Error in execute_list: opcode=%d", (int) opcode);
_mesa_sprintf( ctx, msg, "Error in execute_list: opcode=%d", (int) opcode);
_mesa_problem( ctx, msg );
}
done = GL_TRUE;
......
/* $Id: enable.c,v 1.67 2002/06/18 16:53:46 brianp Exp $ */
/* $Id: enable.c,v 1.68 2002/06/29 19:48:15 brianp Exp $ */
/*
* Mesa 3-D graphics library
......@@ -44,9 +44,8 @@
#define CHECK_EXTENSION(EXTNAME, CAP) \
if (!ctx->Extensions.EXTNAME) { \
char s[100]; \
sprintf(s, "gl%sClientState(0x%x)", state ? "Enable" : "Disable", CAP);\
_mesa_error(ctx, GL_INVALID_ENUM, s); \
_mesa_error(ctx, GL_INVALID_ENUM, "gl%sClientState(0x%x)", \
state ? "Enable" : "Disable", CAP); \
return; \
}
......@@ -117,11 +116,8 @@ client_state( GLcontext *ctx, GLenum cap, GLboolean state )
}
break;
default:
{
char s[100];
sprintf(s, "glEnable/DisableClientState(0x%x)", cap);
_mesa_error( ctx, GL_INVALID_ENUM, s);
}
_mesa_error( ctx, GL_INVALID_ENUM,
"glEnable/DisableClientState(0x%x)", cap);
return;
}
......@@ -166,9 +162,8 @@ _mesa_DisableClientState( GLenum cap )
#undef CHECK_EXTENSION
#define CHECK_EXTENSION(EXTNAME, CAP) \
if (!ctx->Extensions.EXTNAME) { \
char s[100]; \
sprintf(s, "gl%s(0x%x)", state ? "Enable" : "Disable", CAP); \
_mesa_error(ctx, GL_INVALID_ENUM, s); \
_mesa_error(ctx, GL_INVALID_ENUM, "gl%s(0x%x)", \
state ? "Enable" : "Disable", CAP); \
return; \
}
......@@ -895,11 +890,8 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
break;
default:
{
char s[100];
sprintf(s, "%s(0x%x)", state ? "glEnable" : "glDisable", cap);
_mesa_error(ctx, GL_INVALID_ENUM, s);
}
_mesa_error(ctx, GL_INVALID_ENUM,
"%s(0x%x)", state ? "glEnable" : "glDisable", cap);
return;
}
......@@ -1272,11 +1264,7 @@ _mesa_IsEnabled( GLenum cap )
}
default:
{
char s[100];
sprintf(s, "glIsEnabled(0x%x)", (int) cap);
_mesa_error( ctx, GL_INVALID_ENUM, s );
}
_mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(0x%x)", (int) cap);
return GL_FALSE;
}
}
/* $Id: enums.c,v 1.20 2001/06/08 20:10:55 brianp Exp $ */
/* $Id: enums.c,v 1.21 2002/06/29 19:48:15 brianp Exp $ */
/*
* Mesa 3-D graphics library
......@@ -33,6 +33,7 @@
#else
#include "glheader.h"
#include "enums.h"
#include "imports.h"
#include "mem.h"
#endif
......@@ -928,7 +929,7 @@ const char *_mesa_lookup_enum_by_nr( int nr )
}
else {
/* this isn't re-entrant safe, no big deal here */
sprintf(token_tmp, "0x%x", nr);
_mesa_sprintf(NULL, token_tmp, "0x%x", nr);
return token_tmp;
}
}
/* $Id: get.c,v 1.83 2002/06/18 16:53:46 brianp Exp $ */
/* $Id: get.c,v 1.84 2002/06/29 19:48:15 brianp Exp $ */
/*
* Mesa 3-D graphics library
......@@ -63,33 +63,29 @@
#define CHECK_EXTENSION_B(EXTNAME, PNAME) \
if (!ctx->Extensions.EXTNAME) { \
char s[100]; \
sprintf(s, "glGetBooleanv(0x%x)", (int) PNAME); \
_mesa_error(ctx, GL_INVALID_VALUE, s); \
_mesa_error(ctx, GL_INVALID_VALUE, \
"glGetBooleanv(0x%x)", (int) PNAME); \
return; \
}
#define CHECK_EXTENSION_I(EXTNAME, PNAME) \
if (!ctx->Extensions.EXTNAME) { \
char s[100]; \
sprintf(s, "glGetIntegerv(0x%x)", (int) PNAME); \
_mesa_error(ctx, GL_INVALID_VALUE, s); \
_mesa_error(ctx, GL_INVALID_VALUE, \
"glGetIntegerv(0x%x)", (int) PNAME); \
return; \
}
#define CHECK_EXTENSION_F(EXTNAME, PNAME) \
if (!ctx->Extensions.EXTNAME) { \
char s[100]; \
sprintf(s, "glGetFloatv(0x%x)", (int) PNAME); \
_mesa_error(ctx, GL_INVALID_VALUE, s); \
_mesa_error(ctx, GL_INVALID_VALUE, \
"glGetFloatv(0x%x)", (int) PNAME); \
return; \
}
#define CHECK_EXTENSION_D(EXTNAME, PNAME) \
if (!ctx->Extensions.EXTNAME) { \
char s[100]; \
sprintf(s, "glGetDoublev(0x%x)", (int) PNAME); \
_mesa_error(ctx, GL_INVALID_VALUE, s); \
_mesa_error(ctx, GL_INVALID_VALUE, \
"glGetDoublev(0x%x)", (int) PNAME); \
return; \
}
......@@ -1471,11 +1467,7 @@ _mesa_GetBooleanv( GLenum pname, GLboolean *params )
break;
default:
{
char s[100];
sprintf(s, "glGetBooleanv(pname=0x%x)", pname);
_mesa_error( ctx, GL_INVALID_ENUM, s );
}
_mesa_error(ctx, GL_INVALID_ENUM, "glGetBooleanv(pname=0x%x)", pname);
}
}
......@@ -2829,11 +2821,7 @@ _mesa_GetDoublev( GLenum pname, GLdouble *params )
break;
default:
{
char s[100];
sprintf(s, "glGetDoublev(pname=0x%x)", pname);
_mesa_error( ctx, GL_INVALID_ENUM, s );
}
_mesa_error(ctx, GL_INVALID_ENUM, "glGetDoublev(pname=0x%x)", pname);
}
}
......@@ -4163,11 +4151,7 @@ _mesa_GetFloatv( GLenum pname, GLfloat *params )
break;
default:
{
char s[100];
sprintf(s, "glGetFloatv(0x%x)", pname);
_mesa_error(ctx, GL_INVALID_ENUM, s);
}
_mesa_error(ctx, GL_INVALID_ENUM, "glGetFloatv(0x%x)", pname