[Mono-dev] Strange enum issue

Neale Ferguson neale at sinenomine.net
Tue Mar 10 21:47:34 UTC 2015

No, I think the change here is germane:

- switch (mono_class_enum_basetype (enumc)->type) {
- case MONO_TYPE_U1:
- case MONO_TYPE_I1:
- mono_array_set (info->values, gchar, j, *p);
- break;
- case MONO_TYPE_U2:
- case MONO_TYPE_I2:
- mono_array_set (info->values, gint16, j, read16 (p));
- break;
- case MONO_TYPE_U4:
- case MONO_TYPE_I4:
- mono_array_set (info->values, gint32, j, read32 (p));
- break;
- case MONO_TYPE_U8:
- case MONO_TYPE_I8:
- mono_array_set (info->values, gint64, j, read64 (p));
- break;
- default:
- g_error ("Implement type 0x%02x in get_enum_info", mono_class_enum_basetype (enumc)->type);
- }
+ field_value = read_enum_value (p, base_type);
+ mono_array_set (*values, guint64, j, field_value);
+ if (previous_value > field_value)
+ sorted = FALSE;
+ previous_value = field_value;

Note the use of read16/read32/read64 which are defined in mono-endian.h:

#define read16(x) GUINT16_FROM_LE (*((const guint16 *) (x)))

#define read32(x) GUINT32_FROM_LE (*((const guint32 *) (x)))

#define read64(x) GUINT64_FROM_LE (*((const guint64 *) (x)))

From: Marek Safar <marek.safar at gmail.com<mailto:marek.safar at gmail.com>>
Date: Tuesday, March 10, 2015 at 1:44 PM
To: Neale Ferguson <neale at sinenomine.net<mailto:neale at sinenomine.net>>
Cc: Mono-Devel <mono-devel-list at lists.ximian.com<mailto:mono-devel-list at lists.ximian.com>>
Subject: Re: [Mono-dev] Strange enum issue

Hi Neale,

ves_icall_System_Enum_GetEnumValuesAndNames.3229: 0. field=System_Runtime
ves_icall_System_Enum_GetEnumValuesAndNames.3229: 1.
field=System_Runtime_InteropServices_WindowsRuntime value=16777216
ves_icall_System_Enum_GetEnumValuesAndNames.3229: 2.
field=System_ObjectModel value=33554432
ves_icall_System_Enum_GetEnumValuesAndNames.3229: 3.
field=System_Runtime_WindowsRuntime value=50331648
ves_icall_System_Enum_GetEnumValuesAndNames.3229: 4.
field=System_Runtime_WindowsRuntime_UI_Xaml value=67108864
ves_icall_System_Enum_GetEnumValuesAndNames.3229: 5. field=Count

Note 16777216 is hex 10000000. Now to find out how that value gets placed
there and to do some byte swapping on it.

You are probably looking for https://github.com/mono/mono/blob/master/mono/metadata/icall.c#L2961. There has been no endian changes there for years but due to different codepath this is now hit more often before.


P.S. I am wondering if it would be worth it to create a routine or more in
icall.c to do the byte swap for 2/4/8 byte integers rather than coding up
clumsy stuff in managed code.

On 3/10/15, 3:01 PM, "Robert Jordan" <robertj at gmx.net<mailto:robertj at gmx.net>> wrote:

>There was a recent commit which added MS' reference source Enum
>support to Mono:
>Maybe it's an endian-related issue.

Mono-devel-list mailing list
Mono-devel-list at lists.ximian.com<mailto:Mono-devel-list at lists.ximian.com>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20150310/b95bfbde/attachment-0001.html>

More information about the Mono-devel-list mailing list