Skip to content

Commit 21a2f2c

Browse files
Basic C library changes for 64 bit tsk_size_t
Partial Update offset column accessors Fix uint32 in sample_set_sizes Tests passing Partial Tests mostly passing here
1 parent 35e7d5f commit 21a2f2c

File tree

9 files changed

+107
-99
lines changed

9 files changed

+107
-99
lines changed

c/tests/test_file_format.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,10 @@ verify_bad_offset_columns(tsk_treeseq_t *ts, const char *offset_col)
359359
int ret = 0;
360360
kastore_t store;
361361
tsk_table_collection_t tables;
362-
tsk_size_t *offset_array, *offset_copy;
362+
uint32_t *offset_array, *offset_copy;
363363
size_t offset_len;
364364
int type;
365-
tsk_size_t data_len;
365+
uint32_t data_len;
366366

367367
ret = tsk_treeseq_dump(ts, _tmp_file_name, 0);
368368
CU_ASSERT_EQUAL_FATAL(ret, 0);
@@ -371,7 +371,7 @@ verify_bad_offset_columns(tsk_treeseq_t *ts, const char *offset_col)
371371

372372
ret = kastore_gets(&store, offset_col, (void **) &offset_array, &offset_len, &type);
373373
CU_ASSERT_EQUAL_FATAL(ret, 0);
374-
CU_ASSERT_EQUAL_FATAL(type, TSK_SIZE_STORAGE_TYPE);
374+
CU_ASSERT_EQUAL_FATAL(type, KAS_UINT32);
375375
offset_copy = malloc(offset_len * sizeof(*offset_array));
376376
CU_ASSERT_FATAL(offset_copy != NULL);
377377
memcpy(offset_copy, offset_array, offset_len * sizeof(*offset_array));
@@ -383,8 +383,7 @@ verify_bad_offset_columns(tsk_treeseq_t *ts, const char *offset_col)
383383
copy_store_drop_columns(ts, 1, &offset_col, _tmp_file_name);
384384
ret = kastore_open(&store, _tmp_file_name, "a", 0);
385385
CU_ASSERT_EQUAL_FATAL(ret, 0);
386-
ret = kastore_puts(
387-
&store, offset_col, offset_copy, offset_len, TSK_SIZE_STORAGE_TYPE, 0);
386+
ret = kastore_puts(&store, offset_col, offset_copy, offset_len, KAS_UINT32, 0);
388387
CU_ASSERT_EQUAL_FATAL(ret, 0);
389388
ret = kastore_close(&store);
390389
CU_ASSERT_EQUAL_FATAL(ret, 0);
@@ -397,8 +396,7 @@ verify_bad_offset_columns(tsk_treeseq_t *ts, const char *offset_col)
397396
copy_store_drop_columns(ts, 1, &offset_col, _tmp_file_name);
398397
ret = kastore_open(&store, _tmp_file_name, "a", 0);
399398
CU_ASSERT_EQUAL_FATAL(ret, 0);
400-
ret = kastore_puts(
401-
&store, offset_col, offset_copy, offset_len, TSK_SIZE_STORAGE_TYPE, 0);
399+
ret = kastore_puts(&store, offset_col, offset_copy, offset_len, KAS_UINT32, 0);
402400
CU_ASSERT_EQUAL_FATAL(ret, 0);
403401
ret = kastore_close(&store);
404402
CU_ASSERT_EQUAL_FATAL(ret, 0);
@@ -410,8 +408,7 @@ verify_bad_offset_columns(tsk_treeseq_t *ts, const char *offset_col)
410408
copy_store_drop_columns(ts, 1, &offset_col, _tmp_file_name);
411409
ret = kastore_open(&store, _tmp_file_name, "a", 0);
412410
CU_ASSERT_EQUAL_FATAL(ret, 0);
413-
ret = kastore_puts(
414-
&store, offset_col, offset_copy, offset_len, TSK_SIZE_STORAGE_TYPE, 0);
411+
ret = kastore_puts(&store, offset_col, offset_copy, offset_len, KAS_UINT32, 0);
415412
CU_ASSERT_EQUAL_FATAL(ret, 0);
416413
ret = kastore_close(&store);
417414
CU_ASSERT_EQUAL_FATAL(ret, 0);
@@ -422,7 +419,7 @@ verify_bad_offset_columns(tsk_treeseq_t *ts, const char *offset_col)
422419
copy_store_drop_columns(ts, 1, &offset_col, _tmp_file_name);
423420
ret = kastore_open(&store, _tmp_file_name, "a", 0);
424421
CU_ASSERT_EQUAL_FATAL(ret, 0);
425-
ret = kastore_puts(&store, offset_col, NULL, 0, TSK_SIZE_STORAGE_TYPE, 0);
422+
ret = kastore_puts(&store, offset_col, NULL, 0, KAS_UINT32, 0);
426423
CU_ASSERT_EQUAL_FATAL(ret, 0);
427424
ret = kastore_close(&store);
428425
CU_ASSERT_EQUAL_FATAL(ret, 0);
@@ -977,24 +974,24 @@ static void
977974
test_load_node_table_errors(void)
978975
{
979976
char format_name[TSK_FILE_FORMAT_NAME_LENGTH];
980-
tsk_size_t uuid_size = 36;
977+
size_t uuid_size = 36;
981978
char uuid[uuid_size];
982979
double L = 1;
983980
double time = 0;
984981
double flags = 0;
985982
tsk_id_t population = 0;
986983
tsk_id_t individual = 0;
987984
int8_t metadata = 0;
988-
tsk_size_t metadata_offset[] = { 0, 1 };
989-
tsk_size_t version[2]
985+
uint32_t metadata_offset[] = { 0, 1 };
986+
uint32_t version[2]
990987
= { TSK_FILE_FORMAT_VERSION_MAJOR, TSK_FILE_FORMAT_VERSION_MINOR };
991988
write_table_col_t write_cols[] = {
992989
{ "nodes/time", (void *) &time, 1, KAS_FLOAT64 },
993990
{ "nodes/flags", (void *) &flags, 1, TSK_FLAGS_STORAGE_TYPE },
994991
{ "nodes/population", (void *) &population, 1, TSK_ID_STORAGE_TYPE },
995992
{ "nodes/individual", (void *) &individual, 1, TSK_ID_STORAGE_TYPE },
996993
{ "nodes/metadata", (void *) &metadata, 1, KAS_UINT8 },
997-
{ "nodes/metadata_offset", (void *) metadata_offset, 2, TSK_SIZE_STORAGE_TYPE },
994+
{ "nodes/metadata_offset", (void *) metadata_offset, 2, KAS_UINT32 },
998995
{ "format/name", (void *) format_name, sizeof(format_name), KAS_INT8 },
999996
{ "format/version", (void *) version, 2, KAS_UINT32 },
1000997
{ "uuid", (void *) uuid, uuid_size, KAS_INT8 },

c/tskit/core.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,9 @@ typedef int32_t tsk_id_t;
147147
The ``tsk_size_t`` type is an unsigned integer used for any size or count value.
148148
@endrst
149149
*/
150-
#ifdef _TSK_BIG_TABLES
151-
/* TODO get rid of this typdef once we move to 64 bit sizes */
152150
typedef uint64_t tsk_size_t;
153151
#define TSK_MAX_SIZE UINT64_MAX
154152
#define TSK_SIZE_STORAGE_TYPE KAS_UINT64
155-
#else
156-
typedef uint32_t tsk_size_t;
157-
#define TSK_MAX_SIZE UINT32_MAX
158-
#define TSK_SIZE_STORAGE_TYPE KAS_UINT32
159-
#endif
160153

161154
/**
162155
@brief Container for bitwise flags.

c/tskit/tables.c

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ read_table_cols(kastore_t *store, tsk_size_t *num_rows, read_table_col_t *cols,
146146
}
147147

148148
static int
149-
cast_offset_array(read_table_ragged_col_t *col, uint64_t *source, tsk_size_t num_rows)
149+
cast_offset_array(read_table_ragged_col_t *col, uint32_t *source, tsk_size_t num_rows)
150150
{
151151
int ret = 0;
152152
tsk_size_t len = num_rows + 1;
153153
tsk_size_t j;
154-
uint32_t *dest = tsk_malloc(len * sizeof(*dest));
154+
uint64_t *dest = tsk_malloc(len * sizeof(*dest));
155155

156156
if (dest == NULL) {
157157
ret = TSK_ERR_NO_MEMORY;
@@ -160,9 +160,7 @@ cast_offset_array(read_table_ragged_col_t *col, uint64_t *source, tsk_size_t num
160160
col->offset_array_mem = dest;
161161
*col->offset_array_dest = dest;
162162
for (j = 0; j < len; j++) {
163-
/* We don't bother catching errors here because we'll be switching this
164-
* to casting up to 64 bit soon; current version is temporary. */
165-
dest[j] = (uint32_t) source[j];
163+
dest[j] = source[j];
166164
}
167165
out:
168166
return ret;
@@ -243,10 +241,10 @@ read_table_ragged_cols(kastore_t *store, tsk_size_t *num_rows,
243241
goto out;
244242
}
245243
}
246-
if (type == KAS_UINT32) {
247-
*col->offset_array_dest = (uint32_t *) store_offset_array;
248-
} else if (type == KAS_UINT64) {
249-
ret = cast_offset_array(col, (uint64_t *) store_offset_array, *num_rows);
244+
if (type == KAS_UINT64) {
245+
*col->offset_array_dest = (uint64_t *) store_offset_array;
246+
} else if (type == KAS_UINT32) {
247+
ret = cast_offset_array(col, (uint32_t *) store_offset_array, *num_rows);
250248
if (ret != 0) {
251249
goto out;
252250
}
@@ -351,44 +349,39 @@ write_offset_col(
351349
{
352350
int ret = 0;
353351
char offset_col_name[TSK_MAX_COL_NAME_LEN];
354-
int64_t *offset64 = NULL;
352+
uint32_t *offset32 = NULL;
355353
tsk_size_t len = col->num_rows + 1;
356354
tsk_size_t j;
357355
int type;
358356
const void *data;
357+
bool needs_64 = col->offset_array[col->num_rows] > UINT32_MAX;
359358

360359
assert(strlen(col->name) + strlen("_offset") + 2 < sizeof(offset_col_name));
361360
strcpy(offset_col_name, col->name);
362361
strcat(offset_col_name, "_offset");
363362

364-
/* Note: this is a temporary implementation while we're getting some infrastructure
365-
* in place for the change to 64 bit offsets. Ultimately we'll be doing the cast
366-
* in the other direction, if the size of small enough. The TSK_DUMP_FORCE_OFFSET_64
367-
* option will still be useful for testing though, because that means we don't have
368-
* to force huge arrays to test all the code paths.
369-
*/
370-
if (options & TSK_DUMP_FORCE_OFFSET_64) {
371-
offset64 = tsk_malloc(len * sizeof(*offset64));
372-
if (offset64 == NULL) {
363+
if (options & TSK_DUMP_FORCE_OFFSET_64 || needs_64) {
364+
type = KAS_UINT64;
365+
data = col->offset_array;
366+
} else {
367+
offset32 = tsk_malloc(len * sizeof(*offset32));
368+
if (offset32 == NULL) {
373369
ret = TSK_ERR_NO_MEMORY;
374370
goto out;
375371
}
376372
for (j = 0; j < len; j++) {
377-
offset64[j] = col->offset_array[j];
373+
offset32[j] = (uint32_t) col->offset_array[j];
378374
}
379-
type = KAS_UINT64;
380-
data = offset64;
381-
} else {
382375
type = KAS_UINT32;
383-
data = col->offset_array;
376+
data = offset32;
384377
}
385378
ret = kastore_puts(store, offset_col_name, data, len, type, 0);
386379
if (ret != 0) {
387380
ret = tsk_set_kas_error(ret);
388381
goto out;
389382
}
390383
out:
391-
tsk_safe_free(offset64);
384+
tsk_safe_free(offset32);
392385
return ret;
393386
}
394387

docs/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,11 @@ def handle_item(fieldarg, content):
287287
nitpick_ignore = [
288288
("c:identifier", "int32_t"),
289289
("c:identifier", "uint32_t"),
290+
("c:identifier", "uint64_t"),
290291
("c:identifier", "FILE"),
291292
("c:type", "int32_t"),
292293
("c:type", "uint32_t"),
294+
("c:type", "uint64_t"),
293295
("c:type", "bool"),
294296
("py:class", "tskit.metadata.AbstractMetadataCodec"),
295297
("py:class", "tskit.trees.Site"),

0 commit comments

Comments
 (0)