mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
enforce buff channel size > 0 (#2952)
* fix(stdlib): enforce BufferedChannel size > 0 and add regression test * chore(repo): ignore cmake/test artifacts * Formatting --------- Co-authored-by: Christoffer Lerno <christoffer.lerno@gmail.com>
This commit is contained in:
committed by
GitHub
parent
143fa70f87
commit
9fbf6bc213
7
.gitignore
vendored
7
.gitignore
vendored
@@ -73,6 +73,9 @@ out/
|
|||||||
/cmake-build-debug/
|
/cmake-build-debug/
|
||||||
/cmake-build-release/
|
/cmake-build-release/
|
||||||
|
|
||||||
|
CMakeFiles/cmake.check_cache
|
||||||
|
CMakeCache.txt
|
||||||
|
|
||||||
# etags(Emacs), ctags, gtags
|
# etags(Emacs), ctags, gtags
|
||||||
TAGS
|
TAGS
|
||||||
GPATH
|
GPATH
|
||||||
@@ -94,8 +97,8 @@ result
|
|||||||
|
|
||||||
# tests
|
# tests
|
||||||
/test/tmp/*
|
/test/tmp/*
|
||||||
/test/testrun
|
testrun
|
||||||
/test/test_suite_runner
|
test_suite_runner
|
||||||
|
|
||||||
# patches, originals and rejects
|
# patches, originals and rejects
|
||||||
*.patch
|
*.patch
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ struct BufferedChannelImpl @private
|
|||||||
Type[*] buf;
|
Type[*] buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<*
|
||||||
|
@require size > 0: "channel size must be > 0"
|
||||||
|
*>
|
||||||
fn void? BufferedChannel.init(&self, Allocator allocator, usz size = 1)
|
fn void? BufferedChannel.init(&self, Allocator allocator, usz size = 1)
|
||||||
{
|
{
|
||||||
BufferedChannelImpl* channel = allocator::new_with_padding(allocator, BufferedChannelImpl, Type.sizeof * size)!;
|
BufferedChannelImpl* channel = allocator::new_with_padding(allocator, BufferedChannelImpl, Type.sizeof * size)!;
|
||||||
@@ -155,4 +158,3 @@ fn void? BufferedChannel.close(self) @maydiscard // Remove optional in 0.8.0
|
|||||||
channel.mu.unlock();
|
channel.mu.unlock();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
8
test/test_suite/stdlib/channels.c3
Normal file
8
test/test_suite/stdlib/channels.c3
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import std::thread;
|
||||||
|
|
||||||
|
fn int main()
|
||||||
|
{
|
||||||
|
BufferedChannel{int} c;
|
||||||
|
c.init(mem, 0)!!; // #error: @require "size > 0" violated: 'channel size must be > 0'.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user