diff --git a/src/evalfunc.c b/src/evalfunc.c index e7b38132a7eb5..f1cb9dc607aef 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -14777,7 +14777,7 @@ f_writefile(typval_T *argvars, typval_T *rettv) else if (do_fsync) // Ignore the error, the user wouldn't know what to do about it. // May happen for a device. - vim_ignored = fsync(fileno(fd)); + vim_ignored = vim_fsync(fileno(fd)); #endif fclose(fd); } @@ -14789,7 +14789,7 @@ f_writefile(typval_T *argvars, typval_T *rettv) else if (do_fsync) /* Ignore the error, the user wouldn't know what to do about it. * May happen for a device. */ - vim_ignored = fsync(fileno(fd)); + vim_ignored = vim_fsync(fileno(fd)); #endif fclose(fd); } diff --git a/src/fileio.c b/src/fileio.c index cd2723bf83fd4..85d2df3bbfbdf 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -4661,7 +4661,7 @@ buf_write( * work (could be a pipe). * If the 'fsync' option is FALSE, don't fsync(). Useful for laptops. */ - if (p_fs && fsync(fd) != 0 && !device) + if (p_fs && vim_fsync(fd) != 0 && !device) { errmsg = (char_u *)_(e_fsync); end = 0; @@ -5123,6 +5123,25 @@ buf_write( return retval; } +#if defined(HAVE_FSYNC) || defined(PROTO) +/* + * Call fsync() with Mac-specific exception. + * Return fsync() result: zero for success. + */ + int +vim_fsync(int fd) +{ + int r; + +# ifdef MACOS_X + r = fcntl(fd, F_FULLFSYNC); + if (r != 0 && errno == ENOTTY) +# endif + r = fsync(fd); + return r; +} +#endif + /* * Set the name of the current buffer. Use when the buffer doesn't have a * name and a ":r" or ":w" command with a file name is used. diff --git a/src/if_py_both.h b/src/if_py_both.h index a0c16637841e9..8d11488d3989d 100644 --- a/src/if_py_both.h +++ b/src/if_py_both.h @@ -87,9 +87,9 @@ static PyObject *vim_special_path_object; #if PY_VERSION_HEX >= 0x030700f0 static PyObject *py_find_spec; #else -static PyObject *py_find_module; static PyObject *py_load_module; #endif +static PyObject *py_find_module; static PyObject *VimError; @@ -759,7 +759,7 @@ VimToPython(typval_T *our_tv, int depth, PyObject *lookup_dict) sprintf(buf, "%ld", (long)our_tv->vval.v_number); ret = PyString_FromString((char *)buf); } -# ifdef FEAT_FLOAT +#ifdef FEAT_FLOAT else if (our_tv->v_type == VAR_FLOAT) { char buf[NUMBUFLEN]; @@ -767,7 +767,7 @@ VimToPython(typval_T *our_tv, int depth, PyObject *lookup_dict) sprintf(buf, "%f", our_tv->vval.v_float); ret = PyString_FromString((char *)buf); } -# endif +#endif else if (our_tv->v_type == VAR_LIST) { list_T *list = our_tv->vval.v_list; @@ -6093,18 +6093,18 @@ convert_dl(PyObject *obj, typval_T *tv, sprintf(hexBuf, "%p", (void *)obj); -# ifdef PY_USE_CAPSULE +#ifdef PY_USE_CAPSULE capsule = PyDict_GetItemString(lookup_dict, hexBuf); -# else +#else capsule = (PyObject *)PyDict_GetItemString(lookup_dict, hexBuf); -# endif +#endif if (capsule == NULL) { -# ifdef PY_USE_CAPSULE +#ifdef PY_USE_CAPSULE capsule = PyCapsule_New(tv, NULL, NULL); -# else +#else capsule = PyCObject_FromVoidPtr(tv, NULL); -# endif +#endif if (PyDict_SetItemString(lookup_dict, hexBuf, capsule)) { Py_DECREF(capsule); @@ -6130,11 +6130,11 @@ convert_dl(PyObject *obj, typval_T *tv, { typval_T *v; -# ifdef PY_USE_CAPSULE +#ifdef PY_USE_CAPSULE v = PyCapsule_GetPointer(capsule, NULL); -# else +#else v = PyCObject_AsVoidPtr(capsule); -# endif +#endif copy_tv(v, tv); } return 0; @@ -6921,6 +6921,13 @@ populate_module(PyObject *m) return -1; } + if ((py_find_module = PyObject_GetAttrString(cls, "find_module"))) + { + // find_module() is deprecated, this may stop working in some later + // version. + ADD_OBJECT(m, "_find_module", py_find_module); + } + Py_DECREF(imp); ADD_OBJECT(m, "_find_spec", py_find_spec); diff --git a/src/memfile.c b/src/memfile.c index f2e774a4eddb8..1a527340adb7c 100644 --- a/src/memfile.c +++ b/src/memfile.c @@ -600,7 +600,7 @@ mf_sync(memfile_T *mfp, int flags) */ if (STRCMP(p_sws, "fsync") == 0) { - if (fsync(mfp->mf_fd)) + if (vim_fsync(mfp->mf_fd)) status = FAIL; } else @@ -617,7 +617,7 @@ mf_sync(memfile_T *mfp, int flags) #ifdef VMS if (STRCMP(p_sws, "fsync") == 0) { - if (fsync(mfp->mf_fd)) + if (vim_fsync(mfp->mf_fd)) status = FAIL; } #endif @@ -627,7 +627,7 @@ mf_sync(memfile_T *mfp, int flags) #endif #ifdef AMIGA # if defined(__AROS__) || defined(__amigaos4__) - if (fsync(mfp->mf_fd) != 0) + if (vim_fsync(mfp->mf_fd) != 0) status = FAIL; # else /* diff --git a/src/message.c b/src/message.c index 1deb6b717ac2e..800a99e126a11 100644 --- a/src/message.c +++ b/src/message.c @@ -2570,54 +2570,42 @@ msg_use_printf(void) msg_puts_printf(char_u *str, int maxlen) { char_u *s = str; - char_u buf[4]; - char_u *p; -#ifdef WIN3264 -# if !defined(FEAT_GUI_MSWIN) - char_u *ccp = NULL; + char_u *buf = NULL; + char_u *p = s; -# endif +#ifdef WIN3264 if (!(silent_mode && p_verbose == 0)) - mch_settmode(TMODE_COOK); /* handle '\r' and '\n' correctly */ - -# if !defined(FEAT_GUI_MSWIN) - if (enc_codepage >= 0 && (int)GetConsoleCP() != enc_codepage) - { - int inlen = (int)STRLEN(str); - int outlen; - WCHAR *widestr = (WCHAR *)enc_to_utf16(str, &inlen); - - if (widestr != NULL) - { - WideCharToMultiByte_alloc(GetConsoleCP(), 0, widestr, inlen, - (LPSTR *)&ccp, &outlen, 0, 0); - vim_free(widestr); - s = str = ccp; - } - } -# endif + mch_settmode(TMODE_COOK); /* handle CR and NL correctly */ #endif while ((maxlen < 0 || (int)(s - str) < maxlen) && *s != NUL) { if (!(silent_mode && p_verbose == 0)) { - /* NL --> CR NL translation (for Unix, not for "--version") */ - p = &buf[0]; - if (*s == '\n' && !info_message) - *p++ = '\r'; - *p++ = *s; - *p = '\0'; - if (info_message) /* informative message, not an error */ - mch_msg((char *)buf); - else - mch_errmsg((char *)buf); + // NL --> CR NL translation (for Unix, not for "--version") + if (*s == NL) + { + int n = (int)(s - p); + + buf = alloc(n + 3); + memcpy(buf, p, n); + if (!info_message) + buf[n++] = CAR; + buf[n++] = NL; + buf[n++] = NUL; + if (info_message) // informative message, not an error + mch_msg((char *)buf); + else + mch_errmsg((char *)buf); + vim_free(buf); + p = s + 1; + } } - /* primitive way to compute the current column */ + // primitive way to compute the current column #ifdef FEAT_RIGHTLEFT if (cmdmsg_rl) { - if (*s == '\r' || *s == '\n') + if (*s == CAR || *s == NL) msg_col = Columns - 1; else --msg_col; @@ -2625,19 +2613,27 @@ msg_puts_printf(char_u *str, int maxlen) else #endif { - if (*s == '\r' || *s == '\n') + if (*s == CAR || *s == NL) msg_col = 0; else ++msg_col; } ++s; } - msg_didout = TRUE; /* assume that line is not empty */ + + if (*p != NUL && !(silent_mode && p_verbose == 0)) + { + if (maxlen > 0 && STRLEN(p) > (size_t)maxlen) + p[maxlen] = 0; + if (info_message) + mch_msg((char *)p); + else + mch_errmsg((char *)p); + } + + msg_didout = TRUE; // assume that line is not empty #ifdef WIN3264 -# if !defined(FEAT_GUI_MSWIN) - vim_free(ccp); -# endif if (!(silent_mode && p_verbose == 0)) mch_settmode(TMODE_RAW); #endif @@ -2938,32 +2934,51 @@ do_more_prompt(int typed_char) void mch_errmsg(char *str) { +#if defined(WIN3264) && !defined(FEAT_GUI_MSWIN) + int len = STRLEN(str); + DWORD nwrite = 0; + DWORD mode = 0; + HANDLE h = GetStdHandle(STD_ERROR_HANDLE); + + if (GetConsoleMode(h, &mode) && enc_codepage >= 0 + && (int)GetConsoleCP() != enc_codepage) + { + WCHAR *w = enc_to_utf16((char_u *)str, &len); + + WriteConsoleW(h, w, len, &nwrite, NULL); + vim_free(w); + } + else + { + fprintf(stderr, "%s", str); + } +#else int len; -#if (defined(UNIX) || defined(FEAT_GUI)) && !defined(ALWAYS_USE_GUI) +# if (defined(UNIX) || defined(FEAT_GUI)) && !defined(ALWAYS_USE_GUI) /* On Unix use stderr if it's a tty. * When not going to start the GUI also use stderr. * On Mac, when started from Finder, stderr is the console. */ if ( -# ifdef UNIX -# ifdef MACOS_X +# ifdef UNIX +# ifdef MACOS_X (isatty(2) && strcmp("/dev/console", ttyname(2)) != 0) -# else +# else isatty(2) -# endif -# ifdef FEAT_GUI +# endif +# ifdef FEAT_GUI || +# endif # endif -# endif -# ifdef FEAT_GUI +# ifdef FEAT_GUI !(gui.in_use || gui.starting) -# endif +# endif ) { fprintf(stderr, "%s", str); return; } -#endif +# endif /* avoid a delay for a message that isn't there */ emsg_on_display = FALSE; @@ -2978,7 +2993,7 @@ mch_errmsg(char *str) { mch_memmove((char_u *)error_ga.ga_data + error_ga.ga_len, (char_u *)str, len); -#ifdef UNIX +# ifdef UNIX /* remove CR characters, they are displayed */ { char_u *p; @@ -2992,10 +3007,11 @@ mch_errmsg(char *str) *p = ' '; } } -#endif +# endif --len; /* don't count the NUL at the end */ error_ga.ga_len += len; } +#endif } /* @@ -3006,7 +3022,27 @@ mch_errmsg(char *str) void mch_msg(char *str) { -#if (defined(UNIX) || defined(FEAT_GUI)) && !defined(ALWAYS_USE_GUI) +#if defined(WIN3264) && !defined(FEAT_GUI_MSWIN) + int len = STRLEN(str); + DWORD nwrite = 0; + DWORD mode; + HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); + + + if (GetConsoleMode(h, &mode) && enc_codepage >= 0 + && (int)GetConsoleCP() != enc_codepage) + { + WCHAR *w = enc_to_utf16((char_u *)str, &len); + + WriteConsoleW(h, w, len, &nwrite, NULL); + vim_free(w); + } + else + { + printf("%s", str); + } +#else +# if (defined(UNIX) || defined(FEAT_GUI)) && !defined(ALWAYS_USE_GUI) /* On Unix use stdout if we have a tty. This allows "vim -h | more" and * uses mch_errmsg() when started from the desktop. * When not going to start the GUI also use stdout. @@ -3032,6 +3068,7 @@ mch_msg(char *str) } # endif mch_errmsg(str); +#endif } #endif /* USE_MCH_ERRMSG */ diff --git a/src/os_mswin.c b/src/os_mswin.c index 8dafaa35b1b78..9da72b0a4d97f 100644 --- a/src/os_mswin.c +++ b/src/os_mswin.c @@ -675,6 +675,7 @@ mch_suspend(void) # undef display_errors #endif +#ifdef FEAT_GUI /* * Display the saved error message(s). */ @@ -690,13 +691,9 @@ display_errors(void) if (!isspace(*p)) { (void)gui_mch_dialog( -#ifdef FEAT_GUI gui.starting ? VIM_INFO : -#endif VIM_ERROR, -#ifdef FEAT_GUI gui.starting ? (char_u *)_("Message") : -#endif (char_u *)_("Error"), (char_u *)p, (char_u *)_("&Ok"), 1, NULL, FALSE); @@ -705,6 +702,13 @@ display_errors(void) ga_clear(&error_ga); } } +#else + void +display_errors(void) +{ + FlushFileBuffers(GetStdHandle(STD_ERROR_HANDLE)); +} +#endif #endif diff --git a/src/proto/fileio.pro b/src/proto/fileio.pro index c9f668152abb3..1844924fdb3ff 100644 --- a/src/proto/fileio.pro +++ b/src/proto/fileio.pro @@ -7,6 +7,7 @@ void set_file_options(int set_options, exarg_T *eap); void set_forced_fenc(exarg_T *eap); int check_file_readonly(char_u *fname, int perm); int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_T end, exarg_T *eap, int append, int forceit, int reset_changed, int filtering); +int vim_fsync(int fd); void msg_add_fname(buf_T *buf, char_u *fname); void msg_add_lines(int insert_space, long lnum, off_T nchars); char_u *shorten_fname1(char_u *full_path); diff --git a/src/userfunc.c b/src/userfunc.c index a293dd68e3f42..6deb8a9f1f85c 100644 --- a/src/userfunc.c +++ b/src/userfunc.c @@ -205,6 +205,7 @@ get_lambda_tv(char_u **arg, typval_T *rettv, int evaluate) garray_T newlines; garray_T *pnewargs; ufunc_T *fp = NULL; + partial_T *pt = NULL; int varargs; int ret; char_u *start = skipwhite(*arg + 1); @@ -252,7 +253,6 @@ get_lambda_tv(char_u **arg, typval_T *rettv, int evaluate) int len, flags = 0; char_u *p; char_u name[20]; - partial_T *pt; sprintf((char*)name, "%d", ++lambda_no); @@ -261,10 +261,7 @@ get_lambda_tv(char_u **arg, typval_T *rettv, int evaluate) goto errret; pt = (partial_T *)alloc_clear((unsigned)sizeof(partial_T)); if (pt == NULL) - { - vim_free(fp); goto errret; - } ga_init2(&newlines, (int)sizeof(char_u *), 1); if (ga_grow(&newlines, 1) == FAIL) @@ -318,6 +315,7 @@ get_lambda_tv(char_u **arg, typval_T *rettv, int evaluate) ga_clear_strings(&newargs); ga_clear_strings(&newlines); vim_free(fp); + vim_free(pt); eval_lavars_used = old_eval_lavars; return FAIL; } diff --git a/src/version.c b/src/version.c index ed224a454ce57..73840c25131df 100644 --- a/src/version.c +++ b/src/version.c @@ -783,6 +783,14 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 918, +/**/ + 917, +/**/ + 916, +/**/ + 915, /**/ 914, /**/ diff --git a/src/vim.h b/src/vim.h index 7ee164af77f77..be1ec1d317113 100644 --- a/src/vim.h +++ b/src/vim.h @@ -2093,7 +2093,7 @@ typedef enum { * functions of these names. The declarations would break if the defines had * been seen at that stage. But it must be before globals.h, where error_ga * is declared. */ -#if !defined(FEAT_GUI_W32) && !defined(FEAT_GUI_X11) \ +#if !defined(MSWIN) && !defined(FEAT_GUI_X11) \ && !defined(FEAT_GUI_GTK) && !defined(FEAT_GUI_MAC) && !defined(PROTO) # define mch_errmsg(str) fprintf(stderr, "%s", (str)) # define display_errors() fflush(stderr)