2004-07-05 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / metadata / object.c
index a3f4edcbc55dc8b96dbe0b3fef12542acfca2175..bdf832baa6dcb0a122d98130410123ff6c39076e 100644 (file)
@@ -357,7 +357,7 @@ mono_class_compute_gc_descriptor (MonoClass *class)
 
                /* GC 6.1 has trouble handling 64 bit descriptors... */
                if ((class->instance_size / sizeof (gpointer)) > 30) {
-//                     printf ("TOO LARGE: %s %d.\n", class->name, class->instance_size / sizeof (gpointer));
+/*                     printf ("TOO LARGE: %s %d.\n", class->name, class->instance_size / sizeof (gpointer)); */
                        return;
                }
 
@@ -365,10 +365,10 @@ mono_class_compute_gc_descriptor (MonoClass *class)
 
                count ++;
 
-//             if (count > 442)
-//                     return;
+/*             if (count > 442) */
+/*                     return;  */
 
-//             printf("KLASS: %s.\n", class->name);
+/*             printf("KLASS: %s.\n", class->name); */
 
                for (p = class; p != NULL; p = p->parent) {
                for (i = 0; i < p->field.count; ++i) {
@@ -396,7 +396,7 @@ mono_class_compute_gc_descriptor (MonoClass *class)
                        case MONO_TYPE_U8:
                        case MONO_TYPE_R4:
                        case MONO_TYPE_R8:
-//                             printf ("F: %s %s %d %lld %llx.\n", class->name, field->name, field->offset, ((guint64)1) << pos, bitmap);
+/*                             printf ("F: %s %s %d %lld %llx.\n", class->name, field->name, field->offset, ((guint64)1) << pos, bitmap); */
                                break;
                        case MONO_TYPE_I:
                        case MONO_TYPE_STRING:
@@ -408,7 +408,7 @@ mono_class_compute_gc_descriptor (MonoClass *class)
                                g_assert ((field->offset % sizeof(gpointer)) == 0);
 
                                bitmap |= ((guint64)1) << pos;
-//                             printf ("F: %s %s %d %d %lld %llx.\n", class->name, field->name, field->offset, pos, ((guint64)(1)) << pos, bitmap);
+/*                             printf ("F: %s %s %d %d %lld %llx.\n", class->name, field->name, field->offset, pos, ((guint64)(1)) << pos, bitmap); */
                                break;
                        case MONO_TYPE_VALUETYPE: {
                                MonoClass *fclass = field->type->data.klass;
@@ -424,7 +424,7 @@ mono_class_compute_gc_descriptor (MonoClass *class)
                }
                }
 
-//             printf("CLASS: %s.%s -> %d %llx.\n", class->name_space, class->name, class->instance_size / sizeof (gpointer), bitmap);
+/*             printf("CLASS: %s.%s -> %d %llx.\n", class->name_space, class->name, class->instance_size / sizeof (gpointer), bitmap); */
                class->gc_bitmap = bitmap;
                /* Convert to the format expected by GC_make_descriptor */
                bm [0] = (guint32)bitmap;
@@ -908,8 +908,10 @@ void mono_upgrade_remote_class (MonoDomain *domain, MonoRemoteClass *remote_clas
        mono_domain_unlock (domain);
 }
 
-/*
- * Retrieve the MonoMethod that would to be called on obj if obj is passed as
+/**
+ * mono_object_get_virtual_method:
+ *
+ * Retrieve the MonoMethod that would be called on obj if obj is passed as
  * the instance of a callvirt of method.
  */
 MonoMethod*
@@ -960,6 +962,36 @@ dummy_mono_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObj
 
 static MonoInvokeFunc default_mono_runtime_invoke = dummy_mono_runtime_invoke;
 
+/**
+ * mono_runtime_invoke:
+ *
+ * Invokes the method represented by `method' on the object `obj'.
+ *
+ * obj is the 'this' pointer, it should be NULL for static
+ * methods, a MonoObject* for object instances and a pointer to
+ * the value type for value types.
+ *
+ * The params array contains the arguments to the method with the
+ * same convention: MonoObject* pointers for object instances and
+ * pointers to the value type otherwise. 
+ * 
+ * From unmanaged code you'll usually use the
+ * mono_runtime_invoke() variant.
+ *
+ * Note that this function doesn't handle virtual methods for
+ * you, it will exec the exact method you pass: we still need to
+ * expose a function to lookup the derived class implementation
+ * of a virtual method (there are examples of this in the code,
+ * though).
+ * 
+ * You can pass NULL as the exc argument if you don't want to
+ * catch exceptions, otherwise, *exc will be set to the exception
+ * thrown, if any.  if an exception is thrown, you can't use the
+ * MonoObject* result from the function.
+ * 
+ * If the method returns a value type, it is boxed in an object
+ * reference.
+ */
 MonoObject*
 mono_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc)
 {
@@ -1490,6 +1522,39 @@ mono_install_runtime_invoke (MonoInvokeFunc func)
        default_mono_runtime_invoke = func ? func: dummy_mono_runtime_invoke;
 }
 
+/**
+ * mono_runtime_invoke:
+ *
+ * Invokes the method represented by `method' on the object `obj'.
+ *
+ * obj is the 'this' pointer, it should be NULL for static
+ * methods, a MonoObject* for object instances and a pointer to
+ * the value type for value types.
+ *
+ * The params array contains the arguments to the method with the
+ * same convention: MonoObject* pointers for object instances and
+ * pointers to the value type otherwise. The _invoke_array
+ * variant takes a C# object[] as the params argument (MonoArray
+ * *params): in this case the value types are boxed inside the
+ * respective reference representation.
+ * 
+ * From unmanaged code you'll usually use the
+ * mono_runtime_invoke() variant.
+ *
+ * Note that this function doesn't handle virtual methods for
+ * you, it will exec the exact method you pass: we still need to
+ * expose a function to lookup the derived class implementation
+ * of a virtual method (there are examples of this in the code,
+ * though).
+ * 
+ * You can pass NULL as the exc argument if you don't want to
+ * catch exceptions, otherwise, *exc will be set to the exception
+ * thrown, if any.  if an exception is thrown, you can't use the
+ * MonoObject* result from the function.
+ * 
+ * If the method returns a value type, it is boxed in an object
+ * reference.
+ */
 MonoObject*
 mono_runtime_invoke_array (MonoMethod *method, void *obj, MonoArray *params,
                           MonoObject **exc)
@@ -1620,8 +1685,10 @@ mono_object_allocate_spec (size_t size, void *gcdescr)
  * mono_object_new:
  * @klass: the class of the object that we want to create
  *
- * Returns: A newly created object whose definition is
- * looked up using @klass
+ * Returns a newly created object whose definition is
+ * looked up using @klass.   This will not invoke any constructors, 
+ * so the consumer of this routine has to invoke any constructors on
+ * its own to initialize the object.
  */
 MonoObject *
 mono_object_new (MonoDomain *domain, MonoClass *klass)
@@ -1686,7 +1753,7 @@ mono_object_new_fast (MonoVTable *vtable)
        if (vtable->gc_descr != GC_NO_DESCRIPTOR) {
                o = mono_object_allocate_spec (vtable->klass->instance_size, vtable);
        } else {
-//             printf("OBJECT: %s.%s.\n", vtable->klass->name_space, vtable->klass->name);
+/*             printf("OBJECT: %s.%s.\n", vtable->klass->name_space, vtable->klass->name); */
                o = mono_object_allocate (vtable->klass->instance_size);
                o->vtable = vtable;
        }
@@ -1706,7 +1773,7 @@ mono_object_new_alloc_specific (MonoVTable *vtable)
        if (vtable->gc_descr != GC_NO_DESCRIPTOR) {
                o = mono_object_allocate_spec (vtable->klass->instance_size, vtable);
        } else {
-//             printf("OBJECT: %s.%s.\n", vtable->klass->name_space, vtable->klass->name);
+/*             printf("OBJECT: %s.%s.\n", vtable->klass->name_space, vtable->klass->name); */
                o = mono_object_allocate (vtable->klass->instance_size);
                o->vtable = vtable;
        }
@@ -1943,7 +2010,7 @@ mono_array_new_specific (MonoVTable *vtable, guint32 n)
        if (vtable->gc_descr != GC_NO_DESCRIPTOR) {
                o = mono_object_allocate_spec (byte_len, vtable);
        } else {
-//             printf("ARRAY: %s.%s.\n", vtable->klass->name_space, vtable->klass->name);
+/*             printf("ARRAY: %s.%s.\n", vtable->klass->name_space, vtable->klass->name); */
                o = mono_object_allocate (byte_len);
                o->vtable = vtable;
        }