Patchwork [stable] cext: fix Python 3.11 compatibility - Py_SIZE is not an lvalue (issue6610)

login
register
mail settings
Submitter Mads Kiilerich
Date Nov. 18, 2021, 3:49 p.m.
Message ID <9c41494c5dd2fa8816bc.1637250568@xps>
Download mbox | patch
Permalink /patch/50094/
State Accepted
Headers show

Comments

Mads Kiilerich - Nov. 18, 2021, 3:49 p.m.
# HG changeset patch
# User Mads Kiilerich <mads@kiilerich.com>
# Date 1637235097 -3600
#      Thu Nov 18 12:31:37 2021 +0100
# Branch stable
# Node ID 9c41494c5dd2fa8816bc7b70e76b28c4d3941af0
# Parent  6e576e4665f43101ef9bb98b0f5234f85c5db2ea
cext: fix Python 3.11 compatibility - Py_SIZE is not an lvalue (issue6610)

Py_SIZE was made a static inline function during Python 3.10 development, as
described on https://vstinner.github.io/c-api-opaque-structures.html .
e92ca942ddca updated the Mercurial code base accordingly, but somehow missed a
couple of cases introduced long time ago in a8c948ee3668.

The Python change was dropped for 3.10, but is coming back again in 3.11 .
Yuya Nishihara - Nov. 19, 2021, 11:38 a.m.
On Thu, 18 Nov 2021 16:49:28 +0100, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <mads@kiilerich.com>
> # Date 1637235097 -3600
> #      Thu Nov 18 12:31:37 2021 +0100
> # Branch stable
> # Node ID 9c41494c5dd2fa8816bc7b70e76b28c4d3941af0
> # Parent  6e576e4665f43101ef9bb98b0f5234f85c5db2ea
> cext: fix Python 3.11 compatibility - Py_SIZE is not an lvalue (issue6610)

Queued for stable, thanks.

Patch

diff --git a/mercurial/cext/pathencode.c b/mercurial/cext/pathencode.c
--- a/mercurial/cext/pathencode.c
+++ b/mercurial/cext/pathencode.c
@@ -176,7 +176,7 @@  PyObject *encodedir(PyObject *self, PyOb
 
 	if (newobj) {
 		assert(PyBytes_Check(newobj));
-		Py_SIZE(newobj)--;
+		Py_SET_SIZE(newobj, Py_SIZE(newobj) - 1);
 		_encodedir(PyBytes_AS_STRING(newobj), newlen, path, len + 1);
 	}
 
@@ -791,7 +791,7 @@  PyObject *pathencode(PyObject *self, PyO
 
 		if (newobj) {
 			assert(PyBytes_Check(newobj));
-			Py_SIZE(newobj)--;
+			Py_SET_SIZE(newobj, Py_SIZE(newobj) - 1);
 			basicencode(PyBytes_AS_STRING(newobj), newlen, path,
 			            len + 1);
 		}