Skip to content

Commit fef6b0d

Browse files
authored
Merge pull request #1284 from microsoft/dev-main
Release v3.3.2
2 parents b196396 + da23e1a commit fef6b0d

28 files changed

Lines changed: 365 additions & 170 deletions

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ permissions:
99
contents: write
1010

1111
env:
12-
RELEASE: Release v3.3.1
12+
RELEASE: Release v3.3.2
1313
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
1414

1515
name: Release
@@ -19,7 +19,7 @@ jobs:
1919
runs-on: ${{ matrix.os }}
2020
strategy:
2121
matrix:
22-
branch: [v1.9.9,v2.3.1,v3.3.1] # [dev,dev2,dev3]
22+
branch: [v1.9.10,v2.3.2,v3.3.2] # [dev,dev2,dev3]
2323
# we build on the oldest ubuntu version for better binary compatibility.
2424
os: [windows-latest, macOS-latest, macos-15-intel, ubuntu-22.04, ubuntu-22.04-arm]
2525

.github/workflows/stale.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
on:
2+
workflow_dispatch: # allow running the workflow manually
3+
schedule:
4+
- cron: "15 21 * * *" # minute, hour, day (1-31), month (1-12), day of the week (0 - 6 or SUN-SAT)
5+
6+
name: Close inactive issues
7+
jobs:
8+
close-issues:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
issues: write
12+
pull-requests: write
13+
steps:
14+
- uses: actions/stale@v10
15+
with:
16+
days-before-issue-stale: 360
17+
days-before-issue-close: 14
18+
stale-issue-label: "stale"
19+
stale-issue-message: "This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs in the next 14 days. Thank you for your contributions!"
20+
close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale. Please feel free to reopen if this is still an active issue."
21+
days-before-pr-stale: -1
22+
days-before-pr-close: -1
23+
stale-pr-label: "stale"
24+
stale-pr-message: "This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs in the next 14 days. Thank you for your contributions!"
25+
close-pr-message: "This PR was closed because it has been inactive for 14 days since being marked as stale. Please feel free to reopen if you think this PR should still be considered. Thank you again for your help."
26+
operations-per-run: 32
27+
repo-token: ${{ secrets.GITHUB_TOKEN }}

cmake/mimalloc-config-version.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
set(mi_version_major 2)
22
set(mi_version_minor 3)
3-
set(mi_version_patch 1)
3+
set(mi_version_patch 2)
44
set(mi_version ${mi_version_major}.${mi_version_minor})
55

66
set(PACKAGE_VERSION ${mi_version})

contrib/vcpkg/portfile.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ vcpkg_from_github(
33
REPO microsoft/mimalloc
44
HEAD_REF master
55

6-
# The "REF" can be a commit hash, branch name (dev3), or a version (v3.3.1).
6+
# The "REF" can be a commit hash, branch name (dev3), or a version (v3.3.2).
77
REF "v${VERSION}"
88
# REF e2db21e9ba9fb9172b7b0aa0fe9b8742525e8774
99

contrib/vcpkg/vcpkg.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mimalloc",
3-
"version": "3.3.0",
3+
"version": "3.3.2",
44
"port-version": 0,
55
"description": "Compact general purpose allocator with excellent performance",
66
"homepage": "https://github.com/microsoft/mimalloc",

doc/release-notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ Notes:
1010
- Generally it is recommended to download sources (or use `vcpkg` etc.) and build mimalloc as
1111
part of your project.
1212
- Source releases can also be downloaded directly from github by the tag.
13-
For example <https://github.com/microsoft/mimalloc/archive/v3.3.0.tar.gz>.
13+
For example <https://github.com/microsoft/mimalloc/archive/v3.3.2.tar.gz>.
1414
- Binary releases include a release-, debug-, and secure build.
1515
- Linux binaries are built on Ubuntu 22.

include/mimalloc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ terms of the MIT license. A copy of the license can be found in the file
88
#ifndef MIMALLOC_H
99
#define MIMALLOC_H
1010

11-
#define MI_MALLOC_VERSION 20301 // major + 2 digits minor + 2 digits patch
11+
#define MI_MALLOC_VERSION 20302 // major + 2 digits minor + 2 digits patch
1212

1313
// ------------------------------------------------------
1414
// Compiler specific attributes
@@ -380,7 +380,7 @@ typedef mi_heap_t mi_theap_t;
380380
#define mi_theap_collect(hp,force) mi_heap_collect(hp,force)
381381
#define mi_theap_malloc(hp,sz) mi_heap_malloc(hp,sz)
382382
#define mi_theap_zalloc(hp,sz) mi_heap_zalloc(hp,sz)
383-
#define mi_theap_calloc(hp,cnt,sz) mi_heap_malloc(hp,cnt,sz)
383+
#define mi_theap_calloc(hp,cnt,sz) mi_heap_calloc(hp,cnt,sz)
384384
#define mi_theap_malloc_small(hp,sz) mi_heap_malloc_small(hp,sz)
385385
#define mi_theap_malloc_aligned(hp,sz,a) mi_heap_malloc_aligned(hp,sz,a)
386386
#define mi_theap_realloc(hp,p,newsz) mi_heap_realloc(hp,p,newsz)

include/mimalloc/atomic.h

Lines changed: 105 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,17 @@ static inline void mi_atomic_maxi64_relaxed(volatile int64_t* p, int64_t x) {
155155
#elif defined(_MSC_VER)
156156

157157
// Deprecated: MSVC plain C compilation wrapper that uses Interlocked operations to model C11 atomics.
158-
// It is recommended to always compile as C++ when using MSVC
158+
// It is recommended to always compile as C++ when using MSVC.
159159

160160
#include <intrin.h>
161161
#ifdef _WIN64
162-
typedef LONG64 msc_intptr_t;
163-
#define MI_64(f) f##64
162+
typedef LONG64 msc_intptr_t;
163+
#define MI_MSC_64(f) f##64
164+
#define MI_MSC_XX(f) f##64
164165
#else
165-
typedef LONG msc_intptr_t;
166-
#define MI_64(f) f
166+
typedef LONG msc_intptr_t;
167+
#define MI_MSC_64(f) f
168+
#define MI_MSC_XX(f) f##32
167169
#endif
168170

169171
typedef enum mi_memory_order_e {
@@ -177,23 +179,23 @@ typedef enum mi_memory_order_e {
177179

178180
static inline uintptr_t mi_atomic_fetch_add_explicit(_Atomic(uintptr_t)*p, uintptr_t add, mi_memory_order mo) {
179181
(void)(mo);
180-
return (uintptr_t)MI_64(_InterlockedExchangeAdd)((volatile msc_intptr_t*)p, (msc_intptr_t)add);
182+
return (uintptr_t)MI_MSC_64(_InterlockedExchangeAdd)((volatile msc_intptr_t*)p, (msc_intptr_t)add);
181183
}
182184
static inline uintptr_t mi_atomic_fetch_sub_explicit(_Atomic(uintptr_t)*p, uintptr_t sub, mi_memory_order mo) {
183185
(void)(mo);
184-
return (uintptr_t)MI_64(_InterlockedExchangeAdd)((volatile msc_intptr_t*)p, -((msc_intptr_t)sub));
186+
return (uintptr_t)MI_MSC_64(_InterlockedExchangeAdd)((volatile msc_intptr_t*)p, -((msc_intptr_t)sub));
185187
}
186188
static inline uintptr_t mi_atomic_fetch_and_explicit(_Atomic(uintptr_t)*p, uintptr_t x, mi_memory_order mo) {
187189
(void)(mo);
188-
return (uintptr_t)MI_64(_InterlockedAnd)((volatile msc_intptr_t*)p, (msc_intptr_t)x);
190+
return (uintptr_t)MI_MSC_64(_InterlockedAnd)((volatile msc_intptr_t*)p, (msc_intptr_t)x);
189191
}
190192
static inline uintptr_t mi_atomic_fetch_or_explicit(_Atomic(uintptr_t)*p, uintptr_t x, mi_memory_order mo) {
191193
(void)(mo);
192-
return (uintptr_t)MI_64(_InterlockedOr)((volatile msc_intptr_t*)p, (msc_intptr_t)x);
194+
return (uintptr_t)MI_MSC_64(_InterlockedOr)((volatile msc_intptr_t*)p, (msc_intptr_t)x);
193195
}
194196
static inline bool mi_atomic_compare_exchange_strong_explicit(_Atomic(uintptr_t)*p, uintptr_t* expected, uintptr_t desired, mi_memory_order mo1, mi_memory_order mo2) {
195197
(void)(mo1); (void)(mo2);
196-
uintptr_t read = (uintptr_t)MI_64(_InterlockedCompareExchange)((volatile msc_intptr_t*)p, (msc_intptr_t)desired, (msc_intptr_t)(*expected));
198+
const uintptr_t read = (uintptr_t)MI_MSC_64(_InterlockedCompareExchange)((volatile msc_intptr_t*)p, (msc_intptr_t)desired, (msc_intptr_t)(*expected));
197199
if (read == *expected) {
198200
return true;
199201
}
@@ -207,68 +209,119 @@ static inline bool mi_atomic_compare_exchange_weak_explicit(_Atomic(uintptr_t)*p
207209
}
208210
static inline uintptr_t mi_atomic_exchange_explicit(_Atomic(uintptr_t)*p, uintptr_t exchange, mi_memory_order mo) {
209211
(void)(mo);
210-
return (uintptr_t)MI_64(_InterlockedExchange)((volatile msc_intptr_t*)p, (msc_intptr_t)exchange);
212+
return (uintptr_t)MI_MSC_64(_InterlockedExchange)((volatile msc_intptr_t*)p, (msc_intptr_t)exchange);
211213
}
212214
static inline void mi_atomic_thread_fence(mi_memory_order mo) {
213215
(void)(mo);
214216
_Atomic(uintptr_t) x = 0;
215217
mi_atomic_exchange_explicit(&x, 1, mo);
216218
}
219+
217220
static inline uintptr_t mi_atomic_load_explicit(_Atomic(uintptr_t) const* p, mi_memory_order mo) {
218221
(void)(mo);
219-
#if defined(_M_IX86) || defined(_M_X64)
220-
return *p;
221-
#else
222-
uintptr_t x = *p;
223-
if (mo > mi_memory_order_relaxed) {
224-
while (!mi_atomic_compare_exchange_weak_explicit((_Atomic(uintptr_t)*)p, &x, x, mo, mi_memory_order_relaxed)) { /* nothing */ };
225-
}
226-
return x;
227-
#endif
222+
// assert(mo<=mi_memory_order_acquire); // others are not used by mimalloc
223+
#if defined(_M_IX86) || defined(_M_X64)
224+
return (uintptr_t)MI_MSC_XX(__iso_volatile_load)((volatile const intptr_t*)p);
225+
#elif defined(_M_ARM) || defined(_M_ARM64)
226+
if (mo == mi_memory_order_relaxed) {
227+
return (uintptr_t)MI_MSC_XX(__iso_volatile_load)((volatile const intptr_t*)p);
228+
}
229+
else if (mo <= mi_memory_order_acquire) {
230+
return MI_MSC_XX(__ldar)((volatile const uintptr_t*)p);
231+
}
232+
else {
233+
const uintptr_t u = (uintptr_t)MI_MSC_XX(__iso_volatile_load)((volatile const intptr_t*)p);
234+
__dmb(15); // _ARM(64)_BARRIER_SY
235+
return u;
236+
}
237+
#else
238+
#warning "define mi_atomic_load_explicit for MSVC C compilation on this platform (which should be readonly, see issue #1277)"
239+
return MI_MSC_XX(__iso_volatile_load)((volatile const intptr_t*)p);
240+
#endif
228241
}
229242
static inline void mi_atomic_store_explicit(_Atomic(uintptr_t)*p, uintptr_t x, mi_memory_order mo) {
230243
(void)(mo);
231-
#if defined(_M_IX86) || defined(_M_X64)
232-
*p = x;
233-
#else
234-
mi_atomic_exchange_explicit(p, x, mo);
235-
#endif
244+
// assert(mo<=mi_memory_order_release); // others are not used by mimalloc
245+
#if defined(_M_IX86) || defined(_M_X64)
246+
MI_MSC_XX(__iso_volatile_store)((volatile intptr_t*)p, x);
247+
#elif defined(_M_ARM) || defined(_M_ARM64)
248+
if (mo == mi_memory_order_relaxed) {
249+
MI_MSC_XX(__iso_volatile_store)((volatile intptr_t*)p, x);
250+
}
251+
else if (mo <= mi_memory_order_release) {
252+
MI_MSC_XX(__stlr)((volatile uintptr_t*)p,x);
253+
}
254+
else {
255+
mi_atomic_exchange_explicit(p, x, mo);
256+
}
257+
#else
258+
mi_atomic_exchange_explicit(p, x, mo);
259+
#endif
236260
}
261+
237262
static inline int64_t mi_atomic_loadi64_explicit(_Atomic(int64_t)*p, mi_memory_order mo) {
238263
(void)(mo);
239-
#if defined(_M_X64)
240-
return *p;
241-
#else
242-
int64_t old = *p;
243-
int64_t x = old;
244-
while ((old = InterlockedCompareExchange64(p, x, old)) != x) {
245-
x = old;
246-
}
247-
return x;
248-
#endif
264+
// assert(mo<=mi_memory_order_acquire); // others are not used by mimalloc
265+
#if defined(_M_IX86) || defined(_M_X64)
266+
return __iso_volatile_load64((volatile const int64_t*)p);
267+
#elif defined(_M_ARM) || defined(_M_ARM64)
268+
if (mo == mi_memory_order_relaxed) {
269+
return __iso_volatile_load64((volatile const int64_t*)p);
270+
}
271+
#if defined(_M_ARM64)
272+
else if (mo <= mi_memory_order_acquire) {
273+
return __ldar64((volatile const uintptr_t*)p);
274+
}
275+
#endif
276+
else {
277+
const int64_t i = __iso_volatile_load64((volatile const int64_t*)p);
278+
__dmb(15); // _ARM(64)_BARRIER_SY
279+
return i;
280+
}
281+
#else
282+
#warning "define mi_atomic_loadi64_explicit for MSVC C compilation on this platform (which should be readonly, see issue #1277)"
283+
return __iso_volatile_load64((volatile const int64_t*)p);
284+
#endif
249285
}
286+
250287
static inline void mi_atomic_storei64_explicit(_Atomic(int64_t)*p, int64_t x, mi_memory_order mo) {
251288
(void)(mo);
252-
#if defined(_M_X64)
253-
*p = x;
254-
#else
255-
InterlockedExchange64(p, x);
256-
#endif
289+
// assert(mo<=mi_memory_order_release); // others are not used by mimalloc
290+
#if defined(_M_IX86) || defined(_M_X64)
291+
__iso_volatile_store64((volatile int64_t*)p,x);
292+
#elif defined(_M_ARM) || defined(_M_ARM64)
293+
if (mo == mi_memory_order_relaxed) {
294+
__iso_volatile_store64((volatile int64_t*)p,x);
295+
}
296+
#if defined(_M_ARM64)
297+
else if (mo == mi_memory_order_release) {
298+
__stlr64((volatile uint64_t*)p, (uint64_t)x);
299+
}
300+
#endif
301+
else {
302+
InterlockedExchange64(p, x);
303+
}
304+
#else
305+
InterlockedExchange64(p, x);
306+
#endif
257307
}
258308

259309
// These are used by the statistics
260310
static inline int64_t mi_atomic_addi64_relaxed(volatile _Atomic(int64_t)*p, int64_t add) {
261-
#ifdef _WIN64
262-
return (int64_t)mi_atomic_addi((int64_t*)p, add);
263-
#else
264-
int64_t current;
265-
int64_t sum;
266-
do {
267-
current = *p;
268-
sum = current + add;
269-
} while (_InterlockedCompareExchange64(p, sum, current) != current);
270-
return current;
271-
#endif
311+
#ifdef _WIN64
312+
return (int64_t)mi_atomic_addi((int64_t*)p, add);
313+
#elif defined(_M_ARM)
314+
return _InterlockedExchangeAdd64(p, add);
315+
#else
316+
// x86
317+
int64_t current;
318+
int64_t sum;
319+
do {
320+
current = __iso_volatile_load64((volatile const int64_t*)p);
321+
sum = current + add;
322+
} while (_InterlockedCompareExchange64(p, sum, current) != current);
323+
return current;
324+
#endif
272325
}
273326
static inline void mi_atomic_void_addi64_relaxed(volatile int64_t* p, const volatile int64_t* padd) {
274327
const int64_t add = *padd;
@@ -289,7 +342,7 @@ static inline void mi_atomic_addi64_acq_rel(volatile _Atomic(int64_t*)p, int64_t
289342
}
290343

291344
static inline bool mi_atomic_casi64_strong_acq_rel(volatile _Atomic(int64_t*)p, int64_t* exp, int64_t des) {
292-
int64_t read = _InterlockedCompareExchange64(p, des, *exp);
345+
const int64_t read = _InterlockedCompareExchange64(p, des, *exp);
293346
if (read == *exp) {
294347
return true;
295348
}

include/mimalloc/internal.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ mi_decl_noreturn mi_decl_cold void _mi_assert_fail(const char* assertion, const
352352
Inlined definitions
353353
----------------------------------------------------------- */
354354
#define MI_UNUSED(x) (void)(x)
355-
#if (MI_DEBUG>0)
355+
#if (MI_DEBUG>1)
356356
#define MI_UNUSED_RELEASE(x)
357357
#else
358358
#define MI_UNUSED_RELEASE(x) MI_UNUSED(x)
@@ -378,8 +378,7 @@ static inline bool _mi_is_power_of_two(uintptr_t x) {
378378

379379
// Is a pointer aligned?
380380
static inline bool _mi_is_aligned(void* p, size_t alignment) {
381-
mi_assert_internal(alignment != 0);
382-
return (((uintptr_t)p % alignment) == 0);
381+
return (alignment==0 || ((uintptr_t)p % alignment) == 0);
383382
}
384383

385384
// Align upwards

include/mimalloc/prim.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,9 @@ static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept;
282282
#if defined(MI_PRIM_THREAD_ID)
283283

284284
static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept {
285-
return MI_PRIM_THREAD_ID(); // used for example by CPython for a free threaded build (see python/cpython#115488)
285+
const mi_threadid_t tid = MI_PRIM_THREAD_ID(); // used for example by CPython for a free threaded build (see python/cpython#115488)
286+
mi_assert_internal( (tid & 0x03) == 0 ); // mimalloc reserves the bottom 2 bits
287+
return tid;
286288
}
287289

288290
#elif defined(_WIN32)

0 commit comments

Comments
 (0)