<div dir="ltr">Hi Brian,<div><br></div><div>I think I've pushed this patch. Could you verify that I haven't broken anything?</div><div><br></div><div>Thanks!</div><div>Courtney</div></div><div class="gmail_extra"><br>
<br><div class="gmail_quote">On Fri, Jun 6, 2014 at 7:20 PM, Brian Paul <span dir="ltr"><<a href="mailto:brianp@vmware.com" target="_blank">brianp@vmware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Reviewed-by: Brian Paul <<a href="mailto:brianp@vmware.com" target="_blank">brianp@vmware.com</a>><br>
<br>
Do you need someone to commit/push this for you?<br>
<br>
-Brian<div class=""><br>
<br>
On 06/06/2014 12:04 PM, Cody Northrop wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">
Whoops, yes, you're right.  ftell() of SEEK_END and strlen() are<br>
returning the same value, which does not include the terminating zero.<br>
Updated patch below.<br>
<br>
We use this quite a bit, much faster than editing large apitrace files<br>
<br>
Thanks,<br>
<br>
-C<br>
<br>
<br></div>
Signed-off-by: Cody Northrop <<a href="mailto:cody@lunarg.com" target="_blank">cody@lunarg.com</a> <mailto:<a href="mailto:cody@lunarg.com" target="_blank">cody@lunarg.com</a>>><div><div class="h5"><br>
---<br>
  src/mesa/main/shaderapi.c | 17 ++++++++++++++---<br>
  1 file changed, 14 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c<br>
index 6f84acd..4048ddf 100644<br>
--- a/src/mesa/main/shaderapi.c<br>
+++ b/src/mesa/main/shaderapi.c<br>
@@ -1392,7 +1392,7 @@ _mesa_LinkProgram(GLhandleARB programObj)<br>
  static GLcharARB *<br>
  read_shader(const char *fname)<br>
  {<br>
-   const int max = 50*1000;<br>
+   int shader_size = 0;<br>
     FILE *f = fopen(fname, "r");<br>
     GLcharARB *buffer, *shader;<br>
     int len;<br>
@@ -1401,8 +1401,19 @@ read_shader(const char *fname)<br>
        return NULL;<br>
     }<br>
<br>
-   buffer = malloc(max);<br>
-   len = fread(buffer, 1, max, f);<br>
+   /* allocate enough room for the entire shader */<br>
+   fseek(f, 0, SEEK_END);<br>
+   shader_size = ftell(f);<br>
+   rewind(f);<br>
+   assert(shader_size);<br>
+<br>
+   /* add one for terminating zero */<br>
+   shader_size++;<br>
+<br>
+   buffer = malloc(shader_size);<br>
+   assert(buffer);<br>
+<br>
+   len = fread(buffer, 1, shader_size, f);<br>
     buffer[len] = 0;<br>
<br>
     fclose(f);<br>
--<br>
1.8.3.2<br>
<br>
<br>
<br>
<br>
<br>
<br>
On Thu, Jun 5, 2014 at 7:13 PM, Brian Paul <<a href="mailto:brianp@vmware.com" target="_blank">brianp@vmware.com</a><br></div></div><div class="">
<mailto:<a href="mailto:brianp@vmware.com" target="_blank">brianp@vmware.com</a>>> wrote:<br>
<br>
    On 06/05/2014 10:47 AM, Cody Northrop wrote:<br>
<br>
        The fixed size is insufficient for shaders I'm debugging.<br>
          Rather than<br>
        just bump it up, make it dynamic.<br>
<br>
        Thanks,<br>
<br>
        -C<br>
<br>
        Signed-off-by: Cody Northrop <<a href="mailto:cody@lunarg.com" target="_blank">cody@lunarg.com</a><br></div>
        <mailto:<a href="mailto:cody@lunarg.com" target="_blank">cody@lunarg.com</a>> <mailto:<a href="mailto:cody@lunarg.com" target="_blank">cody@lunarg.com</a><div><div class="h5"><br>
        <mailto:<a href="mailto:cody@lunarg.com" target="_blank">cody@lunarg.com</a>>>><br>
<br>
        ---<br>
           src/mesa/main/shaderapi.c | 14 +++++++++++---<br>
           1 file changed, 11 insertions(+), 3 deletions(-)<br>
<br>
        diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c<br>
        index 6f84acd..e63c124 100644<br>
        --- a/src/mesa/main/shaderapi.c<br>
        +++ b/src/mesa/main/shaderapi.c<br>
        @@ -1392,7 +1392,7 @@ _mesa_LinkProgram(GLhandleARB programObj)<br>
           static GLcharARB *<br>
           read_shader(const char *fname)<br>
           {<br>
        -   const int max = 50*1000;<br>
        +   int shader_size = 0;<br>
              FILE *f = fopen(fname, "r");<br>
              GLcharARB *buffer, *shader;<br>
              int len;<br>
        @@ -1401,8 +1401,16 @@ read_shader(const char *fname)<br>
                 return NULL;<br>
              }<br>
<br>
        -   buffer = malloc(max);<br>
        -   len = fread(buffer, 1, max, f);<br>
        +   /* allocate enough room for the entire shader */<br>
        +   fseek(f, 0, SEEK_END);<br>
        +   shader_size = ftell(f);<br>
        +   rewind(f);<br>
        +   assert(shader_size);<br>
        +<br>
        +   buffer = malloc(shader_size);<br>
<br>
<br>
    Do you have to add one for the terminating zero?<br>
<br>
<br>
<br>
        +   assert(buffer);<br>
        +<br>
        +   len = fread(buffer, 1, shader_size, f);<br>
              buffer[len] = 0;<br>
<br>
              fclose(f);<br>
        --<br>
<br>
<br>
    I thought I was the only person who ever used this code!<br>
<br>
    Other than the one question above this looks alright.<br>
<br></div></div>
    Reviewed-by: Brian Paul <<a href="mailto:brianp@vmware.com" target="_blank">brianp@vmware.com</a> <mailto:<a href="mailto:brianp@vmware.com" target="_blank">brianp@vmware.com</a>>><br>
<br>
    ______________________________<u></u>___________________<br>
    mesa-dev mailing list<br>
    <a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a> <mailto:<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.<u></u>freedesktop.org</a>><br>

    <a href="http://lists.freedesktop.org/__mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/_<u></u>_mailman/listinfo/mesa-dev</a><br>
    <<a href="https://urldefense.proofpoint.com/v1/url?u=http://lists.freedesktop.org/mailman/listinfo/mesa-dev&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=lGQMzzTgII0I7jefp2FHq7WtZ%2BTLs8wadB%2BiIj9xpBY%3D%0A&m=BQB5tezP6JJarG3K6deQKB%2FgjK%2FGhKQvd8LRF8usgCs%3D%0A&s=6d587c1f9718375e59390ea001cad3ee836a3597c86c77596f02292c818b3051" target="_blank">https://urldefense.<u></u>proofpoint.com/v1/url?u=http:/<u></u>/lists.freedesktop.org/<u></u>mailman/listinfo/mesa-dev&k=<u></u>oIvRg1%2BdGAgOoM1BIlLLqw%3D%<u></u>3D%0A&r=<u></u>lGQMzzTgII0I7jefp2FHq7WtZ%<u></u>2BTLs8wadB%2BiIj9xpBY%3D%0A&m=<u></u>BQB5tezP6JJarG3K6deQKB%2FgjK%<u></u>2FGhKQvd8LRF8usgCs%3D%0A&s=<u></u>6d587c1f9718375e59390ea001cad3<u></u>ee836a3597c86c77596f02292c818b<u></u>3051</a>><div class="">
<br>
<br>
<br>
<br>
<br>
--<br>
  Cody Northrop<br>
  Graphics Software Engineer<br>
  LunarG, Inc.- 3D Driver Innovations<br></div>
  Email: <a href="mailto:cody@lunarg.com" target="_blank">cody@lunarg.com</a> <mailto:<a href="mailto:cody@lunarg.com" target="_blank">cody@lunarg.com</a>><br>
  Website: <a href="http://www.lunarg.com" target="_blank">http://www.lunarg.com</a><br>
<<a href="https://urldefense.proofpoint.com/v1/url?u=http://www.lunarg.com/&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=lGQMzzTgII0I7jefp2FHq7WtZ%2BTLs8wadB%2BiIj9xpBY%3D%0A&m=BQB5tezP6JJarG3K6deQKB%2FgjK%2FGhKQvd8LRF8usgCs%3D%0A&s=e4c25bb2e76d3a5cbff56061766e2be646a3106ae813979beea26ede2680e7ec" target="_blank">https://urldefense.<u></u>proofpoint.com/v1/url?u=http:/<u></u>/www.lunarg.com/&k=oIvRg1%<u></u>2BdGAgOoM1BIlLLqw%3D%3D%0A&r=<u></u>lGQMzzTgII0I7jefp2FHq7WtZ%<u></u>2BTLs8wadB%2BiIj9xpBY%3D%0A&m=<u></u>BQB5tezP6JJarG3K6deQKB%2FgjK%<u></u>2FGhKQvd8LRF8usgCs%3D%0A&s=<u></u>e4c25bb2e76d3a5cbff56061766e2b<u></u>e646a3106ae813979beea26ede2680<u></u>e7ec</a>><br>

</blockquote><div class="HOEnZb"><div class="h5">
<br>
______________________________<u></u>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/<u></u>mailman/listinfo/mesa-dev</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Courtney Goeltzenleuchter<br><div>LunarG</div><div><img src="http://media.lunarg.com/wp-content/themes/LunarG/images/logo.png" width="96" height="65"><br>
</div></div>
</div>