simpledisplay getting dynamic loads, terminal gui gracefully degrades, i muse on scope raii classes

Posted 2020-06-29

Core D Development Statistics

In the community

Community announcements

See more at the announce forum.

What Adam is working on

Continuing with last week's dynamic load thing, I converted simpledisplay.d to dynamic load its dependencies (not yet formally released) and then adjusted terminal.d's newish embedded emulator to check the flag and fallback to normal terminal if the gui is impossible.

The implementation uses static constructors to load, but if the library is not there, it sets all the library pointers to the C abort function and sets a __gshared bool flag that can be checked later. If your program checks that flag, you can avoid all the other functions, and if not, you get the runtime error (and the XDisplayConnection.get method will throw instead of abort, similar to if X was simply not available, so you should be expecting that to potentially fail anyway).

The benefit here is you can write a single binary that uses gui if needed and doesn't if not; no additional build time or load time needs. A script language, for example, using simpledisplay in its library, can still run on a server without X installed, yet use the gui when running elsewhere.

Adam's musing

RAII classes in D (aka scoped!) are actually pretty easy to use, but one of the difficulties is managing the reference - in order to implicitly cast to any interfaces, you need to alias this to the inner reference. Then any information in the type system about ownership is lost; since classes are typically GC'd in D, most user functions are liable to assume they are allowed to hold to it.

Well, the new DIP 25 stuff coming through, the return ref thing, might acutally help with that. I kinda wanna give it a try and see how it goes.