Skip to content

Commit 868ce92

Browse files
committed
Fixes #5
1 parent 755a024 commit 868ce92

5 files changed

Lines changed: 39 additions & 8 deletions

File tree

RcppTskit/R/Class-TreeSequence.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ TreeSequence <- R6::R6Class(
1717
#' @param options see \code{\link{ts_load}()}
1818
#' @param pointer an external pointer to a tree sequence
1919
initialize = function(file, options = 0L, pointer = NULL) {
20-
if (missing(file) & is.null(pointer)) {
20+
if (missing(file) && is.null(pointer)) {
2121
stop("you must provide a file name or a pointer!")
2222
}
23-
if (!missing(file) & !is.null(pointer)) {
24-
stop("you must provide either a file name or a pointer!")
23+
if (!missing(file) && !is.null(pointer)) {
24+
stop("you must provide either a file name or a pointer, but not both!")
2525
}
2626
if (!missing(file)) {
2727
if (!is.character(file)) {

RcppTskit/inst/include/tskit/core.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <tskit/tskit/core.h>
66

77
// Redefinition of tsk_bug_assert to avoid aborting R sessions with tskit C API
8-
// (following R extensions manual recommendations).
8+
// (see R extensions manual).
99
// While tsk_bug_assert is called only in C API (atm) we provide both C and C++
1010
// macros for completeness.
1111
// TODO: Redefine TSK_BUG_ASSERT_MESSAGE or create RcppTskit version if we will
@@ -33,7 +33,7 @@
3333
#endif
3434

3535
// Redefinition of tsk_trace_error to avoid writing to stderr from tskit C API
36-
// (following R extensions manual recommendations).
36+
// (see R extensions manual).
3737
// While tsk_trace_error is called only in C API (atm) we provide both C and C++
3838
// macros for completeness.
3939
#undef tsk_trace_error
@@ -61,4 +61,19 @@ static inline int _RcppTskit_trace_error_c(int err, int line,
6161
#define tsk_trace_error(err) (err)
6262
#endif
6363

64+
// Discard tskit debug output to avoid using stdout, as it is not captured by R.
65+
// (see R extensions manual).
66+
#if defined(_WIN32)
67+
#define RCPPTSKIT_NULL_DEVICE "NUL"
68+
#else
69+
#define RCPPTSKIT_NULL_DEVICE "/dev/null"
6470
#endif
71+
72+
static inline FILE *rcpptskit_default_debug_stream(void) {
73+
return fopen(RCPPTSKIT_NULL_DEVICE, "w");
74+
}
75+
76+
#undef TSK_DEFAULT_DEBUG_STREAM
77+
#define TSK_DEFAULT_DEBUG_STREAM rcpptskit_default_debug_stream()
78+
79+
#endif // RCPPTSKIT_TSKIT_CORE_H

RcppTskit/inst/include/tskit/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)) { \

RcppTskit/src/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
}

0 commit comments

Comments
 (0)