From 1c712008ba8d59e1f90b173a86a8bbeef5edbaed Mon Sep 17 00:00:00 2001 From: suter Date: Thu, 2 Dec 2010 13:35:59 +0000 Subject: [PATCH 1/1] Add a new function xbt_dynar_to_array that transforms a dynar into a NULL-terminated array. This may solve backward compatibility issues due to the change to return type of SD_Simulate. See also: http://lists.gforge.inria.fr/pipermail/simgrid-user/2010-December/002206.html git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8882 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- ChangeLog | 6 ++++++ include/xbt/dynar.h | 1 + src/xbt/dynar.c | 13 +++++++++++++ 3 files changed, 20 insertions(+) diff --git a/ChangeLog b/ChangeLog index 82f02777d5..bd7d97aa56 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,12 @@ SimGrid (3.6) unstable; urgency=low Simix * completely rewrote this module to allow parallel execution. + XBT + * Add a new function xbt_dynar_to_array that transforms a dynar into a + NULL-terminated array. This may solve backward compatibility issues + due to the change to return type of SD_Simulate. See also: + http://lists.gforge.inria.fr/pipermail/simgrid-user/2010-December/002206.html + -- Da SimGrid team SimGrid (3.5) stable; urgency=medium diff --git a/include/xbt/dynar.h b/include/xbt/dynar.h index b38a3e6265..563cf2a4ca 100644 --- a/include/xbt/dynar.h +++ b/include/xbt/dynar.h @@ -108,6 +108,7 @@ XBT_PUBLIC(void) xbt_dynar_sort(xbt_dynar_t const dynar, int_f_cpvoid_cpvoid_t compar_fn); XBT_INLINE XBT_PUBLIC(int) xbt_dynar_compare(xbt_dynar_t d1, xbt_dynar_t d2, int(*compar)(const void *, const void *)); +XBT_INLINE void * xbt_dynar_to_array (xbt_dynar_t dynar); /** @} */ /** @defgroup XBT_dynar_perl Perl-like use of dynars diff --git a/src/xbt/dynar.c b/src/xbt/dynar.c index 1065cc5c90..c84b2ee084 100644 --- a/src/xbt/dynar.c +++ b/src/xbt/dynar.c @@ -748,6 +748,19 @@ XBT_INLINE void xbt_dynar_sort(xbt_dynar_t dynar, _dynar_unlock(dynar); } +/** @brief Transform a dynar into a NULL terminated array + * + * \param dynar the dynar to transform + */ +XBT_INLINE void * xbt_dynar_to_array (xbt_dynar_t dynar) +{ + void * last = xbt_new0(char,dynar->elmsize); + xbt_dynar_push(dynar, last); + free(last); + dynar->used--; + return dynar->data; +} + /* * Return 0 if d1 and d2 are equal and 1 if not equal */ -- 2.20.1