Skip to content

Commit e618218

Browse files
committed
Create tuple in TriContour the same way as QuadContour.
1 parent 608a5db commit e618218

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

src/tri/_tri.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -651,20 +651,22 @@ PyObject* TriContourGenerator::contour_line_to_segs_and_kinds(const Contour& con
651651
PyList_SetItem(codes_list, i, (PyObject*)codes)) {
652652
Py_XDECREF(segs);
653653
Py_XDECREF(codes);
654-
PyErr_SetString(PyExc_RuntimeError,
655-
"Unable to set contour segments and kind codes");
656-
return NULL;
654+
throw std::runtime_error(
655+
"Unable to set contour segments and kind codes");
657656
}
658657
}
659658

660659
PyObject* result = PyTuple_New(2);
661-
if (PyTuple_SetItem(result, 0, (PyObject*)vertices_list) ||
662-
PyTuple_SetItem(result, 1, (PyObject*)codes_list)) {
663-
Py_XDECREF(result);
664-
PyErr_SetString(PyExc_RuntimeError,
665-
"Unable to set contour segments and kind codes");
666-
return NULL;
660+
if (result == 0) {
661+
Py_XDECREF(vertices_list);
662+
Py_XDECREF(codes_list);
663+
throw std::runtime_error("Failed to create Python tuple");
667664
}
665+
666+
// No error checking here as filling in a brand new pre-allocated result.
667+
PyTuple_SET_ITEM(result, 0, vertices_list);
668+
PyTuple_SET_ITEM(result, 1, codes_list);
669+
668670
return result;
669671
}
670672

@@ -730,13 +732,16 @@ PyObject* TriContourGenerator::contour_to_segs_and_kinds(const Contour& contour)
730732
}
731733

732734
PyObject* result = PyTuple_New(2);
733-
if (PyTuple_SetItem(result, 0, (PyObject*)vertices_list) ||
734-
PyTuple_SetItem(result, 1, (PyObject*)codes_list)) {
735-
Py_XDECREF(result);
736-
PyErr_SetString(PyExc_RuntimeError,
737-
"Unable to set contour segments and kinds");
738-
return NULL;
735+
if (result == 0) {
736+
Py_XDECREF(vertices_list);
737+
Py_XDECREF(codes_list);
738+
throw std::runtime_error("Failed to create Python tuple");
739739
}
740+
741+
// No error checking here as filling in a brand new pre-allocated tuple.
742+
PyTuple_SET_ITEM(result, 0, vertices_list);
743+
PyTuple_SET_ITEM(result, 1, codes_list);
744+
740745
return result;
741746
}
742747

0 commit comments

Comments
 (0)