]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Change isc_buffer_reallocate() into a static functions as it is not used outside...
authorOndřej Surý <ondrej@sury.org>
Sat, 28 Jul 2018 04:24:12 +0000 (06:24 +0200)
committerOndřej Surý <ondrej@sury.org>
Tue, 31 Jul 2018 20:00:30 +0000 (22:00 +0200)
lib/isc/buffer.c
lib/isc/include/isc/buffer.h
lib/isc/tests/buffer_test.c
lib/isc/win32/libisc.def.in

index 166d1ded4d22446ae95222a72cb367d8e9a92f84..095ee2530b09b5da25d4397423ab291481ac918a 100644 (file)
@@ -568,46 +568,22 @@ isc_buffer_allocate(isc_mem_t *mctx, isc_buffer_t **dynbuffer,
        return (ISC_R_SUCCESS);
 }
 
-isc_result_t
-isc_buffer_reallocate(isc_buffer_t **dynbuffer, unsigned int length) {
-       unsigned char *bdata;
-
-       REQUIRE(dynbuffer != NULL);
-       REQUIRE(ISC_BUFFER_VALID(*dynbuffer));
-       REQUIRE((*dynbuffer)->mctx != NULL);
-
-       /*
-        * XXXMUKS: This is far more expensive than plain realloc() as
-        * it doesn't remap pages, but does ordinary copy. So is
-        * isc_mem_reallocate(), which has additional issues.
-        */
-       bdata = isc_mem_get((*dynbuffer)->mctx, length);
-       if (bdata == NULL)
-               return (ISC_R_NOMEMORY);
-
-       memmove(bdata, (*dynbuffer)->base, (*dynbuffer)->length);
-       isc_mem_put((*dynbuffer)->mctx, (*dynbuffer)->base,
-                   (*dynbuffer)->length);
-
-       (*dynbuffer)->base = bdata;
-       (*dynbuffer)->length = length;
-
-       return (ISC_R_SUCCESS);
-}
-
 isc_result_t
 isc_buffer_reserve(isc_buffer_t **dynbuffer, unsigned int size) {
+       unsigned char *bdata;
        isc_uint64_t len;
 
        REQUIRE(dynbuffer != NULL);
        REQUIRE(ISC_BUFFER_VALID(*dynbuffer));
 
        len = (*dynbuffer)->length;
-       if ((len - (*dynbuffer)->used) >= size)
+       if ((len - (*dynbuffer)->used) >= size) {
                return (ISC_R_SUCCESS);
+       }
 
-       if ((*dynbuffer)->mctx == NULL)
+       if ((*dynbuffer)->mctx == NULL) {
                return (ISC_R_NOSPACE);
+       }
 
        /* Round to nearest buffer size increment */
        len = size + (*dynbuffer)->used;
@@ -618,10 +594,28 @@ isc_buffer_reserve(isc_buffer_t **dynbuffer, unsigned int size) {
                len = UINT_MAX;
        }
 
-       if ((len - (*dynbuffer)->used) < size)
+       if ((len - (*dynbuffer)->used) < size) {
                return (ISC_R_NOMEMORY);
+       }
 
-       return (isc_buffer_reallocate(dynbuffer, (unsigned int) len));
+       /*
+        * XXXMUKS: This is far more expensive than plain realloc() as
+        * it doesn't remap pages, but does ordinary copy. So is
+        * isc_mem_reallocate(), which has additional issues.
+        */
+       bdata = isc_mem_get((*dynbuffer)->mctx, (unsigned int) len);
+       if (bdata == NULL) {
+               return (ISC_R_NOMEMORY);
+       }
+
+       memmove(bdata, (*dynbuffer)->base, (*dynbuffer)->length);
+       isc_mem_put((*dynbuffer)->mctx, (*dynbuffer)->base,
+                   (*dynbuffer)->length);
+
+       (*dynbuffer)->base = bdata;
+       (*dynbuffer)->length = (unsigned int) len;
+
+       return (ISC_R_SUCCESS);
 }
 
 void
index 9af0f40fe32fefef839fb0c205de900612a02a2c..edcbc6f913ea576a622c71c408d80e3df32e79e0 100644 (file)
@@ -209,29 +209,6 @@ isc_buffer_allocate(isc_mem_t *mctx, isc_buffer_t **dynbuffer,
  *\li  Changing the buffer's length field is not permitted.
  */
 
-isc_result_t
-isc_buffer_reallocate(isc_buffer_t **dynbuffer, unsigned int length);
-/*!<
- * \brief Reallocate the buffer to be "length" bytes long. The buffer
- * pointer may move when you call this function.
- *
- * Requires:
- *\li  "dynbuffer" is not NULL.
- *
- *\li  "*dynbuffer" is a valid dynamic buffer.
- *
- *\li  'length' > current length of buffer.
- *
- * Returns:
- *\li  ISC_R_SUCCESS           - success
- *\li  ISC_R_NOMEMORY          - no memory available
- *
- * Ensures:
- *\li  "*dynbuffer" will be valid on return and will contain all the
- *     original data. However, the buffer pointer may be moved during
- *     reallocation.
- */
-
 isc_result_t
 isc_buffer_reserve(isc_buffer_t **dynbuffer, unsigned int size);
 /*!<
index d584c51c23c3a675740ba095d78185fc4c7eb3f5..ba145f92da9eb43ec2fc5494a45005ffea7ee56a 100644 (file)
@@ -96,35 +96,6 @@ ATF_TC_BODY(isc_buffer_reserve, tc) {
        isc_test_end();
 }
 
-ATF_TC(isc_buffer_reallocate);
-ATF_TC_HEAD(isc_buffer_reallocate, tc) {
-       atf_tc_set_md_var(tc, "descr", "reallocate dynamic buffers");
-}
-
-ATF_TC_BODY(isc_buffer_reallocate, tc) {
-       isc_result_t result;
-       isc_buffer_t *b;
-
-       result = isc_test_begin(NULL, ISC_TRUE, 0);
-       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
-
-       b = NULL;
-       result = isc_buffer_allocate(mctx, &b, 1024);
-       ATF_CHECK_EQ(result, ISC_R_SUCCESS);
-       ATF_REQUIRE(b != NULL);
-       ATF_CHECK_EQ(b->length, 1024);
-
-       result = isc_buffer_reallocate(&b, 1536);
-       ATF_CHECK_EQ(result, ISC_R_SUCCESS);
-       ATF_CHECK(ISC_BUFFER_VALID(b));
-       ATF_REQUIRE(b != NULL);
-       ATF_CHECK_EQ(b->length, 1536);
-
-       isc_buffer_free(&b);
-
-       isc_test_end();
-}
-
 ATF_TC(isc_buffer_dynamic);
 ATF_TC_HEAD(isc_buffer_dynamic, tc) {
        atf_tc_set_md_var(tc, "descr", "dynamic buffer automatic reallocation");
@@ -306,7 +277,6 @@ ATF_TC_BODY(isc_buffer_printf, tc) {
  */
 ATF_TP_ADD_TCS(tp) {
        ATF_TP_ADD_TC(tp, isc_buffer_reserve);
-       ATF_TP_ADD_TC(tp, isc_buffer_reallocate);
        ATF_TP_ADD_TC(tp, isc_buffer_dynamic);
        ATF_TP_ADD_TC(tp, isc_buffer_printf);
        return (atf_no_error());
index 1e112fa93d7a312d9bd37281edf02f7b52ed1732..aa4e71178f804622792a057b457fe521382da164 100644 (file)
@@ -164,7 +164,6 @@ isc_buffer_getuint48
 isc_buffer_getuint8
 isc_buffer_printf
 isc_buffer_putdecint
-isc_buffer_reallocate
 isc_buffer_reinit
 isc_buffer_reserve
 isc_buffer_setautorealloc