intel/gen_decoder: Fix parsing of small genxml file.
authorRafael Antognolli <rafael.antognolli@intel.com>
Tue, 16 Jul 2019 17:00:18 +0000 (10:00 -0700)
committerRafael Antognolli <rafael.antognolli@intel.com>
Tue, 23 Jul 2019 17:45:19 +0000 (17:45 +0000)
When using gen_spec_load_from path, only abort decoding if the read
length is 0. Previously, we were aborting if finding an EOF, even if
something was read from the file.

Also only kill the decoded file if no commands or structs were found,
and print a message in such case.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
src/intel/common/gen_decoder.c

index 50ef2c4204fd294d94cd2218335c830a8966703b..90b0f97965f971d9cc36e36af6fef7f893693de0 100644 (file)
@@ -697,7 +697,7 @@ gen_spec_load_from_path(const struct gen_device_info *devinfo,
          gen_spec_destroy(ctx.spec);
          ctx.spec = NULL;
          goto end;
-      } else if (feof(input))
+      } else if (len == 0 && feof(input))
          goto end;
 
       if (XML_ParseBuffer(ctx.parser, len, len == 0) == 0) {
@@ -719,7 +719,11 @@ gen_spec_load_from_path(const struct gen_device_info *devinfo,
    free(filename);
 
    /* free ctx.spec if genxml is empty */
-   if (ctx.spec && _mesa_hash_table_num_entries(ctx.spec->commands) == 0) {
+   if (ctx.spec &&
+       _mesa_hash_table_num_entries(ctx.spec->commands) == 0 &&
+       _mesa_hash_table_num_entries(ctx.spec->structs) == 0) {
+      fprintf(stderr,
+              "Error parsing XML: empty spec.\n");
       gen_spec_destroy(ctx.spec);
       return NULL;
    }