]> pd.if.org Git - pdclib.old/blob - Readme.rst
PDCLIB-2 PDCLIB-9: As an extension, add the POSIX thread-local locale API
[pdclib.old] / Readme.rst
1 PDCLib - the `Public Domain C Library <http://pdclib.e43.eu>`_\r
2 ================================\r
3 \r
4 What is it\r
5 ----------\r
6 \r
7 This is a C Standard Library - what's defined in ISO/IEC 9899 "Information \r
8 technology — Programming languages — C" or extensions to the above defined in\r
9 ISO/IEC 14882 "Information technology — Programming languages — C++". A few \r
10 extensions may optionally be provided.\r
11 \r
12 License\r
13 -------\r
14 \r
15 Written in \r
16  * 2003-2012 by Martin "Solar" Baute,\r
17  * 2012-     by Owen Shepherd\r
18 \r
19 To the extent possible under law, the author(s) have dedicated all copyright \r
20 and related and neighboring rights to this software to the public domain \r
21 worldwide. This software is distributed without any warranty.\r
22 \r
23 You should have received a copy of the CC0 Public Domain Dedication along with \r
24 this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.\r
25 \r
26     **Exception:** Portions of the test suite are under different licenses. \r
27     Where this is the case, it is clearly noted in the relevant location.\r
28 \r
29     The license of this code has no bearing upon the licensing of the built \r
30     library (as it does not comprise part of it).\r
31 \r
32     At the time this was written, this exception only applies to portions of the\r
33     printf test suite, which are released under the terms of the 2-clause BSD\r
34     license (see testing/printf_testcases.h for full details)\r
35 \r
36 Terms for extensions\r
37 --------------------\r
38 Extensions are permitted only if they pass the following tests:\r
39 \r
40 Pre-existing wide usage\r
41     On most systems, the system C library must maintain its application binary\r
42     interface for long periods of time (potentially eternity). Existing wide \r
43     usage demonstrates utility\r
44 \r
45 In keeping with the spirit of the standard\r
46     The extension should respect the design, intentions and conventions of the C\r
47     standard, and feel like a natural extension to the offered capability. \r
48 \r
49 Not system dependent\r
50     The extension should not add any additional dependencies on the underlying \r
51     system\r
52 \r
53 Non-duplicative\r
54     Extensions should not duplicate functionality already provided by the \r
55     standard\r
56 \r
57 Disabled by default\r
58     PDCLib will always default to a "strictly conforming" mode exposing only\r
59     functionality offered by the version of the standard specified by the\r
60     __STDC_VERSION__, __STDC__ or __cplusplus macro; extensions will only be \r
61     exposed when requested.\r
62 \r
63 Additionally, extra consideration will be given to extensions which are \r
64 difficult or impossible to implement without access to internal structures of \r
65 the C library.\r
66 \r
67 Conrete Examples:\r
68 \r
69 strndup\r
70     **Included.** strndup is easily defined in terms of existing standard \r
71     functions, follows  the standard's naming conventions, is in wide usage, and\r
72     does not duplicate  features already provided.\r
73 \r
74 posix_memalign\r
75     **Rejected.** Has existing wide usage, is not system dependent (can be \r
76     implemented, albeit inefficiently, on top of malloc), but naming is not \r
77     consistent with the naming used by the standard (posix_ prefix) and \r
78     duplicates functionality provided by the C11 standard\r
79 \r
80 open, close, read, write, ...\r
81     **Rejected.** Widely used, but duplicates functionality provided by the \r
82     standard (FILE objects set to be unbuffered), and not able to implement full\r
83     semantics (e.g. in relation to POSIX fork and other functionality from the \r
84     same defining standard) in a platform-neutral way\r
85 \r
86 strl*\r
87     **Rejected.** Used somewhat widely, in keeping with the standard, not system\r
88     dependent, but duplicative of functionality provided by (optional) Annex K \r
89     of the C standard. \r
90 \r
91 flockfile, funlockfile, getc_unlocked, putc_unlocked, fwrite_unlocked, ...\r
92     **Accepted.** Provide functionality not provided by the standard (and \r
93     useful in light of the C11 addition of threading). Can be trivially \r
94     implemented in terms of the <threads.h> mutex functions and the bodies of \r
95     the existing I/O functions, and impossible to implement externally\r
96 \r
97 Internals\r
98 ---------\r
99 \r
100 As a namespace convention, everything (files, typedefs, functions,\r
101 macros) not defined in ISO/IEC 9899 is prefixed with _PDCLIB.\r
102 The standard defines any identifiers starting with '_' and a capital\r
103 letter as reserved for the implementation, and since the chances of\r
104 your compiler using an identifier in the _PDCLIB range are slim,\r
105 any strictly conforming application should work with this library.\r
106 \r
107 PDCLib consists of several parts:\r
108 \r
109 1) standard headers;\r
110 2) implementation files for standard functions;\r
111 3) internal header files keeping complex stuff out of the standard\r
112    headers;\r
113 4) the central, platform-specific file _PDCLIB_config.h;\r
114 5) platform-specific implementation files;\r
115 \r
116 The standard headers (in ./includes/) only contain what they are\r
117 defined to contain. Where additional logic or macro magic is\r
118 necessary, that is deferred to the internal files. This has been done\r
119 so that the headers are actually educational as to what they provide\r
120 (as opposed to how the library does it).\r
121 \r
122 There is a seperate implementation file (in ./function/{header}/) for\r
123 every function defined by the standard, named {function}.c. Not only\r
124 does this avoid linking in huge amounts of unused code when you use\r
125 but a single function, it also allows the optimization overlay to work\r
126 (see below).\r
127 \r
128 (The directory ./functions/_PDCLIB/ contains internal and helper\r
129 functions that are not part of the standard.)\r
130 \r
131 Then there are internal header files (in ./internal/), which contain\r
132 all the "black magic" and "code fu" that was kept out of the standard\r
133 headers. You should not have to touch them if you want to adapt PDCLib\r
134 to a new platform. Note that, if you *do* have to touch them, I would\r
135 consider it a serious design flaw, and would be happy to fix it in the\r
136 next PDCLib release. Any adaption work should be covered by the steps\r
137 detailed below.\r
138 \r
139 For adapting PDCLib to a new platform (the trinity of CPU, operating\r
140 system, and compiler), make a copy of ./platform/example/ named\r
141 ./platform/{your_platform}/, and modify the files of your copy to suit\r
142 the constraints of your platform. When you are done, copy the contents\r
143 of your platform directory over the source directory structure\r
144 of PDCLib (or link them into the appropriate places). That should be\r
145 all that is actually required to make PDCLib work for your platform.\r
146 \r
147 Future directions\r
148 -----------------\r
149 Obviously, full C89, C99 and C11 conformance; and full support for the \r
150 applicable portions of C++98, C++03 and C++11 (the version which acomplishes \r
151 this will be christened "1.0").\r
152 \r
153 Support for "optimization overlays." These would allow efficient \r
154 implementations of certain functions on individual platforms, for example \r
155 memcpy, strcpy and memset. This requires further work to only compile in one\r
156 version of a given function.\r
157 \r
158 Post 1.0, support for C11 Annexe K "Bounds checking interfaces"\r
159 \r
160 Development Status\r
161 ------------------\r
162 \r
163 ``v0.1 - 2004-12-12``\r
164     Freestanding-only C99 implementation without any overlay, and missing\r
165     the INTN_C() / UINTN_C() macros. <float.h> still has the enquire.c\r
166     values hardcoded into it; not sure whether to include enquire.c in the\r
167     package, to leave <float.h> to the overlay, or devise some parameterized\r
168     macro magic as for <limits.h> / <stdint.h>. Not thoroughly tested, but\r
169     I had to make the 0.1 release sometime so why not now.\r
170 \r
171 ``v0.2 - 2005-01-12``\r
172     Adds implementations for <string.h> (excluding strerror()), INTN_C() /\r
173     UINTN_C() macros, and some improvements in the internal headers.\r
174     Test drivers still missing, but added warnings about that.\r
175 \r
176 ``v0.3 - 2005-11-21``\r
177     Adds test drivers, fixes some bugs in <string.h>.\r
178 \r
179 ``v0.4 - 2005-02-06``\r
180     Implementations for parts of <stdlib.h>. Still missing are the floating\r
181     point conversions, and the wide-/multibyte-character functions.\r
182 \r
183 ``v0.4.1 - 2006-11-16``\r
184     With v0.5 (<stdio.h>) taking longer than expected, v0.4.1 was set up as\r
185     a backport of bugfixes in the current development code.\r
186 \r
187     - #1 realloc( NULL, size ) fails\r
188     - #2 stdlib.h - insufficient documentation\r
189     - #4  Misspelled name in credits\r
190     - #5  malloc() splits off too-small nodes\r
191     - #6  qsort() stack overflow\r
192     - #7  malloc() bug in list handling\r
193     - #8  strncmp() does not terminate at '\0'\r
194     - #9  stdint.h dysfunctional\r
195     - #10 NULL redefinition warnings\r
196 \r
197 ``v0.5 - 2010-12-22``\r
198     Implementations for <inttypes.h>, <errno.h>, most parts of <stdio.h>,\r
199     and strerror() from <string.h>.\r
200     Still no locale / wide-char support. Enabled all GCC compiler warnings I\r
201     could find, and fixed everything that threw a warning. (You see this,\r
202     maintainers of Open Source software? No warnings whatsoever. Stop telling\r
203     me it cannot be done.) Fixed all known bugs in the v0.4 release.\r
204 \r
205 Near Future\r
206 -----------\r
207 Current development directions are:\r
208 \r
209 Implement portions of the C11 standard that have a direct impact on the way \r
210 that PDCLib itself is built. For example, in order to support multithreading,\r
211 PDCLib needs a threading abstraction; therefore, C11's thread library is being\r
212 implemented to provide the backing for this (as there is no purpose in \r
213 implementing two abstractions)\r
214 \r
215 Cleanup portions of <stdio.h>, particularly the backend. _PDCLIB_fillbuffer and\r
216 _PDCLIB_flushbuffer in particular do not feel 'well' factored and need to know\r
217 too much about FILE's internals. \r
218 \r
219 Modularize the library somewhat. This can already be seen with components under \r
220 "opt/". This structure is preliminary; it will likely change as the process \r
221 continues.