[Mesa-dev] [PATCH 04/11] mesa: split error handling into its own file

nobled nobled at dreamwidth.org
Mon May 2 16:00:18 PDT 2011


---
 src/mesa/SConscript       |    1 +
 src/mesa/main/descrip.mms |    3 +
 src/mesa/main/errors.c    |  276 +++++++++++++++++++++++++++++++++++++++++++++
 src/mesa/main/imports.c   |  238 --------------------------------------
 src/mesa/sources.mak      |    1 +
 5 files changed, 281 insertions(+), 238 deletions(-)
 create mode 100644 src/mesa/main/errors.c

diff --git a/src/mesa/SConscript b/src/mesa/SConscript
index 2d8a177..6bb546f 100644
--- a/src/mesa/SConscript
+++ b/src/mesa/SConscript
@@ -63,6 +63,7 @@ main_sources = [
     'main/drawtex.c',
     'main/enable.c',
     'main/enums.c',
+    'main/errors.c',
     'main/eval.c',
     'main/execmem.c',
     'main/extensions.c',
diff --git a/src/mesa/main/descrip.mms b/src/mesa/main/descrip.mms
index 70bc263..91d7225 100644
--- a/src/mesa/main/descrip.mms
+++ b/src/mesa/main/descrip.mms
@@ -42,6 +42,7 @@ SOURCES =accum.c \
 	drawpix.c \
 	enable.c \
 	enums.c \
+	errors.c \
 	eval.c \
 	execmem.c \
 	extensions.c \
@@ -116,6 +117,7 @@ dlist.obj,\
 drawpix.obj,\
 enable.obj,\
 enums.obj,\
+errors.obj,\
 eval.obj,\
 execmem.obj,\
 extensions.obj,\
@@ -200,6 +202,7 @@ dlist.obj : dlist.c
 drawpix.obj : drawpix.c
 enable.obj : enable.c
 enums.obj : enums.c
+errors.obj : errors.c
 eval.obj : eval.c
 execmem.obj : execmem.c
 extensions.obj : extensions.c
diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c
new file mode 100644
index 0000000..009681a
--- /dev/null
+++ b/src/mesa/main/errors.c
@@ -0,0 +1,276 @@
+/**
+ * \file errors.c
+ * Mesa debugging and error handling functions.
+ */
+
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.1
+ *
+ * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+
+#include "imports.h"
+
+#include "context.h"
+#include "mtypes.h"
+#include "version.h"
+
+
+#define MAXSTRING 4000  /* for _mesa_vsnprintf() */
+
+/**********************************************************************/
+/** \name Diagnostics */
+/*@{*/
+
+static void
+output_if_debug(const char *prefixString, const char *outputString,
+                GLboolean newline)
+{
+   static int debug = -1;
+
+   /* Check the MESA_DEBUG environment variable if it hasn't
+    * been checked yet.  We only have to check it once...
+    */
+   if (debug == -1) {
+      char *env = _mesa_getenv("MESA_DEBUG");
+
+      /* In a debug build, we print warning messages *unless*
+       * MESA_DEBUG is 0.  In a non-debug build, we don't
+       * print warning messages *unless* MESA_DEBUG is
+       * set *to any value*.
+       */
+#ifdef DEBUG
+      debug = (env != NULL && atoi(env) == 0) ? 0 : 1;
+#else
+      debug = (env != NULL) ? 1 : 0;
+#endif
+   }
+
+   /* Now only print the string if we're required to do so. */
+   if (debug) {
+      fprintf(stderr, "%s: %s", prefixString, outputString);
+      if (newline)
+         fprintf(stderr, "\n");
+
+#if defined(_WIN32) && !defined(_WIN32_WCE)
+      /* stderr from windows applications without console is not usually
+       * visible, so communicate with the debugger instead */
+      {
+         char buf[4096];
+         _mesa_snprintf(buf, sizeof(buf), "%s: %s%s", prefixString,
outputString, newline ? "\n" : "");
+         OutputDebugStringA(buf);
+      }
+#endif
+   }
+}
+
+
+/**
+ * Return string version of GL error code.
+ */
+static const char *
+error_string( GLenum error )
+{
+   switch (error) {
+   case GL_NO_ERROR:
+      return "GL_NO_ERROR";
+   case GL_INVALID_VALUE:
+      return "GL_INVALID_VALUE";
+   case GL_INVALID_ENUM:
+      return "GL_INVALID_ENUM";
+   case GL_INVALID_OPERATION:
+      return "GL_INVALID_OPERATION";
+   case GL_STACK_OVERFLOW:
+      return "GL_STACK_OVERFLOW";
+   case GL_STACK_UNDERFLOW:
+      return "GL_STACK_UNDERFLOW";
+   case GL_OUT_OF_MEMORY:
+      return "GL_OUT_OF_MEMORY";
+   case GL_TABLE_TOO_LARGE:
+      return "GL_TABLE_TOO_LARGE";
+   case GL_INVALID_FRAMEBUFFER_OPERATION_EXT:
+      return "GL_INVALID_FRAMEBUFFER_OPERATION";
+   default:
+      return "unknown";
+   }
+}
+
+
+/**
+ * When a new type of error is recorded, print a message describing
+ * previous errors which were accumulated.
+ */
+static void
+flush_delayed_errors( struct gl_context *ctx )
+{
+   char s[MAXSTRING];
+
+   if (ctx->ErrorDebugCount) {
+      _mesa_snprintf(s, MAXSTRING, "%d similar %s errors",
+                     ctx->ErrorDebugCount,
+                     error_string(ctx->ErrorValue));
+
+      output_if_debug("Mesa", s, GL_TRUE);
+
+      ctx->ErrorDebugCount = 0;
+   }
+}
+
+
+/**
+ * Report a warning (a recoverable error condition) to stderr if
+ * either DEBUG is defined or the MESA_DEBUG env var is set.
+ *
+ * \param ctx GL context.
+ * \param fmtString printf()-like format string.
+ */
+void
+_mesa_warning( struct gl_context *ctx, const char *fmtString, ... )
+{
+   char str[MAXSTRING];
+   va_list args;
+   va_start( args, fmtString );
+   (void) _mesa_vsnprintf( str, MAXSTRING, fmtString, args );
+   va_end( args );
+
+   if (ctx)
+      flush_delayed_errors( ctx );
+
+   output_if_debug("Mesa warning", str, GL_TRUE);
+}
+
+
+/**
+ * Report an internal implementation problem.
+ * Prints the message to stderr via fprintf().
+ *
+ * \param ctx GL context.
+ * \param fmtString problem description string.
+ */
+void
+_mesa_problem( const struct gl_context *ctx, const char *fmtString, ... )
+{
+   va_list args;
+   char str[MAXSTRING];
+   static int numCalls = 0;
+
+   (void) ctx;
+
+   if (numCalls < 50) {
+      numCalls++;
+
+      va_start( args, fmtString );
+      _mesa_vsnprintf( str, MAXSTRING, fmtString, args );
+      va_end( args );
+      fprintf(stderr, "Mesa %s implementation error: %s\n",
+              MESA_VERSION_STRING, str);
+      fprintf(stderr, "Please report at bugs.freedesktop.org\n");
+   }
+}
+
+
+/**
+ * Record an OpenGL state error.  These usually occur when the user
+ * passes invalid parameters to a GL function.
+ *
+ * If debugging is enabled (either at compile-time via the DEBUG macro, or
+ * run-time via the MESA_DEBUG environment variable), report the error with
+ * _mesa_debug().
+ *
+ * \param ctx the GL context.
+ * \param error the error value.
+ * \param fmtString printf() style format string, followed by optional args
+ */
+void
+_mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... )
+{
+   static GLint debug = -1;
+
+   /* Check debug environment variable only once:
+    */
+   if (debug == -1) {
+      const char *debugEnv = _mesa_getenv("MESA_DEBUG");
+
+#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) {
+      if (ctx->ErrorValue == error &&
+          ctx->ErrorDebugFmtString == fmtString) {
+         ctx->ErrorDebugCount++;
+      }
+      else {
+         char s[MAXSTRING], s2[MAXSTRING];
+         va_list args;
+
+         flush_delayed_errors( ctx );
+
+         va_start(args, fmtString);
+         _mesa_vsnprintf(s, MAXSTRING, fmtString, args);
+         va_end(args);
+
+         _mesa_snprintf(s2, MAXSTRING, "%s in %s", error_string(error), s);
+         output_if_debug("Mesa: User error", s2, GL_TRUE);
+
+         ctx->ErrorDebugFmtString = fmtString;
+         ctx->ErrorDebugCount = 0;
+      }
+   }
+
+   _mesa_record_error(ctx, error);
+}
+
+
+/**
+ * Report debug information.  Print error message to stderr via fprintf().
+ * No-op if DEBUG mode not enabled.
+ *
+ * \param ctx GL context.
+ * \param fmtString printf()-style format string, followed by optional args.
+ */
+void
+_mesa_debug( const struct gl_context *ctx, const char *fmtString, ... )
+{
+#ifdef DEBUG
+   char s[MAXSTRING];
+   va_list args;
+   va_start(args, fmtString);
+   _mesa_vsnprintf(s, MAXSTRING, fmtString, args);
+   va_end(args);
+   output_if_debug("Mesa", s, GL_FALSE);
+#endif /* DEBUG */
+   (void) ctx;
+   (void) fmtString;
+}
+
+/*@}*/
diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
index f971338..005c122 100644
--- a/src/mesa/main/imports.c
+++ b/src/mesa/main/imports.c
@@ -57,8 +57,6 @@
 #endif


-#define MAXSTRING 4000  /* for vsnprintf() */
-
 #ifdef WIN32
 #define vsnprintf _vsnprintf
 #elif defined(__IBMC__) || defined(__IBMCPP__) || ( defined(__VMS) &&
__CRTL_VER < 70312000 )
@@ -803,239 +801,3 @@ _mesa_snprintf( char *str, size_t size, const
char *fmt, ... )
 }


-/**********************************************************************/
-/** \name Diagnostics */
-/*@{*/
-
-static void
-output_if_debug(const char *prefixString, const char *outputString,
-                GLboolean newline)
-{
-   static int debug = -1;
-
-   /* Check the MESA_DEBUG environment variable if it hasn't
-    * been checked yet.  We only have to check it once...
-    */
-   if (debug == -1) {
-      char *env = _mesa_getenv("MESA_DEBUG");
-
-      /* In a debug build, we print warning messages *unless*
-       * MESA_DEBUG is 0.  In a non-debug build, we don't
-       * print warning messages *unless* MESA_DEBUG is
-       * set *to any value*.
-       */
-#ifdef DEBUG
-      debug = (env != NULL && atoi(env) == 0) ? 0 : 1;
-#else
-      debug = (env != NULL) ? 1 : 0;
-#endif
-   }
-
-   /* Now only print the string if we're required to do so. */
-   if (debug) {
-      fprintf(stderr, "%s: %s", prefixString, outputString);
-      if (newline)
-         fprintf(stderr, "\n");
-
-#if defined(_WIN32) && !defined(_WIN32_WCE)
-      /* stderr from windows applications without console is not usually
-       * visible, so communicate with the debugger instead */
-      {
-         char buf[4096];
-         _mesa_snprintf(buf, sizeof(buf), "%s: %s%s", prefixString,
outputString, newline ? "\n" : "");
-         OutputDebugStringA(buf);
-      }
-#endif
-   }
-}
-
-
-/**
- * Return string version of GL error code.
- */
-static const char *
-error_string( GLenum error )
-{
-   switch (error) {
-   case GL_NO_ERROR:
-      return "GL_NO_ERROR";
-   case GL_INVALID_VALUE:
-      return "GL_INVALID_VALUE";
-   case GL_INVALID_ENUM:
-      return "GL_INVALID_ENUM";
-   case GL_INVALID_OPERATION:
-      return "GL_INVALID_OPERATION";
-   case GL_STACK_OVERFLOW:
-      return "GL_STACK_OVERFLOW";
-   case GL_STACK_UNDERFLOW:
-      return "GL_STACK_UNDERFLOW";
-   case GL_OUT_OF_MEMORY:
-      return "GL_OUT_OF_MEMORY";
-   case GL_TABLE_TOO_LARGE:
-      return "GL_TABLE_TOO_LARGE";
-   case GL_INVALID_FRAMEBUFFER_OPERATION_EXT:
-      return "GL_INVALID_FRAMEBUFFER_OPERATION";
-   default:
-      return "unknown";
-   }
-}
-
-
-/**
- * When a new type of error is recorded, print a message describing
- * previous errors which were accumulated.
- */
-static void
-flush_delayed_errors( struct gl_context *ctx )
-{
-   char s[MAXSTRING];
-
-   if (ctx->ErrorDebugCount) {
-      _mesa_snprintf(s, MAXSTRING, "%d similar %s errors",
-                     ctx->ErrorDebugCount,
-                     error_string(ctx->ErrorValue));
-
-      output_if_debug("Mesa", s, GL_TRUE);
-
-      ctx->ErrorDebugCount = 0;
-   }
-}
-
-
-/**
- * Report a warning (a recoverable error condition) to stderr if
- * either DEBUG is defined or the MESA_DEBUG env var is set.
- *
- * \param ctx GL context.
- * \param fmtString printf()-like format string.
- */
-void
-_mesa_warning( struct gl_context *ctx, const char *fmtString, ... )
-{
-   char str[MAXSTRING];
-   va_list args;
-   va_start( args, fmtString );
-   (void) vsnprintf( str, MAXSTRING, fmtString, args );
-   va_end( args );
-
-   if (ctx)
-      flush_delayed_errors( ctx );
-
-   output_if_debug("Mesa warning", str, GL_TRUE);
-}
-
-
-/**
- * Report an internal implementation problem.
- * Prints the message to stderr via fprintf().
- *
- * \param ctx GL context.
- * \param fmtString problem description string.
- */
-void
-_mesa_problem( const struct gl_context *ctx, const char *fmtString, ... )
-{
-   va_list args;
-   char str[MAXSTRING];
-   static int numCalls = 0;
-
-   (void) ctx;
-
-   if (numCalls < 50) {
-      numCalls++;
-
-      va_start( args, fmtString );
-      vsnprintf( str, MAXSTRING, fmtString, args );
-      va_end( args );
-      fprintf(stderr, "Mesa %s implementation error: %s\n",
-              MESA_VERSION_STRING, str);
-      fprintf(stderr, "Please report at bugs.freedesktop.org\n");
-   }
-}
-
-
-/**
- * Record an OpenGL state error.  These usually occur when the user
- * passes invalid parameters to a GL function.
- *
- * If debugging is enabled (either at compile-time via the DEBUG macro, or
- * run-time via the MESA_DEBUG environment variable), report the error with
- * _mesa_debug().
- *
- * \param ctx the GL context.
- * \param error the error value.
- * \param fmtString printf() style format string, followed by optional args
- */
-void
-_mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... )
-{
-   static GLint debug = -1;
-
-   /* Check debug environment variable only once:
-    */
-   if (debug == -1) {
-      const char *debugEnv = _mesa_getenv("MESA_DEBUG");
-
-#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) {
-      if (ctx->ErrorValue == error &&
-          ctx->ErrorDebugFmtString == fmtString) {
-         ctx->ErrorDebugCount++;
-      }
-      else {
-         char s[MAXSTRING], s2[MAXSTRING];
-         va_list args;
-
-         flush_delayed_errors( ctx );
-
-         va_start(args, fmtString);
-         vsnprintf(s, MAXSTRING, fmtString, args);
-         va_end(args);
-
-         _mesa_snprintf(s2, MAXSTRING, "%s in %s", error_string(error), s);
-         output_if_debug("Mesa: User error", s2, GL_TRUE);
-
-         ctx->ErrorDebugFmtString = fmtString;
-         ctx->ErrorDebugCount = 0;
-      }
-   }
-
-   _mesa_record_error(ctx, error);
-}
-
-
-/**
- * Report debug information.  Print error message to stderr via fprintf().
- * No-op if DEBUG mode not enabled.
- *
- * \param ctx GL context.
- * \param fmtString printf()-style format string, followed by optional args.
- */
-void
-_mesa_debug( const struct gl_context *ctx, const char *fmtString, ... )
-{
-#ifdef DEBUG
-   char s[MAXSTRING];
-   va_list args;
-   va_start(args, fmtString);
-   vsnprintf(s, MAXSTRING, fmtString, args);
-   va_end(args);
-   output_if_debug("Mesa", s, GL_FALSE);
-#endif /* DEBUG */
-   (void) ctx;
-   (void) fmtString;
-}
-
-/*@}*/
diff --git a/src/mesa/sources.mak b/src/mesa/sources.mak
index 9b2cb1a..be415b7 100644
--- a/src/mesa/sources.mak
+++ b/src/mesa/sources.mak
@@ -35,6 +35,7 @@ MAIN_SOURCES = \
 	main/drawtex.c \
 	main/enable.c \
 	main/enums.c \
+	main/errors.c \
 	main/eval.c \
 	main/execmem.c \
 	main/extensions.c \
-- 
1.7.0.4
-------------- next part --------------
From 67ba8469f3a304d18b5fe28697c95eeea1ddfd01 Mon Sep 17 00:00:00 2001
From: nobled <nobled at dreamwidth.org>
Date: Sun, 1 May 2011 15:44:41 +0000
Subject: [PATCH 3/5] mesa: split error handling into its own file

---
 src/mesa/SConscript       |    1 +
 src/mesa/main/descrip.mms |    3 +
 src/mesa/main/errors.c    |  276 +++++++++++++++++++++++++++++++++++++++++++++
 src/mesa/main/imports.c   |  238 --------------------------------------
 src/mesa/sources.mak      |    1 +
 5 files changed, 281 insertions(+), 238 deletions(-)
 create mode 100644 src/mesa/main/errors.c

diff --git a/src/mesa/SConscript b/src/mesa/SConscript
index 2d8a177..6bb546f 100644
--- a/src/mesa/SConscript
+++ b/src/mesa/SConscript
@@ -63,6 +63,7 @@ main_sources = [
     'main/drawtex.c',
     'main/enable.c',
     'main/enums.c',
+    'main/errors.c',
     'main/eval.c',
     'main/execmem.c',
     'main/extensions.c',
diff --git a/src/mesa/main/descrip.mms b/src/mesa/main/descrip.mms
index 70bc263..91d7225 100644
--- a/src/mesa/main/descrip.mms
+++ b/src/mesa/main/descrip.mms
@@ -42,6 +42,7 @@ SOURCES =accum.c \
 	drawpix.c \
 	enable.c \
 	enums.c \
+	errors.c \
 	eval.c \
 	execmem.c \
 	extensions.c \
@@ -116,6 +117,7 @@ dlist.obj,\
 drawpix.obj,\
 enable.obj,\
 enums.obj,\
+errors.obj,\
 eval.obj,\
 execmem.obj,\
 extensions.obj,\
@@ -200,6 +202,7 @@ dlist.obj : dlist.c
 drawpix.obj : drawpix.c
 enable.obj : enable.c
 enums.obj : enums.c
+errors.obj : errors.c
 eval.obj : eval.c
 execmem.obj : execmem.c
 extensions.obj : extensions.c
diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c
new file mode 100644
index 0000000..009681a
--- /dev/null
+++ b/src/mesa/main/errors.c
@@ -0,0 +1,276 @@
+/**
+ * \file errors.c
+ * Mesa debugging and error handling functions.
+ */
+
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.1
+ *
+ * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+
+#include "imports.h"
+
+#include "context.h"
+#include "mtypes.h"
+#include "version.h"
+
+
+#define MAXSTRING 4000  /* for _mesa_vsnprintf() */
+
+/**********************************************************************/
+/** \name Diagnostics */
+/*@{*/
+
+static void
+output_if_debug(const char *prefixString, const char *outputString,
+                GLboolean newline)
+{
+   static int debug = -1;
+
+   /* Check the MESA_DEBUG environment variable if it hasn't
+    * been checked yet.  We only have to check it once...
+    */
+   if (debug == -1) {
+      char *env = _mesa_getenv("MESA_DEBUG");
+
+      /* In a debug build, we print warning messages *unless*
+       * MESA_DEBUG is 0.  In a non-debug build, we don't
+       * print warning messages *unless* MESA_DEBUG is
+       * set *to any value*.
+       */
+#ifdef DEBUG
+      debug = (env != NULL && atoi(env) == 0) ? 0 : 1;
+#else
+      debug = (env != NULL) ? 1 : 0;
+#endif
+   }
+
+   /* Now only print the string if we're required to do so. */
+   if (debug) {
+      fprintf(stderr, "%s: %s", prefixString, outputString);
+      if (newline)
+         fprintf(stderr, "\n");
+
+#if defined(_WIN32) && !defined(_WIN32_WCE)
+      /* stderr from windows applications without console is not usually 
+       * visible, so communicate with the debugger instead */ 
+      {
+         char buf[4096];
+         _mesa_snprintf(buf, sizeof(buf), "%s: %s%s", prefixString, outputString, newline ? "\n" : "");
+         OutputDebugStringA(buf);
+      }
+#endif
+   }
+}
+
+
+/**
+ * Return string version of GL error code.
+ */
+static const char *
+error_string( GLenum error )
+{
+   switch (error) {
+   case GL_NO_ERROR:
+      return "GL_NO_ERROR";
+   case GL_INVALID_VALUE:
+      return "GL_INVALID_VALUE";
+   case GL_INVALID_ENUM:
+      return "GL_INVALID_ENUM";
+   case GL_INVALID_OPERATION:
+      return "GL_INVALID_OPERATION";
+   case GL_STACK_OVERFLOW:
+      return "GL_STACK_OVERFLOW";
+   case GL_STACK_UNDERFLOW:
+      return "GL_STACK_UNDERFLOW";
+   case GL_OUT_OF_MEMORY:
+      return "GL_OUT_OF_MEMORY";
+   case GL_TABLE_TOO_LARGE:
+      return "GL_TABLE_TOO_LARGE";
+   case GL_INVALID_FRAMEBUFFER_OPERATION_EXT:
+      return "GL_INVALID_FRAMEBUFFER_OPERATION";
+   default:
+      return "unknown";
+   }
+}
+
+
+/**
+ * When a new type of error is recorded, print a message describing
+ * previous errors which were accumulated.
+ */
+static void
+flush_delayed_errors( struct gl_context *ctx )
+{
+   char s[MAXSTRING];
+
+   if (ctx->ErrorDebugCount) {
+      _mesa_snprintf(s, MAXSTRING, "%d similar %s errors", 
+                     ctx->ErrorDebugCount,
+                     error_string(ctx->ErrorValue));
+
+      output_if_debug("Mesa", s, GL_TRUE);
+
+      ctx->ErrorDebugCount = 0;
+   }
+}
+
+
+/**
+ * Report a warning (a recoverable error condition) to stderr if
+ * either DEBUG is defined or the MESA_DEBUG env var is set.
+ *
+ * \param ctx GL context.
+ * \param fmtString printf()-like format string.
+ */
+void
+_mesa_warning( struct gl_context *ctx, const char *fmtString, ... )
+{
+   char str[MAXSTRING];
+   va_list args;
+   va_start( args, fmtString );  
+   (void) _mesa_vsnprintf( str, MAXSTRING, fmtString, args );
+   va_end( args );
+   
+   if (ctx)
+      flush_delayed_errors( ctx );
+
+   output_if_debug("Mesa warning", str, GL_TRUE);
+}
+
+
+/**
+ * Report an internal implementation problem.
+ * Prints the message to stderr via fprintf().
+ *
+ * \param ctx GL context.
+ * \param fmtString problem description string.
+ */
+void
+_mesa_problem( const struct gl_context *ctx, const char *fmtString, ... )
+{
+   va_list args;
+   char str[MAXSTRING];
+   static int numCalls = 0;
+
+   (void) ctx;
+
+   if (numCalls < 50) {
+      numCalls++;
+
+      va_start( args, fmtString );  
+      _mesa_vsnprintf( str, MAXSTRING, fmtString, args );
+      va_end( args );
+      fprintf(stderr, "Mesa %s implementation error: %s\n",
+              MESA_VERSION_STRING, str);
+      fprintf(stderr, "Please report at bugs.freedesktop.org\n");
+   }
+}
+
+
+/**
+ * Record an OpenGL state error.  These usually occur when the user
+ * passes invalid parameters to a GL function.
+ *
+ * If debugging is enabled (either at compile-time via the DEBUG macro, or
+ * run-time via the MESA_DEBUG environment variable), report the error with
+ * _mesa_debug().
+ * 
+ * \param ctx the GL context.
+ * \param error the error value.
+ * \param fmtString printf() style format string, followed by optional args
+ */
+void
+_mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... )
+{
+   static GLint debug = -1;
+
+   /* Check debug environment variable only once:
+    */
+   if (debug == -1) {
+      const char *debugEnv = _mesa_getenv("MESA_DEBUG");
+
+#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) {      
+      if (ctx->ErrorValue == error &&
+          ctx->ErrorDebugFmtString == fmtString) {
+         ctx->ErrorDebugCount++;
+      }
+      else {
+         char s[MAXSTRING], s2[MAXSTRING];
+         va_list args;
+
+         flush_delayed_errors( ctx );
+         
+         va_start(args, fmtString);
+         _mesa_vsnprintf(s, MAXSTRING, fmtString, args);
+         va_end(args);
+
+         _mesa_snprintf(s2, MAXSTRING, "%s in %s", error_string(error), s);
+         output_if_debug("Mesa: User error", s2, GL_TRUE);
+         
+         ctx->ErrorDebugFmtString = fmtString;
+         ctx->ErrorDebugCount = 0;
+      }
+   }
+
+   _mesa_record_error(ctx, error);
+}
+
+
+/**
+ * Report debug information.  Print error message to stderr via fprintf().
+ * No-op if DEBUG mode not enabled.
+ * 
+ * \param ctx GL context.
+ * \param fmtString printf()-style format string, followed by optional args.
+ */
+void
+_mesa_debug( const struct gl_context *ctx, const char *fmtString, ... )
+{
+#ifdef DEBUG
+   char s[MAXSTRING];
+   va_list args;
+   va_start(args, fmtString);
+   _mesa_vsnprintf(s, MAXSTRING, fmtString, args);
+   va_end(args);
+   output_if_debug("Mesa", s, GL_FALSE);
+#endif /* DEBUG */
+   (void) ctx;
+   (void) fmtString;
+}
+
+/*@}*/
diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
index f971338..005c122 100644
--- a/src/mesa/main/imports.c
+++ b/src/mesa/main/imports.c
@@ -57,8 +57,6 @@
 #endif
 
 
-#define MAXSTRING 4000  /* for vsnprintf() */
-
 #ifdef WIN32
 #define vsnprintf _vsnprintf
 #elif defined(__IBMC__) || defined(__IBMCPP__) || ( defined(__VMS) && __CRTL_VER < 70312000 )
@@ -803,239 +801,3 @@ _mesa_snprintf( char *str, size_t size, const char *fmt, ... )
 }
 
 
-/**********************************************************************/
-/** \name Diagnostics */
-/*@{*/
-
-static void
-output_if_debug(const char *prefixString, const char *outputString,
-                GLboolean newline)
-{
-   static int debug = -1;
-
-   /* Check the MESA_DEBUG environment variable if it hasn't
-    * been checked yet.  We only have to check it once...
-    */
-   if (debug == -1) {
-      char *env = _mesa_getenv("MESA_DEBUG");
-
-      /* In a debug build, we print warning messages *unless*
-       * MESA_DEBUG is 0.  In a non-debug build, we don't
-       * print warning messages *unless* MESA_DEBUG is
-       * set *to any value*.
-       */
-#ifdef DEBUG
-      debug = (env != NULL && atoi(env) == 0) ? 0 : 1;
-#else
-      debug = (env != NULL) ? 1 : 0;
-#endif
-   }
-
-   /* Now only print the string if we're required to do so. */
-   if (debug) {
-      fprintf(stderr, "%s: %s", prefixString, outputString);
-      if (newline)
-         fprintf(stderr, "\n");
-
-#if defined(_WIN32) && !defined(_WIN32_WCE)
-      /* stderr from windows applications without console is not usually 
-       * visible, so communicate with the debugger instead */ 
-      {
-         char buf[4096];
-         _mesa_snprintf(buf, sizeof(buf), "%s: %s%s", prefixString, outputString, newline ? "\n" : "");
-         OutputDebugStringA(buf);
-      }
-#endif
-   }
-}
-
-
-/**
- * Return string version of GL error code.
- */
-static const char *
-error_string( GLenum error )
-{
-   switch (error) {
-   case GL_NO_ERROR:
-      return "GL_NO_ERROR";
-   case GL_INVALID_VALUE:
-      return "GL_INVALID_VALUE";
-   case GL_INVALID_ENUM:
-      return "GL_INVALID_ENUM";
-   case GL_INVALID_OPERATION:
-      return "GL_INVALID_OPERATION";
-   case GL_STACK_OVERFLOW:
-      return "GL_STACK_OVERFLOW";
-   case GL_STACK_UNDERFLOW:
-      return "GL_STACK_UNDERFLOW";
-   case GL_OUT_OF_MEMORY:
-      return "GL_OUT_OF_MEMORY";
-   case GL_TABLE_TOO_LARGE:
-      return "GL_TABLE_TOO_LARGE";
-   case GL_INVALID_FRAMEBUFFER_OPERATION_EXT:
-      return "GL_INVALID_FRAMEBUFFER_OPERATION";
-   default:
-      return "unknown";
-   }
-}
-
-
-/**
- * When a new type of error is recorded, print a message describing
- * previous errors which were accumulated.
- */
-static void
-flush_delayed_errors( struct gl_context *ctx )
-{
-   char s[MAXSTRING];
-
-   if (ctx->ErrorDebugCount) {
-      _mesa_snprintf(s, MAXSTRING, "%d similar %s errors", 
-                     ctx->ErrorDebugCount,
-                     error_string(ctx->ErrorValue));
-
-      output_if_debug("Mesa", s, GL_TRUE);
-
-      ctx->ErrorDebugCount = 0;
-   }
-}
-
-
-/**
- * Report a warning (a recoverable error condition) to stderr if
- * either DEBUG is defined or the MESA_DEBUG env var is set.
- *
- * \param ctx GL context.
- * \param fmtString printf()-like format string.
- */
-void
-_mesa_warning( struct gl_context *ctx, const char *fmtString, ... )
-{
-   char str[MAXSTRING];
-   va_list args;
-   va_start( args, fmtString );  
-   (void) vsnprintf( str, MAXSTRING, fmtString, args );
-   va_end( args );
-   
-   if (ctx)
-      flush_delayed_errors( ctx );
-
-   output_if_debug("Mesa warning", str, GL_TRUE);
-}
-
-
-/**
- * Report an internal implementation problem.
- * Prints the message to stderr via fprintf().
- *
- * \param ctx GL context.
- * \param fmtString problem description string.
- */
-void
-_mesa_problem( const struct gl_context *ctx, const char *fmtString, ... )
-{
-   va_list args;
-   char str[MAXSTRING];
-   static int numCalls = 0;
-
-   (void) ctx;
-
-   if (numCalls < 50) {
-      numCalls++;
-
-      va_start( args, fmtString );  
-      vsnprintf( str, MAXSTRING, fmtString, args );
-      va_end( args );
-      fprintf(stderr, "Mesa %s implementation error: %s\n",
-              MESA_VERSION_STRING, str);
-      fprintf(stderr, "Please report at bugs.freedesktop.org\n");
-   }
-}
-
-
-/**
- * Record an OpenGL state error.  These usually occur when the user
- * passes invalid parameters to a GL function.
- *
- * If debugging is enabled (either at compile-time via the DEBUG macro, or
- * run-time via the MESA_DEBUG environment variable), report the error with
- * _mesa_debug().
- * 
- * \param ctx the GL context.
- * \param error the error value.
- * \param fmtString printf() style format string, followed by optional args
- */
-void
-_mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... )
-{
-   static GLint debug = -1;
-
-   /* Check debug environment variable only once:
-    */
-   if (debug == -1) {
-      const char *debugEnv = _mesa_getenv("MESA_DEBUG");
-
-#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) {      
-      if (ctx->ErrorValue == error &&
-          ctx->ErrorDebugFmtString == fmtString) {
-         ctx->ErrorDebugCount++;
-      }
-      else {
-         char s[MAXSTRING], s2[MAXSTRING];
-         va_list args;
-
-         flush_delayed_errors( ctx );
-         
-         va_start(args, fmtString);
-         vsnprintf(s, MAXSTRING, fmtString, args);
-         va_end(args);
-
-         _mesa_snprintf(s2, MAXSTRING, "%s in %s", error_string(error), s);
-         output_if_debug("Mesa: User error", s2, GL_TRUE);
-         
-         ctx->ErrorDebugFmtString = fmtString;
-         ctx->ErrorDebugCount = 0;
-      }
-   }
-
-   _mesa_record_error(ctx, error);
-}
-
-
-/**
- * Report debug information.  Print error message to stderr via fprintf().
- * No-op if DEBUG mode not enabled.
- * 
- * \param ctx GL context.
- * \param fmtString printf()-style format string, followed by optional args.
- */
-void
-_mesa_debug( const struct gl_context *ctx, const char *fmtString, ... )
-{
-#ifdef DEBUG
-   char s[MAXSTRING];
-   va_list args;
-   va_start(args, fmtString);
-   vsnprintf(s, MAXSTRING, fmtString, args);
-   va_end(args);
-   output_if_debug("Mesa", s, GL_FALSE);
-#endif /* DEBUG */
-   (void) ctx;
-   (void) fmtString;
-}
-
-/*@}*/
diff --git a/src/mesa/sources.mak b/src/mesa/sources.mak
index 9b2cb1a..be415b7 100644
--- a/src/mesa/sources.mak
+++ b/src/mesa/sources.mak
@@ -35,6 +35,7 @@ MAIN_SOURCES = \
 	main/drawtex.c \
 	main/enable.c \
 	main/enums.c \
+	main/errors.c \
 	main/eval.c \
 	main/execmem.c \
 	main/extensions.c \
-- 
1.7.0.4


More information about the mesa-dev mailing list