mirror of
https://github.com/isc-projects/bind9.git
synced 2026-04-22 23:01:43 -04:00
Change isc_buffer_reallocate() into a static functions as it is not used outside of isc_buffer_reserve()
This commit is contained in:
parent
7785f644c3
commit
20faf4652a
4 changed files with 25 additions and 85 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
/*!<
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue