Author: lupus
Date: 2005-09-23 11:57:11 -0400 (Fri, 23 Sep 2005)
New Revision: 50587

Modified:
   trunk/mono/mono/metadata/ChangeLog
   trunk/mono/mono/metadata/loader.h
   trunk/mono/mono/metadata/metadata.c
   trunk/mono/mono/metadata/metadata.h
Log:


Fri Sep 23 17:56:21 CEST 2005 Paolo Molaro <[EMAIL PROTECTED]>

        * metadata.c, metadata.h, loader.h: documentation updates, code and
        API cleanups.



Modified: trunk/mono/mono/metadata/ChangeLog
===================================================================
--- trunk/mono/mono/metadata/ChangeLog  2005-09-23 15:52:22 UTC (rev 50586)
+++ trunk/mono/mono/metadata/ChangeLog  2005-09-23 15:57:11 UTC (rev 50587)
@@ -1,3 +1,9 @@
+
+Fri Sep 23 17:56:21 CEST 2005 Paolo Molaro <[EMAIL PROTECTED]>
+
+       * metadata.c, metadata.h, loader.h: documentation updates, code and
+       API cleanups.
+
 2005-09-23  Zoltan Varga  <[EMAIL PROTECTED]>
 
        * rawbuffer.h rawbuffer.c: Add code and APIs to help determine the 
number of

Modified: trunk/mono/mono/metadata/loader.h
===================================================================
--- trunk/mono/mono/metadata/loader.h   2005-09-23 15:52:22 UTC (rev 50586)
+++ trunk/mono/mono/metadata/loader.h   2005-09-23 15:57:11 UTC (rev 50587)
@@ -6,8 +6,6 @@
 
 G_BEGIN_DECLS
 
-typedef struct _MonoMethod MonoMethod;
-
 typedef gboolean (*MonoStackWalk)     (MonoMethod *method, gint32 
native_offset, gint32 il_offset, gboolean managed, gpointer data);
 
 MonoMethod *

Modified: trunk/mono/mono/metadata/metadata.c
===================================================================
--- trunk/mono/mono/metadata/metadata.c 2005-09-23 15:52:22 UTC (rev 50586)
+++ trunk/mono/mono/metadata/metadata.c 2005-09-23 15:57:11 UTC (rev 50587)
@@ -456,6 +456,7 @@
  * @result_bitfield return value along with the number of columns in the table.
  * the resulting bitfield should be handed to the mono_metadata_table_size()
  * and mono_metadata_table_count() macros.
+ * This is a Mono runtime internal only function.
  */
 int
 mono_metadata_compute_size (MonoImage *meta, int tableindex, guint32 
*result_bitfield)
@@ -784,14 +785,14 @@
        int i;
        const char *base = meta->tables_base;
        
-       for (i = 0; i < MONO_TABLE_NUM; i++){
-               if (meta->tables [i].rows == 0)
+       for (i = 0; i < MONO_TABLE_NUM; i++) {
+               MonoTableInfo *table = &meta->tables [i];
+               if (table->rows == 0)
                        continue;
 
-               meta->tables [i].row_size = mono_metadata_compute_size (
-                       meta, i, &meta->tables [i].size_bitfield);
-               meta->tables [i].base = base;
-               base += meta->tables [i].rows * meta->tables [i].row_size;
+               table->row_size = mono_metadata_compute_size (meta, i, 
&table->size_bitfield);
+               table->base = base;
+               base += table->rows * table->row_size;
        }
 }
 
@@ -913,7 +914,7 @@
        
        g_assert (res_size == count);
        
-       for (i = 0; i < count; i++){
+       for (i = 0; i < count; i++) {
                int n = mono_metadata_table_size (bitfield, i);
 
                switch (n){
@@ -921,10 +922,8 @@
                        res [i] = *data; break;
                case 2:
                        res [i] = read16 (data); break;
-                       
                case 4:
                        res [i] = read32 (data); break;
-                       
                default:
                        g_assert_not_reached ();
                }
@@ -956,7 +955,7 @@
                data += n;
                n = mono_metadata_table_size (bitfield, i + 1);
        }
-       switch (n){
+       switch (n) {
        case 1:
                return *data;
        case 2:
@@ -1072,8 +1071,7 @@
 mono_metadata_parse_custom_mod (MonoImage *m, MonoCustomMod *dest, const char 
*ptr, const char **rptr)
 {
        MonoCustomMod local;
-       if ((*ptr == MONO_TYPE_CMOD_OPT) ||
-           (*ptr == MONO_TYPE_CMOD_REQD)) {
+       if ((*ptr == MONO_TYPE_CMOD_OPT) || (*ptr == MONO_TYPE_CMOD_REQD)) {
                if (!dest)
                        dest = &local;
                dest->required = *ptr == MONO_TYPE_CMOD_REQD ? 1 : 0;
@@ -1280,7 +1278,8 @@
 /**
  * mono_metadata_init:
  *
- *  Initialize the global variables of this module.
+ * Initialize the global variables of this module.
+ * This is a Mono runtime internal function.
  */
 void
 mono_metadata_init (void)
@@ -1314,6 +1313,7 @@
  * (the `generic_container' field in the MonoMethodNormal) generic container.
  * When we encounter any MONO_TYPE_VAR or MONO_TYPE_MVAR's, they're looked up 
in
  * this MonoGenericContainer.
+ * This is a Mono runtime internal function.
  *
  * Returns: a #MonoType structure representing the decoded type.
  */
@@ -1435,15 +1435,16 @@
 }
 
 /*
- * mono_metadata_parse_signature:
+ * mono_metadata_parse_signature_full:
  * @image: metadata context
+ * @generic_context: generics context
  * @toke: metadata token
  *
  * Decode a method signature stored in the STANDALONESIG table
  *
  * Returns: a MonoMethodSignature describing the signature.
  */
-MonoMethodSignature *
+MonoMethodSignature*
 mono_metadata_parse_signature_full (MonoImage *image, MonoGenericContext 
*generic_context, guint32 token)
 {
        MonoTableInfo *tables = image->tables;
@@ -1464,12 +1465,32 @@
        return mono_metadata_parse_method_signature_full (image, 
generic_context, FALSE, ptr, NULL); 
 }
 
-MonoMethodSignature *
+/*
+ * mono_metadata_parse_signature:
+ * @image: metadata context
+ * @toke: metadata token
+ *
+ * Decode a method signature stored in the STANDALONESIG table
+ *
+ * Returns: a MonoMethodSignature describing the signature.
+ */
+MonoMethodSignature*
 mono_metadata_parse_signature (MonoImage *image, guint32 token)
 {
        return mono_metadata_parse_signature_full (image, NULL, token);
 }
 
+/*
+ * mono_metadata_signature_alloc:
+ * @image: metadata context
+ * @nparmas: number of parameters in the signature
+ *
+ * Allocate a MonoMethodSignature structure with the specified number of 
params.
+ * The return type and the params types need to be filled later.
+ * This is a Mono runtime internal function.
+ *
+ * Returns: the new MonoMethodSignature structure.
+ */
 MonoMethodSignature*
 mono_metadata_signature_alloc (MonoImage *m, guint32 nparams)
 {
@@ -1483,6 +1504,15 @@
        return sig;
 }
 
+/*
+ * mono_metadata_signature_dup:
+ * @sig: method signature
+ *
+ * Duplicate an existing MonoMethodSignature so it can be modified.
+ * This is a Mono runtime internal function.
+ *
+ * Returns: the new MonoMethodSignature structure.
+ */
 MonoMethodSignature*
 mono_metadata_signature_dup (MonoMethodSignature *sig)
 {
@@ -1495,11 +1525,13 @@
 /*
  * mono_metadata_parse_method_signature:
  * @m: metadata context
+ * @generic_context: generics context
  * @def: the MethodDef index or 0 for Ref signatures.
  * @ptr: pointer to the signature metadata representation
  * @rptr: pointer updated to match the end of the decoded stream
  *
  * Decode a method signature stored at @ptr.
+ * This is a Mono runtime internal function.
  *
  * Returns: a MonoMethodSignature describing the signature.
  */
@@ -1571,8 +1603,9 @@
                        container->type_params [i].owner = container;
                        container->type_params [i].num = i;
                }
-       } else
+       } else {
                context = generic_context;
+       }
 
        if (call_convention != 0xa) {
                method->ret = mono_metadata_parse_type_full (m, context, 
MONO_PARSE_RET, ret_attrs, ptr, &ptr);
@@ -1585,7 +1618,7 @@
                for (i = 0; i < method->param_count; ++i) {
                        if (*ptr == MONO_TYPE_SENTINEL) {
                                if (method->call_convention != MONO_CALL_VARARG 
|| def)
-                                               g_error ("found sentinel for 
methoddef or no vararg method");
+                                       g_error ("found sentinel for methoddef 
or no vararg method");
                                method->sentinelpos = i;
                                ptr++;
                        }
@@ -1611,6 +1644,18 @@
        return method;
 }
 
+/*
+ * mono_metadata_parse_method_signature:
+ * @m: metadata context
+ * @def: the MethodDef index or 0 for Ref signatures.
+ * @ptr: pointer to the signature metadata representation
+ * @rptr: pointer updated to match the end of the decoded stream
+ *
+ * Decode a method signature stored at @ptr.
+ * This is a Mono runtime internal function.
+ *
+ * Returns: a MonoMethodSignature describing the signature.
+ */
 MonoMethodSignature *
 mono_metadata_parse_method_signature (MonoImage *m, int def, const char *ptr, 
const char **rptr)
 {
@@ -1839,7 +1884,11 @@
 /* 
  * do_mono_metadata_parse_type:
  * @type: MonoType to be filled in with the return value
- * @
+ * @m: image context
+ * @generic_context: generics_context
+ * @ptr: pointer to the encoded type
+ * @rptr: pointer where the end of the encoded type is saved
+ * 
  * Internal routine used to "fill" the contents of @type from an 
  * allocated pointer.  This is done this way to avoid doing too
  * many mini-allocations (particularly for the MonoFieldType which
@@ -1898,19 +1947,15 @@
        case MONO_TYPE_ARRAY:
                type->data.array = mono_metadata_parse_array_full (m, 
generic_context, ptr, &ptr);
                break;
-
        case MONO_TYPE_MVAR:
                type->data.generic_param = mono_metadata_parse_generic_param 
(m, generic_context, TRUE, ptr, &ptr);
                break;
-
        case MONO_TYPE_VAR:
                type->data.generic_param = mono_metadata_parse_generic_param 
(m, generic_context, FALSE, ptr, &ptr);
                break;
-
        case MONO_TYPE_GENERICINST:
                do_mono_metadata_parse_generic_class (type, m, generic_context, 
ptr, &ptr);
                break;
-               
        default:
                g_error ("type 0x%02x not handled in 
do_mono_metadata_parse_type", type->type);
        }
@@ -2024,30 +2069,20 @@
                                guint32 tof_value;
                                if (is_fat) {
                                        ec->flags = read32 (p);
-                                       p += 4;
-                                       ec->try_offset = read32 (p);
-                                       p += 4;
-                                       ec->try_len = read32 (p);
-                                       p += 4;
-                                       ec->handler_offset = read32 (p);
-                                       p += 4;
-                                       ec->handler_len = read32 (p);
-                                       p += 4;
-                                       tof_value = read32 (p);
-                                       p += 4;
+                                       ec->try_offset = read32 (p + 4);
+                                       ec->try_len = read32 (p + 8);
+                                       ec->handler_offset = read32 (p + 12);
+                                       ec->handler_len = read32 (p + 16);
+                                       tof_value = read32 (p + 20);
+                                       p += 24;
                                } else {
                                        ec->flags = read16 (p);
-                                       p += 2;
-                                       ec->try_offset = read16 (p);
-                                       p += 2;
-                                       ec->try_len = *p;
-                                       ++p;
-                                       ec->handler_offset = read16 (p);
-                                       p += 2;
-                                       ec->handler_len = *p;
-                                       ++p;
-                                       tof_value = read32 (p);
-                                       p += 4;
+                                       ec->try_offset = read16 (p + 2);
+                                       ec->try_len = *(p + 4);
+                                       ec->handler_offset = read16 (p + 5);
+                                       ec->handler_len = *(p + 7);
+                                       tof_value = read32 (p + 8);
+                                       p += 12;
                                }
                                if (ec->flags == MONO_EXCEPTION_CLAUSE_FILTER) {
                                        ec->data.filter_offset = tof_value;
@@ -2068,12 +2103,14 @@
 }
 
 /*
- * mono_metadata_parse_mh:
+ * mono_metadata_parse_mh_full:
  * @m: metadata context
+ * @generic_context: generics context
  * @ptr: pointer to the method header.
  *
  * Decode the method header at @ptr, including pointer to the IL code,
  * info about local variables and optional exception tables.
+ * This is a Mono runtime internal function.
  *
  * Returns: a MonoMethodHeader.
  */
@@ -2090,7 +2127,7 @@
        
        g_return_val_if_fail (ptr != NULL, NULL);
 
-       switch (format){
+       switch (format) {
        case METHOD_HEADER_TINY_FORMAT:
                mh = g_new0 (MonoMethodHeader, 1);
                ptr++;
@@ -2137,9 +2174,7 @@
                 * There are more sections
                 */
                ptr = code + code_size;
-               
                break;
-               
        default:
                return NULL;
        }
@@ -2174,6 +2209,17 @@
        return mh;
 }
 
+/*
+ * mono_metadata_parse_mh:
+ * @generic_context: generics context
+ * @ptr: pointer to the method header.
+ *
+ * Decode the method header at @ptr, including pointer to the IL code,
+ * info about local variables and optional exception tables.
+ * This is a Mono runtime internal function.
+ *
+ * Returns: a MonoMethodHeader.
+ */
 MonoMethodHeader *
 mono_metadata_parse_mh (MonoImage *m, const char *ptr)
 {
@@ -2185,6 +2231,7 @@
  * @mh: a method header
  *
  * Free the memory allocated for the method header.
+ * This is a Mono runtime internal function.
  */
 void
 mono_metadata_free_mh (MonoMethodHeader *mh)
@@ -2196,6 +2243,103 @@
        g_free (mh);
 }
 
+/*
+ * mono_method_header_get_code:
+ * @header: a MonoMethodHeader pointer
+ * @code_size: memory location for returning the code size
+ * @max_stack: memory location for returning the max stack
+ *
+ * Method header accessor to retreive info about the IL code properties:
+ * a pointer to the IL code itself, the size of the code and the max number
+ * of stack slots used by the code.
+ *
+ * Returns: pointer to the IL code represented by the method header.
+ */
+const unsigned char*
+mono_method_header_get_code (MonoMethodHeader *header, guint32* code_size, 
guint32* max_stack)
+{
+       if (code_size)
+               *code_size = header->code_size;
+       if (max_stack)
+               *max_stack = header->max_stack;
+       return header->code;
+}
+
+/*
+ * mono_method_header_get_locals:
+ * @header: a MonoMethodHeader pointer
+ * @num_locals: memory location for returning the number of local variables
+ * @init_locals: memory location for returning the init_locals flag
+ *
+ * Method header accessor to retreive info about the local variables:
+ * an array of local types, the number of locals and whether the locals
+ * are supposed to be initialized to 0 on method entry
+ *
+ * Returns: pointer to an array of types of the local variables
+ */
+MonoType**
+mono_method_header_get_locals (MonoMethodHeader *header, guint32* num_locals, 
gboolean *init_locals)
+{
+       if (num_locals)
+               *num_locals = header->num_locals;
+       if (init_locals)
+               *init_locals = header->init_locals;
+       return header->locals;
+}
+
+/*
+ * mono_method_header_get_num_clauses:
+ * @header: a MonoMethodHeader pointer
+ *
+ * Method header accessor to retreive the number of exception clauses.
+ *
+ * Returns: the number of exception clauses present
+ */
+int
+mono_method_header_get_num_clauses (MonoMethodHeader *header)
+{
+       return header->num_clauses;
+}
+
+/*
+ * mono_method_header_get_clauses:
+ * @header: a MonoMethodHeader pointer
+ * @method: MonoMethod the header belongs to
+ * @iter: pointer to a iterator
+ * @clause: pointer to a MonoExceptionClause structure which will be filled 
with the info
+ *
+ * Get the info about the exception clauses in the method. Set *iter to NULL to
+ * initiate the iteration, then call the method repeatedly until it returns 
FALSE.
+ * At each iteration, the structure pointed to by clause if filled with the
+ * exception clause information.
+ *
+ * Returns: TRUE if clause was filled with info, FALSE if there are no more 
exception
+ * clauses.
+ */
+int
+mono_method_header_get_clauses (MonoMethodHeader *header, MonoMethod *method, 
gpointer *iter, MonoExceptionClause *clause)
+{
+       MonoExceptionClause *sc;
+       /* later we'll be able to use this interface to parse the clause info 
on demand,
+        * without allocating anything.
+        */
+       if (!iter || !header->num_clauses)
+               return FALSE;
+       if (!*iter) {
+               *iter = sc = header->clauses;
+               *clause = *sc;
+               return TRUE;
+       }
+       sc = *iter;
+       sc++;
+       if (sc < header->clauses + header->num_clauses) {
+               *iter = sc;
+               *clause = *sc;
+               return TRUE;
+       }
+       return FALSE;
+}
+
 /**
  * mono_metadata_parse_field_type:
  * @m: metadata context to extract information from
@@ -2249,13 +2393,10 @@
        switch (table){
        case 0: /* TypeDef */
                return MONO_TOKEN_TYPE_DEF | idx;
-
        case 1: /* TypeRef */
                return MONO_TOKEN_TYPE_REF | idx;
-
        case 2: /* TypeSpec */
                return MONO_TOKEN_TYPE_SPEC | idx;
-
        default:
                g_assert_not_reached ();
        }
@@ -2495,7 +2636,7 @@
        MonoClass **interfaces;
        gboolean rv;
 
-    rv = mono_metadata_interfaces_from_typedef_full (meta, index, &interfaces, 
count, NULL);
+       rv = mono_metadata_interfaces_from_typedef_full (meta, index, 
&interfaces, count, NULL);
        if (rv)
                return interfaces;
        else
@@ -2783,6 +2924,7 @@
        }
        case MONO_TYPE_VAR:
        case MONO_TYPE_MVAR:
+               /* FIXME: Martin, this is wrong. */
                *align = __alignof__(gpointer);
                return sizeof (gpointer);
        default:
@@ -3013,8 +3155,7 @@
 static gboolean
 do_mono_metadata_type_equal (MonoType *t1, MonoType *t2, gboolean 
signature_only)
 {
-       if (t1->type != t2->type ||
-           t1->byref != t2->byref)
+       if (t1->type != t2->type || t1->byref != t2->byref)
                return FALSE;
 
        switch (t1->type) {
@@ -3084,8 +3225,7 @@
 {
        int i;
 
-       if (sig1->hasthis != sig2->hasthis ||
-           sig1->param_count != sig2->param_count)
+       if (sig1->hasthis != sig2->hasthis || sig1->param_count != 
sig2->param_count)
                return FALSE;
 
        /*
@@ -3727,9 +3867,7 @@
                                        *conv = MONO_MARSHAL_CONV_DEL_FTN;
                                        return MONO_NATIVE_FUNC;
                                }
-                               else
-                                       /* Fall through */
-                                       ;
+                               /* Fall through */
                        default:
                                g_error ("cant marshal object as native type 
%02x", mspec->native);
                        }

Modified: trunk/mono/mono/metadata/metadata.h
===================================================================
--- trunk/mono/mono/metadata/metadata.h 2005-09-23 15:52:22 UTC (rev 50586)
+++ trunk/mono/mono/metadata/metadata.h 2005-09-23 15:57:11 UTC (rev 50587)
@@ -33,6 +33,7 @@
 
 typedef struct _MonoClass MonoClass;
 typedef struct _MonoDomain MonoDomain;
+typedef struct _MonoMethod MonoMethod;
 
 typedef enum {
        MONO_EXCEPTION_CLAUSE_NONE,
@@ -306,6 +307,9 @@
        int *lobounds;
 };
 
+/* This structure is internal to the runtime: use the mono_type*
+ * accessors below, because it will soon ago away from the public header file.
+ */
 struct _MonoType {
        union {
                MonoClass *klass; /* for VALUETYPE and CLASS */
@@ -323,6 +327,10 @@
        MonoCustomMod modifiers [MONO_ZERO_LEN_ARRAY]; /* this may grow */
 };
 
+/*
+ * This structure is an internal runtime detail: use the mono_signature_*
+ * accessors below, because it will go away from the public header.
+ */
 struct _MonoMethodSignature {
        unsigned int  hasthis : 1;
        unsigned int  explicit_this   : 1;
@@ -338,6 +346,10 @@
        MonoType     *params [MONO_ZERO_LEN_ARRAY];
 };
 
+/*
+ * This structure is an internal runtime detail: use the mono_method_header_*
+ * accessors below, because it will go away from the public header.
+ */
 typedef struct {
        guint32      code_size;
        const unsigned char  *code;
@@ -462,6 +474,19 @@
 MonoMethodHeader *mono_metadata_parse_mh (MonoImage *m, const char *ptr);
 void              mono_metadata_free_mh  (MonoMethodHeader *mh);
 
+/* MonoMethodHeader acccessors */
+const unsigned char*
+mono_method_header_get_code (MonoMethodHeader *header, guint32* code_size, 
guint32* max_stack);
+
+MonoType**
+mono_method_header_get_locals (MonoMethodHeader *header, guint32* num_locals, 
gboolean *init_locals);
+
+int
+mono_method_header_get_num_clauses (MonoMethodHeader *header);
+
+int
+mono_method_header_get_clauses (MonoMethodHeader *header, MonoMethod *method, 
gpointer *iter, MonoExceptionClause *clause);
+
 guint32 
 mono_type_to_unmanaged (MonoType *type, MonoMarshalSpec *mspec, 
                        gboolean as_field, gboolean unicode, MonoMarshalConv 
*conv);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to