Skip to content

Commit a931714

Browse files
Will-Tylerjeromekelleher
authored andcommitted
Revert "Push variant-wise for-loop to C extension"
This reverts commit b73b02a.
1 parent 08b042d commit a931714

File tree

2 files changed

+13
-56
lines changed

2 files changed

+13
-56
lines changed

vcztools/_vcztoolsmodule.c

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -476,57 +476,6 @@ VcfEncoder_encode(VcfEncoder *self, PyObject *args)
476476
return ret;
477477
}
478478

479-
static PyObject *
480-
VcfEncoder_encode_all(VcfEncoder *self, PyObject *args)
481-
{
482-
bool allowed_threads = false;
483-
484-
if (VcfEncoder_check_state(self) != 0) {
485-
goto out;
486-
}
487-
488-
Py_BEGIN_ALLOW_THREADS
489-
allowed_threads = true;
490-
const size_t num_variants = self->vcf_encoder->num_variants;
491-
size_t bufsize = 1024;
492-
493-
for (size_t row = 0; row < num_variants; row++) {
494-
while (true) {
495-
char* const buf = PyMem_RawMalloc(bufsize);
496-
497-
if (buf == NULL) {
498-
PyErr_NoMemory();
499-
goto out;
500-
}
501-
502-
const int64_t line_length = vcz_variant_encoder_encode(
503-
self->vcf_encoder, row, buf, bufsize);
504-
505-
if (line_length < 0) {
506-
PyMem_RawFree(buf);
507-
508-
if (line_length == VCZ_ERR_BUFFER_OVERFLOW) {
509-
bufsize *= 2;
510-
} else {
511-
handle_library_error((int) line_length);
512-
goto out;
513-
}
514-
} else {
515-
puts(buf);
516-
PyMem_RawFree(buf);
517-
break;
518-
} // if (line_length < 0)
519-
} // while (true)
520-
}
521-
522-
out:
523-
if (allowed_threads) {
524-
Py_END_ALLOW_THREADS
525-
}
526-
527-
Py_RETURN_NONE;
528-
}
529-
530479
static PyObject *
531480
VcfEncoder_print_state(VcfEncoder *self, PyObject *args)
532481
{
@@ -597,10 +546,6 @@ static PyMethodDef VcfEncoder_methods[] = {
597546
.ml_meth = (PyCFunction) VcfEncoder_encode,
598547
.ml_flags = METH_VARARGS,
599548
.ml_doc = "Return the specified row of VCF text" },
600-
{ .ml_name = "encode_all",
601-
.ml_meth = (PyCFunction) VcfEncoder_encode_all,
602-
.ml_flags = METH_VARARGS,
603-
.ml_doc = "Print all rows of VCF text" },
604549
{ NULL } /* Sentinel */
605550
};
606551

vcztools/vcf_writer.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,19 @@ def c_chunk_to_vcf(
415415
if preceding_future:
416416
concurrent.futures.wait((preceding_future,))
417417

418-
encoder.encode_all()
418+
# TODO: (1) make a guess at this based on number of fields and samples,
419+
# and (2) log a DEBUG message when we have to double.
420+
buflen = 1024
421+
for j in range(num_variants):
422+
failed = True
423+
while failed:
424+
try:
425+
line = encoder.encode(j, buflen)
426+
failed = False
427+
except _vcztools.VczBufferTooSmall:
428+
buflen *= 2
429+
# print("Bumping buflen to", buflen)
430+
print(line, file=output)
419431

420432

421433
def _generate_header(ds, original_header, sample_ids, *, no_version: bool = False):

0 commit comments

Comments
 (0)