Skip to content

Commit f5609dc

Browse files
authored
Merge branch 'main' into docs-mimetypes-example
2 parents 4a6dd21 + 83ea621 commit f5609dc

14 files changed

Lines changed: 90 additions & 43 deletions

File tree

‎Include/internal/mimalloc/mimalloc.h‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ terms of the MIT license. A copy of the license can be found in the file
1515
// ------------------------------------------------------
1616

1717
#ifdef __cplusplus
18-
#if (__cplusplus >= 201103L) || (_MSC_VER > 1900) // C++11
18+
#if (__cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER > 1900) // C++11
1919
#define mi_attr_noexcept noexcept
2020
#else
2121
#define mi_attr_noexcept throw()
@@ -30,7 +30,7 @@ terms of the MIT license. A copy of the license can be found in the file
3030
#define mi_decl_nodiscard __attribute__((warn_unused_result))
3131
#elif defined(_HAS_NODISCARD)
3232
#define mi_decl_nodiscard _NODISCARD
33-
#elif (_MSC_VER >= 1700)
33+
#elif defined(_MSC_VER) && (_MSC_VER >= 1700)
3434
#define mi_decl_nodiscard _Check_return_
3535
#else
3636
#define mi_decl_nodiscard
@@ -513,7 +513,7 @@ mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_heap_alloc_new_n(mi_h
513513

514514
#include <cstddef> // std::size_t
515515
#include <cstdint> // PTRDIFF_MAX
516-
#if (__cplusplus >= 201103L) || (_MSC_VER > 1900) // C++11
516+
#if (__cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER > 1900) // C++11
517517
#include <type_traits> // std::true_type
518518
#include <utility> // std::forward
519519
#endif
@@ -527,7 +527,7 @@ template<class T> struct _mi_stl_allocator_common {
527527
typedef value_type* pointer;
528528
typedef value_type const* const_pointer;
529529

530-
#if ((__cplusplus >= 201103L) || (_MSC_VER > 1900)) // C++11
530+
#if ((__cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER > 1900)) // C++11
531531
using propagate_on_container_copy_assignment = std::true_type;
532532
using propagate_on_container_move_assignment = std::true_type;
533533
using propagate_on_container_swap = std::true_type;
@@ -562,7 +562,7 @@ template<class T> struct mi_stl_allocator : public _mi_stl_allocator_common<T> {
562562
mi_decl_nodiscard pointer allocate(size_type count, const void* = 0) { return static_cast<pointer>(mi_new_n(count, sizeof(value_type))); }
563563
#endif
564564

565-
#if ((__cplusplus >= 201103L) || (_MSC_VER > 1900)) // C++11
565+
#if ((__cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER > 1900)) // C++11
566566
using is_always_equal = std::true_type;
567567
#endif
568568
};
@@ -571,7 +571,7 @@ template<class T1,class T2> bool operator==(const mi_stl_allocator<T1>& , const
571571
template<class T1,class T2> bool operator!=(const mi_stl_allocator<T1>& , const mi_stl_allocator<T2>& ) mi_attr_noexcept { return false; }
572572

573573

574-
#if (__cplusplus >= 201103L) || (_MSC_VER >= 1900) // C++11
574+
#if (__cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1900) // C++11
575575
#define MI_HAS_HEAP_STL_ALLOCATOR 1
576576

577577
#include <memory> // std::shared_ptr
@@ -591,7 +591,7 @@ template<class T, bool _mi_destroy> struct _mi_heap_stl_allocator_common : publi
591591
mi_decl_nodiscard pointer allocate(size_type count, const void* = 0) { return static_cast<pointer>(mi_heap_alloc_new_n(this->heap.get(), count, sizeof(value_type))); }
592592
#endif
593593

594-
#if ((__cplusplus >= 201103L) || (_MSC_VER > 1900)) // C++11
594+
#if ((__cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER > 1900)) // C++11
595595
using is_always_equal = std::false_type;
596596
#endif
597597

‎Include/internal/mimalloc/mimalloc/atomic.h‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ terms of the MIT license. A copy of the license can be found in the file
1414
#define WIN32_LEAN_AND_MEAN
1515
#endif
1616
#include <windows.h>
17-
#elif !defined(__wasi__) && (!defined(__EMSCRIPTEN__) || defined(__EMSCRIPTEN_PTHREADS__))
18-
#define MI_USE_PTHREADS
17+
#endif
18+
#if !defined(MI_USE_PTHREADS)
19+
#if !defined(_WIN32) && !defined(__wasi__) && (!defined(__EMSCRIPTEN__) || defined(__EMSCRIPTEN_PTHREADS__))
20+
#define MI_USE_PTHREADS 1
21+
#else
22+
#define MI_USE_PTHREADS 0
23+
#endif
24+
#endif
25+
#if MI_USE_PTHREADS
1926
#include <pthread.h>
2027
#endif
2128

@@ -511,7 +518,7 @@ static inline void mi_atomic_yield_sleep( size_t* ticks, const size_t ticks_unti
511518
// These should be light-weight in-process only locks.
512519
// Only used for reserving arena's and to maintain the abandoned list.
513520
// ----------------------------------------------------------------------
514-
#if _MSC_VER
521+
#if defined(_MSC_VER)
515522
#pragma warning(disable:26110) // unlock with holding lock
516523
#endif
517524

@@ -543,7 +550,7 @@ static inline void mi_lock_done(mi_lock_t* lock) {
543550
(void)(lock);
544551
}
545552

546-
#elif defined(MI_USE_PTHREADS)
553+
#elif MI_USE_PTHREADS
547554

548555
#include <string.h> // memcpy
549556
void _mi_error_message(int err, const char* fmt, ...);

‎Include/internal/mimalloc/mimalloc/internal.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ void _mi_segment_page_abandon(mi_page_t* page, mi_segments_tld_t* tld);
236236
bool _mi_segment_try_reclaim_abandoned( mi_heap_t* heap, bool try_all, mi_segments_tld_t* tld);
237237
void _mi_segment_collect(mi_segment_t* segment, bool force);
238238

239-
#if MI_HUGE_PAGE_ABANDON
239+
#if defined(MI_HUGE_PAGE_ABANDON) && MI_HUGE_PAGE_ABANDON
240240
void _mi_segment_huge_page_free(mi_segment_t* segment, mi_page_t* page, mi_block_t* block);
241241
#else
242242
void _mi_segment_huge_page_reset(mi_segment_t* segment, mi_page_t* page, mi_block_t* block);

‎Include/internal/mimalloc/mimalloc/prim.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ static inline void* mi_prim_tls_slot(size_t slot) mi_attr_noexcept {
183183
__asm__ volatile ("mv %0, tp" : "=r" (tcb));
184184
res = tcb[slot];
185185
#elif defined(__APPLE__) && defined(__POWERPC__) // ppc, issue #781
186+
#if !MI_USE_PTHREADS
187+
#error PowerPC TLS slots require MI_USE_PTHREADS
188+
#endif
186189
MI_UNUSED(ofs);
187190
res = pthread_getspecific(slot);
188191
#endif
@@ -405,6 +408,10 @@ static inline mi_heap_t* mi_prim_get_default_heap(void) {
405408

406409
#elif defined(MI_TLS_PTHREAD_SLOT_OFS)
407410

411+
#if !MI_USE_PTHREADS
412+
#error MI_TLS_PTHREAD_SLOT_OFS requires MI_USE_PTHREADS
413+
#endif
414+
408415
static inline mi_heap_t** mi_prim_tls_pthread_heap_slot(void) {
409416
pthread_t self = pthread_self();
410417
#if defined(__DragonFly__)
@@ -423,6 +430,10 @@ static inline mi_heap_t* mi_prim_get_default_heap(void) {
423430

424431
#elif defined(MI_TLS_PTHREAD)
425432

433+
#if !MI_USE_PTHREADS
434+
#error MI_TLS_PTHREAD requires MI_USE_PTHREADS
435+
#endif
436+
426437
extern mi_decl_hidden pthread_key_t _mi_heap_default_key;
427438
static inline mi_heap_t* mi_prim_get_default_heap(void) {
428439
mi_heap_t* heap = (mi_unlikely(_mi_heap_default_key == (pthread_key_t)(-1)) ? _mi_heap_main_get() : (mi_heap_t*)pthread_getspecific(_mi_heap_default_key));

‎Include/internal/mimalloc/mimalloc/track.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ defined, undefined, or not accessible at all:
4343
4444
-------------------------------------------------------------------------------------------------------*/
4545

46-
#if MI_TRACK_VALGRIND
46+
#if defined(MI_TRACK_VALGRIND) && MI_TRACK_VALGRIND
4747
// valgrind tool
4848

4949
#define MI_TRACK_ENABLED 1
@@ -60,7 +60,7 @@ defined, undefined, or not accessible at all:
6060
#define mi_track_mem_undefined(p,size) VALGRIND_MAKE_MEM_UNDEFINED(p,size)
6161
#define mi_track_mem_noaccess(p,size) VALGRIND_MAKE_MEM_NOACCESS(p,size)
6262

63-
#elif MI_TRACK_ASAN
63+
#elif defined(MI_TRACK_ASAN) && MI_TRACK_ASAN
6464
// address sanitizer
6565

6666
#define MI_TRACK_ENABLED 1
@@ -75,7 +75,7 @@ defined, undefined, or not accessible at all:
7575
#define mi_track_mem_undefined(p,size) ASAN_UNPOISON_MEMORY_REGION(p,size)
7676
#define mi_track_mem_noaccess(p,size) ASAN_POISON_MEMORY_REGION(p,size)
7777

78-
#elif MI_TRACK_ETW
78+
#elif defined(MI_TRACK_ETW) && MI_TRACK_ETW
7979
// windows event tracing
8080

8181
#define MI_TRACK_ENABLED 1

‎Include/internal/mimalloc/mimalloc/types.h‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ terms of the MIT license. A copy of the license can be found in the file
2626
#include <stddef.h> // ptrdiff_t
2727
#include <stdint.h> // uintptr_t, uint16_t, etc
2828
#include <stdbool.h> // bool
29+
#include <limits.h> // LONG_MAX
2930
#include "atomic.h" // _Atomic
3031

3132
#ifdef _MSC_VER
@@ -83,9 +84,12 @@ terms of the MIT license. A copy of the license can be found in the file
8384

8485
// Reserve extra padding at the end of each block to be more resilient against heap block overflows.
8586
// The padding can detect buffer overflow on free.
86-
#if !defined(MI_PADDING) && (MI_SECURE>=3 || MI_DEBUG>=1 || (MI_TRACK_VALGRIND || MI_TRACK_ASAN || MI_TRACK_ETW))
87+
#if !defined(MI_PADDING) && (MI_SECURE>=3 || MI_DEBUG>=1 || (defined(MI_TRACK_VALGRIND) && MI_TRACK_VALGRIND) || (defined(MI_TRACK_ASAN) && MI_TRACK_ASAN) || (defined(MI_TRACK_ETW) && MI_TRACK_ETW))
8788
#define MI_PADDING 1
8889
#endif
90+
#if !defined(MI_PADDING)
91+
#define MI_PADDING 0
92+
#endif
8993

9094
// Check padding bytes; allows byte-precise buffer overflow detection
9195
#if !defined(MI_PADDING_CHECK) && MI_PADDING && (MI_SECURE>=3 || MI_DEBUG>=1)
@@ -99,7 +103,7 @@ terms of the MIT license. A copy of the license can be found in the file
99103
#define MI_ENCODE_FREELIST 1
100104
#endif
101105

102-
#if (MI_ENCODE_FREELIST && (MI_SECURE>=4 || MI_DEBUG!=0))
106+
#if defined(MI_ENCODE_FREELIST) && (MI_SECURE>=4 || MI_DEBUG!=0)
103107
#define MI_CHECK_DOUBLE_FREE 1
104108
#endif
105109

@@ -228,7 +232,7 @@ typedef int32_t mi_ssize_t;
228232

229233
// we never allocate more than PTRDIFF_MAX (see also <https://sourceware.org/ml/libc-announce/2019/msg00001.html>)
230234
// on 64-bit+ systems we also limit the maximum allocation size such that the slice count fits in 32-bits. (issue #877)
231-
#if (PTRDIFF_MAX > INT32_MAX) && (PTRDIFF_MAX >= (MI_SEGMENT_SLIZE_SIZE * UINT32_MAX))
235+
#if (PTRDIFF_MAX > INT32_MAX) && (PTRDIFF_MAX >= (MI_SEGMENT_SLICE_SIZE * UINT32_MAX))
232236
#define MI_MAX_ALLOC_SIZE (MI_SEGMENT_SLICE_SIZE * (UINT32_MAX-1))
233237
#else
234238
#define MI_MAX_ALLOC_SIZE PTRDIFF_MAX
@@ -270,7 +274,7 @@ typedef enum mi_delayed_e {
270274

271275
// The `in_full` and `has_aligned` page flags are put in a union to efficiently
272276
// test if both are false (`full_aligned == 0`) in the `mi_free` routine.
273-
#if !MI_TSAN
277+
#if !(defined(MI_TSAN) && MI_TSAN)
274278
typedef union mi_page_flags_s {
275279
uint8_t full_aligned;
276280
struct {
@@ -347,7 +351,7 @@ typedef struct mi_page_s {
347351
size_t block_size; // size available in each block (always `>0`)
348352
uint8_t* page_start; // start of the page area containing the blocks
349353

350-
#if (MI_ENCODE_FREELIST || MI_PADDING)
354+
#if (defined(MI_ENCODE_FREELIST) || MI_PADDING)
351355
uintptr_t keys[2]; // two random keys to encode the free lists (see `_mi_block_next`) or padding canary
352356
#endif
353357

‎Lib/ipaddress.py‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,21 +1954,22 @@ def _explode_shorthand_ip_string(self):
19541954
19551955
"""
19561956
if isinstance(self, IPv6Network):
1957-
ip_str = str(self.network_address)
1958-
elif isinstance(self, IPv6Interface):
1959-
ip_str = str(self.ip)
1957+
ip_int = self.network_address._ip
1958+
scope_id = self.network_address._scope_id
19601959
else:
1961-
ip_str = self._string_from_ip_int(self._ip)
1962-
1963-
ip_int = self._ip_int_from_string(ip_str)
1964-
hex_str = '%032x' % ip_int
1965-
exploded = ':'.join([hex_str[x:x+4] for x in range(0, 32, 4)])
1966-
if isinstance(self, _BaseNetwork):
1967-
return '%s/%d' % (exploded, self._prefixlen)
1968-
if self._scope_id:
1969-
exploded = '%s%%%s' % (exploded, self._scope_id)
1970-
if isinstance(self, IPv6Interface):
1971-
return '%s/%d' % (exploded, self._prefixlen)
1960+
ip_int = self._ip
1961+
scope_id = self._scope_id
1962+
1963+
exploded = (
1964+
f'{ip_int >> 112:04x}:{(ip_int >> 96) & 0xFFFF:04x}:'
1965+
f'{(ip_int >> 80) & 0xFFFF:04x}:{(ip_int >> 64) & 0xFFFF:04x}:'
1966+
f'{(ip_int >> 48) & 0xFFFF:04x}:{(ip_int >> 32) & 0xFFFF:04x}:'
1967+
f'{(ip_int >> 16) & 0xFFFF:04x}:{ip_int & 0xFFFF:04x}'
1968+
)
1969+
if scope_id:
1970+
exploded = f'{exploded}%{scope_id}'
1971+
if isinstance(self, (_BaseNetwork, IPv6Interface)):
1972+
return f'{exploded}/{self._prefixlen}'
19721973
return exploded
19731974

19741975
def _reverse_pointer(self):

‎Lib/test/test_ipaddress.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,6 +2807,10 @@ def testExplodeShortHandIpStr(self):
28072807
ipaddress.IPv6Address('fe80::1%eth0').exploded)
28082808
self.assertEqual('fe80:0000:0000:0000:0000:0000:0000:0001%1/64',
28092809
ipaddress.IPv6Interface('fe80::1%1/64').exploded)
2810+
self.assertEqual('fe80:0000:0000:0000:0000:0000:0000:0000%eth0/64',
2811+
ipaddress.IPv6Network('fe80::%eth0/64').exploded)
2812+
self.assertEqual('fe80:0000:0000:0000:0000:0000:0000:0000%1/64',
2813+
ipaddress.IPv6Network('fe80::%1/64').exploded)
28102814
# issue 77
28112815
self.assertEqual('2001:0000:5ef5:79fd:0000:059d:a0e5:0ba1',
28122816
addr2.exploded)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :attr:`ipaddress.IPv6Network.exploded` for networks with a scope ID and
2+
avoid redundant string round-tripping in ``_BaseV6._explode_shorthand_ip_string()``.

‎Objects/mimalloc/prim/emscripten/prim.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ bool _mi_prim_random_buf(void* buf, size_t buf_len) {
207207
// Thread init/done
208208
//----------------------------------------------------------------
209209

210-
#if defined(MI_USE_PTHREADS)
210+
#if MI_USE_PTHREADS
211211

212212
// use pthread local storage keys to detect thread ending
213213
// (and used with MI_TLS_PTHREADS for the default heap)

0 commit comments

Comments
 (0)