Bump for 3.6-28
[LibreOffice.git] / python / Python-2.6.1-py2422.patch
bloba76e26b2628033ac161e1a60e5c3d28c37114df3
1 http://bugs.python.org/issue2422 - adaption of the patch there to honour our G_SLICE
2 --- misc/Python-2.6.1/Objects/obmalloc.c 2011-07-26 13:10:12.668380720 +0100
3 +++ misc/build/Python-2.6.1/Objects/obmalloc.c 2011-07-26 13:17:41.951444953 +0100
4 @@ -1,7 +1,18 @@
5 #include "Python.h"
6 +#include <stdlib.h>
8 #ifdef WITH_PYMALLOC
10 +static int running_with_system_allocator = -1;
12 +/* If we're using GCC, use __builtin_expect() to reduce overhead of
13 + the allocator checks */
14 +#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
15 +# define UNLIKELY(value) __builtin_expect((value), 0)
16 +#else
17 +# define UNLIKELY(value) (value)
18 +#endif
20 /* An object allocator for Python.
22 Here is an introduction to the layers of the Python memory architecture,
23 @@ -728,6 +739,11 @@
24 poolp next;
25 uint size;
27 + if (UNLIKELY(running_with_system_allocator == -1))
28 + running_with_system_allocator = (getenv("G_SLICE") != NULL);
29 + if (UNLIKELY(running_with_system_allocator))
30 + goto redirect;
33 * Limit ourselves to PY_SSIZE_T_MAX bytes to prevent security holes.
34 * Most python internals blindly use a signed Py_ssize_t to track
35 @@ -927,6 +943,9 @@
36 if (p == NULL) /* free(NULL) has no effect */
37 return;
39 + if (UNLIKELY(running_with_system_allocator > 0))
40 + goto redirect;
42 pool = POOL_ADDR(p);
43 if (Py_ADDRESS_IN_RANGE(p, pool)) {
44 /* We allocated this address. */
45 @@ -1121,6 +1140,7 @@
46 return;
49 +redirect:
50 /* We didn't allocate this address. */
51 free(p);
53 @@ -1150,6 +1170,10 @@
54 if (nbytes > PY_SSIZE_T_MAX)
55 return NULL;
57 + /* Treat running_with_system_allocator == -1 the same as 0 */
58 + if (UNLIKELY(running_with_system_allocator > 0))
59 + goto redirect;
61 pool = POOL_ADDR(p);
62 if (Py_ADDRESS_IN_RANGE(p, pool)) {
63 /* We're in charge of this block */
64 @@ -1177,6 +1201,7 @@
66 return bp;
68 +redirect:
69 /* We're not managing this block. If nbytes <=
70 * SMALL_REQUEST_THRESHOLD, it's tempting to try to take over this
71 * block. However, if we do, we need to copy the valid data from