From 4df57fda09c04f71a595154ca6962a95666b3685 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Thu, 5 Jan 2012 13:58:48 -0800 Subject: [PATCH] Incorporate Siteshwar's patch for building on Linux --- Makefile.in | 124 ------------------------------------------------ common.cpp | 18 +++++-- common.h | 19 +++++++- complete.cpp | 8 ++-- env.cpp | 7 +-- fish.cpp | 1 + fish_indent.cpp | 2 +- fish_pager.cpp | 2 +- fish_tests.cpp | 2 +- fishd.cpp | 1 + function.cpp | 2 +- key_reader.cpp | 2 +- mimedb.cpp | 2 +- wgetopt.cpp | 2 +- wildcard.cpp | 14 +++--- xdgmime.cpp | 2 +- 16 files changed, 55 insertions(+), 153 deletions(-) diff --git a/Makefile.in b/Makefile.in index 32dc2bb70..7e7296c79 100644 --- a/Makefile.in +++ b/Makefile.in @@ -892,127 +892,3 @@ clean: # DO NOT DELETE THIS LINE -- make depend depends on it. - -builtin.o: config.h fallback.h util.h wutil.h builtin.h io.h function.h -builtin.o: complete.h proc.h parser.h event.h reader.h env.h common.h -builtin.o: wgetopt.h sanity.h tokenizer.h wildcard.h input_common.h input.h -builtin.o: intern.h signal.h exec.h highlight.h halloc.h halloc_util.h -builtin.o: parse_util.h parser_keywords.h expand.h path.h builtin_set.c -builtin.o: builtin_commandline.c builtin_complete.c builtin_ulimit.c -builtin.o: builtin_jobs.c -builtin_commandline.o: config.h signal.h fallback.h util.h wutil.h builtin.h -builtin_commandline.o: io.h common.h wgetopt.h reader.h proc.h parser.h -builtin_commandline.o: event.h tokenizer.h input_common.h input.h -builtin_commandline.o: parse_util.h -builtin_complete.o: config.h signal.h fallback.h util.h wutil.h builtin.h -builtin_complete.o: io.h common.h complete.h wgetopt.h parser.h proc.h -builtin_complete.o: event.h reader.h -builtin_jobs.o: config.h fallback.h util.h wutil.h builtin.h io.h proc.h -builtin_jobs.o: parser.h event.h common.h wgetopt.h -builtin_set.o: config.h signal.h fallback.h util.h wutil.h builtin.h io.h -builtin_set.o: env.h expand.h common.h wgetopt.h proc.h parser.h event.h -builtin_ulimit.o: config.h fallback.h util.h builtin.h io.h common.h -builtin_ulimit.o: wgetopt.h -common.o: config.h fallback.h util.h wutil.h common.h expand.h proc.h io.h -common.o: wildcard.h parser.h event.h util.c halloc.c halloc.h halloc_util.c -common.o: fallback.c -complete.o: config.h signal.h fallback.h util.h tokenizer.h wildcard.h proc.h -complete.o: io.h parser.h event.h function.h complete.h builtin.h env.h -complete.o: exec.h expand.h common.h reader.h history.h intern.h parse_util.h -complete.o: parser_keywords.h halloc.h halloc_util.h wutil.h path.h -env.o: config.h signal.h fallback.h util.h wutil.h proc.h io.h common.h env.h -env.o: sanity.h expand.h history.h reader.h parser.h event.h env_universal.h -env.o: env_universal_common.h input_common.h path.h halloc.h halloc_util.h -env.o: complete.h -env_universal.o: config.h signal.h fallback.h util.h common.h wutil.h -env_universal.o: env_universal_common.h env_universal.h -env_universal_common.o: config.h signal.h fallback.h util.h common.h wutil.h -env_universal_common.o: env_universal_common.h -event.o: config.h signal.h fallback.h util.h wutil.h function.h proc.h io.h -event.o: parser.h event.h common.h halloc_util.h -exec.o: config.h signal.h fallback.h util.h common.h wutil.h proc.h io.h -exec.o: exec.h parser.h event.h builtin.h function.h env.h wildcard.h -exec.o: sanity.h expand.h halloc.h halloc_util.h parse_util.h -expand.o: config.h signal.h fallback.h util.h common.h wutil.h env.h proc.h -expand.o: io.h parser.h event.h expand.h wildcard.h exec.h tokenizer.h -expand.o: complete.h parse_util.h halloc.h halloc_util.h -fallback.o: config.h fallback.h util.h -fish.o: config.h signal.h fallback.h util.h common.h reader.h io.h builtin.h -fish.o: function.h complete.h wutil.h env.h sanity.h proc.h parser.h event.h -fish.o: expand.h intern.h exec.h output.h halloc.h halloc_util.h history.h -fish.o: path.h -fish_indent.o: config.h fallback.h util.h common.h wutil.h halloc.h -fish_indent.o: halloc_util.h tokenizer.h print_help.h parser_keywords.h -fish_pager.o: config.h signal.h fallback.h util.h wutil.h common.h complete.h -fish_pager.o: output.h input_common.h env_universal.h env_universal_common.h -fish_pager.o: halloc.h halloc_util.h print_help.h -fish_tests.o: config.h signal.h fallback.h util.h common.h proc.h io.h -fish_tests.o: reader.h builtin.h function.h complete.h wutil.h env.h expand.h -fish_tests.o: parser.h event.h tokenizer.h output.h exec.h path.h halloc.h -fish_tests.o: halloc_util.h -fishd.o: config.h signal.h fallback.h util.h common.h wutil.h -fishd.o: env_universal_common.h halloc.h halloc_util.h path.h print_help.h -function.o: config.h signal.h wutil.h fallback.h util.h function.h proc.h -function.o: io.h parser.h event.h common.h intern.h reader.h parse_util.h -function.o: parser_keywords.h env.h expand.h halloc.h halloc_util.h -halloc.o: config.h fallback.h util.h common.h halloc.h -halloc_util.o: config.h fallback.h util.h common.h halloc.h -highlight.o: config.h signal.h fallback.h util.h wutil.h highlight.h -highlight.o: tokenizer.h proc.h io.h parser.h event.h parse_util.h -highlight.o: parser_keywords.h builtin.h function.h env.h expand.h sanity.h -highlight.o: common.h complete.h output.h halloc.h halloc_util.h wildcard.h -highlight.o: path.h -history.o: config.h fallback.h util.h wutil.h history.h common.h halloc.h -history.o: halloc_util.h intern.h path.h signal.h -input.o: config.h signal.h fallback.h util.h wutil.h reader.h io.h proc.h -input.o: common.h sanity.h input_common.h input.h parser.h event.h env.h -input.o: expand.h output.h intern.h halloc.h halloc_util.h -input_common.o: config.h fallback.h util.h common.h wutil.h input_common.h -input_common.o: env_universal.h env_universal_common.h -intern.o: config.h fallback.h util.h wutil.h common.h intern.h -io.o: config.h fallback.h util.h wutil.h exec.h proc.h io.h common.h halloc.h -key_reader.o: config.h fallback.h input_common.h -kill.o: config.h signal.h fallback.h util.h wutil.h kill.h proc.h io.h -kill.o: sanity.h common.h env.h exec.h halloc.h path.h -mimedb.o: config.h xdgmime.h fallback.h util.h print_help.h -output.o: config.h signal.h fallback.h util.h wutil.h expand.h common.h -output.o: output.h halloc_util.h highlight.h -parse_util.o: config.h fallback.h util.h wutil.h common.h tokenizer.h -parse_util.o: parse_util.h expand.h intern.h exec.h proc.h io.h env.h -parse_util.o: signal.h wildcard.h halloc_util.h -parser.o: config.h signal.h fallback.h util.h common.h wutil.h proc.h io.h -parser.o: parser.h event.h parser_keywords.h tokenizer.h exec.h wildcard.h -parser.o: function.h builtin.h env.h expand.h reader.h sanity.h -parser.o: env_universal.h env_universal_common.h intern.h parse_util.h -parser.o: halloc.h halloc_util.h path.h -parser_keywords.o: config.h fallback.h common.h util.h parser_keywords.h -path.o: config.h fallback.h util.h common.h env.h wutil.h halloc.h -path.o: halloc_util.h path.h expand.h -print_help.o: print_help.h -proc.o: config.h signal.h fallback.h util.h wutil.h proc.h io.h common.h -proc.o: reader.h sanity.h env.h parser.h event.h halloc.h halloc_util.h -proc.o: output.h -reader.o: config.h signal.h fallback.h util.h wutil.h highlight.h reader.h -reader.o: io.h proc.h parser.h event.h complete.h history.h common.h sanity.h -reader.o: env.h exec.h expand.h tokenizer.h kill.h input_common.h input.h -reader.o: function.h output.h screen.h halloc.h halloc_util.h parse_util.h -sanity.o: config.h signal.h fallback.h util.h common.h sanity.h proc.h io.h -sanity.o: history.h reader.h kill.h wutil.h -screen.o: config.h fallback.h common.h util.h wutil.h output.h highlight.h -screen.o: screen.h env.h -set_color.o: config.h fallback.h print_help.h -signal.o: config.h signal.h common.h util.h fallback.h wutil.h event.h -signal.o: reader.h io.h proc.h -tokenizer.o: config.h fallback.h util.h wutil.h tokenizer.h common.h -util.o: config.h fallback.h util.h common.h wutil.h -wgetopt.o: config.h wgetopt.h wutil.h fallback.h -wildcard.o: config.h fallback.h util.h wutil.h complete.h common.h wildcard.h -wildcard.o: reader.h io.h expand.h exec.h proc.h halloc_util.h -wutil.o: config.h fallback.h util.h common.h wutil.h halloc.h halloc_util.h -xdgmime.o: xdgmime.h xdgmimeint.h xdgmimeglob.h xdgmimemagic.h xdgmimealias.h -xdgmime.o: xdgmimeparent.h -xdgmimealias.o: xdgmimealias.h xdgmime.h xdgmimeint.h -xdgmimeglob.o: xdgmimeglob.h xdgmime.h xdgmimeint.h -xdgmimeint.o: xdgmimeint.h xdgmime.h -xdgmimemagic.o: xdgmimemagic.h xdgmime.h xdgmimeint.h -xdgmimeparent.o: xdgmimeparent.h xdgmime.h xdgmimeint.h diff --git a/common.cpp b/common.cpp index 4b6c33c56..fb97b1788 100644 --- a/common.cpp +++ b/common.cpp @@ -97,6 +97,8 @@ parts of fish. struct termios shell_modes; +static pthread_t main_thread_id = 0; + wchar_t ellipsis_char; char *profile=0; @@ -494,7 +496,7 @@ wchar_t *wcsvarname( const wchar_t *str ) return 0; } -wchar_t *wcsfuncname( const wchar_t *str ) +const wchar_t *wcsfuncname( const wchar_t *str ) { return wcschr( str, L'/' ); } @@ -1943,9 +1945,19 @@ extern "C" { __attribute__((noinline)) void debug_thread_error(void) {} } + +void set_main_thread() { + main_thread_id = pthread_self(); +} + +static bool is_main_thread() { + assert (main_thread_id != 0); + return main_thread_id == pthread_self(); +} + void assert_is_main_thread(const char *who) { - if (! pthread_main_np()) { + if (! is_main_thread()) { fprintf(stderr, "Warning: %s called off of main thread. Break on debug_thread_error to debug.\n", who); debug_thread_error(); } @@ -1953,7 +1965,7 @@ void assert_is_main_thread(const char *who) void assert_is_background_thread(const char *who) { - if (pthread_main_np()) { + if (is_main_thread()) { fprintf(stderr, "Warning: %s called on the main thread (may block!). Break on debug_thread_error to debug.\n", who); debug_thread_error(); } diff --git a/common.h b/common.h index 5bd420d4a..b8cb8d5bb 100644 --- a/common.h +++ b/common.h @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include "util.h" @@ -72,6 +74,7 @@ typedef std::vector wcstring_list_t; */ #define VOMIT_ON_FAILURE(a) do { if (0 != (a)) { int err = errno; fprintf(stderr, "%s failed on line %d in file %s: %d (%s)\n", #a, __LINE__, __FILE__, err, strerror(err)); abort(); }} while (0) + /** Save the shell mode on startup so we can restore them on exit */ @@ -366,7 +369,7 @@ wchar_t *wcsvarname( const wchar_t *str ); \return null if this is a valid name, and a pointer to the first invalid character otherwise */ -wchar_t *wcsfuncname( const wchar_t *str ); +const wchar_t *wcsfuncname( const wchar_t *str ); /** Test if the given string is valid in a variable name @@ -561,6 +564,20 @@ void sb_format_size( string_buffer_t *sb, */ double timef(); +/** + Call the following function early in main to set the main thread. + This is our replacement for pthread_main_np(). + */ +void set_main_thread(); + +/** + +*/ + +/** + + */ + #endif diff --git a/complete.cpp b/complete.cpp index d76a53878..5a288176b 100644 --- a/complete.cpp +++ b/complete.cpp @@ -594,7 +594,7 @@ static void parse_cmd_string( void *context, } /* Make sure the path is not included in the command */ - cmd = wcsrchr( str, L'/' ); + cmd = const_cast(wcsrchr( str, L'/' )); if( cmd != 0 ) { cmd++; @@ -680,7 +680,7 @@ int complete_is_valid_option( const wchar_t *str, is_gnu_opt = opt[1]==L'-'; if( is_gnu_opt ) { - wchar_t *opt_end = wcschr(opt, L'=' ); + const wchar_t *opt_end = wcschr(opt, L'=' ); if( opt_end ) { gnu_opt_len = (opt_end-opt)-2; @@ -1319,7 +1319,7 @@ static int short_ok( const wchar_t *arg, for( ptr = arg+1; *ptr; ptr++ ) { - wchar_t *tmp = wcschr( allopt, *ptr ); + const wchar_t *tmp = wcschr( allopt, *ptr ); /* Unknown option */ if( tmp == 0 ) { @@ -1739,7 +1739,7 @@ static int try_complete_user( const wchar_t *cmd, if( *first_char ==L'~' && !wcschr(first_char, L'/')) { const wchar_t *user_name = first_char+1; - wchar_t *name_end = wcschr( user_name, L'~' ); + const wchar_t *name_end = wcschr( user_name, L'~' ); if( name_end == 0 ) { struct passwd *pw; diff --git a/env.cpp b/env.cpp index 3305d861d..b84e08d6c 100644 --- a/env.cpp +++ b/env.cpp @@ -1238,12 +1238,7 @@ wcstring env_get_string( const wchar_t *key ) wchar_t *env_get( const wchar_t *key ) { ASSERT_IS_MAIN_THREAD(); - - if (! pthread_main_np()) - { - fwprintf(stderr, L"env_get(%ls)\n", key); - } - + var_entry_t *res; env_node_t *env = top; wchar_t *item; diff --git a/fish.cpp b/fish.cpp index b44d48bd4..b7daa8a89 100644 --- a/fish.cpp +++ b/fish.cpp @@ -284,6 +284,7 @@ int main( int argc, char **argv ) int my_optind=0; halloc_util_init(); + set_main_thread(); wsetlocale( LC_ALL, L"" ); is_interactive_session=1; diff --git a/fish_indent.cpp b/fish_indent.cpp index 39bd1de05..232c4f9f1 100644 --- a/fish_indent.cpp +++ b/fish_indent.cpp @@ -302,7 +302,7 @@ int main( int argc, char **argv ) string_buffer_t sb_out; int do_indent=1; - + set_main_thread(); wsetlocale( LC_ALL, L"" ); program_name=L"fish_indent"; diff --git a/fish_pager.cpp b/fish_pager.cpp index f0dbd2e9c..b054b818c 100644 --- a/fish_pager.cpp +++ b/fish_pager.cpp @@ -1226,7 +1226,7 @@ int main( int argc, char **argv ) int mangle_descriptors = 0; int result_fd = -1; - + set_main_thread(); /* This initialization is made early, so that the other init code can use global_context for memory managment diff --git a/fish_tests.cpp b/fish_tests.cpp index 69d0e6235..da192a7bd 100644 --- a/fish_tests.cpp +++ b/fish_tests.cpp @@ -818,7 +818,7 @@ int main( int argc, char **argv ) say( L"Testing low-level functionality"); say( L"Lines beginning with '(ignore):' are not errors, they are warning messages\ngenerated by the fish parser library when given broken input, and can be\nignored. All actual errors begin with 'Error:'." ); - + set_main_thread(); proc_init(); halloc_util_init(); event_init(); diff --git a/fishd.cpp b/fishd.cpp index a1369e515..3177106e1 100644 --- a/fishd.cpp +++ b/fishd.cpp @@ -573,6 +573,7 @@ int main( int argc, char ** argv ) fd_set read_fd, write_fd; halloc_util_init(); + set_main_thread(); program_name=L"fishd"; wsetlocale( LC_ALL, L"" ); diff --git a/function.cpp b/function.cpp index 760d05f41..a9e1f6196 100644 --- a/function.cpp +++ b/function.cpp @@ -176,7 +176,7 @@ static void autoload_names( array_list_t *out, int get_hidden ) if( !get_hidden && fn[0] == L'_' ) continue; - suffix = wcsrchr( fn, L'.' ); + suffix = const_cast(wcsrchr( fn, L'.' )); if( suffix && (wcscmp( suffix, L".fish" ) == 0 ) ) { const wchar_t *dup; diff --git a/key_reader.cpp b/key_reader.cpp index e7d6611f7..52ef733be 100644 --- a/key_reader.cpp +++ b/key_reader.cpp @@ -27,7 +27,7 @@ int writestr( char *str ) int main( int argc, char **argv) { - + set_main_thread(); setlocale( LC_ALL, "" ); diff --git a/mimedb.cpp b/mimedb.cpp index 4b83e00a7..d0187b284 100644 --- a/mimedb.cpp +++ b/mimedb.cpp @@ -267,7 +267,7 @@ static char *file_exists( const char *dir, const char *in ) a slash in the name as a directory separator. We try to replace a dash with a slash and try again. */ - replaceme = strchr( in, '-' ); + replaceme = const_cast(strchr( in, '-' )); if( replaceme ) { char *res; diff --git a/wgetopt.cpp b/wgetopt.cpp index 0440c48bf..37c920a56 100644 --- a/wgetopt.cpp +++ b/wgetopt.cpp @@ -617,7 +617,7 @@ _wgetopt_internal (int argc, wchar_t *const *argv, const wchar_t *optstring, con { wchar_t c = *nextchar++; - wchar_t *temp = my_index (optstring, c); + wchar_t *temp = const_cast(my_index (optstring, c)); /* Increment `woptind' when we start to process its last character. */ if (*nextchar == '\0') diff --git a/wildcard.cpp b/wildcard.cpp index 3e168bb2d..416af60f8 100644 --- a/wildcard.cpp +++ b/wildcard.cpp @@ -518,7 +518,7 @@ static const wchar_t *file_get_desc( const wchar_t *filename, struct stat buf, int err ) { - wchar_t *suffix; + const wchar_t *suffix; CHECK( filename, 0 ); @@ -782,7 +782,7 @@ static int wildcard_expand_internal( const wchar_t *wc, { /* Points to the end of the current wildcard segment */ - wchar_t *wc_end; + const wchar_t *wc_end; /* Variables for traversing a directory */ DIR *dir; @@ -794,7 +794,7 @@ static int wildcard_expand_internal( const wchar_t *wc, int base_len; /* Variables for testing for presense of recursive wildcards */ - wchar_t *wc_recursive; + const wchar_t *wc_recursive; int is_recursive; /* Sligtly mangled version of base_dir */ @@ -1052,8 +1052,8 @@ static int wildcard_expand_internal( const wchar_t *wc, */ if( is_recursive ) { - wchar_t *end = wcschr( wc, ANY_STRING_RECURSIVE ); - wchar_t *wc_sub = wcsndup( wc, end-wc+1); + const wchar_t *end = wcschr( wc, ANY_STRING_RECURSIVE ); + wchar_t *wc_sub = const_cast(wcsndup( wc, end-wc+1)); partial_match = wildcard_match2( name, wc_sub, 1 ); free( wc_sub ); } @@ -1090,7 +1090,7 @@ static int wildcard_expand_internal( const wchar_t *wc, wchar_t *new_wc = L""; if( wc_end ) { - new_wc=wc_end+1; + new_wc=const_cast(wc_end+1); /* Accept multiple '/' as a single direcotry separator */ @@ -1165,7 +1165,7 @@ int wildcard_expand( const wchar_t *wc, if( flags & ACCEPT_INCOMPLETE ) { wchar_t *wc_base=L""; - wchar_t *wc_base_ptr = wcsrchr( wc, L'/' ); + wchar_t *wc_base_ptr = const_cast(wcsrchr( wc, L'/' )); string_buffer_t sb; diff --git a/xdgmime.cpp b/xdgmime.cpp index 819a669fa..4a6278769 100644 --- a/xdgmime.cpp +++ b/xdgmime.cpp @@ -576,7 +576,7 @@ xdg_mime_media_type_equal (const char *mime_a, xdg_mime_init (); - sep = strchr (mime_a, '/'); + sep = const_cast(strchr (mime_a, '/')); if (sep && strncmp (mime_a, mime_b, sep - mime_a + 1) == 0) return 1;