Make the presence of stdin and stdout optional.
The idea behind Nuxi CloudABI is that it is targeted at (but not limited to) running networked services in a sandboxed environment. The model behind stdin, stdout and stderr is strongly focused on interactive tools in a command shell. CloudABI does not support the notion of stdin and stdout, as 'standard input/output' does not apply to services. The concept of stderr does makes sense though, as services do need some mechanism to log error messages in a uniform way. This patch extends libc++ in such a way that std::cin and std::cout and the associated <cstdio>/<cwchar> functions can be disabled through the flags _LIBCPP_HAS_NO_STDIN and _LIBCPP_HAS_NO_STDOUT, respectively. At the same time it attempts to clean up src/iostream.cpp a bit. Instead of using a single array of mbstate_t objects and hardcoding the array indices, it creates separate objects that declared next to the iostream objects and their buffers. The code is also restructured by interleaving the construction and setup of c* and wc* objects. That way it is more obvious that this is done identically. The c* and wc* objects already have separate unit tests. Make use of this fact by adding XFAILs in case libcpp-has-no-std* is set. That way the tests work in both directions. If stdin or stdout is disabled, these tests will therefore test for the absence of c* and wc*. Differential Revision: http://reviews.llvm.org/D8340 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@233275 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -740,6 +740,13 @@ extern "C" void __sanitizer_annotate_contiguous_container(
|
||||
#define _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
|
||||
#endif
|
||||
|
||||
// CloudABI is intended for running networked services. Processes do not
|
||||
// have standard input and output channels.
|
||||
#ifdef __CloudABI__
|
||||
#define _LIBCPP_HAS_NO_STDIN
|
||||
#define _LIBCPP_HAS_NO_STDOUT
|
||||
#endif
|
||||
|
||||
#if defined(__ANDROID__) || defined(__CloudABI__)
|
||||
#define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
|
||||
#endif
|
||||
|
@@ -144,34 +144,20 @@ using ::FILE;
|
||||
using ::fpos_t;
|
||||
using ::size_t;
|
||||
|
||||
#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
|
||||
using ::remove;
|
||||
using ::rename;
|
||||
using ::tmpfile;
|
||||
using ::tmpnam;
|
||||
#endif
|
||||
using ::fclose;
|
||||
using ::fflush;
|
||||
#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
|
||||
using ::fopen;
|
||||
using ::freopen;
|
||||
#endif
|
||||
using ::setbuf;
|
||||
using ::setvbuf;
|
||||
using ::fprintf;
|
||||
using ::fscanf;
|
||||
using ::printf;
|
||||
using ::scanf;
|
||||
using ::snprintf;
|
||||
using ::sprintf;
|
||||
using ::sscanf;
|
||||
#ifndef _LIBCPP_MSVCRT
|
||||
using ::vfprintf;
|
||||
using ::vfscanf;
|
||||
using ::vscanf;
|
||||
using ::vsscanf;
|
||||
#endif // _LIBCPP_MSVCRT
|
||||
using ::vprintf;
|
||||
using ::vsnprintf;
|
||||
using ::vsprintf;
|
||||
using ::fgetc;
|
||||
@@ -179,13 +165,7 @@ using ::fgets;
|
||||
using ::fputc;
|
||||
using ::fputs;
|
||||
using ::getc;
|
||||
using ::getchar;
|
||||
#if _LIBCPP_STD_VER <= 11
|
||||
using ::gets;
|
||||
#endif
|
||||
using ::putc;
|
||||
using ::putchar;
|
||||
using ::puts;
|
||||
using ::ungetc;
|
||||
using ::fread;
|
||||
using ::fwrite;
|
||||
@@ -199,6 +179,31 @@ using ::feof;
|
||||
using ::ferror;
|
||||
using ::perror;
|
||||
|
||||
#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
|
||||
using ::fopen;
|
||||
using ::freopen;
|
||||
using ::remove;
|
||||
using ::rename;
|
||||
using ::tmpfile;
|
||||
using ::tmpnam;
|
||||
#endif
|
||||
|
||||
#ifndef _LIBCPP_HAS_NO_STDIN
|
||||
using ::getchar;
|
||||
#if _LIBCPP_STD_VER <= 11
|
||||
using ::gets;
|
||||
#endif
|
||||
using ::scanf;
|
||||
using ::vscanf;
|
||||
#endif
|
||||
|
||||
#ifndef _LIBCPP_HAS_NO_STDOUT
|
||||
using ::printf;
|
||||
using ::putchar;
|
||||
using ::puts;
|
||||
using ::vprintf;
|
||||
#endif
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_CSTDIO
|
||||
|
@@ -126,24 +126,18 @@ using ::fwscanf;
|
||||
using ::swprintf;
|
||||
using ::vfwprintf;
|
||||
using ::vswprintf;
|
||||
using ::vwprintf;
|
||||
#ifndef _LIBCPP_MSVCRT
|
||||
using ::swscanf;
|
||||
using ::vfwscanf;
|
||||
using ::vswscanf;
|
||||
using ::vwscanf;
|
||||
#endif // _LIBCPP_MSVCRT
|
||||
using ::wprintf;
|
||||
using ::wscanf;
|
||||
using ::fgetwc;
|
||||
using ::fgetws;
|
||||
using ::fputwc;
|
||||
using ::fputws;
|
||||
using ::fwide;
|
||||
using ::getwc;
|
||||
using ::getwchar;
|
||||
using ::putwc;
|
||||
using ::putwchar;
|
||||
using ::ungetwc;
|
||||
using ::wcstod;
|
||||
#ifndef _LIBCPP_MSVCRT
|
||||
@@ -212,6 +206,20 @@ using ::wcrtomb;
|
||||
using ::mbsrtowcs;
|
||||
using ::wcsrtombs;
|
||||
|
||||
#ifndef _LIBCPP_HAS_NO_STDIN
|
||||
using ::getwchar;
|
||||
#ifndef _LIBCPP_MSVCRT
|
||||
using ::vwscanf;
|
||||
#endif // _LIBCPP_MSVCRT
|
||||
using ::wscanf;
|
||||
#endif
|
||||
|
||||
#ifndef _LIBCPP_HAS_NO_STDOUT
|
||||
using ::putwchar;
|
||||
using ::vwprintf;
|
||||
using ::wprintf;
|
||||
#endif
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_CWCHAR
|
||||
|
@@ -46,13 +46,17 @@ extern wostream wclog;
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
#ifndef _LIBCPP_HAS_NO_STDIN
|
||||
extern _LIBCPP_FUNC_VIS istream cin;
|
||||
extern _LIBCPP_FUNC_VIS ostream cout;
|
||||
extern _LIBCPP_FUNC_VIS ostream cerr;
|
||||
extern _LIBCPP_FUNC_VIS ostream clog;
|
||||
extern _LIBCPP_FUNC_VIS wistream wcin;
|
||||
#endif
|
||||
#ifndef _LIBCPP_HAS_NO_STDOUT
|
||||
extern _LIBCPP_FUNC_VIS ostream cout;
|
||||
extern _LIBCPP_FUNC_VIS wostream wcout;
|
||||
#endif
|
||||
extern _LIBCPP_FUNC_VIS ostream cerr;
|
||||
extern _LIBCPP_FUNC_VIS wostream wcerr;
|
||||
extern _LIBCPP_FUNC_VIS ostream clog;
|
||||
extern _LIBCPP_FUNC_VIS wostream wclog;
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
Reference in New Issue
Block a user