Signed-off-by: Emil Velikov <emil.l.veli...@gmail.com>
---
 src/mesa/main/imports.c           | 74 +--------------------------------------
 src/mesa/main/imports.h           |  7 ----
 src/mesa/program/prog_parameter.c | 18 +++++++---
 src/mesa/tnl/t_vertex.c           |  5 ++-
 4 files changed, 18 insertions(+), 86 deletions(-)

diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
index a7ffe22..5961587 100644
--- a/src/mesa/main/imports.c
+++ b/src/mesa/main/imports.c
@@ -115,57 +115,7 @@ _mesa_align_malloc(size_t bytes, unsigned long alignment)
 }
 
 /**
- * Same as _mesa_align_malloc(), but using calloc(1, ) instead of
- * malloc()
- */
-void *
-_mesa_align_calloc(size_t bytes, unsigned long alignment)
-{
-#if defined(HAVE_POSIX_MEMALIGN)
-   void *mem;
-   
-   mem = _mesa_align_malloc(bytes, alignment);
-   if (mem != NULL) {
-      (void) memset(mem, 0, bytes);
-   }
-
-   return mem;
-#elif defined(_WIN32) && defined(_MSC_VER)
-   void *mem;
-
-   mem = _aligned_malloc(bytes, alignment);
-   if (mem != NULL) {
-      (void) memset(mem, 0, bytes);
-   }
-
-   return mem;
-#else
-   uintptr_t ptr, buf;
-
-   assert( alignment > 0 );
-
-   ptr = (uintptr_t)calloc(1, bytes + alignment + sizeof(void *));
-   if (!ptr)
-      return NULL;
-
-   buf = (ptr + alignment + sizeof(void *)) & ~(uintptr_t)(alignment - 1);
-   *(uintptr_t *)(buf - sizeof(void *)) = ptr;
-
-#ifdef DEBUG
-   /* mark the non-aligned area */
-   while ( ptr < buf - sizeof(void *) ) {
-      *(unsigned long *)ptr = 0xcdcdcdcd;
-      ptr += sizeof(unsigned long);
-   }
-#endif
-
-   return (void *)buf;
-#endif /* defined(HAVE_POSIX_MEMALIGN) */
-}
-
-/**
- * Free memory which was allocated with either _mesa_align_malloc()
- * or _mesa_align_calloc().
+ * Free memory which was allocated with either _mesa_align_malloc().
  * \param ptr pointer to the memory to be freed.
  * The actual address to free is stored in the word immediately before the
  * address the client sees.
@@ -188,28 +138,6 @@ _mesa_align_free(void *ptr)
 #endif /* defined(HAVE_POSIX_MEMALIGN) */
 }
 
-/**
- * Reallocate memory, with alignment.
- */
-void *
-_mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize,
-                    unsigned long alignment)
-{
-#if defined(_WIN32) && defined(_MSC_VER)
-   (void) oldSize;
-   return _aligned_realloc(oldBuffer, newSize, alignment);
-#else
-   const size_t copySize = (oldSize < newSize) ? oldSize : newSize;
-   void *newBuf = _mesa_align_malloc(newSize, alignment);
-   if (newBuf && oldBuffer && copySize > 0) {
-      memcpy(newBuf, oldBuffer, copySize);
-   }
-
-   _mesa_align_free(oldBuffer);
-   return newBuf;
-#endif
-}
-
 /*@}*/
 
 
diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h
index 7921000..a3767fd 100644
--- a/src/mesa/main/imports.h
+++ b/src/mesa/main/imports.h
@@ -363,17 +363,10 @@ _mesa_little_endian(void)
 extern void *
 _mesa_align_malloc( size_t bytes, unsigned long alignment );
 
-extern void *
-_mesa_align_calloc( size_t bytes, unsigned long alignment );
-
 extern void
 _mesa_align_free( void *ptr );
 
 extern void *
-_mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize,
-                    unsigned long alignment);
-
-extern void *
 _mesa_exec_malloc( GLuint size );
 
 extern void 
diff --git a/src/mesa/program/prog_parameter.c 
b/src/mesa/program/prog_parameter.c
index 5939f6f..edb5389 100644
--- a/src/mesa/program/prog_parameter.c
+++ b/src/mesa/program/prog_parameter.c
@@ -116,19 +116,27 @@ _mesa_add_parameter(struct gl_program_parameter_list 
*paramList,
    assert(size > 0);
 
    if (oldNum + sz4 > paramList->Size) {
+      size_t newSize, copySize;
+      void *newBuf;
+
       /* Need to grow the parameter list array (alloc some extra) */
       paramList->Size = paramList->Size + 4 * sz4;
 
+      newSize = paramList->Size * 4 * sizeof(gl_constant_value);
+      copySize = MIN2(oldNum * 4 * sizeof(gl_constant_value), newSize);
+
       /* realloc arrays */
       paramList->Parameters =
          realloc(paramList->Parameters,
                  paramList->Size * sizeof(struct gl_program_parameter));
 
-      paramList->ParameterValues = (gl_constant_value (*)[4])
-         _mesa_align_realloc(paramList->ParameterValues,         /* old buf */
-                             oldNum * 4 * sizeof(gl_constant_value),/* old sz 
*/
-                             
paramList->Size*4*sizeof(gl_constant_value),/*new*/
-                             16);
+      newBuf = _mesa_align_malloc(newSize, 16);
+      if (newBuf && paramList->ParameterValues && copySize > 0) {
+         memcpy(newBuf, paramList->ParameterValues, copySize);
+      }
+
+      _mesa_align_free(paramList->ParameterValues);
+      paramList->ParameterValues = (gl_constant_value (*)[4]) newBuf;
    }
 
    if (!paramList->Parameters ||
diff --git a/src/mesa/tnl/t_vertex.c b/src/mesa/tnl/t_vertex.c
index 369d6d9..607977c 100644
--- a/src/mesa/tnl/t_vertex.c
+++ b/src/mesa/tnl/t_vertex.c
@@ -26,6 +26,7 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 #include "main/glheader.h"
 #include "main/context.h"
 #include "main/colormac.h"
@@ -509,9 +510,11 @@ void _tnl_init_vertices( struct gl_context *ctx,
 
    vtx->need_extras = GL_TRUE;
    if (max_vertex_size > vtx->max_vertex_size) {
+      const size_t total_vb_size = vb_size * max_vertex_size;
       _tnl_free_vertices( ctx );
       vtx->max_vertex_size = max_vertex_size;
-      vtx->vertex_buf = _mesa_align_calloc(vb_size * max_vertex_size, 32 );
+      vtx->vertex_buf =
+         memset(_mesa_align_malloc(total_vb_size, 32), 0, total_vb_size);
       invalidate_funcs(vtx);
    }
 
-- 
2.1.3

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to