Show More
@@ -21,11 +21,11 b' lib = _bdiff.lib' | |||||
21 |
|
21 | |||
22 |
|
22 | |||
23 | def blocks(sa: bytes, sb: bytes) -> List[Tuple[int, int, int, int]]: |
|
23 | def blocks(sa: bytes, sb: bytes) -> List[Tuple[int, int, int, int]]: | |
24 |
a = ffi.new( |
|
24 | a = ffi.new("struct bdiff_line**") | |
25 |
b = ffi.new( |
|
25 | b = ffi.new("struct bdiff_line**") | |
26 |
ac = ffi.new( |
|
26 | ac = ffi.new("char[]", str(sa)) | |
27 |
bc = ffi.new( |
|
27 | bc = ffi.new("char[]", str(sb)) | |
28 |
l = ffi.new( |
|
28 | l = ffi.new("struct bdiff_hunk*") | |
29 | try: |
|
29 | try: | |
30 | an = lib.bdiff_splitlines(ac, len(sa), a) |
|
30 | an = lib.bdiff_splitlines(ac, len(sa), a) | |
31 | bn = lib.bdiff_splitlines(bc, len(sb), b) |
|
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 | def bdiff(sa: bytes, sb: bytes) -> bytes: |
|
51 | def bdiff(sa: bytes, sb: bytes) -> bytes: | |
52 |
a = ffi.new( |
|
52 | a = ffi.new("struct bdiff_line**") | |
53 |
b = ffi.new( |
|
53 | b = ffi.new("struct bdiff_line**") | |
54 |
ac = ffi.new( |
|
54 | ac = ffi.new("char[]", str(sa)) | |
55 |
bc = ffi.new( |
|
55 | bc = ffi.new("char[]", str(sb)) | |
56 |
l = ffi.new( |
|
56 | l = ffi.new("struct bdiff_hunk*") | |
57 | try: |
|
57 | try: | |
58 | an = lib.bdiff_splitlines(ac, len(sa), a) |
|
58 | an = lib.bdiff_splitlines(ac, len(sa), a) | |
59 | bn = lib.bdiff_splitlines(bc, len(sb), b) |
|
59 | bn = lib.bdiff_splitlines(bc, len(sb), b) |
@@ -19,8 +19,8 b' lib = _mpatch.lib' | |||||
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( |
|
22 | container = ffi.new("struct mpatch_flist*[1]") | |
23 |
to_pass = ffi.new( |
|
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: | |
@@ -41,7 +41,7 b' def patches(text: bytes, bins: List[byte' | |||||
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( |
|
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") |
@@ -39,8 +39,8 b' if pycompat.isdarwin:' | |||||
39 | self.st_mtime = st_mtime |
|
39 | self.st_mtime = st_mtime | |
40 | self.st_size = st_size |
|
40 | self.st_size = st_size | |
41 |
|
41 | |||
42 |
tv_sec_ofs = ffi.offsetof( |
|
42 | tv_sec_ofs = ffi.offsetof("struct timespec", "tv_sec") | |
43 |
buf = ffi.new( |
|
43 | buf = ffi.new("char[]", listdir_batch_size) | |
44 |
|
44 | |||
45 | def listdirinternal(dfd, req, stat, skip): |
|
45 | def listdirinternal(dfd, req, stat, skip): | |
46 | ret = [] |
|
46 | ret = [] | |
@@ -50,16 +50,16 b' if pycompat.isdarwin:' | |||||
50 | break |
|
50 | break | |
51 | if r == -1: |
|
51 | if r == -1: | |
52 | raise OSError(ffi.errno, os.strerror(ffi.errno)) |
|
52 | raise OSError(ffi.errno, os.strerror(ffi.errno)) | |
53 |
cur = ffi.cast( |
|
53 | cur = ffi.cast("val_attrs_t*", buf) | |
54 | for i in range(r): |
|
54 | for i in range(r): | |
55 | lgt = cur.length |
|
55 | lgt = cur.length | |
56 |
assert lgt == ffi.cast( |
|
56 | assert lgt == ffi.cast('uint32_t*', cur)[0] | |
57 | ofs = cur.name_info.attr_dataoffset |
|
57 | ofs = cur.name_info.attr_dataoffset | |
58 | str_lgt = cur.name_info.attr_length |
|
58 | str_lgt = cur.name_info.attr_length | |
59 |
base_ofs = ffi.offsetof( |
|
59 | base_ofs = ffi.offsetof('val_attrs_t', 'name_info') | |
60 | name = bytes( |
|
60 | name = bytes( | |
61 | ffi.buffer( |
|
61 | ffi.buffer( | |
62 |
ffi.cast( |
|
62 | ffi.cast("char*", cur) + base_ofs + ofs, str_lgt - 1 | |
63 | ) |
|
63 | ) | |
64 | ) |
|
64 | ) | |
65 | tp = attrkinds[cur.obj_type] |
|
65 | tp = attrkinds[cur.obj_type] | |
@@ -84,12 +84,12 b' if pycompat.isdarwin:' | |||||
84 | else: |
|
84 | else: | |
85 | ret.append((name, tp)) |
|
85 | ret.append((name, tp)) | |
86 | cur = ffi.cast( |
|
86 | cur = ffi.cast( | |
87 |
|
|
87 | "val_attrs_t*", int(ffi.cast("intptr_t", cur)) + lgt | |
88 | ) |
|
88 | ) | |
89 | return ret |
|
89 | return ret | |
90 |
|
90 | |||
91 | def listdir(path, stat=False, skip=None): |
|
91 | def listdir(path, stat=False, skip=None): | |
92 |
req = ffi.new( |
|
92 | req = ffi.new("struct attrlist*") | |
93 | req.bitmapcount = lib.ATTR_BIT_MAP_COUNT |
|
93 | req.bitmapcount = lib.ATTR_BIT_MAP_COUNT | |
94 | req.commonattr = ( |
|
94 | req.commonattr = ( | |
95 | lib.ATTR_CMN_RETURNED_ATTRS |
|
95 | lib.ATTR_CMN_RETURNED_ATTRS |
General Comments 0
You need to be logged in to leave comments.
Login now