Merge pull request #4621 from alexanderkyte/strdup_env
[mono.git] / mono / metadata / icall.c
index 2e6392549d835a732a4f28b7cdf9b5ca317593a3..cb562cde7613af2419d55b049d8a3a7ece434449 100644 (file)
@@ -1,5 +1,5 @@
-/*
- * icall.c:
+/**
+ * \file
  *
  * Authors:
  *   Dietmar Maurer (dietmar@ximian.com)
@@ -732,14 +732,6 @@ ves_icall_System_Array_ClearInternal (MonoArray *arr, int idx, int length)
        mono_gc_bzero_atomic (mono_array_addr_with_size_fast (arr, sz, idx), length * sz);
 }
 
-ICALL_EXPORT MonoArray*
-ves_icall_System_Array_Clone (MonoArray *arr)
-{
-       MonoError error;
-       MonoArray *result = mono_array_clone_checked (arr, &error);
-       mono_error_set_pending_exception (&error);
-       return result;
-}
 
 ICALL_EXPORT gboolean
 ves_icall_System_Array_FastCopy (MonoArray *source, int source_idx, MonoArray* dest, int dest_idx, int length)
@@ -6404,6 +6396,8 @@ ICALL_EXPORT MonoReflectionType *
 ves_icall_Remoting_RealProxy_InternalGetProxyType (MonoTransparentProxy *tp)
 {
        MonoError error;
+       g_assert (tp != NULL && mono_object_class (tp) == mono_defaults.transparent_proxy_class);
+       g_assert (tp->remote_class != NULL && tp->remote_class->proxy_class != NULL);
        MonoReflectionType *ret = mono_type_get_object_checked (mono_object_domain (tp), &tp->remote_class->proxy_class->byval_arg, &error);
        mono_error_set_pending_exception (&error);
 
@@ -6564,7 +6558,7 @@ char **environ;
 #endif
 
 ICALL_EXPORT MonoArray *
-ves_icall_System_Environment_GetCoomandLineArgs (void)
+ves_icall_System_Environment_GetCommandLineArgs (void)
 {
        MonoError error;
        MonoArray *result = mono_runtime_get_main_args_checked (&error);
@@ -7287,10 +7281,20 @@ ves_icall_MonoMethod_get_base_method (MonoReflectionMethodHandle m, gboolean def
 
        MonoMethod *base = mono_method_get_base_method (method, definition, error);
        return_val_if_nok (error, MONO_HANDLE_CAST (MonoReflectionMethod, NULL_HANDLE));
-       if (base == method)
-               return m;
-       else
-               return mono_method_get_object_handle (mono_domain_get (), base, NULL, error);
+       if (base == method) {
+               /* we want to short-circuit and return 'm' here. But we should
+                  return the same method object that
+                  mono_method_get_object_handle, below would return.  Since
+                  that call takes NULL for the reftype argument, it will take
+                  base->klass as the reflected type for the MonoMethod.  So we
+                  need to check that m also has base->klass as the reflected
+                  type. */
+               MonoReflectionTypeHandle orig_reftype = MONO_HANDLE_NEW_GET (MonoReflectionType, m, reftype);
+               MonoClass *orig_klass = mono_class_from_mono_type (MONO_HANDLE_GETVAL (orig_reftype, type));
+               if (base->klass == orig_klass)
+                       return m;
+       }
+       return mono_method_get_object_handle (mono_domain_get (), base, NULL, error);
 }
 
 ICALL_EXPORT MonoStringHandle
@@ -8087,12 +8091,12 @@ mono_icall_cleanup (void)
 
 /**
  * mono_add_internal_call:
- * @name: method specification to surface to the managed world
- * @method: pointer to a C method to invoke when the method is called
+ * \param name method specification to surface to the managed world
+ * \param method pointer to a C method to invoke when the method is called
  *
- * This method surfaces the C function pointed by @method as a method
+ * This method surfaces the C function pointed by \p method as a method
  * that has been surfaced in managed code with the method specified in
- * @name as an internal call.
+ * \p name as an internal call.
  *
  * Internal calls are surfaced to all app domains loaded and they are
  * accessibly by a type with the specified name.
@@ -8103,15 +8107,16 @@ mono_icall_cleanup (void)
  *
  * For example, the following are all valid declarations:
  *
- * "MyApp.Services.ScriptService:Accelerate"
- * "MyApp.Services.ScriptService:Slowdown(int,bool)"
+ * \c MyApp.Services.ScriptService:Accelerate
+ *
+ * \c MyApp.Services.ScriptService:Slowdown(int,bool)
  *
  * You use method parameters in cases where there might be more than
  * one surface method to managed code.  That way you can register different
  * internal calls for different method overloads.
  *
  * The internal calls are invoked with no marshalling.   This means that .NET
- * types like System.String are exposed as `MonoString *` parameters.   This is
+ * types like \c System.String are exposed as \c MonoString* parameters.   This is
  * different than the way that strings are surfaced in P/Invoke.
  *
  * For more information on how the parameters are marshalled, see the
@@ -8271,11 +8276,10 @@ no_icall_table (void)
 
 /**
  * mono_lookup_internal_call_full:
- * @method: the method to look up
- * @uses_handles: out argument if method needs handles around managed objects.
- *
- * Returns a pointer to the icall code for the given method.  If
- * uses_handles is not NULL, it will be set to TRUE if the method
+ * \param method the method to look up
+ * \param uses_handles out argument if method needs handles around managed objects.
+ * \returns a pointer to the icall code for the given method.  If
+ * \p uses_handles is not NULL, it will be set to TRUE if the method
  * needs managed objects wrapped using the infrastructure in handle.h
  *
  * If the method is not found, warns and returns NULL.
@@ -8404,6 +8408,9 @@ mono_lookup_internal_call_full (MonoMethod *method, mono_bool *uses_handles)
 #endif
 }
 
+/**
+ * mono_lookup_internal_call:
+ */
 gpointer
 mono_lookup_internal_call (MonoMethod *method)
 {