Skip to content

Commit 995a7be

Browse files
Add support for compile time setting of debug stream
Also add some notes on macros that were redefined as part of an experimental downstream build as an Rcpp package. These notes are intended to prevent accidental change and the macros may get promoted to being formally documented if this approach works and the R package is published.
1 parent b7fd993 commit 995a7be

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

c/tskit/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ FILE *
10411041
tsk_get_debug_stream(void)
10421042
{
10431043
if (_tsk_debug_stream == NULL) {
1044-
_tsk_debug_stream = stdout;
1044+
_tsk_debug_stream = TSK_DEFAULT_DEBUG_STREAM;
10451045
}
10461046
return _tsk_debug_stream;
10471047
}

c/tskit/core.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ disallowed (use compute_mutation_times?).
511511
*/
512512
#define TSK_ERR_DISALLOWED_UNKNOWN_MUTATION_TIME -510
513513

514-
/**
514+
/**
515515
A mutation's parent was not consistent with the topology of the tree.
516516
*/
517517
#define TSK_ERR_BAD_MUTATION_PARENT -511
@@ -971,6 +971,12 @@ not be freed by client code.
971971
*/
972972
const char *tsk_strerror(int err);
973973

974+
/* Redefine this macro in downstream builds if stdout is not the
975+
* approriate stream to emit debug information when the TSK_DEBUG
976+
* flag is passed to supporting functions (e.g. in R).
977+
*/
978+
#define TSK_DEFAULT_DEBUG_STREAM stdout
979+
974980
#ifdef TSK_TRACE_ERRORS
975981

976982
static inline int
@@ -981,6 +987,11 @@ _tsk_trace_error(int err, int line, const char *file)
981987
return err;
982988
}
983989

990+
/*
991+
Developer note: this macro may be redefined as part of compilation for
992+
an R package, and should be treated as part of the documented API
993+
(no changes).
994+
*/
984995
#define tsk_trace_error(err) (_tsk_trace_error(err, __LINE__, __FILE__))
985996
#else
986997
#define tsk_trace_error(err) (err)
@@ -1001,6 +1012,11 @@ means compiling without NDEBUG. This macro still asserts when NDEBUG is defined.
10011012
If you are using this macro in your own software then please set TSK_BUG_ASSERT_MESSAGE
10021013
to point users to your issue tracker.
10031014
*/
1015+
/*
1016+
Developer note: this macro may redefined as part of compilation for
1017+
an R package, and should be treated as part of the documented API
1018+
(no changes).
1019+
*/
10041020
#define tsk_bug_assert(condition) \
10051021
do { \
10061022
if (!(condition)) { \

0 commit comments

Comments
 (0)