From: Martin Quinson Date: Sat, 12 Sep 2015 22:46:10 +0000 (+0200) Subject: [MSVC] use our extended xbt_malloc, but don't choke on 'strdup' that should read... X-Git-Tag: v3_12~235 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/de8cfa17c0e30bf9dccf0b0c9ecaff7858926f04 [MSVC] use our extended xbt_malloc, but don't choke on 'strdup' that should read '_strdup' --- diff --git a/include/simgrid_config.h.in b/include/simgrid_config.h.in index 354fceccc7..5b362cb535 100644 --- a/include/simgrid_config.h.in +++ b/include/simgrid_config.h.in @@ -64,6 +64,8 @@ #else typedef long ssize_t; #endif + #define snprintf _snprintf + #define strdup _strdup #endif /* Define to 1 if mmalloc is compiled in. */ diff --git a/include/xbt/base.h b/include/xbt/base.h index 1241b6366e..748b475626 100644 --- a/include/xbt/base.h +++ b/include/xbt/base.h @@ -89,7 +89,7 @@ # define XBT_INLINE # endif # else -# if defined (__VISUALC__) +# if defined (_MSC_VER) # define XBT_INLINE __inline # else # define XBT_INLINE inline @@ -97,6 +97,12 @@ # endif /* __cplusplus */ #endif +#if defined(__GNUC__) +# define XBT_ALWAYS_INLINE inline __attribute__ ((always_inline)) +#else +# define XBT_ALWAYS_INLINE XBT_INLINE +#endif + /* improvable on gcc (by evaluating arguments only once), but wouldn't be portable */ #ifdef MIN # undef MIN diff --git a/include/xbt/sysdep.h b/include/xbt/sysdep.h index 9ed7c53e13..d990aaa0e9 100644 --- a/include/xbt/sysdep.h +++ b/include/xbt/sysdep.h @@ -71,11 +71,8 @@ XBT_PUBLIC(char *) bprintf(const char *fmt, ...) _XBT_GNUC_PRINTF(1, 2); * @{ */ -#if defined(__GNUC__) || defined(DOXYGEN) /** @brief Like strdup, but xbt_die() on error */ -static inline __attribute__ ((always_inline)) -char *xbt_strdup(const char *s) -{ +static XBT_ALWAYS_INLINE char *xbt_strdup(const char *s) { char *res = NULL; if (s) { res = strdup(s); @@ -89,9 +86,7 @@ XBT_PUBLIC(void) xbt_backtrace_display_current(void); /** @brief Like malloc, but xbt_die() on error @hideinitializer */ -static inline __attribute__ ((always_inline)) -void *xbt_malloc(size_t n) -{ +static XBT_ALWAYS_INLINE void *xbt_malloc(size_t n) { void *res; /* if (n==0) { xbt_backtrace_display_current(); @@ -106,9 +101,7 @@ void *xbt_malloc(size_t n) /** @brief like malloc, but xbt_die() on error and memset data to 0 @hideinitializer */ -static inline __attribute__ ((always_inline)) -void *xbt_malloc0(size_t n) -{ +static XBT_ALWAYS_INLINE void *xbt_malloc0(size_t n) { void *res; //if (n==0) xbt_die("calloc(0) is not portable"); res = calloc(n, 1); @@ -119,9 +112,7 @@ void *xbt_malloc0(size_t n) /** @brief like realloc, but xbt_die() on error @hideinitializer */ -static inline __attribute__ ((always_inline)) -void *xbt_realloc(void *p, size_t s) -{ +static XBT_ALWAYS_INLINE void *xbt_realloc(void *p, size_t s) { void *res = NULL; //if (s==0) xbt_die("realloc(0) is not portable"); if (s) { @@ -137,12 +128,6 @@ void *xbt_realloc(void *p, size_t s) } return res; } -#else /* non __GNUC__ */ -# define xbt_strdup(s) strdup(s) -# define xbt_malloc(n) malloc(n) -# define xbt_malloc0(n) calloc(n,1) -# define xbt_realloc(p,s) realloc(p,s) -#endif /* __GNUC__ ? */ /** @brief like free @hideinitializer */