##// END OF EJS Templates
cffi: pass C type and attribute names as str instead of bytes
Manuel Jacob -
r52683:ecc3a893 stable
parent child Browse files
Show More
@@ -21,11 +21,11 b' lib = _bdiff.lib'
21 21
22 22
23 23 def blocks(sa: bytes, sb: bytes) -> List[Tuple[int, int, int, int]]:
24 a = ffi.new(b"struct bdiff_line**")
25 b = ffi.new(b"struct bdiff_line**")
26 ac = ffi.new(b"char[]", str(sa))
27 bc = ffi.new(b"char[]", str(sb))
28 l = ffi.new(b"struct bdiff_hunk*")
24 a = ffi.new("struct bdiff_line**")
25 b = ffi.new("struct bdiff_line**")
26 ac = ffi.new("char[]", str(sa))
27 bc = ffi.new("char[]", str(sb))
28 l = ffi.new("struct bdiff_hunk*")
29 29 try:
30 30 an = lib.bdiff_splitlines(ac, len(sa), a)
31 31 bn = lib.bdiff_splitlines(bc, len(sb), b)
@@ -49,11 +49,11 b' def blocks(sa: bytes, sb: bytes) -> List'
49 49
50 50
51 51 def bdiff(sa: bytes, sb: bytes) -> bytes:
52 a = ffi.new(b"struct bdiff_line**")
53 b = ffi.new(b"struct bdiff_line**")
54 ac = ffi.new(b"char[]", str(sa))
55 bc = ffi.new(b"char[]", str(sb))
56 l = ffi.new(b"struct bdiff_hunk*")
52 a = ffi.new("struct bdiff_line**")
53 b = ffi.new("struct bdiff_line**")
54 ac = ffi.new("char[]", str(sa))
55 bc = ffi.new("char[]", str(sb))
56 l = ffi.new("struct bdiff_hunk*")
57 57 try:
58 58 an = lib.bdiff_splitlines(ac, len(sa), a)
59 59 bn = lib.bdiff_splitlines(bc, len(sb), b)
@@ -19,8 +19,8 b' lib = _mpatch.lib'
19 19 @ffi.def_extern()
20 20 def cffi_get_next_item(arg, pos):
21 21 all, bins = ffi.from_handle(arg)
22 container = ffi.new(b"struct mpatch_flist*[1]")
23 to_pass = ffi.new(b"char[]", str(bins[pos]))
22 container = ffi.new("struct mpatch_flist*[1]")
23 to_pass = ffi.new("char[]", str(bins[pos]))
24 24 all.append(to_pass)
25 25 r = lib.mpatch_decode(to_pass, len(to_pass) - 1, container)
26 26 if r < 0:
@@ -41,7 +41,7 b' def patches(text: bytes, bins: List[byte'
41 41 if outlen < 0:
42 42 lib.mpatch_lfree(patch)
43 43 raise mpatchError(b"inconsistency detected")
44 buf = ffi.new(b"char[]", outlen)
44 buf = ffi.new("char[]", outlen)
45 45 if lib.mpatch_apply(buf, text, len(text), patch) < 0:
46 46 lib.mpatch_lfree(patch)
47 47 raise mpatchError(b"error applying patches")
@@ -39,8 +39,8 b' if pycompat.isdarwin:'
39 39 self.st_mtime = st_mtime
40 40 self.st_size = st_size
41 41
42 tv_sec_ofs = ffi.offsetof(b"struct timespec", b"tv_sec")
43 buf = ffi.new(b"char[]", listdir_batch_size)
42 tv_sec_ofs = ffi.offsetof("struct timespec", "tv_sec")
43 buf = ffi.new("char[]", listdir_batch_size)
44 44
45 45 def listdirinternal(dfd, req, stat, skip):
46 46 ret = []
@@ -50,16 +50,16 b' if pycompat.isdarwin:'
50 50 break
51 51 if r == -1:
52 52 raise OSError(ffi.errno, os.strerror(ffi.errno))
53 cur = ffi.cast(b"val_attrs_t*", buf)
53 cur = ffi.cast("val_attrs_t*", buf)
54 54 for i in range(r):
55 55 lgt = cur.length
56 assert lgt == ffi.cast(b'uint32_t*', cur)[0]
56 assert lgt == ffi.cast('uint32_t*', cur)[0]
57 57 ofs = cur.name_info.attr_dataoffset
58 58 str_lgt = cur.name_info.attr_length
59 base_ofs = ffi.offsetof(b'val_attrs_t', b'name_info')
59 base_ofs = ffi.offsetof('val_attrs_t', 'name_info')
60 60 name = bytes(
61 61 ffi.buffer(
62 ffi.cast(b"char*", cur) + base_ofs + ofs, str_lgt - 1
62 ffi.cast("char*", cur) + base_ofs + ofs, str_lgt - 1
63 63 )
64 64 )
65 65 tp = attrkinds[cur.obj_type]
@@ -84,12 +84,12 b' if pycompat.isdarwin:'
84 84 else:
85 85 ret.append((name, tp))
86 86 cur = ffi.cast(
87 b"val_attrs_t*", int(ffi.cast(b"intptr_t", cur)) + lgt
87 "val_attrs_t*", int(ffi.cast("intptr_t", cur)) + lgt
88 88 )
89 89 return ret
90 90
91 91 def listdir(path, stat=False, skip=None):
92 req = ffi.new(b"struct attrlist*")
92 req = ffi.new("struct attrlist*")
93 93 req.bitmapcount = lib.ATTR_BIT_MAP_COUNT
94 94 req.commonattr = (
95 95 lib.ATTR_CMN_RETURNED_ATTRS
General Comments 0
You need to be logged in to leave comments. Login now