Skip to content

Commit 094f301

Browse files
committed
Change the inner compute parents function back to static and add integrity flag to public method
1 parent bdde20d commit 094f301

3 files changed

Lines changed: 22 additions & 24 deletions

File tree

c/tskit/tables.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10986,8 +10986,8 @@ tsk_table_collection_check_index_integrity(const tsk_table_collection_t *self)
1098610986
return ret;
1098710987
}
1098810988

10989-
int TSK_WARN_UNUSED
10990-
tsk_table_collection_compute_mutation_parents_no_integrity_check(
10989+
static int TSK_WARN_UNUSED
10990+
tsk_table_collection_compute_mutation_parents_to_array(
1099110991
const tsk_table_collection_t *self, tsk_id_t *mutation_parent)
1099210992
{
1099310993
int ret = 0;
@@ -11110,10 +11110,8 @@ tsk_table_collection_check_mutation_parents(const tsk_table_collection_t *self)
1111011110
ret = tsk_trace_error(TSK_ERR_NO_MEMORY);
1111111111
goto out;
1111211112
}
11113-
tsk_memcpy(new_parents, mutations.parent, mutations.num_rows * sizeof(*new_parents));
1111411113

11115-
ret = tsk_table_collection_compute_mutation_parents_no_integrity_check(
11116-
self, new_parents);
11114+
ret = tsk_table_collection_compute_mutation_parents_to_array(self, new_parents);
1111711115
if (ret != 0) {
1111811116
goto out;
1111911117
}
@@ -12504,24 +12502,30 @@ tsk_table_collection_deduplicate_sites(
1250412502

1250512503
int TSK_WARN_UNUSED
1250612504
tsk_table_collection_compute_mutation_parents(
12507-
tsk_table_collection_t *self, tsk_flags_t TSK_UNUSED(options))
12505+
tsk_table_collection_t *self, tsk_flags_t options)
1250812506
{
1250912507
int ret = 0;
12510-
tsk_id_t num_trees;
1251112508
const tsk_mutation_table_t mutations = self->mutations;
1251212509

12513-
/* Set the mutation parent to TSK_NULL so that we don't use the
12514-
* parent values we are about to write over. */
12515-
tsk_memset(mutations.parent, 0xff, mutations.num_rows * sizeof(*mutations.parent));
12516-
12517-
num_trees = tsk_table_collection_check_integrity(self, TSK_CHECK_TREES);
12518-
if (num_trees < 0) {
12519-
ret = (int) num_trees;
12520-
goto out;
12510+
if (!(options & TSK_NO_CHECK_INTEGRITY)) {
12511+
/* Set the mutation parent to TSK_NULL so that we don't error
12512+
in the integrity check on data we're about to overwite.
12513+
*/
12514+
tsk_memset(
12515+
mutations.parent, 0xff, mutations.num_rows * sizeof(*mutations.parent));
12516+
12517+
/* Safe to cast here as we're not counting trees */
12518+
ret = (int) tsk_table_collection_check_integrity(self, TSK_CHECK_TREES);
12519+
if (ret < 0) {
12520+
goto out;
12521+
}
1252112522
}
1252212523

12523-
ret = tsk_table_collection_compute_mutation_parents_no_integrity_check(
12524+
ret = tsk_table_collection_compute_mutation_parents_to_array(
1252412525
self, self->mutations.parent);
12526+
if (ret != 0) {
12527+
goto out;
12528+
}
1252512529

1252612530
out:
1252712531
return ret;

c/tskit/tables.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4624,8 +4624,6 @@ int tsk_table_collection_deduplicate_sites(
46244624
tsk_table_collection_t *tables, tsk_flags_t options);
46254625
int tsk_table_collection_compute_mutation_parents(
46264626
tsk_table_collection_t *self, tsk_flags_t options);
4627-
int tsk_table_collection_compute_mutation_parents_no_integrity_check(
4628-
const tsk_table_collection_t *self, tsk_id_t *mutation_parent);
46294627
int tsk_table_collection_compute_mutation_times(
46304628
tsk_table_collection_t *self, double *random, tsk_flags_t options);
46314629
int tsk_table_collection_delete_older(

c/tskit/trees.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,8 @@ tsk_treeseq_init(
469469
goto out;
470470
}
471471

472-
/* Set the mutation parent to TSK_NULL so that we don't use the
473-
parent values we are about to write over. */
474-
tsk_memset(self->tables->mutations.parent, 0xff,
475-
self->tables->mutations.num_rows * sizeof(*self->tables->mutations.parent));
476-
ret = tsk_table_collection_compute_mutation_parents_no_integrity_check(
477-
self->tables, self->tables->mutations.parent);
472+
ret = tsk_table_collection_compute_mutation_parents(
473+
self->tables, TSK_NO_CHECK_INTEGRITY);
478474
if (ret != 0) {
479475
goto out;
480476
}

0 commit comments

Comments
 (0)