Skip to content

Commit

Permalink
Fix wrong init return value
Browse files Browse the repository at this point in the history
  • Loading branch information
betatim committed Nov 4, 2016
1 parent c7fb26b commit 240d970
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions khmer/_khmer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,12 @@ khmer_Read_new(PyTypeObject * type, PyObject * args, PyObject * kwds)
khmer_Read_Object * self;
self = (khmer_Read_Object *)type->tp_alloc(type, 0);
if (self != NULL) {
self->read = new Read;
try {
self->read = new Read;
} catch (std::bad_alloc &exc) {
Py_DECREF(self);
return PyErr_NoMemory();
}
}
return (PyObject *)self;
}
Expand All @@ -304,7 +309,7 @@ khmer_Read_init(khmer_Read_Object *self, PyObject *args, PyObject *kwds)

if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|zz", kwlist,
&name, &sequence, &quality, &annotations)) {
return 0;
return -1;
}

if (name != NULL) {
Expand Down
4 changes: 4 additions & 0 deletions tests/test_read_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@

def test_read_type_basic():
# test that basic properties of khmer.Read behave like screed.Record
# Constructing without mandatory arguments should raise an exception
with pytest.raises(TypeError):
Read()

name = "895:1:1:1246:14654 1:N:0:NNNNN"
sequence = "ACGT"
r = Read(name, sequence)
Expand Down

0 comments on commit 240d970

Please sign in to comment.