From 087940ec9ee6ee8f989eac49453ebe6be761fa6b Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 3 Mar 2012 22:48:21 -0800 Subject: [PATCH] Fix a bug where wfopen would always fail Removed some buffer_t --- env.cpp | 9 --------- fish_pager.cpp | 13 ++++++++----- fish_tests.cpp | 16 +++++++--------- reader.cpp | 16 +++++++--------- wutil.cpp | 9 +++++---- 5 files changed, 27 insertions(+), 36 deletions(-) diff --git a/env.cpp b/env.cpp index 7c1abadcf..3795c896c 100644 --- a/env.cpp +++ b/env.cpp @@ -173,11 +173,6 @@ static bool is_electric(const wcstring &key) */ static null_terminated_array_t export_array; -/** - Buffer used for storing string contents for export_arr -*/ -static buffer_t export_buffer; - /** Flag for checking if we need to regenerate the exported variable @@ -507,8 +502,6 @@ void env_init() wchar_t *uname; wchar_t *version; - b_init( &export_buffer ); - /* env_read_only variables can not be altered directly by the user */ @@ -671,8 +664,6 @@ void env_destroy() { env_universal_destroy(); - b_destroy( &export_buffer ); - while( &top->env != global ) { env_pop(); diff --git a/fish_pager.cpp b/fish_pager.cpp index dbfc62f0e..2c7db065d 100644 --- a/fish_pager.cpp +++ b/fish_pager.cpp @@ -49,6 +49,7 @@ #endif #include +#include #include "fallback.h" #include "util.h" @@ -136,11 +137,11 @@ static struct termios saved_modes; static int is_ca_mode = 0; /** - This buffer_t is used to buffer the output of the pager to improve + This buffer is used to buffer the output of the pager to improve screen redraw performance bu cutting down the number of write() calls to only one. */ -static buffer_t pager_buffer; +static std::vector pager_buffer; /** The environment variables used to specify the color of different @@ -340,7 +341,7 @@ static wint_t readch() */ static int pager_buffered_writer( char c) { - b_append( &pager_buffer, &c, 1 ); + pager_buffer.push_back(c); return 0; } @@ -349,8 +350,10 @@ static int pager_buffered_writer( char c) */ static void pager_flush() { - write_loop( 1, pager_buffer.buff, pager_buffer.used ); - pager_buffer.used = 0; + if (! pager_buffer.empty()) { + write_loop( 1, & pager_buffer.at(0), pager_buffer.size() * sizeof(char) ); + pager_buffer.clear(); + } } /** diff --git a/fish_tests.cpp b/fish_tests.cpp index 1cc986d59..317619245 100644 --- a/fish_tests.cpp +++ b/fish_tests.cpp @@ -228,30 +228,28 @@ static void test_convert() int i; - buffer_t sb; + std::vector sb; say( L"Testing wide/narrow string conversion" ); - - b_init( &sb ); for( i=0; i acc; int des = fd == 0 ? dup(0) : fd; int res=0; @@ -3371,8 +3371,6 @@ static int read_ni( int fd, io_data_t *io ) return 1; } - b_init( &acc ); - in_stream = fdopen( des, "r" ); if( in_stream != 0 ) { @@ -3394,17 +3392,17 @@ static int read_ni( int fd, io_data_t *io ) /* Reset buffer on error. We won't evaluate incomplete files. */ - acc.used=0; + acc.clear(); break; } - b_append( &acc, buff, c ); + acc.insert(acc.end(), buff, buff + c); } - b_append( &acc, "\0", 1 ); - acc_used = acc.used; - str = str2wcs( acc.buff ); - b_destroy( &acc ); + acc.push_back(0); + acc_used = acc.size(); + str = str2wcs(&acc.at(0)); + acc.clear(); if( fclose( in_stream )) { diff --git a/wutil.cpp b/wutil.cpp index fa29ad3d9..30a840442 100644 --- a/wutil.cpp +++ b/wutil.cpp @@ -142,7 +142,8 @@ int wchdir( const wcstring &dir ) FILE *wfopen(const wcstring &path, const char *mode) { int permissions = 0, options = 0; - switch (*mode++) { + size_t idx = 0; + switch (mode[idx++]) { case 'r': permissions = O_RDONLY; break; @@ -160,11 +161,11 @@ FILE *wfopen(const wcstring &path, const char *mode) break; } /* Skip binary */ - if (*mode == 'b') - mode++; + if (mode[idx] == 'b') + idx++; /* Consider append option */ - if (*mode == '+') + if (mode[idx] == '+') permissions = O_RDWR; int fd = wopen_cloexec(path, permissions | options, 0666);