X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e37c1e4bba9bb89cd2842f08cde998eb7f941d04..1af04af978a0d15f9e4e16db1270e42ff0fc6d11:/src/xbt/dynar.c diff --git a/src/xbt/dynar.c b/src/xbt/dynar.c index 720b376b89..6924f0bd89 100644 --- a/src/xbt/dynar.c +++ b/src/xbt/dynar.c @@ -466,6 +466,19 @@ xbt_dynar_remove_n_at(xbt_dynar_t const dynar, /** @brief Returns the position of the element in the dynar * + * Beware that if your dynar contains pointed values (such as strings) instead + * of scalar, this function compares the pointer value, not what's pointed. The only + * solution to search for a pointed value is then to write the foreach loop yourself: + * \code + * signed int position = -1; + * xbt_dynar_foreach(dynar, iter, elem) { + * if (!memcmp(elem, searched_element, sizeof(*elem))) { + * position = iter; + * break; + * } + * } + * \endcode + * * Raises not_found_error if not found. If you have less than 2 millions elements, * you probably want to use #xbt_dynar_search_or_negative() instead, so that you * don't have to TRY/CATCH on element not found. @@ -485,6 +498,10 @@ unsigned int xbt_dynar_search(xbt_dynar_t const dynar, void *const elem) /** @brief Returns the position of the element in the dynar (or -1 if not found) * + * Beware that if your dynar contains pointed values (such as + * strings) instead of scalar, this function is probably not what you + * want. Check the documentation of xbt_dynar_search() for more info. + * * Note that usually, the dynar indices are unsigned integers. If you have more * than 2 million elements in your dynar, this very function will not work (but the other will). */ @@ -500,7 +517,12 @@ signed int xbt_dynar_search_or_negative(xbt_dynar_t const dynar, void *const ele return -1; } -/** @brief Returns a boolean indicating whether the element is part of the dynar */ +/** @brief Returns a boolean indicating whether the element is part of the dynar + * + * Beware that if your dynar contains pointed values (such as + * strings) instead of scalar, this function is probably not what you + * want. Check the documentation of xbt_dynar_search() for more info. + */ int xbt_dynar_member(xbt_dynar_t const dynar, void *const elem) { @@ -526,9 +548,6 @@ int xbt_dynar_member(xbt_dynar_t const dynar, void *const elem) */ XBT_INLINE void *xbt_dynar_push_ptr(xbt_dynar_t const dynar) { - /* we have to inline xbt_dynar_insert_at_ptr here to make sure that - dynar->used don't change between reading it and getting the lock - within xbt_dynar_insert_at_ptr */ return xbt_dynar_insert_at_ptr(dynar, dynar->used); } @@ -537,8 +556,7 @@ XBT_INLINE void xbt_dynar_push(xbt_dynar_t const dynar, const void *const src) { /* checks done in xbt_dynar_insert_at_ptr */ - memcpy(xbt_dynar_insert_at_ptr(dynar, dynar->used), src, - dynar->elmsize); + memcpy(xbt_dynar_insert_at_ptr(dynar, dynar->used), src, dynar->elmsize); } /** @brief Mark the last dynar's element as unused and return a pointer to it.