From 3173f319e2aaeb9df6963c37f7209bed90762269 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 27 Jul 2022 00:49:01 +0800 Subject: set stdio buffer size --- core/src/xmake/io/stdfile.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/core/src/xmake/io/stdfile.c b/core/src/xmake/io/stdfile.c index 4838ebb0f..6f08c643c 100644 --- a/core/src/xmake/io/stdfile.c +++ b/core/src/xmake/io/stdfile.c @@ -78,6 +78,38 @@ static tb_size_t xm_io_stdfile_isatty(tb_size_t type) if (answer) type |= XM_IO_FILE_FLAG_TTY; return type; } + +static tb_void_t xm_io_stdfile_init_buffer(tb_size_t type) +{ +#if defined(TB_CONFIG_OS_WINDOWS) + // TODO +#else + tb_int_t size = 0; + tb_char_t data[256]; + switch (type) + { + case XM_IO_FILE_TYPE_STDIN: + { + if (tb_environment_first("XMAKE_STDIN_NBUF", data, sizeof(data)) && ((size = tb_stoi32(data)) > 0)) + setvbuf(stdin, tb_null, _IONBF, 0); + } + break; + case XM_IO_FILE_TYPE_STDOUT: + { + if (tb_environment_first("XMAKE_STDOUT_NBUF", data, sizeof(data)) && ((size = tb_stoi32(data)) > 0)) + setvbuf(stdout, tb_null, _IONBF, 0); + } + break; + case XM_IO_FILE_TYPE_STDERR: + { + if (tb_environment_first("XMAKE_STDERR_NBUF", data, sizeof(data)) && ((size = tb_stoi32(data)) > 0)) + setvbuf(stderr, tb_null, _IONBF, 0); + } + break; + } +#endif +} + static xm_io_file_t* xm_io_stdfile_new(lua_State* lua, tb_size_t type) { // init stdfile @@ -106,6 +138,9 @@ static xm_io_file_t* xm_io_stdfile_new(lua_State* lua, tb_size_t type) file->type = xm_io_stdfile_isatty(type); file->encoding = TB_CHARSET_TYPE_UTF8; + // init stdio buffer + xm_io_stdfile_init_buffer(type); + // init the read/write line cache buffer tb_buffer_init(&file->rcache); tb_buffer_init(&file->wcache); -- cgit v1.3.1 From 75f38ceadc5628f723d5a78d0c14cf61f24f8cd5 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 27 Jul 2022 07:13:54 +0800 Subject: Update stdfile.c --- core/src/xmake/io/stdfile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/xmake/io/stdfile.c b/core/src/xmake/io/stdfile.c index 6f08c643c..1fce85f33 100644 --- a/core/src/xmake/io/stdfile.c +++ b/core/src/xmake/io/stdfile.c @@ -90,19 +90,19 @@ static tb_void_t xm_io_stdfile_init_buffer(tb_size_t type) { case XM_IO_FILE_TYPE_STDIN: { - if (tb_environment_first("XMAKE_STDIN_NBUF", data, sizeof(data)) && ((size = tb_stoi32(data)) > 0)) + if (tb_environment_first("XMAKE_STDIN_NBUF", data, sizeof(data)) && ((size = tb_stoi32(data)) >= 0)) setvbuf(stdin, tb_null, _IONBF, 0); } break; case XM_IO_FILE_TYPE_STDOUT: { - if (tb_environment_first("XMAKE_STDOUT_NBUF", data, sizeof(data)) && ((size = tb_stoi32(data)) > 0)) + if (tb_environment_first("XMAKE_STDOUT_NBUF", data, sizeof(data)) && ((size = tb_stoi32(data)) >= 0)) setvbuf(stdout, tb_null, _IONBF, 0); } break; case XM_IO_FILE_TYPE_STDERR: { - if (tb_environment_first("XMAKE_STDERR_NBUF", data, sizeof(data)) && ((size = tb_stoi32(data)) > 0)) + if (tb_environment_first("XMAKE_STDERR_NBUF", data, sizeof(data)) && ((size = tb_stoi32(data)) >= 0)) setvbuf(stderr, tb_null, _IONBF, 0); } break; -- cgit v1.3.1 From 154a8add02e1df42beab6e5073f97298d924b33e Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 27 Jul 2022 22:32:06 +0800 Subject: pass size --- core/src/xmake/io/stdfile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/xmake/io/stdfile.c b/core/src/xmake/io/stdfile.c index 1fce85f33..549b01112 100644 --- a/core/src/xmake/io/stdfile.c +++ b/core/src/xmake/io/stdfile.c @@ -91,19 +91,19 @@ static tb_void_t xm_io_stdfile_init_buffer(tb_size_t type) case XM_IO_FILE_TYPE_STDIN: { if (tb_environment_first("XMAKE_STDIN_NBUF", data, sizeof(data)) && ((size = tb_stoi32(data)) >= 0)) - setvbuf(stdin, tb_null, _IONBF, 0); + setvbuf(stdin, tb_null, _IONBF, size); } break; case XM_IO_FILE_TYPE_STDOUT: { if (tb_environment_first("XMAKE_STDOUT_NBUF", data, sizeof(data)) && ((size = tb_stoi32(data)) >= 0)) - setvbuf(stdout, tb_null, _IONBF, 0); + setvbuf(stdout, tb_null, _IONBF, size); } break; case XM_IO_FILE_TYPE_STDERR: { if (tb_environment_first("XMAKE_STDERR_NBUF", data, sizeof(data)) && ((size = tb_stoi32(data)) >= 0)) - setvbuf(stderr, tb_null, _IONBF, 0); + setvbuf(stderr, tb_null, _IONBF, size); } break; } -- cgit v1.3.1 From 7e53425e7c9c804a7a2009dbf41cff56f6024964 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 27 Jul 2022 23:47:14 +0800 Subject: improve stdio --- core/src/xmake/io/stdfile.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/core/src/xmake/io/stdfile.c b/core/src/xmake/io/stdfile.c index 549b01112..4b830ccac 100644 --- a/core/src/xmake/io/stdfile.c +++ b/core/src/xmake/io/stdfile.c @@ -34,6 +34,8 @@ # include "iscygpty.c" #else # include +# include +# include #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -84,28 +86,15 @@ static tb_void_t xm_io_stdfile_init_buffer(tb_size_t type) #if defined(TB_CONFIG_OS_WINDOWS) // TODO #else - tb_int_t size = 0; tb_char_t data[256]; - switch (type) + if (tb_environment_first("XMAKE_STDOUT_LINEFLUSH", data, sizeof(data))) { - case XM_IO_FILE_TYPE_STDIN: - { - if (tb_environment_first("XMAKE_STDIN_NBUF", data, sizeof(data)) && ((size = tb_stoi32(data)) >= 0)) - setvbuf(stdin, tb_null, _IONBF, size); - } - break; - case XM_IO_FILE_TYPE_STDOUT: - { - if (tb_environment_first("XMAKE_STDOUT_NBUF", data, sizeof(data)) && ((size = tb_stoi32(data)) >= 0)) - setvbuf(stdout, tb_null, _IONBF, size); - } - break; - case XM_IO_FILE_TYPE_STDERR: - { - if (tb_environment_first("XMAKE_STDERR_NBUF", data, sizeof(data)) && ((size = tb_stoi32(data)) >= 0)) - setvbuf(stderr, tb_null, _IONBF, size); - } - break; + struct stat stats; + tb_int_t size = BUFSIZ; + int fileno(FILE*); + if (fstat(fileno(stdout), &stats) != -1) + size = stats.st_blksize; + setvbuf(stdout, tb_null, _IOLBF, size); } #endif } -- cgit v1.3.1 From 052592ef62dc4d868a8ad27b7aa6b93605e77586 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 28 Jul 2022 00:38:04 +0800 Subject: remove env --- .github/workflows/freebsd.yml | 2 +- core/src/xmake/io/stdfile.c | 21 ++++++++------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/.github/workflows/freebsd.yml b/.github/workflows/freebsd.yml index e9c55944d..9a81d1a6c 100644 --- a/.github/workflows/freebsd.yml +++ b/.github/workflows/freebsd.yml @@ -27,7 +27,7 @@ jobs: copyback: false prepare: pkg install -y curl unzip gmake llvm gsed bash perl5 run: | - gmake -j4 + gmake gmake install export XMAKE_ROOT=y xrepo --version diff --git a/core/src/xmake/io/stdfile.c b/core/src/xmake/io/stdfile.c index 4b830ccac..25364d9c7 100644 --- a/core/src/xmake/io/stdfile.c +++ b/core/src/xmake/io/stdfile.c @@ -81,21 +81,16 @@ static tb_size_t xm_io_stdfile_isatty(tb_size_t type) return type; } +// @see https://github.com/xmake-io/xmake/issues/2580 static tb_void_t xm_io_stdfile_init_buffer(tb_size_t type) { -#if defined(TB_CONFIG_OS_WINDOWS) - // TODO -#else - tb_char_t data[256]; - if (tb_environment_first("XMAKE_STDOUT_LINEFLUSH", data, sizeof(data))) - { - struct stat stats; - tb_int_t size = BUFSIZ; - int fileno(FILE*); - if (fstat(fileno(stdout), &stats) != -1) - size = stats.st_blksize; - setvbuf(stdout, tb_null, _IOLBF, size); - } +#if !defined(TB_CONFIG_OS_WINDOWS) + struct stat stats; + tb_int_t size = BUFSIZ; + int fileno(FILE*); + if (fstat(fileno(stdout), &stats) != -1) + size = stats.st_blksize; + setvbuf(stdout, tb_null, _IOLBF, size); #endif } -- cgit v1.3.1 From 35a16e3972d1f5993f47b1b4eaf61b27358176d6 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 28 Jul 2022 00:40:09 +0800 Subject: fix errors --- .github/workflows/freebsd.yml | 2 +- core/src/xmake/io/stdfile.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/freebsd.yml b/.github/workflows/freebsd.yml index 9a81d1a6c..e9c55944d 100644 --- a/.github/workflows/freebsd.yml +++ b/.github/workflows/freebsd.yml @@ -27,7 +27,7 @@ jobs: copyback: false prepare: pkg install -y curl unzip gmake llvm gsed bash perl5 run: | - gmake + gmake -j4 gmake install export XMAKE_ROOT=y xrepo --version diff --git a/core/src/xmake/io/stdfile.c b/core/src/xmake/io/stdfile.c index 25364d9c7..06d6fc579 100644 --- a/core/src/xmake/io/stdfile.c +++ b/core/src/xmake/io/stdfile.c @@ -33,6 +33,7 @@ # include # include "iscygpty.c" #else +# include # include # include # include @@ -87,7 +88,6 @@ static tb_void_t xm_io_stdfile_init_buffer(tb_size_t type) #if !defined(TB_CONFIG_OS_WINDOWS) struct stat stats; tb_int_t size = BUFSIZ; - int fileno(FILE*); if (fstat(fileno(stdout), &stats) != -1) size = stats.st_blksize; setvbuf(stdout, tb_null, _IOLBF, size); -- cgit v1.3.1