Permalink
Browse files

2006-12-18 Miguel de Icaza <miguel@novell.com>

	* marshal.c (emit_object_to_ptr_conv): Handle null safehandles
	in structures by throwing ArgumentNullException.

	(emit_marshal_safehandle): Also when they are null parameters.


svn path=/trunk/mono/; revision=69709
  • Loading branch information...
1 parent 4f7b0c5 commit 2ab644384e372e4b75f564193bc8a44cadff2a19 @migueldeicaza migueldeicaza committed Dec 19, 2006
Showing with 42 additions and 4 deletions.
  1. +7 −2 mono/metadata/ChangeLog
  2. +12 −2 mono/metadata/marshal.c
  3. +23 −0 mono/tests/safehandle.2.cs
View
@@ -1,7 +1,12 @@
2006-12-18 Miguel de Icaza <miguel@novell.com>
- * marshal.c (emit_marshal_safehandle): Add support for ref
- SafeHandles.
+ * marshal.c (emit_object_to_ptr_conv): Handle null safehandles
+ in structures by throwing ArgumentNullException.
+
+ (emit_marshal_safehandle): Also when they are null parameters.
+
+ (emit_marshal_safehandle): Add support for ref
+ SafeHandles parameters
Mon Dec 18 19:14:44 CET 2006 Paolo Molaro <lupus@ximian.com>
View
@@ -2213,7 +2213,7 @@ emit_object_to_ptr_conv (MonoMethodBuilder *mb, MonoType *type, MonoMarshalConv
}
case MONO_MARSHAL_CONV_SAFEHANDLE: {
- int dar_release_slot;
+ int dar_release_slot, pos;
dar_release_slot = mono_mb_add_local (mb, &mono_defaults.boolean_class->byval_arg);
@@ -2234,6 +2234,11 @@ emit_object_to_ptr_conv (MonoMethodBuilder *mb, MonoType *type, MonoMarshalConv
mono_mb_emit_ldloc_addr (mb, dar_release_slot);
mono_mb_emit_managed_call (mb, sh_dangerous_add_ref, NULL);
#endif
+ mono_mb_emit_ldloc (mb, 0);
+ mono_mb_emit_byte (mb, CEE_LDIND_I);
+ pos = mono_mb_emit_branch (mb, CEE_BRTRUE);
+ mono_mb_emit_exception (mb, "ArgumentNullException", NULL);
+ mono_mb_patch_branch (mb, pos);
/* Pull the handle field from SafeHandle */
mono_mb_emit_ldloc (mb, 1);
@@ -6028,7 +6033,7 @@ emit_marshal_safehandle (EmitMarshalContext *m, int argnum, MonoType *t,
switch (action){
case MARSHAL_ACTION_CONV_IN: {
MonoType *intptr_type;
- int dar_release_slot;
+ int dar_release_slot, pos;
intptr_type = &mono_defaults.int_class->byval_arg;
conv_arg = mono_mb_add_local (mb, intptr_type);
@@ -6037,6 +6042,11 @@ emit_marshal_safehandle (EmitMarshalContext *m, int argnum, MonoType *t,
if (!sh_dangerous_add_ref)
init_safe_handle ();
+ mono_mb_emit_ldarg (mb, argnum);
+ pos = mono_mb_emit_branch (mb, CEE_BRTRUE);
+ mono_mb_emit_exception (mb, "ArgumentNullException", NULL);
+
+ mono_mb_patch_branch (mb, pos);
if (t->byref){
/*
* My tests in show that ref SafeHandles are not really
View
@@ -94,6 +94,17 @@ public static int test_0_marshal_safehandle_argument ()
return 0;
}
+ public static int test_0_marshal_safehandle_argument_null ()
+ {
+ try {
+ mono_xr (null);
+ } catch (ArgumentNullException){
+ return 0;
+ }
+ return 1;
+ }
+
+
[StructLayout (LayoutKind.Sequential)]
public struct StringOnStruct {
public string a;
@@ -198,6 +209,18 @@ public static int test_0_simple ()
return mono_safe_handle_struct_simple (s) == 2468 ? 0 : 1;
}
+
+ public static int test_0_struct_empty ()
+ {
+ StructTest1 s = new StructTest1 ();
+
+ try {
+ mono_safe_handle_struct_simple (s);
+ } catch (ArgumentNullException){
+ return 0;
+ }
+ return 1;
+ }
public static int test_0_sf_dispose ()
{

0 comments on commit 2ab6443

Please sign in to comment.