Merge pull request #2894 from marek-safar/mono.security
[mono.git] / mono / metadata / mono-mlist.c
index 0b8389e731a8534400145e394d376956320b93b7..657800afbe35e70255efb0f3588a9a41f7ef0225 100644 (file)
@@ -4,14 +4,16 @@
  * Author:
  *   Paolo Molaro (lupus@ximian.com)
  *
- * (C) 2006 Novell, Inc.
+ * Copyright 2006-2009 Novell, Inc (http://www.novell.com)
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
  */
 
 #include "mono/metadata/mono-mlist.h"
 #include "mono/metadata/appdomain.h"
 #include "mono/metadata/class-internals.h"
+#include "mono/metadata/object-internals.h"
 
-/* matches the System.MonoListItem objcet*/
+/* matches the System.MonoListItem object*/
 struct _MonoMList {
        MonoObject object;
        MonoMList *next;
@@ -37,12 +39,15 @@ static MonoVTable *monolist_item_vtable = NULL;
 MonoMList*
 mono_mlist_alloc (MonoObject *data)
 {
+       MonoError error;
        MonoMList* res;
        if (!monolist_item_vtable) {
-               MonoClass *klass = mono_class_from_name (mono_defaults.corlib, "System", "MonoListItem");
+               MonoClass *klass = mono_class_load_from_name (mono_defaults.corlib, "System", "MonoListItem");
                monolist_item_vtable = mono_class_vtable (mono_get_root_domain (), klass);
+               g_assert (monolist_item_vtable);
        }
-       res = (MonoMList*)mono_object_new_fast (monolist_item_vtable);
+       res = (MonoMList*)mono_object_new_fast_checked (monolist_item_vtable, &error);
+       mono_error_raise_exception (&error);
        MONO_OBJECT_SETREF (res, data, data);
        return res;
 }
@@ -71,6 +76,23 @@ mono_mlist_set_data (MonoMList* list, MonoObject *data)
        MONO_OBJECT_SETREF (list, data, data);
 }
 
+/**
+ * mono_mlist_set_next:
+ * @list: a managed list node
+ * @next: list node that will be next for the @list node.
+ *
+ * Set next node for @list to @next.
+ */
+MonoMList *
+mono_mlist_set_next (MonoMList* list, MonoMList *next)
+{
+       if (!list)
+               return next;
+
+       MONO_OBJECT_SETREF (list, next, next);
+       return list;
+}
+
 /**
  * mono_mlist_length:
  * @list: the managed list
@@ -174,7 +196,7 @@ find_prev (MonoMList* list, MonoMList *item)
 /**
  * mono_mlist_remove_item:
  * @list: the managed list
- * @data: the object to add to the list
+ * @data: the object to remove from the list
  *
  * Remove the list node @item from the managed list @list.
  * Since managed lists are singly-linked, this operation can take O(n) time.