Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[MSVC] use our extended xbt_malloc, but don't choke on 'strdup' that should read...
authorMartin Quinson <martin.quinson@loria.fr>
Sat, 12 Sep 2015 22:46:10 +0000 (00:46 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sat, 12 Sep 2015 22:46:10 +0000 (00:46 +0200)
include/simgrid_config.h.in
include/xbt/base.h
include/xbt/sysdep.h

index 354fcec..5b362cb 100644 (file)
@@ -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. */
index 1241b63..748b475 100644 (file)
@@ -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
 #  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
index 9ed7c53..d990aaa 100644 (file)
@@ -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 */