To: vim_dev@googlegroups.com Subject: Patch 8.0.0709 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.0709 Problem: Libvterm cannot use vsnprintf(), it does not exist in C90. Solution: Use vim_vsnprintf() instead. Files: src/message.c, src/Makefile, src/proto.h, src/evalfunc.c, src/netbeans.c, src/libvterm/src/vterm.c *** ../vim-8.0.0708/src/message.c 2017-06-23 20:52:21.571128803 +0200 --- src/message.c 2017-07-11 22:21:04.466036369 +0200 *************** *** 382,388 **** va_list arglist; va_start(arglist, s); ! vim_vsnprintf((char *)IObuff, IOSIZE, (char *)s, arglist, NULL); va_end(arglist); return msg(IObuff); } --- 382,388 ---- va_list arglist; va_start(arglist, s); ! vim_vsnprintf((char *)IObuff, IOSIZE, (char *)s, arglist); va_end(arglist); return msg(IObuff); } *************** *** 396,402 **** va_list arglist; va_start(arglist, s); ! vim_vsnprintf((char *)IObuff, IOSIZE, (char *)s, arglist, NULL); va_end(arglist); return msg_attr(IObuff, attr); } --- 396,402 ---- va_list arglist; va_start(arglist, s); ! vim_vsnprintf((char *)IObuff, IOSIZE, (char *)s, arglist); va_end(arglist); return msg_attr(IObuff, attr); } *************** *** 4232,4238 **** /* * When va_list is not supported we only define vim_snprintf(). * ! * vim_vsnprintf() can be invoked with either "va_list" or a list of * "typval_T". When the latter is not used it must be NULL. */ --- 4232,4238 ---- /* * When va_list is not supported we only define vim_snprintf(). * ! * vim_vsnprintf_typval() can be invoked with either "va_list" or a list of * "typval_T". When the latter is not used it must be NULL. */ *************** *** 4254,4260 **** else space = str_m - len; va_start(ap, fmt); ! str_l = vim_vsnprintf(str + len, space, fmt, ap, NULL); va_end(ap); return str_l; } --- 4254,4260 ---- else space = str_m - len; va_start(ap, fmt); ! str_l = vim_vsnprintf(str + len, space, fmt, ap); va_end(ap); return str_l; } *************** *** 4266,4272 **** int str_l; va_start(ap, fmt); ! str_l = vim_vsnprintf(str, str_m, fmt, ap, NULL); va_end(ap); return str_l; } --- 4266,4272 ---- int str_l; va_start(ap, fmt); ! str_l = vim_vsnprintf(str, str_m, fmt, ap); va_end(ap); return str_l; } *************** *** 4276,4281 **** --- 4276,4291 ---- char *str, size_t str_m, char *fmt, + va_list ap) + { + return vim_vsnprintf_typval(str, str_m, fmt, ap, NULL); + } + + int + vim_vsnprintf_typval( + char *str, + size_t str_m, + char *fmt, va_list ap, typval_T *tvs) { *** ../vim-8.0.0708/src/Makefile 2017-07-11 21:45:26.613831235 +0200 --- src/Makefile 2017-07-11 22:22:04.813588790 +0200 *************** *** 3284,3290 **** Makefile: @echo The name of the makefile MUST be "Makefile" (with capital M)!!!! ! CCCTERM = $(CCC) -Ilibvterm/include -DINLINE="" objects/term_encoding.o: libvterm/src/encoding.c $(TERM_DEPS) $(CCCTERM) -o $@ libvterm/src/encoding.c --- 3284,3290 ---- Makefile: @echo The name of the makefile MUST be "Makefile" (with capital M)!!!! ! CCCTERM = $(CCC) -Ilibvterm/include -DINLINE="" -DVSNPRINTF=vim_vsnprintf objects/term_encoding.o: libvterm/src/encoding.c $(TERM_DEPS) $(CCCTERM) -o $@ libvterm/src/encoding.c *** ../vim-8.0.0708/src/proto.h 2017-07-07 11:53:29.515876528 +0200 --- src/proto.h 2017-07-11 22:11:27.502342137 +0200 *************** *** 127,133 **** # endif vim_snprintf(char *, size_t, char *, ...); ! int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs); # include "message.pro" # include "misc1.pro" --- 127,134 ---- # endif vim_snprintf(char *, size_t, char *, ...); ! int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap); ! int vim_vsnprintf_typval(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs); # include "message.pro" # include "misc1.pro" *** ../vim-8.0.0708/src/evalfunc.c 2017-07-07 11:53:29.511876559 +0200 --- src/evalfunc.c 2017-07-11 22:09:34.619190795 +0200 *************** *** 8043,8056 **** /* Get the required length, allocate the buffer and do it for real. */ did_emsg = FALSE; fmt = (char *)get_tv_string_buf(&argvars[0], buf); ! len = vim_vsnprintf(NULL, 0, fmt, ap, argvars + 1); if (!did_emsg) { s = alloc(len + 1); if (s != NULL) { rettv->vval.v_string = s; ! (void)vim_vsnprintf((char *)s, len + 1, fmt, ap, argvars + 1); } } did_emsg |= saved_did_emsg; --- 8043,8057 ---- /* Get the required length, allocate the buffer and do it for real. */ did_emsg = FALSE; fmt = (char *)get_tv_string_buf(&argvars[0], buf); ! len = vim_vsnprintf_typval(NULL, 0, fmt, ap, argvars + 1); if (!did_emsg) { s = alloc(len + 1); if (s != NULL) { rettv->vval.v_string = s; ! (void)vim_vsnprintf_typval((char *)s, len + 1, fmt, ! ap, argvars + 1); } } did_emsg |= saved_did_emsg; *** ../vim-8.0.0708/src/netbeans.c 2017-01-22 15:19:16.814623922 +0100 --- src/netbeans.c 2017-07-11 22:10:34.590739887 +0200 *************** *** 2301,2307 **** va_list ap; va_start(ap, cmd); ! vim_vsnprintf(buf, sizeof(buf), cmd, ap, NULL); va_end(ap); nbdebug((" COLONCMD %s\n", buf)); --- 2301,2307 ---- va_list ap; va_start(ap, cmd); ! vim_vsnprintf(buf, sizeof(buf), cmd, ap); va_end(ap); nbdebug((" COLONCMD %s\n", buf)); *** ../vim-8.0.0708/src/libvterm/src/vterm.c 2017-07-07 11:53:29.523876467 +0200 --- src/libvterm/src/vterm.c 2017-07-11 22:31:49.777250373 +0200 *************** *** 130,145 **** --- 130,171 ---- return vt->outbuffer_cur >= vt->outbuffer_len - 1; } + #if _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE || _BSD_SOURCE + # undef VSNPRINTF + # define VSNPRINTF vsnprintf + #else + # ifdef VSNPRINTF + /* Use a provided vsnprintf() function. */ + int VSNPRINTF(char *str, size_t str_m, const char *fmt, va_list ap); + # endif + #endif + + INTERNAL void vterm_push_output_vsprintf(VTerm *vt, const char *format, va_list args) { int written; + #ifndef VSNPRINTF + /* When vsnprintf() is not available (C90) fall back to vsprintf(). */ char buffer[1024]; /* 1Kbyte is enough for everybody, right? */ + #endif if(outbuffer_is_full(vt)) { DEBUG_LOG("vterm_push_output(): buffer overflow; truncating output\n"); return; } + #ifdef VSNPRINTF + written = VSNPRINTF(vt->outbuffer + vt->outbuffer_cur, + vt->outbuffer_len - vt->outbuffer_cur, + format, args); + + if(written == (int)(vt->outbuffer_len - vt->outbuffer_cur)) { + /* output was truncated */ + vt->outbuffer_cur = vt->outbuffer_len - 1; + } + else + vt->outbuffer_cur += written; + #else written = vsprintf(buffer, format, args); if(written >= (int)(vt->outbuffer_len - vt->outbuffer_cur)) { *************** *** 151,156 **** --- 177,183 ---- strncpy(vt->outbuffer + vt->outbuffer_cur, buffer, written + 1); vt->outbuffer_cur += written; } + #endif } INTERNAL void vterm_push_output_sprintf(VTerm *vt, const char *format, ...) *** ../vim-8.0.0708/src/version.c 2017-07-11 21:45:26.617831206 +0200 --- src/version.c 2017-07-11 22:32:31.372941878 +0200 *************** *** 766,767 **** --- 766,769 ---- { /* Add new patch number below this line */ + /**/ + 709, /**/ -- hundred-and-one symptoms of being an internet addict: 141. You'd rather go to http://www.weather.com/ than look out your window. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///