From: Ondřej Surý Date: Sat, 28 Jul 2018 04:24:12 +0000 (+0200) Subject: Change isc_buffer_reallocate() into a static functions as it is not used outside... X-Git-Tag: v9.13.3~90^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=20faf4652a772eb95271ed698f7be13cd5079ad2;p=thirdparty%2Fbind9.git Change isc_buffer_reallocate() into a static functions as it is not used outside of isc_buffer_reserve() --- diff --git a/lib/isc/buffer.c b/lib/isc/buffer.c index 166d1ded4d2..095ee2530b0 100644 --- a/lib/isc/buffer.c +++ b/lib/isc/buffer.c @@ -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 diff --git a/lib/isc/include/isc/buffer.h b/lib/isc/include/isc/buffer.h index 9af0f40fe32..edcbc6f913e 100644 --- a/lib/isc/include/isc/buffer.h +++ b/lib/isc/include/isc/buffer.h @@ -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); /*!< diff --git a/lib/isc/tests/buffer_test.c b/lib/isc/tests/buffer_test.c index d584c51c23c..ba145f92da9 100644 --- a/lib/isc/tests/buffer_test.c +++ b/lib/isc/tests/buffer_test.c @@ -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()); diff --git a/lib/isc/win32/libisc.def.in b/lib/isc/win32/libisc.def.in index 1e112fa93d7..aa4e71178f8 100644 --- a/lib/isc/win32/libisc.def.in +++ b/lib/isc/win32/libisc.def.in @@ -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