[Mesa-dev] [PATCH 3/4] glsl: Create a standalone executable for testing optimization passes.

Paul Berry stereotype441 at gmail.com
Wed Jul 20 09:34:34 PDT 2011


On 20 July 2011 08:50, Kenneth Graunke <kenneth at whitecape.org> wrote:
> Without taking sides, I would like to point out load_text_file, which
> already implements this.  Unfortunately, it got cut and pasted and
> diverged, so there's one in glsl/main.cpp and one in glsl/glcpp/glcpp.c.
>  (That should probably be fixed.)  Paul seemed to think the one in
> main.cpp wouldn't work with stdin, but I know for a fact the one in
> glcpp does.

Thanks for pointing this out, Kenneth.  I wasn't aware of the function
in glcpp.c, and you're right, load_text_fp() looks like it would work
just fine with stdin.  It also has a few advantages over the strawman
C implementation of read_stdin_to_eof() I sent to the list yesterday
(namely, it avoids some unnecessary copying, it checks for memory
allocation failure, and it grows its buffer size by factors of 2,
which is likely to be a huge win for large files).  It has a memory
leak in its failure handling code (if the call to reralloc_size()
fails, it never frees the original block of memory), but this is
unlikely to cause problems in practice.

I still prefer the 3-line C++ implementation of read_stdin_to_eof() to
the 20-some lines of load_text_fp(), but if the consensus is against
me, I'd be willing to rework my patch to call lord_text_fp(), in the
interest of not bike-shedding this any longer.


More information about the mesa-dev mailing list