comparison mercurial/cffi/mpatch.py @ 51786:ecc3a893979d stable

cffi: pass C type and attribute names as str instead of bytes
author Manuel Jacob <me@manueljacob.de>
date Mon, 05 Aug 2024 21:08:36 +0200
parents 94a797032fc4
children 472699b5ddb3
comparison
equal deleted inserted replaced
51785:99632adff795 51786:ecc3a893979d
17 17
18 18
19 @ffi.def_extern() 19 @ffi.def_extern()
20 def cffi_get_next_item(arg, pos): 20 def cffi_get_next_item(arg, pos):
21 all, bins = ffi.from_handle(arg) 21 all, bins = ffi.from_handle(arg)
22 container = ffi.new(b"struct mpatch_flist*[1]") 22 container = ffi.new("struct mpatch_flist*[1]")
23 to_pass = ffi.new(b"char[]", str(bins[pos])) 23 to_pass = ffi.new("char[]", str(bins[pos]))
24 all.append(to_pass) 24 all.append(to_pass)
25 r = lib.mpatch_decode(to_pass, len(to_pass) - 1, container) 25 r = lib.mpatch_decode(to_pass, len(to_pass) - 1, container)
26 if r < 0: 26 if r < 0:
27 return ffi.NULL 27 return ffi.NULL
28 return container[0] 28 return container[0]
39 raise mpatchError(b"cannot decode chunk") 39 raise mpatchError(b"cannot decode chunk")
40 outlen = lib.mpatch_calcsize(len(text), patch) 40 outlen = lib.mpatch_calcsize(len(text), patch)
41 if outlen < 0: 41 if outlen < 0:
42 lib.mpatch_lfree(patch) 42 lib.mpatch_lfree(patch)
43 raise mpatchError(b"inconsistency detected") 43 raise mpatchError(b"inconsistency detected")
44 buf = ffi.new(b"char[]", outlen) 44 buf = ffi.new("char[]", outlen)
45 if lib.mpatch_apply(buf, text, len(text), patch) < 0: 45 if lib.mpatch_apply(buf, text, len(text), patch) < 0:
46 lib.mpatch_lfree(patch) 46 lib.mpatch_lfree(patch)
47 raise mpatchError(b"error applying patches") 47 raise mpatchError(b"error applying patches")
48 res = ffi.buffer(buf, outlen)[:] 48 res = ffi.buffer(buf, outlen)[:]
49 lib.mpatch_lfree(patch) 49 lib.mpatch_lfree(patch)