The main posixpp library and associated tests.
Revision | bfd378be8d50026a4a7bdf80900c6eb80e382e3c (tree) |
---|---|
Time | 2020-07-12 15:19:59 |
Author | Eric Hopper <hopper@omni...> |
Commiter | Eric Hopper |
Add a README about what I'm up to and why.
@@ -0,0 +1,47 @@ | ||
1 | +# A pure C++ Posix interface # | |
2 | + | |
3 | +With this project, I intend to implement many parts of Posix in pure | |
4 | +C++ without any reliance on libc. | |
5 | + | |
6 | +Part of the motivation for this is that glibc and pthreads are very | |
7 | +bloated with features that are rarely used in most programs. | |
8 | + | |
9 | +Another part of the motivation is that system calls are not exposed to | |
10 | +the C++ optimizer in a useful way. The register stores and loads | |
11 | +required to make them work can often be combined with the calculations a | |
12 | +program is already doing so that the values mysteriously appear in the | |
13 | +registers when needed instead of having to be moved there just before | |
14 | +the system call. | |
15 | + | |
16 | +To this end, a subgoal is to implement the system call interface for | |
17 | +many architectures (and potentially many operating systems) as inline | |
18 | +assembly inside of inline functions. | |
19 | + | |
20 | +A third part of the motivation is to eliminate the horrible hack that is | |
21 | +errno. Errno is the bane of clean error handling, and it requires | |
22 | +expensive to access thread local storage to implement. Error returns | |
23 | +should not be global variables. | |
24 | + | |
25 | +To this end, a simple `expected` type is used for error handling at | |
26 | +every level of the interface. This also causes default error handling | |
27 | +(if you just assume the `expected` object always contains the expected | |
28 | +value) to throw an exception whenever errors are ignored. And if you | |
29 | +purposely check for errors, all code relating to exceptions will be | |
30 | +optimized out of existence. | |
31 | + | |
32 | +Ideally, parts of the C++ standard library that rely on operating system | |
33 | +facilities would also be implemented in this library. | |
34 | + | |
35 | +For example, pthreads is a terrible interface, designed when threading | |
36 | +was mysterious, strange, complex, and rare. And it was designed for old | |
37 | +ideas about how threads should synchronize. It's far more expensive to | |
38 | +use than it should be for simple mutexes and condition variables. | |
39 | + | |
40 | +IOstreams isn't the best part of C++. But, being able to implement it | |
41 | +while ignoring C's stdio might make things easier. | |
42 | + | |
43 | +Lastly, it would be really nice to have namespaces that aren't chock | |
44 | +full macro definitions (most of which are just using the preprocessor to | |
45 | +implement constants). And it would be nice to have names and types for | |
46 | +various flags passed to various system calls that made it easier to | |
47 | +write correct programs. |