mesa: make error checking optional in _mesa_lookup_shader_include()
authorTimothy Arceri <tarceri@itsqueeze.com>
Mon, 26 Aug 2019 03:56:59 +0000 (13:56 +1000)
committerTimothy Arceri <tarceri@itsqueeze.com>
Wed, 20 Nov 2019 05:05:55 +0000 (05:05 +0000)
This will be usefull when implementing glIsNamedStringARB() which
doesn't do error checking, it just returns false for invalid
lookups instead.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Reviewed-by: Witold Baryluk <witold.baryluk@gmail.com>
src/mesa/main/shaderapi.c
src/mesa/main/shaderapi.h

index 82f4bdc8210bb880768158f2a82ee5a38094b1f1..13faf787a2d68af0233ecc94e6a410bd455cc06c 100644 (file)
@@ -3234,11 +3234,13 @@ static bool
 validate_and_tokenise_sh_incl(struct gl_context *ctx,
                               void *mem_ctx,
                               struct sh_incl_path_entry **path_list,
-                              char *full_path)
+                              char *full_path, bool error_check)
 {
    if (!valid_path_format(full_path)) {
-       _mesa_error(ctx, GL_INVALID_VALUE,
-                   "glNamedStringARB(invalid name %s)", full_path);
+      if (error_check) {
+         _mesa_error(ctx, GL_INVALID_VALUE,
+                     "glNamedStringARB(invalid name %s)", full_path);
+      }
       return false;
    }
 
@@ -3251,8 +3253,11 @@ validate_and_tokenise_sh_incl(struct gl_context *ctx,
 
    while (path_str != NULL) {
       if (strlen(path_str) == 0) {
-         _mesa_error(ctx, GL_INVALID_VALUE,
-                     "glNamedStringARB(invalid name %s)", full_path);
+         if (error_check) {
+            _mesa_error(ctx, GL_INVALID_VALUE,
+                        "glNamedStringARB(invalid name %s)", full_path);
+         }
+
          return false;
       }
 
@@ -3276,12 +3281,14 @@ validate_and_tokenise_sh_incl(struct gl_context *ctx,
 }
 
 const char *
-_mesa_lookup_shader_include(struct gl_context *ctx, char *path)
+_mesa_lookup_shader_include(struct gl_context *ctx, char *path,
+                            bool error_check)
 {
    void *mem_ctx = ralloc_context(NULL);
    struct sh_incl_path_entry *path_list;
 
-   if (!validate_and_tokenise_sh_incl(ctx, mem_ctx, &path_list, path)) {
+   if (!validate_and_tokenise_sh_incl(ctx, mem_ctx, &path_list, path,
+                                      error_check)) {
       ralloc_free(mem_ctx);
       return NULL;
    }
@@ -3352,7 +3359,8 @@ _mesa_NamedStringARB(GLenum type, GLint namelen, const GLchar *name,
    void *mem_ctx = ralloc_context(NULL);
    struct sh_incl_path_entry *path_list;
 
-   if (!validate_and_tokenise_sh_incl(ctx, mem_ctx, &path_list, name_cp)) {
+   if (!validate_and_tokenise_sh_incl(ctx, mem_ctx, &path_list, name_cp,
+                                      true)) {
       free(string_cp);
       free(name_cp);
       ralloc_free(mem_ctx);
@@ -3422,7 +3430,7 @@ _mesa_GetNamedStringARB(GLint namelen, const GLchar *name, GLsizei bufSize,
    if (!name_cp)
       return;
 
-   const char *source = _mesa_lookup_shader_include(ctx, name_cp);
+   const char *source = _mesa_lookup_shader_include(ctx, name_cp, true);
    if (!source) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
                   "%s(no string associated with path %s)", caller, name_cp);
index 05048672089658de642fce5ac42435ce599d34f4..13cde963ff86954e5f1938d182da29f5fc5e06e5 100644 (file)
@@ -416,7 +416,8 @@ void
 _mesa_destroy_shader_includes(struct gl_shared_state *shared);
 
 const char *
-_mesa_lookup_shader_include(struct gl_context *ctx, char *path);
+_mesa_lookup_shader_include(struct gl_context *ctx, char *path,
+                            bool error_check);
 
 #ifdef __cplusplus
 }