Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Revert "Make gras compil with Visual C++." This commit is too large/unreadable. It...
authoralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 2 Jun 2010 13:11:54 +0000 (13:11 +0000)
committeralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 2 Jun 2010 13:11:54 +0000 (13:11 +0000)
This reverts commit eae1f516d7042d8a589b3d4150cc2721dc146a24.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7820 48e7efb5-ca39-0410-a469-dd3cf9ba447f

CMakeLists.txt
buildtools/Cmake/Flags.cmake
buildtools/Cmake/gras_config.h.in
include/xbt/misc.h
src/gras/DataDesc/ddt_create.c
src/xbt/heap.c
src/xbt/setset.c
src/xbt/xbt_log_layout_simple.c
src/xbt/xbt_os_time.c

index e533911..e40adb6 100644 (file)
@@ -8,6 +8,21 @@ set(libsimgrid_version "${release_version}")
 set(libgras_version "${release_version}")
 set(libsmpi_version "${release_version}")
 
+if(WIN32)
+       message("       Be sure all those variables are correctely set.")
+    message("          -- C_COMPILER                   $ENV{CC}")
+    message("          -- CXX_COMPILER                 $ENV{CXX}")    
+    message("          -- RC_COMPILER                  $ENV{RC}")
+    message("          -- INCLUDE                      $ENV{INCLUDE}")
+    message("          -- LIB                          $ENV{LIB}")
+    message("          -- MAKE_PROGRAM                 ${CMAKE_MAKE_PROGRAM}")
+    message("          -- CMAKE_BUILD_TOOL                     ${CMAKE_BUILD_TOOL}")
+    message("          -- LINKER                               ${CMAKE_LINKER}")
+    message("          -- CMAKE_GENERATOR                      ${CMAKE_GENERATOR}\n\n")
+    set(__STRICT_ANSI__ 1)
+    set(_MSC_VER 1)
+endif(WIN32)
+
 ### Find programs and paths
 find_path(GCOV_PATH NAMES gcov PATHS NO_DEFAULT_PATHS)
 find_path(VALGRIND_PATH        NAMES valgrind  PATHS NO_DEFAULT_PATHS)
@@ -16,6 +31,7 @@ find_path(VALGRIND_PATH       NAMES valgrind  PATHS NO_DEFAULT_PATHS)
 SET(PROJECT_DIRECTORY "${CMAKE_HOME_DIRECTORY}")
 
 ### Set some variables for Cmake
+#SET(PROJECT_SOURCE_DIRECTORY "${PROJECT_DIRECTORY}/src") #this one is evil since it speaks to CPack instead
 SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
 set(INCLUDES "-I${PROJECT_DIRECTORY}/include -I${PROJECT_DIRECTORY}/src/include -I${PROJECT_DIRECTORY}/src -I${CMAKE_CURRENT_BINARY_DIR}/src/")
 set(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIRECTORY})
@@ -25,28 +41,7 @@ if(EXISTS /usr/include/)
 endif(EXISTS /usr/include/)
 
 if(WIN32)
-       set(INCLUDES_MORE $ENV{INCLUDE})
-       string(REPLACE "\\" "/" INCLUDES_MORE "${INCLUDES_MORE}")
-       foreach(include_dir ${INCLUDES_MORE})
-               set(INCLUDES "${INCLUDES} -I\"${include_dir}\"")
-       endforeach(include_dir ${INCLUDES_MORE})
-endif(WIN32)
-
-if(WIN32)
-       message("       Be sure all those variables are correctely set.")
-    message("          -- C_COMPILER                   $ENV{CC}")
-    message("          -- CXX_COMPILER                 $ENV{CXX}")    
-    message("          -- RC_COMPILER                  $ENV{RC}")
-    message("          -- INCLUDE                      $ENV{INCLUDE}")
-    message("          -- LIB                          $ENV{LIB}")
-    message("          -- MAKE_PROGRAM                 ${CMAKE_MAKE_PROGRAM}")
-    message("          -- CMAKE_BUILD_TOOL             ${CMAKE_BUILD_TOOL}")
-    message("          -- LINKER                       ${CMAKE_LINKER}")
-    message("          -- CMAKE_GENERATOR              ${CMAKE_GENERATOR}\n\n")
-    message("          -- INCLUDES                     ${INCLUDES}")
-    set(__STRICT_ANSI__ 1)
-    set(_MSC_VER 1)
-    set(_WIN32 1)
+       set(INCLUDES "${INCLUDES} -I$ENV{INCLUDE}")
 endif(WIN32)
 
 if(enable_coverage)
index 90a5d50..72fc89b 100644 (file)
@@ -1,8 +1,8 @@
 set(warnCFLAGS "")
 set(optCFLAGS "")
 
-if(NOT WIN32)
 set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS}-g3)
+
 if(enable_supernovae)
        set(warnCFLAGS "-Wall -Wunused -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wchar-subscripts -Wcomment -Wformat -Wwrite-strings -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing -Wno-format-nonliteral -Werror ")
        set(optCFLAGS "-O3 -finline-functions -funroll-loops -fno-strict-aliasing ")
@@ -15,6 +15,6 @@ endif(enable_compile_warnings)
 if(enable_compile_optimizations)
        set(optCFLAGS "-O3 -finline-functions -funroll-loops -fno-strict-aliasing ")
 endif(enable_compile_optimizations)
-endif(NOT WIN32)
 
 set(CMAKE_C_FLAGS "${optCFLAGS}${warnCFLAGS}${CMAKE_C_FLAGS}")
+
index 1ef70ee..fccb701 100644 (file)
@@ -2,14 +2,8 @@
 // With Cmake it creates <root>/src/gras_config.h
 
 /* Set somes variables for Windows compilation */
-#ifndef __STRICT_ANSI__
-       #cmakedefine __STRICT_ANSI__ @__STRICT_ANSI__@
-#endif
-#ifndef _MSC_VER
-       #cmakedefine _MSC_VER @_MSC_VER@
-#endif
-#cmakedefine _WIN32 @_WIN32@
-#cmakedefine WIN32 @WIN32@
+#cmakedefine __STRICT_ANSI__ @__STRICT_ANSI__@
+#cmakedefine _MSC_VER @_MSC_VER@
 
 /* Set to true if enable_model-checking is true */
 #cmakedefine MMALLOC_WANT_OVERIDE_LEGACY @MMALLOC_WANT_OVERIDE_LEGACY@
index 9964ea6..5ee2661 100644 (file)
-/* xbt.h - Public interface to the xbt (gras's toolbox)                     */\r
-/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.\r
- * All rights reserved.                                                     */\r
-\r
-/* This program is free software; you can redistribute it and/or modify it\r
- * under the terms of the license (GNU LGPL) which comes with this package. */\r
-\r
-#include "gras_config.h"\r
-\r
-#ifndef XBT_MISC_H\r
-#define XBT_MISC_H\r
-\r
-/* Attributes are only in recent versions of GCC */\r
-#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4))\r
-# define _XBT_GNUC_PRINTF( format_idx, arg_idx )    \\r
-          __attribute__((__format__ (__printf__, format_idx, arg_idx)))\r
-# define _XBT_GNUC_SCANF( format_idx, arg_idx )     \\r
-              __attribute__((__format__ (__scanf__, format_idx, arg_idx)))\r
-# define _XBT_GNUC_FORMAT( arg_idx )                \\r
-                  __attribute__((__format_arg__ (arg_idx)))\r
-# define _XBT_GNUC_NORETURN __attribute__((__noreturn__))\r
-# define _XBT_GNUC_UNUSED  __attribute__((unused))\r
-# define _XBT_GNUC_CONSTRUCTOR __attribute__((__constructor__))\r
-# define _XBT_GNUC_DESTRUCTOR __attribute__((__destructor__))\r
-# undef _XBT_NEED_INIT_PRAGMA\r
-\r
-#else /* !__GNUC__ */\r
-# define _XBT_GNUC_PRINTF( format_idx, arg_idx )\r
-# define _XBT_GNUC_SCANF( format_idx, arg_idx )\r
-# define _XBT_GNUC_FORMAT( arg_idx )\r
-# define _XBT_GNUC_NORETURN\r
-# define _XBT_GNUC_UNUSED\r
-# define _XBT_GNUC_CONSTRUCTOR\r
-# define _XBT_GNUC_DESTRUCTOR\r
-# define  _XBT_NEED_INIT_PRAGMA 1\r
-\r
-#endif /* !__GNUC__ */\r
-\r
-/* inline and __FUNCTION__ are only in GCC when -ansi is off */\r
-\r
-#if defined(__GNUC__) && ! defined(__STRICT_ANSI__)\r
-# define _XBT_FUNCTION __FUNCTION__\r
-#elif (defined(__STDC__) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)\r
-# define _XBT_FUNC__ __func__   /* ISO-C99 compliant */\r
-#else\r
-# define _XBT_FUNCTION "function"\r
-#endif\r
-\r
-#ifndef __cplusplus\r
-#    if defined(__GNUC__) && ! defined(__STRICT_ANSI__)\r
-#        define XBT_INLINE inline\r
-#    elif (defined(__STDC__) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)\r
-#        define XBT_INLINE inline\r
-#    elif defined(__BORLANDC__) && !defined(__STRICT_ANSI__)\r
-#        define XBT_INLINE __inline\r
-#    else\r
-#        define XBT_INLINE\r
-#    endif\r
-# else\r
-#    define XBT_INLINE  inline\r
-#endif\r
-\r
-/* improvable on gcc (by evaluating arguments only once), but wouldn't be portable */\r
-#ifdef MIN\r
-# undef MIN\r
-#endif\r
-#define MIN(a,b) ((a)<(b)?(a):(b))\r
-\r
-#ifdef MAX\r
-# undef MAX\r
-#endif\r
-#define MAX(a,b) ((a)>(b)?(a):(b))\r
-\r
-\r
-/* \r
- * Function calling convention (not used for now) \r
- */\r
-\r
-#ifdef _WIN32\r
-#  ifndef _XBT_CALL\r
-#    define _XBT_CALL __cdecl\r
-#   endif\r
-#else\r
-#  define _XBT_CALL\r
-#endif\r
-\r
-/* Handle import/export stuff\r
- * \r
- * Rational of XBT_PUBLIC: \r
- *   * This is for library symbols visible from the application-land.\r
- *     Basically, any symbols defined in the include/directory must be \r
- *     like this (plus some other globals). \r
- *\r
- *     UNIX coders should just think of it as a special way to say "extern".\r
- *\r
- *   * If you build the DLL, define the DLL_EXPORT symbol so that all symbols\r
- *     actually get exported by this file.\r
-\r
- *   * If you do a static windows compilation, define DLL_STATIC, both when\r
- *     compiling the application files and when compiling the library.\r
- *\r
- *   * If you link your application against the DLL or if you do a UNIX build,\r
- *     don't do anything special. This file will do the right thing for you \r
- *     by default.\r
- *\r
- * \r
- * Rational of XBT_EXPORT_NO_IMPORT: (windows-only cruft)\r
- *   * Symbols which must be exported in the DLL, but not imported from it.\r
- * \r
- *   * This is obviously useful for initialized globals (which cannot be \r
- *     extern or similar).\r
- *   * This is also used in the log mecanism where a macro creates the \r
- *     variable automatically. When the macro is called from within SimGrid,\r
- *     the symbol must be exported, but when called  from within the client\r
- *     code, it must not try to retrieve the symbol from the DLL since it's\r
- *      not in there.\r
- * \r
- * Rational of XBT_IMPORT_NO_EXPORT: (windows-only cruft)\r
- *   * Symbols which must be imported from the DLL, but not explicitely \r
- *     exported from it.\r
- * \r
- *   * The root log category is already exported, but not imported explicitely \r
- *     when creating a subcategory since we cannot import the parent category \r
- *     to deal with the fact that the parent may be in application space, not \r
- *     DLL space.\r
- */\r
-\r
-\r
-/* Build the DLL */\r
-#if defined(DLL_EXPORT)\r
-#  define XBT_PUBLIC(type)            __declspec(dllexport) type\r
-#  define XBT_EXPORT_NO_IMPORT(type)  __declspec(dllexport) type\r
-#  define XBT_IMPORT_NO_EXPORT(type)  type\r
-#  define XBT_PUBLIC_DATA(type)              __declspec(dllexport) type\r
-\r
-/* Pack everything up statically */\r
-#elif defined(DLL_STATIC)\r
-#  define XBT_PUBLIC(type)           extern type\r
-#  define XBT_EXPORT_NO_IMPORT(type)  type\r
-#  define XBT_IMPORT_NO_EXPORT(type)  type\r
-#  define XBT_PUBLIC_DATA(type)       extern type\r
-\r
-\r
-/* Link against the DLL */\r
-#elif (defined(_WIN32) && !defined(DLL_EXPORT) && !defined(DLL_STATIC))\r
-#  define XBT_PUBLIC(type)             type\r
-#  define XBT_EXPORT_NO_IMPORT(type)   type\r
-#  define XBT_IMPORT_NO_EXPORT(type)   __declspec(dllimport) type\r
-#  define XBT_PUBLIC_DATA(type)                __declspec(dllimport) type\r
-\r
-/* UNIX build */\r
-#else\r
-#  define XBT_PUBLIC(type)            extern type\r
-#  define XBT_EXPORT_NO_IMPORT(type)  type\r
-#  define XBT_IMPORT_NO_EXPORT(type)  type\r
-#  define XBT_PUBLIC_DATA(type)       extern type\r
-#endif\r
-\r
-#if !defined (max) && !defined(__cplusplus)\r
-#  define max(a,b)     (((a) > (b)) ? (a) : (b))\r
-#endif\r
-#if !defined (min) && !defined(__cplusplus)\r
-#  define min(a,b)     (((a) < (b)) ? (a) : (b))\r
-#endif\r
-\r
-#define TRUE  1\r
-#define FALSE 0\r
-\r
-#define XBT_MAX_CHANNEL 10      /* FIXME: killme */\r
-/*! C++ users need love */\r
-#ifndef SG_BEGIN_DECL\r
-# ifdef __cplusplus\r
-#  define SG_BEGIN_DECL() extern "C" {\r
-# else\r
-#  define SG_BEGIN_DECL()\r
-# endif\r
-#endif\r
-\r
-#ifndef SG_END_DECL\r
-# ifdef __cplusplus\r
-#  define SG_END_DECL() }\r
-# else\r
-#  define SG_END_DECL()\r
-# endif\r
-#endif\r
-/* End of cruft for C++ */\r
-\r
-SG_BEGIN_DECL()\r
-\r
-XBT_PUBLIC(const char *) xbt_procname(void);\r
-\r
-#define XBT_BACKTRACE_SIZE 10   /* FIXME: better place? Do document */\r
-\r
-SG_END_DECL()\r
-#endif /* XBT_MISC_H */\r
+/* xbt.h - Public interface to the xbt (gras's toolbox)                     */
+
+/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#ifndef XBT_MISC_H
+#define XBT_MISC_H
+
+/* Attributes are only in recent versions of GCC */
+#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4))
+# define _XBT_GNUC_PRINTF( format_idx, arg_idx )    \
+          __attribute__((__format__ (__printf__, format_idx, arg_idx)))
+# define _XBT_GNUC_SCANF( format_idx, arg_idx )     \
+              __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
+# define _XBT_GNUC_FORMAT( arg_idx )                \
+                  __attribute__((__format_arg__ (arg_idx)))
+# define _XBT_GNUC_NORETURN __attribute__((__noreturn__))
+# define _XBT_GNUC_UNUSED  __attribute__((unused))
+# define _XBT_GNUC_CONSTRUCTOR __attribute__((__constructor__))
+# define _XBT_GNUC_DESTRUCTOR __attribute__((__destructor__))
+# undef _XBT_NEED_INIT_PRAGMA
+
+#else /* !__GNUC__ */
+# define _XBT_GNUC_PRINTF( format_idx, arg_idx )
+# define _XBT_GNUC_SCANF( format_idx, arg_idx )
+# define _XBT_GNUC_FORMAT( arg_idx )
+# define _XBT_GNUC_NORETURN
+# define _XBT_GNUC_UNUSED
+# define _XBT_GNUC_CONSTRUCTOR
+# define _XBT_GNUC_DESTRUCTOR
+# define  _XBT_NEED_INIT_PRAGMA 1
+
+#endif /* !__GNUC__ */
+
+/* inline and __FUNCTION__ are only in GCC when -ansi is off */
+
+#if defined(__GNUC__) && ! defined(__STRICT_ANSI__)
+# define _XBT_FUNCTION __FUNCTION__
+#elif (defined(__STDC__) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
+# define _XBT_FUNC__ __func__   /* ISO-C99 compliant */
+#else
+# define _XBT_FUNCTION "function"
+#endif
+
+#ifndef __cplusplus
+#    if defined(__GNUC__) && ! defined(__STRICT_ANSI__)
+#        define XBT_INLINE inline
+#    elif (defined(__STDC__) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
+#        define XBT_INLINE inline
+#    elif defined(__BORLANDC__) && !defined(__STRICT_ANSI__)
+#        define XBT_INLINE __inline
+#    else
+#        define XBT_INLINE
+#    endif
+# else
+#    define XBT_INLINE  inline
+#endif
+
+/* improvable on gcc (by evaluating arguments only once), but wouldn't be portable */
+#ifdef MIN
+# undef MIN
+#endif
+#define MIN(a,b) ((a)<(b)?(a):(b))
+
+#ifdef MAX
+# undef MAX
+#endif
+#define MAX(a,b) ((a)>(b)?(a):(b))
+
+
+/* 
+ * Function calling convention (not used for now) 
+ */
+
+#ifdef _WIN32
+#  ifndef _XBT_CALL
+#    define _XBT_CALL __cdecl
+#   endif
+#else
+#  define _XBT_CALL
+#endif
+
+/* Handle import/export stuff
+ * 
+ * Rational of XBT_PUBLIC: 
+ *   * This is for library symbols visible from the application-land.
+ *     Basically, any symbols defined in the include/directory must be 
+ *     like this (plus some other globals). 
+ *
+ *     UNIX coders should just think of it as a special way to say "extern".
+ *
+ *   * If you build the DLL, define the DLL_EXPORT symbol so that all symbols
+ *     actually get exported by this file.
+
+ *   * If you do a static windows compilation, define DLL_STATIC, both when
+ *     compiling the application files and when compiling the library.
+ *
+ *   * If you link your application against the DLL or if you do a UNIX build,
+ *     don't do anything special. This file will do the right thing for you 
+ *     by default.
+ *
+ * 
+ * Rational of XBT_EXPORT_NO_IMPORT: (windows-only cruft)
+ *   * Symbols which must be exported in the DLL, but not imported from it.
+ * 
+ *   * This is obviously useful for initialized globals (which cannot be 
+ *     extern or similar).
+ *   * This is also used in the log mecanism where a macro creates the 
+ *     variable automatically. When the macro is called from within SimGrid,
+ *     the symbol must be exported, but when called  from within the client
+ *     code, it must not try to retrieve the symbol from the DLL since it's
+ *      not in there.
+ * 
+ * Rational of XBT_IMPORT_NO_EXPORT: (windows-only cruft)
+ *   * Symbols which must be imported from the DLL, but not explicitely 
+ *     exported from it.
+ * 
+ *   * The root log category is already exported, but not imported explicitely 
+ *     when creating a subcategory since we cannot import the parent category 
+ *     to deal with the fact that the parent may be in application space, not 
+ *     DLL space.
+ */
+
+
+/* Build the DLL */
+#if defined(DLL_EXPORT)
+#  define XBT_PUBLIC(type)            __declspec(dllexport) type
+#  define XBT_EXPORT_NO_IMPORT(type)  __declspec(dllexport) type
+#  define XBT_IMPORT_NO_EXPORT(type)  type
+#  define XBT_PUBLIC_DATA(type)              __declspec(dllexport) type
+
+/* Pack everything up statically */
+#elif defined(DLL_STATIC)
+#  define XBT_PUBLIC(type)           extern type
+#  define XBT_EXPORT_NO_IMPORT(type)  type
+#  define XBT_IMPORT_NO_EXPORT(type)  type
+#  define XBT_PUBLIC_DATA(type)       extern type
+
+
+/* Link against the DLL */
+#elif (defined(_WIN32) && !defined(DLL_EXPORT) && !defined(DLL_STATIC))
+#  define XBT_PUBLIC(type)             __declspec(dllimport) type
+#  define XBT_EXPORT_NO_IMPORT(type)   type
+#  define XBT_IMPORT_NO_EXPORT(type)   __declspec(dllimport) type
+#  define XBT_PUBLIC_DATA(type)                __declspec(dllimport) type
+
+/* UNIX build */
+#else
+#  define XBT_PUBLIC(type)            extern type
+#  define XBT_EXPORT_NO_IMPORT(type)  type
+#  define XBT_IMPORT_NO_EXPORT(type)  type
+#  define XBT_PUBLIC_DATA(type)       extern type
+#endif
+
+#if !defined (max) && !defined(__cplusplus)
+#  define max(a,b)     (((a) > (b)) ? (a) : (b))
+#endif
+#if !defined (min) && !defined(__cplusplus)
+#  define min(a,b)     (((a) < (b)) ? (a) : (b))
+#endif
+
+#define TRUE  1
+#define FALSE 0
+
+#define XBT_MAX_CHANNEL 10      /* FIXME: killme */
+/*! C++ users need love */
+#ifndef SG_BEGIN_DECL
+# ifdef __cplusplus
+#  define SG_BEGIN_DECL() extern "C" {
+# else
+#  define SG_BEGIN_DECL()
+# endif
+#endif
+
+#ifndef SG_END_DECL
+# ifdef __cplusplus
+#  define SG_END_DECL() }
+# else
+#  define SG_END_DECL()
+# endif
+#endif
+/* End of cruft for C++ */
+
+SG_BEGIN_DECL()
+
+XBT_PUBLIC(const char *) xbt_procname(void);
+
+#define XBT_BACKTRACE_SIZE 10   /* FIXME: better place? Do document */
+
+SG_END_DECL()
+#endif /* XBT_MISC_H */
index a947f07..2f1158e 100644 (file)
-/* ddt_new - creation/deletion of datatypes structs (private to this module)*/\r
-\r
-/* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010. The SimGrid Team.\r
- * All rights reserved.                                                     */\r
-\r
-/* This program is free software; you can redistribute it and/or modify it\r
- * under the terms of the license (GNU LGPL) which comes with this package. */\r
-\r
-#include "xbt/misc.h"           /* min()/max() */\r
-#include "xbt/ex.h"\r
-#include "gras/DataDesc/datadesc_private.h"\r
-\r
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_ddt_create, gras_ddt,\r
-                                "Creating new datadescriptions");\r
-\r
-/*** prototypes ***/\r
-static gras_dd_cat_field_t\r
-gras_dd_find_field(gras_datadesc_type_t type, const char *field_name);\r
-/**\r
- * gras_ddt_freev:\r
- *\r
- * gime that memory back, dude. I mean it.\r
- */\r
-void gras_ddt_freev(void *ddt)\r
-{\r
-  gras_datadesc_type_t type = (gras_datadesc_type_t) ddt;\r
-\r
-  if (type) {\r
-    gras_datadesc_free(&type);\r
-  }\r
-}\r
-\r
-static gras_datadesc_type_t gras_ddt_new(const char *name)\r
-{\r
-  gras_datadesc_type_t res;\r
-\r
-  XBT_IN1("(%s)", name);\r
-  res = xbt_new0(s_gras_datadesc_type_t, 1);\r
-\r
-  res->name = (char *) strdup(name);\r
-  res->name_len = strlen(name);\r
-  res->cycle = 0;\r
-\r
-  xbt_set_add(gras_datadesc_set_local, (xbt_set_elm_t) res, gras_ddt_freev);\r
-  XBT_OUT;\r
-  return res;\r
-}\r
-\r
-/** @brief retrieve an existing message type from its name (or NULL if it does not exist). */\r
-gras_datadesc_type_t gras_datadesc_by_name_or_null(const char *name)\r
-{\r
-  xbt_ex_t e;\r
-  gras_datadesc_type_t res = NULL;\r
-\r
-  TRY {\r
-    res = gras_datadesc_by_name(name);\r
-  } CATCH(e) {\r
-    res = NULL;\r
-    xbt_ex_free(e);\r
-  }\r
-  return res;\r
-}\r
-\r
-/**\r
- * Search the given datadesc (or raises an exception if it can't be found)\r
- */\r
-gras_datadesc_type_t gras_datadesc_by_name(const char *name)\r
-{\r
-  xbt_ex_t e;\r
-  gras_datadesc_type_t res = NULL;\r
-  volatile int found = 0;\r
-  TRY {\r
-    res =\r
-      (gras_datadesc_type_t) xbt_set_get_by_name(gras_datadesc_set_local,\r
-                                                 name);\r
-    found = 1;\r
-  } CATCH(e) {\r
-    if (e.category != not_found_error)\r
-      RETHROW;\r
-    xbt_ex_free(e);\r
-  }\r
-  if (!found)\r
-    THROW1(not_found_error, 0, "No registred datatype of that name: %s",\r
-           name);\r
-\r
-  return res;\r
-}\r
-\r
-/**\r
- * Retrieve a type from its code (or NULL if not found)\r
- */\r
-gras_datadesc_type_t gras_datadesc_by_id(long int code)\r
-{\r
-  xbt_ex_t e;\r
-  gras_datadesc_type_t res = NULL;\r
-  TRY {\r
-    res =\r
-      (gras_datadesc_type_t) xbt_set_get_by_id(gras_datadesc_set_local, code);\r
-  } CATCH(e) {\r
-    if (e.category != not_found_error)\r
-      RETHROW;\r
-    xbt_ex_free(e);\r
-    res = NULL;\r
-  }\r
-  return res;\r
-}\r
-\r
-/**\r
- * Create a new scalar and give a pointer to it\r
- */\r
-gras_datadesc_type_t\r
-gras_datadesc_scalar(const char *name,\r
-                     gras_ddt_scalar_type_t type,\r
-                     enum e_gras_dd_scalar_encoding encoding)\r
-{\r
-\r
-  gras_datadesc_type_t res;\r
-  long int arch;\r
-\r
-  XBT_IN;\r
-  res = gras_datadesc_by_name_or_null(name);\r
-  if (res) {\r
-    xbt_assert1(res->category_code == e_gras_datadesc_type_cat_scalar,\r
-                "Redefinition of type %s does not match", name);\r
-    xbt_assert1(res->category.scalar_data.encoding == encoding,\r
-                "Redefinition of type %s does not match", name);\r
-    xbt_assert1(res->category.scalar_data.type == type,\r
-                "Redefinition of type %s does not match", name);\r
-    VERB1("Discarding redefinition of %s", name);\r
-    return res;\r
-  }\r
-  res = gras_ddt_new(name);\r
-\r
-  for (arch = 0; arch < gras_arch_count; arch++) {\r
-    res->size[arch] = gras_arches[arch].sizeofs[type];\r
-    res->alignment[arch] = gras_arches[arch].boundaries[type];\r
-    res->aligned_size[arch] =\r
-      ddt_aligned(res->size[arch], res->alignment[arch]);\r
-  }\r
-\r
-  res->category_code = e_gras_datadesc_type_cat_scalar;\r
-  res->category.scalar_data.encoding = encoding;\r
-  res->category.scalar_data.type = type;\r
-  XBT_OUT;\r
-\r
-  return res;\r
-}\r
-\r
-\r
-/** Frees one struct or union field */\r
-void gras_dd_cat_field_free(void *f)\r
-{\r
-  gras_dd_cat_field_t field = *(gras_dd_cat_field_t *) f;\r
-  XBT_IN;\r
-  if (field) {\r
-    if (field->name)\r
-      free(field->name);\r
-    free(field);\r
-  }\r
-  XBT_OUT;\r
-}\r
-\r
-/** \brief Declare a new structure description */\r
-gras_datadesc_type_t gras_datadesc_struct(const char *name)\r
-{\r
-\r
-  gras_datadesc_type_t res;\r
-  long int arch;\r
-\r
-  XBT_IN1("(%s)", name);\r
-  res = gras_datadesc_by_name_or_null(name);\r
-  if (res) {\r
-    /* FIXME: Check that field redefinition matches */\r
-    xbt_assert1(res->category_code == e_gras_datadesc_type_cat_struct,\r
-                "Redefinition of type %s does not match", name);\r
-    VERB1("Discarding redefinition of %s", name);\r
-    return res;\r
-  }\r
-  res = gras_ddt_new(name);\r
-\r
-  for (arch = 0; arch < gras_arch_count; arch++) {\r
-    res->size[arch] = 0;\r
-    res->alignment[arch] = 0;\r
-    res->aligned_size[arch] = 0;\r
-  }\r
-  res->category_code = e_gras_datadesc_type_cat_struct;\r
-  res->category.struct_data.fields =\r
-    xbt_dynar_new(sizeof(gras_dd_cat_field_t), gras_dd_cat_field_free);\r
-\r
-  XBT_OUT;\r
-  return res;\r
-}\r
-\r
-/** \brief Append a new field to a structure description */\r
-void\r
-gras_datadesc_struct_append(gras_datadesc_type_t struct_type,\r
-                            const char *name, gras_datadesc_type_t field_type)\r
-{\r
-\r
-  gras_dd_cat_field_t field;\r
-  int arch;\r
-\r
-  xbt_assert2(field_type,\r
-              "Cannot add the field '%s' into struct '%s': its type is NULL",\r
-              name, struct_type->name);\r
-  XBT_IN3("(%s %s.%s;)", field_type->name, struct_type->name, name);\r
-  if (struct_type->category.struct_data.closed) {\r
-    VERB1\r
-      ("Ignoring request to add field to struct %s (closed. Redefinition?)",\r
-       struct_type->name);\r
-    return;\r
-  }\r
-\r
-  xbt_assert1(field_type->size[GRAS_THISARCH] >= 0,\r
-              "Cannot add a dynamically sized field in structure %s",\r
-              struct_type->name);\r
-\r
-  field = xbt_new(s_gras_dd_cat_field_t, 1);\r
-  field->name = (char *) strdup(name);\r
-\r
-  DEBUG0("----------------");\r
-  DEBUG3("PRE s={size=%ld,align=%ld,asize=%ld}",\r
-         struct_type->size[GRAS_THISARCH],\r
-         struct_type->alignment[GRAS_THISARCH],\r
-         struct_type->aligned_size[GRAS_THISARCH]);\r
-\r
-\r
-  for (arch = 0; arch < gras_arch_count; arch++) {\r
-    field->offset[arch] = ddt_aligned(struct_type->size[arch],\r
-                                      field_type->alignment[arch]);\r
-\r
-    struct_type->size[arch] = field->offset[arch] + field_type->size[arch];\r
-    struct_type->alignment[arch] = max(struct_type->alignment[arch],\r
-                                       field_type->alignment[arch]);\r
-    struct_type->aligned_size[arch] = ddt_aligned(struct_type->size[arch],\r
-                                                  struct_type->alignment\r
-                                                  [arch]);\r
-  }\r
-  field->type = field_type;\r
-  field->send = NULL;\r
-  field->recv = NULL;\r
-\r
-  xbt_dynar_push(struct_type->category.struct_data.fields, &field);\r
-\r
-  DEBUG3("Push a %s into %s at offset %ld.",\r
-         field_type->name, struct_type->name, field->offset[GRAS_THISARCH]);\r
-  DEBUG3("  f={size=%ld,align=%ld,asize=%ld}",\r
-         field_type->size[GRAS_THISARCH],\r
-         field_type->alignment[GRAS_THISARCH],\r
-         field_type->aligned_size[GRAS_THISARCH]);\r
-  DEBUG3("  s={size=%ld,align=%ld,asize=%ld}",\r
-         struct_type->size[GRAS_THISARCH],\r
-         struct_type->alignment[GRAS_THISARCH],\r
-         struct_type->aligned_size[GRAS_THISARCH]);\r
-  XBT_OUT;\r
-}\r
-\r
-/** \brief Close a structure description\r
- *\r
- * No new field can be added afterward, and it is mandatory to close the structure before using it.\r
- */\r
-void gras_datadesc_struct_close(gras_datadesc_type_t struct_type)\r
-{\r
-  int arch;\r
-  XBT_IN;\r
-  struct_type->category.struct_data.closed = 1;\r
-  for (arch = 0; arch < gras_arch_count; arch++) {\r
-    struct_type->size[arch] = struct_type->aligned_size[arch];\r
-  }\r
-  DEBUG4("structure %s closed. size=%ld,align=%ld,asize=%ld",\r
-         struct_type->name,\r
-         struct_type->size[GRAS_THISARCH],\r
-         struct_type->alignment[GRAS_THISARCH],\r
-         struct_type->aligned_size[GRAS_THISARCH]);\r
-}\r
-\r
-/**\r
- * gras_datadesc_cycle_set:\r
- *\r
- * Tell GRAS that the pointers of the type described by ddt may present\r
- * some loop, and that the cycle detection mechanism is needed.\r
- *\r
- * Note that setting this option when not needed have a rather bad effect\r
- * on the performance (several times slower on big data).\r
- */\r
-void gras_datadesc_cycle_set(gras_datadesc_type_t ddt)\r
-{\r
-  ddt->cycle = 1;\r
-}\r
-\r
-/**\r
- * gras_datadesc_cycle_unset:\r
- *\r
- * Tell GRAS that the pointers of the type described by ddt do not present\r
- * any loop and that cycle detection mechanism are not needed.\r
- * (default)\r
- */\r
-void gras_datadesc_cycle_unset(gras_datadesc_type_t ddt)\r
-{\r
-  ddt->cycle = 0;\r
-}\r
-\r
-/** \brief Declare a new union description */\r
-gras_datadesc_type_t\r
-gras_datadesc_union(const char *name, gras_datadesc_type_cb_int_t selector)\r
-{\r
-\r
-  gras_datadesc_type_t res;\r
-  int arch;\r
-\r
-  XBT_IN1("(%s)", name);\r
-  xbt_assert0(selector,\r
-              "Attempt to creat an union without field_count function");\r
-\r
-  res = gras_datadesc_by_name_or_null(name);\r
-  if (res) {\r
-    /* FIXME: Check that field redefinition matches */\r
-    xbt_assert1(res->category_code == e_gras_datadesc_type_cat_union,\r
-                "Redefinition of type %s does not match", name);\r
-    xbt_assert1(res->category.union_data.selector == selector,\r
-                "Redefinition of type %s does not match", name);\r
-    VERB1("Discarding redefinition of %s", name);\r
-    return res;\r
-  }\r
-\r
-  res = gras_ddt_new(name);\r
-\r
-  for (arch = 0; arch < gras_arch_count; arch++) {\r
-    res->size[arch] = 0;\r
-    res->alignment[arch] = 0;\r
-    res->aligned_size[arch] = 0;\r
-  }\r
-\r
-  res->category_code = e_gras_datadesc_type_cat_union;\r
-  res->category.union_data.fields =\r
-    xbt_dynar_new(sizeof(gras_dd_cat_field_t *), gras_dd_cat_field_free);\r
-  res->category.union_data.selector = selector;\r
-\r
-  return res;\r
-}\r
-\r
-/** \brief Append a new field to an union description */\r
-void gras_datadesc_union_append(gras_datadesc_type_t union_type,\r
-                                const char *name,\r
-                                gras_datadesc_type_t field_type)\r
-{\r
-\r
-  gras_dd_cat_field_t field;\r
-  int arch;\r
-\r
-  XBT_IN3("(%s %s.%s;)", field_type->name, union_type->name, name);\r
-  xbt_assert1(field_type->size[GRAS_THISARCH] >= 0,\r
-              "Cannot add a dynamically sized field in union %s",\r
-              union_type->name);\r
-\r
-  if (union_type->category.union_data.closed) {\r
-    VERB1("Ignoring request to add field to union %s (closed)",\r
-          union_type->name);\r
-    return;\r
-  }\r
-\r
-  field = xbt_new0(s_gras_dd_cat_field_t, 1);\r
-\r
-  field->name = (char *) strdup(name);\r
-  field->type = field_type;\r
-  /* All offset are left to 0 in an union */\r
-\r
-  xbt_dynar_push(union_type->category.union_data.fields, &field);\r
-\r
-  for (arch = 0; arch < gras_arch_count; arch++) {\r
-    union_type->size[arch] = max(union_type->size[arch],\r
-                                 field_type->size[arch]);\r
-    union_type->alignment[arch] = max(union_type->alignment[arch],\r
-                                      field_type->alignment[arch]);\r
-    union_type->aligned_size[arch] = ddt_aligned(union_type->size[arch],\r
-                                                 union_type->alignment[arch]);\r
-  }\r
-}\r
-\r
-\r
-/** \brief Close an union description\r
- *\r
- * No new field can be added afterward, and it is mandatory to close the union before using it.\r
- */\r
-void gras_datadesc_union_close(gras_datadesc_type_t union_type)\r
-{\r
-  union_type->category.union_data.closed = 1;\r
-}\r
-\r
-/** \brief Copy a type under another name\r
- *\r
- * This may reveal useful to circumvent parsing macro limitations\r
- */\r
-gras_datadesc_type_t\r
-gras_datadesc_copy(const char *name, gras_datadesc_type_t copied)\r
-{\r
-\r
-  gras_datadesc_type_t res = gras_ddt_new(name);\r
-  char *name_cpy = res->name;\r
-\r
-  memcpy(res, copied, sizeof(s_gras_datadesc_type_t));\r
-  res->name = name_cpy;\r
-  return res;\r
-}\r
-\r
-/** \brief Declare a new type being a reference to the one passed in arg */\r
-gras_datadesc_type_t\r
-gras_datadesc_ref(const char *name, gras_datadesc_type_t referenced_type)\r
-{\r
-\r
-  gras_datadesc_type_t res;\r
-  gras_datadesc_type_t pointer_type = gras_datadesc_by_name("data pointer");\r
-  int arch;\r
-\r
-  XBT_IN1("(%s)", name);\r
-  res = gras_datadesc_by_name_or_null(name);\r
-  if (res) {\r
-    xbt_assert1(res->category_code == e_gras_datadesc_type_cat_ref,\r
-                "Redefinition of %s does not match", name);\r
-    xbt_assert1(res->category.ref_data.type == referenced_type,\r
-                "Redefinition of %s does not match", name);\r
-    xbt_assert1(res->category.ref_data.selector == NULL,\r
-                "Redefinition of %s does not match", name);\r
-    VERB1("Discarding redefinition of %s", name);\r
-    return res;\r
-  }\r
-\r
-  res = gras_ddt_new(name);\r
-\r
-  xbt_assert0(pointer_type, "Cannot get the description of data pointer");\r
-\r
-  for (arch = 0; arch < gras_arch_count; arch++) {\r
-    res->size[arch] = pointer_type->size[arch];\r
-    res->alignment[arch] = pointer_type->alignment[arch];\r
-    res->aligned_size[arch] = pointer_type->aligned_size[arch];\r
-  }\r
-\r
-  res->category_code = e_gras_datadesc_type_cat_ref;\r
-  res->category.ref_data.type = referenced_type;\r
-  res->category.ref_data.selector = NULL;\r
-\r
-  return res;\r
-}\r
-\r
-/** \brief Declare a new type being a generic reference.\r
- *\r
- * The callback passed in argument is to be used to select which type is currently used.\r
- * So, when GRAS wants to send a generic reference, it passes the current data to the selector\r
- * callback and expects it to return the type description to use.\r
- */\r
-gras_datadesc_type_t\r
-gras_datadesc_ref_generic(const char *name, gras_datadesc_selector_t selector)\r
-{\r
-\r
-  gras_datadesc_type_t res;\r
-  gras_datadesc_type_t pointer_type = gras_datadesc_by_name("data pointer");\r
-  int arch;\r
-\r
-  XBT_IN1("(%s)", name);\r
-  res = gras_datadesc_by_name_or_null(name);\r
-\r
-  if (res) {\r
-    xbt_assert1(res->category_code == e_gras_datadesc_type_cat_ref,\r
-                "Redefinition of type %s does not match", name);\r
-    xbt_assert1(res->category.ref_data.type == NULL,\r
-                "Redefinition of type %s does not match", name);\r
-    xbt_assert1(res->category.ref_data.selector == selector,\r
-                "Redefinition of type %s does not match", name);\r
-    VERB1("Discarding redefinition of %s", name);\r
-    return res;\r
-  }\r
-  res = gras_ddt_new(name);\r
-\r
-  xbt_assert0(pointer_type, "Cannot get the description of data pointer");\r
-\r
-  for (arch = 0; arch < gras_arch_count; arch++) {\r
-    res->size[arch] = pointer_type->size[arch];\r
-    res->alignment[arch] = pointer_type->alignment[arch];\r
-    res->aligned_size[arch] = pointer_type->aligned_size[arch];\r
-  }\r
-\r
-  res->category_code = e_gras_datadesc_type_cat_ref;\r
-\r
-  res->category.ref_data.type = NULL;\r
-  res->category.ref_data.selector = selector;\r
-\r
-  return res;\r
-}\r
-\r
-/** \brief Declare a new type being an array of fixed size and content */\r
-gras_datadesc_type_t\r
-gras_datadesc_array_fixed(const char *name,\r
-                          gras_datadesc_type_t element_type,\r
-                          long int fixed_size)\r
-{\r
-\r
-  gras_datadesc_type_t res;\r
-  int arch;\r
-\r
-  XBT_IN1("(%s)", name);\r
-  res = gras_datadesc_by_name_or_null(name);\r
-  if (res) {\r
-    xbt_assert1(res->category_code == e_gras_datadesc_type_cat_array,\r
-                "Redefinition of type %s does not match", name);\r
-\r
-    if (res->category.array_data.type != element_type) {\r
-      ERROR1("Redefinition of type %s does not match: array elements differ",\r
-             name);\r
-      gras_datadesc_type_dump(res->category.array_data.type);\r
-      gras_datadesc_type_dump(element_type);\r
-    }\r
-\r
-    xbt_assert1(res->category.array_data.fixed_size == fixed_size,\r
-                "Redefinition of type %s does not match", name);\r
-    xbt_assert1(res->category.array_data.dynamic_size == NULL,\r
-                "Redefinition of type %s does not match", name);\r
-    VERB1("Discarding redefinition of %s", name);\r
-\r
-    return res;\r
-  }\r
-  res = gras_ddt_new(name);\r
-\r
-  xbt_assert1(fixed_size >= 0, "'%s' is a array of negative fixed size",\r
-              name);\r
-  for (arch = 0; arch < gras_arch_count; arch++) {\r
-    res->size[arch] = fixed_size * element_type->aligned_size[arch];\r
-    res->alignment[arch] = element_type->alignment[arch];\r
-    res->aligned_size[arch] = res->size[arch];\r
-  }\r
-\r
-  res->category_code = e_gras_datadesc_type_cat_array;\r
-\r
-  res->category.array_data.type = element_type;\r
-  res->category.array_data.fixed_size = fixed_size;\r
-  res->category.array_data.dynamic_size = NULL;\r
-\r
-  return res;\r
-}\r
-\r
-/** \brief Declare a new type being an array of fixed size, but accepting several content types. */\r
-gras_datadesc_type_t gras_datadesc_array_dyn(const char *name,\r
-                                             gras_datadesc_type_t\r
-                                             element_type,\r
-                                             gras_datadesc_type_cb_int_t\r
-                                             dynamic_size)\r
-{\r
-\r
-  gras_datadesc_type_t res;\r
-  int arch;\r
-\r
-  XBT_IN1("(%s)", name);\r
-  xbt_assert1(dynamic_size,\r
-              "'%s' is a dynamic array without size discriminant", name);\r
-\r
-  res = gras_datadesc_by_name_or_null(name);\r
-  if (res) {\r
-    xbt_assert1(res->category_code == e_gras_datadesc_type_cat_array,\r
-                "Redefinition of type %s does not match", name);\r
-    xbt_assert1(res->category.array_data.type == element_type,\r
-                "Redefinition of type %s does not match", name);\r
-    xbt_assert1(res->category.array_data.fixed_size == -1,\r
-                "Redefinition of type %s does not match", name);\r
-    xbt_assert1(res->category.array_data.dynamic_size == dynamic_size,\r
-                "Redefinition of type %s does not match", name);\r
-    VERB1("Discarding redefinition of %s", name);\r
-\r
-    return res;\r
-  }\r
-\r
-  res = gras_ddt_new(name);\r
-\r
-  for (arch = 0; arch < gras_arch_count; arch++) {\r
-    res->size[arch] = 0;        /* make sure it indicates "dynamic" */\r
-    res->alignment[arch] = element_type->alignment[arch];\r
-    res->aligned_size[arch] = 0;        /*FIXME: That was so in GS, but looks stupid */\r
-  }\r
-\r
-  res->category_code = e_gras_datadesc_type_cat_array;\r
-\r
-  res->category.array_data.type = element_type;\r
-  res->category.array_data.fixed_size = -1;\r
-  res->category.array_data.dynamic_size = dynamic_size;\r
-\r
-  return res;\r
-}\r
-\r
-/** \brief Declare a new type being an array which size can be found with \ref gras_cbps_i_pop\r
- *\r
- * Most of the time, you want to include a reference in your structure which\r
- * is a pointer to a dynamic array whose size is fixed by another field of\r
- * your structure.\r
- *\r
- * This case pops up so often that this function was created to take care of\r
- * this case. It creates a dynamic array type whose size is poped from the\r
- * current cbps, and then create a reference to it.\r
- *\r
- * The name of the created datatype will be the name of the element type, with\r
- * '[]*' appended to it.\r
- *\r
- * Then to use it, you just have to make sure that your structure pre-callback\r
- * does push the size of the array in the cbps (using #gras_cbps_i_push), and\r
- * you are set.\r
- *\r
- * But be remember that this is a stack. If you have two different pop_arr, you\r
- * should push the second one first, so that the first one is on the top of the\r
- * list when the first field gets transfered.\r
- *\r
- */\r
-gras_datadesc_type_t\r
-gras_datadesc_ref_pop_arr(gras_datadesc_type_t element_type)\r
-{\r
-  int cpt=0;\r
-  gras_datadesc_type_t res,ddt2;\r
-  char *name = (char *) xbt_malloc(strlen(element_type->name) + 4);\r
-\r
-  sprintf(name, "%s[]", element_type->name);\r
-  /* Make sure we are not trying to redefine a ddt with the same name */\r
-  ddt2 = gras_datadesc_by_name_or_null(name);\r
-\r
-  while (ddt2) {\r
-    free(name);\r
-    name=bprintf("%s[]_%d",element_type->name,cpt++);\r
-    ddt2=gras_datadesc_by_name_or_null(name);\r
-  }\r
-\r
-  res = gras_datadesc_array_dyn(name, element_type, gras_datadesc_cb_pop);\r
-\r
-  sprintf(name, "%s[]*", element_type->name);\r
-  cpt=0;\r
-  ddt2 = gras_datadesc_by_name_or_null(name);\r
-  while (ddt2) {\r
-    free(name);\r
-    name=bprintf("%s[]*_%d",element_type->name,cpt++);\r
-    ddt2=gras_datadesc_by_name_or_null(name);\r
-  }\r
-\r
-  res = gras_datadesc_ref(name, res);\r
-\r
-  free(name);\r
-\r
-  return res;\r
-}\r
-\r
-/*\r
- *##\r
- *## Constructor of container datatypes\r
- *##\r
- */\r
-\r
-static void gras_datadesc_dynar_cb(gras_datadesc_type_t typedesc,\r
-                                   gras_cbps_t vars, void *data)\r
-{\r
-  gras_datadesc_type_t subtype;\r
-  xbt_dynar_t dynar = (xbt_dynar_t) data;\r
-\r
-  memcpy(&dynar->free_f, &typedesc->extra, sizeof(dynar->free_f));\r
-\r
-  /* search for the elemsize in what we have. If elements are "int", typedesc got is "int[]*" */\r
-  subtype = gras_dd_find_field(typedesc, "data")->type;\r
-\r
-  /* this is now a ref to array of what we're looking for */\r
-  subtype = subtype->category.ref_data.type;\r
-  subtype = subtype->category.array_data.type;\r
-\r
-  DEBUG1("subtype is %s", subtype->name);\r
-\r
-  dynar->elmsize = subtype->size[GRAS_THISARCH];\r
-  dynar->size = dynar->used;\r
-  dynar->mutex = NULL;\r
-}\r
-\r
-/** \brief Declare a new type being a dynar in which each elements are of the given type\r
- *\r
- *  The type gets registered under the name "dynar(%s)_s", where %s is the name of the subtype.\r
- *  For example, a dynar of doubles will be called "dynar(double)_s" and a dynar of dynar of\r
- *  strings will be called "dynar(dynar(string)_s)_s".\r
- *\r
- *  \param elm_t: the datadesc of the elements\r
- *  \param free_func: the function to use to free the elements when the dynar gets freed\r
- */\r
-gras_datadesc_type_t\r
-gras_datadesc_dynar(gras_datadesc_type_t elm_t, void_f_pvoid_t free_func)\r
-{\r
-\r
-  char *buffname;\r
-  gras_datadesc_type_t res;\r
-\r
-  asprintf(&buffname, "s_xbt_dynar_of_%s", elm_t->name);\r
-\r
-  res = gras_datadesc_struct(buffname);\r
-\r
-  gras_datadesc_struct_append(res, "size",\r
-                              gras_datadesc_by_name("unsigned long int"));\r
-\r
-  gras_datadesc_struct_append(res, "used",\r
-                              gras_datadesc_by_name("unsigned long int"));\r
-\r
-  gras_datadesc_struct_append(res, "elmsize",\r
-                              gras_datadesc_by_name("unsigned long int"));\r
-\r
-  gras_datadesc_struct_append(res, "data", gras_datadesc_ref_pop_arr(elm_t));\r
-\r
-  gras_datadesc_struct_append(res, "free_f",\r
-                              gras_datadesc_by_name("function pointer"));\r
-  memcpy(res->extra, &free_func, sizeof(free_func));\r
-\r
-  gras_datadesc_struct_append(res, "mutex",\r
-                              gras_datadesc_by_name("data pointer"));\r
-\r
-  gras_datadesc_struct_close(res);\r
-\r
-  gras_datadesc_cb_field_push(res, "used");\r
-  gras_datadesc_cb_recv(res, &gras_datadesc_dynar_cb);\r
-\r
-  /* build a ref to it */\r
-  free(buffname);\r
-  asprintf(&buffname, "xbt_dynar_of_%s", elm_t->name);\r
-  res = gras_datadesc_ref(buffname, res);\r
-  free(buffname);\r
-  return res;\r
-}\r
-\r
-#include "xbt/matrix.h"\r
-static void gras_datadesc_matrix_cb(gras_datadesc_type_t typedesc,\r
-                                    gras_cbps_t vars, void *data)\r
-{\r
-  gras_datadesc_type_t subtype;\r
-  xbt_matrix_t matrix = (xbt_matrix_t) data;\r
-\r
-  memcpy(&matrix->free_f, &typedesc->extra, sizeof(matrix->free_f));\r
-\r
-  /* search for the elemsize in what we have. If elements are "int", typedesc got is "int[]*" */\r
-  subtype = gras_dd_find_field(typedesc, "data")->type;\r
-\r
-  /* this is now a ref to array of what we're looking for */\r
-  subtype = subtype->category.ref_data.type;\r
-  subtype = subtype->category.array_data.type;\r
-\r
-  DEBUG1("subtype is %s", subtype->name);\r
-\r
-  matrix->elmsize = subtype->size[GRAS_THISARCH];\r
-}\r
-\r
-gras_datadesc_type_t\r
-gras_datadesc_matrix(gras_datadesc_type_t elm_t, void_f_pvoid_t const free_f)\r
-{\r
-  char *buffname;\r
-  gras_datadesc_type_t res;\r
-\r
-  asprintf(&buffname, "s_xbt_matrix_t(%s)", elm_t->name);\r
-  res = gras_datadesc_struct(buffname);\r
-\r
-  gras_datadesc_struct_append(res, "lines",\r
-                              gras_datadesc_by_name("unsigned int"));\r
-  gras_datadesc_struct_append(res, "rows",\r
-                              gras_datadesc_by_name("unsigned int"));\r
-\r
-  gras_datadesc_struct_append(res, "elmsize",\r
-                              gras_datadesc_by_name("unsigned long int"));\r
-\r
-  gras_datadesc_struct_append(res, "data", gras_datadesc_ref_pop_arr(elm_t));\r
-  gras_datadesc_struct_append(res, "free_f",\r
-                              gras_datadesc_by_name("function pointer"));\r
-  gras_datadesc_struct_close(res);\r
-\r
-  gras_datadesc_cb_field_push(res, "lines");\r
-  gras_datadesc_cb_field_push_multiplier(res, "rows");\r
-\r
-  gras_datadesc_cb_recv(res, &gras_datadesc_matrix_cb);\r
-  memcpy(res->extra, &free_f, sizeof(free_f));\r
-\r
-  /* build a ref to it */\r
-  free(buffname);\r
-  asprintf(&buffname, "xbt_matrix_t(%s)", elm_t->name);\r
-  res = gras_datadesc_ref(buffname, res);\r
-  free(buffname);\r
-  return res;\r
-}\r
-\r
-gras_datadesc_type_t\r
-gras_datadesc_import_nws(const char *name,\r
-                         const DataDescriptor * desc, unsigned long howmany)\r
-{\r
-  THROW_UNIMPLEMENTED;\r
-}\r
-\r
-/**\r
- * (useful to push the sizes of the upcoming arrays, for example)\r
- */\r
-void gras_datadesc_cb_send(gras_datadesc_type_t type,\r
-                           gras_datadesc_type_cb_void_t send)\r
-{\r
-  type->send = send;\r
-}\r
-\r
-/**\r
- * (useful to put the function pointers to the rigth value, for example)\r
- */\r
-void gras_datadesc_cb_recv(gras_datadesc_type_t type,\r
-                           gras_datadesc_type_cb_void_t recv)\r
-{\r
-  type->recv = recv;\r
-}\r
-\r
-/*\r
- * gras_dd_find_field:\r
- *\r
- * Returns the type descriptor of the given field. Abort on error.\r
- */\r
-static gras_dd_cat_field_t\r
-gras_dd_find_field(gras_datadesc_type_t type, const char *field_name)\r
-{\r
-  xbt_dynar_t field_array;\r
-\r
-  gras_dd_cat_field_t field = NULL;\r
-  unsigned int field_num;\r
-\r
-  if (type->category_code == e_gras_datadesc_type_cat_union) {\r
-    field_array = type->category.union_data.fields;\r
-  } else if (type->category_code == e_gras_datadesc_type_cat_struct) {\r
-    field_array = type->category.struct_data.fields;\r
-  } else {\r
-    ERROR2("%s (%p) is not a struct nor an union. There is no field.",\r
-           type->name, (void *) type);\r
-    xbt_abort();\r
-  }\r
-  xbt_dynar_foreach(field_array, field_num, field) {\r
-    if (!strcmp(field_name, field->name)) {\r
-      return field;\r
-    }\r
-  }\r
-  ERROR2("No field named '%s' in '%s'", field_name, type->name);\r
-  xbt_abort();\r
-\r
-}\r
-\r
-/**\r
- * The given datadesc must be a struct or union (abort if not).\r
- * (useful to push the sizes of the upcoming arrays, for example)\r
- */\r
-void gras_datadesc_cb_field_send(gras_datadesc_type_t type,\r
-                                 const char *field_name,\r
-                                 gras_datadesc_type_cb_void_t send)\r
-{\r
-\r
-  gras_dd_cat_field_t field = gras_dd_find_field(type, field_name);\r
-  field->send = send;\r
-}\r
-\r
-\r
-/**\r
- * The value, which must be an int, unsigned int, long int or unsigned long int\r
- * is pushed to the stacks of sizes and can then be retrieved with\r
- * \ref gras_datadesc_ref_pop_arr or directly with \ref gras_cbps_i_pop.\r
- */\r
-void gras_datadesc_cb_field_push(gras_datadesc_type_t type,\r
-                                 const char *field_name)\r
-{\r
-\r
-  gras_dd_cat_field_t field = gras_dd_find_field(type, field_name);\r
-  gras_datadesc_type_t sub_type = field->type;\r
-\r
-  DEBUG3("add a PUSHy cb to '%s' field (type '%s') of '%s'",\r
-         field_name, sub_type->name, type->name);\r
-  if (!strcmp("int", sub_type->name)) {\r
-    field->send = gras_datadesc_cb_push_int;\r
-  } else if (!strcmp("unsigned int", sub_type->name)) {\r
-    field->send = gras_datadesc_cb_push_uint;\r
-  } else if (!strcmp("long int", sub_type->name)) {\r
-    field->send = gras_datadesc_cb_push_lint;\r
-  } else if (!strcmp("unsigned long int", sub_type->name)) {\r
-    field->send = gras_datadesc_cb_push_ulint;\r
-  } else {\r
-    ERROR1\r
-      ("Field %s is not an int, unsigned int, long int neither unsigned long int",\r
-       sub_type->name);\r
-    xbt_abort();\r
-  }\r
-}\r
-\r
-/**\r
- * Any previously pushed value is poped and the field value is multiplied to\r
- * it. The result is then pushed back into the stack of sizes. It can then be\r
- * retrieved with \ref gras_datadesc_ref_pop_arr or directly with \ref\r
- * gras_cbps_i_pop.\r
- *\r
- * The field must be an int, unsigned int, long int or unsigned long int.\r
- */\r
-void gras_datadesc_cb_field_push_multiplier(gras_datadesc_type_t type,\r
-                                            const char *field_name)\r
-{\r
-\r
-  gras_dd_cat_field_t field = gras_dd_find_field(type, field_name);\r
-  gras_datadesc_type_t sub_type = field->type;\r
-\r
-  DEBUG3("add a MPUSHy cb to '%s' field (type '%s') of '%s'",\r
-         field_name, sub_type->name, type->name);\r
-  if (!strcmp("int", sub_type->name)) {\r
-    field->send = gras_datadesc_cb_push_int_mult;\r
-  } else if (!strcmp("unsigned int", sub_type->name)) {\r
-    field->send = gras_datadesc_cb_push_uint_mult;\r
-  } else if (!strcmp("long int", sub_type->name)) {\r
-    field->send = gras_datadesc_cb_push_lint_mult;\r
-  } else if (!strcmp("unsigned long int", sub_type->name)) {\r
-    field->send = gras_datadesc_cb_push_ulint_mult;\r
-  } else {\r
-    ERROR1\r
-      ("Field %s is not an int, unsigned int, long int neither unsigned long int",\r
-       sub_type->name);\r
-    xbt_abort();\r
-  }\r
-}\r
-\r
-/**\r
- * The given datadesc must be a struct or union (abort if not).\r
- * (useful to put the function pointers to the right value, for example)\r
- */\r
-void gras_datadesc_cb_field_recv(gras_datadesc_type_t type,\r
-                                 const char *field_name,\r
-                                 gras_datadesc_type_cb_void_t recv)\r
-{\r
-\r
-  gras_dd_cat_field_t field = gras_dd_find_field(type, field_name);\r
-  field->recv = recv;\r
-}\r
-\r
-/*\r
- * Free a datadesc. Should only be called at xbt_exit.\r
- */\r
-void gras_datadesc_free(gras_datadesc_type_t * type)\r
-{\r
-\r
-  DEBUG1("Let's free ddt %s", (*type)->name);\r
-\r
-  switch ((*type)->category_code) {\r
-  case e_gras_datadesc_type_cat_scalar:\r
-  case e_gras_datadesc_type_cat_ref:\r
-  case e_gras_datadesc_type_cat_array:\r
-    /* nothing to free in there */\r
-    break;\r
-\r
-  case e_gras_datadesc_type_cat_struct:\r
-    xbt_dynar_free(&((*type)->category.struct_data.fields));\r
-    break;\r
-\r
-  case e_gras_datadesc_type_cat_union:\r
-    xbt_dynar_free(&((*type)->category.union_data.fields));\r
-    break;\r
-\r
-  default:\r
-    /* datadesc was invalid. Killing it is like euthanasy, I guess */\r
-    break;\r
-  }\r
-  free((*type)->name);\r
-  free(*type);\r
-  type = NULL;\r
-}\r
-\r
-/**\r
- * gras_datadesc_type_cmp:\r
- *\r
- * Compares two datadesc types with the same semantic than strcmp.\r
- *\r
- * This comparison does not take the set headers into account (name and ID),\r
- * but only the payload (actual type description).\r
- */\r
-int gras_datadesc_type_cmp(const gras_datadesc_type_t d1,\r
-                           const gras_datadesc_type_t d2)\r
-{\r
-  int ret;\r
-  unsigned int cpt;\r
-  gras_dd_cat_field_t field1, field2;\r
-  gras_datadesc_type_t field_desc_1, field_desc_2;\r
-\r
-  if (d1 == d2)\r
-    return 0;                   /* easy optimization */\r
-\r
-  if (!d1 && d2) {\r
-    DEBUG0("ddt_cmp: !d1 && d2 => 1");\r
-    return 1;\r
-  }\r
-  if (!d1 && !d2) {\r
-    DEBUG0("ddt_cmp: !d1 && !d2 => 0");\r
-    return 0;\r
-  }\r
-  if (d1 && !d2) {\r
-    DEBUG0("ddt_cmp: d1 && !d2 => -1");\r
-    return -1;\r
-  }\r
-\r
-  for (cpt = 0; cpt < gras_arch_count; cpt++) {\r
-    if (d1->size[cpt] != d2->size[cpt]) {\r
-      DEBUG5("ddt_cmp: %s->size=%ld  !=  %s->size=%ld (on %s)",\r
-             d1->name, d1->size[cpt], d2->name, d2->size[cpt],\r
-             gras_arches[cpt].name);\r
-      return d1->size[cpt] > d2->size[cpt] ? 1 : -1;\r
-    }\r
-\r
-    if (d1->alignment[cpt] != d2->alignment[cpt]) {\r
-      DEBUG5("ddt_cmp: %s->alignment=%ld  !=  %s->alignment=%ld (on %s)",\r
-             d1->name, d1->alignment[cpt], d2->name, d2->alignment[cpt],\r
-             gras_arches[cpt].name);\r
-      return d1->alignment[cpt] > d2->alignment[cpt] ? 1 : -1;\r
-    }\r
-\r
-    if (d1->aligned_size[cpt] != d2->aligned_size[cpt]) {\r
-      DEBUG5\r
-        ("ddt_cmp: %s->aligned_size=%ld  !=  %s->aligned_size=%ld (on %s)",\r
-         d1->name, d1->aligned_size[cpt], d2->name, d2->aligned_size[cpt],\r
-         gras_arches[cpt].name);\r
-      return d1->aligned_size[cpt] > d2->aligned_size[cpt] ? 1 : -1;\r
-    }\r
-  }\r
-\r
-  if (d1->category_code != d2->category_code) {\r
-    DEBUG4("ddt_cmp: %s->cat=%s  !=  %s->cat=%s",\r
-           d1->name, gras_datadesc_cat_names[d1->category_code],\r
-           d2->name, gras_datadesc_cat_names[d2->category_code]);\r
-    return d1->category_code > d2->category_code ? 1 : -1;\r
-  }\r
-\r
-  if (d1->send != d2->send) {\r
-    DEBUG4("ddt_cmp: %s->send=%p  !=  %s->send=%p",\r
-           d1->name, (void *) d1->send, d2->name, (void *) d2->send);\r
-    return 1;                   /* ISO C forbids ordered comparisons of pointers to functions */\r
-  }\r
-\r
-  if (d1->recv != d2->recv) {\r
-    DEBUG4("ddt_cmp: %s->recv=%p  !=  %s->recv=%p",\r
-           d1->name, (void *) d1->recv, d2->name, (void *) d2->recv);\r
-    return 1;                   /* ISO C forbids ordered comparisons of pointers to functions */\r
-  }\r
-\r
-  switch (d1->category_code) {\r
-  case e_gras_datadesc_type_cat_scalar:\r
-    if (d1->category.scalar_data.encoding !=\r
-        d2->category.scalar_data.encoding)\r
-      return d1->category.scalar_data.encoding >\r
-        d2->category.scalar_data.encoding ? 1 : -1;\r
-    break;\r
-\r
-  case e_gras_datadesc_type_cat_struct:\r
-    if (xbt_dynar_length(d1->category.struct_data.fields) !=\r
-        xbt_dynar_length(d2->category.struct_data.fields)) {\r
-      DEBUG4("ddt_cmp: %s (having %lu fields) !=  %s (having %lu fields)",\r
-             d1->name, xbt_dynar_length(d1->category.struct_data.fields),\r
-             d2->name, xbt_dynar_length(d2->category.struct_data.fields));\r
-\r
-      return xbt_dynar_length(d1->category.struct_data.fields) >\r
-        xbt_dynar_length(d2->category.struct_data.fields) ? 1 : -1;\r
-    }\r
-    xbt_dynar_foreach(d1->category.struct_data.fields, cpt, field1) {\r
-\r
-      field2 =\r
-        xbt_dynar_get_as(d2->category.struct_data.fields, cpt,\r
-                         gras_dd_cat_field_t);\r
-      field_desc_1 = field1->type;\r
-      field_desc_2 = field2->type;\r
-      ret = gras_datadesc_type_cmp(field_desc_1, field_desc_2);\r
-      if (ret) {\r
-        DEBUG6("%s->field[%d]=%s != %s->field[%d]=%s",\r
-               d1->name, cpt, field1->name, d2->name, cpt, field2->name);\r
-        return ret;\r
-      }\r
-\r
-    }\r
-    break;\r
-\r
-  case e_gras_datadesc_type_cat_union:\r
-    if (d1->category.union_data.selector != d2->category.union_data.selector)\r
-      return 1;                 /* ISO C forbids ordered comparisons of pointers to functions */\r
-\r
-    if (xbt_dynar_length(d1->category.union_data.fields) !=\r
-        xbt_dynar_length(d2->category.union_data.fields))\r
-      return xbt_dynar_length(d1->category.union_data.fields) >\r
-        xbt_dynar_length(d2->category.union_data.fields) ? 1 : -1;\r
-\r
-    xbt_dynar_foreach(d1->category.union_data.fields, cpt, field1) {\r
-\r
-      field2 =\r
-        xbt_dynar_get_as(d2->category.union_data.fields, cpt,\r
-                         gras_dd_cat_field_t);\r
-      field_desc_1 = field1->type;\r
-      field_desc_2 = field2->type;\r
-      ret = gras_datadesc_type_cmp(field_desc_1, field_desc_2);\r
-      if (ret)\r
-        return ret;\r
-\r
-    }\r
-    break;\r
-\r
-\r
-  case e_gras_datadesc_type_cat_ref:\r
-    if (d1->category.ref_data.selector != d2->category.ref_data.selector)\r
-      return 1;                 /* ISO C forbids ordered comparisons of pointers to functions */\r
-\r
-    if (d1->category.ref_data.type != d2->category.ref_data.type)\r
-      return d1->category.ref_data.type > d2->category.ref_data.type ? 1 : -1;\r
-    break;\r
-\r
-  case e_gras_datadesc_type_cat_array:\r
-    if (d1->category.array_data.type != d2->category.array_data.type)\r
-      return d1->category.array_data.type >\r
-        d2->category.array_data.type ? 1 : -1;\r
-\r
-    if (d1->category.array_data.fixed_size !=\r
-        d2->category.array_data.fixed_size)\r
-      return d1->category.array_data.fixed_size >\r
-        d2->category.array_data.fixed_size ? 1 : -1;\r
-\r
-    if (d1->category.array_data.dynamic_size !=\r
-        d2->category.array_data.dynamic_size)\r
-      return 1;                 /* ISO C forbids ordered comparisons of pointers to functions */\r
-\r
-    break;\r
-\r
-  default:\r
-    /* two stupidly created ddt are equally stupid ;) */\r
-    break;\r
-  }\r
-  return 0;\r
-\r
-}\r
+/* ddt_new - creation/deletion of datatypes structs (private to this module)*/
+
+/* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "xbt/misc.h"           /* min()/max() */
+#include "xbt/ex.h"
+#include "gras/DataDesc/datadesc_private.h"
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_ddt_create, gras_ddt,
+                                "Creating new datadescriptions");
+
+/*** prototypes ***/
+static gras_dd_cat_field_t
+gras_dd_find_field(gras_datadesc_type_t type, const char *field_name);
+/**
+ * gras_ddt_freev:
+ *
+ * gime that memory back, dude. I mean it.
+ */
+void gras_ddt_freev(void *ddt)
+{
+  gras_datadesc_type_t type = (gras_datadesc_type_t) ddt;
+
+  if (type) {
+    gras_datadesc_free(&type);
+  }
+}
+
+static gras_datadesc_type_t gras_ddt_new(const char *name)
+{
+  gras_datadesc_type_t res;
+
+  XBT_IN1("(%s)", name);
+  res = xbt_new0(s_gras_datadesc_type_t, 1);
+
+  res->name = (char *) strdup(name);
+  res->name_len = strlen(name);
+  res->cycle = 0;
+
+  xbt_set_add(gras_datadesc_set_local, (xbt_set_elm_t) res, gras_ddt_freev);
+  XBT_OUT;
+  return res;
+}
+
+/** @brief retrieve an existing message type from its name (or NULL if it does not exist). */
+gras_datadesc_type_t gras_datadesc_by_name_or_null(const char *name)
+{
+  xbt_ex_t e;
+  gras_datadesc_type_t res = NULL;
+
+  TRY {
+    res = gras_datadesc_by_name(name);
+  } CATCH(e) {
+    res = NULL;
+    xbt_ex_free(e);
+  }
+  return res;
+}
+
+/**
+ * Search the given datadesc (or raises an exception if it can't be found)
+ */
+gras_datadesc_type_t gras_datadesc_by_name(const char *name)
+{
+  xbt_ex_t e;
+  gras_datadesc_type_t res = NULL;
+  volatile int found = 0;
+  TRY {
+    res =
+      (gras_datadesc_type_t) xbt_set_get_by_name(gras_datadesc_set_local,
+                                                 name);
+    found = 1;
+  } CATCH(e) {
+    if (e.category != not_found_error)
+      RETHROW;
+    xbt_ex_free(e);
+  }
+  if (!found)
+    THROW1(not_found_error, 0, "No registred datatype of that name: %s",
+           name);
+
+  return res;
+}
+
+/**
+ * Retrieve a type from its code (or NULL if not found)
+ */
+gras_datadesc_type_t gras_datadesc_by_id(long int code)
+{
+  xbt_ex_t e;
+  gras_datadesc_type_t res = NULL;
+  TRY {
+    res =
+      (gras_datadesc_type_t) xbt_set_get_by_id(gras_datadesc_set_local, code);
+  } CATCH(e) {
+    if (e.category != not_found_error)
+      RETHROW;
+    xbt_ex_free(e);
+    res = NULL;
+  }
+  return res;
+}
+
+/**
+ * Create a new scalar and give a pointer to it
+ */
+gras_datadesc_type_t
+gras_datadesc_scalar(const char *name,
+                     gras_ddt_scalar_type_t type,
+                     enum e_gras_dd_scalar_encoding encoding)
+{
+
+  gras_datadesc_type_t res;
+  long int arch;
+
+  XBT_IN;
+  res = gras_datadesc_by_name_or_null(name);
+  if (res) {
+    xbt_assert1(res->category_code == e_gras_datadesc_type_cat_scalar,
+                "Redefinition of type %s does not match", name);
+    xbt_assert1(res->category.scalar_data.encoding == encoding,
+                "Redefinition of type %s does not match", name);
+    xbt_assert1(res->category.scalar_data.type == type,
+                "Redefinition of type %s does not match", name);
+    VERB1("Discarding redefinition of %s", name);
+    return res;
+  }
+  res = gras_ddt_new(name);
+
+  for (arch = 0; arch < gras_arch_count; arch++) {
+    res->size[arch] = gras_arches[arch].sizeofs[type];
+    res->alignment[arch] = gras_arches[arch].boundaries[type];
+    res->aligned_size[arch] =
+      ddt_aligned(res->size[arch], res->alignment[arch]);
+  }
+
+  res->category_code = e_gras_datadesc_type_cat_scalar;
+  res->category.scalar_data.encoding = encoding;
+  res->category.scalar_data.type = type;
+  XBT_OUT;
+
+  return res;
+}
+
+
+/** Frees one struct or union field */
+void gras_dd_cat_field_free(void *f)
+{
+  gras_dd_cat_field_t field = *(gras_dd_cat_field_t *) f;
+  XBT_IN;
+  if (field) {
+    if (field->name)
+      free(field->name);
+    free(field);
+  }
+  XBT_OUT;
+}
+
+/** \brief Declare a new structure description */
+gras_datadesc_type_t gras_datadesc_struct(const char *name)
+{
+
+  gras_datadesc_type_t res;
+  long int arch;
+
+  XBT_IN1("(%s)", name);
+  res = gras_datadesc_by_name_or_null(name);
+  if (res) {
+    /* FIXME: Check that field redefinition matches */
+    xbt_assert1(res->category_code == e_gras_datadesc_type_cat_struct,
+                "Redefinition of type %s does not match", name);
+    VERB1("Discarding redefinition of %s", name);
+    return res;
+  }
+  res = gras_ddt_new(name);
+
+  for (arch = 0; arch < gras_arch_count; arch++) {
+    res->size[arch] = 0;
+    res->alignment[arch] = 0;
+    res->aligned_size[arch] = 0;
+  }
+  res->category_code = e_gras_datadesc_type_cat_struct;
+  res->category.struct_data.fields =
+    xbt_dynar_new(sizeof(gras_dd_cat_field_t), gras_dd_cat_field_free);
+
+  XBT_OUT;
+  return res;
+}
+
+/** \brief Append a new field to a structure description */
+void
+gras_datadesc_struct_append(gras_datadesc_type_t struct_type,
+                            const char *name, gras_datadesc_type_t field_type)
+{
+
+  gras_dd_cat_field_t field;
+  int arch;
+
+  xbt_assert2(field_type,
+              "Cannot add the field '%s' into struct '%s': its type is NULL",
+              name, struct_type->name);
+  XBT_IN3("(%s %s.%s;)", field_type->name, struct_type->name, name);
+  if (struct_type->category.struct_data.closed) {
+    VERB1
+      ("Ignoring request to add field to struct %s (closed. Redefinition?)",
+       struct_type->name);
+    return;
+  }
+
+  xbt_assert1(field_type->size[GRAS_THISARCH] >= 0,
+              "Cannot add a dynamically sized field in structure %s",
+              struct_type->name);
+
+  field = xbt_new(s_gras_dd_cat_field_t, 1);
+  field->name = (char *) strdup(name);
+
+  DEBUG0("----------------");
+  DEBUG3("PRE s={size=%ld,align=%ld,asize=%ld}",
+         struct_type->size[GRAS_THISARCH],
+         struct_type->alignment[GRAS_THISARCH],
+         struct_type->aligned_size[GRAS_THISARCH]);
+
+
+  for (arch = 0; arch < gras_arch_count; arch++) {
+    field->offset[arch] = ddt_aligned(struct_type->size[arch],
+                                      field_type->alignment[arch]);
+
+    struct_type->size[arch] = field->offset[arch] + field_type->size[arch];
+    struct_type->alignment[arch] = max(struct_type->alignment[arch],
+                                       field_type->alignment[arch]);
+    struct_type->aligned_size[arch] = ddt_aligned(struct_type->size[arch],
+                                                  struct_type->alignment
+                                                  [arch]);
+  }
+  field->type = field_type;
+  field->send = NULL;
+  field->recv = NULL;
+
+  xbt_dynar_push(struct_type->category.struct_data.fields, &field);
+
+  DEBUG3("Push a %s into %s at offset %ld.",
+         field_type->name, struct_type->name, field->offset[GRAS_THISARCH]);
+  DEBUG3("  f={size=%ld,align=%ld,asize=%ld}",
+         field_type->size[GRAS_THISARCH],
+         field_type->alignment[GRAS_THISARCH],
+         field_type->aligned_size[GRAS_THISARCH]);
+  DEBUG3("  s={size=%ld,align=%ld,asize=%ld}",
+         struct_type->size[GRAS_THISARCH],
+         struct_type->alignment[GRAS_THISARCH],
+         struct_type->aligned_size[GRAS_THISARCH]);
+  XBT_OUT;
+}
+
+/** \brief Close a structure description
+ *
+ * No new field can be added afterward, and it is mandatory to close the structure before using it.
+ */
+void gras_datadesc_struct_close(gras_datadesc_type_t struct_type)
+{
+  int arch;
+  XBT_IN;
+  struct_type->category.struct_data.closed = 1;
+  for (arch = 0; arch < gras_arch_count; arch++) {
+    struct_type->size[arch] = struct_type->aligned_size[arch];
+  }
+  DEBUG4("structure %s closed. size=%ld,align=%ld,asize=%ld",
+         struct_type->name,
+         struct_type->size[GRAS_THISARCH],
+         struct_type->alignment[GRAS_THISARCH],
+         struct_type->aligned_size[GRAS_THISARCH]);
+}
+
+/**
+ * gras_datadesc_cycle_set:
+ *
+ * Tell GRAS that the pointers of the type described by ddt may present
+ * some loop, and that the cycle detection mechanism is needed.
+ *
+ * Note that setting this option when not needed have a rather bad effect
+ * on the performance (several times slower on big data).
+ */
+void gras_datadesc_cycle_set(gras_datadesc_type_t ddt)
+{
+  ddt->cycle = 1;
+}
+
+/**
+ * gras_datadesc_cycle_unset:
+ *
+ * Tell GRAS that the pointers of the type described by ddt do not present
+ * any loop and that cycle detection mechanism are not needed.
+ * (default)
+ */
+void gras_datadesc_cycle_unset(gras_datadesc_type_t ddt)
+{
+  ddt->cycle = 0;
+}
+
+/** \brief Declare a new union description */
+gras_datadesc_type_t
+gras_datadesc_union(const char *name, gras_datadesc_type_cb_int_t selector)
+{
+
+  gras_datadesc_type_t res;
+  int arch;
+
+  XBT_IN1("(%s)", name);
+  xbt_assert0(selector,
+              "Attempt to creat an union without field_count function");
+
+  res = gras_datadesc_by_name_or_null(name);
+  if (res) {
+    /* FIXME: Check that field redefinition matches */
+    xbt_assert1(res->category_code == e_gras_datadesc_type_cat_union,
+                "Redefinition of type %s does not match", name);
+    xbt_assert1(res->category.union_data.selector == selector,
+                "Redefinition of type %s does not match", name);
+    VERB1("Discarding redefinition of %s", name);
+    return res;
+  }
+
+  res = gras_ddt_new(name);
+
+  for (arch = 0; arch < gras_arch_count; arch++) {
+    res->size[arch] = 0;
+    res->alignment[arch] = 0;
+    res->aligned_size[arch] = 0;
+  }
+
+  res->category_code = e_gras_datadesc_type_cat_union;
+  res->category.union_data.fields =
+    xbt_dynar_new(sizeof(gras_dd_cat_field_t *), gras_dd_cat_field_free);
+  res->category.union_data.selector = selector;
+
+  return res;
+}
+
+/** \brief Append a new field to an union description */
+void gras_datadesc_union_append(gras_datadesc_type_t union_type,
+                                const char *name,
+                                gras_datadesc_type_t field_type)
+{
+
+  gras_dd_cat_field_t field;
+  int arch;
+
+  XBT_IN3("(%s %s.%s;)", field_type->name, union_type->name, name);
+  xbt_assert1(field_type->size[GRAS_THISARCH] >= 0,
+              "Cannot add a dynamically sized field in union %s",
+              union_type->name);
+
+  if (union_type->category.union_data.closed) {
+    VERB1("Ignoring request to add field to union %s (closed)",
+          union_type->name);
+    return;
+  }
+
+  field = xbt_new0(s_gras_dd_cat_field_t, 1);
+
+  field->name = (char *) strdup(name);
+  field->type = field_type;
+  /* All offset are left to 0 in an union */
+
+  xbt_dynar_push(union_type->category.union_data.fields, &field);
+
+  for (arch = 0; arch < gras_arch_count; arch++) {
+    union_type->size[arch] = max(union_type->size[arch],
+                                 field_type->size[arch]);
+    union_type->alignment[arch] = max(union_type->alignment[arch],
+                                      field_type->alignment[arch]);
+    union_type->aligned_size[arch] = ddt_aligned(union_type->size[arch],
+                                                 union_type->alignment[arch]);
+  }
+}
+
+
+/** \brief Close an union description
+ *
+ * No new field can be added afterward, and it is mandatory to close the union before using it.
+ */
+void gras_datadesc_union_close(gras_datadesc_type_t union_type)
+{
+  union_type->category.union_data.closed = 1;
+}
+
+/** \brief Copy a type under another name
+ *
+ * This may reveal useful to circumvent parsing macro limitations
+ */
+gras_datadesc_type_t
+gras_datadesc_copy(const char *name, gras_datadesc_type_t copied)
+{
+
+  gras_datadesc_type_t res = gras_ddt_new(name);
+  char *name_cpy = res->name;
+
+  memcpy(res, copied, sizeof(s_gras_datadesc_type_t));
+  res->name = name_cpy;
+  return res;
+}
+
+/** \brief Declare a new type being a reference to the one passed in arg */
+gras_datadesc_type_t
+gras_datadesc_ref(const char *name, gras_datadesc_type_t referenced_type)
+{
+
+  gras_datadesc_type_t res;
+  gras_datadesc_type_t pointer_type = gras_datadesc_by_name("data pointer");
+  int arch;
+
+  XBT_IN1("(%s)", name);
+  res = gras_datadesc_by_name_or_null(name);
+  if (res) {
+    xbt_assert1(res->category_code == e_gras_datadesc_type_cat_ref,
+                "Redefinition of %s does not match", name);
+    xbt_assert1(res->category.ref_data.type == referenced_type,
+                "Redefinition of %s does not match", name);
+    xbt_assert1(res->category.ref_data.selector == NULL,
+                "Redefinition of %s does not match", name);
+    VERB1("Discarding redefinition of %s", name);
+    return res;
+  }
+
+  res = gras_ddt_new(name);
+
+  xbt_assert0(pointer_type, "Cannot get the description of data pointer");
+
+  for (arch = 0; arch < gras_arch_count; arch++) {
+    res->size[arch] = pointer_type->size[arch];
+    res->alignment[arch] = pointer_type->alignment[arch];
+    res->aligned_size[arch] = pointer_type->aligned_size[arch];
+  }
+
+  res->category_code = e_gras_datadesc_type_cat_ref;
+  res->category.ref_data.type = referenced_type;
+  res->category.ref_data.selector = NULL;
+
+  return res;
+}
+
+/** \brief Declare a new type being a generic reference.
+ *
+ * The callback passed in argument is to be used to select which type is currently used.
+ * So, when GRAS wants to send a generic reference, it passes the current data to the selector
+ * callback and expects it to return the type description to use.
+ */
+gras_datadesc_type_t
+gras_datadesc_ref_generic(const char *name, gras_datadesc_selector_t selector)
+{
+
+  gras_datadesc_type_t res;
+  gras_datadesc_type_t pointer_type = gras_datadesc_by_name("data pointer");
+  int arch;
+
+  XBT_IN1("(%s)", name);
+  res = gras_datadesc_by_name_or_null(name);
+
+  if (res) {
+    xbt_assert1(res->category_code == e_gras_datadesc_type_cat_ref,
+                "Redefinition of type %s does not match", name);
+    xbt_assert1(res->category.ref_data.type == NULL,
+                "Redefinition of type %s does not match", name);
+    xbt_assert1(res->category.ref_data.selector == selector,
+                "Redefinition of type %s does not match", name);
+    VERB1("Discarding redefinition of %s", name);
+    return res;
+  }
+  res = gras_ddt_new(name);
+
+  xbt_assert0(pointer_type, "Cannot get the description of data pointer");
+
+  for (arch = 0; arch < gras_arch_count; arch++) {
+    res->size[arch] = pointer_type->size[arch];
+    res->alignment[arch] = pointer_type->alignment[arch];
+    res->aligned_size[arch] = pointer_type->aligned_size[arch];
+  }
+
+  res->category_code = e_gras_datadesc_type_cat_ref;
+
+  res->category.ref_data.type = NULL;
+  res->category.ref_data.selector = selector;
+
+  return res;
+}
+
+/** \brief Declare a new type being an array of fixed size and content */
+gras_datadesc_type_t
+gras_datadesc_array_fixed(const char *name,
+                          gras_datadesc_type_t element_type,
+                          long int fixed_size)
+{
+
+  gras_datadesc_type_t res;
+  int arch;
+
+  XBT_IN1("(%s)", name);
+  res = gras_datadesc_by_name_or_null(name);
+  if (res) {
+    xbt_assert1(res->category_code == e_gras_datadesc_type_cat_array,
+                "Redefinition of type %s does not match", name);
+
+    if (res->category.array_data.type != element_type) {
+      ERROR1("Redefinition of type %s does not match: array elements differ",
+             name);
+      gras_datadesc_type_dump(res->category.array_data.type);
+      gras_datadesc_type_dump(element_type);
+    }
+
+    xbt_assert1(res->category.array_data.fixed_size == fixed_size,
+                "Redefinition of type %s does not match", name);
+    xbt_assert1(res->category.array_data.dynamic_size == NULL,
+                "Redefinition of type %s does not match", name);
+    VERB1("Discarding redefinition of %s", name);
+
+    return res;
+  }
+  res = gras_ddt_new(name);
+
+  xbt_assert1(fixed_size >= 0, "'%s' is a array of negative fixed size",
+              name);
+  for (arch = 0; arch < gras_arch_count; arch++) {
+    res->size[arch] = fixed_size * element_type->aligned_size[arch];
+    res->alignment[arch] = element_type->alignment[arch];
+    res->aligned_size[arch] = res->size[arch];
+  }
+
+  res->category_code = e_gras_datadesc_type_cat_array;
+
+  res->category.array_data.type = element_type;
+  res->category.array_data.fixed_size = fixed_size;
+  res->category.array_data.dynamic_size = NULL;
+
+  return res;
+}
+
+/** \brief Declare a new type being an array of fixed size, but accepting several content types. */
+gras_datadesc_type_t gras_datadesc_array_dyn(const char *name,
+                                             gras_datadesc_type_t
+                                             element_type,
+                                             gras_datadesc_type_cb_int_t
+                                             dynamic_size)
+{
+
+  gras_datadesc_type_t res;
+  int arch;
+
+  XBT_IN1("(%s)", name);
+  xbt_assert1(dynamic_size,
+              "'%s' is a dynamic array without size discriminant", name);
+
+  res = gras_datadesc_by_name_or_null(name);
+  if (res) {
+    xbt_assert1(res->category_code == e_gras_datadesc_type_cat_array,
+                "Redefinition of type %s does not match", name);
+    xbt_assert1(res->category.array_data.type == element_type,
+                "Redefinition of type %s does not match", name);
+    xbt_assert1(res->category.array_data.fixed_size == -1,
+                "Redefinition of type %s does not match", name);
+    xbt_assert1(res->category.array_data.dynamic_size == dynamic_size,
+                "Redefinition of type %s does not match", name);
+    VERB1("Discarding redefinition of %s", name);
+
+    return res;
+  }
+
+  res = gras_ddt_new(name);
+
+  for (arch = 0; arch < gras_arch_count; arch++) {
+    res->size[arch] = 0;        /* make sure it indicates "dynamic" */
+    res->alignment[arch] = element_type->alignment[arch];
+    res->aligned_size[arch] = 0;        /*FIXME: That was so in GS, but looks stupid */
+  }
+
+  res->category_code = e_gras_datadesc_type_cat_array;
+
+  res->category.array_data.type = element_type;
+  res->category.array_data.fixed_size = -1;
+  res->category.array_data.dynamic_size = dynamic_size;
+
+  return res;
+}
+
+/** \brief Declare a new type being an array which size can be found with \ref gras_cbps_i_pop
+ *
+ * Most of the time, you want to include a reference in your structure which
+ * is a pointer to a dynamic array whose size is fixed by another field of
+ * your structure.
+ *
+ * This case pops up so often that this function was created to take care of
+ * this case. It creates a dynamic array type whose size is poped from the
+ * current cbps, and then create a reference to it.
+ *
+ * The name of the created datatype will be the name of the element type, with
+ * '[]*' appended to it.
+ *
+ * Then to use it, you just have to make sure that your structure pre-callback
+ * does push the size of the array in the cbps (using #gras_cbps_i_push), and
+ * you are set.
+ *
+ * But be remember that this is a stack. If you have two different pop_arr, you
+ * should push the second one first, so that the first one is on the top of the
+ * list when the first field gets transfered.
+ *
+ */
+gras_datadesc_type_t
+gras_datadesc_ref_pop_arr(gras_datadesc_type_t element_type)
+{
+
+  gras_datadesc_type_t res,ddt2;
+  char *name = (char *) xbt_malloc(strlen(element_type->name) + 4);
+
+  sprintf(name, "%s[]", element_type->name);
+  /* Make sure we are not trying to redefine a ddt with the same name */
+  ddt2 = gras_datadesc_by_name_or_null(name);
+  int cpt=0;
+  while (ddt2) {
+    free(name);
+    name=bprintf("%s[]_%d",element_type->name,cpt++);
+    ddt2=gras_datadesc_by_name_or_null(name);
+  }
+
+  res = gras_datadesc_array_dyn(name, element_type, gras_datadesc_cb_pop);
+
+  sprintf(name, "%s[]*", element_type->name);
+  cpt=0;
+  ddt2 = gras_datadesc_by_name_or_null(name);
+  while (ddt2) {
+    free(name);
+    name=bprintf("%s[]*_%d",element_type->name,cpt++);
+    ddt2=gras_datadesc_by_name_or_null(name);
+  }
+
+  res = gras_datadesc_ref(name, res);
+
+  free(name);
+
+  return res;
+}
+
+/*
+ *##
+ *## Constructor of container datatypes
+ *##
+ */
+
+static void gras_datadesc_dynar_cb(gras_datadesc_type_t typedesc,
+                                   gras_cbps_t vars, void *data)
+{
+  gras_datadesc_type_t subtype;
+  xbt_dynar_t dynar = (xbt_dynar_t) data;
+
+  memcpy(&dynar->free_f, &typedesc->extra, sizeof(dynar->free_f));
+
+  /* search for the elemsize in what we have. If elements are "int", typedesc got is "int[]*" */
+  subtype = gras_dd_find_field(typedesc, "data")->type;
+
+  /* this is now a ref to array of what we're looking for */
+  subtype = subtype->category.ref_data.type;
+  subtype = subtype->category.array_data.type;
+
+  DEBUG1("subtype is %s", subtype->name);
+
+  dynar->elmsize = subtype->size[GRAS_THISARCH];
+  dynar->size = dynar->used;
+  dynar->mutex = NULL;
+}
+
+/** \brief Declare a new type being a dynar in which each elements are of the given type
+ *
+ *  The type gets registered under the name "dynar(%s)_s", where %s is the name of the subtype.
+ *  For example, a dynar of doubles will be called "dynar(double)_s" and a dynar of dynar of
+ *  strings will be called "dynar(dynar(string)_s)_s".
+ *
+ *  \param elm_t: the datadesc of the elements
+ *  \param free_func: the function to use to free the elements when the dynar gets freed
+ */
+gras_datadesc_type_t
+gras_datadesc_dynar(gras_datadesc_type_t elm_t, void_f_pvoid_t free_func)
+{
+
+  char *buffname;
+  gras_datadesc_type_t res;
+
+  asprintf(&buffname, "s_xbt_dynar_of_%s", elm_t->name);
+
+  res = gras_datadesc_struct(buffname);
+
+  gras_datadesc_struct_append(res, "size",
+                              gras_datadesc_by_name("unsigned long int"));
+
+  gras_datadesc_struct_append(res, "used",
+                              gras_datadesc_by_name("unsigned long int"));
+
+  gras_datadesc_struct_append(res, "elmsize",
+                              gras_datadesc_by_name("unsigned long int"));
+
+  gras_datadesc_struct_append(res, "data", gras_datadesc_ref_pop_arr(elm_t));
+
+  gras_datadesc_struct_append(res, "free_f",
+                              gras_datadesc_by_name("function pointer"));
+  memcpy(res->extra, &free_func, sizeof(free_func));
+
+  gras_datadesc_struct_append(res, "mutex",
+                              gras_datadesc_by_name("data pointer"));
+
+  gras_datadesc_struct_close(res);
+
+  gras_datadesc_cb_field_push(res, "used");
+  gras_datadesc_cb_recv(res, &gras_datadesc_dynar_cb);
+
+  /* build a ref to it */
+  free(buffname);
+  asprintf(&buffname, "xbt_dynar_of_%s", elm_t->name);
+  res = gras_datadesc_ref(buffname, res);
+  free(buffname);
+  return res;
+}
+
+#include "xbt/matrix.h"
+static void gras_datadesc_matrix_cb(gras_datadesc_type_t typedesc,
+                                    gras_cbps_t vars, void *data)
+{
+  gras_datadesc_type_t subtype;
+  xbt_matrix_t matrix = (xbt_matrix_t) data;
+
+  memcpy(&matrix->free_f, &typedesc->extra, sizeof(matrix->free_f));
+
+  /* search for the elemsize in what we have. If elements are "int", typedesc got is "int[]*" */
+  subtype = gras_dd_find_field(typedesc, "data")->type;
+
+  /* this is now a ref to array of what we're looking for */
+  subtype = subtype->category.ref_data.type;
+  subtype = subtype->category.array_data.type;
+
+  DEBUG1("subtype is %s", subtype->name);
+
+  matrix->elmsize = subtype->size[GRAS_THISARCH];
+}
+
+gras_datadesc_type_t
+gras_datadesc_matrix(gras_datadesc_type_t elm_t, void_f_pvoid_t const free_f)
+{
+  char *buffname;
+  gras_datadesc_type_t res;
+
+  asprintf(&buffname, "s_xbt_matrix_t(%s)", elm_t->name);
+  res = gras_datadesc_struct(buffname);
+
+  gras_datadesc_struct_append(res, "lines",
+                              gras_datadesc_by_name("unsigned int"));
+  gras_datadesc_struct_append(res, "rows",
+                              gras_datadesc_by_name("unsigned int"));
+
+  gras_datadesc_struct_append(res, "elmsize",
+                              gras_datadesc_by_name("unsigned long int"));
+
+  gras_datadesc_struct_append(res, "data", gras_datadesc_ref_pop_arr(elm_t));
+  gras_datadesc_struct_append(res, "free_f",
+                              gras_datadesc_by_name("function pointer"));
+  gras_datadesc_struct_close(res);
+
+  gras_datadesc_cb_field_push(res, "lines");
+  gras_datadesc_cb_field_push_multiplier(res, "rows");
+
+  gras_datadesc_cb_recv(res, &gras_datadesc_matrix_cb);
+  memcpy(res->extra, &free_f, sizeof(free_f));
+
+  /* build a ref to it */
+  free(buffname);
+  asprintf(&buffname, "xbt_matrix_t(%s)", elm_t->name);
+  res = gras_datadesc_ref(buffname, res);
+  free(buffname);
+  return res;
+}
+
+gras_datadesc_type_t
+gras_datadesc_import_nws(const char *name,
+                         const DataDescriptor * desc, unsigned long howmany)
+{
+  THROW_UNIMPLEMENTED;
+}
+
+/**
+ * (useful to push the sizes of the upcoming arrays, for example)
+ */
+void gras_datadesc_cb_send(gras_datadesc_type_t type,
+                           gras_datadesc_type_cb_void_t send)
+{
+  type->send = send;
+}
+
+/**
+ * (useful to put the function pointers to the rigth value, for example)
+ */
+void gras_datadesc_cb_recv(gras_datadesc_type_t type,
+                           gras_datadesc_type_cb_void_t recv)
+{
+  type->recv = recv;
+}
+
+/*
+ * gras_dd_find_field:
+ *
+ * Returns the type descriptor of the given field. Abort on error.
+ */
+static gras_dd_cat_field_t
+gras_dd_find_field(gras_datadesc_type_t type, const char *field_name)
+{
+  xbt_dynar_t field_array;
+
+  gras_dd_cat_field_t field = NULL;
+  unsigned int field_num;
+
+  if (type->category_code == e_gras_datadesc_type_cat_union) {
+    field_array = type->category.union_data.fields;
+  } else if (type->category_code == e_gras_datadesc_type_cat_struct) {
+    field_array = type->category.struct_data.fields;
+  } else {
+    ERROR2("%s (%p) is not a struct nor an union. There is no field.",
+           type->name, (void *) type);
+    xbt_abort();
+  }
+  xbt_dynar_foreach(field_array, field_num, field) {
+    if (!strcmp(field_name, field->name)) {
+      return field;
+    }
+  }
+  ERROR2("No field named '%s' in '%s'", field_name, type->name);
+  xbt_abort();
+
+}
+
+/**
+ * The given datadesc must be a struct or union (abort if not).
+ * (useful to push the sizes of the upcoming arrays, for example)
+ */
+void gras_datadesc_cb_field_send(gras_datadesc_type_t type,
+                                 const char *field_name,
+                                 gras_datadesc_type_cb_void_t send)
+{
+
+  gras_dd_cat_field_t field = gras_dd_find_field(type, field_name);
+  field->send = send;
+}
+
+
+/**
+ * The value, which must be an int, unsigned int, long int or unsigned long int
+ * is pushed to the stacks of sizes and can then be retrieved with
+ * \ref gras_datadesc_ref_pop_arr or directly with \ref gras_cbps_i_pop.
+ */
+void gras_datadesc_cb_field_push(gras_datadesc_type_t type,
+                                 const char *field_name)
+{
+
+  gras_dd_cat_field_t field = gras_dd_find_field(type, field_name);
+  gras_datadesc_type_t sub_type = field->type;
+
+  DEBUG3("add a PUSHy cb to '%s' field (type '%s') of '%s'",
+         field_name, sub_type->name, type->name);
+  if (!strcmp("int", sub_type->name)) {
+    field->send = gras_datadesc_cb_push_int;
+  } else if (!strcmp("unsigned int", sub_type->name)) {
+    field->send = gras_datadesc_cb_push_uint;
+  } else if (!strcmp("long int", sub_type->name)) {
+    field->send = gras_datadesc_cb_push_lint;
+  } else if (!strcmp("unsigned long int", sub_type->name)) {
+    field->send = gras_datadesc_cb_push_ulint;
+  } else {
+    ERROR1
+      ("Field %s is not an int, unsigned int, long int neither unsigned long int",
+       sub_type->name);
+    xbt_abort();
+  }
+}
+
+/**
+ * Any previously pushed value is poped and the field value is multiplied to
+ * it. The result is then pushed back into the stack of sizes. It can then be
+ * retrieved with \ref gras_datadesc_ref_pop_arr or directly with \ref
+ * gras_cbps_i_pop.
+ *
+ * The field must be an int, unsigned int, long int or unsigned long int.
+ */
+void gras_datadesc_cb_field_push_multiplier(gras_datadesc_type_t type,
+                                            const char *field_name)
+{
+
+  gras_dd_cat_field_t field = gras_dd_find_field(type, field_name);
+  gras_datadesc_type_t sub_type = field->type;
+
+  DEBUG3("add a MPUSHy cb to '%s' field (type '%s') of '%s'",
+         field_name, sub_type->name, type->name);
+  if (!strcmp("int", sub_type->name)) {
+    field->send = gras_datadesc_cb_push_int_mult;
+  } else if (!strcmp("unsigned int", sub_type->name)) {
+    field->send = gras_datadesc_cb_push_uint_mult;
+  } else if (!strcmp("long int", sub_type->name)) {
+    field->send = gras_datadesc_cb_push_lint_mult;
+  } else if (!strcmp("unsigned long int", sub_type->name)) {
+    field->send = gras_datadesc_cb_push_ulint_mult;
+  } else {
+    ERROR1
+      ("Field %s is not an int, unsigned int, long int neither unsigned long int",
+       sub_type->name);
+    xbt_abort();
+  }
+}
+
+/**
+ * The given datadesc must be a struct or union (abort if not).
+ * (useful to put the function pointers to the right value, for example)
+ */
+void gras_datadesc_cb_field_recv(gras_datadesc_type_t type,
+                                 const char *field_name,
+                                 gras_datadesc_type_cb_void_t recv)
+{
+
+  gras_dd_cat_field_t field = gras_dd_find_field(type, field_name);
+  field->recv = recv;
+}
+
+/*
+ * Free a datadesc. Should only be called at xbt_exit.
+ */
+void gras_datadesc_free(gras_datadesc_type_t * type)
+{
+
+  DEBUG1("Let's free ddt %s", (*type)->name);
+
+  switch ((*type)->category_code) {
+  case e_gras_datadesc_type_cat_scalar:
+  case e_gras_datadesc_type_cat_ref:
+  case e_gras_datadesc_type_cat_array:
+    /* nothing to free in there */
+    break;
+
+  case e_gras_datadesc_type_cat_struct:
+    xbt_dynar_free(&((*type)->category.struct_data.fields));
+    break;
+
+  case e_gras_datadesc_type_cat_union:
+    xbt_dynar_free(&((*type)->category.union_data.fields));
+    break;
+
+  default:
+    /* datadesc was invalid. Killing it is like euthanasy, I guess */
+    break;
+  }
+  free((*type)->name);
+  free(*type);
+  type = NULL;
+}
+
+/**
+ * gras_datadesc_type_cmp:
+ *
+ * Compares two datadesc types with the same semantic than strcmp.
+ *
+ * This comparison does not take the set headers into account (name and ID),
+ * but only the payload (actual type description).
+ */
+int gras_datadesc_type_cmp(const gras_datadesc_type_t d1,
+                           const gras_datadesc_type_t d2)
+{
+  int ret;
+  unsigned int cpt;
+  gras_dd_cat_field_t field1, field2;
+  gras_datadesc_type_t field_desc_1, field_desc_2;
+
+  if (d1 == d2)
+    return 0;                   /* easy optimization */
+
+  if (!d1 && d2) {
+    DEBUG0("ddt_cmp: !d1 && d2 => 1");
+    return 1;
+  }
+  if (!d1 && !d2) {
+    DEBUG0("ddt_cmp: !d1 && !d2 => 0");
+    return 0;
+  }
+  if (d1 && !d2) {
+    DEBUG0("ddt_cmp: d1 && !d2 => -1");
+    return -1;
+  }
+
+  for (cpt = 0; cpt < gras_arch_count; cpt++) {
+    if (d1->size[cpt] != d2->size[cpt]) {
+      DEBUG5("ddt_cmp: %s->size=%ld  !=  %s->size=%ld (on %s)",
+             d1->name, d1->size[cpt], d2->name, d2->size[cpt],
+             gras_arches[cpt].name);
+      return d1->size[cpt] > d2->size[cpt] ? 1 : -1;
+    }
+
+    if (d1->alignment[cpt] != d2->alignment[cpt]) {
+      DEBUG5("ddt_cmp: %s->alignment=%ld  !=  %s->alignment=%ld (on %s)",
+             d1->name, d1->alignment[cpt], d2->name, d2->alignment[cpt],
+             gras_arches[cpt].name);
+      return d1->alignment[cpt] > d2->alignment[cpt] ? 1 : -1;
+    }
+
+    if (d1->aligned_size[cpt] != d2->aligned_size[cpt]) {
+      DEBUG5
+        ("ddt_cmp: %s->aligned_size=%ld  !=  %s->aligned_size=%ld (on %s)",
+         d1->name, d1->aligned_size[cpt], d2->name, d2->aligned_size[cpt],
+         gras_arches[cpt].name);
+      return d1->aligned_size[cpt] > d2->aligned_size[cpt] ? 1 : -1;
+    }
+  }
+
+  if (d1->category_code != d2->category_code) {
+    DEBUG4("ddt_cmp: %s->cat=%s  !=  %s->cat=%s",
+           d1->name, gras_datadesc_cat_names[d1->category_code],
+           d2->name, gras_datadesc_cat_names[d2->category_code]);
+    return d1->category_code > d2->category_code ? 1 : -1;
+  }
+
+  if (d1->send != d2->send) {
+    DEBUG4("ddt_cmp: %s->send=%p  !=  %s->send=%p",
+           d1->name, (void *) d1->send, d2->name, (void *) d2->send);
+    return 1;                   /* ISO C forbids ordered comparisons of pointers to functions */
+  }
+
+  if (d1->recv != d2->recv) {
+    DEBUG4("ddt_cmp: %s->recv=%p  !=  %s->recv=%p",
+           d1->name, (void *) d1->recv, d2->name, (void *) d2->recv);
+    return 1;                   /* ISO C forbids ordered comparisons of pointers to functions */
+  }
+
+  switch (d1->category_code) {
+  case e_gras_datadesc_type_cat_scalar:
+    if (d1->category.scalar_data.encoding !=
+        d2->category.scalar_data.encoding)
+      return d1->category.scalar_data.encoding >
+        d2->category.scalar_data.encoding ? 1 : -1;
+    break;
+
+  case e_gras_datadesc_type_cat_struct:
+    if (xbt_dynar_length(d1->category.struct_data.fields) !=
+        xbt_dynar_length(d2->category.struct_data.fields)) {
+      DEBUG4("ddt_cmp: %s (having %lu fields) !=  %s (having %lu fields)",
+             d1->name, xbt_dynar_length(d1->category.struct_data.fields),
+             d2->name, xbt_dynar_length(d2->category.struct_data.fields));
+
+      return xbt_dynar_length(d1->category.struct_data.fields) >
+        xbt_dynar_length(d2->category.struct_data.fields) ? 1 : -1;
+    }
+    xbt_dynar_foreach(d1->category.struct_data.fields, cpt, field1) {
+
+      field2 =
+        xbt_dynar_get_as(d2->category.struct_data.fields, cpt,
+                         gras_dd_cat_field_t);
+      field_desc_1 = field1->type;
+      field_desc_2 = field2->type;
+      ret = gras_datadesc_type_cmp(field_desc_1, field_desc_2);
+      if (ret) {
+        DEBUG6("%s->field[%d]=%s != %s->field[%d]=%s",
+               d1->name, cpt, field1->name, d2->name, cpt, field2->name);
+        return ret;
+      }
+
+    }
+    break;
+
+  case e_gras_datadesc_type_cat_union:
+    if (d1->category.union_data.selector != d2->category.union_data.selector)
+      return 1;                 /* ISO C forbids ordered comparisons of pointers to functions */
+
+    if (xbt_dynar_length(d1->category.union_data.fields) !=
+        xbt_dynar_length(d2->category.union_data.fields))
+      return xbt_dynar_length(d1->category.union_data.fields) >
+        xbt_dynar_length(d2->category.union_data.fields) ? 1 : -1;
+
+    xbt_dynar_foreach(d1->category.union_data.fields, cpt, field1) {
+
+      field2 =
+        xbt_dynar_get_as(d2->category.union_data.fields, cpt,
+                         gras_dd_cat_field_t);
+      field_desc_1 = field1->type;
+      field_desc_2 = field2->type;
+      ret = gras_datadesc_type_cmp(field_desc_1, field_desc_2);
+      if (ret)
+        return ret;
+
+    }
+    break;
+
+
+  case e_gras_datadesc_type_cat_ref:
+    if (d1->category.ref_data.selector != d2->category.ref_data.selector)
+      return 1;                 /* ISO C forbids ordered comparisons of pointers to functions */
+
+    if (d1->category.ref_data.type != d2->category.ref_data.type)
+      return d1->category.ref_data.type > d2->category.ref_data.type ? 1 : -1;
+    break;
+
+  case e_gras_datadesc_type_cat_array:
+    if (d1->category.array_data.type != d2->category.array_data.type)
+      return d1->category.array_data.type >
+        d2->category.array_data.type ? 1 : -1;
+
+    if (d1->category.array_data.fixed_size !=
+        d2->category.array_data.fixed_size)
+      return d1->category.array_data.fixed_size >
+        d2->category.array_data.fixed_size ? 1 : -1;
+
+    if (d1->category.array_data.dynamic_size !=
+        d2->category.array_data.dynamic_size)
+      return 1;                 /* ISO C forbids ordered comparisons of pointers to functions */
+
+    break;
+
+  default:
+    /* two stupidly created ddt are equally stupid ;) */
+    break;
+  }
+  return 0;
+
+}
index ed69bc7..8032737 100644 (file)
-/* a generic and efficient heap                                             */\r
-\r
-/* Copyright (c) 2004, 2005, 2007, 2008, 2009, 2010. The SimGrid Team.\r
- * All rights reserved.                                                     */\r
-\r
-/* This program is free software; you can redistribute it and/or modify it\r
- * under the terms of the license (GNU LGPL) which comes with this package. */\r
-\r
-#include "xbt/sysdep.h"\r
-#include "xbt/log.h"\r
-#include "heap_private.h"\r
-\r
-#include <stdio.h>\r
-\r
-\r
-/** @addtogroup XBT_heap\r
- *  \brief This section describes the API to generic heap with O(log(n)) access.\r
- */\r
-\r
-/**\r
- * @brief Creates a new heap.\r
- * \param init_size initial size of the heap\r
- * \param free_func function to call on each element when you want to free\r
- *             the whole heap (or NULL if nothing to do).\r
- *\r
- * Creates a new heap.\r
- */\r
-XBT_INLINE xbt_heap_t xbt_heap_new(int init_size, void_f_pvoid_t const free_func)\r
-{\r
-  xbt_heap_t H = xbt_new0(struct xbt_heap, 1);\r
-  H->size = init_size;\r
-  H->count = 0;\r
-  H->items = (xbt_heapItem_t) xbt_new0(struct xbt_heapItem, init_size);\r
-  H->free = free_func;\r
-  return H;\r
-}\r
-\r
-/**\r
- * @brief Set the update callback function.\r
- * @param H the heap we're working on\r
- * \param update_callback function to call on each element to update its index when needed.\r
- */\r
-XBT_INLINE void xbt_heap_set_update_callback(xbt_heap_t H,\r
-                                  void (*update_callback) (void *, int))\r
-{\r
-  H->update_callback = update_callback;\r
-}\r
-\r
-\r
-/**\r
- * @brief kilkil a heap and its content\r
- * @param H poor victim\r
- */\r
-void xbt_heap_free(xbt_heap_t H)\r
-{\r
-  int i;\r
-  if (H->free)\r
-    for (i = 0; i < H->count; i++)\r
-      (*(H->free)) (H->items[i].content);\r
-  free(H->items);\r
-  free(H);\r
-  return;\r
-}\r
-\r
-/**\r
- * @brief returns the number of elements in the heap\r
- * @param H the heap we're working on\r
- * @return the number of elements in the heap\r
- */\r
-XBT_INLINE int xbt_heap_size(xbt_heap_t H)\r
-{\r
-  return (H->count);\r
-}\r
-\r
-/**\r
- * @brief Add an element into the heap.\r
- * \param H the heap we're working on\r
- * \param content the object you want to add to the heap\r
- * \param key the key associated to this object\r
- *\r
- * The element with the smallest key is automatically moved at the top of the heap.\r
- */\r
-void xbt_heap_push(xbt_heap_t H, void *content, double key)\r
-{\r
-  int count = ++(H->count);\r
-\r
-  int size = H->size;\r
-  xbt_heapItem_t item;\r
-\r
-  if (count > size) {\r
-    H->size = 2 * size + 1;\r
-    H->items =\r
-      (void *) realloc(H->items, (H->size) * sizeof(struct xbt_heapItem));\r
-  }\r
-\r
-  item = &(H->items[count - 1]);\r
-  item->key = key;\r
-  item->content = content;\r
-  xbt_heap_increaseKey(H, count - 1);\r
-  return;\r
-}\r
-\r
-/**\r
- * @brief Extracts from the heap and returns the element with the smallest key.\r
- * \param H the heap we're working on\r
- * \return the element with the smallest key\r
- *\r
- * Extracts from the heap and returns the element with the smallest\r
- * key. The element with the next smallest key is automatically moved\r
- * at the top of the heap.\r
- */\r
-void *xbt_heap_pop(xbt_heap_t H)\r
-{\r
-  void *max;\r
-\r
-  if (H->count == 0)\r
-    return NULL;\r
-\r
-  max = CONTENT(H, 0);\r
-\r
-  H->items[0] = H->items[(H->count) - 1];\r
-  (H->count)--;\r
-  xbt_heap_maxHeapify(H);\r
-  if (H->count < H->size / 4 && H->size > 16) {\r
-    H->size = H->size / 2 + 1;\r
-    H->items =\r
-      (void *) realloc(H->items, (H->size) * sizeof(struct xbt_heapItem));\r
-  }\r
-\r
-  if(H->update_callback) H->update_callback(max, -1);\r
-  return max;\r
-}\r
-\r
-/**\r
- * @brief Extracts from the heap and returns the element at position i.\r
- * \param H the heap we're working on\r
- * \param i    element position\r
- * \return the element at position i if ok, NULL otherwise\r
- *\r
- * Extracts from the heap and returns the element at position i. The head is automatically reorded.\r
- */\r
-void *xbt_heap_remove(xbt_heap_t H, int i)\r
-{\r
-  if ((i < 0) || (i > H->count - 1))\r
-    return NULL;\r
-  /* put element i at head */\r
-  if (i > 0) {\r
-    KEY(H, i) = MIN_KEY_VALUE;\r
-    xbt_heap_increaseKey(H, i);\r
-  }\r
-\r
-  return xbt_heap_pop(H);\r
-}\r
-\r
-/**\r
- * @brief returns the smallest key in the heap (heap unchanged)\r
- * \param H the heap we're working on\r
- *\r
- * \return the smallest key in the heap without modifying the heap.\r
- */\r
-XBT_INLINE double xbt_heap_maxkey(xbt_heap_t H)\r
-{\r
-  xbt_assert0(H->count != 0, "Empty heap");\r
-  return KEY(H, 0);\r
-}\r
-\r
-/**\r
- * @brief returns the value associated to the smallest key in the heap (heap unchanged)\r
- * \param H the heap we're working on\r
- *\r
- * \return the value associated to the smallest key in the heap\r
- * without modifying the heap.\r
- */\r
-void *xbt_heap_maxcontent(xbt_heap_t H)\r
-{\r
-  xbt_assert0(H->count != 0, "Empty heap");\r
-  return CONTENT(H, 0);\r
-}\r
-\r
-/* <<<< private >>>>\r
- * \param H the heap we're working on\r
- *\r
- * Restores the heap property once an element has been deleted.\r
- */\r
-static void xbt_heap_maxHeapify(xbt_heap_t H)\r
-{\r
-  int i = 0;\r
-  while (1) {\r
-    int greatest = i;\r
-    int l = LEFT(i);\r
-    int r = RIGHT(i);\r
-    int count = H->count;\r
-    if (l < count && KEY(H, l) < KEY(H, i))\r
-      greatest = l;\r
-    if (r < count && KEY(H, r) < KEY(H, greatest))\r
-      greatest = r;\r
-    if (greatest != i) {\r
-      struct xbt_heapItem tmp = H->items[i];\r
-      H->items[i] = H->items[greatest];\r
-      H->items[greatest] = tmp;\r
-      if(H->update_callback) H->update_callback(CONTENT(H, i), i);\r
-      i = greatest;\r
-    } else {\r
-      if(H->update_callback) H->update_callback(CONTENT(H, i), i);\r
-      return;\r
-    }\r
-  }\r
-}\r
-\r
-/* <<<< private >>>>\r
- * \param H the heap we're working on\r
- * \param i an item position in the heap\r
- *\r
- * Moves up an item at position i to its correct position. Works only\r
- * when called from xbt_heap_push. Do not use otherwise.\r
- */\r
-static void xbt_heap_increaseKey(xbt_heap_t H, int i)\r
-{\r
-  while (i > 0 && KEY(H, PARENT(i)) > KEY(H, i)) {\r
-    struct xbt_heapItem tmp = H->items[i];\r
-    H->items[i] = H->items[PARENT(i)];\r
-    H->items[PARENT(i)] = tmp;\r
-    if(H->update_callback) H->update_callback(CONTENT(H, i), i);\r
-    i = PARENT(i);\r
-  }\r
-  if(H->update_callback) H->update_callback(CONTENT(H, i), i);\r
-  return;\r
-}\r
-\r
+/* a generic and efficient heap                                             */
+
+/* Copyright (c) 2004, 2005, 2007, 2008, 2009, 2010. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "xbt/sysdep.h"
+#include "xbt/log.h"
+#include "heap_private.h"
+
+#include <stdio.h>
+
+
+/** @addtogroup XBT_heap
+ *  \brief This section describes the API to generic heap with O(log(n)) access.
+ */
+
+/**
+ * @brief Creates a new heap.
+ * \param init_size initial size of the heap
+ * \param free_func function to call on each element when you want to free
+ *             the whole heap (or NULL if nothing to do).
+ *
+ * Creates a new heap.
+ */
+XBT_INLINE xbt_heap_t xbt_heap_new(int init_size, void_f_pvoid_t const free_func)
+{
+  xbt_heap_t H = xbt_new0(struct xbt_heap, 1);
+  H->size = init_size;
+  H->count = 0;
+  H->items = (xbt_heapItem_t) xbt_new0(struct xbt_heapItem, init_size);
+  H->free = free_func;
+  return H;
+}
+
+/**
+ * @brief Set the update callback function.
+ * @param H the heap we're working on
+ * \param update_callback function to call on each element to update its index when needed.
+ */
+XBT_INLINE void xbt_heap_set_update_callback(xbt_heap_t H,
+                                  void (*update_callback) (void *, int))
+{
+  H->update_callback = update_callback;
+}
+
+
+/**
+ * @brief kilkil a heap and its content
+ * @param H poor victim
+ */
+void xbt_heap_free(xbt_heap_t H)
+{
+  int i;
+  if (H->free)
+    for (i = 0; i < H->count; i++)
+      (*(H->free)) (H->items[i].content);
+  free(H->items);
+  free(H);
+  return;
+}
+
+/**
+ * @brief returns the number of elements in the heap
+ * @param H the heap we're working on
+ * @return the number of elements in the heap
+ */
+XBT_INLINE int xbt_heap_size(xbt_heap_t H)
+{
+  return (H->count);
+}
+
+/**
+ * @brief Add an element into the heap.
+ * \param H the heap we're working on
+ * \param content the object you want to add to the heap
+ * \param key the key associated to this object
+ *
+ * The element with the smallest key is automatically moved at the top of the heap.
+ */
+void xbt_heap_push(xbt_heap_t H, void *content, double key)
+{
+  int count = ++(H->count);
+
+  int size = H->size;
+  xbt_heapItem_t item;
+
+  if (count > size) {
+    H->size = 2 * size + 1;
+    H->items =
+      (void *) realloc(H->items, (H->size) * sizeof(struct xbt_heapItem));
+  }
+
+  item = &(H->items[count - 1]);
+  item->key = key;
+  item->content = content;
+  xbt_heap_increaseKey(H, count - 1);
+  return;
+}
+
+/**
+ * @brief Extracts from the heap and returns the element with the smallest key.
+ * \param H the heap we're working on
+ * \return the element with the smallest key
+ *
+ * Extracts from the heap and returns the element with the smallest
+ * key. The element with the next smallest key is automatically moved
+ * at the top of the heap.
+ */
+void *xbt_heap_pop(xbt_heap_t H)
+{
+  void *max;
+
+  if (H->count == 0)
+    return NULL;
+
+  max = CONTENT(H, 0);
+
+  H->items[0] = H->items[(H->count) - 1];
+  (H->count)--;
+  xbt_heap_maxHeapify(H);
+  if (H->count < H->size / 4 && H->size > 16) {
+    H->size = H->size / 2 + 1;
+    H->items =
+      (void *) realloc(H->items, (H->size) * sizeof(struct xbt_heapItem));
+  }
+
+  H->update_callback ? H->update_callback(max, -1) : NULL;
+  return max;
+}
+
+/**
+ * @brief Extracts from the heap and returns the element at position i.
+ * \param H the heap we're working on
+ * \param i    element position
+ * \return the element at position i if ok, NULL otherwise
+ *
+ * Extracts from the heap and returns the element at position i. The head is automatically reorded.
+ */
+void *xbt_heap_remove(xbt_heap_t H, int i)
+{
+  if ((i < 0) || (i > H->count - 1))
+    return NULL;
+  /* put element i at head */
+  if (i > 0) {
+    KEY(H, i) = MIN_KEY_VALUE;
+    xbt_heap_increaseKey(H, i);
+  }
+
+  return xbt_heap_pop(H);
+}
+
+/**
+ * @brief returns the smallest key in the heap (heap unchanged)
+ * \param H the heap we're working on
+ *
+ * \return the smallest key in the heap without modifying the heap.
+ */
+XBT_INLINE double xbt_heap_maxkey(xbt_heap_t H)
+{
+  xbt_assert0(H->count != 0, "Empty heap");
+  return KEY(H, 0);
+}
+
+/**
+ * @brief returns the value associated to the smallest key in the heap (heap unchanged)
+ * \param H the heap we're working on
+ *
+ * \return the value associated to the smallest key in the heap
+ * without modifying the heap.
+ */
+void *xbt_heap_maxcontent(xbt_heap_t H)
+{
+  xbt_assert0(H->count != 0, "Empty heap");
+  return CONTENT(H, 0);
+}
+
+/* <<<< private >>>>
+ * \param H the heap we're working on
+ *
+ * Restores the heap property once an element has been deleted.
+ */
+static void xbt_heap_maxHeapify(xbt_heap_t H)
+{
+  int i = 0;
+  while (1) {
+    int greatest = i;
+    int l = LEFT(i);
+    int r = RIGHT(i);
+    int count = H->count;
+    if (l < count && KEY(H, l) < KEY(H, i))
+      greatest = l;
+    if (r < count && KEY(H, r) < KEY(H, greatest))
+      greatest = r;
+    if (greatest != i) {
+      struct xbt_heapItem tmp = H->items[i];
+      H->items[i] = H->items[greatest];
+      H->items[greatest] = tmp;
+      H->update_callback ? H->update_callback(CONTENT(H, i), i) : NULL;
+      i = greatest;
+    } else {
+      H->update_callback ? H->update_callback(CONTENT(H, i), i) : NULL;
+      return;
+    }
+  }
+}
+
+/* <<<< private >>>>
+ * \param H the heap we're working on
+ * \param i an item position in the heap
+ *
+ * Moves up an item at position i to its correct position. Works only
+ * when called from xbt_heap_push. Do not use otherwise.
+ */
+static void xbt_heap_increaseKey(xbt_heap_t H, int i)
+{
+  while (i > 0 && KEY(H, PARENT(i)) > KEY(H, i)) {
+    struct xbt_heapItem tmp = H->items[i];
+    H->items[i] = H->items[PARENT(i)];
+    H->items[PARENT(i)] = tmp;
+    H->update_callback ? H->update_callback(CONTENT(H, i), i) : NULL;
+    i = PARENT(i);
+  }
+  H->update_callback ? H->update_callback(CONTENT(H, i), i) : NULL;
+  return;
+}
+
index 5c63ee0..a583713 100644 (file)
@@ -45,10 +45,9 @@ void xbt_setset_elm_add(xbt_setset_t setset, void *obj)
 {
   xbt_setset_elm_entry_t new_entry = NULL;
   xbt_setset_elm_t e = (xbt_setset_elm_t)obj;
-  xbt_setset_elm_entry_t first_elm = NULL;
-
   xbt_assert0(e->ID == 0, "Adding element with non NULL ID");
-  first_elm = (xbt_setset_elm_entry_t)xbt_dynar_get_ptr(setset->elm_array, 0);
+  xbt_setset_elm_entry_t first_elm = 
+    (xbt_setset_elm_entry_t)xbt_dynar_get_ptr(setset->elm_array, 0);
   
   /* Before create a new elm entry check if there is one in the free elm list. */
   /* If there is not free elm entries, then create a new one  */
@@ -357,4 +356,4 @@ int bitcount(int v)
   v = v - ((v >> 1) & 0x55555555);                        // reuse input as temporary
   v = (v & 0x33333333) + ((v >> 2) & 0x33333333);         // temp
   return (((v + (v >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;  // count
-}
+}
\ No newline at end of file
index 6d94aea..277ea18 100644 (file)
-/* layout_simple - a dumb log layout                                        */\r
-\r
-/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.\r
- * All rights reserved.                                                     */\r
-\r
-/* This program is free software; you can redistribute it and/or modify it\r
- * under the terms of the license (GNU LGPL) which comes with this package. */\r
-\r
-#include "xbt/sysdep.h"\r
-#include "xbt/strbuff.h"        /* For dynamic version when the static one fails */\r
-#include "xbt/log_private.h"\r
-#include "xbt/synchro.h"        /* xbt_thread_name */\r
-\r
-#include "gras/virtu.h"\r
-#include <stdio.h>\r
-#include "portable.h"\r
-\r
-extern const char *xbt_log_priority_names[8];\r
-extern int xbt_log_no_loc;\r
-\r
-static double simple_begin_of_time = -1;\r
-\r
-static void xbt_log_layout_simple_dynamic(xbt_log_layout_t l,\r
-                                          xbt_log_event_t ev,\r
-                                          const char *fmt,\r
-                                          xbt_log_appender_t app)\r
-{\r
-  xbt_strbuff_t buff = xbt_strbuff_new();\r
-  char loc_buff[256];\r
-  char *p;\r
-\r
-  /* Put every static information in a static buffer, and copy them in the dyn one */\r
-  p = loc_buff;\r
-  p += snprintf(p, 256 - (p - loc_buff), "[");\r
-\r
-  if (strlen(xbt_procname()))\r
-    p += snprintf(p, 256 - (p - loc_buff), "%s:%s:(%d) ",\r
-                  gras_os_myname(), xbt_procname(), (*xbt_getpid) ());\r
-  p +=\r
-    snprintf(p, 256 - (p - loc_buff), "%f] ",\r
-             gras_os_time() - simple_begin_of_time);\r
-  if (ev->priority != xbt_log_priority_info && xbt_log_no_loc==0)\r
-    p +=\r
-      snprintf(p, 256 - (p - loc_buff), "%s:%d: ", ev->fileName,\r
-               ev->lineNum);\r
-  p +=\r
-    snprintf(p, 256 - (p - loc_buff), "[%s/%s] ", ev->cat->name,\r
-             xbt_log_priority_names[ev->priority]);\r
-\r
-  xbt_strbuff_append(buff, loc_buff);\r
-\r
-  vasprintf(&p, fmt, ev->ap_copy);\r
-  xbt_strbuff_append(buff, p);\r
-  free(p);\r
-\r
-  xbt_strbuff_append(buff, "\n");\r
-\r
-  app->do_append(app, buff->data);\r
-  xbt_strbuff_free(buff);\r
-}\r
-\r
-/* only used after the format using: we suppose that the buffer is big enough to display our data */\r
-#undef check_overflow\r
-#define check_overflow \\r
-  do {if (p-ev->buffer > XBT_LOG_BUFF_SIZE) { \\r
-  xbt_log_layout_simple_dynamic(l,ev,fmt,app); \\r
-  return ; \\r
-  } } while(0)\r
-\r
-static void xbt_log_layout_simple_doit(xbt_log_layout_t l,\r
-                                       xbt_log_event_t ev,\r
-                                       const char *fmt,\r
-                                       xbt_log_appender_t app)\r
-{\r
-  char *p;\r
-  const char *procname=xbt_procname();\r
-\r
-  xbt_assert0(ev->priority >= 0,\r
-              "Negative logging priority naturally forbidden");\r
-  xbt_assert1(ev->priority < sizeof(xbt_log_priority_names),\r
-              "Priority %d is greater than the biggest allowed value",\r
-              ev->priority);\r
-\r
-  p = ev->buffer;\r
-  p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "[");\r
-  check_overflow;\r
-\r
-  /* Display the proc info if available */\r
-\r
-  if (strlen(procname)) {\r
-    p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s:%s:(%d) ",\r
-                  gras_os_myname(), procname, (*xbt_getpid) ());\r
-    check_overflow;\r
-  }\r
-\r
-  /* Display the date */\r
-  p +=\r
-    snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%f] ",\r
-             gras_os_time() - simple_begin_of_time);\r
-  check_overflow;\r
-\r
-  /* Display file position if not INFO */\r
-  if (ev->priority != xbt_log_priority_info && !xbt_log_no_loc)\r
-    p +=\r
-      snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s:%d: ",\r
-               ev->fileName, ev->lineNum);\r
-\r
-  /* Display category name */\r
-  p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "[%s/%s] ",\r
-                ev->cat->name, xbt_log_priority_names[ev->priority]);\r
-\r
-  /* Display user-provided message */\r
-  p += vsnprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), fmt, ev->ap);\r
-  check_overflow;\r
-\r
-  /* End it */\r
-  p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "\n");\r
-  check_overflow;\r
-  app->do_append(app, ev->buffer);\r
-}\r
-\r
-xbt_log_layout_t xbt_log_layout_simple_new(char *arg)\r
-{\r
-  xbt_log_layout_t res = xbt_new0(s_xbt_log_layout_t, 1);\r
-  res->do_layout = xbt_log_layout_simple_doit;\r
-\r
-  if (simple_begin_of_time < 0)\r
-    simple_begin_of_time = gras_os_time();\r
-\r
-  return res;\r
-}\r
+/* layout_simple - a dumb log layout                                        */
+
+/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "xbt/sysdep.h"
+#include "xbt/strbuff.h"        /* For dynamic version when the static one fails */
+#include "xbt/log_private.h"
+#include "xbt/synchro.h"        /* xbt_thread_name */
+
+#include "gras/virtu.h"
+#include <stdio.h>
+#include "portable.h"
+
+extern const char *xbt_log_priority_names[8];
+extern int xbt_log_no_loc;
+
+static double simple_begin_of_time = -1;
+
+static void xbt_log_layout_simple_dynamic(xbt_log_layout_t l,
+                                          xbt_log_event_t ev,
+                                          const char *fmt,
+                                          xbt_log_appender_t app)
+{
+  xbt_strbuff_t buff = xbt_strbuff_new();
+  char loc_buff[256];
+  char *p;
+
+  /* Put every static information in a static buffer, and copy them in the dyn one */
+  p = loc_buff;
+  p += snprintf(p, 256 - (p - loc_buff), "[");
+
+  if (strlen(xbt_procname()))
+    p += snprintf(p, 256 - (p - loc_buff), "%s:%s:(%d) ",
+                  gras_os_myname(), xbt_procname(), (*xbt_getpid) ());
+  p +=
+    snprintf(p, 256 - (p - loc_buff), "%f] ",
+             gras_os_time() - simple_begin_of_time);
+  if (ev->priority != xbt_log_priority_info && xbt_log_no_loc==0)
+    p +=
+      snprintf(p, 256 - (p - loc_buff), "%s:%d: ", ev->fileName,
+               ev->lineNum);
+  p +=
+    snprintf(p, 256 - (p - loc_buff), "[%s/%s] ", ev->cat->name,
+             xbt_log_priority_names[ev->priority]);
+
+  xbt_strbuff_append(buff, loc_buff);
+
+  vasprintf(&p, fmt, ev->ap_copy);
+  xbt_strbuff_append(buff, p);
+  free(p);
+
+  xbt_strbuff_append(buff, "\n");
+
+  app->do_append(app, buff->data);
+  xbt_strbuff_free(buff);
+}
+
+/* only used after the format using: we suppose that the buffer is big enough to display our data */
+#undef check_overflow
+#define check_overflow \
+  if (p-ev->buffer > XBT_LOG_BUFF_SIZE) { /* buffer overflow */ \
+  xbt_log_layout_simple_dynamic(l,ev,fmt,app); \
+  return; \
+  }
+
+static void xbt_log_layout_simple_doit(xbt_log_layout_t l,
+                                       xbt_log_event_t ev,
+                                       const char *fmt,
+                                       xbt_log_appender_t app)
+{
+  char *p;
+
+  xbt_assert0(ev->priority >= 0,
+              "Negative logging priority naturally forbidden");
+  xbt_assert1(ev->priority < sizeof(xbt_log_priority_names),
+              "Priority %d is greater than the biggest allowed value",
+              ev->priority);
+
+  p = ev->buffer;
+  p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "[");
+  check_overflow;
+
+  /* Display the proc info if available */
+  const char *procname=xbt_procname();
+  if (strlen(procname)) {
+    p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s:%s:(%d) ",
+                  gras_os_myname(), procname, (*xbt_getpid) ());
+    check_overflow;
+  }
+
+  /* Display the date */
+  p +=
+    snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%f] ",
+             gras_os_time() - simple_begin_of_time);
+  check_overflow;
+
+  /* Display file position if not INFO */
+  if (ev->priority != xbt_log_priority_info && !xbt_log_no_loc)
+    p +=
+      snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s:%d: ",
+               ev->fileName, ev->lineNum);
+
+  /* Display category name */
+  p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "[%s/%s] ",
+                ev->cat->name, xbt_log_priority_names[ev->priority]);
+
+  /* Display user-provided message */
+  p += vsnprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), fmt, ev->ap);
+  check_overflow;
+
+  /* End it */
+  p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "\n");
+  check_overflow;
+  app->do_append(app, ev->buffer);
+}
+
+xbt_log_layout_t xbt_log_layout_simple_new(char *arg)
+{
+  xbt_log_layout_t res = xbt_new0(s_xbt_log_layout_t, 1);
+  res->do_layout = xbt_log_layout_simple_doit;
+
+  if (simple_begin_of_time < 0)
+    simple_begin_of_time = gras_os_time();
+
+  return res;
+}
index 365d127..0345e0f 100644 (file)
-/* xbt_os_time.c -- portable interface to time-related functions            */\r
-\r
-/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.\r
- * All rights reserved.                                                     */\r
-\r
-/* This program is free software; you can redistribute it and/or modify it\r
- * under the terms of the license (GNU LGPL) which comes with this package. */\r
-\r
-#include "xbt/sysdep.h"\r
-#include "xbt/xbt_os_time.h"    /* this module */\r
-#include "xbt/log.h"\r
-#include "portable.h"\r
-#include <math.h>               /* floor */\r
-\r
-#ifdef WIN32\r
-#include <sys/timeb.h>\r
-#endif\r
-\r
-double xbt_os_time(void)\r
-{\r
-#ifdef HAVE_GETTIMEOFDAY\r
-  struct timeval tv;\r
-  gettimeofday(&tv, NULL);\r
-#elif defined(WIN32)\r
-  struct timeval tv;\r
-#  if defined(WIN32_WCE) || (_WIN32_WINNT < 0x0400)\r
-  struct _timeb tm;\r
-\r
-  _ftime(&tm);\r
-\r
-  tv.tv_sec = tm.time;\r
-  tv.tv_usec = tm.millitm * 1000;\r
-\r
-#  else\r
-  FILETIME ft;\r
-  unsigned __int64 tm;\r
-\r
-  GetSystemTimeAsFileTime(&ft);\r
-  tm = (unsigned __int64) ft.dwHighDateTime << 32;\r
-  tm |= ft.dwLowDateTime;\r
-  tm /= 10;\r
-  tm -= 11644473600000000ULL;\r
-\r
-  tv.tv_sec = (long) (tm / 1000000L);\r
-  tv.tv_usec = (long) (tm % 1000000L);\r
-#  endif /* windows version checker */\r
-\r
-#else /* not windows, no gettimeofday => poor resolution */\r
-  return (double) (time(NULL));\r
-#endif /* HAVE_GETTIMEOFDAY? */\r
-\r
-  return (double) (tv.tv_sec + tv.tv_usec / 1000000.0);\r
-}\r
-\r
-void xbt_os_sleep(double sec)\r
-{\r
-#ifdef HAVE_USLEEP\r
-  sleep(sec);\r
-  (void) usleep((sec - floor(sec)) * 1000000);\r
-\r
-#elif WIN32\r
-  Sleep((floor(sec) * 1000) + ((sec - floor(sec)) * 1000));\r
-\r
-#else /* don't have usleep. Use select to sleep less than one second */\r
-  struct timeval timeout;\r
-\r
-\r
-  timeout.tv_sec = (unsigned long) (sec);\r
-  timeout.tv_usec = (sec - floor(sec)) * 1000000;\r
-\r
-  select(0, NULL, NULL, NULL, &timeout);\r
-#endif\r
-}\r
-\r
-/* TSC (tick-level) timers are said to be unreliable on SMP hosts and thus\r
-   disabled in SDL source code */\r
-\r
-\r
-/* \defgroup XBT_sysdep All system dependency\r
- * \brief This section describes many macros/functions that can serve as\r
- *  an OS abstraction.\r
- */\r
-\r
-\r
-struct s_xbt_os_timer {\r
-#ifdef HAVE_POSIX_GETTIME\r
-  struct timespec start, stop;\r
-#elif defined(HAVE_GETTIMEOFDAY)\r
-  struct timeval start, stop;\r
-#else\r
-  unsigned long int start, stop;\r
-#endif\r
-};\r
-\r
-xbt_os_timer_t xbt_os_timer_new(void) {\r
-  return xbt_new0(struct s_xbt_os_timer, 1);\r
-}\r
-\r
-void xbt_os_timer_free(xbt_os_timer_t timer) {\r
-  free(timer);\r
-}\r
-\r
-void xbt_os_timer_start(xbt_os_timer_t timer) {\r
-#ifdef HAVE_POSIX_GETTIME\r
-  clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&(timer->start));\r
-#elif defined(HAVE_GETTIMEOFDAY)\r
-  gettimeofday(&(timer->start), NULL);\r
-#else\r
-  timer->start = (unsigned long int) (time(NULL));\r
-#endif\r
-}\r
-\r
-void xbt_os_timer_stop(xbt_os_timer_t timer) {\r
-#ifdef HAVE_POSIX_GETTIME\r
-  clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&(timer->stop));\r
-#elif defined(HAVE_GETTIMEOFDAY)\r
-  gettimeofday(&(timer->stop), NULL);\r
-#else\r
-  timer->stop = (unsigned long int) (time(NULL));\r
-#endif\r
-}\r
-\r
-double xbt_os_timer_elapsed(xbt_os_timer_t timer)\r
-{\r
-#ifdef HAVE_POSIX_GETTIME\r
-  return ((double) timer->stop.tv_sec) - ((double) timer->start.tv_sec) +\r
-      ((((double) timer->stop.tv_nsec) -\r
-        ((double) timer->start.tv_nsec)) / 1e9);\r
-#elif defined(HAVE_GETTIMEOFDAY)\r
-  return ((double) timer->stop.tv_sec) - ((double) timer->start.tv_sec) +\r
-    ((((double) timer->stop.tv_usec) -\r
-      ((double) timer->start.tv_usec)) / 1000000.0);\r
-#else\r
-  return (double) timer->stop - (double) timer->start;\r
-#endif\r
-}\r
+/* xbt_os_time.c -- portable interface to time-related functions            */
+
+/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "xbt/sysdep.h"
+#include "xbt/xbt_os_time.h"    /* this module */
+#include "xbt/log.h"
+#include "portable.h"
+#include <math.h>               /* floor */
+
+
+#ifdef WIN32
+#include <sys/timeb.h>
+#endif
+
+double xbt_os_time(void)
+{
+#ifdef HAVE_GETTIMEOFDAY
+  struct timeval tv;
+  gettimeofday(&tv, NULL);
+#elif defined(WIN32)
+  struct timeval tv;
+#  if defined(WIN32_WCE) || (_WIN32_WINNT < 0x0400)
+  struct _timeb tm;
+
+  _ftime(&tm);
+
+  tv.tv_sec = tm.time;
+  tv.tv_usec = tm.millitm * 1000;
+
+#  else
+  FILETIME ft;
+  unsigned __int64 tm;
+
+  GetSystemTimeAsFileTime(&ft);
+  tm = (unsigned __int64) ft.dwHighDateTime << 32;
+  tm |= ft.dwLowDateTime;
+  tm /= 10;
+  tm -= 11644473600000000ULL;
+
+  tv.tv_sec = (long) (tm / 1000000L);
+  tv.tv_usec = (long) (tm % 1000000L);
+#  endif /* windows version checker */
+
+#else /* not windows, no gettimeofday => poor resolution */
+  return (double) (time(NULL));
+#endif /* HAVE_GETTIMEOFDAY? */
+
+  return (double) (tv.tv_sec + tv.tv_usec / 1000000.0);
+}
+
+void xbt_os_sleep(double sec)
+{
+#ifdef HAVE_USLEEP
+  sleep(sec);
+  (void) usleep((sec - floor(sec)) * 1000000);
+
+#elif WIN32
+  Sleep((floor(sec) * 1000) + ((sec - floor(sec)) * 1000));
+
+#else /* don't have usleep. Use select to sleep less than one second */
+  struct timeval timeout;
+
+
+  timeout.tv_sec = (unsigned long) (sec);
+  timeout.tv_usec = (sec - floor(sec)) * 1000000;
+
+  select(0, NULL, NULL, NULL, &timeout);
+#endif
+}
+
+/* TSC (tick-level) timers are said to be unreliable on SMP hosts and thus
+   disabled in SDL source code */
+
+
+/* \defgroup XBT_sysdep All system dependency
+ * \brief This section describes many macros/functions that can serve as
+ *  an OS abstraction.
+ */
+
+
+struct s_xbt_os_timer {
+#ifdef HAVE_POSIX_GETTIME
+  struct timespec start, stop;
+#elif defined(HAVE_GETTIMEOFDAY)
+  struct timeval start, stop;
+#else
+  unsigned long int start, stop;
+#endif
+};
+
+xbt_os_timer_t xbt_os_timer_new(void) {
+  return xbt_new0(struct s_xbt_os_timer, 1);
+}
+
+void xbt_os_timer_free(xbt_os_timer_t timer) {
+  free(timer);
+}
+
+void xbt_os_timer_start(xbt_os_timer_t timer) {
+#ifdef HAVE_POSIX_GETTIME
+  clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&(timer->start));
+#elif defined(HAVE_GETTIMEOFDAY)
+  gettimeofday(&(timer->start), NULL);
+#else
+  timer->start = (unsigned long int) (time(NULL));
+#endif
+}
+
+void xbt_os_timer_stop(xbt_os_timer_t timer) {
+#ifdef HAVE_POSIX_GETTIME
+  clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&(timer->stop));
+#elif defined(HAVE_GETTIMEOFDAY)
+  gettimeofday(&(timer->stop), NULL);
+#else
+  timer->stop = (unsigned long int) (time(NULL));
+#endif
+}
+
+double xbt_os_timer_elapsed(xbt_os_timer_t timer)
+{
+#ifdef HAVE_POSIX_GETTIME
+  return ((double) timer->stop.tv_sec) - ((double) timer->start.tv_sec) +
+      ((((double) timer->stop.tv_nsec) -
+        ((double) timer->start.tv_nsec)) / 1e9);
+#elif defined(HAVE_GETTIMEOFDAY)
+  return ((double) timer->stop.tv_sec) - ((double) timer->start.tv_sec) +
+    ((((double) timer->stop.tv_usec) -
+      ((double) timer->start.tv_usec)) / 1000000.0);
+#else
+  return (double) timer->stop - (double) timer->start;
+#endif
+}