Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
thradams
searching Neon…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
8 ms
·
1.
▲
Ownership model and nullable pointers for C
(cakecc.org)
3 points
by
thradams
9mo ago
|
1 comments
2.
▲
by
thradams
9mo ago
In this model, ownership is checked statically when variables go out of scope and before assignment. "Owner pointers" must be uninitialized or null at the end of their scope. Basically, the nullable state needs to be tracked at co
3.
▲
by
thradams
2y ago
When exploring the design of nullable pointers in C and comparing them with other languages like C# and TypeScript, which have constructors, I realized that C might benefit from a way to represent transient states, the state equivalent of w
4.
▲
by
thradams
2y ago
A two-minute video explaining the concepts of nullable pointers and pointer ownership in Cake, using a simple example.
5.
▲
Fixing C source code from the internet using cake static analyzer
(youtube.com)
12 points
by
thradams
2y ago
|
2 comments
6.
▲
by
thradams
2y ago
Cake is a open source compiler and static analyzer in development. (Not production quality yet.) This video shows how cake can help programmers to create safe code just fixing warnings. https://youtu.be/X5tmkF16UMQ We copy
7.
▲
by
thradams
3y ago
I think at "Keep the language small and simple" it should say avoid "two ways of doing something" ( The sample I have is 0, NULL and nullptr where nullptr is something new. Two ways of doing something makes the language
8.
▲
by
thradams
3y ago
Cake disabled checks in a few linked list functions like pop_front pop_back.
9.
▲
by
thradams
3y ago
Cake is not porting Rust semantics. It works on classical C code, like the first sample using fopen. #include <ownership.h> #include <stdio.h> int main() { FILE *owner f = fopen("file.txt", &q
10.
▲
by
thradams
3y ago
(question about rust.. this is not implemented in cake yet) Let's say I have to objects on the heap. A and B. A have a "view" to B. Then we put a prompt for the user. (or dynamic condition) "Which object do you want to d
11.
▲
by
thradams
3y ago
The ownership checks are new in Cake, less than one year. So the answer is no, just cake is using. And there is a lot of work to do..in flow analysis etc. The cake source itself is moving to another experimental feature that is nullable typ
12.
▲
by
thradams
3y ago
(I think preprocessor is the place where memory is used and released all the time while expanding macros.)
13.
▲
by
thradams
3y ago
This "dynamic drop semantics" does not exist in cake. int * owner p = malloc(sizeof(int)); if (condition) free(p); free(p); // error p may be initialized/moved. to fix int * owner p =
14.
▲
by
thradams
3y ago
auto, typeof, _Generic are implemented in cake. Sometimes when they are used inside macros the macros needs to be expanded. Then cake has #pragma expand MACRO. for this task. Sample macro NEW using c23 typeof. #include <stdlib.h&g
15.
▲
by
thradams
3y ago
The idea is to keep cake aligned with C, not a language fork. But Cake itself could have a fork to Cake++. :D
16.
▲
by
thradams
3y ago
(by the way, embed is not working on web version because of include directory bug - it is an open issue and regression)
17.
▲
by
thradams
3y ago
Rust needs to add some runtime checks when calling destructors in scenarios where some object may or may not be moved. In C++ for instance, for smart pointers, the destructor will have a "if p!= NULL". Then if the smart pointer w
18.
▲
by
thradams
3y ago
One issue I see with this approach (compiler leaking memory) is, for instance, if the requirements change and you need to utilize the compiler as a lib or service. For example, if the Cake source is used within a web browser compiled with
19.
▲
by
thradams
3y ago
In cake there is no temporal hole, we cannot reuse the deleted object. This prevents double free and use after free. int main() { struct X * owner p = malloc(sizeof(struct X)); p->text = malloc(10);
20.
▲
by
thradams
3y ago
Thanks for the rust sample. It looks very similar. Can the allocator be customized? As I said I am not Rust specialist. Also, in my understanding is that in Rust, sometimes a dynamic state is created when the object may or may not be moved
21.
▲
by
thradams
3y ago
Cake implements defer as an extension, where ownership and defer work together. The flow analysis must be prepared for defer. int * owner p = calloc(1, sizeof(int)); defer free(p); However, with ownership checks, the code is a
22.
▲
by
thradams
3y ago
>Can you ask Github Co-pilot to look at C code and answer the question "What is >the length of the array 'buf' passed to this function"? That tells you how to >express the array in a language where arrays have e
23.
▲
by
thradams
3y ago
mempool does not solve double free, use after free (at least at compile time) or fopen sample. But mempool and ownership can be complementary.
24.
▲
by
thradams
3y ago
In cake object and memory are two resources. We can for instance, delete the object and reuse the same memory. For instance, this code is correct. #include <ownership.h> #include <stdlib.h> struct X { char
25.
▲
by
thradams
3y ago
the other difference in RAII destructor cannot be turned off. In cake the same object can be a "view" struct X x = {0}; //... view struct X x2 = x; destroy(&x); //x2 does not need dest
26.
▲
by
thradams
3y ago
I think gsl::Owner is related with RAII. The difference with cake ownership and RAII , is that with C++ RAII, the destructor is unconditionally called at end of scope. Then flow analysis is not required in RAII. Cake requires flow analysis
27.
▲
by
thradams
3y ago
the cake implementation cannot be mapped to rust. I am not rust specialist but one concept for instance is that a owner pointer owns two resources at same time, the memory and object. In rust it is one concept. Owner pointers take on the re
28.
▲
by
thradams
3y ago
currently cake uses existing msvc and gcc headers. These headers does not have any owner qualifiers. The temporary solution, is the re-declare the malloc etc when compiling with cake and not complain withe the function signature difference
29.
▲
by
thradams
3y ago
Not sure if I understood. the usage of old and new (checked and unchecked) is a challenge.We may have the same headers used in both codes. The other challenging is that same source may compile in compiler with or without support. Ownership
30.
▲
by
thradams
3y ago
This code will not compile because we cannot return owner as non owner. To fix we need to add qualifier owner at return type. FILE* owner open_file(const char* p) { FILE* owner f = … return f; } Then when retur
More ›