Mercurial > vim
annotate src/xdiff/xmacros.h @ 33583:123acdc8e64c v9.0.2036
patch 9.0.2036: if_python: rework python3.12 build dependency
Commit: https://github.com/vim/vim/commit/396058acd0cc66e5071d052e03d2067b134952af
Author: Yee Cheng Chin <ychin.git@gmail.com>
Date: Tue Oct 17 10:38:11 2023 +0200
patch 9.0.2036: if_python: rework python3.12 build dependency
Problem: if_python: rework python3.12 build dependency
(after 9.0.1996)
Solution: use PyTuple_Size instead of inlining the Py_SIZE
into the Vim code base
Use a simpler fix for Python 3.12 build issues
Python 3.12 introduced link dependencies to their `Py_SIZE()` inline
function, which #13290 fixed by copying the inline function to Vim's
Python binding code. This works but it's fragile, as a future update may
change the implementation of `Py_SIZE` and there is no way for us to
know.
The reason we need `Py_SIZE` to begin with is that we use
`PyTuple_GET_SIZE()` which calls that. Just fix it by mapping that to
(confusingly similarly named) `PyTuple_Size()`, which we already do in
the stable ABI implementation. There's a minor performance cost in that
it's not inlined and it does error checking but that's fine as we only
call this function rarely (in an error handler).
related: #13290
closes: #13359
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 17 Oct 2023 10:45:04 +0200 |
parents | 9493de63a3f6 |
children | cb88e5c589d0 |
rev | line source |
---|---|
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 * LibXDiff by Davide Libenzi ( File Differential Library ) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3 * Copyright (C) 2003 Davide Libenzi |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4 * |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5 * This library is free software; you can redistribute it and/or |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6 * modify it under the terms of the GNU Lesser General Public |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
7 * License as published by the Free Software Foundation; either |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
8 * version 2.1 of the License, or (at your option) any later version. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
9 * |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
10 * This library is distributed in the hope that it will be useful, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
13 * Lesser General Public License for more details. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
14 * |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU Lesser General Public |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
16 * License along with this library; if not, see |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
17 * <http://www.gnu.org/licenses/>. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
18 * |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
19 * Davide Libenzi <davidel@xmailserver.org> |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
20 * |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
21 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
22 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 #if !defined(XMACROS_H) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
24 #define XMACROS_H |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
25 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
26 |
32178
9493de63a3f6
patch 9.0.1420: build failure because SIZE_MAX is not defined
Bram Moolenaar <Bram@vim.org>
parents:
32174
diff
changeset
|
27 #ifdef __hpux |
9493de63a3f6
patch 9.0.1420: build failure because SIZE_MAX is not defined
Bram Moolenaar <Bram@vim.org>
parents:
32174
diff
changeset
|
28 # ifndef SIZE_MAX |
9493de63a3f6
patch 9.0.1420: build failure because SIZE_MAX is not defined
Bram Moolenaar <Bram@vim.org>
parents:
32174
diff
changeset
|
29 # define SIZE_MAX ((size_t)(-1)) |
9493de63a3f6
patch 9.0.1420: build failure because SIZE_MAX is not defined
Bram Moolenaar <Bram@vim.org>
parents:
32174
diff
changeset
|
30 # endif |
9493de63a3f6
patch 9.0.1420: build failure because SIZE_MAX is not defined
Bram Moolenaar <Bram@vim.org>
parents:
32174
diff
changeset
|
31 #endif |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
32 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
33 #define XDL_MIN(a, b) ((a) < (b) ? (a): (b)) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
34 #define XDL_MAX(a, b) ((a) > (b) ? (a): (b)) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
35 #define XDL_ABS(v) ((v) >= 0 ? (v): -(v)) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
36 #define XDL_ISDIGIT(c) ((c) >= '0' && (c) <= '9') |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
37 #define XDL_ISSPACE(c) (isspace((unsigned char)(c))) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
38 #define XDL_ADDBITS(v,b) ((v) + ((v) >> (b))) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
39 #define XDL_MASKBITS(b) ((1UL << (b)) - 1) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
40 #define XDL_HASHLONG(v,b) (XDL_ADDBITS((unsigned long)(v), b) & XDL_MASKBITS(b)) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
41 #define XDL_LE32_PUT(p, v) \ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
42 do { \ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
43 unsigned char *__p = (unsigned char *) (p); \ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
44 *__p++ = (unsigned char) (v); \ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
45 *__p++ = (unsigned char) ((v) >> 8); \ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
46 *__p++ = (unsigned char) ((v) >> 16); \ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
47 *__p = (unsigned char) ((v) >> 24); \ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
48 } while (0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
49 #define XDL_LE32_GET(p, v) \ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
50 do { \ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
51 unsigned char const *__p = (unsigned char const *) (p); \ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
52 (v) = (unsigned long) __p[0] | ((unsigned long) __p[1]) << 8 | \ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
53 ((unsigned long) __p[2]) << 16 | ((unsigned long) __p[3]) << 24; \ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
54 } while (0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
55 |
32174
f84e5db372ea
patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
56 /* Allocate an array of nr elements, returns NULL on failure */ |
f84e5db372ea
patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
57 #define XDL_ALLOC_ARRAY(p, nr) \ |
f84e5db372ea
patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
58 ((p) = SIZE_MAX / sizeof(*(p)) >= (size_t)(nr) \ |
f84e5db372ea
patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
59 ? xdl_malloc((nr) * sizeof(*(p))) \ |
f84e5db372ea
patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
60 : NULL) |
f84e5db372ea
patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
61 |
f84e5db372ea
patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
62 /* Allocate an array of nr zeroed out elements, returns NULL on failure */ |
f84e5db372ea
patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
63 #define XDL_CALLOC_ARRAY(p, nr) ((p) = xdl_calloc(nr, sizeof(*(p)))) |
f84e5db372ea
patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
64 |
f84e5db372ea
patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
65 /* |
f84e5db372ea
patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
66 * Ensure array p can accommodate at least nr elements, growing the |
f84e5db372ea
patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
67 * array and updating alloc (which is the number of allocated |
f84e5db372ea
patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
68 * elements) as necessary. Frees p and returns -1 on failure, returns |
f84e5db372ea
patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
69 * 0 on success |
f84e5db372ea
patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
70 */ |
f84e5db372ea
patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
71 #define XDL_ALLOC_GROW(p, nr, alloc) \ |
f84e5db372ea
patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
72 (-!((nr) <= (alloc) || \ |
f84e5db372ea
patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents:
25709
diff
changeset
|
73 ((p) = xdl_alloc_grow_helper((p), (nr), &(alloc), sizeof(*(p)))))) |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
74 |
25709
d5142d87f898
patch 8.2.3390: included xdiff code is outdated
Bram Moolenaar <Bram@vim.org>
parents:
18802
diff
changeset
|
75 #endif /* #if !defined(XMACROS_H) */ |