Merge pull request #3686 from lambdageek/dev-format-printf
authorAleksey Kliger (λgeek) <akliger@gmail.com>
Tue, 4 Oct 2016 14:05:33 +0000 (10:05 -0400)
committerGitHub <noreply@github.com>
Tue, 4 Oct 2016 14:05:33 +0000 (10:05 -0400)
Add MONO_ATTR_FORMAT_PRINTF macro

1  2 
mono/metadata/marshal.c
mono/metadata/metadata-internals.h
mono/metadata/object.c
mono/utils/mono-compiler.h

diff --combined mono/metadata/marshal.c
index 162702a3d7c122c8e6c973aeabdef23dc01f58a4,fd20aea402f3651fcaa22801629447222f2de0ce..f5cfadbb8faf929ec49a9295ab0f955476660643
  #include <string.h>
  #include <errno.h>
  
 +#if defined(HOST_WIN32)
 +#include <objbase.h>
 +#endif
 +
  /* #define DEBUG_RUNTIME_CODE */
  
  #define OPDEF(a,b,c,d,e,f,g,h,i,j) \
@@@ -10535,7 -10531,7 +10535,7 @@@ mono_marshal_alloc (gulong size, MonoEr
  #else
        res = g_try_malloc ((gulong)size);
        if (!res)
-               mono_error_set_out_of_memory (error, "Could not allocate %i bytes", size);
+               mono_error_set_out_of_memory (error, "Could not allocate %lu bytes", size);
  #endif
        return res;
  }
index 5d3604d181bae2f762f3f427b9ce2ac4475401c8,9d2e569dfd7d4ceb58dfd0ab61019c2faa393d6b..a68897538aec5f910d666a786c38532051f87d5d
@@@ -499,6 -499,7 +499,6 @@@ struct _MonoDynamicImage 
        GHashTable *method_aux_hash;
        GHashTable *vararg_aux_hash;
        MonoGHashTable *generic_def_objects;
 -      MonoGHashTable *methodspec;
        /*
         * Maps final token values to the object they describe.
         */
@@@ -642,7 -643,7 +642,7 @@@ char
  mono_image_strdup_vprintf (MonoImage *image, const char *format, va_list args);
  
  char*
- mono_image_strdup_printf (MonoImage *image, const char *format, ...);
+ mono_image_strdup_printf (MonoImage *image, const char *format, ...) MONO_ATTR_FORMAT_PRINTF(2,3);;
  
  GList*
  g_list_prepend_image (MonoImage *image, GList *list, gpointer data);
diff --combined mono/metadata/object.c
index 0603774589ed0b35babf69bd342d79ad46c03808,057e858b882fe4d2e135185473d69afa2e795eb1..3ab92326b1b388bfdf002a7bc1074694047887c4
@@@ -5457,7 -5457,7 +5457,7 @@@ mono_class_get_allocation_ftn (MonoVTab
  
        *pass_size_in_words = FALSE;
  
 -      if (mono_class_has_finalizer (vtable->klass) || mono_class_is_marshalbyref (vtable->klass) || (mono_profiler_get_events () & MONO_PROFILE_ALLOCATIONS))
 +      if (mono_class_has_finalizer (vtable->klass) || mono_class_is_marshalbyref (vtable->klass))
                return ves_icall_object_new_specific;
  
        if (vtable->gc_descr != MONO_GC_DESCRIPTOR_NULL) {
@@@ -5822,7 -5822,7 +5822,7 @@@ mono_array_new_full_checked (MonoDomai
                o = (MonoObject *)mono_gc_alloc_vector (vtable, byte_len, len);
  
        if (G_UNLIKELY (!o)) {
-               mono_error_set_out_of_memory (error, "Could not allocate %i bytes", byte_len);
+               mono_error_set_out_of_memory (error, "Could not allocate %zd bytes", (gsize) byte_len);
                return NULL;
        }
  
@@@ -5936,7 -5936,7 +5936,7 @@@ mono_array_new_specific_checked (MonoVT
        o = (MonoObject *)mono_gc_alloc_vector (vtable, byte_len, n);
  
        if (G_UNLIKELY (!o)) {
-               mono_error_set_out_of_memory (error, "Could not allocate %i bytes", byte_len);
+               mono_error_set_out_of_memory (error, "Could not allocate %zd bytes", (gsize) byte_len);
                return NULL;
        }
  
@@@ -6094,7 -6094,7 +6094,7 @@@ mono_string_new_size_checked (MonoDomai
        s = (MonoString *)mono_gc_alloc_string (vtable, size, len);
  
        if (G_UNLIKELY (!s)) {
-               mono_error_set_out_of_memory (error, "Could not allocate %i bytes", size);
+               mono_error_set_out_of_memory (error, "Could not allocate %zd bytes", size);
                return NULL;
        }
  
index 5c942e06fa2e5e1e4c9667e7e9c6932004fef0a7,1f4f889904500d13befec05cd6944c83de19d698..8a044e50d31a2eb15cc4bb2a56a2266db85644b6
  #define MONO_ATTR_USED
  #endif
  
+ #ifdef __GNUC__
+ #define MONO_ATTR_FORMAT_PRINTF(fmt_pos,arg_pos) __attribute__((format(printf,fmt_pos,arg_pos)))
+ #else
+ #define MONO_ATTR_FORMAT_PRINTF(fmt_pos,arg_pos)
+ #endif
  #ifdef HAVE_KW_THREAD
  
  #define MONO_HAVE_FAST_TLS
@@@ -275,6 -281,12 +281,6 @@@ typedef SSIZE_T ssize_t
  #define MONO_LLVM_INTERNAL 
  #endif
  
 -#if HAVE_DEPRECATED
 -#define MONO_DEPRECATED __attribute__ ((deprecated))
 -#else
 -#define MONO_DEPRECATED 
 -#endif
 -
  #ifdef __GNUC__
  #define MONO_ALWAYS_INLINE __attribute__((always_inline))
  #elif defined(_MSC_VER)