eina_buf: replace eina_strbuf_free_return with eina_xXxbuf_release
authorMarcel Hollerbach <marcel-hollerbach@t-online.de>
Fri, 6 Jan 2017 11:18:32 +0000 (12:18 +0100)
committerMarcel Hollerbach <marcel-hollerbach@t-online.de>
Fri, 6 Jan 2017 11:45:27 +0000 (12:45 +0100)
The api name free_return wasnt a good choice so it is changed to
release. This also moves the implementation to binbuf template so it is
available in all buf types.

src/lib/eina/eina_binbuf.h
src/lib/eina/eina_binbuf_template_c.x
src/lib/eina/eina_strbuf.c
src/lib/eina/eina_strbuf.h
src/lib/eina/eina_ustrbuf.h
src/tests/eina/eina_test_strbuf.c

index e10728e..8c6d3a4 100644 (file)
@@ -388,6 +388,17 @@ EAPI Eina_Slice eina_binbuf_slice_get(const Eina_Binbuf *buf) EINA_WARN_UNUSED_R
  * @since 1.19
  */
 EAPI Eina_Rw_Slice eina_binbuf_rw_slice_get(const Eina_Binbuf *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
+/**
+ * @brief Get the content of the buffer and free the buffer
+ *
+ * @param buf the buffer to get the content from and which will be freed
+ *
+ * @return The content contained by buf. The caller must release the memory of the returned content by calling
+ * free().
+ *
+ * @since 1.19
+ */
+EAPI unsigned char* eina_binbuf_release(Eina_Binbuf *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
 
 /**
  * @}
index 72b6fd7..2699997 100644 (file)
@@ -216,3 +216,14 @@ _FUNC_EXPAND(rw_slice_get)(const _STRBUF_STRUCT_NAME *buf)
    EINA_MAGIC_CHECK_STRBUF(buf, ret);
    return eina_strbuf_common_rw_slice_get(buf);
 }
+
+EAPI _STRBUF_DATA_TYPE*
+_FUNC_EXPAND(release)(_STRBUF_STRUCT_NAME *buf)
+{
+   _STRBUF_DATA_TYPE *result;
+
+   result = _FUNC_EXPAND(string_steal)(buf);
+   _FUNC_EXPAND(string_free)(buf);
+
+   return result;
+}
index b784a70..81ab30a 100644 (file)
@@ -220,17 +220,6 @@ eina_strbuf_substr_get(Eina_Strbuf *buf, size_t pos, size_t len)
    return eina_strbuf_manage_new(str);
 }
 
-EAPI char*
-eina_strbuf_free_return(Eina_Strbuf *buf)
-{
-   char *result;
-
-   result = eina_strbuf_string_steal(buf);
-   eina_strbuf_free(buf);
-
-   return result;
-}
-
 /* Unicode */
 
 #include "eina_strbuf_template_c.x"
index 9c2506c..cd70a3d 100644 (file)
@@ -729,7 +729,7 @@ EAPI Eina_Rw_Slice eina_strbuf_rw_slice_get(const Eina_Strbuf *buf) EINA_WARN_UN
  *
  * @since 1.19
  */
-EAPI char* eina_strbuf_free_return(Eina_Strbuf *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
+EAPI char* eina_strbuf_release(Eina_Strbuf *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
 
 /**
  * @}
index b0c6799..f186b2c 100644 (file)
@@ -469,6 +469,18 @@ EAPI Eina_Slice eina_ustrbuf_slice_get(const Eina_UStrbuf *buf) EINA_WARN_UNUSED
 EAPI Eina_Rw_Slice eina_ustrbuf_rw_slice_get(const Eina_UStrbuf *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
 
 /**
+ * @brief Get the string of the buffer and free the buffer
+ *
+ * @param buf the buffer to get the string from and which will be freed
+ *
+ * @return The string contained by buf. The caller must release the memory of the returned string by calling
+ * free().
+ *
+ * @since 1.19
+ */
+EAPI Eina_Unicode* eina_ustrbuf_release(Eina_UStrbuf *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
+
+/**
  * @}
  */
 
index 8206720..0511d96 100644 (file)
@@ -646,17 +646,17 @@ START_TEST(strbuf_prepend_print)
 }
 END_TEST
 
-START_TEST(strbuf_free_return_test)
+START_TEST(strbuf_release_test)
 {
    Eina_Strbuf *buf;
    char *string;
 
    buf = eina_strbuf_new();
    ck_assert_ptr_ne(buf, NULL);
-   eina_strbuf_append(buf, "strbuf_free_return_test");
+   eina_strbuf_append(buf, "strbuf_release_test");
 
-   string = eina_strbuf_free_return(buf);
-   ck_assert_str_eq(string, "strbuf_free_return_test");
+   string = eina_strbuf_release(buf);
+   ck_assert_str_eq(string, "strbuf_release_test");
 }
 END_TEST
 
@@ -676,5 +676,5 @@ eina_test_strbuf(TCase *tc)
    tcase_add_test(tc, strbuf_tolower);
    tcase_add_test(tc, strbuf_substr_get);
    tcase_add_test(tc, strbuf_prepend_print);
-   tcase_add_test(tc, strbuf_free_return_test);
+   tcase_add_test(tc, strbuf_release_test);
 }