mirror of
https://github.com/isc-projects/bind9.git
synced 2026-03-15 23:22:35 -04:00
Merge branch '3553-static-buffer-functions-v9_18' into 'v9_18'
change ISC__BUFFER macros to inline functions See merge request isc-projects/bind9!6819
This commit is contained in:
commit
a44ccdbabb
4 changed files with 549 additions and 889 deletions
|
|
@ -615,7 +615,7 @@ gcc:oraclelinux8:amd64:
|
|||
variables:
|
||||
CC: gcc
|
||||
CFLAGS: "${CFLAGS_COMMON}"
|
||||
EXTRA_CONFIGURE: "--enable-buffer-useinline --with-libidn2"
|
||||
EXTRA_CONFIGURE: "--with-libidn2"
|
||||
<<: *oraclelinux_8_amd64_image
|
||||
<<: *build_job
|
||||
|
||||
|
|
@ -1486,6 +1486,16 @@ gcov:
|
|||
# Help gcovr process the nasty tricks in lib/dns/code.h, where we include C
|
||||
# source files from lib/dns/rdata/*/, using an even nastier trick.
|
||||
- find lib/dns/rdata/* -name "*.c" -execdir cp -f "{}" ../../ \;
|
||||
# Help gcovr process inline functions in headers
|
||||
- cp -f lib/dns/include/dns/*.h lib/dns/
|
||||
- cp -f lib/dns/include/dns/*.h lib/ns/
|
||||
- cp -f lib/isc/include/isc/*.h lib/isc/
|
||||
- cp -f lib/isc/include/isc/*.h lib/dns/
|
||||
- cp -f lib/isc/include/isc/*.h lib/ns/
|
||||
- find bin lib -maxdepth 1 -mindepth 1 -type d -exec cp -f lib/isc/include/isc/buffer.h "{}" \;
|
||||
- cp -f lib/isc/include/isc/buffer.h fuzz/
|
||||
- cp -f lib/isc/include/isc/buffer.h lib/isc/netmgr/buffer.h
|
||||
- cp -f lib/isc/include/isc/hash.h lib/dns/hash.h
|
||||
# Generate XML file in the Cobertura XML format suitable for use by GitLab
|
||||
# for the purpose of displaying code coverage information in the diff view
|
||||
# of a given merge request.
|
||||
|
|
|
|||
12
configure.ac
12
configure.ac
|
|
@ -186,18 +186,6 @@ PKG_PROG_PKG_CONFIG
|
|||
AS_IF([test -z "$PKG_CONFIG"],
|
||||
[AC_MSG_ERROR([The pkg-config script could not be found or is too old.])])
|
||||
|
||||
# [pairwise: --enable-buffer-useinline, --disable-buffer-useinline]
|
||||
AC_ARG_ENABLE(buffer_useinline,
|
||||
AS_HELP_STRING([--enable-buffer-useinline],
|
||||
[define ISC_BUFFER_USEINLINE when compiling
|
||||
[default=yes]]),
|
||||
if test yes = "${enable}"
|
||||
then
|
||||
AC_DEFINE([ISC_BUFFER_USEINLINE], [1],
|
||||
[Define if you want to use inline buffers])
|
||||
fi,
|
||||
AC_DEFINE([ISC_BUFFER_USEINLINE], [1]))
|
||||
|
||||
# Fuzzing is not included in pairwise testing as fuzzing tools are
|
||||
# not present in the relevant Docker image.
|
||||
#
|
||||
|
|
|
|||
298
lib/isc/buffer.c
298
lib/isc/buffer.c
|
|
@ -24,28 +24,6 @@
|
|||
#include <isc/string.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
void
|
||||
isc__buffer_init(isc_buffer_t *b, void *base, unsigned int length) {
|
||||
/*
|
||||
* Make 'b' refer to the 'length'-byte region starting at 'base'.
|
||||
* XXXDCL see the comment in buffer.h about base being const.
|
||||
*/
|
||||
|
||||
REQUIRE(b != NULL);
|
||||
|
||||
ISC__BUFFER_INIT(b, base, length);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_initnull(isc_buffer_t *b) {
|
||||
/*
|
||||
* Initialize a new buffer which has no backing store. This can
|
||||
* later be grown as needed and swapped in place.
|
||||
*/
|
||||
|
||||
ISC__BUFFER_INIT(b, NULL, 0);
|
||||
}
|
||||
|
||||
void
|
||||
isc_buffer_reinit(isc_buffer_t *b, void *base, unsigned int length) {
|
||||
/*
|
||||
|
|
@ -69,19 +47,6 @@ isc_buffer_reinit(isc_buffer_t *b, void *base, unsigned int length) {
|
|||
b->length = length;
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_invalidate(isc_buffer_t *b) {
|
||||
/*
|
||||
* Make 'b' an invalid buffer.
|
||||
*/
|
||||
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
REQUIRE(!ISC_LINK_LINKED(b, link));
|
||||
REQUIRE(b->mctx == NULL);
|
||||
|
||||
ISC__BUFFER_INVALIDATE(b);
|
||||
}
|
||||
|
||||
void
|
||||
isc_buffer_setautorealloc(isc_buffer_t *b, bool enable) {
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
|
|
@ -89,160 +54,6 @@ isc_buffer_setautorealloc(isc_buffer_t *b, bool enable) {
|
|||
b->autore = enable;
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_region(isc_buffer_t *b, isc_region_t *r) {
|
||||
/*
|
||||
* Make 'r' refer to the region of 'b'.
|
||||
*/
|
||||
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
REQUIRE(r != NULL);
|
||||
|
||||
ISC__BUFFER_REGION(b, r);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_usedregion(const isc_buffer_t *b, isc_region_t *r) {
|
||||
/*
|
||||
* Make 'r' refer to the used region of 'b'.
|
||||
*/
|
||||
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
REQUIRE(r != NULL);
|
||||
|
||||
ISC__BUFFER_USEDREGION(b, r);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_availableregion(isc_buffer_t *b, isc_region_t *r) {
|
||||
/*
|
||||
* Make 'r' refer to the available region of 'b'.
|
||||
*/
|
||||
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
REQUIRE(r != NULL);
|
||||
|
||||
ISC__BUFFER_AVAILABLEREGION(b, r);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_add(isc_buffer_t *b, unsigned int n) {
|
||||
/*
|
||||
* Increase the 'used' region of 'b' by 'n' bytes.
|
||||
*/
|
||||
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
REQUIRE(b->used + n <= b->length);
|
||||
|
||||
ISC__BUFFER_ADD(b, n);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_subtract(isc_buffer_t *b, unsigned int n) {
|
||||
/*
|
||||
* Decrease the 'used' region of 'b' by 'n' bytes.
|
||||
*/
|
||||
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
REQUIRE(b->used >= n);
|
||||
|
||||
ISC__BUFFER_SUBTRACT(b, n);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_clear(isc_buffer_t *b) {
|
||||
/*
|
||||
* Make the used region empty.
|
||||
*/
|
||||
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
|
||||
ISC__BUFFER_CLEAR(b);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_consumedregion(isc_buffer_t *b, isc_region_t *r) {
|
||||
/*
|
||||
* Make 'r' refer to the consumed region of 'b'.
|
||||
*/
|
||||
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
REQUIRE(r != NULL);
|
||||
|
||||
ISC__BUFFER_CONSUMEDREGION(b, r);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_remainingregion(isc_buffer_t *b, isc_region_t *r) {
|
||||
/*
|
||||
* Make 'r' refer to the remaining region of 'b'.
|
||||
*/
|
||||
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
REQUIRE(r != NULL);
|
||||
|
||||
ISC__BUFFER_REMAININGREGION(b, r);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_activeregion(isc_buffer_t *b, isc_region_t *r) {
|
||||
/*
|
||||
* Make 'r' refer to the active region of 'b'.
|
||||
*/
|
||||
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
REQUIRE(r != NULL);
|
||||
|
||||
ISC__BUFFER_ACTIVEREGION(b, r);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_setactive(isc_buffer_t *b, unsigned int n) {
|
||||
/*
|
||||
* Sets the end of the active region 'n' bytes after current.
|
||||
*/
|
||||
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
REQUIRE(b->current + n <= b->used);
|
||||
|
||||
ISC__BUFFER_SETACTIVE(b, n);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_first(isc_buffer_t *b) {
|
||||
/*
|
||||
* Make the consumed region empty.
|
||||
*/
|
||||
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
|
||||
ISC__BUFFER_FIRST(b);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_forward(isc_buffer_t *b, unsigned int n) {
|
||||
/*
|
||||
* Increase the 'consumed' region of 'b' by 'n' bytes.
|
||||
*/
|
||||
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
REQUIRE(b->current + n <= b->used);
|
||||
|
||||
ISC__BUFFER_FORWARD(b, n);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_back(isc_buffer_t *b, unsigned int n) {
|
||||
/*
|
||||
* Decrease the 'consumed' region of 'b' by 'n' bytes.
|
||||
*/
|
||||
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
REQUIRE(n <= b->current);
|
||||
|
||||
ISC__BUFFER_BACK(b, n);
|
||||
}
|
||||
|
||||
void
|
||||
isc_buffer_compact(isc_buffer_t *b) {
|
||||
unsigned int length;
|
||||
|
|
@ -290,19 +101,6 @@ isc_buffer_getuint8(isc_buffer_t *b) {
|
|||
return (result);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_putuint8(isc_buffer_t *b, uint8_t val) {
|
||||
isc_result_t result;
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
if (b->autore) {
|
||||
result = isc_buffer_reserve(&b, 1);
|
||||
REQUIRE(result == ISC_R_SUCCESS);
|
||||
}
|
||||
REQUIRE(isc_buffer_availablelength(b) >= 1);
|
||||
|
||||
ISC__BUFFER_PUTUINT8(b, val);
|
||||
}
|
||||
|
||||
uint16_t
|
||||
isc_buffer_getuint16(isc_buffer_t *b) {
|
||||
unsigned char *cp;
|
||||
|
|
@ -324,32 +122,6 @@ isc_buffer_getuint16(isc_buffer_t *b) {
|
|||
return (result);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_putuint16(isc_buffer_t *b, uint16_t val) {
|
||||
isc_result_t result;
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
if (b->autore) {
|
||||
result = isc_buffer_reserve(&b, 2);
|
||||
REQUIRE(result == ISC_R_SUCCESS);
|
||||
}
|
||||
REQUIRE(isc_buffer_availablelength(b) >= 2);
|
||||
|
||||
ISC__BUFFER_PUTUINT16(b, val);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_putuint24(isc_buffer_t *b, uint32_t val) {
|
||||
isc_result_t result;
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
if (b->autore) {
|
||||
result = isc_buffer_reserve(&b, 3);
|
||||
REQUIRE(result == ISC_R_SUCCESS);
|
||||
}
|
||||
REQUIRE(isc_buffer_availablelength(b) >= 3);
|
||||
|
||||
ISC__BUFFER_PUTUINT24(b, val);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
isc_buffer_getuint32(isc_buffer_t *b) {
|
||||
unsigned char *cp;
|
||||
|
|
@ -373,19 +145,6 @@ isc_buffer_getuint32(isc_buffer_t *b) {
|
|||
return (result);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_putuint32(isc_buffer_t *b, uint32_t val) {
|
||||
isc_result_t result;
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
if (b->autore) {
|
||||
result = isc_buffer_reserve(&b, 4);
|
||||
REQUIRE(result == ISC_R_SUCCESS);
|
||||
}
|
||||
REQUIRE(isc_buffer_availablelength(b) >= 4);
|
||||
|
||||
ISC__BUFFER_PUTUINT32(b, val);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
isc_buffer_getuint48(isc_buffer_t *b) {
|
||||
unsigned char *cp;
|
||||
|
|
@ -411,63 +170,6 @@ isc_buffer_getuint48(isc_buffer_t *b) {
|
|||
return (result);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_putuint48(isc_buffer_t *b, uint64_t val) {
|
||||
isc_result_t result;
|
||||
uint16_t valhi;
|
||||
uint32_t vallo;
|
||||
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
if (b->autore) {
|
||||
result = isc_buffer_reserve(&b, 6);
|
||||
REQUIRE(result == ISC_R_SUCCESS);
|
||||
}
|
||||
REQUIRE(isc_buffer_availablelength(b) >= 6);
|
||||
|
||||
valhi = (uint16_t)(val >> 32);
|
||||
vallo = (uint32_t)(val & 0xFFFFFFFF);
|
||||
ISC__BUFFER_PUTUINT16(b, valhi);
|
||||
ISC__BUFFER_PUTUINT32(b, vallo);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_putmem(isc_buffer_t *b, const unsigned char *base,
|
||||
unsigned int length) {
|
||||
isc_result_t result;
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
if (b->autore) {
|
||||
result = isc_buffer_reserve(&b, length);
|
||||
REQUIRE(result == ISC_R_SUCCESS);
|
||||
}
|
||||
REQUIRE(isc_buffer_availablelength(b) >= length);
|
||||
|
||||
ISC__BUFFER_PUTMEM(b, base, length);
|
||||
}
|
||||
|
||||
void
|
||||
isc__buffer_putstr(isc_buffer_t *b, const char *source) {
|
||||
unsigned int l;
|
||||
unsigned char *cp;
|
||||
isc_result_t result;
|
||||
|
||||
REQUIRE(ISC_BUFFER_VALID(b));
|
||||
REQUIRE(source != NULL);
|
||||
|
||||
/*
|
||||
* Do not use ISC__BUFFER_PUTSTR(), so strlen is only done once.
|
||||
*/
|
||||
l = strlen(source);
|
||||
if (b->autore) {
|
||||
result = isc_buffer_reserve(&b, l);
|
||||
REQUIRE(result == ISC_R_SUCCESS);
|
||||
}
|
||||
REQUIRE(isc_buffer_availablelength(b) >= l);
|
||||
|
||||
cp = isc_buffer_used(b);
|
||||
memmove(cp, source, l);
|
||||
b->used += l;
|
||||
}
|
||||
|
||||
void
|
||||
isc_buffer_putdecint(isc_buffer_t *b, int64_t v) {
|
||||
unsigned int l = 0;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue