mesa: Branch 'master' - 14 commits

Brian Paul brianp at kemper.freedesktop.org
Sat Apr 21 16:05:16 UTC 2007


 progs/demos/arbfplight.c                        |    4 
 progs/demos/fplight.c                           |    6 -
 src/mesa/shader/nvfragparse.c                   |   12 --
 src/mesa/shader/prog_execute.c                  |    3 
 src/mesa/shader/prog_instruction.c              |    8 +
 src/mesa/shader/program.c                       |    2 
 src/mesa/shader/shader_api.c                    |    5 
 src/mesa/shader/slang/slang_compile_operation.c |   32 ++---
 src/mesa/shader/slang/slang_emit.c              |    9 +
 src/mesa/shader/slang/slang_link.c              |    6 -
 src/mesa/shader/slang/slang_mem.c               |  142 ++++++++++++++++++++++++
 src/mesa/shader/slang/slang_mem.h               |   59 +++++++++
 src/mesa/shader/slang/slang_preprocess.c        |    2 
 src/mesa/sources                                |    1 
 src/mesa/swrast/s_fragprog.c                    |    2 
 15 files changed, 260 insertions(+), 33 deletions(-)

New commits:
diff-tree d5e7234ba80c59505838c67c92501fa7cfde0b66 (from bc74cb4c0ae6210eab403ee879492fc19644b3f2)
Author: Brian <brian at yutani.localnet.net>
Date:   Fri Apr 20 12:59:26 2007 -0600

    call grammar_alloc_free() to fix memleaks

diff --git a/src/mesa/shader/slang/slang_preprocess.c b/src/mesa/shader/slang/slang_preprocess.c
index 66a6a98..72281ed 100644
--- a/src/mesa/shader/slang/slang_preprocess.c
+++ b/src/mesa/shader/slang/slang_preprocess.c
@@ -1138,10 +1138,12 @@ preprocess_source (slang_string *output,
       goto error;
    }
 
+   grammar_alloc_free(prod);
    pp_state_free (&state);
    return GL_TRUE;
 
 error:
+   grammar_alloc_free(prod);
    pp_state_free (&state);
    return GL_FALSE;
 }
diff-tree bc74cb4c0ae6210eab403ee879492fc19644b3f2 (from 257f799849a1eb3e81851b92a8fd27efa8f93d47)
Author: Brian <brian at yutani.localnet.net>
Date:   Fri Apr 20 11:59:18 2007 -0600

    destroy window upon exit

diff --git a/progs/demos/arbfplight.c b/progs/demos/arbfplight.c
index d9c564f..bc2c7e3 100644
--- a/progs/demos/arbfplight.c
+++ b/progs/demos/arbfplight.c
@@ -24,6 +24,7 @@ static GLuint VertProg;
 static GLboolean Anim = GL_TRUE;
 static GLboolean Wire = GL_FALSE;
 static GLboolean PixelLight = GL_TRUE;
+static GLint Win;
 
 static GLint T0 = 0;
 static GLint Frames = 0;
@@ -148,6 +149,7 @@ static void Key( unsigned char key, int 
       case 27:
          glDeleteProgramsARB_func(1, &VertProg);
          glDeleteProgramsARB_func(1, &FragProg);
+         glutDestroyWindow(Win);
          exit(0);
          break;
    }
@@ -382,7 +384,7 @@ int main( int argc, char *argv[] )
    glutInitWindowPosition( 0, 0 );
    glutInitWindowSize( 200, 200 );
    glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
-   glutCreateWindow(argv[0]);
+   Win = glutCreateWindow(argv[0]);
    glutReshapeFunc( Reshape );
    glutKeyboardFunc( Key );
    glutSpecialFunc( SpecialKey );
diff --git a/progs/demos/fplight.c b/progs/demos/fplight.c
index c7a3824..fb510cc 100644
--- a/progs/demos/fplight.c
+++ b/progs/demos/fplight.c
@@ -24,7 +24,7 @@ static GLuint VertProg;
 static GLboolean Anim = GL_TRUE;
 static GLboolean Wire = GL_FALSE;
 static GLboolean PixelLight = GL_TRUE;
-
+static GLint Win;
 static GLfloat Xrot = 0, Yrot = 0;
 
 
@@ -136,8 +136,8 @@ static void Key( unsigned char key, int 
          }
          break;
       case 27:
+         glutDestroyWindow(Win);
          exit(0);
-         break;
    }
    glutPostRedisplay();
 }
@@ -272,7 +272,7 @@ int main( int argc, char *argv[] )
    glutInitWindowPosition( 0, 0 );
    glutInitWindowSize( 200, 200 );
    glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
-   glutCreateWindow(argv[0]);
+   Win = glutCreateWindow(argv[0]);
    glutReshapeFunc( Reshape );
    glutKeyboardFunc( Key );
    glutSpecialFunc( SpecialKey );
diff-tree 257f799849a1eb3e81851b92a8fd27efa8f93d47 (from 81c4fee160cd2840caf77bbdbf462e783911141a)
Author: Brian <brian at yutani.localnet.net>
Date:   Fri Apr 20 11:54:30 2007 -0600

    remove more unused vars, assertions

diff --git a/src/mesa/shader/nvfragparse.c b/src/mesa/shader/nvfragparse.c
index 02da3ad..0f1a1ea 100644
--- a/src/mesa/shader/nvfragparse.c
+++ b/src/mesa/shader/nvfragparse.c
@@ -1036,25 +1036,23 @@ Parse_VectorSrc(struct parse_state *pars
    else if (IsDigit(token[0]) || token[0] == '-' || token[0] == '+' || token[0] == '.'){
       /* literal scalar constant */
       GLfloat values[4];
-      GLuint paramIndex, swizzle;
+      GLuint paramIndex;
       if (!Parse_ScalarConstant(parseState, values))
          RETURN_ERROR;
       paramIndex = _mesa_add_unnamed_constant(parseState->parameters,
                                               values, 4, NULL);
-      ASSERT(swizzle == SWIZZLE_NOOP);
       srcReg->File = PROGRAM_NAMED_PARAM;
       srcReg->Index = paramIndex;
    }
    else if (token[0] == '{'){
       /* literal vector constant */
       GLfloat values[4];
-      GLuint paramIndex, swizzle;
+      GLuint paramIndex;
       (void) Parse_String(parseState, "{");
       if (!Parse_VectorConstant(parseState, values))
          RETURN_ERROR;
       paramIndex = _mesa_add_unnamed_constant(parseState->parameters,
                                               values, 4, NULL);
-      ASSERT(swizzle == SWIZZLE_NOOP);
       srcReg->File = PROGRAM_NAMED_PARAM;
       srcReg->Index = paramIndex;      
    }
diff-tree 81c4fee160cd2840caf77bbdbf462e783911141a (from 1fbdd9d794ca61512eb65d3e228f5fb29fb1ed83)
Author: Brian <brian at yutani.localnet.net>
Date:   Fri Apr 20 11:53:48 2007 -0600

    remove unused vars, assertions

diff --git a/src/mesa/shader/nvfragparse.c b/src/mesa/shader/nvfragparse.c
index ffa7ba4..02da3ad 100644
--- a/src/mesa/shader/nvfragparse.c
+++ b/src/mesa/shader/nvfragparse.c
@@ -1140,13 +1140,12 @@ Parse_ScalarSrcReg(struct parse_state *p
    else if (token[0] == '{') {
       /* vector literal */
       GLfloat values[4];
-      GLuint paramIndex, swizzle;
+      GLuint paramIndex;
       (void) Parse_String(parseState, "{");
       if (!Parse_VectorConstant(parseState, values))
          RETURN_ERROR;
       paramIndex = _mesa_add_unnamed_constant(parseState->parameters,
                                               values, 4, NULL);
-      ASSERT(swizzle == SWIZZLE_NOOP);
       srcReg->File = PROGRAM_NAMED_PARAM;
       srcReg->Index = paramIndex;      
    }
@@ -1167,12 +1166,11 @@ Parse_ScalarSrcReg(struct parse_state *p
    else if (IsDigit(token[0])) {
       /* scalar literal */
       GLfloat values[4];
-      GLuint paramIndex, swizzle;
+      GLuint paramIndex;
       if (!Parse_ScalarConstant(parseState, values))
          RETURN_ERROR;
       paramIndex = _mesa_add_unnamed_constant(parseState->parameters,
                                               values, 4, NULL);
-      ASSERT(swizzle == SWIZZLE_NOOP);
       srcReg->Index = paramIndex;      
       srcReg->File = PROGRAM_NAMED_PARAM;
       needSuffix = GL_FALSE;
diff-tree 1fbdd9d794ca61512eb65d3e228f5fb29fb1ed83 (from 82839e8430aa7f88357cad887ae2d804072de568)
Author: Brian <brian at yutani.localnet.net>
Date:   Fri Apr 20 08:30:42 2007 -0600

    added slang_mem.c

diff --git a/src/mesa/sources b/src/mesa/sources
index 6a6d594..0066c59 100644
--- a/src/mesa/sources
+++ b/src/mesa/sources
@@ -182,6 +182,7 @@ SLANG_SOURCES =	\
 	shader/slang/slang_library_noise.c	\
 	shader/slang/slang_link.c	\
 	shader/slang/slang_log.c	\
+	shader/slang/slang_mem.c	\
 	shader/slang/slang_preprocess.c	\
 	shader/slang/slang_print.c	\
 	shader/slang/slang_simplify.c	\
diff-tree 82839e8430aa7f88357cad887ae2d804072de568 (from ced6f76404ff1a6713c85edff17551f82c33cc24)
Author: Brian <brian at yutani.localnet.net>
Date:   Fri Apr 20 08:30:24 2007 -0600

    Memory pool manager.
    
    Instead of doing intricate malloc/free tracking during compiling, allocate
    everything (which would be discarded after compiling) from a pool that can
    be freed en masse when done.

diff --git a/src/mesa/shader/slang/slang_mem.c b/src/mesa/shader/slang/slang_mem.c
new file mode 100644
index 0000000..c7be9a7
--- /dev/null
+++ b/src/mesa/shader/slang/slang_mem.c
@@ -0,0 +1,142 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  6.5.3
+ *
+ * Copyright (C) 2005-2007  Brian Paul   All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file slang_mem.c
+ *
+ * Memory manager for GLSL compiler.  The general idea is to do all
+ * allocations out of a large pool then just free the pool when done
+ * compiling to avoid intricate malloc/free tracking and memory leaks.
+ *
+ * \author Brian Paul
+ */
+
+#include "context.h"
+#include "slang_mem.h"
+
+#define GRANULARITY 8
+#define ROUND_UP(B)  ( ((B) + (GRANULARITY - 1)) & ~(GRANULARITY - 1) )
+
+
+slang_mempool *
+_slang_new_mempool(GLuint initialSize)
+{
+   slang_mempool *pool = (slang_mempool *) _mesa_calloc(sizeof(slang_mempool));
+   if (pool) {
+      pool->Data = (char *) _mesa_calloc(initialSize);
+      if (!pool->Data) {
+         _mesa_free(pool);
+         return NULL;
+      }
+      pool->Size = initialSize;
+      pool->Used = 0;
+   }
+   return pool;
+}
+
+
+void
+_slang_delete_mempool(slang_mempool *pool)
+{
+   GLuint total = 0;
+   while (pool) {
+      slang_mempool *next = pool->Next;
+      total += pool->Used;
+      _mesa_free(pool->Data);
+      _mesa_free(pool);
+      pool = next;
+   }
+   printf("TOTAL USED %u\n", total);
+}
+
+
+/**
+ * Alloc 'bytes' from shader mempool.
+ */
+void *
+_slang_alloc(GLuint bytes)
+{
+   slang_mempool *pool;
+   GET_CURRENT_CONTEXT(ctx);
+
+   pool = (slang_mempool *) ctx->Shader.MemPool;
+
+   while (pool) {
+      if (pool->Used + bytes <= pool->Size) {
+         /* found room */
+         void *addr = (void *) (pool->Data + pool->Used);
+         pool->Used += ROUND_UP(bytes);
+         /*printf("alloc %u  Used %u\n", bytes, pool->Used);*/
+         return addr;
+      }
+      else if (pool->Next) {
+         /* try next block */
+         pool = pool->Next;
+      }
+      else {
+         /* alloc new pool */
+         assert(bytes <= pool->Size); /* XXX or max2() */
+         pool->Next = _slang_new_mempool(pool->Size);
+         if (!pool->Next) {
+            /* we're _really_ out of memory */
+            return NULL;
+         }
+         else {
+            pool->Used = ROUND_UP(bytes);
+            return (void *) pool->Data;
+         }
+      }
+   }
+   return NULL;
+}
+
+
+void *
+_slang_realloc(void *oldBuffer, GLuint oldSize, GLuint newSize)
+{
+   const GLuint copySize = (oldSize < newSize) ? oldSize : newSize;
+   void *newBuffer = _slang_alloc(newSize);
+   if (newBuffer && oldBuffer && copySize > 0)
+      _mesa_memcpy(newBuffer, oldBuffer, copySize);
+   return newBuffer;
+}
+
+
+/**
+ * Clone string, storing in current mempool.
+ */
+char *
+_slang_strdup(const char *s)
+{
+   if (s) {
+      size_t l = _mesa_strlen(s);
+      char *s2 = (char *) _slang_alloc(l + 1);
+      if (s2)
+         _mesa_strcpy(s2, s);
+      return s2;
+   }
+   else {
+      return NULL;
+   }
+}
diff --git a/src/mesa/shader/slang/slang_mem.h b/src/mesa/shader/slang/slang_mem.h
new file mode 100644
index 0000000..f448926
--- /dev/null
+++ b/src/mesa/shader/slang/slang_mem.h
@@ -0,0 +1,59 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  6.5.3
+ *
+ * Copyright (C) 2005-2007  Brian Paul   All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#ifndef SLANG_MEM_H
+#define SLANG_MEM_H
+
+
+#include "imports.h"
+
+
+typedef struct slang_mempool_
+{
+   GLuint Size, Used;
+   char *Data;
+   struct slang_mempool_ *Next;
+} slang_mempool;
+
+
+extern slang_mempool *
+_slang_new_mempool(GLuint initialSize);
+
+extern void
+_slang_delete_mempool(slang_mempool *pool);
+
+extern void *
+_slang_alloc(GLuint bytes);
+
+extern void *
+_slang_realloc(void *oldBuffer, GLuint oldSize, GLuint newSize);
+
+extern char *
+_slang_strdup(const char *s);
+
+
+#define USE_MEMPOOL 1  /* XXX temporary */
+
+#endif
diff-tree ced6f76404ff1a6713c85edff17551f82c33cc24 (from 4cc2674aee98a4c2972f4f097a89b7b4a30df4ab)
Author: Brian <brian at yutani.localnet.net>
Date:   Fri Apr 20 08:21:49 2007 -0600

    undo a test/debug change

diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c
index 1b5f20d..882fec2 100644
--- a/src/mesa/swrast/s_fragprog.c
+++ b/src/mesa/swrast/s_fragprog.c
@@ -104,7 +104,7 @@ init_machine(GLcontext *ctx, struct gl_p
    if (ctx->FragmentProgram.CallbackEnabled)
       inputsRead = ~0;
 
-   if (1/*program->Base.Target == GL_FRAGMENT_PROGRAM_NV*/) {
+   if (program->Base.Target == GL_FRAGMENT_PROGRAM_NV) {
       /* Clear temporary registers (undefined for ARB_f_p) */
       _mesa_bzero(machine->Temporaries,
                   MAX_PROGRAM_TEMPS * 4 * sizeof(GLfloat));
diff-tree 4cc2674aee98a4c2972f4f097a89b7b4a30df4ab (from a7f7366d382b2fe124f1495baf0360bffa30f0c0)
Author: Brian <brian at yutani.localnet.net>
Date:   Fri Apr 20 08:12:17 2007 -0600

    fix instruction comment code

diff --git a/src/mesa/shader/prog_instruction.c b/src/mesa/shader/prog_instruction.c
index 1e8e081..d6b5652 100644
--- a/src/mesa/shader/prog_instruction.c
+++ b/src/mesa/shader/prog_instruction.c
@@ -108,7 +108,13 @@ struct prog_instruction *
 _mesa_copy_instructions(struct prog_instruction *dest,
                         const struct prog_instruction *src, GLuint n)
 {
-   return _mesa_memcpy(dest, src, n * sizeof(struct prog_instruction));
+   GLuint i;
+   _mesa_memcpy(dest, src, n * sizeof(struct prog_instruction));
+   for (i = 0; i < n; i++) {
+      if (src[i].Comment)
+         dest[i].Comment = _mesa_strdup(src[i].Comment);
+   }
+   return dest;
 }
 
 
diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c
index e872d78..4205919 100644
--- a/src/mesa/shader/program.c
+++ b/src/mesa/shader/program.c
@@ -281,6 +281,8 @@ _mesa_delete_program(GLcontext *ctx, str
       for (i = 0; i < prog->NumInstructions; i++) {
          if (prog->Instructions[i].Data)
             _mesa_free(prog->Instructions[i].Data);
+         if (prog->Instructions[i].Comment)
+            _mesa_free((char *) prog->Instructions[i].Comment);
       }
       _mesa_free(prog->Instructions);
    }
diff-tree a7f7366d382b2fe124f1495baf0360bffa30f0c0 (from 11e3f733ba5c26f68fb8a7d69e6f94c1b5361f7d)
Author: Brian <brian at yutani.localnet.net>
Date:   Fri Apr 20 08:11:51 2007 -0600

    another bit of debug code

diff --git a/src/mesa/shader/prog_execute.c b/src/mesa/shader/prog_execute.c
index 013d65c..356d4ce 100644
--- a/src/mesa/shader/prog_execute.c
+++ b/src/mesa/shader/prog_execute.c
@@ -933,6 +933,9 @@ _mesa_execute_program(GLcontext * ctx,
             else {
                cond = eval_condition(machine, inst);
             }
+            if (DEBUG_PROG) {
+               printf("IF: %d\n", cond);
+            }
             /* do if/else */
             if (cond) {
                /* do if-clause (just continue execution) */
diff-tree 11e3f733ba5c26f68fb8a7d69e6f94c1b5361f7d (from 98ef18909a97dea9a28f0fe30797c0353a1117ce)
Author: Brian <brian at yutani.localnet.net>
Date:   Thu Apr 19 15:37:24 2007 -0600

    free subroutine array (fix mem leak)

diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index c2f2e85..badeb69 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -1762,6 +1762,7 @@ _slang_resolve_subroutines(slang_emit_in
    mainP->Instructions = _mesa_realloc_instructions(mainP->Instructions,
                                                     mainP->NumInstructions,
                                                     total);
+   mainP->NumInstructions = total;
    for (i = 0; i < emitInfo->NumSubroutines; i++) {
       struct gl_program *sub = emitInfo->Subroutines[i];
       _mesa_copy_instructions(mainP->Instructions + subroutineLoc[i],
@@ -1771,7 +1772,13 @@ _slang_resolve_subroutines(slang_emit_in
       sub->Parameters = NULL; /* prevent double-free */
       _mesa_delete_program(ctx, sub);
    }
-   mainP->NumInstructions = total;
+
+   /* free subroutine list */
+   if (emitInfo->Subroutines) {
+      _mesa_free(emitInfo->Subroutines);
+      emitInfo->Subroutines = NULL;
+   }
+   emitInfo->NumSubroutines = 0;
 
    /* Examine CAL instructions.
     * At this point, the BranchTarget field of the CAL instructions is
diff-tree 98ef18909a97dea9a28f0fe30797c0353a1117ce (from f2346498aacdfc3e574fed43e0fe13ad3f8e2a2d)
Author: Brian <brian at yutani.localnet.net>
Date:   Thu Apr 19 15:30:11 2007 -0600

    new varnames in slang_operation_insert()

diff --git a/src/mesa/shader/slang/slang_compile_operation.c b/src/mesa/shader/slang/slang_compile_operation.c
index 5d80bc7..dfba196 100644
--- a/src/mesa/shader/slang/slang_compile_operation.c
+++ b/src/mesa/shader/slang/slang_compile_operation.c
@@ -175,40 +175,40 @@ slang_operation_grow(GLuint *numChildren
 
 /**
  * Insert a new slang_operation into an array.
- * \param numChildren  pointer to current number of children (in/out)
- * \param children  address of array (in/out)
- * \param pos  position to insert
- * \return  pointer to the new operation
+ * \param numElements  pointer to current array size (in/out)
+ * \param array  address of the array (in/out)
+ * \param pos  position to insert new element
+ * \return  pointer to the new operation/element
  */
 slang_operation *
-slang_operation_insert(GLuint *numChildren, slang_operation **children,
+slang_operation_insert(GLuint *numElements, slang_operation **array,
                        GLuint pos)
 {
    slang_operation *ops;
 
-   assert(pos <= *numChildren);
+   assert(pos <= *numElements);
 
    ops = (slang_operation *)
-      _mesa_malloc((*numChildren + 1) * sizeof(slang_operation));
+      _mesa_malloc((*numElements + 1) * sizeof(slang_operation));
    if (ops) {
       slang_operation *newOp;
       newOp = ops + pos;
       if (pos > 0)
-         _mesa_memcpy(ops, *children, pos * sizeof(slang_operation));
-      if (pos < *numChildren)
-         _mesa_memcpy(newOp + 1, (*children) + pos,
-                      (*numChildren - pos) * sizeof(slang_operation));
+         _mesa_memcpy(ops, *array, pos * sizeof(slang_operation));
+      if (pos < *numElements)
+         _mesa_memcpy(newOp + 1, (*array) + pos,
+                      (*numElements - pos) * sizeof(slang_operation));
 
       if (!slang_operation_construct(newOp)) {
          _mesa_free(ops);
-         *numChildren = 0;
-         *children = NULL;
+         *numElements = 0;
+         *array = NULL;
          return NULL;
       }
-      if (*children)
-         _mesa_free(*children);
-      *children = ops;
-      (*numChildren)++;
+      if (*array)
+         _mesa_free(*array);
+      *array = ops;
+      (*numElements)++;
       return newOp;
    }
    return NULL;
diff-tree f2346498aacdfc3e574fed43e0fe13ad3f8e2a2d (from 4b7c6fc5a655bfb8f165cb94521bc49521303a35)
Author: Brian <brian at yutani.localnet.net>
Date:   Thu Apr 19 15:28:42 2007 -0600

    fix memleak in slang_operation_insert()

diff --git a/src/mesa/shader/slang/slang_compile_operation.c b/src/mesa/shader/slang/slang_compile_operation.c
index 410d215..5d80bc7 100644
--- a/src/mesa/shader/slang/slang_compile_operation.c
+++ b/src/mesa/shader/slang/slang_compile_operation.c
@@ -205,6 +205,8 @@ slang_operation_insert(GLuint *numChildr
          *children = NULL;
          return NULL;
       }
+      if (*children)
+         _mesa_free(*children);
       *children = ops;
       (*numChildren)++;
       return newOp;
diff-tree 4b7c6fc5a655bfb8f165cb94521bc49521303a35 (from fe16b9f6633e468aa2244c36e540c1cfac2517e6)
Author: Brian <brian at yutani.localnet.net>
Date:   Thu Apr 19 15:23:34 2007 -0600

    free shProg->Attributes in _mesa_free_shader_program_data()

diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c
index 418ef5c..64f2a9f 100644
--- a/src/mesa/shader/shader_api.c
+++ b/src/mesa/shader/shader_api.c
@@ -119,6 +119,11 @@ _mesa_free_shader_program_data(GLcontext
 
    _mesa_clear_shader_program_data(ctx, shProg);
 
+   if (shProg->Attributes) {
+      _mesa_free_parameter_list(shProg->Attributes);
+      shProg->Attributes = NULL;
+   }
+
    /* detach shaders */
    for (i = 0; i < shProg->NumShaders; i++) {
       _mesa_reference_shader(ctx, &shProg->Shaders[i], NULL);
diff-tree fe16b9f6633e468aa2244c36e540c1cfac2517e6 (from c9855a60f4b4b478bd036db8cefc06d1c7ff521d)
Author: Brian <brian at yutani.localnet.net>
Date:   Thu Apr 19 15:22:04 2007 -0600

    move allocation of shProg->Attributes earlier in function

diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c
index 48c0d68..5a93855 100644
--- a/src/mesa/shader/slang/slang_link.c
+++ b/src/mesa/shader/slang/slang_link.c
@@ -290,6 +290,9 @@ _slang_resolve_attributes(struct gl_shad
 
    assert(prog->Target == GL_VERTEX_PROGRAM_ARB);
 
+   if (!shProg->Attributes)
+      shProg->Attributes = _mesa_new_parameter_list();
+
    /* Build a bitmask indicating which attribute indexes have been
     * explicitly bound by the user with glBindAttributeLocation().
     */
@@ -299,9 +302,6 @@ _slang_resolve_attributes(struct gl_shad
       usedAttributes |= attr;
    }
 
-   if (!shProg->Attributes)
-      shProg->Attributes = _mesa_new_parameter_list();
-
    /*
     * Scan program for generic attribute references
     */



More information about the mesa-commit mailing list