Mesa (glsl2): glsl_type: All glsl_type objects live in their own talloc context

Ian Romanick idr at kemper.freedesktop.org
Tue Jun 29 11:54:42 PDT 2010


Module: Mesa
Branch: glsl2
Commit: e1374d48ded09dba576f5a2b86c3d11984d1f7c4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=e1374d48ded09dba576f5a2b86c3d11984d1f7c4

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Mon Jun 28 12:19:52 2010 -0700

glsl_type: All glsl_type objects live in their own talloc context

---

 src/glsl/glsl_types.cpp |    5 +++--
 src/glsl/glsl_types.h   |   16 ++++++++++++++--
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index f910efd..0d807fb 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -33,6 +33,7 @@ extern "C" {
 
 hash_table *glsl_type::array_types = NULL;
 hash_table *glsl_type::record_types = NULL;
+void *glsl_type::ctx = NULL;
 
 glsl_type::glsl_type(GLenum gl_type,
 		     unsigned base_type, unsigned vector_elements,
@@ -384,7 +385,7 @@ glsl_type::get_array_instance(void *ctx, const glsl_type *base,
 
    const glsl_type *t = (glsl_type *) hash_table_find(array_types, & key);
    if (t == NULL) {
-      t = new(ctx) glsl_type(ctx, base, array_size);
+      t = new glsl_type(ctx, base, array_size);
 
       hash_table_insert(array_types, (void *) t, t);
    }
@@ -455,7 +456,7 @@ glsl_type::get_record_instance(const glsl_struct_field *fields,
 
    const glsl_type *t = (glsl_type *) hash_table_find(record_types, & key);
    if (t == NULL) {
-      t = new(NULL) glsl_type(fields, num_fields, name);
+      t = new glsl_type(fields, num_fields, name);
 
       hash_table_insert(record_types, (void *) t, t);
    }
diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h
index fc94bea..1147d38 100644
--- a/src/glsl/glsl_types.h
+++ b/src/glsl/glsl_types.h
@@ -74,11 +74,16 @@ struct glsl_type {
 
    /* Callers of this talloc-based new need not call delete. It's
     * easier to just talloc_free 'ctx' (or any of its ancestors). */
-   static void* operator new(size_t size, void *ctx)
+   static void* operator new(size_t size)
    {
+      if (glsl_type::ctx == NULL) {
+	 glsl_type::ctx = talloc_init("glsl_type");
+	 assert(glsl_type::ctx != NULL);
+      }
+
       void *type;
 
-      type = talloc_size(ctx, size);
+      type = talloc_size(glsl_type::ctx, size);
       assert(type != NULL);
 
       return type;
@@ -382,6 +387,13 @@ struct glsl_type {
    }
 
 private:
+   /**
+    * talloc context for all glsl_type allocations
+    *
+    * Set on the first call to \c glsl_type::new.
+    */
+   static TALLOC_CTX *ctx;
+
    /** Constructor for vector and matrix types */
    glsl_type(GLenum gl_type,
 	     unsigned base_type, unsigned vector_elements,



More information about the mesa-commit mailing list