2001-08-20 Dietmar Maurer <dietmar@ximian.com>
authorDietmar Maurer <dietmar@mono-cvs.ximian.com>
Mon, 20 Aug 2001 08:52:40 +0000 (08:52 -0000)
committerDietmar Maurer <dietmar@mono-cvs.ximian.com>
Mon, 20 Aug 2001 08:52:40 +0000 (08:52 -0000)
        * mono/tests/stream.cs: new tests for the Stream class

        * configure.in: I really need LIBTOOL for libmonowrapper.so, so I
        added it again.

        * class.h: replaced 'struct MonoMethod' with 'MonoMethod'

        * cli.h: removed #include <mono/cli/object.h>

        * icall.c: changed everything to support the new calling convention

        * hacks.h: added some macros for FreeBSD

        * interp.c (get_named_exception): use mono_object_new instead of
        newobj, initialize the stack before we call the constructor.

        * metadata.c (mono_metadata_signature_equal): impl.

        * *: void is now a realy MonoType (instead of using NULL)

        * metadata.c (do_mono_metadata_parse_type): use
        mono_metadata_parse_type to parse void value.

svn path=/trunk/mono/; revision=502

32 files changed:
ChangeLog
configure.in
mono/Makefile.am
mono/cli/ChangeLog
mono/cli/class.h
mono/cli/cli.h
mono/cli/loader.c
mono/cli/object.c
mono/cli/object.h
mono/dis/ChangeLog
mono/dis/get.c
mono/dis/main.c
mono/interpreter/ChangeLog
mono/interpreter/hacks.h
mono/interpreter/icall.c
mono/interpreter/interp.c
mono/interpreter/interp.h
mono/metadata/ChangeLog
mono/metadata/assembly.c
mono/metadata/class.h
mono/metadata/icall.c
mono/metadata/loader.c
mono/metadata/metadata.c
mono/metadata/metadata.h
mono/metadata/object.c
mono/metadata/object.h
mono/tests/Makefile.am
mono/tests/stream.cs [new file with mode: 0755]
mono/wrapper/.cvsignore [new file with mode: 0644]
mono/wrapper/Makefile.am [new file with mode: 0644]
mono/wrapper/genwrapper.pl [new file with mode: 0755]
mono/wrapper/wrapper.c [new file with mode: 0644]

index eb063560d0320584ec4825e333b9db9e2cbf5504..c8b41e606782876e09cdc6e29a7d2956174a2a07 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2001-08-20  Dietmar Maurer  <dietmar@ximian.com>
+
+       * mono/tests/stream.cs: new tests for the Stream class
+
+       * configure.in: I really need LIBTOOL for libmonowrapper.so, so I
+       added it again.
+
 2001-08-16  Alex Graveley  <alex@ximian.com>
 
        * configure.in: Replace AM_PROG_LIBTOOL with AC_PROG_RANLIB. This
index 9551dca8cc950f9570e16fdee3c7fb5d7fc45db8..16f7684f9552f73f5ec4a4c8594e983e349ed3a6 100644 (file)
@@ -9,7 +9,7 @@ AC_PROG_INSTALL
 
 # Set STDC_HEADERS
 AC_HEADER_STDC
-AC_PROG_RANLIB
+AM_PROG_LIBTOOL
 
 dnl ***************************
 dnl *** Checks for glib 1.2 ***
@@ -43,5 +43,6 @@ mono/cil/Makefile
 mono/cli/Makefile
 mono/interpreter/Makefile
 mono/tests/Makefile
+mono/wrapper/Makefile
 doc/Makefile
 ])
index b2e017f08e2fd854f4e343b478c0b7bc968d8d08..4728b5fa6793a16bbd22a369b66521950b8737dc 100644 (file)
@@ -1 +1 @@
-SUBDIRS = metadata cil cli dis interpreter tests
+SUBDIRS = metadata cil cli dis interpreter wrapper tests
index dc0795f339df60a84db9932b3c51da783b9e97e3..1a294369033cd4842057b8a32f5585f0df65d56f 100644 (file)
@@ -1,3 +1,9 @@
+2001-08-20  Dietmar Maurer  <dietmar@ximian.com>
+
+       * class.h: replaced 'struct MonoMethod' with 'MonoMethod'
+
+       * cli.h: removed #include <mono/cli/object.h> 
+
 Sat Aug 18 12:42:26 CEST 2001 Paolo Molaro <lupus@ximian.com>
 
        * class.c, class.h: load also the methods when loading a class.
index 8928f7e3c196565620bb1aa7fb38111f21d5fee0..9cf8e2a35a11a3a6502425ac0c426b22eb9017a8 100644 (file)
@@ -44,11 +44,11 @@ struct _MonoClass {
         * Field information: Type and location from object base
         */
        MonoClassField *fields;
-       
-       struct MonoMethod **methods;
+
+       MonoMethod **methods;
 
        /*
-        * After the fields, there is room for the static fields...
+        * After the methods, there is room for the static fields...
         */
 };
 
index 95bf87896cfa8de8368f04e0dda0318dcb7bd9ce..4b7f1d7c9f80410baf990de6e3b58cb60537553b 100644 (file)
@@ -4,13 +4,12 @@
 #include <ffi.h>
 #include <mono/metadata/metadata.h>
 #include <mono/metadata/image.h>
-#include <mono/cli/object.h>
 
 typedef struct {
        guint16 flags;  /* method flags */
        guint16 iflags; /* method implementation flags */
        MonoImage *image;
-       MonoMethodSignature  *signature;
+       MonoMethodSignature *signature;
        gpointer addr;
        /* name is useful mostly for debugging */
        const char *name; 
index 5d4a5813674e86648937d34d63e72315065a3638..efa871cf15eb362466b0f5811203f705060f9052 100644 (file)
@@ -205,20 +205,26 @@ mono_get_string_class_info (guint *ttoken, MonoImage **cl)
 static MonoMethod *
 method_from_memberref (MonoImage *image, guint32 index)
 {
+       MonoImage *mimage;
        MonoMetadata *m = &image->metadata;
        MonoTableInfo *tables = m->tables;
        guint32 cols[6];
-       guint32 nindex, sig_len, msig_len, class, i;
-       const char *sig, *msig, *mname, *name, *nspace;
+       guint32 nindex, class, i;
+       const char *mname, *name, *nspace;
+       MonoMethodSignature *sig, *msig;
+       const char *ptr;
 
        mono_metadata_decode_row (&tables [MONO_TABLE_MEMBERREF], index-1, cols, 3);
        nindex = cols [MONO_MEMBERREF_CLASS] >> MEMBERREF_PARENT_BITS;
        class = cols [MONO_MEMBERREF_CLASS] & MEMBERREF_PARENT_MASK;
        /*g_print ("methodref: 0x%x 0x%x %s\n", class, nindex,
                mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]));*/
-       sig = mono_metadata_blob_heap (m, cols [MONO_MEMBERREF_SIGNATURE]);
-       sig_len = mono_metadata_decode_blob_size (sig, &sig);
+
        mname = mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]);
+       
+       ptr = mono_metadata_blob_heap (m, cols [MONO_MEMBERREF_SIGNATURE]);
+       mono_metadata_decode_blob_size (ptr, &ptr);
+       sig = mono_metadata_parse_method_signature (m, 0, ptr, NULL);
 
        switch (class) {
        case MEMBERREF_PARENT_TYPEREF: {
@@ -243,23 +249,31 @@ method_from_memberref (MonoImage *image, guint32 index)
                        /* this will triggered by references to mscorlib */
                        g_assert (image->references [scopeindex-1] != NULL);
 
-                       image = image->references [scopeindex-1]->image;
+                       mimage = image->references [scopeindex-1]->image;
 
-                       m = &image->metadata;
+                       m = &mimage->metadata;
                        tables = &m->tables [MONO_TABLE_METHOD];
-                       mono_typedef_from_name (image, name, nspace, &i);
+                       mono_typedef_from_name (mimage, name, nspace, &i);
                        /* mostly dumb search for now */
-                       for (;i < tables->rows; ++i) {
+                       for (i--; i < tables->rows; ++i) {
+
                                mono_metadata_decode_row (tables, i, cols, MONO_METHOD_SIZE);
-                               msig = mono_metadata_blob_heap (m, cols [MONO_METHOD_SIGNATURE]);
-                               msig_len = mono_metadata_decode_blob_size (msig, &msig);
-                               
-                               if (strcmp (mname, mono_metadata_string_heap (m, cols [MONO_METHOD_NAME])) == 0 
-                                               && sig_len == msig_len
-                                               && strncmp (sig, msig, sig_len) == 0) {
-                                       return mono_get_method (image, MONO_TOKEN_METHOD_DEF | (i + 1));
+
+                               if (!strcmp (mname, mono_metadata_string_heap (m, cols [MONO_METHOD_NAME]))) {
+                                       
+                                       ptr = mono_metadata_blob_heap (m, cols [MONO_METHOD_SIGNATURE]);
+                                       mono_metadata_decode_blob_size (ptr, &ptr);
+                                       msig = mono_metadata_parse_method_signature (m, 1, ptr, NULL);
+
+                                       if (mono_metadata_signature_equal (&image->metadata, sig, 
+                                                                          &mimage->metadata, msig)) {
+                                               mono_metadata_free_method_signature (sig);
+                                               mono_metadata_free_method_signature (msig);
+                                               return mono_get_method (mimage, MONO_TOKEN_METHOD_DEF | (i + 1));
+                                       }
                                }
                        }
+                       g_warning ("cant find method %s.%s::%s",nspace, name, mname);
                        g_assert_not_reached ();
                        break;
                default:
@@ -268,9 +282,7 @@ method_from_memberref (MonoImage *image, guint32 index)
                break;
        }
        case MEMBERREF_PARENT_TYPESPEC: {
-               MonoMethodSignature *ms;
                guint32 bcols [MONO_TYPESPEC_SIZE];
-               const char *ptr;
                guint32 len;
                MonoType *type;
                MonoMethod *result;
@@ -284,19 +296,17 @@ method_from_memberref (MonoImage *image, guint32 index)
                if (type->type != MONO_TYPE_ARRAY)
                        g_assert_not_reached ();                
 
-               ms = mono_metadata_parse_method_signature (m, 0, sig, &sig);
-
                result = (MonoMethod *)g_new0 (MonoMethod, 1);
                result->image = image;
                result->iflags = METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL;
-               result->signature = ms;
+               result->signature = sig;
                
                if (!strcmp (mname, ".ctor")) { 
-                       g_assert (ms->hasthis);
-                       if (type->data.array->rank == ms->param_count) {
+                       g_assert (sig->hasthis);
+                       if (type->data.array->rank == sig->param_count) {
                                result->addr = mono_lookup_internal_call ("__array_ctor");
                                return result;
-                       } else if ((type->data.array->rank * 2) == ms->param_count) {
+                       } else if ((type->data.array->rank * 2) == sig->param_count) {
                                result->addr = mono_lookup_internal_call ("__array_bound_ctor");
                                return result;                  
                        } else 
@@ -304,16 +314,16 @@ method_from_memberref (MonoImage *image, guint32 index)
                }
 
                if (!strcmp (mname, "Set")) {
-                       g_assert (ms->hasthis);
-                       g_assert (type->data.array->rank + 1 == ms->param_count);
+                       g_assert (sig->hasthis);
+                       g_assert (type->data.array->rank + 1 == sig->param_count);
 
                        result->addr = mono_lookup_internal_call ("__array_Set");
                        return result;
                }
 
                if (!strcmp (mname, "Get")) {
-                       g_assert (ms->hasthis);
-                       g_assert (type->data.array->rank == ms->param_count);
+                       g_assert (sig->hasthis);
+                       g_assert (type->data.array->rank == sig->param_count);
 
                        result->addr = mono_lookup_internal_call ("__array_Get");
                        return result;
@@ -334,9 +344,6 @@ ves_map_ffi_type (MonoType *type)
 {
        ffi_type *rettype;
 
-       if (!type)
-               return &ffi_type_void;
-
        switch (type->type) {
        case MONO_TYPE_I1:
                rettype = &ffi_type_sint8;
@@ -367,6 +374,9 @@ ves_map_ffi_type (MonoType *type)
        case MONO_TYPE_STRING:
                rettype = &ffi_type_pointer;
                break;
+       case MONO_TYPE_VOID:
+               rettype = &ffi_type_void;
+               break;
        default:
                g_warning ("not implemented");
                g_assert_not_reached ();
@@ -451,7 +461,7 @@ mono_get_method (MonoImage *image, guint32 token)
        const char *loc, *sig = NULL;
        char *name;
        int size;
-       guint32 cols[6];
+       guint32 cols[MONO_TYPEDEF_SIZE];
 
        if (table == MONO_TABLE_METHOD && (result = g_hash_table_lookup (image->method_cache, GINT_TO_POINTER (token))))
                        return result;
@@ -506,9 +516,7 @@ mono_get_method (MonoImage *image, guint32 token)
        if (!sig) /* already taken from the methodref */
                sig = mono_metadata_blob_heap (m, cols [4]);
        size = mono_metadata_decode_blob_size (sig, &sig);
-       result->signature = mono_metadata_parse_method_signature (m, 0, sig, 
-                                                                 NULL);
-
+       result->signature = mono_metadata_parse_method_signature (m, 0, sig, NULL);
 
        if (result->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
                fill_pinvoke_info (image, (MonoMethodPInvoke *)result, 
index 2f32a9ec85d86684d0dd91c1a2e1e7057feb2985..997e08eac2856709167101427f62827d048e2c4a 100644 (file)
@@ -135,4 +135,3 @@ mono_value_box (MonoImage *image, guint32 etype, gpointer val)
 
        return res;
 }
-
index cea71aa9205328ef9c5cd79862a24a98f0f69b1c..82da795bafc612a4198011aa08196a0c1abfb2ef 100644 (file)
@@ -34,7 +34,7 @@ void
 mono_object_free      (MonoObject *o);
 
 MonoObject *
-mono_value_box        (MonoImage *image, guint32 etype, gpointer val);
+mono_value_box        (MonoImage *image, guint32 type, gpointer val);
                      
 MonoObject *
 mono_object_clone     (MonoObject *obj);
index 623e28f0d2367980a5db89a286d99bc634663055..8ec4f384cdc148c5a6cb86f12ffaf49fd382e0fd 100644 (file)
@@ -1,3 +1,7 @@
+2001-08-20  Dietmar Maurer  <dietmar@ximian.com>
+
+       * get.c (dis_stringify_type): support pinned values
+
 Sat Aug 18 11:24:07 CEST 2001 Paolo Molaro <lupus@ximian.com>
 
        * dump.c, get.c, get.h, main.c: dis_stringify_method_signature()
@@ -6,6 +10,14 @@ Sat Aug 18 11:24:07 CEST 2001 Paolo Molaro <lupus@ximian.com>
        parse_method_signature() and free_method_signature() removed as
        they are useless now.
 
+2001-08-17  Dietmar Maurer  <dietmar@ximian.com>
+
+       * main.c (pinvoke_info): bug fix - use the right column in the table
+
+2001-08-14  Dietmar Maurer  <dietmar@ximian.com>
+
+       * get.c (dis_stringify_type): use strconcat instead of strjoin
+
 Sat Aug 4 12:36:54 CEST 2001 Paolo Molaro <lupus@ximian.com>
 
        * get.c, get.h, main.c, dump.c: implement dis_stringify_method_signature().
index 702a9a244df61aa537b40105ca0bc57f4393d28a..ce5cb694a08ad332e94e31bcef36d25516ac4ec8 100644 (file)
@@ -495,15 +495,9 @@ dis_stringify_method_signature (MonoMetadata *m, MonoMethodSignature *method, in
 char*
 dis_stringify_type (MonoMetadata *m, MonoType *type)
 {
-       char *bare = NULL;
-       char *byref;
+       char *bare = NULL, *pinned = "", *byref = "";
        char *result;
 
-       if (!type)
-               return g_strdup ("void");
-
-       byref = type->byref ? "&" : "";
-
        switch (type->type){
        case MONO_TYPE_BOOLEAN:
        case MONO_TYPE_CHAR:
@@ -553,12 +547,23 @@ dis_stringify_type (MonoMetadata *m, MonoType *type)
        case MONO_TYPE_ARRAY:
                bare = dis_stringify_array (m, type->data.array);
                break;
+       case MONO_TYPE_VOID:
+               bare = g_strdup ("void");
+               break;
        default:
                g_error ("Do not know how to stringify type 0x%x", type->type);
        }
+       
+       if (type->constraint == MONO_TYPE_PINNED)
+               pinned = " pinned";
+
+       if (type->byref)
+               byref = "&";
+               
+       result = g_strconcat (bare, byref, pinned, NULL);
 
-       result = g_strconcat (bare, byref, NULL);
        g_free (bare);
+
        return result;
 }
 
@@ -964,7 +969,6 @@ get_method (MonoMetadata *m, guint32 token)
                name = mono_metadata_string_heap (m, method_cols [MONO_METHOD_NAME]);
 
                sig = get_methodref_signature (m, method_cols [MONO_METHOD_SIGNATURE], name);
-
                return sig;
                
        case MONO_TOKEN_MEMBER_REF: {
@@ -985,7 +989,7 @@ get_method (MonoMetadata *m, guint32 token)
                g_free (sig);
                return res;
        }
-               
+              
        default:
                g_assert_not_reached ();
        }
index 2d4f11fb9ea90306c90fb3b94463de1fd0abde06..09903c3a7486b25c098d3daa07643749b6c8028f 100644 (file)
@@ -288,7 +288,7 @@ pinvoke_flags (guint32 f)
        g_string_append (str, map (cconv, pinvoke_call_conv_map));
        g_string_append (str, flags (f, pinvoke_flags_map));
 
-       s = str->str;
+       s = g_strdup(str->str);
        g_string_free (str, FALSE);
 
        return s;
@@ -398,9 +398,9 @@ pinvoke_info (MonoMetadata *m, guint32 mindex)
 
                mono_metadata_decode_row (im, i, im_cols, MONO_IMPLMAP_SIZE);
 
-               flags = pinvoke_flags (im_cols [MONO_IMPLMAP_FLAGS]);
+               if ((im_cols [MONO_IMPLMAP_MEMBER] >> 1) == mindex + 1) {
 
-               if ((im_cols [MONO_IMPLMAP_FLAGS] >> 1) == mindex + 1) {
+                       flags = pinvoke_flags (im_cols [MONO_IMPLMAP_FLAGS]);
 
                        import = mono_metadata_string_heap (m, im_cols [MONO_IMPLMAP_NAME]);
 
@@ -411,9 +411,8 @@ pinvoke_info (MonoMetadata *m, guint32 mindex)
                                
                        return g_strdup_printf ("(%s as %s %s)", scope, import,
                                                flags);
+                       g_free (flags);
                }
-
-               g_free (flags);
        }
 
        return NULL;
index ca0612f6010b4578272290d98d84152aa9ce0220..7f7cdf086e90b4abf2c18ec6698e719d492dbbcd 100644 (file)
@@ -1,3 +1,11 @@
+2001-08-20  Dietmar Maurer  <dietmar@ximian.com>
+
+       * icall.c: changed everything to support the new calling convention
+
+       * hacks.h: added some macros for FreeBSD 
+
+       * interp.c (get_named_exception): use mono_object_new instead of
+       newobj, initialize the stack before we call the constructor.
 
 Sat Aug 18 12:43:38 CEST 2001 Paolo Molaro <lupus@ximian.com>
 
index dafae4ea6373faed499da0e95e289dbaa6828db0..8b62bd5a0d3d35f33bd2fbb18558a33d14e198ab 100644 (file)
@@ -1,3 +1,43 @@
+/* we need some special math function */
+#define _ISOC99_SOURCE
+#include <math.h>
+
+/* which are not defined on FreeBSD */
+#ifndef isunordered
+#   define isunordered(u, v)                              \
+    (__extension__                                        \
+     ({ __typeof__(u) __u = (u); __typeof__(v) __v = (v); \
+        isnan(__u) || isnan(__v); }))
+#endif
+
+#ifndef islessgreater
+#   define islessgreater(x, u)                                    \
+    (__extension__                                                \
+     ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);         \
+        !isunordered (__x, __y) && (__x < __y) || (__y < __x); }))
+#endif
+
+#ifndef islessequal
+#   define islessequal(x, y)                              \
+    (__extension__                                        \
+     ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
+        !isunordered(__x, __y) && __x <= __y; })) 
+#endif
+
+#ifndef isless
+#   define isless(x, y)                                   \
+    (__extension__                                        \
+     ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
+        !isunordered(__x, __y) && __x < __y; })) 
+#endif
+
+#ifndef isgreater
+#   define isgreater(x, y)                                \
+    (__extension__                                        \
+     ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
+        !isunordered(__x, __y) && __x > __y; }))
+#endif
+
 /*
  * Attempt at using the goto label construct of GNU GCC:
  * it turns out this does give some benefit: 5-15% speedup.
index 70298c78e03ea12d1110d776447d5f3543d8f56c..95ba2d185d3bd9a418831659aca80803472e1359 100644 (file)
 #include "interp.h"
 
 static void 
-ves_icall_array_Set (MonoMethod *mh, stackval *sp)
+ves_icall_array_Set (MonoInvocation *frame)
 {
+       stackval *sp = frame->stack_args;
        MonoObject *o;
        MonoArrayObject *ao;
        MonoArrayClass *ac;
        gint32 i, t, pos;
        gpointer ea;
 
-       g_assert (sp [0].type == VAL_OBJ);
-
-       o = sp [0].data.p;
+       o = frame->obj;
        ao = (MonoArrayObject *)o;
        ac = (MonoArrayClass *)o->klass;
 
        g_assert (ac->rank >= 1);
 
-       pos = sp [1].data.i - ao->bounds [0].lower_bound;
+       pos = sp [0].data.i - ao->bounds [0].lower_bound;
        for (i = 1; i < ac->rank; i++) {
-               if ((t = sp [i + 1].data.i - ao->bounds [i].lower_bound) >= 
+               if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >= 
                    ao->bounds [i].length) {
                        g_warning ("wrong array index");
                        g_assert_not_reached ();
                }
-               pos = pos*ao->bounds [i].length + sp [i + 1].data.i - 
+               pos = pos*ao->bounds [i].length + sp [i].data.i - 
                        ao->bounds [i].lower_bound;
        }
 
        ea = ao->vector + (pos * ac->esize);
-       memcpy (ea, &sp [ac->rank + 1].data.p, ac->esize);
+       memcpy (ea, &sp [ac->rank].data.p, ac->esize);
 }
 
 static void 
-ves_icall_array_Get (MonoMethod *mh, stackval *sp)
+ves_icall_array_Get (MonoInvocation *frame)
 {
+       stackval *sp = frame->stack_args;
        MonoObject *o;
        MonoArrayObject *ao;
        MonoArrayClass *ac;
        gint32 i, pos;
        gpointer ea;
 
-       g_assert (sp [0].type == VAL_OBJ);
-
-       o = sp [0].data.p;
+       o = frame->obj;
        ao = (MonoArrayObject *)o;
        ac = (MonoArrayClass *)o->klass;
 
        g_assert (ac->rank >= 1);
 
-       pos = sp [1].data.i - ao->bounds [0].lower_bound;
+       pos = sp [0].data.i - ao->bounds [0].lower_bound;
        for (i = 1; i < ac->rank; i++)
-               pos = pos*ao->bounds [i].length + sp [i + 1].data.i - 
+               pos = pos*ao->bounds [i].length + sp [i].data.i - 
                        ao->bounds [i].lower_bound;
 
        ea = ao->vector + (pos * ac->esize);
 
-       sp [0].type = VAL_I32; /* fixme: not really true */
-       memcpy (&sp [0].data.p, ea, ac->esize);
+       frame->retval->type = VAL_I32; /* fixme: not really true */
+       memcpy (&frame->retval->data.p, ea, ac->esize);
 }
 
 static void 
-ves_icall_System_Array_GetValue (MonoMethod *mh, stackval *sp)
+ves_icall_System_Array_GetValue (MonoInvocation *frame)
 {
+       stackval *sp = frame->stack_args;
        MonoArrayObject *ao, *io;
        MonoArrayClass *ac, *ic;
        gint32 i, pos, *ind;
        gpointer *ea;
 
-       g_assert (sp [0].type == VAL_OBJ);
-       g_assert (sp [1].type == VAL_OBJ); /* expect an array of integers */
+       g_assert (sp [0].type == VAL_OBJ); /* expect an array of integers */
 
-       io = sp [1].data.p;
+       io = sp [0].data.p;
        ic = (MonoArrayClass *)io->obj.klass;
        
-       ao = (MonoArrayObject *)sp [0].data.p;
+       ao = (MonoArrayObject *)frame->obj;
        ac = (MonoArrayClass *)ao->obj.klass;
 
        g_assert (ic->rank == 1);
@@ -103,34 +101,34 @@ ves_icall_System_Array_GetValue (MonoMethod *mh, stackval *sp)
 
        ea = ao->vector + (pos * ac->esize);
 
-       sp [0].type = VAL_OBJ; 
+       frame->retval->type = VAL_OBJ; 
 
        if (ac->class.evaltype)
-               sp [0].data.p = mono_value_box (ac->class.image, 
-                                               ac->etype_token, ea);
+               frame->retval->data.p = mono_value_box (ac->class.image, 
+                                                       ac->etype_token, ea);
        else
-               sp [0].data.p = ea;
+               frame->retval->data.p = ea;
 }
 
 static void 
-ves_icall_System_Array_SetValue (MonoMethod *mh, stackval *sp)
+ves_icall_System_Array_SetValue (MonoInvocation *frame)
 {
+       stackval *sp = frame->stack_args;
        MonoArrayObject *ao, *io, *vo;
        MonoArrayClass *ac, *ic, *vc;
        gint32 i, pos, *ind;
        gpointer *ea;
 
-       g_assert (sp [0].type == VAL_OBJ);
-       g_assert (sp [1].type == VAL_OBJ); /* the value object */
-       g_assert (sp [2].type == VAL_OBJ); /* expect an array of integers */
+       g_assert (sp [0].type == VAL_OBJ); /* the value object */
+       g_assert (sp [1].type == VAL_OBJ); /* expect an array of integers */
 
-       vo = sp [1].data.p;
+       vo = sp [0].data.p;
        vc = (MonoArrayClass *)vo->obj.klass;
 
-       io = sp [2].data.p;
+       io = sp [1].data.p;
        ic = (MonoArrayClass *)io->obj.klass;
        
-       ao = (MonoArrayObject *)sp [0].data.p;
+       ao = (MonoArrayObject *)frame->obj;
        ac = (MonoArrayClass *)ao->obj.klass;
 
        g_assert (ic->rank == 1);
@@ -156,41 +154,38 @@ ves_icall_System_Array_SetValue (MonoMethod *mh, stackval *sp)
 }
 
 static void 
-ves_icall_array_ctor (MonoMethod *mh, stackval *sp)
+ves_icall_array_ctor (MonoInvocation *frame)
 {
+       stackval *sp = frame->stack_args;
        MonoObject *o;
        MonoArrayObject *ao;
        MonoArrayClass *ac;
        gint32 i, len;
 
-       g_assert (sp [0].type == VAL_OBJ);
-
-       o = sp [0].data.p;
+       o = frame->obj;
        ao = (MonoArrayObject *)o;
        ac = (MonoArrayClass *)o->klass;
 
        g_assert (ac->rank >= 1);
 
-       len = sp [1].data.i;
+       len = sp [0].data.i;
        for (i = 1; i < ac->rank; i++)
-               len *= sp [i + 1].data.i;
+               len *= sp [i].data.i;
 
        ao->vector = g_malloc0 (len * ac->esize);
        ao->bounds = g_malloc0 (ac->rank * sizeof (MonoArrayBounds));
-
+       
        for (i = 0; i < ac->rank; i++)
-               ao->bounds [i].length = sp [i + 1].data.i;
+               ao->bounds [i].length = sp [i].data.i;
 }
 
 static void 
-ves_icall_array_bound_ctor (MonoMethod *mh, stackval *sp)
+ves_icall_array_bound_ctor (MonoInvocation *frame)
 {
        MonoObject *o;
        MonoArrayClass *ac;
 
-       g_assert (sp [0].type == VAL_OBJ);
-
-       o = sp [0].data.p;
+       o = frame->obj;
        ac = (MonoArrayClass *)o->klass;
 
        g_warning ("experimental implementation");
@@ -198,52 +193,52 @@ ves_icall_array_bound_ctor (MonoMethod *mh, stackval *sp)
 }
 
 static void 
-ves_icall_System_Array_GetRank (MonoMethod *mh, stackval *sp)
+ves_icall_System_Array_CreateInstance (MonoInvocation *frame)
 {
-       MonoObject *o;
+       g_warning ("not implemented");
+       g_assert_not_reached ();
+}
 
-       g_assert (sp [0].type == VAL_OBJ);
+static void 
+ves_icall_System_Array_GetRank (MonoInvocation *frame)
+{
+       MonoObject *o;
 
-       o = sp [0].data.p;
+       o = frame->obj;
 
-       sp [0].data.i = ((MonoArrayClass *)o->klass)->rank;
-       sp [0].type = VAL_I32;
+       frame->retval->data.i = ((MonoArrayClass *)o->klass)->rank;
+       frame->retval->type = VAL_I32;
 }
 
 static void 
-ves_icall_System_Array_GetLength (MonoMethod *mh, stackval *sp)
+ves_icall_System_Array_GetLength (MonoInvocation *frame)
 {
+       stackval *sp = frame->stack_args;
        MonoObject *o;
 
-       g_assert (sp [0].type == VAL_OBJ);
+       o = frame->obj;
 
-       o = sp [0].data.p;
-
-       sp [0].data.i = ((MonoArrayObject *)o)->bounds [sp [1].data.i].length;
-       sp [0].type = VAL_I32;
+       frame->retval->data.i = ((MonoArrayObject *)o)->bounds [sp [0].data.i].length;
+       frame->retval->type = VAL_I32;
 }
 
 static void 
-ves_icall_System_Array_GetLowerBound (MonoMethod *mh, stackval *sp)
+ves_icall_System_Array_GetLowerBound (MonoInvocation *frame)
 {
+       stackval *sp = frame->stack_args;
        MonoArrayObject *ao;
 
-       g_assert (sp [0].type == VAL_OBJ);
-
-       ao = (MonoArrayObject *)sp [0].data.p;
+       ao = (MonoArrayObject *)frame->obj;
 
-       sp [0].data.i = ao->bounds [sp [1].data.i].lower_bound;
-       sp [0].type = VAL_I32;
+       frame->retval->data.i = ao->bounds [sp [0].data.i].lower_bound;
+       frame->retval->type = VAL_I32;
 }
 
 static void 
-ves_icall_System_Object_MemberwiseClone (MonoMethod *mh, stackval *sp)
+ves_icall_System_Object_MemberwiseClone (MonoInvocation *frame)
 {
-       MonoObject *o;
-
-       g_assert (sp [0].type == VAL_OBJ);
-
-       sp [0].data.p = mono_object_clone (sp [0].data.p);
+       frame->retval->type = VAL_OBJ;
+       frame->retval->data.p = mono_object_clone (frame->obj);
 }
 
 static gpointer icall_map [] = {
@@ -259,6 +254,7 @@ static gpointer icall_map [] = {
        "System.Array::GetRank",          ves_icall_System_Array_GetRank,
        "System.Array::GetLength",        ves_icall_System_Array_GetLength,
        "System.Array::GetLowerBound",    ves_icall_System_Array_GetLowerBound,
+       "System.Array::CreateInstance",   ves_icall_System_Array_CreateInstance,
 
        /*
         * System.Object
index 3ecaaccbc87ba232cb9c0c3c0017bb583acae9b1..ceca850a1a097e3fbd505ab6119eb900afc4a9d4 100644 (file)
  *
  * (C) 2001 Ximian, Inc.
  */
-#define _ISOC99_SOURCE
-
 #include <config.h>
 #include <stdio.h>
 #include <string.h>
 #include <glib.h>
 #include <ffi.h>
-#include <math.h>
 
 
 #ifdef HAVE_ALLOCA_H
@@ -59,7 +56,7 @@ static MonoImage *corlib = NULL;
 
 static void ves_exec_method (MonoInvocation *frame);
 
-typedef void (*ICallMethod) (MonoMethod *mh, stackval *args);
+typedef void (*ICallMethod) (MonoInvocation *frame);
 
 
 static void
@@ -137,7 +134,9 @@ newobj (MonoImage *image, guint32 token)
        
        switch (mono_metadata_token_code (token)){
        case MONO_TOKEN_METHOD_DEF: {
-               guint32 idx = mono_metadata_typedef_from_method (m, token);
+               guint32 idx;
+
+               idx = mono_metadata_typedef_from_method (m, token);
                result = mono_object_new (image, MONO_TOKEN_TYPE_DEF | idx);
                break;
        }
@@ -174,6 +173,9 @@ newobj (MonoImage *image, guint32 token)
                }
                break;
        }
+       default:
+               g_warning ("dont know how to handle token %p\n", token); 
+               g_assert_not_reached ();
        }
        
        if (result)
@@ -230,29 +232,33 @@ get_named_exception (const char *name)
        MonoClass *klass;
        MonoInvocation call;
        MonoObject *o;
-       MonoMethodSignature sig = {
-               1, /* hasthis */
-               0,
-               MONO_CALL_DEFAULT,
-               0, /* param count */
-               0, /* sentinel pos */
-               NULL, /* retval -> void */
-               NULL, /* params */
-               0
-       };
        int i;
        guint32 tdef = mono_typedef_from_name (corlib, name, "System", NULL);
-       o = newobj (corlib, tdef);
+       stackval sv;
+
+       o = mono_object_new (corlib, tdef);
+       g_assert (o != NULL);
+
        klass = mono_class_get (corlib, tdef);
        call.method = NULL;
+
+       /* fixme: this returns the wrong constructor .ctor() without the
+          string argument */
        for (i = 0; i < klass->method.count; ++i) {
-               if (match_signature (".ctor", &sig, klass->methods [i])) {
+               if (!strcmp (".ctor", klass->methods [i]->name) &&
+                   klass->methods [i]->signature->param_count == 0) {
                        call.method = klass->methods [i];
                        break;
                }
        }
-       g_assert (call.method);
+       sv.data.p = o;
+       sv.type = VAL_OBJ;
+
+       call.stack_args = &sv;
        call.obj = o;
+
+       g_assert (call.method);
+
        ves_exec_method (&call);
        return o;
 }
@@ -411,17 +417,19 @@ mono_get_ansi_string (MonoObject *o)
 }
 
 static void 
-ves_pinvoke_method (MonoMethod *mh, stackval *sp)
+ves_pinvoke_method (MonoInvocation *frame)
 {
-       MonoMethodPInvoke *piinfo = (MonoMethodPInvoke *)mh;
+       MonoMethodPInvoke *piinfo = (MonoMethodPInvoke *)frame->method;
+       MonoMethodSignature *sig = frame->method->signature;
        gpointer *values;
        float *tmp_float;
        char **tmp_string;
        int i, acount, rsize, align;
+       stackval *sp = frame->stack_args;
        gpointer res = NULL; 
        GSList *t, *l = NULL;
 
-       acount = mh->signature->param_count;
+       acount = sig->param_count;
 
        values = alloca (sizeof (gpointer) * acount);
 
@@ -429,7 +437,7 @@ ves_pinvoke_method (MonoMethod *mh, stackval *sp)
 
        for (i = 0; i < acount; i++) {
 
-               switch (mh->signature->params [i]->type->type) {
+               switch (sig->params [i]->type->type) {
 
                case MONO_TYPE_I1:
                case MONO_TYPE_U1:
@@ -452,7 +460,7 @@ ves_pinvoke_method (MonoMethod *mh, stackval *sp)
                case MONO_TYPE_STRING:
                        g_assert (sp [i].type == VAL_OBJ);
 
-                       if (mh->flags & PINVOKE_ATTRIBUTE_CHAR_SET_ANSI && sp [i].data.p) {
+                       if (frame->method->flags & PINVOKE_ATTRIBUTE_CHAR_SET_ANSI && sp [i].data.p) {
                                tmp_string = alloca (sizeof (char *));
                                *tmp_string = mono_get_ansi_string (sp [i].data.p);
                                l = g_slist_prepend (l, *tmp_string);
@@ -468,16 +476,16 @@ ves_pinvoke_method (MonoMethod *mh, stackval *sp)
                        break;
                default:
                        g_warning ("not implemented %x", 
-                                  mh->signature->params [i]->type->type);
+                                  sig->params [i]->type->type);
                        g_assert_not_reached ();
                }
 
        }
 
-       if ((rsize = mono_type_size (mh->signature->ret->type, &align)))
+       if ((rsize = mono_type_size (sig->ret->type, &align)))
                res = alloca (rsize);
 
-       ffi_call (piinfo->cif, mh->addr, res, values);
+       ffi_call (piinfo->cif, frame->method->addr, res, values);
                
        t = l;
        while (t) {
@@ -487,9 +495,8 @@ ves_pinvoke_method (MonoMethod *mh, stackval *sp)
 
        g_slist_free (l);
 
-       if (mh->signature->ret->type)
-               *sp = stackval_from_data (mh->signature->ret->type, res);
-                       
+       if (sig->ret->type->type != MONO_TYPE_VOID)
+               *frame->retval = stackval_from_data (sig->ret->type, res);
 }
 
 #define DEBUG_INTERP 0
@@ -584,16 +591,15 @@ ves_exec_method (MonoInvocation *frame)
 
        if (frame->method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) {
                ICallMethod icall = frame->method->addr;
-
-               icall (frame->method, frame->stack_args);
+               icall (frame);
                return;
-       }
+       } 
 
        if (frame->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
-               ves_pinvoke_method (frame->method, frame->stack_args);
+               ves_pinvoke_method (frame);
                return;
        } 
-
+               
        header = ((MonoMethodNormal *)frame->method)->header;
        signature = frame->method->signature;
        image = frame->method->image;
@@ -852,13 +858,17 @@ ves_exec_method (MonoInvocation *frame)
                        } else {
                                child_frame.obj = NULL;
                        }
-                       if (csignature->ret->type) {
+                       if (csignature->ret->type->type != MONO_TYPE_VOID) {
                                /* FIXME: handle valuetype */
                                child_frame.retval = &retval;
                        } else {
                                child_frame.retval = NULL;
                        }
+
+                       child_frame.ex = NULL;
+
                        ves_exec_method (&child_frame);
+
                        if (child_frame.ex) {
                                /*
                                 * An exception occurred, need to run finally, fault and catch handlers..
@@ -868,7 +878,7 @@ ves_exec_method (MonoInvocation *frame)
                        }
 
                        /* need to handle typedbyref ... */
-                       if (csignature->ret->type) {
+                       if (csignature->ret->type->type != MONO_TYPE_VOID) {
                                *sp = retval;
                                sp++;
                        }
@@ -876,7 +886,7 @@ ves_exec_method (MonoInvocation *frame)
                }
                CASE (CEE_CALLI) ves_abort(); BREAK;
                CASE (CEE_RET)
-                       if (signature->ret->type) {
+                       if (signature->ret->type->type != MONO_TYPE_VOID) {
                                --sp;
                                *frame->retval = *sp;
                        }
index 7faa223f76eaa516130cdc3768301e9d1623b842..eee29287add425340c9cdaf0bd4a5e4a0a965670 100644 (file)
@@ -1,5 +1,7 @@
 
 #include <glib.h>
+#include <mono/cli/cli.h>
+#include <mono/cli/object.h>
 
 enum {
        VAL_I32     = 0,
index 7bfb724831e3fb16044ee985aa544d914535234b..696fb06240e71f5635a766c2c1aff76d1f195489 100644 (file)
@@ -1,8 +1,26 @@
+2001-08-20  Dietmar Maurer  <dietmar@ximian.com>
+
+       * metadata.c (mono_metadata_signature_equal): impl.
+
+       * *: void is now a realy MonoType (instead of using NULL)
+       
+       * metadata.c (do_mono_metadata_parse_type): use
+       mono_metadata_parse_type to parse void value.
+
 Sat Aug 18 12:51:28 CEST 2001 Paolo Molaro <lupus@ximian.com>
 
        * metadata.c, metadata.h: in the signature and method header store
        only the space required for holding the loca vars and incoming arguments.
 
+2001-08-15  Dietmar Maurer  <dietmar@ximian.com>
+
+       * metadata.c (do_mono_metadata_parse_type): treat void like any
+       other type (instead of assigning NULL);
+
+2001-08-14  Dietmar Maurer  <dietmar@ximian.com>
+
+       * metadata.c (mono_metadata_parse_mh): fixxed pinned/byref value
+
 2001-08-09  Dietmar Maurer  <dietmar@ximian.com>
 
        * image.c (do_mono_image_open): added a cache for arrays.
index 8e4d00d317a9b6b25095d3ad12f6dcd907678b58..ad07a4dcf4bea5c81e9dc688d7c24704544e147d 100644 (file)
@@ -52,8 +52,11 @@ mono_assembly_open (const char *filename, MonoAssemblyResolverFn resolver,
        MonoMetadata *m;
        int i;
        const char *basename = strrchr (filename, '/');
+       const char *fullname = filename;
        static MonoAssembly *corlib;
        
+       g_return_val_if_fail (filename != NULL, NULL);
+
        if (basename == NULL)
                basename = filename;
        else
@@ -62,12 +65,13 @@ mono_assembly_open (const char *filename, MonoAssemblyResolverFn resolver,
        /*
         * Temporary hack until we have a complete corlib.dll
         */
-       if (!strcmp (basename, CORLIB_NAME) && corlib != NULL)
-               return corlib;
-               
-       g_return_val_if_fail (filename != NULL, NULL);
-
-       image = mono_image_open (filename, status);
+       if (!strcmp (basename, CORLIB_NAME)) {
+               if (corlib != NULL)
+                       return corlib;
+               fullname = MONO_ASSEMBLIES "/" CORLIB_NAME;
+       }
+       
+       image = mono_image_open (fullname, status);
        if (!image){
                if (status)
                        *status = MONO_IMAGE_ERROR_ERRNO;
index 8928f7e3c196565620bb1aa7fb38111f21d5fee0..9cf8e2a35a11a3a6502425ac0c426b22eb9017a8 100644 (file)
@@ -44,11 +44,11 @@ struct _MonoClass {
         * Field information: Type and location from object base
         */
        MonoClassField *fields;
-       
-       struct MonoMethod **methods;
+
+       MonoMethod **methods;
 
        /*
-        * After the fields, there is room for the static fields...
+        * After the methods, there is room for the static fields...
         */
 };
 
index 70298c78e03ea12d1110d776447d5f3543d8f56c..95ba2d185d3bd9a418831659aca80803472e1359 100644 (file)
 #include "interp.h"
 
 static void 
-ves_icall_array_Set (MonoMethod *mh, stackval *sp)
+ves_icall_array_Set (MonoInvocation *frame)
 {
+       stackval *sp = frame->stack_args;
        MonoObject *o;
        MonoArrayObject *ao;
        MonoArrayClass *ac;
        gint32 i, t, pos;
        gpointer ea;
 
-       g_assert (sp [0].type == VAL_OBJ);
-
-       o = sp [0].data.p;
+       o = frame->obj;
        ao = (MonoArrayObject *)o;
        ac = (MonoArrayClass *)o->klass;
 
        g_assert (ac->rank >= 1);
 
-       pos = sp [1].data.i - ao->bounds [0].lower_bound;
+       pos = sp [0].data.i - ao->bounds [0].lower_bound;
        for (i = 1; i < ac->rank; i++) {
-               if ((t = sp [i + 1].data.i - ao->bounds [i].lower_bound) >= 
+               if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >= 
                    ao->bounds [i].length) {
                        g_warning ("wrong array index");
                        g_assert_not_reached ();
                }
-               pos = pos*ao->bounds [i].length + sp [i + 1].data.i - 
+               pos = pos*ao->bounds [i].length + sp [i].data.i - 
                        ao->bounds [i].lower_bound;
        }
 
        ea = ao->vector + (pos * ac->esize);
-       memcpy (ea, &sp [ac->rank + 1].data.p, ac->esize);
+       memcpy (ea, &sp [ac->rank].data.p, ac->esize);
 }
 
 static void 
-ves_icall_array_Get (MonoMethod *mh, stackval *sp)
+ves_icall_array_Get (MonoInvocation *frame)
 {
+       stackval *sp = frame->stack_args;
        MonoObject *o;
        MonoArrayObject *ao;
        MonoArrayClass *ac;
        gint32 i, pos;
        gpointer ea;
 
-       g_assert (sp [0].type == VAL_OBJ);
-
-       o = sp [0].data.p;
+       o = frame->obj;
        ao = (MonoArrayObject *)o;
        ac = (MonoArrayClass *)o->klass;
 
        g_assert (ac->rank >= 1);
 
-       pos = sp [1].data.i - ao->bounds [0].lower_bound;
+       pos = sp [0].data.i - ao->bounds [0].lower_bound;
        for (i = 1; i < ac->rank; i++)
-               pos = pos*ao->bounds [i].length + sp [i + 1].data.i - 
+               pos = pos*ao->bounds [i].length + sp [i].data.i - 
                        ao->bounds [i].lower_bound;
 
        ea = ao->vector + (pos * ac->esize);
 
-       sp [0].type = VAL_I32; /* fixme: not really true */
-       memcpy (&sp [0].data.p, ea, ac->esize);
+       frame->retval->type = VAL_I32; /* fixme: not really true */
+       memcpy (&frame->retval->data.p, ea, ac->esize);
 }
 
 static void 
-ves_icall_System_Array_GetValue (MonoMethod *mh, stackval *sp)
+ves_icall_System_Array_GetValue (MonoInvocation *frame)
 {
+       stackval *sp = frame->stack_args;
        MonoArrayObject *ao, *io;
        MonoArrayClass *ac, *ic;
        gint32 i, pos, *ind;
        gpointer *ea;
 
-       g_assert (sp [0].type == VAL_OBJ);
-       g_assert (sp [1].type == VAL_OBJ); /* expect an array of integers */
+       g_assert (sp [0].type == VAL_OBJ); /* expect an array of integers */
 
-       io = sp [1].data.p;
+       io = sp [0].data.p;
        ic = (MonoArrayClass *)io->obj.klass;
        
-       ao = (MonoArrayObject *)sp [0].data.p;
+       ao = (MonoArrayObject *)frame->obj;
        ac = (MonoArrayClass *)ao->obj.klass;
 
        g_assert (ic->rank == 1);
@@ -103,34 +101,34 @@ ves_icall_System_Array_GetValue (MonoMethod *mh, stackval *sp)
 
        ea = ao->vector + (pos * ac->esize);
 
-       sp [0].type = VAL_OBJ; 
+       frame->retval->type = VAL_OBJ; 
 
        if (ac->class.evaltype)
-               sp [0].data.p = mono_value_box (ac->class.image, 
-                                               ac->etype_token, ea);
+               frame->retval->data.p = mono_value_box (ac->class.image, 
+                                                       ac->etype_token, ea);
        else
-               sp [0].data.p = ea;
+               frame->retval->data.p = ea;
 }
 
 static void 
-ves_icall_System_Array_SetValue (MonoMethod *mh, stackval *sp)
+ves_icall_System_Array_SetValue (MonoInvocation *frame)
 {
+       stackval *sp = frame->stack_args;
        MonoArrayObject *ao, *io, *vo;
        MonoArrayClass *ac, *ic, *vc;
        gint32 i, pos, *ind;
        gpointer *ea;
 
-       g_assert (sp [0].type == VAL_OBJ);
-       g_assert (sp [1].type == VAL_OBJ); /* the value object */
-       g_assert (sp [2].type == VAL_OBJ); /* expect an array of integers */
+       g_assert (sp [0].type == VAL_OBJ); /* the value object */
+       g_assert (sp [1].type == VAL_OBJ); /* expect an array of integers */
 
-       vo = sp [1].data.p;
+       vo = sp [0].data.p;
        vc = (MonoArrayClass *)vo->obj.klass;
 
-       io = sp [2].data.p;
+       io = sp [1].data.p;
        ic = (MonoArrayClass *)io->obj.klass;
        
-       ao = (MonoArrayObject *)sp [0].data.p;
+       ao = (MonoArrayObject *)frame->obj;
        ac = (MonoArrayClass *)ao->obj.klass;
 
        g_assert (ic->rank == 1);
@@ -156,41 +154,38 @@ ves_icall_System_Array_SetValue (MonoMethod *mh, stackval *sp)
 }
 
 static void 
-ves_icall_array_ctor (MonoMethod *mh, stackval *sp)
+ves_icall_array_ctor (MonoInvocation *frame)
 {
+       stackval *sp = frame->stack_args;
        MonoObject *o;
        MonoArrayObject *ao;
        MonoArrayClass *ac;
        gint32 i, len;
 
-       g_assert (sp [0].type == VAL_OBJ);
-
-       o = sp [0].data.p;
+       o = frame->obj;
        ao = (MonoArrayObject *)o;
        ac = (MonoArrayClass *)o->klass;
 
        g_assert (ac->rank >= 1);
 
-       len = sp [1].data.i;
+       len = sp [0].data.i;
        for (i = 1; i < ac->rank; i++)
-               len *= sp [i + 1].data.i;
+               len *= sp [i].data.i;
 
        ao->vector = g_malloc0 (len * ac->esize);
        ao->bounds = g_malloc0 (ac->rank * sizeof (MonoArrayBounds));
-
+       
        for (i = 0; i < ac->rank; i++)
-               ao->bounds [i].length = sp [i + 1].data.i;
+               ao->bounds [i].length = sp [i].data.i;
 }
 
 static void 
-ves_icall_array_bound_ctor (MonoMethod *mh, stackval *sp)
+ves_icall_array_bound_ctor (MonoInvocation *frame)
 {
        MonoObject *o;
        MonoArrayClass *ac;
 
-       g_assert (sp [0].type == VAL_OBJ);
-
-       o = sp [0].data.p;
+       o = frame->obj;
        ac = (MonoArrayClass *)o->klass;
 
        g_warning ("experimental implementation");
@@ -198,52 +193,52 @@ ves_icall_array_bound_ctor (MonoMethod *mh, stackval *sp)
 }
 
 static void 
-ves_icall_System_Array_GetRank (MonoMethod *mh, stackval *sp)
+ves_icall_System_Array_CreateInstance (MonoInvocation *frame)
 {
-       MonoObject *o;
+       g_warning ("not implemented");
+       g_assert_not_reached ();
+}
 
-       g_assert (sp [0].type == VAL_OBJ);
+static void 
+ves_icall_System_Array_GetRank (MonoInvocation *frame)
+{
+       MonoObject *o;
 
-       o = sp [0].data.p;
+       o = frame->obj;
 
-       sp [0].data.i = ((MonoArrayClass *)o->klass)->rank;
-       sp [0].type = VAL_I32;
+       frame->retval->data.i = ((MonoArrayClass *)o->klass)->rank;
+       frame->retval->type = VAL_I32;
 }
 
 static void 
-ves_icall_System_Array_GetLength (MonoMethod *mh, stackval *sp)
+ves_icall_System_Array_GetLength (MonoInvocation *frame)
 {
+       stackval *sp = frame->stack_args;
        MonoObject *o;
 
-       g_assert (sp [0].type == VAL_OBJ);
+       o = frame->obj;
 
-       o = sp [0].data.p;
-
-       sp [0].data.i = ((MonoArrayObject *)o)->bounds [sp [1].data.i].length;
-       sp [0].type = VAL_I32;
+       frame->retval->data.i = ((MonoArrayObject *)o)->bounds [sp [0].data.i].length;
+       frame->retval->type = VAL_I32;
 }
 
 static void 
-ves_icall_System_Array_GetLowerBound (MonoMethod *mh, stackval *sp)
+ves_icall_System_Array_GetLowerBound (MonoInvocation *frame)
 {
+       stackval *sp = frame->stack_args;
        MonoArrayObject *ao;
 
-       g_assert (sp [0].type == VAL_OBJ);
-
-       ao = (MonoArrayObject *)sp [0].data.p;
+       ao = (MonoArrayObject *)frame->obj;
 
-       sp [0].data.i = ao->bounds [sp [1].data.i].lower_bound;
-       sp [0].type = VAL_I32;
+       frame->retval->data.i = ao->bounds [sp [0].data.i].lower_bound;
+       frame->retval->type = VAL_I32;
 }
 
 static void 
-ves_icall_System_Object_MemberwiseClone (MonoMethod *mh, stackval *sp)
+ves_icall_System_Object_MemberwiseClone (MonoInvocation *frame)
 {
-       MonoObject *o;
-
-       g_assert (sp [0].type == VAL_OBJ);
-
-       sp [0].data.p = mono_object_clone (sp [0].data.p);
+       frame->retval->type = VAL_OBJ;
+       frame->retval->data.p = mono_object_clone (frame->obj);
 }
 
 static gpointer icall_map [] = {
@@ -259,6 +254,7 @@ static gpointer icall_map [] = {
        "System.Array::GetRank",          ves_icall_System_Array_GetRank,
        "System.Array::GetLength",        ves_icall_System_Array_GetLength,
        "System.Array::GetLowerBound",    ves_icall_System_Array_GetLowerBound,
+       "System.Array::CreateInstance",   ves_icall_System_Array_CreateInstance,
 
        /*
         * System.Object
index 5d4a5813674e86648937d34d63e72315065a3638..efa871cf15eb362466b0f5811203f705060f9052 100644 (file)
@@ -205,20 +205,26 @@ mono_get_string_class_info (guint *ttoken, MonoImage **cl)
 static MonoMethod *
 method_from_memberref (MonoImage *image, guint32 index)
 {
+       MonoImage *mimage;
        MonoMetadata *m = &image->metadata;
        MonoTableInfo *tables = m->tables;
        guint32 cols[6];
-       guint32 nindex, sig_len, msig_len, class, i;
-       const char *sig, *msig, *mname, *name, *nspace;
+       guint32 nindex, class, i;
+       const char *mname, *name, *nspace;
+       MonoMethodSignature *sig, *msig;
+       const char *ptr;
 
        mono_metadata_decode_row (&tables [MONO_TABLE_MEMBERREF], index-1, cols, 3);
        nindex = cols [MONO_MEMBERREF_CLASS] >> MEMBERREF_PARENT_BITS;
        class = cols [MONO_MEMBERREF_CLASS] & MEMBERREF_PARENT_MASK;
        /*g_print ("methodref: 0x%x 0x%x %s\n", class, nindex,
                mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]));*/
-       sig = mono_metadata_blob_heap (m, cols [MONO_MEMBERREF_SIGNATURE]);
-       sig_len = mono_metadata_decode_blob_size (sig, &sig);
+
        mname = mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]);
+       
+       ptr = mono_metadata_blob_heap (m, cols [MONO_MEMBERREF_SIGNATURE]);
+       mono_metadata_decode_blob_size (ptr, &ptr);
+       sig = mono_metadata_parse_method_signature (m, 0, ptr, NULL);
 
        switch (class) {
        case MEMBERREF_PARENT_TYPEREF: {
@@ -243,23 +249,31 @@ method_from_memberref (MonoImage *image, guint32 index)
                        /* this will triggered by references to mscorlib */
                        g_assert (image->references [scopeindex-1] != NULL);
 
-                       image = image->references [scopeindex-1]->image;
+                       mimage = image->references [scopeindex-1]->image;
 
-                       m = &image->metadata;
+                       m = &mimage->metadata;
                        tables = &m->tables [MONO_TABLE_METHOD];
-                       mono_typedef_from_name (image, name, nspace, &i);
+                       mono_typedef_from_name (mimage, name, nspace, &i);
                        /* mostly dumb search for now */
-                       for (;i < tables->rows; ++i) {
+                       for (i--; i < tables->rows; ++i) {
+
                                mono_metadata_decode_row (tables, i, cols, MONO_METHOD_SIZE);
-                               msig = mono_metadata_blob_heap (m, cols [MONO_METHOD_SIGNATURE]);
-                               msig_len = mono_metadata_decode_blob_size (msig, &msig);
-                               
-                               if (strcmp (mname, mono_metadata_string_heap (m, cols [MONO_METHOD_NAME])) == 0 
-                                               && sig_len == msig_len
-                                               && strncmp (sig, msig, sig_len) == 0) {
-                                       return mono_get_method (image, MONO_TOKEN_METHOD_DEF | (i + 1));
+
+                               if (!strcmp (mname, mono_metadata_string_heap (m, cols [MONO_METHOD_NAME]))) {
+                                       
+                                       ptr = mono_metadata_blob_heap (m, cols [MONO_METHOD_SIGNATURE]);
+                                       mono_metadata_decode_blob_size (ptr, &ptr);
+                                       msig = mono_metadata_parse_method_signature (m, 1, ptr, NULL);
+
+                                       if (mono_metadata_signature_equal (&image->metadata, sig, 
+                                                                          &mimage->metadata, msig)) {
+                                               mono_metadata_free_method_signature (sig);
+                                               mono_metadata_free_method_signature (msig);
+                                               return mono_get_method (mimage, MONO_TOKEN_METHOD_DEF | (i + 1));
+                                       }
                                }
                        }
+                       g_warning ("cant find method %s.%s::%s",nspace, name, mname);
                        g_assert_not_reached ();
                        break;
                default:
@@ -268,9 +282,7 @@ method_from_memberref (MonoImage *image, guint32 index)
                break;
        }
        case MEMBERREF_PARENT_TYPESPEC: {
-               MonoMethodSignature *ms;
                guint32 bcols [MONO_TYPESPEC_SIZE];
-               const char *ptr;
                guint32 len;
                MonoType *type;
                MonoMethod *result;
@@ -284,19 +296,17 @@ method_from_memberref (MonoImage *image, guint32 index)
                if (type->type != MONO_TYPE_ARRAY)
                        g_assert_not_reached ();                
 
-               ms = mono_metadata_parse_method_signature (m, 0, sig, &sig);
-
                result = (MonoMethod *)g_new0 (MonoMethod, 1);
                result->image = image;
                result->iflags = METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL;
-               result->signature = ms;
+               result->signature = sig;
                
                if (!strcmp (mname, ".ctor")) { 
-                       g_assert (ms->hasthis);
-                       if (type->data.array->rank == ms->param_count) {
+                       g_assert (sig->hasthis);
+                       if (type->data.array->rank == sig->param_count) {
                                result->addr = mono_lookup_internal_call ("__array_ctor");
                                return result;
-                       } else if ((type->data.array->rank * 2) == ms->param_count) {
+                       } else if ((type->data.array->rank * 2) == sig->param_count) {
                                result->addr = mono_lookup_internal_call ("__array_bound_ctor");
                                return result;                  
                        } else 
@@ -304,16 +314,16 @@ method_from_memberref (MonoImage *image, guint32 index)
                }
 
                if (!strcmp (mname, "Set")) {
-                       g_assert (ms->hasthis);
-                       g_assert (type->data.array->rank + 1 == ms->param_count);
+                       g_assert (sig->hasthis);
+                       g_assert (type->data.array->rank + 1 == sig->param_count);
 
                        result->addr = mono_lookup_internal_call ("__array_Set");
                        return result;
                }
 
                if (!strcmp (mname, "Get")) {
-                       g_assert (ms->hasthis);
-                       g_assert (type->data.array->rank == ms->param_count);
+                       g_assert (sig->hasthis);
+                       g_assert (type->data.array->rank == sig->param_count);
 
                        result->addr = mono_lookup_internal_call ("__array_Get");
                        return result;
@@ -334,9 +344,6 @@ ves_map_ffi_type (MonoType *type)
 {
        ffi_type *rettype;
 
-       if (!type)
-               return &ffi_type_void;
-
        switch (type->type) {
        case MONO_TYPE_I1:
                rettype = &ffi_type_sint8;
@@ -367,6 +374,9 @@ ves_map_ffi_type (MonoType *type)
        case MONO_TYPE_STRING:
                rettype = &ffi_type_pointer;
                break;
+       case MONO_TYPE_VOID:
+               rettype = &ffi_type_void;
+               break;
        default:
                g_warning ("not implemented");
                g_assert_not_reached ();
@@ -451,7 +461,7 @@ mono_get_method (MonoImage *image, guint32 token)
        const char *loc, *sig = NULL;
        char *name;
        int size;
-       guint32 cols[6];
+       guint32 cols[MONO_TYPEDEF_SIZE];
 
        if (table == MONO_TABLE_METHOD && (result = g_hash_table_lookup (image->method_cache, GINT_TO_POINTER (token))))
                        return result;
@@ -506,9 +516,7 @@ mono_get_method (MonoImage *image, guint32 token)
        if (!sig) /* already taken from the methodref */
                sig = mono_metadata_blob_heap (m, cols [4]);
        size = mono_metadata_decode_blob_size (sig, &sig);
-       result->signature = mono_metadata_parse_method_signature (m, 0, sig, 
-                                                                 NULL);
-
+       result->signature = mono_metadata_parse_method_signature (m, 0, sig, NULL);
 
        if (result->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
                fill_pinvoke_info (image, (MonoMethodPInvoke *)result, 
index 930eff1587f0a67c8253bb193464b58bad433fb2..5178286937f7764154fac748770235e83237cd07 100644 (file)
@@ -993,7 +993,7 @@ mono_metadata_parse_param (MonoMetadata *m, int rettype, const char *ptr, const
        case MONO_TYPE_VOID: 
                if (!rettype)
                        g_error ("void not allowed in param");
-               ptr++;
+               param->type = mono_metadata_parse_type (m, ptr, &ptr);
                break;
        case MONO_TYPE_BYREF: 
                byref = 1; 
@@ -1092,6 +1092,7 @@ do_mono_metadata_parse_type (MonoType *type, MonoMetadata *m, const char *ptr, c
        type->type = mono_metadata_decode_value (ptr, &ptr);
        
        switch (type->type){
+       case MONO_TYPE_VOID:
        case MONO_TYPE_BOOLEAN:
        case MONO_TYPE_CHAR:
        case MONO_TYPE_I1:
@@ -1131,21 +1132,9 @@ do_mono_metadata_parse_type (MonoType *type, MonoMetadata *m, const char *ptr, c
                        /* save them this time */
                        while (mono_metadata_parse_custom_mod (m, &(mtype->modifiers[count]), ptr, &ptr))
                                count++;
-                       /* FIXME: mono_metadata_decode_value ... */
-                       if (*ptr == MONO_TYPE_VOID) {
-                               mtype->type = NULL;
-                               ptr++;
-                       } else {
-                               mtype->type = mono_metadata_parse_type (m, ptr, &ptr);
-                       }
+                       mtype->type = mono_metadata_parse_type (m, ptr, &ptr);
                } else {
-                       /* FIXME: mono_metadata_decode_value ... */
-                       if (*ptr == MONO_TYPE_VOID) {
-                               type->data.type = NULL;
-                               ptr++;
-                       } else {
-                               type->data.type = mono_metadata_parse_type (m, ptr, &ptr);
-                       }
+                       type->data.type = mono_metadata_parse_type (m, ptr, &ptr);
                }
                break;
        case MONO_TYPE_FNPTR:
@@ -1396,19 +1385,26 @@ mono_metadata_parse_mh (MonoMetadata *m, const char *ptr)
                        return mh;
                mh->locals = g_new (MonoType*, len);
                for (i = 0; i < len; ++i) {
+                       gboolean pinned = FALSE;
                        int val;
                        int align;
                        const char *p = ptr;
                        val = mono_metadata_decode_blob_size (ptr, &ptr);
-                       /* FIXME: store pinned/byref values */
                        if (val == MONO_TYPE_PINNED) {
                                p = ptr;
+                               pinned = TRUE;
                                val = mono_metadata_decode_blob_size (ptr, &ptr);
                        }
                        if (val == MONO_TYPE_BYREF) {
                                p = ptr;
                        }
                        mh->locals [i] = mono_metadata_parse_type (m, p, &ptr);
+
+                       if (pinned) 
+                               mh->locals [i]->constraint = MONO_TYPE_PINNED;
+                       if (val == MONO_TYPE_BYREF) 
+                               mh->locals [i]->byref = 1;
+
                        val = mono_type_size (mh->locals [i], &align);
                        offset += (offset % align);
                        offset += val;
@@ -1580,6 +1576,9 @@ mono_type_size (MonoType *t, gint *align)
        }
 
        switch (t->type){
+       case MONO_TYPE_VOID:
+               *align = 0;
+               return 0;
        case MONO_TYPE_BOOLEAN:
                *align = __alignof__(char);
                return sizeof (char);
@@ -1631,6 +1630,7 @@ mono_type_size (MonoType *t, gint *align)
                /*
                 * FIXME: very bogus value
                 */
+               g_warning ("fixme: wrong size for value type");
                return 4;
        case MONO_TYPE_CLASS:
        case MONO_TYPE_SZARRAY:
@@ -1645,3 +1645,118 @@ mono_type_size (MonoType *t, gint *align)
        return 0;
 }
 
+static gboolean
+mono_metadata_type_token_equal (MonoMetadata *m1, guint32 token1, 
+                               MonoMetadata *m2, guint32 token2)
+{
+       int table1 = mono_metadata_token_table (token1);
+       int index1 = mono_metadata_token_index (token1);
+       int table2 = mono_metadata_token_table (token2);
+       int index2 = mono_metadata_token_index (token2);
+       guint32 cols[MAX (MONO_TYPEDEF_SIZE, MONO_TYPEREF_SIZE)];
+       const char *name1, *nspace1;
+       const char *name2, *nspace2;
+
+       switch (table1) {
+       case MONO_TABLE_TYPEDEF:
+               mono_metadata_decode_row (&m1->tables [table1], index1 - 1, cols, MONO_TYPEDEF_SIZE);
+               name1 = mono_metadata_string_heap (m1, cols [MONO_TYPEDEF_NAME]);
+               nspace1 = mono_metadata_string_heap (m1, cols [MONO_TYPEDEF_NAMESPACE]);
+               break;
+       case MONO_TABLE_TYPEREF:
+               mono_metadata_decode_row (&m1->tables [table1], index1 - 1, cols, MONO_TYPEREF_SIZE);
+               name1 = mono_metadata_string_heap (m1, cols [MONO_TYPEREF_NAME]);
+               nspace1 = mono_metadata_string_heap (m1, cols [MONO_TYPEREF_NAMESPACE]);
+               break;
+       default:
+               g_assert_not_reached ();
+       }
+
+
+       switch (table2) {
+       case MONO_TABLE_TYPEDEF:
+               mono_metadata_decode_row (&m2->tables [table2], index2 - 1, cols, MONO_TYPEDEF_SIZE);
+               name2 = mono_metadata_string_heap (m2, cols [MONO_TYPEDEF_NAME]);
+               nspace2 = mono_metadata_string_heap (m2, cols [MONO_TYPEDEF_NAMESPACE]);
+               break;
+       case MONO_TABLE_TYPEREF:
+               mono_metadata_decode_row (&m2->tables [table2], index2 -1, cols, MONO_TYPEREF_SIZE);
+               name2 = mono_metadata_string_heap (m2, cols [MONO_TYPEREF_NAME]);
+               nspace2 = mono_metadata_string_heap (m2, cols [MONO_TYPEREF_NAMESPACE]);
+               break;
+       default:
+               g_assert_not_reached ();
+       }
+
+
+       if (strcmp (nspace1, nspace2))
+               return FALSE;
+
+       if (strcmp (name1, name2))
+               return FALSE;
+
+       return TRUE;
+}
+
+static gboolean
+mono_metadata_type_equal (MonoMetadata *m1, MonoType *t1, MonoMetadata *m2, MonoType *t2)
+{
+       if (t1->type != t2->type ||
+           t1->byref != t2->byref)
+               return FALSE;
+
+       switch (t1->type) {
+       case MONO_TYPE_VOID:
+       case MONO_TYPE_BOOLEAN:
+       case MONO_TYPE_CHAR:
+       case MONO_TYPE_I1:
+       case MONO_TYPE_U1:
+       case MONO_TYPE_I2:
+       case MONO_TYPE_U2:
+       case MONO_TYPE_I4:
+       case MONO_TYPE_U4:
+       case MONO_TYPE_I8:
+       case MONO_TYPE_U8:
+       case MONO_TYPE_R4:
+       case MONO_TYPE_R8:
+       case MONO_TYPE_STRING:
+       case MONO_TYPE_I:
+       case MONO_TYPE_U:
+       case MONO_TYPE_OBJECT:
+               break;
+       case MONO_TYPE_VALUETYPE:
+       case MONO_TYPE_CLASS:
+               return mono_metadata_type_token_equal (m1, t1->data.token, m2, t2->data.token);
+       default:
+               g_error ("implement type compare for %0x!", t1->type);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+gboolean
+mono_metadata_signature_equal (MonoMetadata *m1, MonoMethodSignature *sig1, 
+                              MonoMetadata *m2, MonoMethodSignature *sig2)
+{
+       int i;
+
+       if (sig1->hasthis != sig2->hasthis ||
+           sig1->param_count != sig2->param_count)
+               return FALSE;
+
+       for (i = 0; i < sig1->param_count; i++) { 
+               MonoParam *p1 = sig1->params[i];
+               MonoParam *p2 = sig2->params[i];
+               
+               if (p1->param_attrs != p2->param_attrs ||
+                   p1->typedbyref !=  p2->typedbyref)
+                       return FALSE;
+               
+               if (!mono_metadata_type_equal (m1, p1->type, m2, p2->type))
+                       return FALSE;
+       }
+
+       return TRUE;
+}
+
index 98b9ced0a5485c26b540842effe605f0deb006b3..363e3f17dc10769f85d2923aad3fe679b721df17 100644 (file)
@@ -269,6 +269,11 @@ MonoMethodSignature  *mono_metadata_parse_method_signature (MonoMetadata
                                                             const char           **rptr);
 void                  mono_metadata_free_method_signature  (MonoMethodSignature   *method);
 
+gboolean          mono_metadata_signature_equal (MonoMetadata *m1, 
+                                                MonoMethodSignature *sig1, 
+                                                MonoMetadata *m2, 
+                                                MonoMethodSignature *sig2);
+
 MonoMethodHeader *mono_metadata_parse_mh (MonoMetadata *m, const char *ptr);
 void              mono_metadata_free_mh  (MonoMethodHeader *mh);
 
index 2f32a9ec85d86684d0dd91c1a2e1e7057feb2985..997e08eac2856709167101427f62827d048e2c4a 100644 (file)
@@ -135,4 +135,3 @@ mono_value_box (MonoImage *image, guint32 etype, gpointer val)
 
        return res;
 }
-
index cea71aa9205328ef9c5cd79862a24a98f0f69b1c..82da795bafc612a4198011aa08196a0c1abfb2ef 100644 (file)
@@ -34,7 +34,7 @@ void
 mono_object_free      (MonoObject *o);
 
 MonoObject *
-mono_value_box        (MonoImage *image, guint32 etype, gpointer val);
+mono_value_box        (MonoImage *image, guint32 type, gpointer val);
                      
 MonoObject *
 mono_object_clone     (MonoObject *obj);
index 7cec0c37f2b86aa151dc218a8c6f25c6d9a29448..1b2fe702501660230c5199d7c8607c41f1e75d71 100644 (file)
@@ -13,7 +13,8 @@ TESTSRC=                      \
        exception.cs            \
        struct.cs               \
        pinvoke.cs              \
-       array.cs
+       array.cs                \
+       stream.cs
 
 TESTS=                         \
        test-ops.exe            \
@@ -26,7 +27,8 @@ TESTS=                                \
        exception.exe           \
        struct.exe              \
        pinvoke.exe             \
-       array.exe
+       array.exe               \
+       stream.exe
 
 EXTRA_DIST=test-driver $(TESTSRC)
 
diff --git a/mono/tests/stream.cs b/mono/tests/stream.cs
new file mode 100755 (executable)
index 0000000..0636c8d
--- /dev/null
@@ -0,0 +1,15 @@
+using System;
+using System.IO;
+
+public class Test {
+
+       public static int Main () {
+               FileStream s = new FileStream ("/tmp/stest.dat", FileMode.Create);
+               
+               
+               
+               return 0;
+       }
+}
+
+
diff --git a/mono/wrapper/.cvsignore b/mono/wrapper/.cvsignore
new file mode 100644 (file)
index 0000000..f0889f3
--- /dev/null
@@ -0,0 +1,8 @@
+Makefile
+Makefile.in
+.deps
+.libs
+wrapper.h
+*.lo
+*.la
+Wrapper.cs
\ No newline at end of file
diff --git a/mono/wrapper/Makefile.am b/mono/wrapper/Makefile.am
new file mode 100644 (file)
index 0000000..1ca825c
--- /dev/null
@@ -0,0 +1,20 @@
+lib_LTLIBRARIES = libmonowrapper.la
+
+INCLUDES = $(GLIB_CFLAGS) -I$(top_srcdir)
+
+libmonowrapper_la_SOURCES =            \
+       wrapper.c       
+
+libmonowrapperincludedir = $(includir)/mono/wrapper
+
+libmonowrapperinclude_HEADERS = 
+       wrapper.h       
+
+noinst_HEADERS =
+
+
+wrapper.h: genwrapper.pl
+       ./genwrapper.pl >wrapper.h
+
+BUILT_SOURCES = wrapper.h
+CLEANFILES += $(BUILT_SOURCES)
diff --git a/mono/wrapper/genwrapper.pl b/mono/wrapper/genwrapper.pl
new file mode 100755 (executable)
index 0000000..7443cfd
--- /dev/null
@@ -0,0 +1,458 @@
+#!/usr/bin/perl
+
+# Author:
+#      Dietmar Maurer (dietmar@ximian.com)
+#
+# (C) 2001 Ximian, Inc.
+
+use Getopt::Long;
+init();
+
+@includes = ("sys/types.h", "sys/stat.h", "unistd.h", "fcntl.h", "glib.h",
+            "errno.h");
+$cflags = `gnome-config --cflags glib`;
+$cflags =~ s/\n//;
+
+$lib = "monowrapper";
+
+create_struct ("MonoWrapperStat", "stat",
+              "uint", "st_dev",
+              "uint", "st_mode",
+              "uint", "st_nlink",
+              "uint", "st_uid",
+              "uint", "st_gid",
+              "long", "st_size",
+              "uint", "st_atime",
+              "uint", "st_mtime",
+              "uint", "st_ctime",
+              );
+
+create_func ($lib, "", "seek", "long", 
+            "IntPtr", "fd",
+            "long", "offset",
+            "int", "whence");
+
+create_func ($lib, "", "read", "int",
+            "IntPtr", "fd",
+            "void *", "buf",
+            "int", "count");
+
+create_func ($lib, "", "write", "int",
+            "IntPtr", "fd",
+            "void *", "buf",
+            "int", "count");
+
+create_func ($lib, "", "fstat", "int",
+            "IntPtr", "fd",
+            "stat *", "buf");
+
+create_func ($lib, "", "ftruncate", "int",
+            "IntPtr", "fd",
+            "long", "length");
+
+create_func ($lib, "", "open", "IntPtr",
+            "string", "path",
+            "int", "flags",
+            "int", "mode");
+
+create_func ($lib, "", "close", "int",
+            "IntPtr", "fd");
+
+map_const ("int", "%d", "SEEK_SET",
+          "int", "%d", "SEEK_CUR",
+          "int", "%d", "SEEK_END",
+
+          "int", "0x%08x", "O_RDONLY",
+          "int", "0x%08x", "O_WRONLY",
+          "int", "0x%08x", "O_RDWR",
+          "int", "0x%08x", "O_CREAT",
+          "int", "0x%08x", "O_EXCL",
+          "int", "0x%08x", "O_NOCTTY",
+          "int", "0x%08x", "O_TRUNC",
+          "int", "0x%08x", "O_SYNC",
+          "int", "0x%08x", "O_APPEND",
+
+          "int", "0x%08x", "STDIN_FILENO",
+          "int", "0x%08x", "STDOUT_FILENO",
+          "int", "0x%08x", "STDERR_FILENO",
+
+          "int", "0x%08x", "S_IFMT",
+          "int", "0x%08x", "S_IFSOCK",
+          "int", "0x%08x", "S_IFLNK",
+          "int", "0x%08x", "S_IFREG",
+          "int", "0x%08x", "S_IFBLK",
+          "int", "0x%08x", "S_IFDIR",
+          "int", "0x%08x", "S_IFCHR",
+          "int", "0x%08x", "S_IFIFO",
+          "int", "0x%08x", "S_ISUID",
+          "int", "0x%08x", "S_ISGID",
+          "int", "0x%08x", "S_ISVTX",
+          "int", "0x%08x", "S_IRWXU",
+          "int", "0x%08x", "S_IRUSR",
+          "int", "0x%08x", "S_IWUSR",
+          "int", "0x%08x", "S_IXUSR",
+          "int", "0x%08x", "S_IRWXG",
+          "int", "0x%08x", "S_IRGRP",
+          "int", "0x%08x", "S_IWGRP",
+          "int", "0x%08x", "S_IXGRP",
+          "int", "0x%08x", "S_IRWXO",
+          "int", "0x%08x", "S_IROTH",
+          "int", "0x%08x", "S_IWOTH",
+          "int", "0x%08x", "S_IXOTH",
+
+          "int", "%d", "EPERM",
+          "int", "%d", "ENOENT",
+          "int", "%d", "ESRCH",
+          "int", "%d", "EINTR",
+          "int", "%d", "EIO",
+          "int", "%d", "ENXIO",
+          "int", "%d", "E2BIG",
+          "int", "%d", "ENOEXEC",
+          "int", "%d", "EBADF",
+          "int", "%d", "ECHILD",
+          "int", "%d", "EAGAIN",
+          "int", "%d", "ENOMEM",
+          "int", "%d", "EACCES",
+          "int", "%d", "EFAULT",
+          "int", "%d", "ENOTBLK",
+          "int", "%d", "EBUSY",
+          "int", "%d", "EEXIST",
+          "int", "%d", "EXDEV",
+          "int", "%d", "ENODEV",
+          "int", "%d", "EISDIR",
+          "int", "%d", "EINVAL",
+          "int", "%d", "ENFILE",
+          "int", "%d", "EMFILE",
+          "int", "%d", "ENOTTY",
+          "int", "%d", "ETXTBSY",
+          "int", "%d", "EFBIG",
+          "int", "%d", "ENOSPC",
+          "int", "%d", "ESPIPE",
+          "int", "%d", "EROFS",
+          "int", "%d", "EMLINK",
+          "int", "%d", "EPIPE",
+          "int", "%d", "EDOM",
+          "int", "%d", "ERANGE",
+          "int", "%d", "EDEADLK",
+          "int", "%d", "ENAMETOOLONG",
+          "int", "%d", "ENOLCK",
+          "int", "%d", "ENOSYS",
+          "int", "%d", "ENOTEMPTY",
+          "int", "%d", "ELOOP",
+          "int", "%d", "EWOULDBLOCK",
+          "int", "%d", "ENOMSG",
+          "int", "%d", "EIDRM",
+          "int", "%d", "ECHRNG",
+          "int", "%d", "EL2NSYNC",
+          "int", "%d", "EL3HLT",
+          "int", "%d", "EL3RST",
+          "int", "%d", "ELNRNG",
+          "int", "%d", "EUNATCH",
+          "int", "%d", "ENOCSI",
+          "int", "%d", "EL2HLT",
+          "int", "%d", "EBADE",
+          "int", "%d", "EBADR",
+          "int", "%d", "EXFULL",
+          "int", "%d", "ENOANO",
+          "int", "%d", "EBADRQC",
+          "int", "%d", "EBADSLT",
+          "int", "%d", "EDEADLOCK",
+          "int", "%d", "EBFONT",
+          "int", "%d", "ENOSTR",
+          "int", "%d", "ENODATA",
+          "int", "%d", "ETIME",
+          "int", "%d", "ENOSR",
+          "int", "%d", "ENONET",
+          "int", "%d", "ENOPKG",
+          "int", "%d", "EREMOTE",
+          "int", "%d", "ENOLINK",
+          "int", "%d", "EADV",
+          "int", "%d", "ESRMNT",
+          "int", "%d", "ECOMM",
+          "int", "%d", "EPROTO",
+          "int", "%d", "EMULTIHOP",
+          "int", "%d", "EDOTDOT",
+          "int", "%d", "EBADMSG",
+          "int", "%d", "EOVERFLOW",
+          "int", "%d", "ENOTUNIQ",
+          "int", "%d", "EBADFD",
+          "int", "%d", "EREMCHG",
+          "int", "%d", "ELIBACC",
+          "int", "%d", "ELIBBAD",
+          "int", "%d", "ELIBSCN",
+          "int", "%d", "ELIBMAX",
+          "int", "%d", "ELIBEXEC",
+          "int", "%d", "EILSEQ",
+          "int", "%d", "ERESTART",
+          "int", "%d", "ESTRPIPE",
+          "int", "%d", "EUSERS",
+          "int", "%d", "ENOTSOCK",
+          "int", "%d", "EDESTADDRREQ",
+          "int", "%d", "EMSGSIZE",
+          "int", "%d", "EPROTOTYPE",
+          "int", "%d", "ENOPROTOOPT",
+          "int", "%d", "EPROTONOSUPPORT",
+          "int", "%d", "ESOCKTNOSUPPORT",
+          "int", "%d", "EOPNOTSUPP",
+          "int", "%d", "EPFNOSUPPORT",
+          "int", "%d", "EAFNOSUPPORT",
+          "int", "%d", "EADDRINUSE",
+          "int", "%d", "EADDRNOTAVAIL",
+          "int", "%d", "ENETDOWN",
+          "int", "%d", "ENETUNREACH",
+          "int", "%d", "ENETRESET",
+          "int", "%d", "ECONNABORTED",
+          "int", "%d", "ECONNRESET",
+          "int", "%d", "ENOBUFS",
+          "int", "%d", "EISCONN",
+          "int", "%d", "ENOTCONN",
+          "int", "%d", "ESHUTDOWN",
+          "int", "%d", "ETOOMANYREFS",
+          "int", "%d", "ETIMEDOUT",
+          "int", "%d", "ECONNREFUSED",
+          "int", "%d", "EHOSTDOWN",
+          "int", "%d", "EHOSTUNREACH",
+          "int", "%d", "EALREADY",
+          "int", "%d", "EINPROGRESS",
+          "int", "%d", "ESTALE",
+          "int", "%d", "EUCLEAN",
+          "int", "%d", "ENOTNAM",
+          "int", "%d", "ENAVAIL",
+          "int", "%d", "EISNAM",
+          "int", "%d", "EREMOTEIO",
+          "int", "%d", "EDQUOT",
+          "int", "%d", "ENOMEDIUM",
+          "int", "%d", "EMEDIUMTYPE",
+          );
+
+sub init {
+
+    $csmode = 0;
+
+    GetOptions ("csharp" => \$csmode) or die "cant parse options";
+
+    $CC = $env{"CC"};
+
+    if (!$CC) {
+       $CC = "gcc";
+    }
+
+
+    %tmap = ("void" => "void",
+            "IntPtr" => "int",
+            "sbyte" => "gint8",
+            "byte" => "guint8",
+            "short" => "gint16",
+            "ushort" => "guint16",
+            "int" => "gint32",
+            "uint" => "guint32",
+            "long" => "gint64",
+            "ulong" => "guint64",
+            "string" => "const char *",
+            );
+}
+
+sub t {
+    my ($name) = @_;
+    my ($rname) = $name;
+
+    if ($name =~ m/(.*)\*\s*$/) {
+       $rname = $1;
+       $rname =~ s/\s+$//; # remove trailing spaces
+       $rval = $tmap{$rname} || die "unable to map type \"$name\"";
+       return "$rval*";
+    }
+
+    $rval = $tmap{$name} || die "unable to map type \"$name\"";
+
+}
+
+sub create_func {
+    my (@func) = @_;
+    my ($i) = 0;
+    my ($res) = "";
+
+    if ($func[1] eq "") {
+       $func[1] = "mono_wrapper_$func[2]";
+    }
+
+    if ($csmode) {
+
+       $res = "\t[DllImport(\"$func[0]\", EntryPoint=\"$func[1]\", CharSet=CharSet.Ansi)]\n";
+       $res .= "\tpublic unsafe static extern $func[3] $func[2] (";
+       $i +=4;
+       while ($i <= $#func) {
+           if ($i>4) {
+               $res .= ", ";
+           }
+           $res .= "$func[$i] $func[$i+1]";
+           
+           $i+=2;
+       }
+       $res .= ");\n\n";
+
+       $res_func .= $res;
+
+    } else  {
+       
+       $res = t($func[3]) . "\n$func[1] (";
+       
+       $i +=4;
+       while ($i <= $#func) {
+           if ($i>4) {
+               $res .= ", ";
+           }
+           $res .= t($func[$i]) . " $func[$i+1]";
+           
+           $i+=2;
+       }
+       $res .= ");\n\n";
+
+       $res_func .= $res;
+    }
+}
+
+sub create_struct {
+    my (@str) = @_;
+    my ($i) = 0;
+    my ($res) = "";
+
+    if ($csmode) {
+       $res = "public struct $str[1] {\n";
+       $i +=2;
+       while ($i <= $#str) {
+           $res .= "\tpublic $str[$i] $str[$i+1];\n";
+           $i+=2;
+       }
+       $res .= "};\n\n";
+    } else {
+       $res = "typedef struct {\n";
+       $i += 2;
+       while ($i <= $#str) {
+           $res .= "\t" . t($str[$i]) . " $str[$i+1];\n";
+           $i+=2;
+       }
+       $res .= "} $str[0];\n\n";
+    }
+
+    $tmap{"$str[1]"} = "$str[0]";
+
+    $res_struct .= $res;
+}
+
+sub map_const {
+    my (@co) = @_;
+    my ($res) = "";
+    my ($l);
+    my ($space);
+
+    if (!$csmode) {
+       return;
+    }
+
+    my ($tfn) = "/tmp/etypes$$.c";
+
+    open (TFN, ">$tfn") || die (0);
+
+    for ($i = 0; $i <= $#includes; $i++) {
+       print TFN "#include \"$includes[$i]\"\n";
+    }
+    
+    print TFN "\nint main () {\n"; 
+    for ($i = 0; $i <= $#co; $i+=3) {
+
+       $l = 20 - length($co[$i+2]);
+
+       $space = "";
+       for (my ($j) = 0; $j < $l; $j++) {
+           $space = $space . " ";
+       }
+
+       print TFN "printf (\"\\tpublic const %s %s $space= $co[$i+1];\\n\",".
+           " \"$co[$i]\", \"$co[$i+2]\", $co[$i+2]);\n";
+
+    }
+    print TFN "exit (-1);\n";
+    print TFN "}\n";
+
+    close (TFN);
+
+    system ("$CC $cflags $tfn") == 0
+       or die "calling c compiler failed";
+
+    system ("rm $tfn");
+
+    $res = `./a.out`;
+
+    if (!$res) {
+       die "calling a.out failde";
+    }
+
+    $res_const = $res_const . $res;
+
+    system ("rm ./a.out");     
+}
+
+sub etypes_end {
+
+    @ae = split (/\./, $__class);
+
+    print $res_struct;
+
+    print "public class $ae[$#ae] {\n\n";
+
+    if ($res_const) {
+       print "$res_const\n\n";
+    }
+
+    print "$res_func";
+
+    printf "} // class $ae[$#ae]\n\n";
+
+    for ($i = $#ae - 1; $i >= 0; $i--) {
+       print "} // namescape $ae[$i]\n";
+    }
+
+}
+
+print "/*\n * Generated automatically: do not edit this file.\n */\n\n";
+
+
+if ($csmode) {
+
+    print "using System;\n";
+    print "using System.Runtime.InteropServices;\n\n";
+
+    print "namespace Unix {\n\n";
+
+    print $res_struct;
+
+    print "public class Wrapper {\n\n";
+
+    if ($res_const) {
+       print "$res_const\n\n";
+    }
+
+    print "$res_func";
+
+    print "}\n";
+
+    print "}\n";
+    
+
+} else {
+
+    print "#ifndef _MONO_WRAPPER_H_\n#define _MONO_WRAPPER_H_ 1\n\n";
+
+    for ($i = 0; $i <= $#includes; $i++) {
+       print "#include <$includes[$i]>\n";
+    }
+
+    print "\n";
+
+    print $res_struct;
+
+    print $res_func;
+
+    print "#endif\n";
+}
diff --git a/mono/wrapper/wrapper.c b/mono/wrapper/wrapper.c
new file mode 100644 (file)
index 0000000..56364ac
--- /dev/null
@@ -0,0 +1,68 @@
+#include <config.h>
+#include <limits.h>
+
+#include "wrapper.h"
+
+gint64
+mono_wrapper_seek (int fd, gint64 offset, gint32 whence)
+{
+       if (offset > INT_MAX || offset < INT_MIN)
+               return -1;
+
+       return lseek (fd, offset, whence);
+}
+
+gint32
+mono_wrapper_read (int fd, void* buf, gint32 count)
+{
+       return read (fd, buf, count);
+}
+
+gint32
+mono_wrapper_write (int fd, void* buf, gint32 count)
+{
+       return write (fd, buf, count);
+}
+
+gint32
+mono_wrapper_fstat (int fd, MonoWrapperStat* buf)
+{
+       struct stat fs;
+
+       if (fstat (fd, &fs) != 0)
+               return -1;
+
+       buf->st_dev = fs.st_dev;
+       buf->st_mode = fs.st_mode;
+       buf->st_nlink = fs.st_nlink;
+       buf->st_uid = fs.st_uid;
+       buf->st_gid = fs.st_gid;
+       buf->st_size = fs.st_size;
+       buf->st_atime = fs.st_atime;
+       buf->st_mtime = fs.st_ctime;
+       buf->st_ctime = fs.st_ctime;
+
+       return 0;
+}
+
+gint32
+mono_wrapper_ftruncate (int fd, gint64 length) 
+{
+       if (length > INT_MAX || length < INT_MIN)
+               return -1;
+
+       return ftruncate (fd, length);
+}
+
+int
+mono_wrapper_open (const char * path, gint32 flags, gint32 mode)
+{
+       return open (path, flags, mode);
+}
+
+gint32
+mono_wrapper_close (int fd)
+{
+       return close (fd);
+}
+