mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-16 01:41:18 -10:00
Marshal char taking Charset into account.
* metadata.c (mono_type_to_unmanaged): Return the appropriate type for char based on unicode option. * marshal.c (emit_marshal_array): Calculate char size based on marshaling preferences. Fixes #647267
This commit is contained in:
1 parent
5a0a50c4e6
commit
1f3cfba319
2 files changed
+26
-1
No files matched your search
@@ -6902,6 +6902,25 @@ emit_marshal_variant (EmitMarshalContext *m, int argnum, MonoType *t,
|
||||
return conv_arg;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
mono_pinvoke_is_unicode (MonoMethodPInvoke *piinfo)
|
||||
{
|
||||
switch (piinfo->piflags & PINVOKE_ATTRIBUTE_CHAR_SET_MASK) {
|
||||
case PINVOKE_ATTRIBUTE_CHAR_SET_ANSI:
|
||||
return FALSE;
|
||||
case PINVOKE_ATTRIBUTE_CHAR_SET_UNICODE:
|
||||
return TRUE;
|
||||
case PINVOKE_ATTRIBUTE_CHAR_SET_AUTO:
|
||||
#ifdef TARGET_WIN32
|
||||
return TRUE;
|
||||
#else
|
||||
return FALSE;
|
||||
#endif
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
emit_marshal_array (EmitMarshalContext *m, int argnum, MonoType *t,
|
||||
MonoMarshalSpec *spec,
|
||||
@@ -6972,6 +6991,8 @@ emit_marshal_array (EmitMarshalContext *m, int argnum, MonoType *t,
|
||||
|
||||
if (is_string)
|
||||
esize = sizeof (gpointer);
|
||||
else if (eklass == mono_defaults.char_class) /*can't call mono_marshal_type_size since it causes all sorts of asserts*/
|
||||
esize = mono_pinvoke_is_unicode (m->piinfo) ? 2 : 1;
|
||||
else
|
||||
esize = mono_class_native_size (eklass, NULL);
|
||||
|
||||
@@ -7061,6 +7082,8 @@ emit_marshal_array (EmitMarshalContext *m, int argnum, MonoType *t,
|
||||
eklass = klass->element_class;
|
||||
if ((eklass == mono_defaults.stringbuilder_class) || (eklass == mono_defaults.string_class))
|
||||
esize = sizeof (gpointer);
|
||||
else if (eklass == mono_defaults.char_class)
|
||||
esize = mono_pinvoke_is_unicode (m->piinfo) ? 2 : 1;
|
||||
else
|
||||
esize = mono_class_native_size (eklass, NULL);
|
||||
src_ptr = mono_mb_add_local (mb, &mono_defaults.int_class->byval_arg);
|
||||
@@ -7504,6 +7527,8 @@ emit_marshal_array (EmitMarshalContext *m, int argnum, MonoType *t,
|
||||
|
||||
if (is_string)
|
||||
esize = sizeof (gpointer);
|
||||
else if (eklass == mono_defaults.char_class)
|
||||
esize = mono_pinvoke_is_unicode (m->piinfo) ? 2 : 1;
|
||||
else
|
||||
esize = mono_class_native_size (eklass, NULL);
|
||||
|
||||
|
||||
@@ -5421,7 +5421,7 @@ handle_enum:
|
||||
}
|
||||
*conv = MONO_MARSHAL_CONV_BOOL_I4;
|
||||
return MONO_NATIVE_BOOLEAN;
|
||||
case MONO_TYPE_CHAR: return MONO_NATIVE_U2;
|
||||
case MONO_TYPE_CHAR: return unicode ? MONO_NATIVE_U2 : MONO_NATIVE_U1;
|
||||
case MONO_TYPE_I1: return MONO_NATIVE_I1;
|
||||
case MONO_TYPE_U1: return MONO_NATIVE_U1;
|
||||
case MONO_TYPE_I2: return MONO_NATIVE_I2;
|
||||
|
||||
Reference in new issue
Block a user