Adam's dynamic link transition
Posted 2020-06-22
Blog
Articles- String interpolation DIP prototype
- terminal inline syntax highlighting, sdpy fonts improved
- January 18, 2021
- gdb debugging tips
- A little work on sdpy/terminal interop and apng debugging
- New plain tcp fiber socket class (with "how it works" docs), new arsd docs started, new dub subpackages in arsd. Also Turkish newsgroups added to forum.dlang.org
- Little audio player in D
- Thoughts on tutorial writing benefits, D marketing, and some simpledisplay.d improvements.
- arsd 9.0 rollup release, my thoughts on "google it" culture and related practices
- dpldocs.info cross-package search finally released! and more terminal getline enhancements
- I did a dconf livestream!
- New selective mouse input in terminal stack, Xft used in simpledisplay to improve TrueType font support
- simpleaudio now has playOgg, Mp3, Wav with resampling and can access multiple soundcards on Linux, adrdox gets ddoc on function params
- Weekend experiment: declarative GUI in D
- October 26, 2020
- My DConf livestream sneak preview
- Off topic jrpg video game review
- My thoughts on breakage, and I'll be in DConf Online 2020
- cgi.d hybrid server basically working, terminal.d can redirect stdout to a window if requested
- Some talk on cgi.d in benchmarks
- September 14, 2020
- New D update "dwidder" website launched, making-of post here
- white noise app in D
- More modern opengl in simpledisplay, document undocumented on dpldocs.info, tip on default template args
- Xlib taskbar in D
- D Tetris running on Webassembly
- Tetris in D
- Zero-runtime classes
- DConf online in the works for Nov 21-22, image copy/paste coming to sdpy soon
- July 13, 2020
- July 6, 2020
- simpledisplay getting dynamic loads, terminal gui gracefully degrades, i muse on scope raii classes
- Adam's dynamic link transition
- June 15, 2020
- June 8, 2020
- June 1, 2020
- foot pedal and midi fun, some dmd speed enhancements. Forum argues about @safe by default on extern.
- May 18, 2020
- simpleaudio dev work, rasp pi gpio module, static foreach rant, gcc 10's D support upped
- May 4, 2020
- my http more compatible with ssl, script+jsvar can do subclasses of D objects
- i want to make a jrpg, and have eye damage.
- Dustmite post on official blog
- What if I were dictator?
- March 30, 2020
- terminal.d with built-in emulator option releaed
- Online DConf in the works
- Dconf 2020 cancelled, Adam plays with terminal gui integration
- March 2, 2020
- some adrdox/dpldocsinfo updates
- terminal.d gets clipboard functions, ldc 1.20 out.
- DConf keynote speaker announced: Lua architect Roberto Ierusalimschy, Named args DIP discussed
- February 3, 2020
- Adam's terminal suite explained
- Understanding mixin templates, terminal.d improvements
- My attribute-by-default proposal. Also dmd 2.090 came out.
- DConf 2020 announced: June 17-20 in London. @safe by default debated. Adam did: Android, JNI, WebSocket in arsd libs
- tar.xz, --DRT tip, dom bug fixes, more Android and JNI, link to old phobos docs
- LDC 1.19 - Android, AVR. My rant on tests, update on JNI and COM.
- Walter's string interpolation proposal is OK but not great. My Android thing nearing beta release. dub downtime explained.
- Android project update, introduction to arsd.jni
- New pattern about interface contracts
- Adam shares Windows console secrets - DO NOT USE chcp!!
- Adam's rant on benchmarks
- Socket tutorial
- November 4, 2019
- October 28, 2019
- arsd package updates, forum nonsense
- Update on Android
- Adam does iOS "goodbye world"
- September 30, 2019
- D turns 20, Adam rants on software freedom
- Named arg DIPs and my thoughts on code organization
- September 9, 2019
- I wrote about mixin templates vs string mixins on Stack Overflow
- August 26, 2019
- Bug bounty in D again - my hot take, on reusing code, a fun picture, my tentative plan for the next month
- Time invested is worth a lot
- cgi.d's new scheduler, static this tricks
- July 29, 2019
- July 22, 2019
- Solving vs managing problems
- A big week in the arsd repo
- July 1, 2019
- June 24, 2019
- June 17, 2019
- CRTP thoughts, named arguments DIP review, DConf videos now on youtube
- musings on hybrid CT/RT tests, some more progress on new web framework
- a little more webassembly
- May 20, 2019
- Adam's string interpolation proposal
- DMD 2.086 live, GCC 9 with D support formally released, DConf coming soon, links to posts on builder pattern and disallowing implicit conversions with templates, and 2d array op overloads
- template constraint error improvements coming?
- dmd 2.086 beta, dstep 1.0 released, Adam works on memory usage
- obj-c and webassembly report, tips on is expressions linked.
- new ldc, new dmd, dpp on the blog
- D's future discussed in forums
- LDC beta, DConf blog link, Adam introduces gamehelpers.d
- March 18, 2019
- LDC 1.15.0-beta1, responsive design rant
- dmd 2.085.0 released
- Obj-C interop and D without druntime code to copy/paste
- dmd beta, more info coming next time, demo of new web framework initial prototype
- automatic web interface discussion, reflection tips and tricks
- Adam busy with weather and a move, lots of community announcements
- January 28, 2019
- Working on official blog 2018 retro, C++ new wrapped, dmd reading zips?
- dmd obj-c growing, Adam static foreaches an interface to RPC
- dmd 2.084, hope for future, but busy non-D week for me
- IDE tools released, my cgi.d gets new features
- DConf announced, tip, Adam rants: mouse trap
- This Week in D is back!
Been busy work work but will tell a brief tale about static to dynamic link transitioning in D code.
Core D Development Statistics
In the community
Community announcements
See more at the announce forum.
Long time without writing, I know, been busy with a variety of things.
What Adam is working on
One of the small things I did in the last few weeks is convert some more static bindings do dynamic ones. Doing this purely by hand is a bit of a pain, since D's syntaxes are pretty different and the loading is a little repetitive:
With static bindings:
With dynamic bindings:
It isn't the biggest of problems, but it is a little obnoxious since you need to move the name in the declaration, then repeat it thrice in the loader. (Actually, and this might be heresy, but I kinda like the C function pointer syntax at times like this.) Moreover, I extern(C)'d the whole thing, whereas technically I really only want the function pointer types to have the extern, not the variables themselves, but that takes even more lines to separate out and I'm the laziest. Isn't there any simpler way to expedite this migration? Well, I have an idea:
Now, it doesn't handle lazy loading - you need to use a module ctor or an explicit call to the load function. But the rest of your "before" code cotinues to work just as well after the migration (well, aside from possible thread issues, but you could take the pointers out of TLS and initialize ahead of time and should be fine like that).
I considered trying to lazy load all the pointers on demand, initializing it to a thunk that actually loads the library then retries the call transparently to the user. But I haven't made it work to actually do that *reliably* yet without actually generating a fair amount of code and hurting compile times. I imagine it should be possible to write a generic naked asm procedure that does the trick, including thread safety, but I need to spend more time on it than I have right now and just being like shared static this() { load; } is so much simpler lol.
Anyway, I haven't used this in the real world yet, but I plan to try soon: I want to change simpledisplay.d to dynamic link xlib and friends on Linux. I figure its static ctor will try to load the libs and if it fails, just set a flag you can explicitly check and fall back if needed. Then you also see if the X connection succeeds and if so, use it, but if not, you can carry on without it (the get connection function will also check that flag and throw if necessary). I'll also make terminal.d's embedded emulator option use this check so it can gracefully degrade back to a normal terminal if needed (this will prolly be configurable in a flag setting too). A fair bit of work to bring it all together but I anticipate no serious problems - and this little interface loader trick makes it less tedious to do across all the various functions simpledisplay.d uses.
(sometimes I am tempted to move from xlib to speaking the protocol directly (think: xcb), which would also accomplish this goal, among others actually, it is just a lot of legacy code to transition. Again, laziness.
The one somewhat scary thing is this would be a potentially scary change: your code might compile on a system then segfault at runtime because of the unloaded library. I think I'll at least put in a default abort thunk to give a nicer error message to the user in the event of this happening. But while it is a change in a sense, it is really just a move of one type of error to another.
BTW people have asked me "why not use derelict/bindbc?" and... I actually don't understand what value they are supposed to provide. Maybe I'm just not reading the code and docs right but it seems to me those libs are really just a very thin wrapper around the OS apis and a set of conventions on how to copy/paste names. Doesn't look like it would help with transitioning existing code and tbh I'm not even sure if it would help with all fresh code either.
Well, I'm hoping to get back to writing next week, maybe talking about module-based versioning or something like that, or a how-to on stdout redirect code, but no promises... been pretty busy with work and nothing much to share in public about it in the near term.