merge from dev

This commit is contained in:
daanx 2025-01-04 22:02:50 -08:00
commit d3d551ab9b
3 changed files with 13 additions and 12 deletions

View file

@ -67,8 +67,8 @@ terms of the MIT license. A copy of the license can be found in the file
// "libc.c"
#include <stdarg.h>
void _mi_vsnprintf(char* buf, size_t bufsize, const char* fmt, va_list args);
void _mi_snprintf(char* buf, size_t buflen, const char* fmt, ...);
int _mi_vsnprintf(char* buf, size_t bufsize, const char* fmt, va_list args);
int _mi_snprintf(char* buf, size_t buflen, const char* fmt, ...);
char _mi_toupper(char c);
int _mi_strnicmp(const char* s, const char* t, size_t n);
void _mi_strlcpy(char* dest, const char* src, size_t dest_size);

View file

@ -84,8 +84,8 @@ bool _mi_getenv(const char* name, char* result, size_t result_size) {
// This is mostly to avoid calling these when libc is not yet
// initialized (and to reduce dependencies)
//
// format: d i, p, x, u, s
// type: z l ll L
// format: d i, p x u, s
// prec: z l ll L
// width: 10
// align-left: -
// fill: 0
@ -160,8 +160,8 @@ static void mi_out_num(uintmax_t x, size_t base, char prefix, char** out, char*
#define MI_NEXTC() c = *in; if (c==0) break; in++;
void _mi_vsnprintf(char* buf, size_t bufsize, const char* fmt, va_list args) {
if (buf == NULL || bufsize == 0 || fmt == NULL) return;
int _mi_vsnprintf(char* buf, size_t bufsize, const char* fmt, va_list args) {
if (buf == NULL || bufsize == 0 || fmt == NULL) return 0;
buf[bufsize - 1] = 0;
char* const end = buf + (bufsize - 1);
const char* in = fmt;
@ -279,13 +279,15 @@ void _mi_vsnprintf(char* buf, size_t bufsize, const char* fmt, va_list args) {
}
mi_assert_internal(out <= end);
*out = 0;
return (int)(out - buf);
}
void _mi_snprintf(char* buf, size_t buflen, const char* fmt, ...) {
int _mi_snprintf(char* buf, size_t buflen, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
_mi_vsnprintf(buf, buflen, fmt, args);
const int written = _mi_vsnprintf(buf, buflen, fmt, args);
va_end(args);
return written;
}

View file

@ -253,7 +253,7 @@ void _mi_page_abandon(mi_page_t* page, mi_page_queue_t* pq) {
mi_page_queue_remove(pq, page);
mi_tld_t* tld = page->heap->tld;
mi_page_set_heap(page, NULL);
_mi_arenas_page_abandon(page);
_mi_arenas_page_abandon(page);
_mi_arenas_collect(false, false, tld); // allow purging
}
}
@ -265,7 +265,7 @@ static mi_page_t* mi_page_fresh_alloc(mi_heap_t* heap, mi_page_queue_t* pq, size
mi_assert_internal(pq != NULL);
mi_assert_internal(mi_heap_contains_queue(heap, pq));
mi_assert_internal(page_alignment > 0 || block_size > MI_LARGE_MAX_OBJ_SIZE || block_size == pq->block_size);
#endif
#endif
mi_page_t* page = _mi_arenas_page_alloc(heap, block_size, page_alignment);
if (page == NULL) {
// out-of-memory
@ -612,7 +612,7 @@ static void mi_page_extend_free(mi_heap_t* heap, mi_page_t* page) {
if (page->slice_committed > 0) {
const size_t needed_size = (page->capacity + extend)*bsize;
const size_t needed_commit = _mi_align_up( mi_page_slice_offset_of(page, needed_size), MI_PAGE_MIN_COMMIT_SIZE );
if (needed_commit > page->slice_committed) {
if (needed_commit > page->slice_committed) {
mi_assert_internal(((needed_commit - page->slice_committed) % _mi_os_page_size()) == 0);
_mi_os_commit(mi_page_slice_start(page) + page->slice_committed, needed_commit - page->slice_committed, NULL);
page->slice_committed = needed_commit;
@ -957,7 +957,6 @@ void* _mi_malloc_generic(mi_heap_t* heap, size_t size, bool zero, size_t huge_al
}
// move singleton pages to the full queue
if (page->reserved == page->used) {
mi_assert_internal(page->reserved == 1);
mi_page_to_full(page, mi_page_queue_of(page));
}
return p;