2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-03 08:05:21 +00:00

Megacommit of many files.

Mostly, several functions that take pointers as arguments, almost
always char * pointers, had those pointers qualified with "const".
Those that returned pointers to previously const-qualified arguments
had their return values qualified as const.  Some structure members
were qualified as const to retain that attribute from the variables
from which they were assigned.

The macro DE_CONST was added to isc/util.h to deal with a handful of very
special places where something is qualified as const but really needs to have
its const qualifier removed.

Also cleaned up a few places where variable names clashed with reserved
identifiers.  (Which mostly works fine, but strictly speaking is undefined
by the standard.)

Minor other ISC style cleanups.
This commit is contained in:
David Lawrence
2000-06-01 17:20:56 +00:00
parent fd6de7af32
commit 87cafc5e70
33 changed files with 685 additions and 516 deletions

View File

@@ -26,7 +26,8 @@
* Forward.
*/
static void default_callback(char *, int, isc_assertiontype_t, char *);
static void
default_callback(const char *, int, isc_assertiontype_t, const char *);
/*
* Public.
@@ -42,9 +43,9 @@ isc_assertion_setcallback(isc_assertioncallback_t cb) {
isc_assertion_failed = cb;
}
char *
const char *
isc_assertion_typetotext(isc_assertiontype_t type) {
char *result;
const char *result;
switch (type) {
case isc_assertiontype_require:
@@ -70,7 +71,9 @@ isc_assertion_typetotext(isc_assertiontype_t type) {
*/
static void
default_callback(char *file, int line, isc_assertiontype_t type, char *cond) {
default_callback(const char *file, int line, isc_assertiontype_t type,
const char *cond)
{
fprintf(stderr, "%s:%d: %s(%s) failed.\n",
file, line, isc_assertion_typetotext(type), cond);
fflush(stderr);

View File

@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: base64.c,v 1.13 2000/05/16 05:19:46 tale Exp $ */
/* $Id: base64.c,v 1.14 2000/06/01 17:20:18 tale Exp $ */
#include <config.h>
@@ -36,18 +36,22 @@
* These static functions are also present in lib/dns/rdata.c. I'm not
* sure where they should go. -- bwelling
*/
static isc_result_t str_totext(char *source, isc_buffer_t *target);
static isc_result_t gettoken(isc_lex_t *lexer, isc_token_t *token,
isc_tokentype_t expect, isc_boolean_t eol);
static isc_result_t mem_tobuffer(isc_buffer_t *target, void *base,
unsigned int length);
static isc_result_t
str_totext(const char *source, isc_buffer_t *target);
static isc_result_t
gettoken(isc_lex_t *lexer, isc_token_t *token, isc_tokentype_t expect,
isc_boolean_t eol);
static isc_result_t
mem_tobuffer(isc_buffer_t *target, void *base, unsigned int length);
static const char base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
isc_result_t
isc_base64_totext(isc_region_t *source, int wordlength,
char *wordbreak, isc_buffer_t *target)
const char *wordbreak, isc_buffer_t *target)
{
char buf[5];
unsigned int loops = 0;
@@ -157,7 +161,7 @@ isc_base64_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length) {
}
static isc_result_t
str_totext(char *source, isc_buffer_t *target) {
str_totext(const char *source, isc_buffer_t *target) {
unsigned int l;
isc_region_t region;

View File

@@ -24,9 +24,10 @@
#include <isc/util.h>
void
isc__buffer_init(isc_buffer_t *b, void *base, unsigned int length) {
isc__buffer_init(isc_buffer_t *b, const void *base, unsigned int length) {
/*
* Make 'b' refer to the 'length'-byte region starting at base.
* 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);
@@ -214,8 +215,8 @@ isc_buffer_compact(isc_buffer_t *b) {
REQUIRE(ISC_BUFFER_VALID(b));
src = (unsigned char *)b->base + b->current;
length = b->used - b->current;
src = isc_buffer_current(b);
length = isc_buffer_remaininglength(b);
(void)memmove(b->base, src, (size_t)length);
if (b->active > b->current)
@@ -238,17 +239,15 @@ isc_buffer_getuint8(isc_buffer_t *b) {
REQUIRE(ISC_BUFFER_VALID(b));
REQUIRE(b->used - b->current >= 1);
cp = b->base;
cp += b->current;
cp = isc_buffer_current(b);
b->current += 1;
result = ((unsigned int)(cp[0]));
result = ((isc_uint8_t)(cp[0]));
return (result);
}
void
isc__buffer_putuint8(isc_buffer_t *b, isc_uint8_t val)
{
isc__buffer_putuint8(isc_buffer_t *b, isc_uint8_t val) {
REQUIRE(ISC_BUFFER_VALID(b));
REQUIRE(b->used + 1 <= b->length);
@@ -268,8 +267,7 @@ isc_buffer_getuint16(isc_buffer_t *b) {
REQUIRE(ISC_BUFFER_VALID(b));
REQUIRE(b->used - b->current >= 2);
cp = b->base;
cp += b->current;
cp = isc_buffer_current(b);
b->current += 2;
result = ((unsigned int)(cp[0])) << 8;
result |= ((unsigned int)(cp[1]));
@@ -278,8 +276,7 @@ isc_buffer_getuint16(isc_buffer_t *b) {
}
void
isc__buffer_putuint16(isc_buffer_t *b, isc_uint16_t val)
{
isc__buffer_putuint16(isc_buffer_t *b, isc_uint16_t val) {
REQUIRE(ISC_BUFFER_VALID(b));
REQUIRE(b->used + 2 <= b->length);
@@ -299,8 +296,7 @@ isc_buffer_getuint32(isc_buffer_t *b) {
REQUIRE(ISC_BUFFER_VALID(b));
REQUIRE(b->used - b->current >= 4);
cp = b->base;
cp += b->current;
cp = isc_buffer_current(b);
b->current += 4;
result = ((unsigned int)(cp[0])) << 24;
result |= ((unsigned int)(cp[1])) << 16;
@@ -311,8 +307,7 @@ isc_buffer_getuint32(isc_buffer_t *b) {
}
void
isc__buffer_putuint32(isc_buffer_t *b, isc_uint32_t val)
{
isc__buffer_putuint32(isc_buffer_t *b, isc_uint32_t val) {
REQUIRE(ISC_BUFFER_VALID(b));
REQUIRE(b->used + 4 <= b->length);
@@ -320,7 +315,9 @@ isc__buffer_putuint32(isc_buffer_t *b, isc_uint32_t val)
}
void
isc__buffer_putmem(isc_buffer_t *b, unsigned char *base, unsigned int length) {
isc__buffer_putmem(isc_buffer_t *b, const unsigned char *base,
unsigned int length)
{
REQUIRE(ISC_BUFFER_VALID(b));
REQUIRE(b->used + length <= b->length);
@@ -328,13 +325,16 @@ isc__buffer_putmem(isc_buffer_t *b, unsigned char *base, unsigned int length) {
}
void
isc_buffer_putstr(isc_buffer_t *b, const char *source) {
isc__buffer_putstr(isc_buffer_t *b, const char *source) {
unsigned int l;
unsigned char *cp;
REQUIRE(ISC_BUFFER_VALID(b));
REQUIRE(source != NULL);
/*
* Do not use ISC__BUFFER_PUTSTR(), so strlen is only done once.
*/
l = strlen(source);
REQUIRE(l <= isc_buffer_availablelength(b));
@@ -352,8 +352,11 @@ isc_buffer_copyregion(isc_buffer_t *b, isc_region_t *r) {
REQUIRE(ISC_BUFFER_VALID(b));
REQUIRE(r != NULL);
base = (unsigned char *)b->base + b->used;
available = b->length - b->used;
/*
* XXXDCL
*/
base = isc_buffer_used(b);
available = isc_buffer_availablelength(b);
if (r->length > available)
return (ISC_R_NOSPACE);
memcpy(base, r->base, r->length);
@@ -385,8 +388,7 @@ isc_buffer_allocate(isc_mem_t *mctx, isc_buffer_t **dynbuffer,
}
void
isc_buffer_free(isc_buffer_t **dynbuffer)
{
isc_buffer_free(isc_buffer_t **dynbuffer) {
unsigned int real_length;
isc_buffer_t *dbuf;
isc_mem_t *mctx;

View File

@@ -48,7 +48,7 @@
* SUCH DAMAGE.
*/
/* $Id: commandline.c,v 1.6 2000/05/08 14:37:20 tale Exp $ */
/* $Id: commandline.c,v 1.7 2000/06/01 17:20:20 tale Exp $ */
/*
* This file was adapted from the NetBSD project's source tree, RCS ID:
@@ -80,9 +80,11 @@ char *isc_commandline_progname; /* For printing error messages. */
isc_boolean_t isc_commandline_errprint = ISC_TRUE; /* Print error messages. */
isc_boolean_t isc_commandline_reset = ISC_TRUE; /* Reset processing. */
static char endopt = '\0';
#define BADOPT '?'
#define BADARG ':'
#define ENDOPT ""
#define ENDOPT &endopt
/*
* getopt --

View File

@@ -23,10 +23,10 @@
#include <isc/error.h>
static void
default_unexpected_callback(char *, int, char *, va_list);
default_unexpected_callback(const char *, int, const char *, va_list);
static void
default_fatal_callback(char *, int, char *, va_list);
default_fatal_callback(const char *, int, const char *, va_list);
static isc_errorcallback_t unexpected_callback = default_unexpected_callback;
static isc_errorcallback_t fatal_callback = default_fatal_callback;
@@ -48,7 +48,7 @@ isc_error_setfatal(isc_errorcallback_t cb) {
}
void
isc_error_unexpected(char *file, int line, char *format, ...) {
isc_error_unexpected(const char *file, int line, const char *format, ...) {
va_list args;
va_start(args, format);
@@ -57,7 +57,7 @@ isc_error_unexpected(char *file, int line, char *format, ...) {
}
void
isc_error_fatal(char *file, int line, char *format, ...) {
isc_error_fatal(const char *file, int line, const char *format, ...) {
va_list args;
va_start(args, format);
@@ -67,12 +67,14 @@ isc_error_fatal(char *file, int line, char *format, ...) {
}
void
isc_error_runtimecheck(char *file, int line, char *expression) {
isc_error_runtimecheck(const char *file, int line, const char *expression) {
isc_error_fatal(file, line, "RUNTIME_CHECK(%s) failed", expression);
}
static void
default_unexpected_callback(char *file, int line, char *format, va_list args) {
default_unexpected_callback(const char *file, int line, const char *format,
va_list args)
{
fprintf(stderr, "%s:%d: ", file, line);
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
@@ -80,7 +82,9 @@ default_unexpected_callback(char *file, int line, char *format, va_list args) {
}
static void
default_fatal_callback(char *file, int line, char *format, va_list args) {
default_fatal_callback(const char *file, int line, const char *format,
va_list args)
{
fprintf(stderr, "%s:%d: fatal error: ", file, line);
vfprintf(stderr, format, args);
fprintf(stderr, "\n");

View File

@@ -38,9 +38,10 @@ destroy(isc_event_t *event) {
isc_event_t *
isc_event_allocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type,
isc_taskaction_t action, void *arg, size_t size)
isc_taskaction_t action, const void *arg, size_t size)
{
isc_event_t *event;
void *deconst_arg;
if (size < sizeof (struct isc_event))
return (NULL);
@@ -50,8 +51,23 @@ isc_event_allocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type,
event = isc_mem_get(mctx, size);
if (event == NULL)
return (NULL);
ISC_EVENT_INIT(event, size, 0, NULL, type, action, arg, sender,
destroy, mctx);
/*
* Removing the const attribute from "arg" is the best of two
* evils here. If the event->ev_arg member is made const, then
* it affects a great many users of the task/event subsystem
* which are not passing in an "arg" which starts its life as
* const. Changing isc_event_allocate() and isc_task_onshutdown()
* to not have "arg" prototyped as const (which is quite legitimate,
* because neither of those functions modify arg) can cause
* compiler whining anytime someone does want to use a const
* arg that they themselves never modify, such as with
* gcc -Wwrite-strings and using a string "arg".
*/
DE_CONST(arg, deconst_arg);
ISC_EVENT_INIT(event, size, 0, NULL, type, action, deconst_arg,
sender, destroy, mctx);
return (event);
}

View File

@@ -16,7 +16,7 @@
*/
/*
* $Id: assertions.h,v 1.9 2000/04/28 16:54:53 tale Exp $
* $Id: assertions.h,v 1.10 2000/06/01 17:20:34 tale Exp $
*/
#ifndef ISC_ASSERTIONS_H
@@ -33,13 +33,16 @@ typedef enum {
isc_assertiontype_invariant
} isc_assertiontype_t;
typedef void (*isc_assertioncallback_t)(char *, int, isc_assertiontype_t,
char *);
typedef void (*isc_assertioncallback_t)(const char *, int, isc_assertiontype_t,
const char *);
extern isc_assertioncallback_t isc_assertion_failed;
void isc_assertion_setcallback(isc_assertioncallback_t);
char *isc_assertion_typetotext(isc_assertiontype_t type);
void
isc_assertion_setcallback(isc_assertioncallback_t);
const char *
isc_assertion_typetotext(isc_assertiontype_t type);
#ifdef ISC_CHECK_ALL
#define ISC_CHECK_REQUIRE 1

View File

@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: base64.h,v 1.6 2000/04/10 21:52:31 gson Exp $ */
/* $Id: base64.h,v 1.7 2000/06/01 17:20:35 tale Exp $ */
#ifndef ISC_BASE64_H
#define ISC_BASE64_H 1
@@ -50,7 +50,7 @@ ISC_LANG_BEGINDECLS
*/
isc_result_t
isc_base64_totext(isc_region_t *source, int wordlength,
char *wordbreak, isc_buffer_t *target);
const char *wordbreak, isc_buffer_t *target);
/* Convert base64 encoded text into data.
*

View File

@@ -62,7 +62,7 @@
* d == used pointer.
* e == length of buffer.
*
* a-e == entire (length) of buffer.
* a-e == entire length of buffer.
* a-d == used region.
* a-b == consumed region.
* b-d == remaining region.
@@ -132,10 +132,13 @@ ISC_LANG_BEGINDECLS
/*
* Fundamental buffer elements. (A through E in the introductory comment.)
*/
#define isc_buffer_base(b) ((unsigned char *)(b)->base) /*a*/
#define isc_buffer_current(b) ((unsigned char *)(b)->base + (b)->current) /*b*/
#define isc_buffer_active(b) ((unsigned char *)(b)->base + (b)->active) /*c*/
#define isc_buffer_used(b) ((unsigned char *)(b)->base + (b)->used) /*d*/
#define isc_buffer_base(b) ((void *)(b)->base) /*a*/
#define isc_buffer_current(b) \
((void *)((unsigned char *)(b)->base + (b)->current)) /*b*/
#define isc_buffer_active(b) \
((void *)((unsigned char *)(b)->base + (b)->active)) /*c*/
#define isc_buffer_used(b) \
((void *)((unsigned char *)(b)->base + (b)->used)) /*d*/
#define isc_buffer_length(b) ((b)->length) /*e*/
/*
@@ -208,7 +211,7 @@ isc_buffer_free(isc_buffer_t **dynbuffer);
*/
void
isc__buffer_init(isc_buffer_t *b, void *base, unsigned int length);
isc__buffer_init(isc_buffer_t *b, const void *base, unsigned int length);
/*
* Make 'b' refer to the 'length'-byte region starting at base.
*
@@ -525,14 +528,9 @@ isc__buffer_putuint32(isc_buffer_t *b, isc_uint32_t val);
* The used pointer in 'b' is advanced by 4.
*/
#define ISC__BUFFER_PUTMEM(_b, _base, _length) \
do { \
memcpy((unsigned char *)(_b)->base + (_b)->used, \
(_base), (_length)); \
(_b)->used += (_length); \
} while (0)
void
isc__buffer_putmem(isc_buffer_t *b, unsigned char *base, unsigned int length);
isc__buffer_putmem(isc_buffer_t *b, const unsigned char *base,
unsigned int length);
/*
* Copy 'length' bytes of memory at 'base' into 'b'.
*
@@ -544,7 +542,7 @@ isc__buffer_putmem(isc_buffer_t *b, unsigned char *base, unsigned int length);
*/
void
isc_buffer_putstr(isc_buffer_t *b, const char *source);
isc__buffer_putstr(isc_buffer_t *b, const char *source);
/*
* Copy 'source' into 'b', not including terminating NUL.
*
@@ -573,6 +571,8 @@ isc_buffer_copyregion(isc_buffer_t *b, isc_region_t *r);
* big enough.
*/
ISC_LANG_ENDDECLS
/*
* Inline macro versions of the functions. These should never be called
* directly by an application, but will be used by the functions within
@@ -580,16 +580,38 @@ isc_buffer_copyregion(isc_buffer_t *b, isc_region_t *r);
* ones beginning with "isc__"
*/
/*
* XXXDCL Something more could be done with initializing buffers that
* point to const data. For example, a new function, isc_buffer_initconst,
* could be used, and a new boolean flag in the buffer structure could
* indicate whether the buffer was initialized with that function.
* (isc_bufer_init itself would be reprototyped to *not* have its "base"
* parameter be const.) Then if the boolean were true, the isc_buffer_put*
* functions could assert a contractual requirement for a non-const buffer.
* One drawback is that the isc_buffer_* functions (macros) that return
* pointers would still need to return non-const pointers to avoid compiler
* warnings, so it would be up to code that uses them to have to deal
* with the possibility that the buffer was initialized as const --
* a problem that they *already* have to deal with but have absolutely
* no ability to. With a new isc_buffer_isconst() function returning
* true/false, they could at least assert a contractual requirement for
* non-const buffers when needed.
*/
#define ISC__BUFFER_INIT(_b, _base, _length) \
do { \
(_b)->magic = ISC_BUFFER_MAGIC; \
(_b)->base = (_base); \
union { \
const void * konst; \
void * var; \
} _u; \
_u.konst = (_base); \
(_b)->base = _u.var; \
(_b)->length = (_length); \
(_b)->used = 0; \
(_b)->current = 0; \
(_b)->active = 0; \
(_b)->mctx = NULL; \
ISC_LINK_INIT(b, link); \
(_b)->magic = ISC_BUFFER_MAGIC; \
} while (0)
#define ISC__BUFFER_INVALIDATE(_b) \
@@ -616,8 +638,8 @@ isc_buffer_copyregion(isc_buffer_t *b, isc_region_t *r);
#define ISC__BUFFER_AVAILABLEREGION(_b, _r) \
do { \
(_r)->base = ((unsigned char *)(_b)->base) + (_b)->used; \
(_r)->length = (_b)->length - (_b)->used; \
(_r)->base = isc_buffer_used(_b); \
(_r)->length = isc_buffer_availablelength(_b); \
} while (0)
#define ISC__BUFFER_ADD(_b, _n) \
@@ -649,16 +671,15 @@ isc_buffer_copyregion(isc_buffer_t *b, isc_region_t *r);
#define ISC__BUFFER_REMAININGREGION(_b, _r) \
do { \
(_r)->base = ((unsigned char *)(_b)->base) + (_b)->current; \
(_r)->length = (_b)->used - (_b)->current; \
(_r)->base = isc_buffer_current(_b); \
(_r)->length = isc_buffer_remaininglength(_b); \
} while (0)
#define ISC__BUFFER_ACTIVEREGION(_b, _r) \
do { \
if ((_b)->current < (_b)->active) { \
(_r)->base = (unsigned char *)(_b)->base \
+ (_b)->current; \
(_r)->length = (_b)->active - (_b)->current; \
(_r)->base = isc_buffer_current(_b); \
(_r)->length = isc_buffer_activelength(_b); \
} else { \
(_r)->base = NULL; \
(_r)->length = 0; \
@@ -685,12 +706,27 @@ isc_buffer_copyregion(isc_buffer_t *b, isc_region_t *r);
(_b)->current -= (_n); \
} while (0)
#define ISC__BUFFER_PUTMEM(_b, _base, _length) \
do { \
memcpy(isc_buffer_used(_b), (_base), (_length)); \
(_b)->used += (_length); \
} while (0)
#define ISC__BUFFER_PUTSTR(_b, _source) \
do { \
unsigned int _length; \
unsigned char *_cp; \
_length = strlen(_source); \
_cp = isc_buffer_used(_b); \
memcpy(_cp, (_source), _length); \
(_b)->used += (_length); \
} while (0)
#define ISC__BUFFER_PUTUINT8(_b, _val) \
do { \
unsigned char *_cp; \
isc_uint8_t _val2 = (_val); \
_cp = (_b)->base; \
_cp += (_b)->used; \
_cp = isc_buffer_used(_b); \
(_b)->used++; \
_cp[0] = (_val2 & 0x00ff); \
} while (0)
@@ -699,8 +735,7 @@ isc_buffer_copyregion(isc_buffer_t *b, isc_region_t *r);
do { \
unsigned char *_cp; \
isc_uint16_t _val2 = (_val); \
_cp = (_b)->base; \
_cp += (_b)->used; \
_cp = isc_buffer_used(_b); \
(_b)->used += 2; \
_cp[0] = (_val2 & 0xff00U) >> 8; \
_cp[1] = (_val2 & 0x00ffU); \
@@ -710,8 +745,7 @@ isc_buffer_copyregion(isc_buffer_t *b, isc_region_t *r);
do { \
unsigned char *_cp; \
isc_uint32_t _val2 = (_val); \
_cp = (_b)->base; \
_cp += (_b)->used; \
_cp = isc_buffer_used(_b); \
(_b)->used += 4; \
_cp[0] = (_val2 & 0xff000000) >> 24; \
_cp[1] = (_val2 & 0x00ff0000) >> 16; \
@@ -735,10 +769,11 @@ isc_buffer_copyregion(isc_buffer_t *b, isc_region_t *r);
#define isc_buffer_first ISC__BUFFER_FIRST
#define isc_buffer_forward ISC__BUFFER_FORWARD
#define isc_buffer_back ISC__BUFFER_BACK
#define isc_buffer_putmem ISC__BUFFER_PUTMEM
#define isc_buffer_putstr ISC__BUFFER_PUTSTR
#define isc_buffer_putuint8 ISC__BUFFER_PUTUINT8
#define isc_buffer_putuint16 ISC__BUFFER_PUTUINT16
#define isc_buffer_putuint32 ISC__BUFFER_PUTUINT32
#define isc_buffer_putmem ISC__BUFFER_PUTMEM
#else
#define isc_buffer_init isc__buffer_init
#define isc_buffer_invalidate isc__buffer_invalidate
@@ -755,12 +790,11 @@ isc_buffer_copyregion(isc_buffer_t *b, isc_region_t *r);
#define isc_buffer_first isc__buffer_first
#define isc_buffer_forward isc__buffer_forward
#define isc_buffer_back isc__buffer_back
#define isc_buffer_putmem isc__buffer_putmem
#define isc_buffer_putstr isc__buffer_putstr
#define isc_buffer_putuint8 isc__buffer_putuint8
#define isc_buffer_putuint16 isc__buffer_putuint16
#define isc_buffer_putuint32 isc__buffer_putuint32
#define isc_buffer_putmem isc__buffer_putmem
#endif
ISC_LANG_ENDDECLS
#endif /* ISC_BUFFER_H */

View File

@@ -24,13 +24,18 @@
ISC_LANG_BEGINDECLS
typedef void (*isc_errorcallback_t)(char *, int, char *, va_list);
typedef void (*isc_errorcallback_t)(const char *, int, const char *, va_list);
void isc_error_setunexpected(isc_errorcallback_t);
void isc_error_setfatal(isc_errorcallback_t);
void isc_error_unexpected(char *, int, char *, ...);
void isc_error_fatal(char *, int, char *, ...);
void isc_error_runtimecheck(char *, int, char *);
void
isc_error_setunexpected(isc_errorcallback_t);
void
isc_error_setfatal(isc_errorcallback_t);
void
isc_error_unexpected(const char *, int, const char *, ...);
void
isc_error_fatal(const char *, int, const char *, ...);
void
isc_error_runtimecheck(const char *, int, const char *);
#define ISC_ERROR_RUNTIMECHECK(cond) \
((void) ((cond) || \

View File

@@ -84,7 +84,7 @@ ISC_LANG_BEGINDECLS
isc_event_t *
isc_event_allocate(isc_mem_t *, void *, isc_eventtype_t, isc_taskaction_t,
void *arg, size_t);
const void *arg, size_t);
void
isc_event_free(isc_event_t **);

View File

@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: log.h,v 1.21 2000/05/25 05:07:21 gson Exp $ */
/* $Id: log.h,v 1.22 2000/06/01 17:20:40 tale Exp $ */
#ifndef ISC_LOG_H
#define ISC_LOG_H 1
@@ -98,7 +98,7 @@ struct isc_logmodule {
*/
typedef struct isc_logfile {
FILE *stream; /* Initialized to NULL for ISC_LOG_TOFILE. */
char *name; /* NULL for ISC_LOG_TOFILEDESC. */
const char *name; /* NULL for ISC_LOG_TOFILEDESC. */
int versions; /* >= 0, ISC_LOG_ROLLNEVER, ISC_LOG_ROLLINFINITE. */
/*
* stdio's ftell is standardized to return a long, which may well not
@@ -365,7 +365,8 @@ isc_log_registermodules(isc_log_t *lctx, isc_logmodule_t modules[]);
isc_result_t
isc_log_createchannel(isc_logconfig_t *lcfg, const char *name,
unsigned int type, int level,
isc_logdestination_t *destination, unsigned int flags);
const isc_logdestination_t *destination,
unsigned int flags);
/*
* Specify the parameters of a logging channel.
*
@@ -433,7 +434,8 @@ isc_log_createchannel(isc_logconfig_t *lcfg, const char *name,
isc_result_t
isc_log_usechannel(isc_logconfig_t *lcfg, const char *name,
isc_logcategory_t *category, isc_logmodule_t *module);
const isc_logcategory_t *category,
const isc_logmodule_t *module);
/*
* Associate a named logging channel with a category and module that
* will use it.
@@ -652,8 +654,8 @@ isc_log_getduplicateinterval(isc_logconfig_t *lcfg);
* The current duplicate filtering interval.
*/
void
isc_log_settag(isc_logconfig_t *lcfg, char *tag);
isc_result_t
isc_log_settag(isc_logconfig_t *lcfg, const char *tag);
/*
* Set the program name or other identifier for ISC_LOG_PRINTTAG.
*
@@ -674,6 +676,10 @@ isc_log_settag(isc_logconfig_t *lcfg, char *tag);
* Because the name is used by ISC_LOG_PRINTTAG, it should not be
* altered or destroyed after isc_log_settag().
*
* Returns:
* ISC_R_SUCCESS Success
* ISC_R_NOMEMORY Resource Limit: Out of memory
*
* XXXDCL when creating a new isc_logconfig_t, it might be nice if the tag
* of the currently active isc_logconfig_t was inherited. this does not
* currently happen.

View File

@@ -30,8 +30,8 @@ typedef struct {
* The intent of this is to allow magic numbers to be checked even though
* the object is otherwise opaque.
*/
#define ISC_MAGIC_VALID(a,b) (((a) != NULL) \
&& (((isc__magic_t *)(a))->magic == (b)))
#define ISC_MAGIC_VALID(a,b) (((a) != NULL) && \
(((const isc__magic_t *)(a))->magic == (b)))
#define ISC_MAGIC(a, b, c, d) ((a) << 24 | (b) << 16 | (c) << 8 | (d))

View File

@@ -166,7 +166,7 @@ isc_mempool_destroy(isc_mempool_t **mpctxp);
*/
void
isc_mempool_setname(isc_mempool_t *mpctx, char *name);
isc_mempool_setname(isc_mempool_t *mpctx, const char *name);
/*
* Associate a name with a memory pool. At most 15 characters may be used.
*

View File

@@ -67,7 +67,7 @@ ISC_LANG_BEGINDECLS
*****/
void
isc_msgcat_open(char *name, isc_msgcat_t **msgcatp);
isc_msgcat_open(const char *name, isc_msgcat_t **msgcatp);
/*
* Open a message catalog.
*
@@ -107,8 +107,9 @@ isc_msgcat_close(isc_msgcat_t **msgcatp);
* *msgcatp == NULL
*/
char *
isc_msgcat_get(isc_msgcat_t *msgcat, int set, int message, char *default_text);
const char *
isc_msgcat_get(isc_msgcat_t *msgcat, int set, int message,
const char *default_text);
/*
* Get message 'message' from message set 'set' in 'msgcat'. If it
* is not available, use 'default_text'.

View File

@@ -30,6 +30,14 @@ struct isc_textregion {
unsigned int length;
};
/* XXXDCL questionable ... bears discussion. we have been putting off
* discussing the region api.
*/
struct isc_constregion {
const void * base;
unsigned int length;
};
/*
* The region structure is not opaque, and is usually directly manipulated.
* Some macros are defined below for convenience.
@@ -53,4 +61,13 @@ struct isc_textregion {
_r->length -= _l; \
} while (0)
#define isc_constregion_consume(r,l) \
do { \
isc_constregion_t *_r = (r); \
unsigned int _l = (l); \
INSIST(_r->length >= _l); \
_r->base += _l; \
_r->length -= _l; \
} while (0)
#endif /* ISC_REGION_H */

View File

@@ -68,15 +68,15 @@
ISC_LANG_BEGINDECLS
char *
const char *
isc_result_totext(isc_result_t);
/*
* Convert an isc_result_t into a string message describing the result.
*/
isc_result_t
isc_result_register(unsigned int base, unsigned int nresults, char **text,
isc_msgcat_t *msgcat, int set);
isc_result_register(unsigned int base, unsigned int nresults,
const char **text, isc_msgcat_t *msgcat, int set);
ISC_LANG_ENDDECLS

View File

@@ -348,7 +348,7 @@ isc_socket_listen(isc_socket_t *sock, unsigned int backlog);
isc_result_t
isc_socket_accept(isc_socket_t *sock,
isc_task_t *task, isc_taskaction_t action, void *arg);
isc_task_t *task, isc_taskaction_t action, const void *arg);
/*
* Queue accept event. When a new connection is received, the task will
* get an ISC_SOCKEVENT_NEWCONN event with the sender set to the listen
@@ -372,7 +372,7 @@ isc_socket_accept(isc_socket_t *sock,
isc_result_t
isc_socket_connect(isc_socket_t *sock, isc_sockaddr_t *addressp,
isc_task_t *task, isc_taskaction_t action,
void *arg);
const void *arg);
/*
* Connect 'socket' to peer with address *saddr. When the connection
* succeeds, or when an error occurs, a CONNECT event with action 'action'
@@ -438,11 +438,11 @@ isc_socket_getsockname(isc_socket_t *sock, isc_sockaddr_t *addressp);
isc_result_t
isc_socket_recv(isc_socket_t *sock, isc_region_t *region,
unsigned int minimum,
isc_task_t *task, isc_taskaction_t action, void *arg);
isc_task_t *task, isc_taskaction_t action, const void *arg);
isc_result_t
isc_socket_recvv(isc_socket_t *sock, isc_bufferlist_t *buflist,
unsigned int minimum,
isc_task_t *task, isc_taskaction_t action, void *arg);
isc_task_t *task, isc_taskaction_t action, const void *arg);
/*
* Receive from 'socket', storing the results in region.
*
@@ -500,17 +500,17 @@ isc_socket_recvv(isc_socket_t *sock, isc_bufferlist_t *buflist,
isc_result_t
isc_socket_send(isc_socket_t *sock, isc_region_t *region,
isc_task_t *task, isc_taskaction_t action, void *arg);
isc_task_t *task, isc_taskaction_t action, const void *arg);
isc_result_t
isc_socket_sendto(isc_socket_t *sock, isc_region_t *region,
isc_task_t *task, isc_taskaction_t action, void *arg,
isc_task_t *task, isc_taskaction_t action, const void *arg,
isc_sockaddr_t *address, struct in6_pktinfo *pktinfo);
isc_result_t
isc_socket_sendv(isc_socket_t *sock, isc_bufferlist_t *buflist,
isc_task_t *task, isc_taskaction_t action, void *arg);
isc_task_t *task, isc_taskaction_t action, const void *arg);
isc_result_t
isc_socket_sendtov(isc_socket_t *sock, isc_bufferlist_t *buflist,
isc_task_t *task, isc_taskaction_t action, void *arg,
isc_task_t *task, isc_taskaction_t action, const void *arg,
isc_sockaddr_t *address, struct in6_pktinfo *pktinfo);
/*
* Send the contents of 'region' to the socket's peer.
@@ -560,11 +560,11 @@ isc_socket_sendtov(isc_socket_t *sock, isc_bufferlist_t *buflist,
*/
isc_result_t
isc_socket_recvmark(isc_socket_t *sock,
isc_task_t *task, isc_taskaction_t action, void *arg);
isc_socket_recvmark(isc_socket_t *sock, isc_task_t *task,
isc_taskaction_t action, const void *arg);
isc_result_t
isc_socket_sendmark(isc_socket_t *sock,
isc_task_t *task, isc_taskaction_t action, void *arg);
isc_socket_sendmark(isc_socket_t *sock, isc_task_t *task,
isc_taskaction_t action, const void *arg);
/*
* Insert a recv/send marker for the socket.
*

View File

@@ -114,11 +114,11 @@ isc_symtab_lookup(isc_symtab_t *symtab, const char *key, unsigned int type,
isc_symvalue_t *value);
isc_result_t
isc_symtab_define(isc_symtab_t *symtab, char *key, unsigned int type,
isc_symtab_define(isc_symtab_t *symtab, const char *key, unsigned int type,
isc_symvalue_t value, isc_symexists_t exists_policy);
isc_result_t
isc_symtab_undefine(isc_symtab_t *symtab, char *key, unsigned int type);
isc_symtab_undefine(isc_symtab_t *symtab, const char *key, unsigned int type);
ISC_LANG_ENDDECLS

View File

@@ -357,7 +357,8 @@ isc_task_unsend(isc_task_t *task, void *sender, isc_eventtype_t type,
*/
isc_result_t
isc_task_onshutdown(isc_task_t *task, isc_taskaction_t action, void *arg);
isc_task_onshutdown(isc_task_t *task, isc_taskaction_t action,
const void *arg);
/*
* Send a shutdown event with action 'action' and argument 'arg' when
* 'task' is shutdown.
@@ -377,6 +378,7 @@ isc_task_onshutdown(isc_task_t *task, isc_taskaction_t action, void *arg);
* When the task is shutdown, shutdown events requested with
* isc_task_onshutdown() will be appended to the task's event queue.
*
* Returns:
*
* ISC_R_SUCCESS
@@ -438,7 +440,7 @@ isc_task_destroy(isc_task_t **taskp);
*/
void
isc_task_setname(isc_task_t *task, char *name, void *tag);
isc_task_setname(isc_task_t *task, const char *name, void *tag);
/*
* Name 'task'.
*

View File

@@ -112,7 +112,7 @@ isc_timer_create(isc_timermgr_t *manager,
isc_interval_t *interval,
isc_task_t *task,
isc_taskaction_t action,
void *arg,
const void *arg,
isc_timer_t **timerp);
/*
* Create a new 'type' timer managed by 'manager'. The timers parameters

View File

@@ -42,6 +42,7 @@
typedef struct isc_bitstring isc_bitstring_t;
typedef struct isc_buffer isc_buffer_t;
typedef ISC_LIST(isc_buffer_t) isc_bufferlist_t;
typedef struct isc_constregion isc_constregion_t;
typedef struct isc_event isc_event_t;
typedef ISC_LIST(isc_event_t) isc_eventlist_t;
typedef unsigned int isc_eventtype_t;

View File

@@ -47,6 +47,21 @@
#define ISC_MAX(a, b) ((a) > (b) ? (a) : (b))
#define ISC_MIN(a, b) ((a) < (b) ? (a) : (b))
/*
* Use this to remove the const qualifier of a variable to assign it to
* a non-const variable or pass it as a non-const function argument ...
* but only when you are sure it won't then be changed!
* This is necessary to sometimes shut up some compilers
* (as with gcc -Wcast-qual) when there is just no other good way to avoid the
* situation.
*/
#define DE_CONST(konst, var) \
do { \
union { const void *k; void *v; } _u; \
_u.k = konst; \
var = _u.v; \
} while (0)
/*
* We use macros instead of calling the routines directly because
* the capital letters make the locking stand out.

View File

@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: log.c,v 1.35 2000/05/24 02:33:16 tale Exp $ */
/* $Id: log.c,v 1.36 2000/06/01 17:20:23 tale Exp $ */
/* Principal Authors: DCL */
@@ -77,7 +77,7 @@ struct isc_logchannel {
typedef struct isc_logchannellist isc_logchannellist_t;
struct isc_logchannellist {
isc_logmodule_t * module;
const isc_logmodule_t * module;
isc_logchannel_t * channel;
ISC_LINK(isc_logchannellist_t) link;
};
@@ -210,7 +210,7 @@ isc_log_t *isc_lctx = NULL;
*/
static isc_result_t
assignchannel(isc_logconfig_t *lcfg, unsigned int category_id,
isc_logmodule_t *module, isc_logchannel_t *channel);
const isc_logmodule_t *module, isc_logchannel_t *channel);
static isc_result_t
sync_channellist(isc_logconfig_t *lcfg);
@@ -474,6 +474,7 @@ isc_logconfig_destroy(isc_logconfig_t **lcfgp) {
isc_mem_t *mctx;
isc_logchannel_t *channel;
isc_logchannellist_t *item;
char *filename;
unsigned int i;
REQUIRE(lcfgp != NULL && VALID_CONFIG(*lcfgp));
@@ -492,7 +493,14 @@ isc_logconfig_destroy(isc_logconfig_t **lcfgp) {
ISC_LIST_UNLINK(lcfg->channels, channel, link);
if (channel->type == ISC_LOG_TOFILE) {
isc_mem_free(mctx, FILE_NAME(channel));
/*
* The filename for the channel may have ultimately
* started its life in user-land as a const string,
* but in isc_log_createchannel it gets copied
* into writable memory and is not longer truly const.
*/
DE_CONST(FILE_NAME(channel), filename);
isc_mem_free(mctx, filename);
if (FILE_STREAM(channel) != NULL)
(void)fclose(FILE_STREAM(channel));
@@ -549,7 +557,11 @@ isc_log_registercategories(isc_log_t *lctx, isc_logcategory_t categories[]) {
*/
for (catp = lctx->categories; catp->name != NULL; catp++)
if (catp->id == UINT_MAX)
catp = (isc_logcategory_t *)catp->name;
/*
* The name pointer points to the next array.
* Ick.
*/
DE_CONST(catp->name, catp);
catp->name = (void *)categories;
catp->id = UINT_MAX;
@@ -571,10 +583,14 @@ isc_log_categorybyname(isc_log_t *lctx, const char *name) {
for (catp = lctx->categories; catp->name != NULL; catp++)
if (catp->id == UINT_MAX)
catp = (isc_logcategory_t *)catp->name;
/*
* catp is neither modified nor returned to the
* caller, so removing its const qualifier is ok.
*/
DE_CONST(catp->name, catp);
else
if (strcmp(catp->name, name) == 0)
return catp;
return (catp);
return (NULL);
}
@@ -604,7 +620,11 @@ isc_log_registermodules(isc_log_t *lctx, isc_logmodule_t modules[]) {
*/
for (modp = lctx->modules; modp->name != NULL; modp++)
if (modp->id == UINT_MAX)
modp = (isc_logmodule_t *)modp->name;
/*
* The name pointer points to the next array.
* Ick.
*/
DE_CONST(modp->name, modp);
modp->name = (void *)modules;
modp->id = UINT_MAX;
@@ -626,10 +646,14 @@ isc_log_modulebyname(isc_log_t *lctx, const char *name) {
for (modp = lctx->modules; modp->name != NULL; modp++)
if (modp->id == UINT_MAX)
modp = (isc_logmodule_t *)modp->name;
/*
* catp is neither modified nor returned to the
* caller, so removing its const qualifier is ok.
*/
DE_CONST(modp->name, modp);
else
if (strcmp(modp->name, name) == 0)
return modp;
return (modp);
return (NULL);
}
@@ -637,7 +661,8 @@ isc_log_modulebyname(isc_log_t *lctx, const char *name) {
isc_result_t
isc_log_createchannel(isc_logconfig_t *lcfg, const char *name,
unsigned int type, int level,
isc_logdestination_t *destination, unsigned int flags)
const isc_logdestination_t *destination,
unsigned int flags)
{
isc_logchannel_t *channel;
isc_mem_t *mctx;
@@ -648,7 +673,8 @@ isc_log_createchannel(isc_logconfig_t *lcfg, const char *name,
type == ISC_LOG_TOFILEDESC || type == ISC_LOG_TONULL);
REQUIRE(destination != NULL || type == ISC_LOG_TONULL);
REQUIRE(level >= ISC_LOG_CRITICAL);
REQUIRE((flags & ~(ISC_LOG_PRINTALL | ISC_LOG_DEBUGONLY)) == 0);
REQUIRE((flags &
(unsigned int)~(ISC_LOG_PRINTALL | ISC_LOG_DEBUGONLY)) == 0);
/* XXXDCL find duplicate names? */
@@ -717,7 +743,8 @@ isc_log_createchannel(isc_logconfig_t *lcfg, const char *name,
isc_result_t
isc_log_usechannel(isc_logconfig_t *lcfg, const char *name,
isc_logcategory_t *category, isc_logmodule_t *module)
const isc_logcategory_t *category,
const isc_logmodule_t *module)
{
isc_log_t *lctx;
isc_logchannel_t *channel;
@@ -848,14 +875,22 @@ isc_log_getduplicateinterval(isc_logconfig_t *lcfg) {
return (lcfg->duplicate_interval);
}
void
isc_log_settag(isc_logconfig_t *lcfg, char *tag) {
isc_result_t
isc_log_settag(isc_logconfig_t *lcfg, const char *tag) {
REQUIRE(VALID_CONFIG(lcfg));
if (tag != NULL && *tag != '\0')
lcfg->tag = tag;
else
if (tag != NULL && *tag != '\0') {
lcfg->tag = isc_mem_strdup(lcfg->lctx->mctx, tag);
if (lcfg->tag == NULL)
return (ISC_R_NOMEMORY);
} else {
if (lcfg->tag != NULL)
isc_mem_free(lcfg->lctx->mctx, lcfg->tag);
lcfg->tag = NULL;
}
return (ISC_R_SUCCESS);
}
char *
@@ -894,7 +929,7 @@ isc_log_closefilelogs(isc_log_t *lctx) {
static isc_result_t
assignchannel(isc_logconfig_t *lcfg, unsigned int category_id,
isc_logmodule_t *module, isc_logchannel_t *channel)
const isc_logmodule_t *module, isc_logchannel_t *channel)
{
isc_logchannellist_t *new_item;
isc_log_t *lctx;
@@ -944,7 +979,7 @@ assignchannel(isc_logconfig_t *lcfg, unsigned int category_id,
*/
static isc_result_t
sync_channellist(isc_logconfig_t *lcfg) {
int bytes;
unsigned int bytes;
isc_log_t *lctx;
void *lists;
@@ -982,7 +1017,8 @@ sync_channellist(isc_logconfig_t *lcfg) {
static unsigned int
greatest_version(isc_logchannel_t *channel) {
/* XXXDCL HIGHLY NT */
char *dirname, *basename, *digit_end;
char *basename, *digit_end;
const char *dirname;
int version, greatest = -1;
unsigned int basenamelen;
isc_dir_t dir;
@@ -990,12 +1026,16 @@ greatest_version(isc_logchannel_t *channel) {
REQUIRE(channel->type == ISC_LOG_TOFILE);
/*
* It is safe to DE_CONST the file.name because it was copied
* with isc_mem_strdup in isc_log_createchannel.
*/
basename = strrchr(FILE_NAME(channel), '/');
if (basename != NULL) {
*basename++ = '\0';
dirname = FILE_NAME(channel);
} else {
basename = FILE_NAME(channel);
DE_CONST(FILE_NAME(channel), basename);
dirname = ".";
}
basenamelen = strlen(basename);
@@ -1029,7 +1069,7 @@ roll_log(isc_logchannel_t *channel) {
int i, greatest, digits = 0;
char current[FILENAME_MAX + 1];
char new[FILENAME_MAX + 1];
char *path;
const char *path;
/*
* Do nothing (not even excess version trimming) if ISC_LOG_ROLLNEVER
@@ -1109,7 +1149,7 @@ isc_log_open(isc_logchannel_t *channel) {
FILE *stream;
struct stat statbuf;
isc_boolean_t regular_file;
char *path;
const char *path;
REQUIRE(channel->type == ISC_LOG_TOFILE);
REQUIRE(FILE_STREAM(channel) == NULL);
@@ -1162,7 +1202,7 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category,
isc_logconfig_t *lcfg;
isc_logchannel_t *channel;
isc_logchannellist_t *category_channels;
isc_time_t time;
isc_time_t isctime;
isc_result_t result;
REQUIRE(lctx == NULL || VALID_CONTEXT(lctx));
@@ -1267,9 +1307,10 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category,
time_string[0] == '\0') {
time_t now;
result = isc_time_now(&time);
result = isc_time_now(&isctime);
if (result == ISC_R_SUCCESS)
result = isc_time_secondsastimet(&time, &now);
result = isc_time_secondsastimet(&isctime,
&now);
if (result == ISC_R_SUCCESS) {
unsigned int len;
@@ -1291,7 +1332,7 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category,
snprintf(time_string + len,
sizeof(time_string) - len,
".%03u ",
isc_time_nanoseconds(&time)
isc_time_nanoseconds(&isctime)
/ 1000000);
} else

View File

@@ -146,14 +146,6 @@ struct isc_mempool {
#endif
};
/*
* Forward.
*/
static inline size_t quantize(size_t);
static inline void mem_putunlocked(isc_mem_t *, void *, size_t);
static inline void * mem_getunlocked(isc_mem_t *, size_t);
/*
* Private Inline-able.
*/
@@ -174,19 +166,314 @@ quantize(size_t size) {
return (temp - temp % ALIGNMENT_SIZE);
}
static inline void
split(isc_mem_t *ctx, size_t size, size_t new_size) {
unsigned char *ptr;
size_t remaining_size;
/*
* Unlink a frag of size 'size'.
*/
ptr = (unsigned char *)ctx->freelists[size];
ctx->freelists[size] = ctx->freelists[size]->next;
ctx->stats[size].freefrags--;
/*
* Create a frag of size 'new_size' and link it in.
*/
((element *)ptr)->next = ctx->freelists[new_size];
ctx->freelists[new_size] = (element *)ptr;
ctx->stats[new_size].freefrags++;
/*
* Create a frag of size 'size - new_size' and link it in.
*/
remaining_size = size - new_size;
ptr += new_size;
((element *)ptr)->next = ctx->freelists[remaining_size];
ctx->freelists[remaining_size] = (element *)ptr;
ctx->stats[remaining_size].freefrags++;
}
static inline isc_boolean_t
try_split(isc_mem_t *ctx, size_t new_size) {
size_t i, doubled_size;
if (!ctx->trysplit)
return (ISC_FALSE);
/*
* Try splitting a frag that's at least twice as big as the size
* we want.
*/
doubled_size = new_size * 2;
for (i = doubled_size;
i < ctx->max_size;
i += ALIGNMENT_SIZE) {
if (ctx->freelists[i] != NULL) {
split(ctx, i, new_size);
return (ISC_TRUE);
}
}
/*
* No luck. Try splitting any frag bigger than the size we need.
*/
for (i = new_size + ALIGNMENT_SIZE;
i < doubled_size;
i += ALIGNMENT_SIZE) {
if (ctx->freelists[i] != NULL) {
split(ctx, i, new_size);
return (ISC_TRUE);
}
}
return (ISC_FALSE);
}
static inline isc_boolean_t
more_basic_blocks(isc_mem_t *ctx) {
void *new;
unsigned char *curr, *next;
unsigned char *first, *last;
unsigned char **table;
unsigned int table_size;
size_t increment;
int i;
/* Require: we hold the context lock. */
/*
* Did we hit the quota for this context?
*/
increment = NUM_BASIC_BLOCKS * ctx->mem_target;
if (ctx->quota != 0 && ctx->total + increment > ctx->quota)
return (ISC_FALSE);
INSIST(ctx->basic_table_count <= ctx->basic_table_size);
if (ctx->basic_table_count == ctx->basic_table_size) {
table_size = ctx->basic_table_size + TABLE_INCREMENT;
table = (ctx->memalloc)(ctx->arg,
table_size * sizeof (unsigned char *));
if (table == NULL)
return (ISC_FALSE);
if (ctx->basic_table_size != 0) {
memcpy(table, ctx->basic_table,
ctx->basic_table_size *
sizeof (unsigned char *));
(ctx->memfree)(ctx->arg, ctx->basic_table);
}
ctx->basic_table = table;
ctx->basic_table_size = table_size;
}
new = (ctx->memalloc)(ctx->arg, NUM_BASIC_BLOCKS * ctx->mem_target);
if (new == NULL)
return (ISC_FALSE);
ctx->total += increment;
ctx->basic_table[ctx->basic_table_count] = new;
ctx->basic_table_count++;
curr = new;
next = curr + ctx->mem_target;
for (i = 0; i < (NUM_BASIC_BLOCKS - 1); i++) {
((element *)curr)->next = (element *)next;
curr = next;
next += ctx->mem_target;
}
/*
* curr is now pointing at the last block in the
* array.
*/
((element *)curr)->next = NULL;
first = new;
last = first + NUM_BASIC_BLOCKS * ctx->mem_target - 1;
if (first < ctx->lowest || ctx->lowest == NULL)
ctx->lowest = first;
if (last > ctx->highest)
ctx->highest = last;
ctx->basic_blocks = new;
return (ISC_TRUE);
}
static inline isc_boolean_t
more_frags(isc_mem_t *ctx, size_t new_size) {
int i, frags;
size_t total_size;
void *new;
unsigned char *curr, *next;
/*
* Try to get more fragments by chopping up a basic block.
*/
if (ctx->basic_blocks == NULL) {
if (!more_basic_blocks(ctx)) {
/*
* We can't get more memory from the OS, or we've
* hit the quota for this context.
*/
/*
* XXXRTH "At quota" notification here.
*/
/*
* Maybe we can split one of our existing
* list frags.
*/
return (try_split(ctx, new_size));
}
}
total_size = ctx->mem_target;
new = ctx->basic_blocks;
ctx->basic_blocks = ctx->basic_blocks->next;
frags = total_size / new_size;
ctx->stats[new_size].blocks++;
ctx->stats[new_size].freefrags += frags;
/*
* Set up a linked-list of blocks of size
* "new_size".
*/
curr = new;
next = curr + new_size;
for (i = 0; i < (frags - 1); i++) {
((element *)curr)->next = (element *)next;
curr = next;
next += new_size;
}
/*
* curr is now pointing at the last block in the
* array.
*/
((element *)curr)->next = NULL;
ctx->freelists[new_size] = new;
return (ISC_TRUE);
}
static inline void *
mem_getunlocked(isc_mem_t *ctx, size_t size) {
size_t new_size = quantize(size);
void *ret;
if (size >= ctx->max_size || new_size >= ctx->max_size) {
/*
* memget() was called on something beyond our upper limit.
*/
if (ctx->quota != 0 && ctx->total + size > ctx->quota) {
ret = NULL;
goto done;
}
ret = (ctx->memalloc)(ctx->arg, size);
if (ret != NULL) {
ctx->total += size;
ctx->inuse += size;
ctx->stats[ctx->max_size].gets++;
ctx->stats[ctx->max_size].totalgets++;
/*
* If we don't set new_size to size, then the
* ISC_MEM_FILL code might write over bytes we
* don't own.
*/
new_size = size;
}
goto done;
}
/*
* If there are no blocks in the free list for this size, get a chunk
* of memory and then break it up into "new_size"-sized blocks, adding
* them to the free list.
*/
if (ctx->freelists[new_size] == NULL && !more_frags(ctx, new_size))
return (NULL);
/*
* The free list uses the "rounded-up" size "new_size".
*/
ret = ctx->freelists[new_size];
ctx->freelists[new_size] = ctx->freelists[new_size]->next;
/*
* The stats[] uses the _actual_ "size" requested by the
* caller, with the caveat (in the code above) that "size" >= the
* max. size (max_size) ends up getting recorded as a call to
* max_size.
*/
ctx->stats[size].gets++;
ctx->stats[size].totalgets++;
ctx->stats[new_size].freefrags--;
ctx->inuse += new_size;
done:
#if ISC_MEM_FILL
if (ret != NULL)
memset(ret, 0xbe, new_size); /* Mnemonic for "beef". */
#endif
return (ret);
}
static inline void
mem_putunlocked(isc_mem_t *ctx, void *mem, size_t size) {
size_t new_size = quantize(size);
if (size == ctx->max_size || new_size >= ctx->max_size) {
/*
* memput() called on something beyond our upper limit.
*/
#if ISC_MEM_FILL
memset(mem, 0xde, size); /* Mnemonic for "dead". */
#endif
(ctx->memfree)(ctx->arg, mem);
INSIST(ctx->stats[ctx->max_size].gets != 0);
ctx->stats[ctx->max_size].gets--;
INSIST(size <= ctx->total);
ctx->inuse -= size;
ctx->total -= size;
return;
}
#if ISC_MEM_FILL
#if ISC_MEM_CHECKOVERRUN
check_overrun(mem, size, new_size);
#endif
memset(mem, 0xde, new_size); /* Mnemonic for "dead". */
#endif
/*
* The free list uses the "rounded-up" size "new_size".
*/
((element *)mem)->next = ctx->freelists[new_size];
ctx->freelists[new_size] = (element *)mem;
/*
* The stats[] uses the _actual_ "size" requested by the
* caller, with the caveat (in the code above) that "size" >= the
* max. size (max_size) ends up getting recorded as a call to
* max_size.
*/
INSIST(ctx->stats[size].gets != 0);
ctx->stats[size].gets--;
ctx->stats[new_size].freefrags++;
ctx->inuse -= new_size;
}
/*
* Private.
*/
static void *
default_memalloc(void *arg, size_t size) {
(void)arg;
UNUSED(arg);
return (malloc(size));
}
static void
default_memfree(void *arg, void *ptr) {
(void)arg;
UNUSED(arg);
free(ptr);
}
@@ -392,72 +679,6 @@ isc_mem_restore(isc_mem_t *ctx) {
return (result);
}
static inline isc_boolean_t
more_basic_blocks(isc_mem_t *ctx) {
void *new;
unsigned char *curr, *next;
unsigned char *first, *last;
unsigned char **table;
unsigned int table_size;
size_t increment;
int i;
/* Require: we hold the context lock. */
/*
* Did we hit the quota for this context?
*/
increment = NUM_BASIC_BLOCKS * ctx->mem_target;
if (ctx->quota != 0 && ctx->total + increment > ctx->quota)
return (ISC_FALSE);
INSIST(ctx->basic_table_count <= ctx->basic_table_size);
if (ctx->basic_table_count == ctx->basic_table_size) {
table_size = ctx->basic_table_size + TABLE_INCREMENT;
table = (ctx->memalloc)(ctx->arg,
table_size * sizeof (unsigned char *));
if (table == NULL)
return (ISC_FALSE);
if (ctx->basic_table_size != 0) {
memcpy(table, ctx->basic_table,
ctx->basic_table_size *
sizeof (unsigned char *));
(ctx->memfree)(ctx->arg, ctx->basic_table);
}
ctx->basic_table = table;
ctx->basic_table_size = table_size;
}
new = (ctx->memalloc)(ctx->arg, NUM_BASIC_BLOCKS * ctx->mem_target);
if (new == NULL)
return (ISC_FALSE);
ctx->total += increment;
ctx->basic_table[ctx->basic_table_count] = new;
ctx->basic_table_count++;
curr = new;
next = curr + ctx->mem_target;
for (i = 0; i < (NUM_BASIC_BLOCKS - 1); i++) {
((element *)curr)->next = (element *)next;
curr = next;
next += ctx->mem_target;
}
/*
* curr is now pointing at the last block in the
* array.
*/
((element *)curr)->next = NULL;
first = new;
last = first + NUM_BASIC_BLOCKS * ctx->mem_target - 1;
if (first < ctx->lowest || ctx->lowest == NULL)
ctx->lowest = first;
if (last > ctx->highest)
ctx->highest = last;
ctx->basic_blocks = new;
return (ISC_TRUE);
}
void *
isc__mem_get(isc_mem_t *ctx, size_t size) {
void *ret;
@@ -486,190 +707,6 @@ check_overrun(void *mem, size_t size, size_t new_size) {
}
#endif
static inline void
split(isc_mem_t *ctx, size_t size, size_t new_size) {
unsigned char *ptr;
size_t remaining_size;
/*
* Unlink a frag of size 'size'.
*/
ptr = (unsigned char *)ctx->freelists[size];
ctx->freelists[size] = ctx->freelists[size]->next;
ctx->stats[size].freefrags--;
/*
* Create a frag of size 'new_size' and link it in.
*/
((element *)ptr)->next = ctx->freelists[new_size];
ctx->freelists[new_size] = (element *)ptr;
ctx->stats[new_size].freefrags++;
/*
* Create a frag of size 'size - new_size' and link it in.
*/
remaining_size = size - new_size;
ptr += new_size;
((element *)ptr)->next = ctx->freelists[remaining_size];
ctx->freelists[remaining_size] = (element *)ptr;
ctx->stats[remaining_size].freefrags++;
}
static inline isc_boolean_t
try_split(isc_mem_t *ctx, size_t new_size) {
size_t i, doubled_size;
if (!ctx->trysplit)
return (ISC_FALSE);
/*
* Try splitting a frag that's at least twice as big as the size
* we want.
*/
doubled_size = new_size * 2;
for (i = doubled_size;
i < ctx->max_size;
i += ALIGNMENT_SIZE) {
if (ctx->freelists[i] != NULL) {
split(ctx, i, new_size);
return (ISC_TRUE);
}
}
/*
* No luck. Try splitting any frag bigger than the size we need.
*/
for (i = new_size + ALIGNMENT_SIZE;
i < doubled_size;
i += ALIGNMENT_SIZE) {
if (ctx->freelists[i] != NULL) {
split(ctx, i, new_size);
return (ISC_TRUE);
}
}
return (ISC_FALSE);
}
static inline isc_boolean_t
more_frags(isc_mem_t *ctx, size_t new_size) {
int i, frags;
size_t total_size;
void *new;
unsigned char *curr, *next;
/*
* Try to get more fragments by chopping up a basic block.
*/
if (ctx->basic_blocks == NULL) {
if (!more_basic_blocks(ctx)) {
/*
* We can't get more memory from the OS, or we've
* hit the quota for this context.
*/
/*
* XXXRTH "At quota" notification here.
*/
/*
* Maybe we can split one of our existing
* list frags.
*/
return (try_split(ctx, new_size));
}
}
total_size = ctx->mem_target;
new = ctx->basic_blocks;
ctx->basic_blocks = ctx->basic_blocks->next;
frags = total_size / new_size;
ctx->stats[new_size].blocks++;
ctx->stats[new_size].freefrags += frags;
/*
* Set up a linked-list of blocks of size
* "new_size".
*/
curr = new;
next = curr + new_size;
for (i = 0; i < (frags - 1); i++) {
((element *)curr)->next = (element *)next;
curr = next;
next += new_size;
}
/*
* curr is now pointing at the last block in the
* array.
*/
((element *)curr)->next = NULL;
ctx->freelists[new_size] = new;
return (ISC_TRUE);
}
static inline void *
mem_getunlocked(isc_mem_t *ctx, size_t size) {
size_t new_size = quantize(size);
void *ret;
if (size >= ctx->max_size || new_size >= ctx->max_size) {
/*
* memget() was called on something beyond our upper limit.
*/
if (ctx->quota != 0 && ctx->total + size > ctx->quota) {
ret = NULL;
goto done;
}
ret = (ctx->memalloc)(ctx->arg, size);
if (ret != NULL) {
ctx->total += size;
ctx->inuse += size;
ctx->stats[ctx->max_size].gets++;
ctx->stats[ctx->max_size].totalgets++;
/*
* If we don't set new_size to size, then the
* ISC_MEM_FILL code might write over bytes we
* don't own.
*/
new_size = size;
}
goto done;
}
/*
* If there are no blocks in the free list for this size, get a chunk
* of memory and then break it up into "new_size"-sized blocks, adding
* them to the free list.
*/
if (ctx->freelists[new_size] == NULL && !more_frags(ctx, new_size))
return (NULL);
/*
* The free list uses the "rounded-up" size "new_size".
*/
ret = ctx->freelists[new_size];
ctx->freelists[new_size] = ctx->freelists[new_size]->next;
/*
* The stats[] uses the _actual_ "size" requested by the
* caller, with the caveat (in the code above) that "size" >= the
* max. size (max_size) ends up getting recorded as a call to
* max_size.
*/
ctx->stats[size].gets++;
ctx->stats[size].totalgets++;
ctx->stats[new_size].freefrags--;
ctx->inuse += new_size;
done:
#if ISC_MEM_FILL
if (ret != NULL)
memset(ret, 0xbe, new_size); /* Mnemonic for "beef". */
#endif
return (ret);
}
void
isc__mem_put(isc_mem_t *ctx, void *mem, size_t size) {
REQUIRE(VALID_CONTEXT(ctx));
@@ -679,51 +716,6 @@ isc__mem_put(isc_mem_t *ctx, void *mem, size_t size) {
UNLOCK(&ctx->lock);
}
static inline void
mem_putunlocked(isc_mem_t *ctx, void *mem, size_t size) {
size_t new_size = quantize(size);
if (size == ctx->max_size || new_size >= ctx->max_size) {
/*
* memput() called on something beyond our upper limit.
*/
#if ISC_MEM_FILL
memset(mem, 0xde, size); /* Mnemonic for "dead". */
#endif
(ctx->memfree)(ctx->arg, mem);
INSIST(ctx->stats[ctx->max_size].gets != 0);
ctx->stats[ctx->max_size].gets--;
INSIST(size <= ctx->total);
ctx->inuse -= size;
ctx->total -= size;
return;
}
#if ISC_MEM_FILL
#if ISC_MEM_CHECKOVERRUN
check_overrun(mem, size, new_size);
#endif
memset(mem, 0xde, new_size); /* Mnemonic for "dead". */
#endif
/*
* The free list uses the "rounded-up" size "new_size".
*/
((element *)mem)->next = ctx->freelists[new_size];
ctx->freelists[new_size] = (element *)mem;
/*
* The stats[] uses the _actual_ "size" requested by the
* caller, with the caveat (in the code above) that "size" >= the
* max. size (max_size) ends up getting recorded as a call to
* max_size.
*/
INSIST(ctx->stats[size].gets != 0);
ctx->stats[size].gets--;
ctx->stats[new_size].freefrags++;
ctx->inuse -= new_size;
}
void *
isc__mem_getdebug(isc_mem_t *ctx, size_t size, const char *file, int line) {
void *ptr;
@@ -1180,7 +1172,7 @@ isc_mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp) {
}
void
isc_mempool_setname(isc_mempool_t *mpctx, char *name) {
isc_mempool_setname(isc_mempool_t *mpctx, const char *name) {
REQUIRE(name != NULL);
#if ISC_MEMPOOL_NAMES
@@ -1193,8 +1185,8 @@ isc_mempool_setname(isc_mempool_t *mpctx, char *name) {
if (mpctx->lock != NULL)
UNLOCK(mpctx->lock);
#else
(void)mpctx;
(void)name;
UNUSED(mpctx);
UNUSED(name);
#endif
}

View File

@@ -53,7 +53,7 @@ isc_boolean_t
isc_netaddr_eqprefix(const isc_netaddr_t *a, const isc_netaddr_t *b,
unsigned int prefixlen)
{
unsigned char *pa, *pb;
const unsigned char *pa, *pb;
unsigned int ipabytes; /* Length of whole IP address in bytes */
unsigned int nbytes; /* Number of significant whole bytes */
unsigned int nbits; /* Number of significant leftover bits */
@@ -65,13 +65,13 @@ isc_netaddr_eqprefix(const isc_netaddr_t *a, const isc_netaddr_t *b,
switch (a->family) {
case AF_INET:
pa = (unsigned char *) &a->type.in;
pb = (unsigned char *) &b->type.in;
pa = (const unsigned char *) &a->type.in;
pb = (const unsigned char *) &b->type.in;
ipabytes = 4;
break;
case AF_INET6:
pa = (unsigned char *) &a->type.in6;
pb = (unsigned char *) &b->type.in6;
pa = (const unsigned char *) &a->type.in6;
pb = (const unsigned char *) &b->type.in6;
ipabytes = 16;
break;
default:
@@ -80,7 +80,9 @@ isc_netaddr_eqprefix(const isc_netaddr_t *a, const isc_netaddr_t *b,
return (ISC_FALSE);
}
/* Don't crash if we get a pattern like 10.0.0.1/9999999. */
/*
* Don't crash if we get a pattern like 10.0.0.1/9999999.
*/
if (prefixlen > ipabytes * 8)
prefixlen = ipabytes * 8;
@@ -154,18 +156,17 @@ isc_netaddr_format(isc_netaddr_t *na, char *array, unsigned int size) {
}
isc_result_t
isc_netaddr_masktoprefixlen(const isc_netaddr_t *s, unsigned int *lenp)
{
isc_netaddr_masktoprefixlen(const isc_netaddr_t *s, unsigned int *lenp) {
unsigned int nbits, nbytes, ipbytes, i;
unsigned char *p;
const unsigned char *p;
switch (s->family) {
case AF_INET:
p = (unsigned char *) &s->type.in;
p = (const unsigned char *) &s->type.in;
ipbytes = 4;
break;
case AF_INET6:
p = (unsigned char *) &s->type.in6;
p = (const unsigned char *) &s->type.in6;
ipbytes = 16;
break;
default:
@@ -197,16 +198,14 @@ isc_netaddr_masktoprefixlen(const isc_netaddr_t *s, unsigned int *lenp)
}
void
isc_netaddr_fromin(isc_netaddr_t *netaddr, const struct in_addr *ina)
{
isc_netaddr_fromin(isc_netaddr_t *netaddr, const struct in_addr *ina) {
memset(netaddr, 0, sizeof *netaddr);
netaddr->family = AF_INET;
netaddr->type.in = *ina;
}
void
isc_netaddr_fromin6(isc_netaddr_t *netaddr, const struct in6_addr *ina6)
{
isc_netaddr_fromin6(isc_netaddr_t *netaddr, const struct in6_addr *ina6) {
memset(netaddr, 0, sizeof *netaddr);
netaddr->family = AF_INET6;
netaddr->type.in6 = *ina6;

View File

@@ -50,7 +50,7 @@ struct isc_msgcat {
(m)->magic == MSGCAT_MAGIC)
void
isc_msgcat_open(char *name, isc_msgcat_t **msgcatp) {
isc_msgcat_open(const char *name, isc_msgcat_t **msgcatp) {
isc_msgcat_t *msgcat;
/*
@@ -103,9 +103,9 @@ isc_msgcat_close(isc_msgcat_t **msgcatp) {
*msgcatp = NULL;
}
char *
const char *
isc_msgcat_get(isc_msgcat_t *msgcat, int set, int message,
char *default_text)
const char *default_text)
{
/*
* Get message 'message' from message set 'set' in 'msgcat'. If it

View File

@@ -29,13 +29,13 @@
typedef struct resulttable {
unsigned int base;
unsigned int last;
char ** text;
const char ** text;
isc_msgcat_t * msgcat;
int set;
ISC_LINK(struct resulttable) link;
} resulttable;
static char *text[ISC_R_NRESULTS] = {
static const char *text[ISC_R_NRESULTS] = {
"success", /* 0 */
"out of memory", /* 1 */
"timed out", /* 2 */
@@ -88,7 +88,7 @@ static ISC_LIST(resulttable) tables;
static isc_mutex_t lock;
static isc_result_t
register_table(unsigned int base, unsigned int nresults, char **text,
register_table(unsigned int base, unsigned int nresults, const char **text,
isc_msgcat_t *msgcat, int set)
{
resulttable *table;
@@ -140,10 +140,10 @@ initialize(void) {
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
}
char *
const char *
isc_result_totext(isc_result_t result) {
resulttable *table;
char *text, *default_text;
const char *text, *default_text;
int index;
initialize();
@@ -177,8 +177,8 @@ isc_result_totext(isc_result_t result) {
}
isc_result_t
isc_result_register(unsigned int base, unsigned int nresults, char **text,
isc_msgcat_t *msgcat, int set)
isc_result_register(unsigned int base, unsigned int nresults,
const char **text, isc_msgcat_t *msgcat, int set)
{
initialize();

View File

@@ -141,10 +141,12 @@ isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target) {
if (1 + plen + 1 > isc_buffer_availablelength(target))
return (ISC_R_NOSPACE);
isc_buffer_putmem(target, (unsigned char *)"#", 1);
isc_buffer_putmem(target, (unsigned char *)pbuf, plen);
isc_buffer_putmem(target, (const unsigned char *)"#", 1);
isc_buffer_putmem(target, (const unsigned char *)pbuf, plen);
/* Null terminate after used region. */
/*
* Null terminate after used region.
*/
isc_buffer_availableregion(target, &avail);
INSIST(avail.length >= 1);
avail.base[0] = '\0';
@@ -185,18 +187,19 @@ isc_sockaddr_hash(const isc_sockaddr_t *sockaddr, isc_boolean_t address_only) {
case AF_INET:
return (ntohl(sockaddr->type.sin.sin_addr.s_addr));
case AF_INET6:
s = (unsigned char *)&sockaddr->type.sin6.sin6_addr;
s = (const unsigned char *)&sockaddr->
type.sin6.sin6_addr;
length = sizeof sockaddr->type.sin6.sin6_addr;
break;
default:
UNEXPECTED_ERROR(__FILE__, __LINE__,
"unknown address family: %d",
(int)sockaddr->type.sa.sa_family);
s = (unsigned char *)&sockaddr->type;
s = (const unsigned char *)&sockaddr->type;
length = sockaddr->length;
}
} else {
s = (unsigned char *)&sockaddr->type;
s = (const unsigned char *)&sockaddr->type;
length = sockaddr->length;
}

View File

@@ -188,7 +188,7 @@ isc_symtab_lookup(isc_symtab_t *symtab, const char *key, unsigned int type,
}
isc_result_t
isc_symtab_define(isc_symtab_t *symtab, char *key, unsigned int type,
isc_symtab_define(isc_symtab_t *symtab, const char *key, unsigned int type,
isc_symvalue_t value, isc_symexists_t exists_policy)
{
unsigned int bucket;
@@ -214,7 +214,15 @@ isc_symtab_define(isc_symtab_t *symtab, char *key, unsigned int type,
if (elt == NULL)
return (ISC_R_NOMEMORY);
}
elt->key = key;
/*
* Though the "key" can be const coming in, it is not stored as const
* so that the calling program can easily have writable access to
* it in its undefine_action function. In the event that it *was*
* truly const coming in and then the caller modified it anyway ...
* well, don't do that!
*/
DE_CONST(key, elt->key);
elt->type = type;
elt->value = value;
@@ -227,7 +235,7 @@ isc_symtab_define(isc_symtab_t *symtab, char *key, unsigned int type,
}
isc_result_t
isc_symtab_undefine(isc_symtab_t *symtab, char *key, unsigned int type) {
isc_symtab_undefine(isc_symtab_t *symtab, const char *key, unsigned int type) {
unsigned int bucket;
elt_t *elt;

View File

@@ -589,7 +589,8 @@ isc_task_unsend(isc_task_t *task, void *sender, isc_eventtype_t type,
}
isc_result_t
isc_task_onshutdown(isc_task_t *task, isc_taskaction_t action, void *arg) {
isc_task_onshutdown(isc_task_t *task, isc_taskaction_t action, const void *arg)
{
isc_boolean_t disallowed = ISC_FALSE;
isc_result_t result = ISC_R_SUCCESS;
isc_event_t *event;
@@ -657,7 +658,7 @@ isc_task_destroy(isc_task_t **taskp) {
}
void
isc_task_setname(isc_task_t *task, char *name, void *tag) {
isc_task_setname(isc_task_t *task, const char *name, void *tag) {
/*
* Name 'task'.

View File

@@ -214,7 +214,7 @@ destroy(isc_timer_t *timer) {
isc_result_t
isc_timer_create(isc_timermgr_t *manager, isc_timertype_t type,
isc_time_t *expires, isc_interval_t *interval,
isc_task_t *task, isc_taskaction_t action, void *arg,
isc_task_t *task, isc_taskaction_t action, const void *arg,
isc_timer_t **timerp)
{
isc_timer_t *timer;
@@ -281,7 +281,17 @@ isc_timer_create(isc_timermgr_t *manager, isc_timertype_t type,
timer->task = NULL;
isc_task_attach(task, &timer->task);
timer->action = action;
timer->arg = arg;
/*
* Removing the const attribute from "arg" is the best of two
* evils here. If the timer->arg member is made const, then
* it affects a great many recipients of the timer event
* which did not pass in an "arg" that was truly const.
* Changing isc_timer_create() to not have "arg" prototyped as const,
* though, can cause compilers warnings for calls that *do*
* have a truly const arg. The caller will have to carefully
* keep track of whether arg started as a true const.
*/
DE_CONST(arg, timer->arg);
timer->index = 0;
if (isc_mutex_init(&timer->lock) != ISC_R_SUCCESS) {
isc_task_detach(&timer->task);

View File

@@ -668,7 +668,7 @@ set_dev_address(isc_sockaddr_t *address, isc_socket_t *sock,
static isc_socketevent_t *
allocate_socketevent(isc_socket_t *sock, isc_eventtype_t eventtype,
isc_taskaction_t action, void *arg)
isc_taskaction_t action, const void *arg)
{
isc_socketevent_t *ev;
@@ -2081,7 +2081,7 @@ isc_socketmgr_destroy(isc_socketmgr_t **managerp) {
isc_result_t
isc_socket_recvv(isc_socket_t *sock, isc_bufferlist_t *buflist,
unsigned int minimum,
isc_task_t *task, isc_taskaction_t action, void *arg)
isc_task_t *task, isc_taskaction_t action, const void *arg)
{
isc_socketevent_t *dev;
isc_socketmgr_t *manager;
@@ -2200,7 +2200,7 @@ isc_socket_recvv(isc_socket_t *sock, isc_bufferlist_t *buflist,
isc_result_t
isc_socket_recv(isc_socket_t *sock, isc_region_t *region, unsigned int minimum,
isc_task_t *task, isc_taskaction_t action, void *arg)
isc_task_t *task, isc_taskaction_t action, const void *arg)
{
isc_socketevent_t *dev;
isc_socketmgr_t *manager;
@@ -2302,7 +2302,7 @@ isc_socket_recv(isc_socket_t *sock, isc_region_t *region, unsigned int minimum,
isc_result_t
isc_socket_send(isc_socket_t *sock, isc_region_t *region,
isc_task_t *task, isc_taskaction_t action, void *arg)
isc_task_t *task, isc_taskaction_t action, const void *arg)
{
/*
* REQUIRE() checking performed in isc_socket_sendto()
@@ -2313,7 +2313,7 @@ isc_socket_send(isc_socket_t *sock, isc_region_t *region,
isc_result_t
isc_socket_sendto(isc_socket_t *sock, isc_region_t *region,
isc_task_t *task, isc_taskaction_t action, void *arg,
isc_task_t *task, isc_taskaction_t action, const void *arg,
isc_sockaddr_t *address, struct in6_pktinfo *pktinfo)
{
isc_socketevent_t *dev;
@@ -2408,7 +2408,7 @@ isc_socket_sendto(isc_socket_t *sock, isc_region_t *region,
isc_result_t
isc_socket_sendv(isc_socket_t *sock, isc_bufferlist_t *buflist,
isc_task_t *task, isc_taskaction_t action, void *arg)
isc_task_t *task, isc_taskaction_t action, const void *arg)
{
return (isc_socket_sendtov(sock, buflist, task, action, arg, NULL,
NULL));
@@ -2416,7 +2416,7 @@ isc_socket_sendv(isc_socket_t *sock, isc_bufferlist_t *buflist,
isc_result_t
isc_socket_sendtov(isc_socket_t *sock, isc_bufferlist_t *buflist,
isc_task_t *task, isc_taskaction_t action, void *arg,
isc_task_t *task, isc_taskaction_t action, const void *arg,
isc_sockaddr_t *address, struct in6_pktinfo *pktinfo)
{
isc_socketevent_t *dev;
@@ -2602,7 +2602,7 @@ isc_socket_listen(isc_socket_t *sock, unsigned int backlog) {
*/
isc_result_t
isc_socket_accept(isc_socket_t *sock,
isc_task_t *task, isc_taskaction_t action, void *arg)
isc_task_t *task, isc_taskaction_t action, const void *arg)
{
isc_socket_newconnev_t *dev;
isc_socketmgr_t *manager;
@@ -2664,7 +2664,7 @@ isc_socket_accept(isc_socket_t *sock,
isc_result_t
isc_socket_connect(isc_socket_t *sock, isc_sockaddr_t *addr,
isc_task_t *task, isc_taskaction_t action, void *arg)
isc_task_t *task, isc_taskaction_t action, const void *arg)
{
isc_socket_connev_t *dev;
isc_task_t *ntask = NULL;
@@ -3051,7 +3051,7 @@ isc_socket_cancel(isc_socket_t *sock, isc_task_t *task, unsigned int how) {
isc_result_t
isc_socket_recvmark(isc_socket_t *sock,
isc_task_t *task, isc_taskaction_t action, void *arg)
isc_task_t *task, isc_taskaction_t action, const void *arg)
{
isc_socketevent_t *dev;
isc_socketmgr_t *manager;
@@ -3108,7 +3108,7 @@ isc_socket_recvmark(isc_socket_t *sock,
isc_result_t
isc_socket_sendmark(isc_socket_t *sock,
isc_task_t *task, isc_taskaction_t action, void *arg)
isc_task_t *task, isc_taskaction_t action, const void *arg)
{
isc_socketevent_t *dev;
isc_socketmgr_t *manager;