mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-02 17:28:30 +00:00
Make fixes, improvements, and chibicc python bindings
- python now mixes audio 10x faster - python octal notation is restored - chibicc now builds code 3x faster - chibicc now has help documentation - chibicc can now generate basic python bindings - linenoise now supports some paredit-like features See #141
This commit is contained in:
parent
28997f3acb
commit
7061c79c22
121 changed files with 5272 additions and 1928 deletions
30
third_party/dlmalloc/README.cosmo
vendored
30
third_party/dlmalloc/README.cosmo
vendored
|
@ -1,15 +1,21 @@
|
|||
Numerous local changes were made while vendoring Doug Lee's original
|
||||
dlmalloc sources. Those changes basically boil down to:
|
||||
ORIGIN
|
||||
|
||||
1. Fewer #ifdefs
|
||||
2. More modules (so linker can do a better job)
|
||||
3. Delete code we don't need (cf. Knight Capital)
|
||||
4. Readability / stylistic consistency
|
||||
http://gee.cs.oswego.edu/
|
||||
|
||||
Since we haven't made any genuine improvements to Doug Lee's legendary
|
||||
allocator, we feel this folder faithfully presents his intended work, in
|
||||
harmony with Cosmopolitan conventions.
|
||||
LOCAL CHANGES
|
||||
|
||||
The only deleted code we're sure has compelling merit is the mspace
|
||||
functionality. If we ever need memory pools, they might be more
|
||||
appropriately vendored under //third_party/dlmalloc_mspace.
|
||||
Numerous local changes were made while vendoring Doug Lee's original
|
||||
dlmalloc sources. Those changes basically boil down to:
|
||||
|
||||
1. Fewer #ifdefs
|
||||
2. More modules (so linker can do a better job)
|
||||
3. Delete code we don't need (cf. Knight Capital)
|
||||
4. Readability / stylistic consistency
|
||||
|
||||
Since we haven't made any genuine improvements to Doug Lee's legendary
|
||||
allocator, we feel this folder faithfully presents his intended work, in
|
||||
harmony with Cosmopolitan conventions.
|
||||
|
||||
The only deleted code we're sure has compelling merit is the mspace
|
||||
functionality. If we ever need memory pools, they might be more
|
||||
appropriately vendored under //third_party/dlmalloc_mspace.
|
||||
|
|
12
third_party/dlmalloc/bulk_free.c
vendored
12
third_party/dlmalloc/bulk_free.c
vendored
|
@ -3,13 +3,13 @@
|
|||
|
||||
/**
|
||||
* Frees and clears (sets to NULL) each non-null pointer in the given
|
||||
* array. This is likely to be faster than freeing them one-by-one. If
|
||||
* footers are used, pointers that have been allocated in different
|
||||
* mspaces are not freed or cleared, and the count of all such pointers
|
||||
* is returned. For large arrays of pointers with poor locality, it may
|
||||
* be worthwhile to sort this array before calling bulk_free.
|
||||
* array. This is twice as fast as freeing them one-by-one. If footers
|
||||
* are used, pointers that have been allocated in different mspaces are
|
||||
* not freed or cleared, and the count of all such pointers is returned.
|
||||
* For large arrays of pointers with poor locality, it may be worthwhile
|
||||
* to sort this array before calling bulk_free.
|
||||
*/
|
||||
size_t bulk_free(void *array[], size_t nelem) {
|
||||
size_t dlbulk_free(void *array[], size_t nelem) {
|
||||
/*
|
||||
* Try to free all pointers in the given array. Note: this could be
|
||||
* made faster, by delaying consolidation, at the price of disabling
|
||||
|
|
4
third_party/dlmalloc/dlcalloc.c
vendored
4
third_party/dlmalloc/dlcalloc.c
vendored
|
@ -6,6 +6,8 @@ void *dlcalloc(size_t n_elements, size_t elem_size) {
|
|||
size_t req;
|
||||
if (__builtin_mul_overflow(n_elements, elem_size, &req)) req = -1;
|
||||
mem = dlmalloc(req);
|
||||
if (mem != 0 && calloc_must_clear(mem2chunk(mem))) memset(mem, 0, req);
|
||||
if (mem != 0 && calloc_must_clear(mem2chunk(mem))) {
|
||||
bzero(mem, req);
|
||||
}
|
||||
return mem;
|
||||
}
|
||||
|
|
2
third_party/dlmalloc/dlindependent_calloc.c
vendored
2
third_party/dlmalloc/dlindependent_calloc.c
vendored
|
@ -66,7 +66,7 @@ static void **ialloc(mstate m, size_t n_elements, size_t *sizes, int opts,
|
|||
assert(!is_mmapped(p));
|
||||
|
||||
if (opts & 0x2) { /* optionally clear the elements */
|
||||
memset((size_t *)mem, 0, remainder_size - SIZE_T_SIZE - array_size);
|
||||
bzero((size_t *)mem, remainder_size - SIZE_T_SIZE - array_size);
|
||||
}
|
||||
|
||||
/* If not provided, allocate the pointer array as final part of chunk */
|
||||
|
|
8
third_party/dlmalloc/dlmalloc.c
vendored
8
third_party/dlmalloc/dlmalloc.c
vendored
|
@ -881,17 +881,13 @@ textstartup void dlmalloc_init(void) {
|
|||
|
||||
void *dlmemalign$impl(mstate m, size_t alignment, size_t bytes) {
|
||||
void *mem = 0;
|
||||
if (alignment < MIN_CHUNK_SIZE) { /* must be at least a minimum chunk size */
|
||||
alignment = MIN_CHUNK_SIZE; /* is 32 bytes on NexGen32e */
|
||||
}
|
||||
if ((alignment & (alignment - SIZE_T_ONE)) != 0) { /* Ensure a power of 2 */
|
||||
alignment = roundup2pow(alignment);
|
||||
}
|
||||
if (bytes >= MAX_REQUEST - alignment) {
|
||||
if (m != 0) { /* Test isn't needed but avoids compiler warning */
|
||||
enomem();
|
||||
}
|
||||
} else {
|
||||
/* alignment is 32+ bytes rounded up to nearest two power */
|
||||
alignment = 2ul << bsrl(MAX(MIN_CHUNK_SIZE, alignment) - 1);
|
||||
size_t nb = request2size(bytes);
|
||||
size_t req = nb + alignment + MIN_CHUNK_SIZE - CHUNK_OVERHEAD;
|
||||
mem = dlmalloc_impl(req, false);
|
||||
|
|
4
third_party/dlmalloc/dlmalloc.internal.h
vendored
4
third_party/dlmalloc/dlmalloc.internal.h
vendored
|
@ -7,6 +7,7 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/log/backtrace.internal.h"
|
||||
#include "libc/nexgen32e/bsf.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/symbols.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
@ -854,7 +855,7 @@ extern struct MallocParams g_mparams;
|
|||
#define compute_bit2idx(X, I) \
|
||||
{ \
|
||||
unsigned int J; \
|
||||
J = __builtin_ctz(X); \
|
||||
J = bsf(X); \
|
||||
I = (bindex_t)J; \
|
||||
}
|
||||
|
||||
|
@ -1309,6 +1310,7 @@ struct MallocStats dlmalloc_stats(mstate) hidden;
|
|||
int dlmalloc_sys_trim(mstate, size_t) hidden;
|
||||
void dlmalloc_dispose_chunk(mstate, mchunkptr, size_t) hidden;
|
||||
mchunkptr dlmalloc_try_realloc_chunk(mstate, mchunkptr, size_t, int) hidden;
|
||||
size_t dlbulk_free(void *[], size_t) hidden;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
2
third_party/dlmalloc/dlmalloc_stats.c
vendored
2
third_party/dlmalloc/dlmalloc_stats.c
vendored
|
@ -22,7 +22,7 @@
|
|||
*/
|
||||
struct MallocStats dlmalloc_stats(mstate m) {
|
||||
struct MallocStats res;
|
||||
memset(&res, 0, sizeof(res));
|
||||
bzero(&res, sizeof(res));
|
||||
ensure_initialization();
|
||||
if (!PREACTION(m)) {
|
||||
check_malloc_state(m);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue