Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix strdup/_strdup detection
authorGabriel Corona <gabriel.corona@loria.fr>
Tue, 9 Jun 2015 17:02:12 +0000 (19:02 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 9 Jun 2015 17:14:23 +0000 (19:14 +0200)
strdup() is not standard C/C++. On Windows, noth _strdup() and
_strdup() are available in C. However, strdup() is not available in
C++ (ar at least in standard C++ mode?). The result is that cmake
dtects that strdup() is available but the C++ compiler fails to
compile code using it. We just use _strdup() on Windows.

include/simgrid_config.h.in
include/xbt/sysdep.h

index 1f853ca..49f6a3a 100644 (file)
@@ -136,8 +136,5 @@ XBT_PUBLIC(char *) bprintf(const char *fmt, ...) _XBT_GNUC_PRINTF(1, 2);
 /* If Model-Checking support was requested */
 #cmakedefine HAVE_MC @HAVE_MC@
 
 /* If Model-Checking support was requested */
 #cmakedefine HAVE_MC @HAVE_MC@
 
-#cmakedefine SIMGRID_HAVE_STRDUP @SIMGRID_HAVE_STRDUP@
-#cmakedefine SIMGRID_HAVE__STRDUP @SIMGRID_HAVE__STRDUP@
-
 SG_END_DECL()
 #endif /* SIMGRID_PUBLIC_CONFIG_H */
 SG_END_DECL()
 #endif /* SIMGRID_PUBLIC_CONFIG_H */
index 26897c4..f464edd 100644 (file)
@@ -74,16 +74,11 @@ char *xbt_strdup(const char *s)
 {
   char *res = NULL;
   if (s) {
 {
   char *res = NULL;
   if (s) {
-# if defined(SIMGRID_HAVE_STRDUP)
+# if !defined(_XBT_WIN32)
     res = strdup(s);
     res = strdup(s);
-# elif defined(SIMGRID_HAVE__STRDUP)
-    res = _strdup(s);
 # else
 # else
-    size_t len  = strlen(s);
-    res = malloc(len + 1);
-    if (res)
-      memcpy(res, s, len + 1);
-#  endif
+    res = _strdup(s);
+# endif
     if (!res)
       xbt_die("memory allocation error (strdup returned NULL)");
   }
     if (!res)
       xbt_die("memory allocation error (strdup returned NULL)");
   }
@@ -143,12 +138,10 @@ void *xbt_realloc(void *p, size_t s)
   return res;
 }
 #else                           /* non __GNUC__  */
   return res;
 }
 #else                           /* non __GNUC__  */
-#  if defined(SIMGRID_HAVE_STRDUP)
+#  if !defined(_XBT_WIN32)
 #    define xbt_strdup(s)    strdup(s)
 #    define xbt_strdup(s)    strdup(s)
-#  elif defined(SIMGRID_HAVE__STRDUP
-#    define xbt_strdup(s)    _strdup(s)
 #  else
 #  else
-#    error Missing strdup
+#    define xbt_strdup(s)    _strdup(s)
 #  endif
 #  define xbt_malloc(n)    malloc(n)
 #  define xbt_malloc0(n)   calloc(n,1)
 #  endif
 #  define xbt_malloc(n)    malloc(n)
 #  define xbt_malloc0(n)   calloc(n,1)