Import C++ Standard Template Library

You can now use the hardest fastest and most dangerous language there is
with Cosmopolitan. So far about 75% of LLVM libcxx has been added. A few
breaking changes needed to be made to help this go smoothly.

- Rename nothrow to dontthrow
- Rename nodiscard to dontdiscard
- Add some libm functions, e.g. lgamma, nan, etc.
- Change intmax_t from int128 to int64 like everything else
- Introduce %jjd formatting directive for int128_t
- Introduce strtoi128(), strtou128(), etc.
- Rename bsrmax() to bsr128()

Some of the templates that should be working currently are std::vector,
std::string, std::map, std::set, std::deque, etc.
This commit is contained in:
Justine Tunney 2022-03-22 05:51:41 -07:00
parent 5022f9e920
commit 868af3f950
286 changed files with 123987 additions and 507 deletions

View file

@ -21,6 +21,6 @@
/**
* Delegates to mkotempsm() w/ owner-only non-execute access.
*/
nodiscard int mkostemps(char *template, int suffixlen, unsigned flags) {
dontdiscard int mkostemps(char *template, int suffixlen, unsigned flags) {
return mkostempsm(template, suffixlen, flags, 0600);
}

View file

@ -74,8 +74,8 @@ static uint64_t g_mkostemps_reseed;
* or -1 w/ errno
* @see kTmpPath
*/
nodiscard int mkostempsm(char *template, int suffixlen, unsigned flags,
int mode) {
dontdiscard int mkostempsm(char *template, int suffixlen, unsigned flags,
int mode) {
if (g_mkostemps_reseed++ % RESEED == 0) g_mkostemps_rand = rand64();
return mkostempsmi(template, suffixlen, flags, &g_mkostemps_rand, mode, open);
}

View file

@ -22,9 +22,9 @@
* Formats and writes string to stdout.
*
* Cosmopolitan supports most of the standard formatting behaviors
* described by `man 3 printf`, in addition to the following:
* described by `man 3 printf`, in addition to the following
*
* - `%jd`, `%jx`, etc. are {,u}intmax_t which in Cosmopolitan is 128-bit.
* - `%jjd`, `%jjx`, etc. are {,u}int128_t (cosmopolitan only)
*
* - `%'d` or `%,d` may be used to insert thousands separators. The prior is
* consistent with C; the latter is consistent with Python.

View file

@ -57,9 +57,9 @@ int putchar(int);
int puts(const char *);
ssize_t getline(char **, size_t *, FILE *) paramsnonnull();
ssize_t getdelim(char **, size_t *, int, FILE *) paramsnonnull();
FILE *fopen(const char *, const char *) paramsnonnull() nodiscard;
FILE *fdopen(int, const char *) paramsnonnull() nodiscard;
FILE *fmemopen(void *, size_t, const char *) paramsnonnull((3)) nodiscard;
FILE *fopen(const char *, const char *) paramsnonnull() dontdiscard;
FILE *fdopen(int, const char *) paramsnonnull() dontdiscard;
FILE *fmemopen(void *, size_t, const char *) paramsnonnull((3)) dontdiscard;
FILE *freopen(const char *, const char *, FILE *) paramsnonnull((2, 3));
size_t fread(void *, size_t, size_t, FILE *) paramsnonnull((4));
size_t fwrite(const void *, size_t, size_t, FILE *) paramsnonnull((4));
@ -90,16 +90,31 @@ int systemexec(const char *);
*/
int printf(const char *, ...) printfesque(1)
paramsnonnull((1)) nothrow nocallback;
int vprintf(const char *, va_list) paramsnonnull() nothrow nocallback;
paramsnonnull((1)) dontthrow nocallback;
int vprintf(const char *, va_list) paramsnonnull() dontthrow nocallback;
int fprintf(FILE *, const char *, ...) printfesque(2)
paramsnonnull((1, 2)) nothrow nocallback;
int vfprintf(FILE *, const char *, va_list) paramsnonnull() nothrow nocallback;
paramsnonnull((1, 2)) dontthrow nocallback;
int vfprintf(FILE *, const char *, va_list)
paramsnonnull() dontthrow nocallback;
int scanf(const char *, ...) scanfesque(1);
int vscanf(const char *, va_list);
int fscanf(FILE *, const char *, ...) scanfesque(2);
int vfscanf(FILE *, const char *, va_list);
int fwprintf(FILE *, const wchar_t *, ...);
int fwscanf(FILE *, const wchar_t *, ...);
int swprintf(wchar_t *, size_t, const wchar_t *, ...);
int swscanf(const wchar_t *, const wchar_t *, ...);
int vfwprintf(FILE *, const wchar_t *, va_list);
int vfwscanf(FILE *, const wchar_t *, va_list);
int vswprintf(wchar_t *, size_t, const wchar_t *, va_list);
int vswscanf(const wchar_t *, const wchar_t *, va_list);
int vwprintf(const wchar_t *, va_list);
int vwscanf(const wchar_t *, va_list);
int wprintf(const wchar_t *, ...);
int wscanf(const wchar_t *, ...);
int fwide(FILE *, int);
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § standard i/o » optimizations
*/

View file

@ -4,16 +4,17 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
nodiscard FILE *tmpfile(void);
nodiscard int mkstemp(char *);
nodiscard int mkostemp(char *, unsigned);
nodiscard int mkstemps(char *, int);
nodiscard int mkostemps(char *, int, unsigned);
nodiscard int mkostempsm(char *, int, unsigned, int);
dontdiscard FILE *tmpfile(void);
dontdiscard int mkstemp(char *);
dontdiscard int mkostemp(char *, unsigned);
dontdiscard int mkstemps(char *, int);
dontdiscard int mkostemps(char *, int, unsigned);
dontdiscard int mkostempsm(char *, int, unsigned, int);
compatfn char *mktemp(char *);
char *tmpnam(char *);
int mkostempsmi(char *, int, unsigned, uint64_t *, int,
int (*)(const char *, int, ...)) hidden nodiscard;
int (*)(const char *, int, ...)) hidden dontdiscard;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */