mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix missing free on GrowableBitSet. init_new/init_temp for GrowableBitSet, LinkedList, List, HashMap, DString, ByteBuffer. Interface to_string renamed to_new_string. Change in allocator usage, malloc is now heap. Added new_array, new_zero_array, new, new_clear, clone. Concat => concat_new. string::printf => string::new_format, string::tprintf => string::tformat. "to_*" are now "to_new_*" and "to_temp_*". "from_*" is "new_from*"
This commit is contained in:
committed by
Christoffer Lerno
parent
69470b8738
commit
1e38ccdd2b
@@ -38,7 +38,7 @@ fn Doc! read_doc(String url)
|
||||
if (url.contains("head-missing")) return { };
|
||||
if (url.contains("title-missing")) return { .head = new_head_val({}) };
|
||||
if (url.contains("title-empty")) return { .head = new_head_val({ .title = new_string_val("")}) };
|
||||
return { .head = new_head_val({ .title = new_string_val(string::printf("Title of %s", url)) }) };
|
||||
return { .head = new_head_val({ .title = new_string_val(string::new_format("Title of %s", url)) }) };
|
||||
}
|
||||
|
||||
fn Summary build_summary(Doc doc)
|
||||
@@ -75,7 +75,7 @@ fn void main()
|
||||
{
|
||||
const String[] URLS = { "good", "title-empty", "title-missing", "head-missing", "fail" };
|
||||
DynamicArenaAllocator dynamic_arena;
|
||||
dynamic_arena.init(1024);
|
||||
dynamic_arena.init(1024, mem::heap());
|
||||
OutStream* out = io::stdout();
|
||||
foreach (String url : URLS)
|
||||
{
|
||||
|
||||
@@ -5,9 +5,9 @@ import libc;
|
||||
|
||||
fn int fannkuchredux(int n)
|
||||
{
|
||||
int* perm = malloc(int, n);
|
||||
int* perm1 = malloc(int, n);
|
||||
int* count = malloc(int, n);
|
||||
int* perm = mem::new_array(int, n);
|
||||
int* perm1 = mem::new_array(int, n);
|
||||
int* count = mem::new_array(int, n);
|
||||
int max_flips_count;
|
||||
int perm_count;
|
||||
int checksum;
|
||||
|
||||
@@ -4,9 +4,9 @@ import std::math;
|
||||
|
||||
fn int fannkuchredux(int n)
|
||||
{
|
||||
int[] perm = malloc(int, n)[:n];
|
||||
int[] perm1 = malloc(int, n)[:n];
|
||||
int* count = malloc(int, n);
|
||||
int[] perm = mem::new_array(int, n);
|
||||
int[] perm1 = mem::new_array(int, n);
|
||||
int* count = mem::new_array(int, n);
|
||||
int max_flips_count;
|
||||
int perm_count;
|
||||
int checksum;
|
||||
|
||||
@@ -44,10 +44,10 @@ fn void eval_AtA_times_u(double[] u, double[] atau, double[] x)
|
||||
fn void main(String[] args)
|
||||
{
|
||||
int n = args.len == 2 ? args[1].to_int()!! : 2000;
|
||||
temparr = malloc(double, n);
|
||||
double[] u = malloc(double, n);
|
||||
double[] v = malloc(double, n);
|
||||
double[] x = malloc(double, n * n);
|
||||
temparr = mem::new_array(double, n);
|
||||
double[] u = mem::new_array(double, n);
|
||||
double[] v = mem::new_array(double, n);
|
||||
double[] x = mem::new_array(double, (usz)(n * n));
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
for (int j = 0; j < n; j++)
|
||||
|
||||
@@ -9,7 +9,7 @@ enum Foo
|
||||
|
||||
fn void print_pages()
|
||||
{
|
||||
mem::temp().print_pages(io::stdout());
|
||||
mem::temp().print_pages(io::stdout())!!;
|
||||
}
|
||||
|
||||
fn void setstring(char* dst, String str)
|
||||
@@ -28,12 +28,12 @@ fn void testAllocator(Allocator* a, int val)
|
||||
io::printf("Aligned with offset %p, align 16: %s offset align 128: %s\n", data, mem::ptr_is_aligned(data, 16), mem::ptr_is_aligned(data + 16, 128));
|
||||
data = a.calloc_aligned(val, 128, 16)!!;
|
||||
io::printf("Aligned with offset %p, align 16: %s offset align 128: %s\n", data, mem::ptr_is_aligned(data, 16), mem::ptr_is_aligned(data + 16, 128));
|
||||
data = a.realloc_aligned(data, val + 1, 128, 16)!!;
|
||||
data = a.realloc_aligned(data, (usz)val + 1, 128, 16)!!;
|
||||
io::printf("Aligned with offset %p, align 16: %s offset align 128: %s\n", data, mem::ptr_is_aligned(data, 16), mem::ptr_is_aligned(data + 16, 128));
|
||||
data = a.realloc_aligned(data, val + 1, 128, 0)!!;
|
||||
data = a.realloc_aligned(data, (usz)val + 1, 128, 0)!!;
|
||||
io::printf("No offset %p, align 16: %s offset align 128: %s\n", data, mem::ptr_is_aligned(data, 16), mem::ptr_is_aligned(data + 16, 128));
|
||||
io::printfn("Freeing %p", data);
|
||||
a.free_aligned(data)!!;
|
||||
a.free_aligned(data);
|
||||
}
|
||||
fn void main()
|
||||
{
|
||||
@@ -63,7 +63,7 @@ fn void main()
|
||||
io::printf("First big: %p\n", first_big);
|
||||
print_pages();
|
||||
};
|
||||
mem::@tscoped()
|
||||
mem::@scoped(mem::temp())
|
||||
{
|
||||
io::printf("Malloc: %p\n", (void*)malloc(23));
|
||||
io::printf("Malloc: %p\n", (void*)malloc(23));
|
||||
@@ -80,7 +80,7 @@ fn void main()
|
||||
testAllocator(&aa, 126);
|
||||
io::printn("Test dynamic arena");
|
||||
DynamicArenaAllocator dynamic_arena;
|
||||
dynamic_arena.init(1024);
|
||||
dynamic_arena.init(1024, mem::heap());
|
||||
testAllocator(&dynamic_arena, 112);
|
||||
testAllocator(&dynamic_arena, 712);
|
||||
first_big[3] = 123;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
module bigint;
|
||||
import libc;
|
||||
import std::io;
|
||||
|
||||
macro @max(a, b)
|
||||
{
|
||||
@@ -22,9 +23,9 @@ fn void BigInt.init(BigInt* bigInt)
|
||||
bigInt.sign = 1;
|
||||
}
|
||||
|
||||
fn void BigInt.initFromString(BigInt* bigInt, char* str)
|
||||
fn void BigInt.initFromString(BigInt* bigInt, ZString str)
|
||||
{
|
||||
uint size = (uint)libc::strlen(str);
|
||||
uint size = (uint)str.len();
|
||||
bigInt.sign = 1;
|
||||
switch (str[0])
|
||||
{
|
||||
@@ -230,8 +231,8 @@ fn char* BigInt.toCharArray(BigInt* bigInt)
|
||||
|
||||
fn void BigInt.print(BigInt* bigInt)
|
||||
{
|
||||
char* chars = bigInt.toCharArray();
|
||||
libc::puts(chars);
|
||||
ZString chars = (ZString)bigInt.toCharArray();
|
||||
io::printn(chars);
|
||||
free(chars);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
module helloworld;
|
||||
|
||||
extern fn void printf(char *str, ...);
|
||||
import std::io;
|
||||
|
||||
fn void main()
|
||||
{
|
||||
printf("Hello World!\n");
|
||||
io::printn("Hello, World!");
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
|
||||
extern fn void printf(char* message, ...);
|
||||
|
||||
fn void defer1() {}
|
||||
fn void defer2() {}
|
||||
fn void defer3() {}
|
||||
fn void defer4() {}
|
||||
fn void defer5() {}
|
||||
fn void defer6() {}
|
||||
fn void defer7() {}
|
||||
fn void defer8() {}
|
||||
fn void defer9() {}
|
||||
fn void defer10() {}
|
||||
fn void defer11() {}
|
||||
|
||||
fn int main(int argc)
|
||||
{
|
||||
int a = 0;
|
||||
{
|
||||
defer
|
||||
{
|
||||
if (a == 1) break;
|
||||
defer1();
|
||||
}
|
||||
defer2();
|
||||
}
|
||||
defer defer3();
|
||||
while (a)
|
||||
{
|
||||
defer defer4();
|
||||
if (argc == 1) break;
|
||||
defer defer5();
|
||||
defer6();
|
||||
}
|
||||
defer defer7();
|
||||
while (a)
|
||||
{
|
||||
defer defer8();
|
||||
if (argc == 1) break;
|
||||
defer defer9();
|
||||
defer10();
|
||||
break;
|
||||
defer11();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import libc;
|
||||
|
||||
struct VarString
|
||||
{
|
||||
Allocator allocator;
|
||||
usz len;
|
||||
usz capacity;
|
||||
char* ptr;
|
||||
|
||||
@@ -23,15 +23,15 @@ struct TopoList
|
||||
|
||||
fn void sort(InputPair[] pairs, uint elements)
|
||||
{
|
||||
InputPair[] result = malloc(InputPair, pairs.len);
|
||||
TopoList* top = malloc(TopoList, elements);
|
||||
InputPair[] result = mem::new_array(InputPair, pairs.len);
|
||||
TopoList* top = mem::new_array(TopoList, elements);
|
||||
for (int i = 0; i < pairs.len; i++)
|
||||
{
|
||||
InputPair pair = pairs[i];
|
||||
assert(pair.value >= 0 && pair.value < elements);
|
||||
assert(pair.successor >= 0 && pair.successor < elements);
|
||||
top[pair.successor].count++;
|
||||
Entry* successor_entry = mem::malloc(Entry);
|
||||
Entry* successor_entry = mem::new(Entry);
|
||||
*successor_entry = { pair.successor, null };
|
||||
Entry** next_ref = &top[pair.value].next;
|
||||
while (*next_ref)
|
||||
@@ -40,7 +40,7 @@ fn void sort(InputPair[] pairs, uint elements)
|
||||
}
|
||||
*next_ref = successor_entry;
|
||||
}
|
||||
int[] intout = malloc(int, elements);
|
||||
int[] intout = mem::new_array(int, elements);
|
||||
int count = 0;
|
||||
while LOOP: (1)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user