User Tools

Site Tools


pdclib:drawingboard

This is an old revision of the document!


Drawing Board

For quite some time I managed to keep the number of “construction sites” in PDCLib to a minimum. Sure, there were plenty of unfinished parts (floating point, multibyte / wide characters, locales, …), but my actual work was focussed on one part of the library only.

Unfortunately, I have strayed a bit from that path, and ended up with more “action items” than I am comfortable with. That is why I opened this “drawing board”, to write down my thoughts about all those “construction sites”, getting them organized, and make the path onward a bit clearer.

freopen

Something that came to my attention when adding threading support to <stdio.h> was my somewhat brittle implementation of freopen(). A failed fopen() would leave the (now closed) stream in the list of open files, which will give undefined behaviour on exit. Also I ran into some trouble figuring out how to lock the stream and the file list in a stable, non-deadlocking way.

Also, as I am writing this, I am not sure carrying over the buffering as I currently do is correct. This function requires reimplementation.

Thread-local Storage

With <threads.h> we get the ability to handle thread-local storage.

One thing that is supposed to be thread-local is errno. Since we already wrap access to errno through calls to _PDCLIB_errno_func(), that should not be all that difficult. However it will require initializing things, and we don't get to call functions from _PDCLIB_stdinit.c

I also need to look into locale information, which IIRC is also thread-local (with the same initialization issue).

Locales

The idea was to write a function _PDCLIB_load_lc_<category> for each locale category (collate, ctype, monetary, numeric, time, messages). This worked rather well at first. For ctype I delved into Unicode, getting the “right” character classes directly from the Unicode database (auxiliary/uctype).

Then I wanted to do the same for collate (sorting equivalence), and this was where I got stuck. Unicode collation is a pretty big subject in the Unicode standard, and information about it is scattered over multiple chapters, even multiple documents. In a kind of repeat performance of the block I had with <stdio.h>, I did not find the necessary uninterrupted time to really grasp what was before me.

The thing to do here would be to identify which data from which Unicode input files I would need, in which format, in order to implement (initially) strcoll and strxfrm. Ideally, whatever architecture I come up with would also serve for (upcoming) multibyte and wide character collation.

time.h

Several time functions are not implemented yet. The gmtime / localtime / mktime group requires timezone information (which in turn requires me looking into the timezone database for proper support code). For asctime / ctime I need alternative access to the “C” strings in the time locale category, because they are both defined locale-independent.

Floating Point Support for printf

A request from downstream was to add FP support to my printf() implementation (which currently breaks for %f/%g et al. because it doesn't draw the accompanying value from the stack – not nice!).

I got a good introduction to the Dragon4 binary-to-string conversion algorithm as well as the paper for the Grisu3 small integer optimization, but this would be another major construction site (touching <math.h> and <fenv.h> matters as well), and I feel it would be just one thing too many to tackle at this point.

pdclib/drawingboard.1569325735.txt.gz · Last modified: 2019/09/24 13:48 by solar