Skip to content

Commit 6462d9b

Browse files
authored
chore: update to C API 1.1.1 (#304)
1 parent 7a6d3e7 commit 6462d9b

File tree

8 files changed

+674
-50
lines changed

8 files changed

+674
-50
lines changed

subprojects/tskit/VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0
1+
1.1.1

subprojects/tskit/tskit/core.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ tsk_strerror_internal(int err)
265265
break;
266266
case TSK_ERR_BAD_EDGES_CONTRADICTORY_CHILDREN:
267267
ret = "Bad edges: contradictory children for a given parent over "
268-
"an interval. (TSK_ERR_BAD_EDGES_CONTRADICTORY_CHILDREN)";
268+
"an interval, or indexes need to be rebuilt. "
269+
"(TSK_ERR_BAD_EDGES_CONTRADICTORY_CHILDREN)";
269270
break;
270271
case TSK_ERR_CANT_PROCESS_EDGES_WITH_METADATA:
271272
ret = "Can't squash, flush, simplify or link ancestors with edges that have "
@@ -336,7 +337,7 @@ tsk_strerror_internal(int err)
336337
ret = "Duplicate sample value. (TSK_ERR_DUPLICATE_SAMPLE)";
337338
break;
338339
case TSK_ERR_BAD_SAMPLES:
339-
ret = "Bad sample configuration provided. (TSK_ERR_BAD_SAMPLES)";
340+
ret = "The nodes provided are not samples. (TSK_ERR_BAD_SAMPLES)";
340341
break;
341342

342343
/* Table errors */
@@ -350,6 +351,10 @@ tsk_strerror_internal(int err)
350351
case TSK_ERR_TABLES_NOT_INDEXED:
351352
ret = "Table collection must be indexed. (TSK_ERR_TABLES_NOT_INDEXED)";
352353
break;
354+
case TSK_ERR_TABLES_BAD_INDEXES:
355+
ret = "Table collection indexes inconsistent: do they need to be rebuilt? "
356+
"(TSK_ERR_TABLES_BAD_INDEXES)";
357+
break;
353358
case TSK_ERR_TABLE_OVERFLOW:
354359
ret = "Table too large; cannot allocate more than 2**31 rows. "
355360
"(TSK_ERR_TABLE_OVERFLOW)";
@@ -408,6 +413,14 @@ tsk_strerror_internal(int err)
408413
ret = "A tree sequence can't take ownership of tables with "
409414
"TSK_NO_EDGE_METADATA. (TSK_ERR_CANT_TAKE_OWNERSHIP_NO_EDGE_METADATA)";
410415
break;
416+
case TSK_ERR_UNDEFINED_NONBINARY:
417+
ret = "Operation undefined for nonbinary trees. "
418+
"(TSK_ERR_UNDEFINED_NONBINARY)";
419+
break;
420+
case TSK_ERR_UNDEFINED_MULTIROOT:
421+
ret = "Operation undefined for trees that are not singly-rooted. "
422+
"(TSK_ERR_UNDEFINED_MULTIROOT)";
423+
break;
411424

412425
/* Stats errors */
413426
case TSK_ERR_BAD_NUM_WINDOWS:
@@ -500,7 +513,8 @@ tsk_strerror_internal(int err)
500513
break;
501514
case TSK_ERR_NO_SAMPLE_LISTS:
502515
ret = "The sample_lists option must be enabled on the tree to perform this "
503-
"operation. (TSK_ERR_NO_SAMPLE_LISTS)";
516+
"operation. Pass the option to the constructor or method that created "
517+
"the tree. (TSK_ERR_NO_SAMPLE_LISTS)";
504518
break;
505519

506520
/* Haplotype matching errors */
@@ -571,6 +585,18 @@ tsk_strerror_internal(int err)
571585
ret = "Individuals cannot be their own ancestor. "
572586
"(TSK_ERR_INDIVIDUAL_PARENT_CYCLE)";
573587
break;
588+
589+
case TSK_ERR_INDIVIDUAL_POPULATION_MISMATCH:
590+
ret = "Individual populations cannot be returned "
591+
"if an individual has nodes from more than one population. "
592+
"(TSK_ERR_INDIVIDUAL_POPULATION_MISMATCH)";
593+
break;
594+
595+
case TSK_ERR_INDIVIDUAL_TIME_MISMATCH:
596+
ret = "Individual times cannot be returned "
597+
"if an individual has nodes from more than one time. "
598+
"(TSK_ERR_INDIVIDUAL_TIME_MISMATCH)";
599+
break;
574600
}
575601
return ret;
576602
}

subprojects/tskit/tskit/core.h

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ sizes and types of externally visible structs.
138138
The library minor version. Incremented when non-breaking backward-compatible changes
139139
to the API or ABI are introduced, i.e., the addition of a new function.
140140
*/
141-
#define TSK_VERSION_MINOR 0
141+
#define TSK_VERSION_MINOR 1
142142
/**
143143
The library patch version. Incremented when any changes not relevant to the
144144
to the API or ABI are introduced, i.e., internal refactors of bugfixes.
145145
*/
146-
#define TSK_VERSION_PATCH 0
146+
#define TSK_VERSION_PATCH 1
147147
/** @} */
148148

149149
/*
@@ -172,12 +172,12 @@ Used in node flags to indicate that a node is a sample node.
172172
*/
173173
#define TSK_NODE_IS_SAMPLE 1u
174174

175-
/**
175+
/**
176176
Null value used for cases such as absent id references.
177177
*/
178178
#define TSK_NULL ((tsk_id_t) -1)
179179

180-
/**
180+
/**
181181
Value used for missing data in genotype arrays.
182182
*/
183183
#define TSK_MISSING_DATA (-1)
@@ -206,7 +206,7 @@ whose representation differs from the NAN generated by computations such as divi
206206

207207
/* Place the common options at the top of the space; this way we can start
208208
options for individual functions at the bottom without worrying about
209-
clashing with the common options
209+
clashing with the common options
210210
*/
211211

212212
/** Turn on debugging output. Not supported by all functions. */
@@ -224,7 +224,7 @@ behaviour.
224224
*/
225225
#define TSK_NO_CHECK_INTEGRITY (1u << 29)
226226

227-
/**
227+
/**
228228
Instead of taking a copy of input objects, the function should take ownership
229229
of them and manage their lifecycle. The caller specifying this flag should no
230230
longer modify or free the object or objects passed. See individual functions
@@ -543,6 +543,10 @@ The table collection contains more than 2**31 trees.
543543
Metadata was attempted to be set on a table where it is disabled.
544544
*/
545545
#define TSK_ERR_METADATA_DISABLED -706
546+
/**
547+
There was an error with the table's indexes.
548+
*/
549+
#define TSK_ERR_TABLES_BAD_INDEXES -707
546550
/** @} */
547551

548552
/**
@@ -595,13 +599,22 @@ A tree sequence cannot take ownership of a table collection where
595599
TSK_NO_EDGE_METADATA.
596600
*/
597601
#define TSK_ERR_CANT_TAKE_OWNERSHIP_NO_EDGE_METADATA -809
602+
/**
603+
Operation is undefined for nonbinary trees
604+
*/
605+
#define TSK_ERR_UNDEFINED_NONBINARY -810
606+
/**
607+
Operation is undefined for trees with multiple roots.
608+
*/
609+
#define TSK_ERR_UNDEFINED_MULTIROOT -811
610+
598611
/** @} */
599612

600613
/**
601614
@defgroup STATS_ERROR_GROUP Stats errors.
602615
@{
603616
*/
604-
/**
617+
/**
605618
Zero windows were specified, at least one window must be specified.
606619
*/
607620
#define TSK_ERR_BAD_NUM_WINDOWS -900
@@ -653,17 +666,17 @@ were ``uncalibrated``.
653666
@defgroup MAPPING_ERROR_GROUP Mutation mapping errors.
654667
@{
655668
*/
656-
/**
669+
/**
657670
Only missing genotypes were specified, at least one non-missing is
658671
required.
659672
*/
660673
#define TSK_ERR_GENOTYPES_ALL_MISSING -1000
661-
/**
674+
/**
662675
A genotype value was greater than the maximum allowed (64) or less
663676
than TSK_MISSING_DATA (-1).
664677
*/
665678
#define TSK_ERR_BAD_GENOTYPE -1001
666-
/**
679+
/**
667680
A ancestral genotype value was greater than the maximum allowed (64) or less
668681
than 0.
669682
*/
@@ -760,7 +773,7 @@ specified table collection.
760773
/**
761774
The shared portions of the specified tree sequences are not equal.
762775
Note that this may be the case if the table collections were not
763-
fully sorted before union was called.
776+
fully sorted before union was called.
764777
*/
765778
#define TSK_ERR_UNION_DIFF_HISTORIES -1401
766779
/** @} */
@@ -812,6 +825,16 @@ An individual was its own parent.
812825
An individual was its own ancestor in a cycle of references.
813826
*/
814827
#define TSK_ERR_INDIVIDUAL_PARENT_CYCLE -1702
828+
/**
829+
An individual had nodes from more than one population
830+
(and only one was requested).
831+
*/
832+
#define TSK_ERR_INDIVIDUAL_POPULATION_MISMATCH -1703
833+
/**
834+
An individual had nodes from more than one time
835+
(and only one was requested).
836+
*/
837+
#define TSK_ERR_INDIVIDUAL_TIME_MISMATCH -1704
815838
/** @} */
816839
// clang-format on
817840

subprojects/tskit/tskit/genotypes.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@ tsk_variant_decode(
463463
tsk_id_t allele_index;
464464
tsk_size_t j, num_missing;
465465
int no_longer_missing;
466-
467466
tsk_mutation_t mutation;
468467
bool impute_missing = !!(self->options & TSK_ISOLATED_NOT_MISSING);
469468
bool by_traversal = self->alt_samples != NULL;
@@ -485,7 +484,7 @@ tsk_variant_decode(
485484
goto out;
486485
}
487486

488-
/* When we have a no specified samples we need sample lists to be active
487+
/* When we have no specified samples we need sample lists to be active
489488
* on the tree, as indicated by the presence of left_sample */
490489
if (!by_traversal && self->tree.left_sample == NULL) {
491490
ret = TSK_ERR_NO_SAMPLE_LISTS;
@@ -582,11 +581,11 @@ tsk_variant_restricted_copy(const tsk_variant_t *self, tsk_variant_t *other)
582581
tsk_size_t total_len, offset, j;
583582

584583
/* Copy everything */
585-
tsk_memcpy(other, self, sizeof(tsk_variant_t));
584+
tsk_memcpy(other, self, sizeof(*other));
586585
/* Tree sequence left as NULL and zero'd tree is a way of indicating this variant is
587586
* fixed and cannot be further decoded. */
588587
other->tree_sequence = NULL;
589-
tsk_memset(&other->tree, sizeof(tsk_tree_t), 0);
588+
tsk_memset(&other->tree, sizeof(other->tree), 0);
590589
other->traversal_stack = NULL;
591590
other->samples = NULL;
592591
other->sample_index_map = NULL;
@@ -598,27 +597,32 @@ tsk_variant_restricted_copy(const tsk_variant_t *self, tsk_variant_t *other)
598597
for (j = 0; j < self->num_alleles; j++) {
599598
total_len += self->allele_lengths[j];
600599
}
601-
other->genotypes = tsk_malloc(other->num_samples * sizeof(int32_t));
602-
other->user_alleles_mem = tsk_malloc(total_len * sizeof(char *));
600+
other->samples = tsk_malloc(other->num_samples * sizeof(*other->samples));
601+
other->genotypes = tsk_malloc(other->num_samples * sizeof(*other->genotypes));
602+
other->user_alleles_mem = tsk_malloc(total_len * sizeof(*other->user_alleles_mem));
603603
other->allele_lengths
604604
= tsk_malloc(other->num_alleles * sizeof(*other->allele_lengths));
605605
other->alleles = tsk_malloc(other->num_alleles * sizeof(*other->alleles));
606-
if (other->genotypes == NULL || other->user_alleles_mem == NULL
607-
|| other->allele_lengths == NULL || other->alleles == NULL) {
606+
if (other->samples == NULL || other->genotypes == NULL
607+
|| other->user_alleles_mem == NULL || other->allele_lengths == NULL
608+
|| other->alleles == NULL) {
608609
ret = TSK_ERR_NO_MEMORY;
609610
goto out;
610611
}
611-
612-
tsk_memcpy(other->genotypes, self->genotypes, other->num_samples * sizeof(int32_t));
612+
tsk_memcpy(
613+
other->samples, self->samples, other->num_samples * sizeof(*other->samples));
614+
tsk_memcpy(other->genotypes, self->genotypes,
615+
other->num_samples * sizeof(*other->genotypes));
613616
tsk_memcpy(other->allele_lengths, self->allele_lengths,
614617
other->num_alleles * sizeof(*other->allele_lengths));
615618
offset = 0;
616619
for (j = 0; j < other->num_alleles; j++) {
617620
tsk_memcpy(other->user_alleles_mem + offset, self->alleles[j],
618-
other->allele_lengths[j] * sizeof(char *));
621+
other->allele_lengths[j] * sizeof(*other->user_alleles_mem));
619622
other->alleles[j] = other->user_alleles_mem + offset;
620623
offset += other->allele_lengths[j];
621624
}
625+
622626
out:
623627
return ret;
624628
}

0 commit comments

Comments
 (0)