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
@@ -27,7 +27,7 @@ fn void! readbuffer()
|
||||
reader_buf.init(&src, buf[..]);
|
||||
|
||||
ByteWriter bw;
|
||||
bw.tinit();
|
||||
bw.init_temp();
|
||||
|
||||
usz n = io::copy_to(&reader_buf, &bw)!;
|
||||
|
||||
@@ -39,7 +39,7 @@ fn void! readbuffer()
|
||||
fn void! writebuffer_large()
|
||||
{
|
||||
ByteWriter out;
|
||||
out.tinit();
|
||||
out.init_temp();
|
||||
char[16] buf;
|
||||
WriteBuffer write_buf;
|
||||
write_buf.init(&out, buf[..]);
|
||||
@@ -56,7 +56,7 @@ fn void! writebuffer()
|
||||
ByteReader br;
|
||||
br.init(DATA);
|
||||
ByteWriter out;
|
||||
out.tinit();
|
||||
out.init_temp();
|
||||
char[3] buf;
|
||||
WriteBuffer write_buf;
|
||||
write_buf.init(&out, buf[..]);
|
||||
|
||||
@@ -4,7 +4,7 @@ import std::io;
|
||||
fn void! write_read()
|
||||
{
|
||||
ByteBuffer buffer;
|
||||
buffer.init(0)!;
|
||||
buffer.init_new(0)!;
|
||||
|
||||
buffer.write("hello")!;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ fn void! bytestream()
|
||||
usz len = s.read(&buffer)!;
|
||||
assert((String)buffer[:len] == "abc");
|
||||
ByteWriter w;
|
||||
w.init();
|
||||
w.init_new();
|
||||
OutStream* ws = &w;
|
||||
ws.write("helloworld")!;
|
||||
assert(w.str_view() == "helloworld");
|
||||
@@ -27,7 +27,7 @@ fn void! bytewriter_buffer()
|
||||
{
|
||||
ByteWriter writer;
|
||||
char[8] z;
|
||||
writer.init_buffer(&z);
|
||||
writer.init_with_buffer(&z);
|
||||
OutStream* s = &writer;
|
||||
s.write("hello")!!;
|
||||
s.write_byte(0)!!;
|
||||
@@ -43,7 +43,7 @@ fn void! bytewriter_read_from()
|
||||
InStream* s = &r;
|
||||
|
||||
ByteWriter bw;
|
||||
bw.tinit();
|
||||
bw.init_temp();
|
||||
bw.read_from(s)!;
|
||||
|
||||
assert(bw.str_view() == data);
|
||||
|
||||
@@ -3,7 +3,7 @@ module std::io @test;
|
||||
fn void! test_writing()
|
||||
{
|
||||
DString foo;
|
||||
foo.init();
|
||||
foo.init_new();
|
||||
OutStream* s = &foo;
|
||||
s.write("hello")!!;
|
||||
s.write_byte('-')!!;
|
||||
|
||||
@@ -3,52 +3,52 @@ module std::io @test;
|
||||
fn void printf_a()
|
||||
{
|
||||
String s;
|
||||
s = string::printf("%08.2a", 234.125);
|
||||
s = string::new_format("%08.2a", 234.125);
|
||||
assert(s == "0x1.d4p+7", "got '%s'; want '0x1.d4p+7'", s);
|
||||
s = string::printf("%a", 234.125);
|
||||
s = string::new_format("%a", 234.125);
|
||||
assert(s == "0x1.d44p+7", "got '%s'; want '0x1.d44p+7'", s);
|
||||
s = string::printf("%A", 234.125);
|
||||
s = string::new_format("%A", 234.125);
|
||||
assert(s == "0X1.D44P+7", "got '%s'; want '0X1.D44P+7'", s);
|
||||
s = string::printf("%20a", 234.125);
|
||||
s = string::new_format("%20a", 234.125);
|
||||
assert(s == " 0x1.d44p+7", "got '%s'; want ' 0x1.d44p+7'", s);
|
||||
s = string::printf("%-20a", 234.125);
|
||||
s = string::new_format("%-20a", 234.125);
|
||||
assert(s == "0x1.d44p+7 ", "got '%s'; want '0x1.d44p+7 '", s);
|
||||
s = string::printf("%-20s", "hello world");
|
||||
s = string::new_format("%-20s", "hello world");
|
||||
assert(s == "hello world ", "got '%s'; want 'hello world '", s);
|
||||
s = string::printf("%20s", "hello world");
|
||||
s = string::new_format("%20s", "hello world");
|
||||
assert(s == " hello world", "got '%s'; want ' hello world'", s);
|
||||
|
||||
String str = "hello!";
|
||||
s = string::printf("%-20s", str);
|
||||
s = string::new_format("%-20s", str);
|
||||
assert(s == "hello! ", "got '%s'; want 'hello! '", s);
|
||||
s = string::printf("%20s", str);
|
||||
s = string::new_format("%20s", str);
|
||||
assert(s == " hello!", "got '%s'; want ' hello!'", s);
|
||||
|
||||
int[2] a = { 12, 23 };
|
||||
s = string::printf("%-20s", a);
|
||||
s = string::new_format("%-20s", a);
|
||||
assert(s == "[12, 23] ", "got '%s'; want '[12, 23] '", s);
|
||||
s = string::printf("%20s", a);
|
||||
s = string::new_format("%20s", a);
|
||||
assert(s == " [12, 23]", "got '%s'; want ' [12, 23]'", s);
|
||||
|
||||
s = string::printf("%-20s", a[..]);
|
||||
s = string::new_format("%-20s", a[..]);
|
||||
assert(s == "[12, 23] ", "got '%s'; want '[12, 23] '", s);
|
||||
s = string::printf("%20s", a[..]);
|
||||
s = string::new_format("%20s", a[..]);
|
||||
assert(s == " [12, 23]", "got '%s'; want ' [12, 23]'", s);
|
||||
|
||||
float[2] f = { 12.0, 23.0 };
|
||||
s = string::printf("%-24s", f);
|
||||
s = string::new_format("%-24s", f);
|
||||
assert(s == "[12.000000, 23.000000] ", "got '%s'; want '[12.000000, 23.000000] '", s);
|
||||
s = string::printf("%24s", f);
|
||||
s = string::new_format("%24s", f);
|
||||
assert(s == " [12.000000, 23.000000]", "got '%s'; want ' [12.000000, 23.000000]'", s);
|
||||
|
||||
int[<2>] vec = { 12, 23 };
|
||||
s = string::printf("%-20s", vec);
|
||||
s = string::new_format("%-20s", vec);
|
||||
assert(s == "[<12, 23>] ", "got '%s'; want '[<12, 23>] '", s);
|
||||
s = string::printf("%20s", vec);
|
||||
s = string::new_format("%20s", vec);
|
||||
assert(s == " [<12, 23>]", "got '%s'; want ' [<12, 23>]'", s);
|
||||
|
||||
String ss = "hello world";
|
||||
s = string::printf("%.4s %.5s", ss, ss);
|
||||
s = string::new_format("%.4s %.5s", ss, ss);
|
||||
assert(s == "hell hello", "got '%s'; want 'hell hello'", s);
|
||||
}
|
||||
|
||||
@@ -62,13 +62,13 @@ fn void printf_enum()
|
||||
{
|
||||
String s;
|
||||
|
||||
s = string::printf("%s", PrintfTest.ENUMA);
|
||||
s = string::new_format("%s", PrintfTest.ENUMA);
|
||||
assert(s == "ENUMA", "got '%s'; want 'ENUMA'", s);
|
||||
s = string::printf("%s", PrintfTest.ENUMB);
|
||||
s = string::new_format("%s", PrintfTest.ENUMB);
|
||||
assert(s == "ENUMB", "got '%s'; want 'ENUMB'", s);
|
||||
|
||||
s = string::printf("%d", PrintfTest.ENUMA);
|
||||
s = string::new_format("%d", PrintfTest.ENUMA);
|
||||
assert(s == "0", "got '%s'; want '0'", s);
|
||||
s = string::printf("%d", PrintfTest.ENUMB);
|
||||
s = string::new_format("%d", PrintfTest.ENUMB);
|
||||
assert(s == "1", "got '%s'; want '1'", s);
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import std::io;
|
||||
fn void! write_read()
|
||||
{
|
||||
ByteBuffer buf;
|
||||
buf.tinit(16)!;
|
||||
buf.init_temp(16)!;
|
||||
usz n;
|
||||
uint x;
|
||||
uint y;
|
||||
@@ -45,7 +45,7 @@ fn void! samples()
|
||||
foreach (tc : tcases)
|
||||
{
|
||||
ByteWriter bw;
|
||||
bw.tinit();
|
||||
bw.init_temp();
|
||||
usz n = io::write_varint(&bw, tc.in)!;
|
||||
assert(n == tc.bytes.len, "got %d; want %d", n, tc.bytes.len);
|
||||
char[] bytes = bw.bytes[:bw.index];
|
||||
|
||||
Reference in New Issue
Block a user