cext: fix Python 3.11 compatibility - Py_SIZE is not an lvalue (issue6610) stable
authorMads Kiilerich <mads@kiilerich.com>
Thu, 18 Nov 2021 12:31:37 +0100
branchstable
changeset 48330 e35807332598
parent 48328 e74c15bd58ee
child 48331 4713bcf78037
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 .
mercurial/cext/pathencode.c
--- a/mercurial/cext/pathencode.c	Tue Nov 16 16:38:37 2021 +0100
+++ b/mercurial/cext/pathencode.c	Thu Nov 18 12:31:37 2021 +0100
@@ -176,7 +176,7 @@
 
 	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 @@
 
 		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);
 		}