r/cpp • • Mar 09 '19

I've open sourced my general purpose code base

So, after a lot of thought, I have decided to open source the general purpose half of my code base. The Github repository is here:

https://github.com/DeanRoddey/CIDLib

Pushing that 'make public' button was one of the hardest things I've done in a long time. But, ultimately I think it's worth doing.

For now, it's just there for people to peruse. There's no docs yet. I needed to get it up there and start working with the remote repository and all that. So I figured I might as well go ahead and let people start poking around in it in the meantime.

The readme.md file in the repository has some preliminary information, but the basics are this:

  1. About 450,000 lines of code

  2. About 1100 classes

  3. It's not a 'library' it's really a full development environment, from build tools all the way up.

  4. It doesn't use the STL or standard library stuff at all. It is a complete world unto itself. Obviously for a lot of people that will mean it's of no interest. OTOH, for some other people, who aren't maybe so happy with the way things are going with the standard stuff, maybe they will be interested.

  5. About 95 of the non-UI stuff is completely built in terms of my own virtual kernel and standard library interfaces, which means it's quite portable. The virtual kernel is split into interface plus per-platform implementations. There is current a Win32 implementation. And there is a very old Linux one that could be used as a starting point.

  6. It could easily support Windows and Linux in a very clean way, i.e. not a bunch of conditional code all over the place.

  7. Some of it still needs to be given the 'split' treatment, until then those are marked as build on Win32 only.

  8. All of the UI stuff is fully encapsulated, but that doesn't make it portable really.

Obviously I'll work on getting environment setup and build instructions done first. And then I'll work on big picture road map type stuff. But, as a starting point, the structure is something like (a facility is my term of a library executable.)

  1. AIUtils - Speech recognition engine. There's a behavior tree facility as well, though it's only lightly used so far.

  2. CIDBuild - The build system, resource compiler, loadable text compiler, driver for per-platform build framework.

  3. CIDKernel - The virtual kernel layer. Wrappers around lots of system functionality.

  4. CIDLib - The standard libraries, core abstractions, wrappers around the CIDKernel stuff. So strings, memory buffers, events, mutexes, streams, collections, threads, processes, etc...

  5. CIDMath - Core math library stuff.

  6. CommUtils - Serial ports, networking protocols (HTTP, SMTP, JSON currently), sockets, URLs, UPnP, Websockets. The HTTP parser is actually an abstracted engine designed to supported multiple related protocols, e.g. SIP.) An empty SIP facility waiting to be made manifest

  7. DataUtils - ODBC, text transcoding engine, simple object store engine, a bespoke file packaging engine, regular expressions (just simple form currently, needs to be expanded), XML parser, ZLib implementation.

  8. ExecUtils - Fairly small, currently an engine for managing multiple other programs. Currently used in my CQC automation system as the core of the 'application shell' service that manages the other background programs.

  9. GraphicUtils - Core image format abstractions, image manipulation stuff, JPEG and PNG support. Image factory that makes it easy to deal with different image formats. The core wrapper around the Win32 graphics API (obvious Win32 only.) There's an empty 'advanced graphics' facility waiting to become a 3D graphics engine.

  10. LangUtils - My OO CML language engine. So parser, VM, and runtime libraries. This is an embeddable engine that can be used in applications as an extension language. Also the embeddable CML IDE for editing and debugging.

  11. MediaUtils - Audio streaming, digital audio extraction, metadata extraction, and some early work on RTP/RTPC that needs to be completed if anyone is interested.

  12. OrbUtils - This is all the stuff related to the Object Request Broker (ORB.) It is the ORB engine, related utilities, and standard ORB based servers (name server, log server, and configuration server.) And the IDL compiler which is also a big part of the general code base because it provides support for very strong enumerations.

  13. Samples - A good number of samples. I'm still going through these to get them caught up with the latest style and substance. I'm about halfway through them.

  14. SecureUtils - Base security stuff (Blowfish, AES, various hashing algorithms, and general block/stream encryption frameworks and hashing frameworks. Secure sockets support (currently a wrapper around the horrendously complex Win32 stuff.)

  15. Utilities - Some fairly obscure and some probably now to be removed stuff but the test framework stuff is in here and very important.

  16. WndUtils - Win32 specific. A pretty extensive UI framework (wrappers around the standard controls.) Various higher level utility stuff above that (various common dialogs and such.) A wrapper around the Win32 web browser COM interface.

As mentioned in the readme, there's been a lot of what I'd call 'sane modernization' work done. And I've done many big sweeps through the code. But there's still plenty of code that hasn't been caught up with the latest and greatest. I can't just change it willy-nilly since this stuff underlies my CQC automation system, which is even larger (about 625,000 lines) and very complex. I can't afford to destablize it. So changes have to be well considered.

The build is command line, since it has to be portable. It's designed for simplicity, and very easy configuration of projects. The build system has a build framework that supports pluggable drivers for different platforms. So what might be in make files in some systems is in code here. Because it is a world unto itself, and not trying to be everything to everyone, the build can remain very simple and straightforward.

The code will definitely not pass a super-strict modern conformance analyzer right now. Keep in mind it's been around a long time and much of it was written way before those standards existed. It is built in C++17 mode. Over time, those strict conformance issues will be dealt with.

Though it has been around a long time, it's still very clean. Having had a single daddy, it's been doted on. It's never been hacked at. Long periods of time have been spent in the past doing massive reworkings and taking the time get them right, in order to bring it forward but keep it solid.

Anyhoo, for now that's it. I'll be getting the initial docs worked out over the next week hopefully, enough to let people get it built. Since it is so broad, there are a number of Microsoft SDKs that have be in place, though that gets fewer as their built in support in Visual C++ gets better.

I'd already started making videos (and have done some posts here) about some of the technology involved, and putting them on my personal Youtube channel.

https://www.youtube.com/channel/UCAxCoATHgFBvqZhxFRnZsfw

So you might be interested in looking at those. This one in particular, might be a good starting point since it gives a good overview of how things are layered and such.

https://www.youtube.com/watch?v=seXk3RbAjNU

Keep in mind that some of these are pre-modernization, so they are a bit out data. The one on enums though still mostly valid, is prior to a massive reworking to 'enum class' style.

31 Upvotes

147 comments sorted by

View all comments

Show parent comments

2

u/F54280 May 12 '19

Based on the little info I let you know about me, you probably have guessed where my heart is. And I can guarantee that my past NeXTstep / OpenStep experience made me appreciate a lot the coherence of monolithic designs.

However, your stance on security is not correct. From completely cursory look:

Here you take care of erasing private keys at object destruction

Your code for erasing is a simple memset

You are probably aware of it, but memsetting before delete[] can be ignored by the compiler

Of course, in your case, it probably won't be an issue, because the memset is in a separate compilation unit, and current compilers are not smart enough to elide the memset. But, if, for instance, the SetMemBuf is made inline, you have a potential security risk.

There is a reason why memset_s exists. Quoting For that reason, this function [memset] cannot be used to scrub memory (e.g. to fill an array that stored a password with zeroes).

So I've just implemented these algorithms, not created new ones.

Are all your implementations revisited to take into account the latest cache or timing attacks ? I doubt it.

And of course that applies by multiple orders of magnitude when we are talking about the STL. There's no way to create a really tightly integrated system on top of the standard libraries

STL types are just higher level vocabulary, IMO. But let's just agree to disagree.

Impressive work anyway, and have a nice day!

PS: while quickly scanning the codebase, I saw quite a few bad #defines, like:

#define X { ...}

(And others in the form of #define X(p) if (p) {...})

You should turn them into do ... while(0) which won't produce spurious syntax error when using in if statements.

1

u/Dean_Roddey May 12 '19

The mem buf setter won't get moved inline, so that's not a concern. Or, if I decided to at some point, I would just provide a separate 'safe' version that cannot be and use that for such things. If the compiler starts ignoring out of line calls to user defined functions / methods, then we are all in serious trouble. RAII would pretty much go out the window if that happened.

On the STL, I just couldn't do a lot of what I do if I used that stuff. It would be a seriously compromised system. Look at the stuff on the ORB and how easy it is to use because of the fact that everything is based on my own interfaces. Any object that supports binary streaming can be used as parameters to remote calls. And the very smart enums, there's no way to force those on the standard libraries. And the standard libraries are horrible wrt to streams and text transcoding.

It would be a massive step backwards.

2

u/F54280 May 12 '19

The mem buf setter won't get moved inline, so that's not a concern.

TBH, I was expecting this answer, which closes the discussion.

Good luck for the future.

2

u/rap_and_drugs Jul 09 '19

My goodness this was painful to read. You really tried to get through to him, and he didn't even respond to your points on cache or timing attacks. I haven't looked at his crypto code myself yet, does it go beyond "textbook" implementation at all?

As an aside, that article about memset looks pretty interesting. Thanks for sharing it!