Mon Nov 12 12:41:32 CET 2001 Paolo Molaro <lupus@ximian.com>
authorPaolo Molaro <lupus@oddwiz.org>
Mon, 12 Nov 2001 08:05:52 +0000 (08:05 -0000)
committerPaolo Molaro <lupus@oddwiz.org>
Mon, 12 Nov 2001 08:05:52 +0000 (08:05 -0000)
* decimal.c, decimal.h: mono_double2decimal() get the sign bit from
the value.
* icall.c: use mono_array_addr instead of array->vector: fixes the
reflection image writing.
* reflection.c: init call convention byte to 0 in method signature.
Encode the property signature. Don't output property-related methods
twice. Really process the properties for a type (don't cast a field to
a property, my mom always told me that).
Fix 64 bit issues in pointer alignment in a different and more
readable way.

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

mono/metadata/ChangeLog
mono/metadata/decimal.c
mono/metadata/decimal.h
mono/metadata/icall.c
mono/metadata/reflection.c
mono/tests/codegen2.cs

index c340b7f23f1b6e07c3b89b8937aec5b6377c481b..ebacd3c8a10a61d22e36cbb7f112221a169b5a81 100644 (file)
@@ -1,3 +1,17 @@
+
+Mon Nov 12 12:41:32 CET 2001 Paolo Molaro <lupus@ximian.com>
+
+       * decimal.c, decimal.h: mono_double2decimal() get the sign bit from
+       the value.
+       * icall.c: use mono_array_addr instead of array->vector: fixes the
+       reflection image writing.
+       * reflection.c: init call convention byte to 0 in method signature.
+       Encode the property signature. Don't output property-related methods
+       twice. Really process the properties for a type (don't cast a field to
+       a property, my mom always told me that).
+       Fix 64 bit issues in pointer alignment in a different and more
+       readable way.
+
 2001-11-10  Sean MacIsaac  <macisaac@ximian.com>
 
        * loader.h: Removed type class from MonoDefaults, added monotype
index bf6a9ba9569e40deb59eebd40cab9456d6c5f90e..55bf5d7f5e9866d111664653e33ab478e6de68a0 100644 (file)
@@ -834,13 +834,14 @@ static int incMultConstant128(guint64* palo, guint64* pahi, int index, int facto
     return DECIMAL_SUCCESS;
 }
 
-gint32 mono_double2decimal(/*[Out]*/decimal_repr* pA, double val, gint32 digits, gint32 sign)
+gint32 mono_double2decimal(/*[Out]*/decimal_repr* pA, double val, gint32 digits)
 {
     int i, dec, decrDecimal, dummySign, roundPos, roundFlag, rc;
     char ecvtcopy[40]; /* we should need maximal room for 16 digits */
     char buf[40]; /* we should need maximal room for 29 digits */
     char* p;
     char* ps;
+    gint32 sign = val < 0 ? 1 : 0;
     decimal_repr roundAdd;
     MonoString *mstring;
 
index f93a6182b680a642d197c0c854e92c21de82a7b5..e3bda72d81265d4a723cca8145b2960f5f8fb979 100644 (file)
@@ -21,7 +21,7 @@ typedef struct
 
 /* function prototypes */
 gint32 mono_decimalIncr(/*[In, Out]*/decimal_repr* pA, /*[In]*/decimal_repr* pB);
-gint32 mono_double2decimal(/*[Out]*/decimal_repr* pA, double val, gint32 digits, gint32 sign);
+gint32 mono_double2decimal(/*[Out]*/decimal_repr* pA, double val, gint32 digits);
 gint32 mono_string2decimal(/*[Out]*/decimal_repr* pA, MonoString* str, gint32 decrDecimal, gint32 sign);
 void mono_decimal2string(/*[In]*/decimal_repr* pA, int digits, int decimals,
                                                                 MonoArray* buf, gint32 bufSize, gint32* pDecPos, gint32* pSign);
index 9dab5a70a369b675b3fec05651979a33e1c3c27d..ff91d19d16cd623d9c6f2b86f61c281b1cd7bbcd 100644 (file)
@@ -163,11 +163,12 @@ ves_icall_get_data_chunk (MonoReflectionAssemblyBuilder *assb, gint32 type, Mono
                        return count;
        } else {
                MonoDynamicAssembly *ass = assb->dynamic_assembly;
+               char *p = mono_array_addr (buf, char, 0);
                count = ass->code.index + ass->meta_size;
                if (count > buf->bounds->length)
                        return 0;
-               memcpy (buf->vector, ass->code.data, ass->code.index);
-               memcpy (buf->vector + ass->code.index, ass->assembly.image->raw_metadata, ass->meta_size);
+               memcpy (p, ass->code.data, ass->code.index);
+               memcpy (p + ass->code.index, ass->assembly.image->raw_metadata, ass->meta_size);
                return count;
        }
        
index 8f2e9d2bf6bacdc596fba2296e6b916c45624619..f05c4c005b430c5e572b63245fa17583a9c1f5a1 100644 (file)
@@ -194,6 +194,7 @@ method_encode_signature (MonoDynamicAssembly *assembly, MonoReflectionMethodBuil
        char *b = blob_size;
        
        p = buf = g_malloc (size);
+       *p = 0;
        if (!(mb->attrs & METHOD_ATTRIBUTE_STATIC))
                *p |= 0x20; /* hasthis */
        /* 
@@ -376,10 +377,34 @@ mono_image_get_field_info (MonoReflectionFieldBuilder *fb, MonoDynamicAssembly *
 static guint32
 property_encode_signature (MonoDynamicAssembly *assembly, MonoReflectionPropertyBuilder *fb)
 {
-       /* 
-        * FIXME: fill me in 
-        */
-       return 0;
+       char *buf, *p;
+       char blob_size [6];
+       char *b = blob_size;
+       guint32 nparams = 0;
+       MonoReflectionMethodBuilder *mb = fb->get_method;
+       guint32 idx, i;
+
+       if (mb && mb->parameters)
+               nparams = mono_array_length (mb->parameters);
+       buf = p = g_malloc (24 + nparams * 10);
+       *p = 0x08;
+       p++;
+       mono_metadata_encode_value (nparams, p, &p);
+       if (mb) {
+               encode_type (mb->rtype->type, p, &p);
+               for (i = 0; i < nparams; ++i) {
+                       MonoReflectionType *pt = mono_array_get (mb->parameters, MonoReflectionType*, i);
+                       encode_type (pt->type, p, &p);
+               }
+       } else {
+               *p++ = 1; /* void: a property should probably not be allowed without a getter */
+       }
+       /* store length */
+       mono_metadata_encode_value (p-buf, b, &b);
+       idx = mono_image_add_stream_data (&assembly->blob, blob_size, b-blob_size);
+       mono_image_add_stream_data (&assembly->blob, buf, p-buf);
+       g_free (buf);
+       return idx;
 }
 
 static void
@@ -395,7 +420,7 @@ mono_image_get_property_info (MonoReflectionPropertyBuilder *pb, MonoDynamicAsse
         * we need to set things in the following tables:
         * PROPERTYMAP (info already filled in _get_type_info ())
         * PROPERTY    (rows already preallocated in _get_type_info ())
-        * METHOD
+        * METHOD      (method info already done with the generic method code)
         * METHODSEMANTICS
         */
        table = &assembly->tables [MONO_TABLE_PROPERTY];
@@ -407,29 +432,24 @@ mono_image_get_property_info (MonoReflectionPropertyBuilder *pb, MonoDynamicAsse
        values [MONO_PROPERTY_FLAGS] = pb->attrs;
        values [MONO_PROPERTY_TYPE] = property_encode_signature (assembly, pb);
 
-       /* alloc room for the methods (we still don't handle 'other' methods) */
+       /* FIXME: we still don't handle 'other' methods */
        if (pb->get_method) num_methods ++;
        if (pb->set_method) num_methods ++;
-       table = &assembly->tables [MONO_TABLE_METHOD];
-       table->rows += num_methods;
-       alloc_table (table, table->rows);
 
        table = &assembly->tables [MONO_TABLE_METHODSEMANTICS];
        table->rows += num_methods;
        alloc_table (table, table->rows);
 
        if (pb->get_method) {
-               mono_image_get_method_info (pb->get_method, assembly);
                semaidx = table->next_idx ++;
-               values = table->values + semaidx *      MONO_METHOD_SEMA_SIZE;
+               values = table->values + semaidx * MONO_METHOD_SEMA_SIZE;
                values [MONO_METHOD_SEMA_SEMANTICS] = METHOD_SEMANTIC_GETTER;
                values [MONO_METHOD_SEMA_METHOD] = pb->get_method->table_idx;
                values [MONO_METHOD_SEMA_ASSOCIATION] = (pb->table_idx << 1) | 1;
        }
        if (pb->set_method) {
-               mono_image_get_method_info (pb->set_method, assembly);
                semaidx = table->next_idx ++;
-               values = table->values + semaidx *      MONO_METHOD_SEMA_SIZE;
+               values = table->values + semaidx * MONO_METHOD_SEMA_SIZE;
                values [MONO_METHOD_SEMA_SEMANTICS] = METHOD_SEMANTIC_SETTER;
                values [MONO_METHOD_SEMA_METHOD] = pb->set_method->table_idx;
                values [MONO_METHOD_SEMA_ASSOCIATION] = (pb->table_idx << 1) | 0;
@@ -515,12 +535,12 @@ mono_image_get_type_info (MonoReflectionTypeBuilder *tb, MonoDynamicAssembly *as
                table = &assembly->tables [MONO_TABLE_PROPERTYMAP];
                table->rows ++;
                alloc_table (table, table->rows);
-               values = table->values + (table->rows - 1) * MONO_PROPERTY_MAP_SIZE;
+               values = table->values + table->rows * MONO_PROPERTY_MAP_SIZE;
                values [MONO_PROPERTY_MAP_PARENT] = tb->table_idx;
-               values [MONO_PROPERTY_MAP_PROPERTY_LIST] = assembly->tables [MONO_TABLE_PROPERTY].next_idx ++;
+               values [MONO_PROPERTY_MAP_PROPERTY_LIST] = assembly->tables [MONO_TABLE_PROPERTY].next_idx;
                for (i = 0; i < mono_array_length (tb->properties); ++i)
                        mono_image_get_property_info (
-                               mono_array_get (tb->fields, MonoReflectionPropertyBuilder*, i), assembly);
+                               mono_array_get (tb->properties, MonoReflectionPropertyBuilder*, i), assembly);
        }
 }
 
@@ -548,6 +568,13 @@ mono_image_fill_module_table (MonoReflectionModuleBuilder *mb, MonoDynamicAssemb
                mono_image_get_type_info (mono_array_get (mb->types, MonoReflectionTypeBuilder*, i), assembly);
 }
 
+#define align_pointer(base,p)\
+       do {\
+               guint32 __diff = (unsigned char*)(p)-(unsigned char*)(base);\
+               if (__diff & 3)\
+                       (p) += 4 - (__diff & 3);\
+       } while (0)
+
 static void
 build_compressed_metadata (MonoDynamicAssembly *assembly)
 {
@@ -562,7 +589,6 @@ build_compressed_metadata (MonoDynamicAssembly *assembly)
        guint16 *int16val;
        MonoImage *meta;
        unsigned char *p;
-       int idx;
        char *version = "mono" VERSION;
        
        /* Compute table sizes */
@@ -596,73 +622,73 @@ build_compressed_metadata (MonoDynamicAssembly *assembly)
        meta->raw_metadata = g_malloc0 (meta_size);
        p = meta->raw_metadata;
        /* the metadata signature */
-       idx = 0;
-       p [idx++] = 'B'; p [idx++] = 'S'; p [idx++] = 'J'; p [idx++] = 'B';
-
+       *p++ = 'B'; *p++ = 'S'; *p++ = 'J'; *p++ = 'B';
        /* version numbers and 4 bytes reserved */
-       int16val = (guint16*) (&p [idx]);
+       int16val = (guint16*)p;
        *int16val++ = 1;
        *int16val = 1;
-       idx += 8;
+       p += 8;
        /* version string */
-       int32val = (guint32*)(&p [idx]);
+       int32val = (guint32*)p;
        *int32val = strlen (version);
-       idx += 4;
-       memcpy (&p [i], version, *int32val);
-       idx += *int32val;
-       idx += 3; idx = idx & ~3; /* align */
-       int16val = (guint16*)(&p [idx]);
+       p += 4;
+       memcpy (p, version, *int32val);
+       p += *int32val;
+       align_pointer (meta->raw_metadata, p);
+       int16val = (guint16*)p;
        *int16val++ = 0; /* flags must be 0 */
        *int16val = 5; /* number of streams */
-       idx += 4;
+       p += 4;
 
        /*
         * write the stream info.
         */
        table_offset = (p - (unsigned char*)meta->raw_metadata) + 5 * 8 + 40; /* room needed for stream headers */
        
-       int32val = (guint32*)(&p [idx]);
+       int32val = (guint32*)p;
        *int32val++ = assembly->tstream.offset = table_offset;
        *int32val = heapt_size;
        table_offset += *int32val;
-       idx += 8;
-       strcpy (&p [idx], "#~");
-       /* 
-        * FIXME: alignment not 64 bit safe: same problem in metadata/image.c 
-        */
-       idx += 3 + 3; idx = idx & ~3;
+       p += 8;
+       strcpy (p, "#~");
+       p += 3;
+       align_pointer (meta->raw_metadata, p);
 
-       int32val = (guint32*)(&p [idx]);
+       int32val = (guint32*)p;
        *int32val++ = assembly->sheap.offset = table_offset;
        *int32val = assembly->sheap.index;
        table_offset += *int32val;
-       idx += 8;
-       strcpy (&p [idx], "#Strings");
-       idx += 9 + 3; idx = idx & ~3;
+       p += 8;
+       strcpy (p, "#Strings");
+       p += 9;
+       align_pointer (meta->raw_metadata, p);
 
-       int32val = (guint32*)(&p [idx]);
+       int32val = (guint32*)p;
        *int32val++ = assembly->us.offset = table_offset;
        *int32val = assembly->us.index;
        table_offset += *int32val;
-       idx += 8;
-       strcpy (&p [idx], "#US");
-       idx += 4 + 3; idx = idx & ~3;
+       p += 8;
+       strcpy (p, "#US");
+       p += 4;
+       align_pointer (meta->raw_metadata, p);
 
-       int32val = (guint32*)(&p [idx]);
+       int32val = (guint32*)p;
        *int32val++ = assembly->blob.offset = table_offset;
        *int32val = assembly->blob.index;
        table_offset += *int32val;
-       idx += 8;
-       strcpy (&p [idx], "#Blob");
-       idx += 6 + 3; idx = idx & ~3;
+       p += 8;
+       strcpy (p, "#Blob");
+       p += 6;
+       align_pointer (meta->raw_metadata, p);
 
-       int32val = (guint32*)(&p [idx]);
+       int32val = (guint32*)p;
        *int32val++ = assembly->guid.offset = table_offset;
        *int32val = assembly->guid.index;
        table_offset += *int32val;
-       idx += 8;
-       strcpy (&p [idx], "#GUID");
-       idx += 6 + 3; idx = idx & ~3;
+       p += 8;
+       strcpy (p, "#GUID");
+       p += 6;
+       align_pointer (meta->raw_metadata, p);
 
        /* 
         * now copy the data, the table stream header and contents goes first.
index 5e4e98151560925eaf39f07a231c9eb1cc7f6c94..0b4b42c0bac0cb5d45b22518172fa68fb9043e58 100644 (file)
@@ -46,12 +46,12 @@ class CGen {
                
 
                fbuilder = tbuilder.DefineField ("int_field", typeof(int), FieldAttributes.Private);
-               /*pbuilder = tbuilder.DefineProperty ("FieldI", PropertyAttributes.None, typeof(int), null);
+               pbuilder = tbuilder.DefineProperty ("FieldI", PropertyAttributes.None, typeof(int), null);
                get_method = tbuilder.DefineMethod("get_FieldI", MethodAttributes.Public, result, null);
                ilg = get_method.GetILGenerator (128);
                ilg.Emit (OpCodes.Ldloc_0);
                ilg.Emit (OpCodes.Ret);
-               pbuilder.SetGetMethod (get_method);*/
+               pbuilder.SetGetMethod (get_method);
 
                Type t = tbuilder.CreateType ();
                abuilder.SetEntryPoint (entryp);