cext: use modern buffer protocol in mpatch_flist()
authorGregory Szorc <gregory.szorc@gmail.com>
Tue, 02 Oct 2018 13:12:56 -0700
changeset 39992 ec3c06a1c554
parent 39991 77492c10a35b
child 39993 cd5f2e615262
cext: use modern buffer protocol in mpatch_flist() Differential Revision: https://phab.mercurial-scm.org/D4841
mercurial/cext/mpatch.c
--- a/mercurial/cext/mpatch.c	Tue Oct 02 13:13:03 2018 -0700
+++ b/mercurial/cext/mpatch.c	Tue Oct 02 13:12:56 2018 -0700
@@ -50,21 +50,22 @@
 
 struct mpatch_flist *cpygetitem(void *bins, ssize_t pos)
 {
-	const char *buffer;
-	struct mpatch_flist *res;
-	ssize_t blen;
+	Py_buffer buffer;
+	struct mpatch_flist *res = NULL;
 	int r;
 
 	PyObject *tmp = PyList_GetItem((PyObject *)bins, pos);
 	if (!tmp)
 		return NULL;
-	if (PyObject_AsCharBuffer(tmp, &buffer, (Py_ssize_t *)&blen))
+	if (PyObject_GetBuffer(tmp, &buffer, PyBUF_CONTIG_RO))
 		return NULL;
-	if ((r = mpatch_decode(buffer, blen, &res)) < 0) {
+	if ((r = mpatch_decode(buffer.buf, buffer.len, &res)) < 0) {
 		if (!PyErr_Occurred())
 			setpyerr(r);
-		return NULL;
+		res = NULL;
 	}
+
+	PyBuffer_Release(&buffer);
 	return res;
 }