[Mesa-dev] [PATCH] hurd: Fix build
Samuel Thibault
samuel.thibault at ens-lyon.org
Sun Nov 13 23:30:36 UTC 2016
GNU/Hurd does not define PATH_MAX since it doesn't have such arbitrary
limitation. This drops the use of PATH_MAX by just allocating
the proper buffer size, and disables the path length check in
_mesa_get_shader_capture_path.
Signed-off-by: Samuel Thibault <samuel.thibault at ens-lyon.org>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=98632
---
src/mesa/main/arbprogram.c | 7 +++++--
src/mesa/main/shaderapi.c | 30 ++++++++++++++++++++++--------
2 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/src/mesa/main/arbprogram.c b/src/mesa/main/arbprogram.c
index 9c7622a..de5deed 100644
--- a/src/mesa/main/arbprogram.c
+++ b/src/mesa/main/arbprogram.c
@@ -382,11 +382,13 @@ _mesa_ProgramStringARB(GLenum target, GLenum format, GLsizei len,
const char *capture_path = _mesa_get_shader_capture_path();
if (capture_path != NULL) {
FILE *file;
- char filename[PATH_MAX];
+ char *filename;
const char *shader_type =
target == GL_FRAGMENT_PROGRAM_ARB ? "fragment" : "vertex";
+ size_t len = strlen(capture_path) + 1 + 1 + 2 + 10 + 12 + 1;
+ filename = malloc(len);
- _mesa_snprintf(filename, sizeof(filename), "%s/%cp-%u.shader_test",
+ _mesa_snprintf(filename, len, "%s/%cp-%u.shader_test",
capture_path, shader_type[0], prog->Id);
file = fopen(filename, "w");
if (file) {
@@ -397,6 +399,7 @@ _mesa_ProgramStringARB(GLenum target, GLenum format, GLsizei len,
} else {
_mesa_warning(ctx, "Failed to open %s", filename);
}
+ free(filename);
}
}
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index be3c203..0bf0267 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -112,6 +112,7 @@ _mesa_get_shader_capture_path(void)
if (!read_env_var) {
path = getenv("MESA_SHADER_CAPTURE_PATH");
read_env_var = true;
+#ifdef PATH_MAX
if (path &&
strlen(path) > PATH_MAX - strlen("/fp-4294967295.shader_test")) {
GET_CURRENT_CONTEXT(ctx);
@@ -119,6 +120,7 @@ _mesa_get_shader_capture_path(void)
"request to capture shaders");
path = NULL;
}
+#endif
}
return path;
@@ -1101,9 +1103,11 @@ _mesa_link_program(struct gl_context *ctx, struct gl_shader_program *shProg)
const char *capture_path = _mesa_get_shader_capture_path();
if (shProg->Name != 0 && shProg->Name != ~0 && capture_path != NULL) {
FILE *file;
- char filename[PATH_MAX];
+ char *filename;
+ size_t len = strlen(capture_path) + 1 + 10 + 12 + 1;
- _mesa_snprintf(filename, sizeof(filename), "%s/%u.shader_test",
+ filename = malloc(len);
+ _mesa_snprintf(filename, len, "%s/%u.shader_test",
capture_path, shProg->Name);
file = fopen(filename, "w");
@@ -1124,6 +1128,7 @@ _mesa_link_program(struct gl_context *ctx, struct gl_shader_program *shProg)
} else {
_mesa_warning(ctx, "Failed to open %s", filename);
}
+ free(filename);
}
if (shProg->LinkStatus == GL_FALSE &&
@@ -1618,18 +1623,25 @@ generate_sha1(const char *source, char sha_str[64])
*
* <path>/<stage prefix>_<CHECKSUM>.glsl
*/
-static void
+static char *
construct_name(const gl_shader_stage stage, const char *source,
- const char *path, char *name, unsigned length)
+ const char *path)
{
char sha[64];
static const char *types[] = {
"VS", "TC", "TE", "GS", "FS", "CS",
};
+ char *name;
+ size_t length;
generate_sha1(source, sha);
+
+ length = strlen(path) + 1 + 2 + 1 + strlen(sha) + 5 + 1;
+ name = malloc(length);
+
_mesa_snprintf(name, length, "%s/%s_%s.glsl", path, types[stage],
sha);
+ return name;
}
/**
@@ -1638,7 +1650,7 @@ construct_name(const gl_shader_stage stage, const char *source,
static void
dump_shader(const gl_shader_stage stage, const char *source)
{
- char name[PATH_MAX];
+ char *name;
static bool path_exists = true;
char *dump_path;
FILE *f;
@@ -1652,7 +1664,7 @@ dump_shader(const gl_shader_stage stage, const char *source)
return;
}
- construct_name(stage, source, dump_path, name, PATH_MAX);
+ name = construct_name(stage, source, dump_path);
f = fopen(name, "w");
if (f) {
@@ -1663,6 +1675,7 @@ dump_shader(const gl_shader_stage stage, const char *source)
_mesa_warning(ctx, "could not open %s for dumping shader (%s)", name,
strerror(errno));
}
+ free(name);
}
/**
@@ -1672,7 +1685,7 @@ dump_shader(const gl_shader_stage stage, const char *source)
static GLcharARB *
read_shader(const gl_shader_stage stage, const char *source)
{
- char name[PATH_MAX];
+ char *name;
char *read_path;
static bool path_exists = true;
int len, shader_size = 0;
@@ -1688,9 +1701,10 @@ read_shader(const gl_shader_stage stage, const char *source)
return NULL;
}
- construct_name(stage, source, read_path, name, PATH_MAX);
+ name = construct_name(stage, source, read_path);
f = fopen(name, "r");
+ free(name);
if (!f)
return NULL;
--
2.10.2
More information about the mesa-dev
mailing list