r300: move some more function to generic
[mesa.git] / src / mesa / shader / slang / slang_label.c
index 4d35d2e72a1e0821ba8551e2780703a977ebb45a..1ca1ef0c7c0490a723f053707c46ae27ef204afc 100644 (file)
@@ -8,14 +8,37 @@
 
 
 #include "slang_label.h"
+#include "slang_mem.h"
+
 
 
 slang_label *
 _slang_label_new(const char *name)
 {
-   slang_label *l = (slang_label *) _mesa_calloc(sizeof(slang_label));
+   slang_label *l = (slang_label *) _slang_alloc(sizeof(slang_label));
    if (l) {
-      l->Name = _mesa_strdup(name);
+      l->Name = _slang_strdup(name);
+      l->Location = -1;
+   }
+   return l;
+}
+
+/**
+ * As above, but suffix the name with a unique number.
+ */
+slang_label *
+_slang_label_new_unique(const char *name)
+{
+   static int id = 1;
+   slang_label *l = (slang_label *) _slang_alloc(sizeof(slang_label));
+   if (l) {
+      l->Name = (char *) _slang_alloc(_mesa_strlen(name) + 10);
+      if (!l->Name) {
+         _mesa_free(l);
+         return NULL;
+      }
+      _mesa_sprintf(l->Name, "%s_%d", name, id);
+      id++;
       l->Location = -1;
    }
    return l;
@@ -24,11 +47,15 @@ _slang_label_new(const char *name)
 void
 _slang_label_delete(slang_label *l)
 {
-   if (l->Name)
-      _mesa_free(l->Name);
-   if (l->References)
-      _mesa_free(l->References);
-   _mesa_free(l);
+   if (l->Name) {
+      _slang_free(l->Name);
+      l->Name = NULL;
+   }
+   if (l->References) {
+      _slang_free(l->References);
+      l->References = NULL;
+   }
+   _slang_free(l);
 }
 
 
@@ -37,8 +64,8 @@ _slang_label_add_reference(slang_label *l, GLuint inst)
 {
    const GLuint oldSize = l->NumReferences * sizeof(GLuint);
    assert(l->Location < 0);
-   l->References = _mesa_realloc(l->References,
-                                 oldSize, oldSize + sizeof(GLuint));
+   l->References = _slang_realloc(l->References,
+                                  oldSize, oldSize + sizeof(GLuint));
    if (l->References) {
       l->References[l->NumReferences] = inst;
       l->NumReferences++;
@@ -71,7 +98,7 @@ _slang_label_set_location(slang_label *l, GLint location,
    }
 
    if (l->References) {
-      _mesa_free(l->References);
+      _slang_free(l->References);
       l->References = NULL;
    }
 }