mercurial/cffi/mpatchbuild.py
author Augie Fackler <augie@google.com>
Fri, 25 Mar 2022 11:33:12 -0400
changeset 49062 533820f5b997
parent 48966 6000f5b25c9b
child 51901 f4733654f144
permissions -rw-r--r--
merge: with stable
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29875
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
     1
import cffi
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
     2
import os
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
     3
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
     4
ffi = cffi.FFI()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36954
diff changeset
     5
mpatch_c = os.path.join(
43432
53607fd3ec6c cffi: fix build on Python 3
Manuel Jacob <me@manueljacob.de>
parents: 43077
diff changeset
     6
    os.path.join(os.path.dirname(__file__), '..', 'mpatch.c')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36954
diff changeset
     7
)
36954
0585337ea787 cleanup: fix some latent open(path).read() et al calls we previously missed
Augie Fackler <augie@google.com>
parents: 32539
diff changeset
     8
with open(mpatch_c) as f:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36954
diff changeset
     9
    ffi.set_source(
43432
53607fd3ec6c cffi: fix build on Python 3
Manuel Jacob <me@manueljacob.de>
parents: 43077
diff changeset
    10
        "mercurial.cffi._mpatch", f.read(), include_dirs=["mercurial"]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36954
diff changeset
    11
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36954
diff changeset
    12
ffi.cdef(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36954
diff changeset
    13
    """
29875
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    14
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    15
struct mpatch_frag {
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    16
       int start, end, len;
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    17
       const char *data;
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    18
};
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    19
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    20
struct mpatch_flist {
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    21
       struct mpatch_frag *base, *head, *tail;
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    22
};
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    23
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    24
extern "Python" struct mpatch_flist* cffi_get_next_item(void*, ssize_t);
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    25
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    26
int mpatch_decode(const char *bin, ssize_t len, struct mpatch_flist** res);
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    27
ssize_t mpatch_calcsize(size_t len, struct mpatch_flist *l);
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    28
void mpatch_lfree(struct mpatch_flist *a);
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    29
static int mpatch_apply(char *buf, const char *orig, size_t len,
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    30
                        struct mpatch_flist *l);
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    31
struct mpatch_flist *mpatch_fold(void *bins,
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    32
                       struct mpatch_flist* (*get_next_item)(void*, ssize_t),
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    33
                       ssize_t start, ssize_t end);
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36954
diff changeset
    34
"""
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36954
diff changeset
    35
)
29875
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    36
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    37
if __name__ == '__main__':
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    38
    ffi.compile()