[Mono-dev] Number of elements in a fixed buffer

Bill Seurer seurer at linux.vnet.ibm.com
Mon Aug 10 14:53:06 UTC 2015


The only mention of FixedBufferAttribute I see is in the C# code in mcs.

I looked through all the mono C code and I see several places where 
MonoCustomAttrInfo is used but no where is it doing anything with fixed 
buffers.  Is there some documentation or more examples of what is in the 
MonoCustomAttrInfo data for something like this?

I experimented a bit and used mono_custom_attrs_from_class() to pull the 
MonoCustomAttrInfo for the class.  It looks like there are two attributes.

{num_attrs = 2, cached = 0, image = 0x10566ed0, attrs = 0x1061c630}

So looking at the two attributes I see

attrs[0]:  {ctor = 0x1061cb10, data_size = 4, data = 0x3fffb7840e71 "\001"}
attrs[1]:  {ctor = 0x1061c990, data_size = 4, data = 0x3fffb7840e71 "\001"}


The data fields are identical and are 01 00 00 00 or maybe the other way 
around depending on what the field represents (this is a LE machine).

The ctors are

(gdb) print cinfo->attrs[0].ctor->klass->name
$14 = 0x3fffb5b225b6 "UnsafeValueTypeAttribute"
(gdb) print cinfo->attrs[1].ctor->klass->name
$15 = 0x3fffb5b22281 "CompilerGeneratedAttribute"

What do those represent?


On 08/06/2015 12:23 PM, Zoltan Varga wrote:
> Hi,
>
>    The type has a FixedBufferAttribute custom attribute which contains
> the length of the array. There are some functions in reflection.c
> like mono_custom_attrs_from_class () which can return information about it.
>
>                 Zoltan
>
> On Thu, Aug 6, 2015 at 12:32 PM, Bill Seurer <seurer at linux.vnet.ibm.com
> <mailto:seurer at linux.vnet.ibm.com>> wrote:
>
>     In some code in mono/mini I need to figure out how many elements
>     there are in a fixed buffer field in a struct, something like this:
>
>              public unsafe struct double_array4 {
>                      public fixed double f1[4];
>              }
>
>     So I'd need to know "4".
>
>     I can get the MonoClass of the field from the MonoFieldType and if I
>     print out the name I get
>
>     Test_double.double_array4.<f1>__FixedBuffer0
>
>     so it knows it is a fixed buffer.  If I look at the fields of the
>     struct in the above example there is just one and it's a double.
>
>     So how can I figure out the number of elements?
>
>     Thanks!


-- 

-Bill Seurer



More information about the Mono-devel-list mailing list