<div dir="ltr">On 31 July 2013 20:41, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im">On 07/31/2013 05:16 PM, Ian Romanick wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im">
On 07/30/2013 03:16 PM, Kenneth Graunke wrote:<br>
</div><div class="im"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
This code is getting ugly.  It looks like the idea is to allocate two<br>
(now three) separate arrays, but somebody decided to be "clever" and<br>
batch them into a single calloc/free big enough to hold all of them.<br>
</blockquote>
<br>
Yeah, that was me.  Since way back, I hate dipping into malloc/free for<br>
a bunch of small, short-lived allocations.  What I really want to use is<br>
alloca, but alas.<br>
</div></blockquote>
<br>
In C++ you can just do:<br>
<br>
struct gl_shader *vert_shader_list[prog-><u></u>NumShaders];<br>
<br>
which basically does alloca() as far as I can tell.  The problem is, any out of bounds writes smash the stack, and can't be caught by tools like Valgrind.<br>
<br>
--Ken<br>
</blockquote></div><br></div><div class="gmail_extra">Actually that's a C99 feature ("variable length arrays"), although GCC allows it as a C++ extension (try compiling with "-pedantic" and you'll get a warning).  As far as I can tell from some internet research, MSVC doesn't support the feature at all, so unfortunately we can't use it in core mesa.</div>
</div>