]> git.llucax.com Git - software/druntime.git/commitdiff
Added _d_delarray_t and _d_allocmemory.
authorsean <sean@4a9d5153-6564-4b3f-b5e1-7e8e9dac548f>
Fri, 10 Oct 2008 21:49:12 +0000 (21:49 +0000)
committersean <sean@4a9d5153-6564-4b3f-b5e1-7e8e9dac548f>
Fri, 10 Oct 2008 21:49:12 +0000 (21:49 +0000)
git-svn-id: http://svn.dsource.org/projects/druntime/trunk@19 4a9d5153-6564-4b3f-b5e1-7e8e9dac548f

src/compiler/dmd/lifetime.d

index 55861b06a2c23253e10ff9b59bf5574b1c72983e..e5ef60f6b903f380046f30a638501f4bb286796f 100644 (file)
@@ -81,6 +81,15 @@ private
 }
 
 
+/**
+ *
+ */
+extern (C) void* _d_allocmemory(size_t sz)
+{
+    return gc_malloc(sz);
+}
+
+
 /**
  *
  */
@@ -397,25 +406,46 @@ struct Array
 
 
 /**
- *
+ * This function has been replaced by _d_delarray_t
  */
-void* _d_allocmemory(size_t nbytes)
+extern (C) void _d_delarray(Array *p)
 {
-    return gc_malloc(nbytes);
+    if (p)
+    {
+        assert(!p.length || p.data);
+
+        if (p.data)
+            gc_free(p.data);
+        p.data = null;
+        p.length = 0;
+    }
 }
 
 
 /**
  *
  */
-extern (C) void _d_delarray(Array *p)
+extern (C) void _d_delarray_t(Array *p, TypeInfo ti)
 {
     if (p)
     {
         assert(!p.length || p.data);
-
         if (p.data)
+        {
+            if (ti)
+            {
+                // Call destructors on all the sub-objects
+                auto sz = ti.tsize();
+                auto pe = p.data;
+                auto pend = pe + p.length * sz;
+                while (pe != pend)
+                {
+                    pend -= sz;
+                    ti.destroy(pend);
+                }
+            }
             gc_free(p.data);
+        }
         p.data = null;
         p.length = 0;
     }