Unify write callback signature

This commit is contained in:
Yinan Zhang 2020-04-17 14:49:20 -07:00
parent fef9abdcc0
commit 2097e1945b
10 changed files with 20 additions and 22 deletions

View File

@ -10,8 +10,6 @@
* some "option like" content for the write_cb, so it doesn't matter. * some "option like" content for the write_cb, so it doesn't matter.
*/ */
typedef void (write_cb_t)(void *, const char *);
typedef struct { typedef struct {
write_cb_t *write_cb; write_cb_t *write_cb;
void *cbopaque; void *cbopaque;

View File

@ -68,7 +68,7 @@ typedef struct emitter_s emitter_t;
struct emitter_s { struct emitter_s {
emitter_output_t output; emitter_output_t output;
/* The output information. */ /* The output information. */
void (*write_cb)(void *, const char *); write_cb_t *write_cb;
void *cbopaque; void *cbopaque;
int nesting_depth; int nesting_depth;
/* True if we've already emitted a value at the given depth. */ /* True if we've already emitted a value at the given depth. */
@ -240,7 +240,7 @@ emitter_json_key_prefix(emitter_t *emitter) {
static inline void static inline void
emitter_init(emitter_t *emitter, emitter_output_t emitter_output, emitter_init(emitter_t *emitter, emitter_output_t emitter_output,
void (*write_cb)(void *, const char *), void *cbopaque) { write_cb_t *write_cb, void *cbopaque) {
emitter->output = emitter_output; emitter->output = emitter_output;
emitter->write_cb = write_cb; emitter->write_cb = write_cb;
emitter->cbopaque = cbopaque; emitter->cbopaque = cbopaque;

View File

@ -17,6 +17,9 @@ enum zero_realloc_action_e {
}; };
typedef enum zero_realloc_action_e zero_realloc_action_t; typedef enum zero_realloc_action_e zero_realloc_action_t;
/* Signature of write callback. */
typedef void (write_cb_t)(void *, const char *);
/* /*
* Flags bits: * Flags bits:
* *

View File

@ -1,6 +1,8 @@
#ifndef JEMALLOC_INTERNAL_MALLOC_IO_H #ifndef JEMALLOC_INTERNAL_MALLOC_IO_H
#define JEMALLOC_INTERNAL_MALLOC_IO_H #define JEMALLOC_INTERNAL_MALLOC_IO_H
#include "jemalloc/internal/jemalloc_internal_types.h"
#ifdef _WIN32 #ifdef _WIN32
# ifdef _WIN64 # ifdef _WIN64
# define FMT64_PREFIX "ll" # define FMT64_PREFIX "ll"
@ -40,7 +42,7 @@
*/ */
#define MALLOC_PRINTF_BUFSIZE 4096 #define MALLOC_PRINTF_BUFSIZE 4096
void wrtmessage(void *cbopaque, const char *s); write_cb_t wrtmessage;
int buferror(int err, char *buf, size_t buflen); int buferror(int err, char *buf, size_t buflen);
uintmax_t malloc_strtoumax(const char *restrict nptr, char **restrict endptr, uintmax_t malloc_strtoumax(const char *restrict nptr, char **restrict endptr,
int base); int base);
@ -58,10 +60,10 @@ size_t malloc_snprintf(char *str, size_t size, const char *format, ...)
* The caller can set write_cb to null to choose to print with the * The caller can set write_cb to null to choose to print with the
* je_malloc_message hook. * je_malloc_message hook.
*/ */
void malloc_vcprintf(void (*write_cb)(void *, const char *), void *cbopaque, void malloc_vcprintf(write_cb_t *write_cb, void *cbopaque, const char *format,
const char *format, va_list ap); va_list ap);
void malloc_cprintf(void (*write_cb)(void *, const char *), void *cbopaque, void malloc_cprintf(write_cb_t *write_cb, void *cbopaque, const char *format,
const char *format, ...) JEMALLOC_FORMAT_PRINTF(3, 4); ...) JEMALLOC_FORMAT_PRINTF(3, 4);
void malloc_printf(const char *format, ...) JEMALLOC_FORMAT_PRINTF(1, 2); void malloc_printf(const char *format, ...) JEMALLOC_FORMAT_PRINTF(1, 2);
static inline ssize_t static inline ssize_t

View File

@ -106,7 +106,6 @@ bool prof_log_stop(tsdn_t *tsdn);
ssize_t prof_recent_alloc_max_ctl_read(); ssize_t prof_recent_alloc_max_ctl_read();
ssize_t prof_recent_alloc_max_ctl_write(tsd_t *tsd, ssize_t max); ssize_t prof_recent_alloc_max_ctl_write(tsd_t *tsd, ssize_t max);
void prof_recent_alloc_dump(tsd_t *tsd, void (*write_cb)(void *, const char *), void prof_recent_alloc_dump(tsd_t *tsd, write_cb_t *write_cb, void *cbopaque);
void *cbopaque);
#endif /* JEMALLOC_INTERNAL_PROF_EXTERNS_H */ #endif /* JEMALLOC_INTERNAL_PROF_EXTERNS_H */

View File

@ -41,8 +41,7 @@ uint64_t stats_interval_accum_batch_size(void);
bool stats_interval_accum(tsd_t *tsd, uint64_t bytes); bool stats_interval_accum(tsd_t *tsd, uint64_t bytes);
/* Implements je_malloc_stats_print. */ /* Implements je_malloc_stats_print. */
void stats_print(void (*write_cb)(void *, const char *), void *cbopaque, void stats_print(write_cb_t *write_cb, void *cbopaque, const char *opts);
const char *opts);
bool stats_boot(void); bool stats_boot(void);

View File

@ -3522,7 +3522,7 @@ label_return:
typedef struct write_cb_packet_s write_cb_packet_t; typedef struct write_cb_packet_s write_cb_packet_t;
struct write_cb_packet_s { struct write_cb_packet_s {
void (*write_cb)(void *, const char *); write_cb_t *write_cb;
void *cbopaque; void *cbopaque;
}; };

View File

@ -619,8 +619,8 @@ malloc_snprintf(char *str, size_t size, const char *format, ...) {
} }
void void
malloc_vcprintf(void (*write_cb)(void *, const char *), void *cbopaque, malloc_vcprintf(write_cb_t *write_cb, void *cbopaque, const char *format,
const char *format, va_list ap) { va_list ap) {
char buf[MALLOC_PRINTF_BUFSIZE]; char buf[MALLOC_PRINTF_BUFSIZE];
if (write_cb == NULL) { if (write_cb == NULL) {
@ -643,8 +643,7 @@ malloc_vcprintf(void (*write_cb)(void *, const char *), void *cbopaque,
*/ */
JEMALLOC_FORMAT_PRINTF(3, 4) JEMALLOC_FORMAT_PRINTF(3, 4)
void void
malloc_cprintf(void (*write_cb)(void *, const char *), void *cbopaque, malloc_cprintf(write_cb_t *write_cb, void *cbopaque, const char *format, ...) {
const char *format, ...) {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);

View File

@ -444,8 +444,7 @@ dump_bt(emitter_t *emitter, prof_tctx_t *tctx) {
#define PROF_RECENT_PRINT_BUFSIZE 4096 #define PROF_RECENT_PRINT_BUFSIZE 4096
void void
prof_recent_alloc_dump(tsd_t *tsd, void (*write_cb)(void *, const char *), prof_recent_alloc_dump(tsd_t *tsd, write_cb_t *write_cb, void *cbopaque) {
void *cbopaque) {
buf_writer_t buf_writer; buf_writer_t buf_writer;
buf_writer_init(tsd_tsdn(tsd), &buf_writer, write_cb, cbopaque, NULL, buf_writer_init(tsd_tsdn(tsd), &buf_writer, write_cb, cbopaque, NULL,
PROF_RECENT_PRINT_BUFSIZE); PROF_RECENT_PRINT_BUFSIZE);

View File

@ -1431,8 +1431,7 @@ stats_print_helper(emitter_t *emitter, bool merged, bool destroyed,
} }
void void
stats_print(void (*write_cb)(void *, const char *), void *cbopaque, stats_print(write_cb_t *write_cb, void *cbopaque, const char *opts) {
const char *opts) {
int err; int err;
uint64_t epoch; uint64_t epoch;
size_t u64sz; size_t u64sz;