Fix ordering of @builtin. malloc <-> alloc, malloc, calloc, realloc, free builtins.

This commit is contained in:
Christoffer Lerno
2022-08-04 01:35:35 +02:00
parent f966250185
commit 6d2ab0c985
22 changed files with 158 additions and 113 deletions

View File

@@ -44,7 +44,7 @@ fn bool contains(char[] haystack, char[] needle)
macro @dupe(value)
{
$typeof(&value) temp = mem::alloc_checked($sizeof(value))?;
$typeof(&value) temp = malloc_checked($sizeof(value))?;
*temp = value;
return temp;
}

View File

@@ -32,7 +32,7 @@ fn int! askGuess(int high)
fn char[]! readLine()
{
char* chars = mem::talloc(1024)?;
char* chars = tmalloc(1024)?;
isize loaded = getline(&chars, &&(usize)1023, libc::stdin());
if (loaded < 0) return InputResult.FAILED_TO_READ!;
chars[loaded] = 0;

View File

@@ -69,8 +69,8 @@ fn int main(int c, char** v)
GameBoard board;
board.w = w;
board.h = h;
board.world = mem::alloc((ulong)(h * w));
board.temp = mem::alloc((ulong)(h * w));
board.world = malloc((ulong)(h * w));
board.temp = malloc((ulong)(h * w));
for (int i = h * w - 1; i >= 0; i--)
{

View File

@@ -118,8 +118,8 @@ fn void! Parser.parse(Parser* p, char* input, char* diagMsg, Blocks* blocks)
p.errorMsg[0] = 0;
p.blocks = blocks;
memset(p.parents, 0, sizeof(Node*)*MaxDepth);
memset(p.lastChild, 0, sizeof(Node*)*MaxDepth);
mem::set(p.parents, 0, sizeof(Node*)*MaxDepth);
mem::set(p.lastChild, 0, sizeof(Node*)*MaxDepth);
p.numParents = 0;
p.topParent = nil;
@@ -438,13 +438,13 @@ fn const Node* Reader.findNode(const Reader* r, const char* key)
switch (*cp) {
case 0:
len = cast<u32>(cp - start);
memcpy(name, start, len);
mem::copy(name, start, len);
name[len] = 0;
node = r.blocks.findNode(name, node);
return node;
case '.':
len = cast<u32>(cp - start);
memcpy(name, start, len);
mem::copy(name, start, len);
name[len] = 0;
start = cp + 1;
node = r.blocks.findNode(name, node);
@@ -644,7 +644,7 @@ public type Blocks struct {
} @(opaque)
fn void Blocks.init(Blocks* b) {
memset(b, 0, sizeof(Blocks));
mem::set(b, 0, sizeof(Blocks));
b.nodes = calloc(MaxNodes, sizeof(Node));
b.namesSize = MaxNames;
@@ -659,7 +659,7 @@ fn void Blocks.init(Blocks* b) {
b.lastCache = 0;
//memset(b.namesCache, 0, sizeof(b.namesCache)); // sizeof(struct member) not supported yet
memset(b.namesCache, 0, sizeof(u32)*NamesCacheSize);
mem::set(b.namesCache, 0, sizeof(u32)*NamesCacheSize);
}
fn void Blocks.destroy(Blocks* b) {
@@ -702,7 +702,7 @@ fn u32 Blocks.addNode(Blocks* b, const char* name, NodeKind k) {
nameOffset = b.namesOffset;
node.nameOffset = nameOffset;
char* newname = &b.names[nameOffset];
memcpy(newname, name, len);
mem::copy(newname, name, len);
b.namesCache[b.lastCache] = nameOffset;
b.lastCache = (b.lastCache + 1) % NamesCacheSize;
b.namesOffset += len;
@@ -716,7 +716,7 @@ fn u32 Blocks.addValue(Blocks* b, const char* value) {
if (value[0] == 0) return 0;
u32 off = b.valuesOffset;
u32 len = cast<u32>(strlen(value)) + 1;
memcpy(&b.values[off], value, len);
mem::copy(&b.values[off], value, len);
b.valuesOffset += len;
return off;
}

View File

@@ -269,7 +269,7 @@ fn void Tokenizer.parseText(Tokenizer* t, Token* result)
uint len = (uint)(t.current - start);
// assert(len < MaxText);
memcpy(t.text as start, len);
mem::copy(t.text as start, len);
t.text[len] = 0;
result.kind = TokenKind.Text;
result.text = t.text;
@@ -310,7 +310,7 @@ fn void! Tokenizer.parseMultiText(Tokenizer* t, Token* result)
uint len = uint(t.current - start);
// assert(len < MaxText);
memcpy(t.text, start, len);
mem::copy(t.text, start, len);
t.text[len] = 0;
result.kind = TokenKind.Text;
result.text = t.text;
@@ -349,7 +349,7 @@ fn void Tokenizer.parseKey(Tokenizer* t, Token* result)
uint len = (uint)(t.current - start);
// assert(len < MaxText);
memcpy(t.text, start, len);
mem::copy(t.text, start, len);
t.text[len] = 0;
result.kind = TokenKind.Word;
result.text = t.text;

View File

@@ -37,41 +37,41 @@ fn void testAllocator(Allocator* a, int val)
}
fn void main()
{
char* small = mem::talloc(128);
char* small = tmalloc(128);
setstring(small, "small");
libc::printf("Small1: %p %s\n", small, small);
print_pages();
small = mem::trealloc(small, 129, 1024 * 16);
small = trealloc(small, 129, 1024 * 16);
libc::printf("Small2: %p %s\n", small, small);
print_pages();
small = mem::trealloc(small, 12933);
small = trealloc(small, 12933);
libc::printf("Small3: %p %s\n", small, small);
print_pages();
char* first_big = mem::talloc(9512);
void *big = mem::talloc(4095);
char* first_big = tmalloc(9512);
void *big = tmalloc(4095);
io::printf("Big: %p\n", big);
io::printf("Small: %p\n", mem::talloc(13));
io::printf("Small: %p\n", tmalloc(13));
print_pages();
@pool() {
big = mem::trealloc(big, 5067);
big = trealloc(big, 5067);
print_pages();
void* hidden = mem::talloc(4096);
void* hidden = tmalloc(4096);
io::printf("Hidden: %p\n", hidden);
io::printf("Big: %p\n", big);
big = mem::trealloc(big, 4096, 256);
big = trealloc(big, 4096, 256);
io::printf("Big: %p\n", big);
io::printf("First big: %p\n", first_big);
print_pages();
};
mem::@tscoped()
{
io::printf("Malloc: %p\n", mem::alloc(23));
io::printf("Malloc: %p\n", mem::alloc(23));
io::printf("Malloc: %p\n", malloc(23));
io::printf("Malloc: %p\n", malloc(23));
};
io::printf("Malloc: %p\n", mem::alloc(23));
io::printf("Malloc: %p\n", malloc(23));
@pool()
{
io::printf("Talloc: %p\n", mem::talloc(22));
io::printf("Talloc: %p\n", tmalloc(22));
};
testAllocator(mem::temp_allocator(), 126);
testAllocator(mem::temp_allocator(), 12600);

View File

@@ -33,7 +33,7 @@ fn void getComm(uint len, char* src)
uint size;
size = len - 2;
char* comm = malloc(size + 1);
memcpy(comm, src, size);
mem::copy(comm, src, size);
}
fn uint* decode_fh(uint* p, SvcFh* fhp)
@@ -42,7 +42,7 @@ fn uint* decode_fh(uint* p, SvcFh* fhp)
fh_init(fhp, NFS3_FHSIZE);
size = ntohl(*p++);
if (size > NFS3_FHSIZE) return NULL;
memcpy(&fhp.fh_handle.fh_base, p, size);
mem::copy(&fhp.fh_handle.fh_base, p, size);
fhp.fh_handle.fh_size = size;
return p + XDR_QUADLEN(size);
}

View File

@@ -13,14 +13,14 @@ struct String
fn void String.init(String *s, char[] c)
{
s.capacity = c.len + 16;
s.ptr = mem::_malloc(s.capacity);
s.ptr = malloc(s.capacity);
s.len = c.len;
mem::copy(s.ptr, (char*)(c), c.len);
}
fn char* String.zstr(String *s)
{
char* c = mem::_malloc(s.len + 1);
char* c = malloc(s.len + 1);
mem::copy(c, s.ptr, s.len);
c[s.len] = 0;
return c;
@@ -31,7 +31,7 @@ fn void String.appendc(String *s, char c)
if (s.capacity == s.len)
{
s.capacity *= 2;
char* new_ptr = mem::_malloc(s.capacity);
char* new_ptr = malloc(s.capacity);
mem::copy(new_ptr, s.ptr, s.len);
s.ptr = new_ptr;
}
@@ -47,7 +47,7 @@ fn void String.append(String *s, char[] other_string)
s.capacity *= 2;
}
while (s.capacity < s.len + other_string.len);
char* new_ptr = mem::_malloc(s.capacity);
char* new_ptr = malloc(s.capacity);
mem::copy(new_ptr, s.ptr, s.len);
s.ptr = new_ptr;
}
@@ -64,7 +64,7 @@ fn void String.concat(String *s, String* other_string)
s.capacity *= 2;
}
while (s.capacity < s.len + other_string.len);
char* new_ptr = mem::_malloc(s.capacity);
char* new_ptr = malloc(s.capacity);
mem::copy(new_ptr, s.ptr, s.len);
s.ptr = new_ptr;
}