Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions c/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ In development.
- Tables loaded from a file can now be edited in the same way as any other
table collection (:user:`jeromekelleher`, :issue:`536`, :pr:`530`.

- Support for reading/writing to arbitrary file streams with the loadf/dumpf
variants for tree sequence and table collection load/dump
(:user:`jeromekelleher`, :user:`grahamgower`, :issue:`565`, :pr:`599`).

**Deprecated**

Expand Down
21 changes: 12 additions & 9 deletions c/examples/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Simple Makefile for building examples.
# This will build the examples in the current directory by compiling in the
# This will build the examples in the current directory by compiling in the
# full tskit source into each of the examples. This is *not* recommended for
# real projects!
#
Expand All @@ -8,28 +8,31 @@
#
# **Note**: This repo uses git submodules, and these must be checked out
# correctly for this makefile to work, e.g.:
#
#
# $ git clone git@github.com:tskit-dev/tskit.git --recurse-submodules
#
#
# See the documentation (https://tskit.readthedocs.io/en/stable/c-api.html)
# for more details on how to use the C API, and the tskit build examples
# repo (https://github.com/tskit-dev/tskit-build-examples) for examples
# for more details on how to use the C API, and the tskit build examples
# repo (https://github.com/tskit-dev/tskit-build-examples) for examples
# of how to set up a production-ready build with tskit.
#

CFLAGS=-I../ -I../subprojects/kastore
TSKIT_SOURCE=../tskit/*.c ../subprojects/kastore/kastore.c

all: tree_iteration haploid_wright_fisher tree_traversal
all: tree_iteration haploid_wright_fisher tree_traversal streaming

tree_iteration: tree_iteration.c
${CC} ${CFLAGS} -o $@ $< ${TSKIT_SOURCE} -lm

tree_iteration: tree_iteration.c
tree_traversal: tree_traversal.c
${CC} ${CFLAGS} -o $@ $< ${TSKIT_SOURCE} -lm

tree_traversal: tree_traversal.c
streaming: streaming.c
${CC} ${CFLAGS} -o $@ $< ${TSKIT_SOURCE} -lm

# This needs GSL
haploid_wright_fisher: haploid_wright_fisher.c
haploid_wright_fisher: haploid_wright_fisher.c
${CC} ${CFLAGS} -o $@ $< ${TSKIT_SOURCE} -lgsl -lgslcblas -lm

clean:
Expand Down
37 changes: 37 additions & 0 deletions c/examples/streaming.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
#include <tskit/tables.h>

#define check_tsk_error(val) \
if (val < 0) { \
fprintf(stderr, "Error: line %d: %s\n", __LINE__, tsk_strerror(val)); \
exit(EXIT_FAILURE); \
}

int
main(int argc, char **argv)
{
int ret;
int j = 0;
tsk_table_collection_t tables;

ret = tsk_table_collection_init(&tables, 0);
check_tsk_error(ret);

while (true) {
ret = tsk_table_collection_loadf(&tables, stdin, TSK_NO_INIT);
if (ret == TSK_ERR_EOF) {
break;
}
check_tsk_error(ret);
fprintf(stderr, "Tree sequence %d had %d mutations\n", j,
(int) tables.mutations.num_rows);
ret = tsk_mutation_table_truncate(&tables.mutations, 0);
check_tsk_error(ret);
ret = tsk_table_collection_dumpf(&tables, stdout, 0);
check_tsk_error(ret);
j++;
}
tsk_table_collection_free(&tables);
return EXIT_SUCCESS;
}
2 changes: 2 additions & 0 deletions c/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ if not meson.is_subproject()
sources: ['examples/tree_iteration.c'], link_with: [tskit_lib], dependencies: lib_deps)
executable('tree_traversal',
sources: ['examples/tree_traversal.c'], link_with: [tskit_lib], dependencies: lib_deps)
executable('streaming',
sources: ['examples/streaming.c'], link_with: [tskit_lib], dependencies: lib_deps)

gsl_dep = dependency('gsl', required: false)
if gsl_dep.found()
Expand Down
2 changes: 1 addition & 1 deletion c/tests/meson-subproject/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test_load_error()
printf("test_open_error\n");
tsk_treeseq_t ts;
int ret = tsk_treeseq_load(&ts, "no such file", 0);
assert(tsk_is_kas_error(ret));
assert(ret == TSK_ERR_IO);
tsk_treeseq_free(&ts);
}

Expand Down
2 changes: 1 addition & 1 deletion c/tests/test_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test_strerror(void)
static void
test_strerror_kastore(void)
{
int kastore_errors[] = { KAS_ERR_NO_MEMORY, KAS_ERR_IO, KAS_ERR_KEY_NOT_FOUND };
int kastore_errors[] = { KAS_ERR_NO_MEMORY, KAS_ERR_KEY_NOT_FOUND };
size_t j;
int err;

Expand Down
Loading