[Piglit] [PATCH] Define asprintf on Windows, and use it on vertex-program-two-side.
jfonseca at vmware.com
jfonseca at vmware.com
Wed Nov 30 08:38:40 PST 2011
From: José Fonseca <jfonseca at vmware.com>
This reverts commit c6fece4b926ca5348578a077f2158b6e280d040a.
---
tests/spec/gl-2.0/vertex-program-two-side.c | 30 ++++++++--------
tests/util/piglit-util.c | 51 +++++++++++++++++++++++++++
tests/util/piglit-util.h | 17 +++++++++
3 files changed, 83 insertions(+), 15 deletions(-)
diff --git a/tests/spec/gl-2.0/vertex-program-two-side.c b/tests/spec/gl-2.0/vertex-program-two-side.c
index 76242b1..500ea7c 100644
--- a/tests/spec/gl-2.0/vertex-program-two-side.c
+++ b/tests/spec/gl-2.0/vertex-program-two-side.c
@@ -129,23 +129,23 @@ piglit_display(void)
}
static void
-setup_output(char *out, const char *name, float *values)
+setup_output(char **out, const char *name, float *values)
{
- sprintf(out,
- " %s = vec4(%f, %f, %f, %f);\n",
- name,
- values[0],
- values[1],
- values[2],
- values[3]);
+ asprintf(out,
+ " %s = vec4(%f, %f, %f, %f);\n",
+ name,
+ values[0],
+ values[1],
+ values[2],
+ values[3]);
}
void
piglit_init(int argc, char **argv)
{
GLint vs, fs;
- static char vs_outputs[4][1024];
- static char vs_source[4096];
+ char *vs_outputs[4] = {"", "", "", ""};
+ char *vs_source;
int i;
piglit_require_GLSL();
@@ -179,15 +179,15 @@ piglit_init(int argc, char **argv)
}
if (front)
- setup_output(vs_outputs[0], "gl_FrontColor", frontcolor);
+ setup_output(&vs_outputs[0], "gl_FrontColor", frontcolor);
if (back)
- setup_output(vs_outputs[1], "gl_BackColor", backcolor);
+ setup_output(&vs_outputs[1], "gl_BackColor", backcolor);
if (front2)
- setup_output(vs_outputs[2], "gl_FrontSecondaryColor", secondary_frontcolor);
+ setup_output(&vs_outputs[2], "gl_FrontSecondaryColor", secondary_frontcolor);
if (back2)
- setup_output(vs_outputs[3], "gl_BackSecondaryColor", secondary_backcolor);
+ setup_output(&vs_outputs[3], "gl_BackSecondaryColor", secondary_backcolor);
- sprintf(vs_source,
+ asprintf(&vs_source,
"void main()\n"
"{\n"
" gl_Position = gl_Vertex;\n"
diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index 0969d35..0f7810e 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -41,6 +41,57 @@
#include "piglit-util.h"
+
+#if defined(_WIN32)
+
+/* Some versions of MinGW are missing _vscprintf's declaration, although they
+ * still provide the symbol in the import library.
+ */
+#ifdef __MINGW32__
+_CRTIMP int _vscprintf(const char *format, va_list argptr);
+#endif
+
+int asprintf(char **strp, const char *fmt, ...)
+{
+ va_list args;
+ va_list args_copy;
+ int length;
+ size_t size;
+
+ va_start(args, fmt);
+
+ va_copy(args_copy, args);
+
+#ifdef _WIN32
+ /* We need to use _vcsprintf to calculate the length as vsnprintf returns -1
+ * if the number of characters to write is greater than count.
+ */
+ length = _vscprintf(fmt, args_copy);
+#else
+ char dummy;
+ length = vsnprintf(&dummy, sizeof dummy, fmt, args_copy);
+#endif
+
+ va_end(args_copy);
+
+ assert(length >= 0);
+ size = length + 1;
+
+ *strp = malloc(size);
+ if (!*strp) {
+ return -1;
+ }
+
+ va_start(args, fmt);
+ vsnprintf(*strp, size, fmt, args);
+ va_end(args);
+
+ return length;
+}
+
+#endif /* _WIN32 */
+
+
void piglit_glutInit(int argc, char **argv)
{
glutInit(&argc, argv);
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index e89092b..95aedfd 100755
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -51,6 +51,7 @@ typedef unsigned __int64 uint64_t;
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <math.h>
#include <float.h>
@@ -71,8 +72,24 @@ roundf(float x) {
return x >= 0.0f ? floorf(x + 0.5f) : ceilf(x - 0.5f);
}
+#ifndef va_copy
+#ifdef __va_copy
+#define va_copy(dest, src) __va_copy((dest), (src))
+#else
+#define va_copy(dest, src) (dest) = (src)
+#endif
+#endif
+
#endif /* defined(_MSC_VER) */
+#ifdef _WIN32
+int asprintf(char **strp, const char *fmt, ...)
+#ifdef __GNUC__
+ __attribute__ ((format (printf, 2, 3)))
+#endif
+;
+#endif /* _WIN32 */
+
// Trick from http://tdistler.com/2011/03/24/how-to-define-nan-not-a-number-on-windows
#ifndef INFINITY
# define INFINITY (FLT_MAX + FLT_MAX)
--
1.7.7.3
More information about the Piglit
mailing list