5 ms·
Maybe Theo wanted fopen-like semantics?
by anilakar 8y ago
Maybe Theo wanted fopen-like semantics?
- bonzini 8y agofopen is not a system call, it is a library call. The system call is open, and it uses bits for flags.
- int_19h 8y agoWhich makes it that much harder to extend. There's nothing wrong with the use of strings here. It's very readable, easily understandable to anyone who knows C, can be checked by automated tools (or at runtime) for invalid values, and is easily extensible in the future. It's also not on a hot path (I mean, you shouldn't have to do this at any point other than process creation).
- therein 8y agoRight but is there really any reason why the implementation should call strncmp or anything that would be costlier than a bitwise AND? It's not like "r" reads better than O_RDONLY.
- codetrotter 8y agoPledge happens on process startup only, so since it’s not like it is called over and over again during the life of the process, the overhead is certainly negligible for all modern servers, desktops and laptops.
- danieldk 8y agoBut compiler errors (typo in a flag) become runtime errors (typo in the unveil string).
- protomyth 8y agoIt is trivial to run a script to check the values are correct.
- vageli 8y agoYou don't see an issue with needing to write and maintain a verification script for something that is essentially a solved problem? Why add more development runtime overhead? What do string-based flags get you that bit-based don't?
- protomyth 8y agoNope, I really don't. I don't fear strings in code because I have to run verification scripts on whatever config format we end up using or you get stuff like [1]. Its just another part of the compile process once setup, and their reasoning was sound[2], so why stress. Heck, the script isn't even complicated. Now, at a language level, would I like the C committee to start looking at some of these things? Yes, but why bother hoping for miracles. 1) https://www.engadget.com/2018/07/13/aliens-colonial-marines-typo-ai/ https://www.engadget.com/2018/07/13/aliens-colonial-marines-... 2) https://www.tedunangst.com/flak/post/string-interfaces https://www.tedunangst.com/flak/post/string-interfaces
- fbender 8y agoIf I’m not mistaken, you can even have the best of both worlds in languages with proper macro support (I’m sure you know which lang I‘m talking about): The Macro call can take the string input and „desugar“ it into bitmasks / function calls / whatever you need at compile time. Then you have: 1) easily readable, string-like input; 2) built-in-your-code verification and 3) compile-time check; 4) zero-overhead execution. Just reading Ted‘s blog post gave me an idea how lang-specific libraries / (thin-layer) abstractions (or simply additional magic helper functionality) can improve upon legacy API designs (e.g. the GLX example) by using lang-specific functionality I never knew I‘d need or even cared about. Sometimes one can learn when you‘d never expect it. :D Unless I‘m mistaken and misunderstood the whole thing, please correct me in that case.
- deleted 8y ago[deleted]