[PATCH stable] cext: back out ec3c06a1c554 (use modern buffer protocol in mpatch_flist())

Manuel Jacob me at manueljacob.de
Thu May 14 00:10:49 UTC 2020


# HG changeset patch
# User Manuel Jacob <me at manueljacob.de>
# Date 1589415041 -7200
#      Thu May 14 02:10:41 2020 +0200
# Branch stable
# Node ID fdbe20620a267f2cc8fb01b60a293117f00cebdb
# Parent  cf3e07d7648a4371ce584d15dd692e7a6845792f
cext: back out ec3c06a1c554 (use modern buffer protocol in mpatch_flist())

On old Python versions (prior to 2.7.4), old-style 'buffer' objects were not
recognized by the new-style buffer API. See https://bugs.python.org/issue10211
for details.

Since old-style buffers are deprecated on Python 3 and the Python version that
fixes this issue was released over 7 years ago, I'm not actually proposing
that this patch should be committed. It might still be helpful for people
compiling Mercurial on very old versions of Python.

diff --git a/mercurial/cext/mpatch.c b/mercurial/cext/mpatch.c
--- a/mercurial/cext/mpatch.c
+++ b/mercurial/cext/mpatch.c
@@ -50,25 +50,24 @@
 
 struct mpatch_flist *cpygetitem(void *bins, ssize_t pos)
 {
-	Py_buffer buffer;
-	struct mpatch_flist *res = NULL;
+	const char *buffer;
+	struct mpatch_flist *res;
+	ssize_t blen;
 	int r;
 
 	PyObject *tmp = PyList_GetItem((PyObject *)bins, pos);
 	if (!tmp) {
 		return NULL;
 	}
-	if (PyObject_GetBuffer(tmp, &buffer, PyBUF_CONTIG_RO)) {
+	if (PyObject_AsCharBuffer(tmp, &buffer, (Py_ssize_t *)&blen)) {
 		return NULL;
 	}
-	if ((r = mpatch_decode(buffer.buf, buffer.len, &res)) < 0) {
+	if ((r = mpatch_decode(buffer, blen, &res)) < 0) {
 		if (!PyErr_Occurred()) {
 			setpyerr(r);
 		}
-		res = NULL;
+		return NULL;
 	}
-
-	PyBuffer_Release(&buffer);
 	return res;
 }
 



More information about the Mercurial-devel mailing list