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;
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
*\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);
/*!<
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");
*/
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());