diff mercurial/cffi/mpatch.py @ 51675:472699b5ddb3 stable

cffi: pass bytes instead of str to ffi.new("char[]", ?) The type annotations seem to imply that the passed values are always already bytes, but they aren?t necessarily. Before Python 3.11, the documentation stated that bytes can be used to annotate arguments whose type is actually any of bytes, bytearray, or memoryview.
author Manuel Jacob <me@manueljacob.de>
date Tue, 06 Aug 2024 17:53:59 +0200
parents ecc3a893979d
children f4733654f144
line wrap: on
line diff
--- a/mercurial/cffi/mpatch.py	Mon Aug 05 21:21:32 2024 +0200
+++ b/mercurial/cffi/mpatch.py	Tue Aug 06 17:53:59 2024 +0200
@@ -20,7 +20,7 @@
 def cffi_get_next_item(arg, pos):
     all, bins = ffi.from_handle(arg)
     container = ffi.new("struct mpatch_flist*[1]")
-    to_pass = ffi.new("char[]", str(bins[pos]))
+    to_pass = ffi.new("char[]", bytes(bins[pos]))
     all.append(to_pass)
     r = lib.mpatch_decode(to_pass, len(to_pass) - 1, container)
     if r < 0: