[PATCH 3 of 3 STABLE] rust: propagate Python exception raised from index_get_parents_checked()

Yuya Nishihara yuya at tcha.org
Sun Oct 28 09:11:03 EDT 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1540730473 -32400
#      Sun Oct 28 21:41:13 2018 +0900
# Branch stable
# Node ID c40ceec4d993927b6788ad430dc6b4f3087d9aeb
# Parent  28a5ec244ba88ce4a46a26a32c24fa36f7597245
rust: propagate Python exception raised from index_get_parents_checked()

Spotted while testing with a bad stoprev value. The current Rust interface
can't report inner errors.

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -2397,7 +2397,7 @@ static void rustla_dealloc(rustlazyances
 
 static PyObject *rustla_next(rustlazyancestorsObject *self) {
 	int res = rustlazyancestors_next(self->iter);
-	if (res == -1) {
+	if (res == -1 || PyErr_Occurred()) {
 		/* Setting an explicit exception seems unnecessary
 		 * as examples from Python source code (Objects/rangeobjets.c and
 		 * Modules/_io/stringio.c) seem to demonstrate.
@@ -2408,10 +2408,14 @@ static PyObject *rustla_next(rustlazyanc
 }
 
 static int rustla_contains(rustlazyancestorsObject *self, PyObject *rev) {
+	int res;
 	if (!(PyInt_Check(rev))) {
 		return 0;
 	}
-	return rustlazyancestors_contains(self->iter, PyInt_AS_LONG(rev));
+	res = rustlazyancestors_contains(self->iter, PyInt_AS_LONG(rev));
+	if (PyErr_Occurred())
+		return -1;
+	return res;
 }
 
 static PySequenceMethods rustla_sequence_methods = {


More information about the Mercurial-devel mailing list