Skip to content

Commit da22244

Browse files
committed
Don't segfault if a file handle has been closed
1 parent 5a4daa0 commit da22244

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

py2bit.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ PyObject *py2bitEnter(pyTwoBit_t *self, PyObject *args) {
3535
pyTwoBit_t *pytb = self->tb;
3636

3737
if(!pytb) {
38-
PyErr_SetString(PyExc_RuntimeError, "The 2bit file handle is not opened!");
38+
PyErr_SetString(PyExc_RuntimeError, "The 2bit file handle is not open!");
3939
return NULL;
4040
}
4141

@@ -62,6 +62,11 @@ static PyObject *py2bitInfo(pyTwoBit_t *self, PyObject *args) {
6262
PyObject *ret = NULL, *val = NULL;
6363
uint32_t i, j, foo;
6464

65+
if(!tb) {
66+
PyErr_SetString(PyExc_RuntimeError, "The 2bit file handle is not open!");
67+
return NULL;
68+
}
69+
6570
ret = PyDict_New();
6671

6772
//file size
@@ -126,6 +131,11 @@ static PyObject *py2bitChroms(pyTwoBit_t *self, PyObject *args) {
126131
char *chrom = NULL;
127132
uint32_t i;
128133

134+
if(!tb) {
135+
PyErr_SetString(PyExc_RuntimeError, "The 2bit file handle is not open!");
136+
return NULL;
137+
}
138+
129139
if(!(PyArg_ParseTuple(args, "|s", &chrom)) || !chrom) {
130140
ret = PyDict_New();
131141
if(!ret) goto error;
@@ -173,6 +183,11 @@ static PyObject *py2bitSequence(pyTwoBit_t *self, PyObject *args, PyObject *kwds
173183
uint32_t start, end, len;
174184
static char *kwd_list[] = {"chrom", "start", "end", NULL};
175185

186+
if(!tb) {
187+
PyErr_SetString(PyExc_RuntimeError, "The 2bit file handle is not open!");
188+
return NULL;
189+
}
190+
176191
if(!PyArg_ParseTupleAndKeywords(args, kwds, "s|kk", kwd_list, &chrom, &startl, &endl)) {
177192
PyErr_SetString(PyExc_RuntimeError, "You must supply at least a chromosome!");
178193
return NULL;
@@ -217,6 +232,11 @@ static PyObject *py2bitBases(pyTwoBit_t *self, PyObject *args, PyObject *kwds) {
217232
static char *kwd_list[] = {"chrom", "start", "end", "fraction", NULL};
218233
int fraction = 1;
219234

235+
if(!tb) {
236+
PyErr_SetString(PyExc_RuntimeError, "The 2bit file handle is not open!");
237+
return NULL;
238+
}
239+
220240
if(!PyArg_ParseTupleAndKeywords(args, kwds, "s|kkO", kwd_list, &chrom, &startl, &endl, &fractionO)) {
221241
PyErr_SetString(PyExc_RuntimeError, "You must supply at least a chromosome!");
222242
return NULL;

0 commit comments

Comments
 (0)