To: vim_dev@googlegroups.com Subject: Patch 8.1.2387 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.2387 Problem: Using old C style comments. Solution: Use // comments where appropriate. Files: src/hardcopy.c, src/hashtab.c, src/if_cscope.c, src/if_lua.c, src/if_mzsch.c, src/if_perlsfio.c, src/if_python.c, src/if_python3.c, src/if_ruby.c, src/if_tcl.c, src/if_xcmdsrv.c *** ../vim-8.1.2386/src/hardcopy.c 2019-05-28 23:08:12.064648717 +0200 --- src/hardcopy.c 2019-12-04 20:58:33.379366249 +0100 *************** *** 127,138 **** */ typedef struct { ! int lead_spaces; /* remaining spaces for a TAB */ ! int print_pos; /* virtual column for computing TABs */ ! colnr_T column; /* byte column */ ! linenr_T file_line; /* line nr in the buffer */ ! long_u bytes_printed; /* bytes printed so far */ ! int ff; /* seen form feed character */ } prt_pos_T; static char *parse_list_options(char_u *option_str, option_table_T *table, int table_size); --- 127,138 ---- */ typedef struct { ! int lead_spaces; // remaining spaces for a TAB ! int print_pos; // virtual column for computing TABs ! colnr_T column; // byte column ! linenr_T file_line; // line nr in the buffer ! long_u bytes_printed; // bytes printed so far ! int ff; // seen form feed character } prt_pos_T; static char *parse_list_options(char_u *option_str, option_table_T *table, int table_size); *************** *** 182,191 **** char_u *colonp; char_u *commap; char_u *p; ! int idx = 0; /* init for GCC */ int len; ! /* Save the old values, so that they can be restored in case of an error. */ old_opts = ALLOC_MULT(option_table_T, table_size); if (old_opts == NULL) return NULL; --- 182,191 ---- char_u *colonp; char_u *commap; char_u *p; ! int idx = 0; // init for GCC int len; ! // Save the old values, so that they can be restored in case of an error. old_opts = ALLOC_MULT(option_table_T, table_size); if (old_opts == NULL) return NULL; *************** *** 234,240 **** break; } ! table[idx].number = getdigits(&p); /*advances p*/ } table[idx].string = p; --- 234,240 ---- break; } ! table[idx].number = getdigits(&p); // advances p } table[idx].string = p; *************** *** 247,253 **** if (ret != NULL) { ! /* Restore old options in case of error */ for (idx = 0; idx < table_size; ++idx) table[idx] = old_opts[idx]; } --- 247,253 ---- if (ret != NULL) { ! // Restore old options in case of error for (idx = 0; idx < table_size; ++idx) table[idx] = old_opts[idx]; } *************** *** 272,278 **** static long_u prt_get_term_color(int colorindex) { ! /* TODO: Should check for xterm with 88 or 256 colors. */ if (t_colors > 8) return cterm_color_16[colorindex % 16]; return cterm_color_8[colorindex % 8]; --- 272,278 ---- static long_u prt_get_term_color(int colorindex) { ! // TODO: Should check for xterm with 88 or 256 colors. if (t_colors > 8) return cterm_color_16[colorindex % 16]; return cterm_color_8[colorindex % 8]; *************** *** 328,334 **** pattr->fg_color = fg_color; pattr->bg_color = bg_color; } ! #endif /* FEAT_SYN_HL */ static void prt_set_fg(long_u fg) --- 328,334 ---- pattr->fg_color = fg_color; pattr->bg_color = bg_color; } ! #endif // FEAT_SYN_HL static void prt_set_fg(long_u fg) *************** *** 381,400 **** prt_set_font(psettings->number.bold, psettings->number.italic, psettings->number.underline); mch_print_start_line(TRUE, page_line); ! /* Leave two spaces between the number and the text; depends on ! * PRINT_NUMBER_WIDTH. */ sprintf((char *)tbuf, "%6ld", (long)lnum); for (i = 0; i < 6; i++) (void)mch_print_text_out(&tbuf[i], 1); #ifdef FEAT_SYN_HL if (psettings->do_syntax) ! /* Set colors for next character. */ current_syn_id = -1; else #endif { ! /* Set colors and font back to normal. */ prt_set_fg(PRCOLOR_BLACK); prt_set_bg(PRCOLOR_WHITE); prt_set_font(FALSE, FALSE, FALSE); --- 381,400 ---- prt_set_font(psettings->number.bold, psettings->number.italic, psettings->number.underline); mch_print_start_line(TRUE, page_line); ! // Leave two spaces between the number and the text; depends on ! // PRINT_NUMBER_WIDTH. sprintf((char *)tbuf, "%6ld", (long)lnum); for (i = 0; i < 6; i++) (void)mch_print_text_out(&tbuf[i], 1); #ifdef FEAT_SYN_HL if (psettings->do_syntax) ! // Set colors for next character. current_syn_id = -1; else #endif { ! // Set colors and font back to normal. prt_set_fg(PRCOLOR_BLACK); prt_set_bg(PRCOLOR_WHITE); prt_set_font(FALSE, FALSE, FALSE); *************** *** 458,464 **** char_u *p; int l; ! /* Also use the space for the line number. */ if (prt_use_number()) width += PRINT_NUMBER_WIDTH; --- 458,464 ---- char_u *p; int l; ! // Also use the space for the line number. if (prt_use_number()) width += PRINT_NUMBER_WIDTH; *************** *** 493,499 **** p_header, use_sandbox, ' ', width, NULL, NULL); ! /* Reset line numbers */ curwin->w_cursor.lnum = tmp_lnum; curwin->w_topline = tmp_topline; curwin->w_botline = tmp_botline; --- 493,499 ---- p_header, use_sandbox, ' ', width, NULL, NULL); ! // Reset line numbers curwin->w_cursor.lnum = tmp_lnum; curwin->w_topline = tmp_topline; curwin->w_botline = tmp_botline; *************** *** 506,512 **** prt_set_bg(PRCOLOR_WHITE); prt_set_font(TRUE, FALSE, FALSE); ! /* Use a negative line number to indicate printing in the top margin. */ page_line = 0 - prt_header_height(); mch_print_start_line(TRUE, page_line); for (p = tbuf; *p != NUL; ) --- 506,512 ---- prt_set_bg(PRCOLOR_WHITE); prt_set_font(TRUE, FALSE, FALSE); ! // Use a negative line number to indicate printing in the top margin. page_line = 0 - prt_header_height(); mch_print_start_line(TRUE, page_line); for (p = tbuf; *p != NUL; ) *************** *** 514,520 **** if (mch_print_text_out(p, (l = (*mb_ptr2len)(p)))) { ++page_line; ! if (page_line >= 0) /* out of room in header */ break; mch_print_start_line(TRUE, page_line); } --- 514,520 ---- if (mch_print_text_out(p, (l = (*mb_ptr2len)(p)))) { ++page_line; ! if (page_line >= 0) // out of room in header break; mch_print_start_line(TRUE, page_line); } *************** *** 525,536 **** #ifdef FEAT_SYN_HL if (psettings->do_syntax) ! /* Set colors for next character. */ current_syn_id = -1; else #endif { ! /* Set colors and font back to normal. */ prt_set_fg(PRCOLOR_BLACK); prt_set_bg(PRCOLOR_WHITE); prt_set_font(FALSE, FALSE, FALSE); --- 525,536 ---- #ifdef FEAT_SYN_HL if (psettings->do_syntax) ! // Set colors for next character. current_syn_id = -1; else #endif { ! // Set colors and font back to normal. prt_set_fg(PRCOLOR_BLACK); prt_set_bg(PRCOLOR_WHITE); prt_set_font(FALSE, FALSE, FALSE); *************** *** 566,572 **** { char *errormsg = NULL; ! /* Expand things like "%.ps". */ if (expand_filename(eap, eap->cmdlinep, &errormsg) == FAIL) { if (errormsg != NULL) --- 566,572 ---- { char *errormsg = NULL; ! // Expand things like "%.ps". if (expand_filename(eap, eap->cmdlinep, &errormsg) == FAIL) { if (errormsg != NULL) *************** *** 616,622 **** settings.do_syntax = settings.has_color; #endif ! /* Set up printing attributes for line numbers */ settings.number.fg_color = PRCOLOR_BLACK; settings.number.bg_color = PRCOLOR_WHITE; settings.number.bold = FALSE; --- 616,622 ---- settings.do_syntax = settings.has_color; #endif ! // Set up printing attributes for line numbers settings.number.fg_color = PRCOLOR_BLACK; settings.number.bg_color = PRCOLOR_WHITE; settings.number.bold = FALSE; *************** *** 649,655 **** goto print_fail_no_begin; } ! /* Set colors and font to normal. */ curr_bg = (long_u)0xffffffffL; curr_fg = (long_u)0xffffffffL; curr_italic = MAYBE; --- 649,655 ---- goto print_fail_no_begin; } ! // Set colors and font to normal. curr_bg = (long_u)0xffffffffL; curr_fg = (long_u)0xffffffffL; curr_italic = MAYBE; *************** *** 677,684 **** collated_copies < settings.n_collated_copies; collated_copies++) { ! prt_pos_T prtpos; /* current print position */ ! prt_pos_T page_prtpos; /* print position at page start */ int side; vim_memset(&page_prtpos, 0, sizeof(prt_pos_T)); --- 677,684 ---- collated_copies < settings.n_collated_copies; collated_copies++) { ! prt_pos_T prtpos; // current print position ! prt_pos_T page_prtpos; // print position at page start int side; vim_memset(&page_prtpos, 0, sizeof(prt_pos_T)); *************** *** 687,693 **** if (jobsplit && collated_copies > 0) { ! /* Splitting jobs: Stop a previous job and start a new one. */ mch_print_end(&settings); if (!mch_print_begin(&settings)) goto print_fail_no_begin; --- 687,693 ---- if (jobsplit && collated_copies > 0) { ! // Splitting jobs: Stop a previous job and start a new one. mch_print_end(&settings); if (!mch_print_begin(&settings)) goto print_fail_no_begin; *************** *** 706,712 **** uncollated_copies < settings.n_uncollated_copies; uncollated_copies++) { ! /* Set the print position to the start of this page. */ prtpos = page_prtpos; /* --- 706,712 ---- uncollated_copies < settings.n_uncollated_copies; uncollated_copies++) { ! // Set the print position to the start of this page. prtpos = page_prtpos; /* *************** *** 718,724 **** * Print one page. */ ! /* Check for interrupt character every page. */ ui_breakcheck(); if (got_int || settings.user_abort) goto print_fail; --- 718,724 ---- * Print one page. */ ! // Check for interrupt character every page. ui_breakcheck(); if (got_int || settings.user_abort) goto print_fail; *************** *** 754,769 **** page_line, &prtpos); if (prtpos.column == 0) { ! /* finished a file line */ prtpos.bytes_printed += STRLEN(skipwhite(ml_get(prtpos.file_line))); if (++prtpos.file_line > eap->line2) ! break; /* reached the end */ } else if (prtpos.ff) { ! /* Line had a formfeed in it - start new page but ! * stay on the current line */ break; } } --- 754,769 ---- page_line, &prtpos); if (prtpos.column == 0) { ! // finished a file line prtpos.bytes_printed += STRLEN(skipwhite(ml_get(prtpos.file_line))); if (++prtpos.file_line > eap->line2) ! break; // reached the end } else if (prtpos.ff) { ! // Line had a formfeed in it - start new page but ! // stay on the current line break; } } *************** *** 771,777 **** if (!mch_print_end_page()) goto print_fail; if (prtpos.file_line > eap->line2) ! break; /* reached the end */ } /* --- 771,777 ---- if (!mch_print_end_page()) goto print_fail; if (prtpos.file_line > eap->line2) ! break; // reached the end } /* *************** *** 789,795 **** if (settings.duplex && prtpos.file_line <= eap->line2) ++page_count; ! /* Remember the position where the next page starts. */ page_prtpos = prtpos; } --- 789,795 ---- if (settings.duplex && prtpos.file_line <= eap->line2) ++page_count; ! // Remember the position where the next page starts. page_prtpos = prtpos; } *************** *** 841,847 **** } else { ! /* left over from wrap halfway a tab */ print_pos = ppos->print_pos; tab_spaces = ppos->lead_spaces; } --- 841,847 ---- } else { ! // left over from wrap halfway a tab print_pos = ppos->print_pos; tab_spaces = ppos->lead_spaces; } *************** *** 868,874 **** id = syn_get_final_id(id); else id = 0; ! /* Get the line again, a multi-line regexp may invalidate it. */ line = ml_get(ppos->file_line); if (id != current_syn_id) --- 868,874 ---- id = syn_get_final_id(id); else id = 0; ! // Get the line again, a multi-line regexp may invalidate it. line = ml_get(ppos->file_line); if (id != current_syn_id) *************** *** 903,909 **** if (need_break) break; } ! /* Keep the TAB if we didn't finish it. */ if (need_break && tab_spaces > 0) break; } --- 903,909 ---- if (need_break) break; } ! // Keep the TAB if we didn't finish it. if (need_break && tab_spaces > 0) break; } *************** *** 974,987 **** #define NUM_ELEMENTS(arr) (sizeof(arr)/sizeof((arr)[0])) ! #define PRT_PS_DEFAULT_DPI (72) /* Default user space resolution */ #define PRT_PS_DEFAULT_FONTSIZE (10) #define PRT_PS_DEFAULT_BUFFER_SIZE (80) struct prt_mediasize_S { char *name; ! float width; /* width and height in points for portrait */ float height; }; --- 974,987 ---- #define NUM_ELEMENTS(arr) (sizeof(arr)/sizeof((arr)[0])) ! #define PRT_PS_DEFAULT_DPI (72) // Default user space resolution #define PRT_PS_DEFAULT_FONTSIZE (10) #define PRT_PS_DEFAULT_BUFFER_SIZE (80) struct prt_mediasize_S { char *name; ! float width; // width and height in points for portrait float height; }; *************** *** 998,1011 **** {"B5", 516.0, 729.0}, {"executive", 522.0, 756.0}, {"folio", 595.0, 935.0}, ! {"ledger", 1224.0, 792.0}, /* Yes, it is wider than taller! */ {"legal", 612.0, 1008.0}, {"quarto", 610.0, 780.0}, {"statement", 396.0, 612.0}, {"tabloid", 792.0, 1224.0} }; ! /* PS font names, must be in Roman, Bold, Italic, Bold-Italic order */ struct prt_ps_font_S { int wx; --- 998,1011 ---- {"B5", 516.0, 729.0}, {"executive", 522.0, 756.0}, {"folio", 595.0, 935.0}, ! {"ledger", 1224.0, 792.0}, // Yes, it is wider than taller! {"legal", 612.0, 1008.0}, {"quarto", 610.0, 780.0}, {"statement", 396.0, 612.0}, {"tabloid", 792.0, 1224.0} }; ! // PS font names, must be in Roman, Bold, Italic, Bold-Italic order struct prt_ps_font_S { int wx; *************** *** 1021,1027 **** #define PRT_PS_FONT_OBLIQUE (2) #define PRT_PS_FONT_BOLDOBLIQUE (3) ! /* Standard font metrics for Courier family */ static struct prt_ps_font_S prt_ps_courier_font = { 600, --- 1021,1027 ---- #define PRT_PS_FONT_OBLIQUE (2) #define PRT_PS_FONT_BOLDOBLIQUE (3) ! // Standard font metrics for Courier family static struct prt_ps_font_S prt_ps_courier_font = { 600, *************** *** 1030,1036 **** {"Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique"} }; ! /* Generic font metrics for multi-byte fonts */ static struct prt_ps_font_S prt_ps_mb_font = { 1000, --- 1030,1036 ---- {"Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique"} }; ! // Generic font metrics for multi-byte fonts static struct prt_ps_font_S prt_ps_mb_font = { 1000, *************** *** 1039,1049 **** {NULL, NULL, NULL, NULL} }; ! /* Pointer to current font set being used */ static struct prt_ps_font_S* prt_ps_font; ! /* Structures to map user named encoding and mapping to PS equivalents for ! * building CID font name */ struct prt_ps_encoding_S { char *encoding; --- 1039,1049 ---- {NULL, NULL, NULL, NULL} }; ! // Pointer to current font set being used static struct prt_ps_font_S* prt_ps_font; ! // Structures to map user named encoding and mapping to PS equivalents for ! // building CID font name struct prt_ps_encoding_S { char *encoding; *************** *** 1068,1074 **** #define CS_KANJITALK6 (0x40) #define CS_KANJITALK7 (0x80) ! /* Japanese encodings and charsets */ static struct prt_ps_encoding_S j_encodings[] = { {"iso-2022-jp", NULL, (CS_JIS_C_1978|CS_JIS_X_1983|CS_JIS_X_1990| --- 1068,1074 ---- #define CS_KANJITALK6 (0x40) #define CS_KANJITALK7 (0x80) ! // Japanese encodings and charsets static struct prt_ps_encoding_S j_encodings[] = { {"iso-2022-jp", NULL, (CS_JIS_C_1978|CS_JIS_X_1983|CS_JIS_X_1990| *************** *** 1100,1106 **** #define CS_GBK (0x20) #define CS_SC_ISO10646 (0x40) ! /* Simplified Chinese encodings and charsets */ static struct prt_ps_encoding_S sc_encodings[] = { {"iso-2022", NULL, (CS_GB_2312_80|CS_GBT_12345_90)}, --- 1100,1106 ---- #define CS_GBK (0x20) #define CS_SC_ISO10646 (0x40) ! // Simplified Chinese encodings and charsets static struct prt_ps_encoding_S sc_encodings[] = { {"iso-2022", NULL, (CS_GB_2312_80|CS_GBT_12345_90)}, *************** *** 1136,1142 **** #define CS_DLHKS (0x800) #define CS_TC_ISO10646 (0x1000) ! /* Traditional Chinese encodings and charsets */ static struct prt_ps_encoding_S tc_encodings[] = { {"iso-2022", NULL, (CS_CNS_PLANE_1|CS_CNS_PLANE_2)}, --- 1136,1142 ---- #define CS_DLHKS (0x800) #define CS_TC_ISO10646 (0x1000) ! // Traditional Chinese encodings and charsets static struct prt_ps_encoding_S tc_encodings[] = { {"iso-2022", NULL, (CS_CNS_PLANE_1|CS_CNS_PLANE_2)}, *************** *** 1173,1179 **** #define CS_KR_X_1992_MS (0x04) #define CS_KR_ISO10646 (0x08) ! /* Korean encodings and charsets */ static struct prt_ps_encoding_S k_encodings[] = { {"iso-2022-kr", NULL, CS_KR_X_1992}, --- 1173,1179 ---- #define CS_KR_X_1992_MS (0x04) #define CS_KR_ISO10646 (0x08) ! // Korean encodings and charsets static struct prt_ps_encoding_S k_encodings[] = { {"iso-2022-kr", NULL, CS_KR_X_1992}, *************** *** 1196,1202 **** {"ISO10646", "UniKS", CS_KR_ISO10646} }; ! /* Collections of encodings and charsets for multi-byte printing */ struct prt_ps_mbfont_S { int num_encodings; --- 1196,1202 ---- {"ISO10646", "UniKS", CS_KR_ISO10646} }; ! // Collections of encodings and charsets for multi-byte printing struct prt_ps_mbfont_S { int num_encodings; *************** *** 1252,1278 **** char_u version[256]; }; ! /* Types of PS resource file currently used */ #define PRT_RESOURCE_TYPE_PROCSET (0) #define PRT_RESOURCE_TYPE_ENCODING (1) #define PRT_RESOURCE_TYPE_CMAP (2) ! /* The PS prolog file version number has to match - if the prolog file is ! * updated, increment the number in the file and here. Version checking was ! * added as of VIM 6.2. ! * The CID prolog file version number behaves as per PS prolog. ! * Table of VIM and prolog versions: ! * ! * VIM Prolog CIDProlog ! * 6.2 1.3 ! * 7.0 1.4 1.0 ! */ #define PRT_PROLOG_VERSION ((char_u *)"1.4") #define PRT_CID_PROLOG_VERSION ((char_u *)"1.0") ! /* String versions of PS resource types - indexed by constants above so don't ! * re-order! ! */ static char *prt_resource_types[] = { "procset", --- 1252,1276 ---- char_u version[256]; }; ! // Types of PS resource file currently used #define PRT_RESOURCE_TYPE_PROCSET (0) #define PRT_RESOURCE_TYPE_ENCODING (1) #define PRT_RESOURCE_TYPE_CMAP (2) ! // The PS prolog file version number has to match - if the prolog file is ! // updated, increment the number in the file and here. Version checking was ! // added as of VIM 6.2. ! // The CID prolog file version number behaves as per PS prolog. ! // Table of VIM and prolog versions: ! // ! // VIM Prolog CIDProlog ! // 6.2 1.3 ! // 7.0 1.4 1.0 #define PRT_PROLOG_VERSION ((char_u *)"1.4") #define PRT_CID_PROLOG_VERSION ((char_u *)"1.0") ! // String versions of PS resource types - indexed by constants above so don't ! // re-order! static char *prt_resource_types[] = { "procset", *************** *** 1280,1286 **** "cmap" }; ! /* Strings to look for in a PS resource file */ #define PRT_RESOURCE_HEADER "%!PS-Adobe-" #define PRT_RESOURCE_RESOURCE "Resource-" #define PRT_RESOURCE_PROCSET "ProcSet" --- 1278,1284 ---- "cmap" }; ! // Strings to look for in a PS resource file #define PRT_RESOURCE_HEADER "%!PS-Adobe-" #define PRT_RESOURCE_RESOURCE "Resource-" #define PRT_RESOURCE_PROCSET "ProcSet" *************** *** 1288,1295 **** #define PRT_RESOURCE_CMAP "CMap" ! /* Data for table based DSC comment recognition, easy to extend if VIM needs to ! * read more comments. */ #define PRT_DSC_MISC_TYPE (-1) #define PRT_DSC_TITLE_TYPE (1) #define PRT_DSC_VERSION_TYPE (2) --- 1286,1293 ---- #define PRT_RESOURCE_CMAP "CMap" ! // Data for table based DSC comment recognition, easy to extend if VIM needs to ! // read more comments. #define PRT_DSC_MISC_TYPE (-1) #define PRT_DSC_TITLE_TYPE (1) #define PRT_DSC_VERSION_TYPE (2) *************** *** 1545,1563 **** int fraction; prt_real_bits(val, prec, &integer, &fraction); ! /* Emit integer part */ sprintf((char *)prt_line_buffer, "%d", integer); prt_write_file(prt_line_buffer); ! /* Only emit fraction if necessary */ if (fraction != 0) { ! /* Remove any trailing zeros */ while ((fraction % 10) == 0) { prec--; fraction /= 10; } ! /* Emit fraction left padded with zeros */ sprintf((char *)prt_line_buffer, ".%0*d", prec, fraction); prt_write_file(prt_line_buffer); } --- 1543,1561 ---- int fraction; prt_real_bits(val, prec, &integer, &fraction); ! // Emit integer part sprintf((char *)prt_line_buffer, "%d", integer); prt_write_file(prt_line_buffer); ! // Only emit fraction if necessary if (fraction != 0) { ! // Remove any trailing zeros while ((fraction % 10) == 0) { prec--; fraction /= 10; } ! // Emit fraction left padded with zeros sprintf((char *)prt_line_buffer, ".%0*d", prec, fraction); prt_write_file(prt_line_buffer); } *************** *** 1579,1585 **** prt_write_file(prt_line_buffer); } ! /* Convert size from font space to user space at current font scale */ #define PRT_PS_FONT_TO_USER(scale, size) ((size) * ((scale)/1000.0)) static void --- 1577,1583 ---- prt_write_file(prt_line_buffer); } ! // Convert size from font space to user space at current font scale #define PRT_PS_FONT_TO_USER(scale, size) ((size) * ((scale)/1000.0)) static void *************** *** 1587,1593 **** { if (prt_ps_buffer.ga_len > 0) { ! /* Any background color must be drawn first */ if (prt_do_bgcol && (prt_new_bgcol != PRCOLOR_WHITE)) { int r, g, b; --- 1585,1591 ---- { if (prt_ps_buffer.ga_len > 0) { ! // Any background color must be drawn first if (prt_do_bgcol && (prt_new_bgcol != PRCOLOR_WHITE)) { int r, g, b; *************** *** 1600,1610 **** prt_do_moveto = FALSE; } ! /* Size of rect of background color on which text is printed */ prt_write_real(prt_text_run, 2); prt_write_real(prt_line_height, 2); ! /* Lastly add the color of the background */ r = ((unsigned)prt_new_bgcol & 0xff0000) >> 16; g = ((unsigned)prt_new_bgcol & 0xff00) >> 8; b = prt_new_bgcol & 0xff; --- 1598,1608 ---- prt_do_moveto = FALSE; } ! // Size of rect of background color on which text is printed prt_write_real(prt_text_run, 2); prt_write_real(prt_line_height, 2); ! // Lastly add the color of the background r = ((unsigned)prt_new_bgcol & 0xff0000) >> 16; g = ((unsigned)prt_new_bgcol & 0xff00) >> 8; b = prt_new_bgcol & 0xff; *************** *** 1613,1621 **** prt_write_real(b / 255.0, 3); prt_write_string("bg\n"); } ! /* Draw underlines before the text as it makes it slightly easier to ! * find the starting point. ! */ if (prt_do_underline) { if (prt_do_moveto) --- 1611,1618 ---- prt_write_real(b / 255.0, 3); prt_write_string("bg\n"); } ! // Draw underlines before the text as it makes it slightly easier to ! // find the starting point. if (prt_do_underline) { if (prt_do_moveto) *************** *** 1626,1638 **** prt_do_moveto = FALSE; } ! /* Underline length of text run */ prt_write_real(prt_text_run, 2); prt_write_string("ul\n"); } ! /* Draw the text ! * Note: we write text out raw - EBCDIC conversion is handled in the ! * PostScript world via the font encoding vector. */ if (prt_out_mbyte) prt_write_string("<"); else --- 1623,1635 ---- prt_do_moveto = FALSE; } ! // Underline length of text run prt_write_real(prt_text_run, 2); prt_write_string("ul\n"); } ! // Draw the text ! // Note: we write text out raw - EBCDIC conversion is handled in the ! // PostScript world via the font encoding vector. if (prt_out_mbyte) prt_write_string("<"); else *************** *** 1642,1657 **** prt_write_string(">"); else prt_write_string(")"); ! /* Add a moveto if need be and use the appropriate show procedure */ if (prt_do_moveto) { prt_write_real(prt_pos_x_moveto, 2); prt_write_real(prt_pos_y_moveto, 2); ! /* moveto and a show */ prt_write_string("ms\n"); prt_do_moveto = FALSE; } ! else /* Simple show */ prt_write_string("s\n"); ga_clear(&prt_ps_buffer); --- 1639,1654 ---- prt_write_string(">"); else prt_write_string(")"); ! // Add a moveto if need be and use the appropriate show procedure if (prt_do_moveto) { prt_write_real(prt_pos_x_moveto, 2); prt_write_real(prt_pos_y_moveto, 2); ! // moveto and a show prt_write_string("ms\n"); prt_do_moveto = FALSE; } ! else // Simple show prt_write_string("s\n"); ga_clear(&prt_ps_buffer); *************** *** 1682,1688 **** return FALSE; vim_strncpy(resource->name, (char_u *)name, 63); ! /* Look for named resource file in runtimepath */ STRCPY(buffer, "print"); add_pathsep(buffer); vim_strcat(buffer, (char_u *)name, MAXPATHL); --- 1679,1685 ---- return FALSE; vim_strncpy(resource->name, (char_u *)name, 63); ! // Look for named resource file in runtimepath STRCPY(buffer, "print"); add_pathsep(buffer); vim_strcat(buffer, (char_u *)name, MAXPATHL); *************** *** 1695,1706 **** return retval; } ! /* PS CR and LF characters have platform independent values */ #define PSLF (0x0a) #define PSCR (0x0d) ! /* Static buffer to read initial comments in a resource file, some can have a ! * couple of KB of comments! */ #define PRT_FILE_BUFFER_LEN (2048) struct prt_resfile_buffer_S { --- 1692,1703 ---- return retval; } ! // PS CR and LF characters have platform independent values #define PSLF (0x0a) #define PSCR (0x0d) ! // Static buffer to read initial comments in a resource file, some can have a ! // couple of KB of comments! #define PRT_FILE_BUFFER_LEN (2048) struct prt_resfile_buffer_S { *************** *** 1717,1723 **** { int idx; ! /* Move to start of next line and then find end of line */ idx = prt_resfile.line_end + 1; while (idx < prt_resfile.len) { --- 1714,1720 ---- { int idx; ! // Move to start of next line and then find end of line idx = prt_resfile.line_end + 1; while (idx < prt_resfile.len) { *************** *** 1741,1747 **** static int prt_resfile_strncmp(int offset, char *string, int len) { ! /* Force not equal if string is longer than remainder of line */ if (len > (prt_resfile.line_end - (prt_resfile.line_start + offset))) return 1; --- 1738,1744 ---- static int prt_resfile_strncmp(int offset, char *string, int len) { ! // Force not equal if string is longer than remainder of line if (len > (prt_resfile.line_end - (prt_resfile.line_start + offset))) return 1; *************** *** 1779,1801 **** return -1; } ! /* prt_next_dsc() - returns detail on next DSC comment line found. Returns true ! * if a DSC comment is found, else false */ static int prt_next_dsc(struct prt_dsc_line_S *p_dsc_line) { int comment; int offset; ! /* Move to start of next line */ if (!prt_resfile_next_line()) return FALSE; ! /* DSC comments always start %% */ if (prt_resfile_strncmp(0, "%%", 2) != 0) return FALSE; ! /* Find type of DSC comment */ for (comment = 0; comment < (int)NUM_ELEMENTS(prt_dsc_table); comment++) if (prt_resfile_strncmp(0, prt_dsc_table[comment].string, prt_dsc_table[comment].len) == 0) --- 1776,1798 ---- return -1; } ! // prt_next_dsc() - returns detail on next DSC comment line found. Returns true ! // if a DSC comment is found, else false static int prt_next_dsc(struct prt_dsc_line_S *p_dsc_line) { int comment; int offset; ! // Move to start of next line if (!prt_resfile_next_line()) return FALSE; ! // DSC comments always start %% if (prt_resfile_strncmp(0, "%%", 2) != 0) return FALSE; ! // Find type of DSC comment for (comment = 0; comment < (int)NUM_ELEMENTS(prt_dsc_table); comment++) if (prt_resfile_strncmp(0, prt_dsc_table[comment].string, prt_dsc_table[comment].len) == 0) *************** *** 1803,1822 **** if (comment != NUM_ELEMENTS(prt_dsc_table)) { ! /* Return type of comment */ p_dsc_line->type = prt_dsc_table[comment].type; offset = prt_dsc_table[comment].len; } else { ! /* Unrecognised DSC comment, skip to ws after comment leader */ p_dsc_line->type = PRT_DSC_MISC_TYPE; offset = prt_resfile_skip_nonws(0); if (offset == -1) return FALSE; } ! /* Skip ws to comment value */ offset = prt_resfile_skip_ws(offset); if (offset == -1) return FALSE; --- 1800,1819 ---- if (comment != NUM_ELEMENTS(prt_dsc_table)) { ! // Return type of comment p_dsc_line->type = prt_dsc_table[comment].type; offset = prt_dsc_table[comment].len; } else { ! // Unrecognised DSC comment, skip to ws after comment leader p_dsc_line->type = PRT_DSC_MISC_TYPE; offset = prt_resfile_skip_nonws(0); if (offset == -1) return FALSE; } ! // Skip ws to comment value offset = prt_resfile_skip_ws(offset); if (offset == -1) return FALSE; *************** *** 1827,1833 **** return TRUE; } ! /* Improved hand crafted parser to get the type, title, and version number of a * PS resource file so the file details can be added to the DSC header comments. */ static int --- 1824,1831 ---- return TRUE; } ! /* ! * Improved hand crafted parser to get the type, title, and version number of a * PS resource file so the file details can be added to the DSC header comments. */ static int *************** *** 1848,1854 **** } vim_memset(prt_resfile.buffer, NUL, PRT_FILE_BUFFER_LEN); ! /* Parse first line to ensure valid resource file */ prt_resfile.len = (int)fread((char *)prt_resfile.buffer, sizeof(char_u), PRT_FILE_BUFFER_LEN, fd_resource); if (ferror(fd_resource)) --- 1846,1852 ---- } vim_memset(prt_resfile.buffer, NUL, PRT_FILE_BUFFER_LEN); ! // Parse first line to ensure valid resource file prt_resfile.len = (int)fread((char *)prt_resfile.buffer, sizeof(char_u), PRT_FILE_BUFFER_LEN, fd_resource); if (ferror(fd_resource)) *************** *** 1875,1881 **** return FALSE; } ! /* Skip over any version numbers and following ws */ offset += (int)STRLEN(PRT_RESOURCE_HEADER); offset = prt_resfile_skip_nonws(offset); if (offset == -1) --- 1873,1879 ---- return FALSE; } ! // Skip over any version numbers and following ws offset += (int)STRLEN(PRT_RESOURCE_HEADER); offset = prt_resfile_skip_nonws(offset); if (offset == -1) *************** *** 1893,1899 **** } offset += (int)STRLEN(PRT_RESOURCE_RESOURCE); ! /* Decide type of resource in the file */ if (prt_resfile_strncmp(offset, PRT_RESOURCE_PROCSET, (int)STRLEN(PRT_RESOURCE_PROCSET)) == 0) resource->type = PRT_RESOURCE_TYPE_PROCSET; --- 1891,1897 ---- } offset += (int)STRLEN(PRT_RESOURCE_RESOURCE); ! // Decide type of resource in the file if (prt_resfile_strncmp(offset, PRT_RESOURCE_PROCSET, (int)STRLEN(PRT_RESOURCE_PROCSET)) == 0) resource->type = PRT_RESOURCE_TYPE_PROCSET; *************** *** 1910,1916 **** return FALSE; } ! /* Look for title and version of resource */ resource->title[0] = '\0'; resource->version[0] = '\0'; seen_title = FALSE; --- 1908,1914 ---- return FALSE; } ! // Look for title and version of resource resource->title[0] = '\0'; resource->version[0] = '\0'; seen_title = FALSE; *************** *** 1935,1946 **** break; case PRT_DSC_ENDCOMMENTS_TYPE: ! /* Wont find title or resource after this comment, stop searching */ seen_all = TRUE; break; case PRT_DSC_MISC_TYPE: ! /* Not interested in whatever comment this line had */ break; } } --- 1933,1944 ---- break; case PRT_DSC_ENDCOMMENTS_TYPE: ! // Wont find title or resource after this comment, stop searching seen_all = TRUE; break; case PRT_DSC_MISC_TYPE: ! // Not interested in whatever comment this line had break; } } *************** *** 1958,1964 **** static int prt_check_resource(struct prt_ps_resource_S *resource, char_u *version) { ! /* Version number m.n should match, the revision number does not matter */ if (STRNCMP(resource->version, version, STRLEN(version))) { semsg(_("E621: \"%s\" resource file has wrong version"), --- 1956,1962 ---- static int prt_check_resource(struct prt_ps_resource_S *resource, char_u *version) { ! // Version number m.n should match, the revision number does not matter if (STRNCMP(resource->version, version, STRLEN(version))) { semsg(_("E621: \"%s\" resource file has wrong version"), *************** *** 1966,1972 **** return FALSE; } ! /* Other checks to be added as needed */ return TRUE; } --- 1964,1970 ---- return FALSE; } ! // Other checks to be added as needed return TRUE; } *************** *** 1995,2001 **** static void prt_dsc_text(char *comment, char *text) { ! /* TODO - should scan 'text' for any chars needing escaping! */ vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), "%%%%%s: (%s)\n", comment, text); prt_write_file(prt_line_buffer); --- 1993,1999 ---- static void prt_dsc_text(char *comment, char *text) { ! // TODO - should scan 'text' for any chars needing escaping! vim_snprintf((char *)prt_line_buffer, sizeof(prt_line_buffer), "%%%%%s: (%s)\n", comment, text); prt_write_file(prt_line_buffer); *************** *** 2023,2029 **** static void prt_dsc_resources( ! char *comment, /* if NULL add to previous */ char *type, char *string) { --- 2021,2027 ---- static void prt_dsc_resources( ! char *comment, // if NULL add to previous char *type, char *string) { *************** *** 2060,2068 **** int color, int num_copies) { ! /* Only output the comment if we need to. ! * Note: tumble is ignored if we are not duplexing ! */ if (!(duplex || collate || color || (num_copies > 1))) return; --- 2058,2065 ---- int color, int num_copies) { ! // Only output the comment if we need to. ! // Note: tumble is ignored if we are not duplexing if (!(duplex || collate || color || (num_copies > 1))) return; *************** *** 2082,2088 **** if (num_copies > 1) { prt_write_string(" numcopies("); ! /* Note: no space wanted so don't use prt_write_int() */ sprintf((char *)prt_line_buffer, "%d", num_copies); prt_write_file(prt_line_buffer); prt_write_string(")"); --- 2079,2085 ---- if (num_copies > 1) { prt_write_string(" numcopies("); ! // Note: no space wanted so don't use prt_write_int() sprintf((char *)prt_line_buffer, "%d", num_copies); prt_write_file(prt_line_buffer); prt_write_string(")"); *************** *** 2124,2133 **** { int i; ! /* Free off all CID font names created, but first clear duplicate ! * pointers to the same string (when the same font is used for more than ! * one style). ! */ for (i = PRT_PS_FONT_ROMAN; i <= PRT_PS_FONT_BOLDOBLIQUE; i++) { if (prt_ps_mb_font.ps_fontname[i] != NULL) --- 2121,2129 ---- { int i; ! // Free off all CID font names created, but first clear duplicate ! // pointers to the same string (when the same font is used for more than ! // one style). for (i = PRT_PS_FONT_ROMAN; i <= PRT_PS_FONT_BOLDOBLIQUE; i++) { if (prt_ps_mb_font.ps_fontname[i] != NULL) *************** *** 2218,2226 **** if (prt_use_number()) { prt_number_width = PRINT_NUMBER_WIDTH * prt_char_width; ! /* If we are outputting multi-byte characters then line numbers will be ! * printed with half width characters ! */ if (prt_out_mbyte) prt_number_width /= 2; prt_left_margin += prt_number_width; --- 2214,2221 ---- if (prt_use_number()) { prt_number_width = PRINT_NUMBER_WIDTH * prt_char_width; ! // If we are outputting multi-byte characters then line numbers will be ! // printed with half width characters if (prt_out_mbyte) prt_number_width /= 2; prt_left_margin += prt_number_width; *************** *** 2267,2279 **** prt_ps_font->bbox_min_y)) / 2); } ! /* Get height for topmost line based on background rect offset. */ prt_first_line_height = prt_line_height + prt_bgcol_offset; ! /* Calculate lpp */ lpp = (int)((prt_top_margin - prt_bottom_margin) / prt_line_height); ! /* Adjust top margin if there is a header */ prt_top_margin -= prt_line_height * prt_header_height(); return lpp - prt_header_height(); --- 2262,2274 ---- prt_ps_font->bbox_min_y)) / 2); } ! // Get height for topmost line based on background rect offset. prt_first_line_height = prt_line_height + prt_bgcol_offset; ! // Calculate lpp lpp = (int)((prt_top_margin - prt_bottom_margin) / prt_line_height); ! // Adjust top margin if there is a header prt_top_margin -= prt_line_height * prt_header_height(); return lpp - prt_header_height(); *************** *** 2290,2296 **** struct prt_ps_encoding_S *p_mbenc; *pp_mbenc = NULL; ! /* Look for recognised encoding */ enc_len = (int)STRLEN(p_encoding); p_mbenc = p_cmap->encodings; for (mbenc = 0; mbenc < p_cmap->num_encodings; mbenc++) --- 2285,2291 ---- struct prt_ps_encoding_S *p_mbenc; *pp_mbenc = NULL; ! // Look for recognised encoding enc_len = (int)STRLEN(p_encoding); p_mbenc = p_cmap->encodings; for (mbenc = 0; mbenc < p_cmap->num_encodings; mbenc++) *************** *** 2315,2321 **** int char_len; struct prt_ps_charset_S *p_mbchar; ! /* Look for recognised character set, using default if one is not given */ if (*p_charset == NUL) p_charset = p_cmap->defcs; char_len = (int)STRLEN(p_charset); --- 2310,2316 ---- int char_len; struct prt_ps_charset_S *p_mbchar; ! // Look for recognised character set, using default if one is not given if (*p_charset == NUL) p_charset = p_cmap->defcs; char_len = (int)STRLEN(p_charset); *************** *** 2379,2388 **** if (*p_encoding == NUL) p_encoding = enc_skip(p_enc); ! /* Look for a multi-byte font that matches the encoding and character set. ! * Only look if multi-byte character set is defined, or using multi-byte ! * encoding other than Unicode. This is because a Unicode encoding does not ! * uniquely identify a CJK character set to use. */ p_mbenc = NULL; props = enc_canon_props(p_encoding); if (!(props & ENC_8BIT) && ((*p_pmcs != NUL) || !(props & ENC_UNICODE))) --- 2374,2383 ---- if (*p_encoding == NUL) p_encoding = enc_skip(p_enc); ! // Look for a multi-byte font that matches the encoding and character set. ! // Only look if multi-byte character set is defined, or using multi-byte ! // encoding other than Unicode. This is because a Unicode encoding does not ! // uniquely identify a CJK character set to use. p_mbenc = NULL; props = enc_canon_props(p_encoding); if (!(props & ENC_8BIT) && ((*p_pmcs != NUL) || !(props & ENC_UNICODE))) *************** *** 2404,2410 **** break; } ! /* Use first encoding matched if no charset matched */ if (p_mbchar == NULL && p_mbenc_first != NULL) { p_mbenc = p_mbenc_first; --- 2399,2405 ---- break; } ! // Use first encoding matched if no charset matched if (p_mbchar == NULL && p_mbenc_first != NULL) { p_mbenc = p_mbenc_first; *************** *** 2415,2434 **** prt_out_mbyte = (p_mbenc != NULL); if (prt_out_mbyte) { ! /* Build CMap name - will be same for all multi-byte fonts used */ prt_cmap[0] = NUL; prt_custom_cmap = (p_mbchar == NULL); if (!prt_custom_cmap) { ! /* Check encoding and character set are compatible */ if ((p_mbenc->needs_charset & p_mbchar->has_charset) == 0) { emsg(_("E673: Incompatible multi-byte encoding and character set.")); return FALSE; } ! /* Add charset name if not empty */ if (p_mbchar->cmap_charset != NULL) { vim_strncpy((char_u *)prt_cmap, --- 2410,2429 ---- prt_out_mbyte = (p_mbenc != NULL); if (prt_out_mbyte) { ! // Build CMap name - will be same for all multi-byte fonts used prt_cmap[0] = NUL; prt_custom_cmap = (p_mbchar == NULL); if (!prt_custom_cmap) { ! // Check encoding and character set are compatible if ((p_mbenc->needs_charset & p_mbchar->has_charset) == 0) { emsg(_("E673: Incompatible multi-byte encoding and character set.")); return FALSE; } ! // Add charset name if not empty if (p_mbchar->cmap_charset != NULL) { vim_strncpy((char_u *)prt_cmap, *************** *** 2438,2444 **** } else { ! /* Add custom CMap character set name */ if (*p_pmcs == NUL) { emsg(_("E674: printmbcharset cannot be empty with multi-byte encoding.")); --- 2433,2439 ---- } else { ! // Add custom CMap character set name if (*p_pmcs == NUL) { emsg(_("E674: printmbcharset cannot be empty with multi-byte encoding.")); *************** *** 2448,2454 **** STRCAT(prt_cmap, "-"); } ! /* CMap name ends with (optional) encoding name and -H for horizontal */ if (p_mbenc->cmap_encoding != NULL && STRLEN(prt_cmap) + STRLEN(p_mbenc->cmap_encoding) + 3 < sizeof(prt_cmap)) { --- 2443,2449 ---- STRCAT(prt_cmap, "-"); } ! // CMap name ends with (optional) encoding name and -H for horizontal if (p_mbenc->cmap_encoding != NULL && STRLEN(prt_cmap) + STRLEN(p_mbenc->cmap_encoding) + 3 < sizeof(prt_cmap)) { *************** *** 2463,2469 **** return FALSE; } ! /* Derive CID font names with fallbacks if not defined */ if (!prt_build_cid_fontname(PRT_PS_FONT_ROMAN, mbfont_opts[OPT_MBFONT_REGULAR].string, mbfont_opts[OPT_MBFONT_REGULAR].strlen)) --- 2458,2464 ---- return FALSE; } ! // Derive CID font names with fallbacks if not defined if (!prt_build_cid_fontname(PRT_PS_FONT_ROMAN, mbfont_opts[OPT_MBFONT_REGULAR].string, mbfont_opts[OPT_MBFONT_REGULAR].strlen)) *************** *** 2484,2496 **** mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].strlen)) return FALSE; ! /* Check if need to use Courier for ASCII code range, and if so pick up ! * the encoding to use */ prt_use_courier = mbfont_opts[OPT_MBFONT_USECOURIER].present && (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_USECOURIER].string[0]) == 'y'); if (prt_use_courier) { ! /* Use national ASCII variant unless ASCII wanted */ if (mbfont_opts[OPT_MBFONT_ASCII].present && (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_ASCII].string[0]) == 'y')) prt_ascii_encoding = "ascii"; --- 2479,2491 ---- mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].strlen)) return FALSE; ! // Check if need to use Courier for ASCII code range, and if so pick up ! // the encoding to use prt_use_courier = mbfont_opts[OPT_MBFONT_USECOURIER].present && (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_USECOURIER].string[0]) == 'y'); if (prt_use_courier) { ! // Use national ASCII variant unless ASCII wanted if (mbfont_opts[OPT_MBFONT_ASCII].present && (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_ASCII].string[0]) == 'y')) prt_ascii_encoding = "ascii"; *************** *** 2575,2581 **** psettings->chars_per_line = prt_get_cpl(); psettings->lines_per_page = prt_get_lpp(); ! /* Catch margin settings that leave no space for output! */ if (psettings->chars_per_line <= 0 || psettings->lines_per_page <= 0) return FAIL; --- 2570,2576 ---- psettings->chars_per_line = prt_get_cpl(); psettings->lines_per_page = prt_get_lpp(); ! // Catch margin settings that leave no space for output! if (psettings->chars_per_line <= 0 || psettings->lines_per_page <= 0) return FAIL; *************** *** 2592,2605 **** || TOLOWER_ASC(printer_opts[OPT_PRINT_COLLATE].string[0]) == 'y'); if (prt_collate) { ! /* TODO: Get number of collated copies wanted. */ psettings->n_collated_copies = 1; } else { ! /* TODO: Get number of uncollated copies wanted and update the cached ! * count. ! */ prt_num_copies = 1; } --- 2587,2599 ---- || TOLOWER_ASC(printer_opts[OPT_PRINT_COLLATE].string[0]) == 'y'); if (prt_collate) { ! // TODO: Get number of collated copies wanted. psettings->n_collated_copies = 1; } else { ! // TODO: Get number of uncollated copies wanted and update the cached ! // count. prt_num_copies = 1; } *************** *** 2624,2633 **** prt_tumble = TRUE; } ! /* For now user abort not supported */ psettings->user_abort = 0; ! /* If the user didn't specify a file name, use a temp file. */ if (psettings->outfile == NULL) { prt_ps_file_name = vim_tempname('p', TRUE); --- 2618,2627 ---- prt_tumble = TRUE; } ! // For now user abort not supported psettings->user_abort = 0; ! // If the user didn't specify a file name, use a temp file. if (psettings->outfile == NULL) { prt_ps_file_name = vim_tempname('p', TRUE); *************** *** 2757,2782 **** STRCPY(buffer, "Unknown"); prt_dsc_textline("For", buffer); prt_dsc_textline("Creator", VIM_VERSION_LONG); ! /* Note: to ensure Clean8bit I don't think we can use LC_TIME */ prt_dsc_textline("CreationDate", get_ctime(time(NULL), FALSE)); prt_dsc_textline("DocumentData", "Clean8Bit"); prt_dsc_textline("Orientation", "Portrait"); prt_dsc_atend("Pages"); prt_dsc_textline("PageOrder", "Ascend"); ! /* The bbox does not change with orientation - it is always in the default ! * user coordinate system! We have to recalculate right and bottom ! * coordinates based on the font metrics for the bbox to be accurate. */ prt_page_margins(prt_mediasize[prt_media].width, prt_mediasize[prt_media].height, &left, &right, &top, &bottom); bbox[0] = (int)left; if (prt_portrait) { ! /* In portrait printing the fixed point is the top left corner so we ! * derive the bbox from that point. We have the expected cpl chars ! * across the media and lpp lines down the media. ! */ bbox[1] = (int)(top - (psettings->lines_per_page + prt_header_height()) * prt_line_height); bbox[2] = (int)(left + psettings->chars_per_line * prt_char_width --- 2751,2775 ---- STRCPY(buffer, "Unknown"); prt_dsc_textline("For", buffer); prt_dsc_textline("Creator", VIM_VERSION_LONG); ! // Note: to ensure Clean8bit I don't think we can use LC_TIME prt_dsc_textline("CreationDate", get_ctime(time(NULL), FALSE)); prt_dsc_textline("DocumentData", "Clean8Bit"); prt_dsc_textline("Orientation", "Portrait"); prt_dsc_atend("Pages"); prt_dsc_textline("PageOrder", "Ascend"); ! // The bbox does not change with orientation - it is always in the default ! // user coordinate system! We have to recalculate right and bottom ! // coordinates based on the font metrics for the bbox to be accurate. prt_page_margins(prt_mediasize[prt_media].width, prt_mediasize[prt_media].height, &left, &right, &top, &bottom); bbox[0] = (int)left; if (prt_portrait) { ! // In portrait printing the fixed point is the top left corner so we ! // derive the bbox from that point. We have the expected cpl chars ! // across the media and lpp lines down the media. bbox[1] = (int)(top - (psettings->lines_per_page + prt_header_height()) * prt_line_height); bbox[2] = (int)(left + psettings->chars_per_line * prt_char_width *************** *** 2785,2794 **** } else { ! /* In landscape printing the fixed point is the bottom left corner so we ! * derive the bbox from that point. We have lpp chars across the media ! * and cpl lines up the media. ! */ bbox[1] = (int)bottom; bbox[2] = (int)(left + ((psettings->lines_per_page + prt_header_height()) * prt_line_height) + 0.5); --- 2778,2786 ---- } else { ! // In landscape printing the fixed point is the bottom left corner so we ! // derive the bbox from that point. We have lpp chars across the media ! // and cpl lines up the media. bbox[1] = (int)bottom; bbox[2] = (int)(left + ((psettings->lines_per_page + prt_header_height()) * prt_line_height) + 0.5); *************** *** 2796,2807 **** + 0.5); } prt_dsc_ints("BoundingBox", 4, bbox); ! /* The media width and height does not change with landscape printing! */ prt_dsc_docmedia(prt_mediasize[prt_media].name, prt_mediasize[prt_media].width, prt_mediasize[prt_media].height, (double)0, NULL, NULL); ! /* Define fonts needed */ if (!prt_out_mbyte || prt_use_courier) prt_dsc_font_resource("DocumentNeededResources", &prt_ps_courier_font); if (prt_out_mbyte) --- 2788,2799 ---- + 0.5); } prt_dsc_ints("BoundingBox", 4, bbox); ! // The media width and height does not change with landscape printing! prt_dsc_docmedia(prt_mediasize[prt_media].name, prt_mediasize[prt_media].width, prt_mediasize[prt_media].height, (double)0, NULL, NULL); ! // Define fonts needed if (!prt_out_mbyte || prt_use_courier) prt_dsc_font_resource("DocumentNeededResources", &prt_ps_courier_font); if (prt_out_mbyte) *************** *** 2812,2818 **** prt_dsc_resources(NULL, "cmap", prt_cmap); } ! /* Search for external resources VIM supplies */ if (!prt_find_resource("prolog", res_prolog)) { emsg(_("E456: Can't find PostScript resource file \"prolog.ps\"")); --- 2804,2810 ---- prt_dsc_resources(NULL, "cmap", prt_cmap); } ! // Search for external resources VIM supplies if (!prt_find_resource("prolog", res_prolog)) { emsg(_("E456: Can't find PostScript resource file \"prolog.ps\"")); *************** *** 2824,2830 **** goto theend; if (prt_out_mbyte) { ! /* Look for required version of multi-byte printing procset */ if (!prt_find_resource("cidfont", res_cidfont)) { emsg(_("E456: Can't find PostScript resource file \"cidfont.ps\"")); --- 2816,2822 ---- goto theend; if (prt_out_mbyte) { ! // Look for required version of multi-byte printing procset if (!prt_find_resource("cidfont", res_cidfont)) { emsg(_("E456: Can't find PostScript resource file \"cidfont.ps\"")); *************** *** 2836,2862 **** goto theend; } ! /* Find an encoding to use for printing. ! * Check 'printencoding'. If not set or not found, then use 'encoding'. If ! * that cannot be found then default to "latin1". ! * Note: VIM specific encoding header is always skipped. ! */ if (!prt_out_mbyte) { p_encoding = enc_skip(p_penc); if (*p_encoding == NUL || !prt_find_resource((char *)p_encoding, res_encoding)) { ! /* 'printencoding' not set or not supported - find alternate */ int props; p_encoding = enc_skip(p_enc); props = enc_canon_props(p_encoding); if (!(props & ENC_8BIT) || !prt_find_resource((char *)p_encoding, res_encoding)) ! /* 8-bit 'encoding' is not supported */ ! { ! /* Use latin1 as default printing encoding */ p_encoding = (char_u *)"latin1"; if (!prt_find_resource((char *)p_encoding, res_encoding)) { --- 2828,2853 ---- goto theend; } ! // Find an encoding to use for printing. ! // Check 'printencoding'. If not set or not found, then use 'encoding'. If ! // that cannot be found then default to "latin1". ! // Note: VIM specific encoding header is always skipped. if (!prt_out_mbyte) { p_encoding = enc_skip(p_penc); if (*p_encoding == NUL || !prt_find_resource((char *)p_encoding, res_encoding)) { ! // 'printencoding' not set or not supported - find alternate int props; p_encoding = enc_skip(p_enc); props = enc_canon_props(p_encoding); if (!(props & ENC_8BIT) || !prt_find_resource((char *)p_encoding, res_encoding)) ! // 8-bit 'encoding' is not supported ! { ! // Use latin1 as default printing encoding p_encoding = (char_u *)"latin1"; if (!prt_find_resource((char *)p_encoding, res_encoding)) { *************** *** 2868,2875 **** } if (!prt_open_resource(res_encoding)) goto theend; ! /* For the moment there are no checks on encoding resource files to ! * perform */ } else { --- 2859,2866 ---- } if (!prt_open_resource(res_encoding)) goto theend; ! // For the moment there are no checks on encoding resource files to ! // perform } else { *************** *** 2878,2884 **** p_encoding = enc_skip(p_enc); if (prt_use_courier) { ! /* Include ASCII range encoding vector */ if (!prt_find_resource(prt_ascii_encoding, res_encoding)) { semsg(_("E456: Can't find PostScript resource file \"%s.ps\""), --- 2869,2875 ---- p_encoding = enc_skip(p_enc); if (prt_use_courier) { ! // Include ASCII range encoding vector if (!prt_find_resource(prt_ascii_encoding, res_encoding)) { semsg(_("E456: Can't find PostScript resource file \"%s.ps\""), *************** *** 2887,2900 **** } if (!prt_open_resource(res_encoding)) goto theend; ! /* For the moment there are no checks on encoding resource files to ! * perform */ } } prt_conv.vc_type = CONV_NONE; if (!(enc_canon_props(p_enc) & enc_canon_props(p_encoding) & ENC_8BIT)) { ! /* Set up encoding conversion if required */ if (FAIL == convert_setup(&prt_conv, p_enc, p_encoding)) { semsg(_("E620: Unable to convert to print encoding \"%s\""), --- 2878,2891 ---- } if (!prt_open_resource(res_encoding)) goto theend; ! // For the moment there are no checks on encoding resource files to ! // perform } } prt_conv.vc_type = CONV_NONE; if (!(enc_canon_props(p_enc) & enc_canon_props(p_encoding) & ENC_8BIT)) { ! // Set up encoding conversion if required if (FAIL == convert_setup(&prt_conv, p_enc, p_encoding)) { semsg(_("E620: Unable to convert to print encoding \"%s\""), *************** *** 2907,2913 **** if (prt_out_mbyte && prt_custom_cmap) { ! /* Find user supplied CMap */ if (!prt_find_resource(prt_cmap, res_cmap)) { semsg(_("E456: Can't find PostScript resource file \"%s.ps\""), --- 2898,2904 ---- if (prt_out_mbyte && prt_custom_cmap) { ! // Find user supplied CMap if (!prt_find_resource(prt_cmap, res_cmap)) { semsg(_("E456: Can't find PostScript resource file \"%s.ps\""), *************** *** 2918,2924 **** goto theend; } ! /* List resources supplied */ STRCPY(buffer, res_prolog->title); STRCAT(buffer, " "); STRCAT(buffer, res_prolog->version); --- 2909,2915 ---- goto theend; } ! // List resources supplied STRCPY(buffer, res_prolog->title); STRCAT(buffer, " "); STRCAT(buffer, res_prolog->version); *************** *** 2959,2965 **** */ prt_dsc_noarg("BeginDefaults"); ! /* List font resources most likely common to all pages */ if (!prt_out_mbyte || prt_use_courier) prt_dsc_font_resource("PageResources", &prt_ps_courier_font); if (prt_out_mbyte) --- 2950,2956 ---- */ prt_dsc_noarg("BeginDefaults"); ! // List font resources most likely common to all pages if (!prt_out_mbyte || prt_use_courier) prt_dsc_font_resource("PageResources", &prt_ps_courier_font); if (prt_out_mbyte) *************** *** 2970,2976 **** prt_dsc_resources(NULL, "cmap", prt_cmap); } ! /* Paper will be used for all pages */ prt_dsc_textline("PageMedia", prt_mediasize[prt_media].name); prt_dsc_noarg("EndDefaults"); --- 2961,2967 ---- prt_dsc_resources(NULL, "cmap", prt_cmap); } ! // Paper will be used for all pages prt_dsc_textline("PageMedia", prt_mediasize[prt_media].name); prt_dsc_noarg("EndDefaults"); *************** *** 2980,2991 **** */ prt_dsc_noarg("BeginProlog"); ! /* Add required procsets - NOTE: order is important! */ if (!prt_add_resource(res_prolog)) goto theend; if (prt_out_mbyte) { ! /* Add CID font procset, and any user supplied CMap */ if (!prt_add_resource(res_cidfont)) goto theend; if (prt_custom_cmap && !prt_add_resource(res_cmap)) --- 2971,2982 ---- */ prt_dsc_noarg("BeginProlog"); ! // Add required procsets - NOTE: order is important! if (!prt_add_resource(res_prolog)) goto theend; if (prt_out_mbyte) { ! // Add CID font procset, and any user supplied CMap if (!prt_add_resource(res_cidfont)) goto theend; if (prt_custom_cmap && !prt_add_resource(res_cmap)) *************** *** 2993,3000 **** } if (!prt_out_mbyte || prt_use_courier) ! /* There will be only one Roman font encoding to be included in the PS ! * file. */ if (!prt_add_resource(res_encoding)) goto theend; --- 2984,2991 ---- } if (!prt_out_mbyte || prt_use_courier) ! // There will be only one Roman font encoding to be included in the PS ! // file. if (!prt_add_resource(res_encoding)) goto theend; *************** *** 3005,3011 **** */ prt_dsc_noarg("BeginSetup"); ! /* Device setup - page size and number of uncollated copies */ prt_write_int((int)prt_mediasize[prt_media].width); prt_write_int((int)prt_mediasize[prt_media].height); prt_write_int(0); --- 2996,3002 ---- */ prt_dsc_noarg("BeginSetup"); ! // Device setup - page size and number of uncollated copies prt_write_int((int)prt_mediasize[prt_media].width); prt_write_int((int)prt_mediasize[prt_media].height); prt_write_int(0); *************** *** 3018,3028 **** prt_write_boolean(prt_collate); prt_write_string("c\n"); ! /* Font resource inclusion and definition */ if (!prt_out_mbyte || prt_use_courier) { ! /* When using Courier for ASCII range when printing multi-byte, need to ! * pick up ASCII encoding to use with it. */ if (prt_use_courier) p_encoding = (char_u *)prt_ascii_encoding; prt_dsc_resources("IncludeResource", "font", --- 3009,3019 ---- prt_write_boolean(prt_collate); prt_write_string("c\n"); ! // Font resource inclusion and definition if (!prt_out_mbyte || prt_use_courier) { ! // When using Courier for ASCII range when printing multi-byte, need to ! // pick up ASCII encoding to use with it. if (prt_use_courier) p_encoding = (char_u *)prt_ascii_encoding; prt_dsc_resources("IncludeResource", "font", *************** *** 3044,3055 **** } if (prt_out_mbyte) { ! /* Define the CID fonts to be used in the job. Typically CJKV fonts do ! * not have an italic form being a western style, so where no font is ! * defined for these faces VIM falls back to an existing face. ! * Note: if using Courier for the ASCII range then the printout will ! * have bold/italic/bolditalic regardless of the setting of printmbfont. ! */ prt_dsc_resources("IncludeResource", "font", prt_ps_mb_font.ps_fontname[PRT_PS_FONT_ROMAN]); if (!prt_custom_cmap) --- 3035,3045 ---- } if (prt_out_mbyte) { ! // Define the CID fonts to be used in the job. Typically CJKV fonts do ! // not have an italic form being a western style, so where no font is ! // defined for these faces VIM falls back to an existing face. ! // Note: if using Courier for the ASCII range then the printout will ! // have bold/italic/bolditalic regardless of the setting of printmbfont. prt_dsc_resources("IncludeResource", "font", prt_ps_mb_font.ps_fontname[PRT_PS_FONT_ROMAN]); if (!prt_custom_cmap) *************** *** 3067,3073 **** prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD]); } else ! /* Use ROMAN for BOLD */ prt_dup_cidfont("CF0", "CF1"); if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE] != NULL) --- 3057,3063 ---- prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD]); } else ! // Use ROMAN for BOLD prt_dup_cidfont("CF0", "CF1"); if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE] != NULL) *************** *** 3080,3086 **** prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE]); } else ! /* Use ROMAN for OBLIQUE */ prt_dup_cidfont("CF0", "CF2"); if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE] != NULL) --- 3070,3076 ---- prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE]); } else ! // Use ROMAN for OBLIQUE prt_dup_cidfont("CF0", "CF2"); if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE] != NULL) *************** *** 3093,3103 **** prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]); } else ! /* Use BOLD for BOLDOBLIQUE */ prt_dup_cidfont("CF1", "CF3"); } ! /* Misc constant vars used for underlining and background rects */ prt_def_var("UO", PRT_PS_FONT_TO_USER(prt_line_height, prt_ps_font->uline_offset), 2); prt_def_var("UW", PRT_PS_FONT_TO_USER(prt_line_height, --- 3083,3093 ---- prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]); } else ! // Use BOLD for BOLDOBLIQUE prt_dup_cidfont("CF1", "CF3"); } ! // Misc constant vars used for underlining and background rects prt_def_var("UO", PRT_PS_FONT_TO_USER(prt_line_height, prt_ps_font->uline_offset), 2); prt_def_var("UW", PRT_PS_FONT_TO_USER(prt_line_height, *************** *** 3106,3112 **** prt_dsc_noarg("EndSetup"); ! /* Fail if any problems writing out to the PS file */ retval = !prt_file_error; theend: --- 3096,3102 ---- prt_dsc_noarg("EndSetup"); ! // Fail if any problems writing out to the PS file retval = !prt_file_error; theend: *************** *** 3130,3143 **** prt_dsc_noarg("EOF"); ! /* Write CTRL-D to close serial communication link if used. ! * NOTHING MUST BE WRITTEN AFTER THIS! */ prt_write_file((char_u *)IF_EB("\004", "\067")); if (!prt_file_error && psettings->outfile == NULL && !got_int && !psettings->user_abort) { ! /* Close the file first. */ if (prt_ps_fd != NULL) { fclose(prt_ps_fd); --- 3120,3133 ---- prt_dsc_noarg("EOF"); ! // Write CTRL-D to close serial communication link if used. ! // NOTHING MUST BE WRITTEN AFTER THIS! prt_write_file((char_u *)IF_EB("\004", "\067")); if (!prt_file_error && psettings->outfile == NULL && !got_int && !psettings->user_abort) { ! // Close the file first. if (prt_ps_fd != NULL) { fclose(prt_ps_fd); *************** *** 3145,3151 **** } prt_message((char_u *)_("Sending to printer...")); ! /* Not printing to a file: use 'printexpr' to print the file. */ if (eval_printexpr(prt_ps_file_name, psettings->arguments) == FAIL) emsg(_("E365: Failed to print PostScript file")); else --- 3135,3141 ---- } prt_message((char_u *)_("Sending to printer...")); ! // Not printing to a file: use 'printexpr' to print the file. if (eval_printexpr(prt_ps_file_name, psettings->arguments) == FAIL) emsg(_("E365: Failed to print PostScript file")); else *************** *** 3189,3195 **** prt_bgcol = PRCOLOR_WHITE; prt_font = PRT_PS_FONT_ROMAN; ! /* Set up page transformation for landscape printing. */ if (!prt_portrait) { prt_write_int(-((int)prt_mediasize[prt_media].width)); --- 3179,3185 ---- prt_bgcol = PRCOLOR_WHITE; prt_font = PRT_PS_FONT_ROMAN; ! // Set up page transformation for landscape printing. if (!prt_portrait) { prt_write_int(-((int)prt_mediasize[prt_media].width)); *************** *** 3198,3204 **** prt_dsc_noarg("EndPageSetup"); ! /* We have reset the font attributes, force setting them again. */ curr_bg = (long_u)0xffffffff; curr_fg = (long_u)0xffffffff; curr_bold = MAYBE; --- 3188,3194 ---- prt_dsc_noarg("EndPageSetup"); ! // We have reset the font attributes, force setting them again. curr_bg = (long_u)0xffffffff; curr_fg = (long_u)0xffffffff; curr_bold = MAYBE; *************** *** 3245,3257 **** char_width = prt_char_width; ! /* Ideally VIM would create a rearranged CID font to combine a Roman and ! * CJKV font to do what VIM is doing here - use a Roman font for characters ! * in the ASCII range, and the original CID font for everything else. ! * The problem is that GhostScript still (as of 8.13) does not support ! * rearranged fonts even though they have been documented by Adobe for 7 ! * years! If they ever do, a lot of this code will disappear. ! */ if (prt_use_courier) { in_ascii = (len == 1 && *p < 0x80); --- 3235,3246 ---- char_width = prt_char_width; ! // Ideally VIM would create a rearranged CID font to combine a Roman and ! // CJKV font to do what VIM is doing here - use a Roman font for characters ! // in the ASCII range, and the original CID font for everything else. ! // The problem is that GhostScript still (as of 8.13) does not support ! // rearranged fonts even though they have been documented by Adobe for 7 ! // years! If they ever do, a lot of this code will disappear. if (prt_use_courier) { in_ascii = (len == 1 && *p < 0x80); *************** *** 3259,3265 **** { if (!in_ascii) { ! /* No longer in ASCII range - need to switch font */ prt_in_ascii = FALSE; prt_need_font = TRUE; prt_attribute_change = TRUE; --- 3248,3254 ---- { if (!in_ascii) { ! // No longer in ASCII range - need to switch font prt_in_ascii = FALSE; prt_need_font = TRUE; prt_attribute_change = TRUE; *************** *** 3267,3273 **** } else if (in_ascii) { ! /* Now in ASCII range - need to switch font */ prt_in_ascii = TRUE; prt_need_font = TRUE; prt_attribute_change = TRUE; --- 3256,3262 ---- } else if (in_ascii) { ! // Now in ASCII range - need to switch font prt_in_ascii = TRUE; prt_need_font = TRUE; prt_attribute_change = TRUE; *************** *** 3297,3309 **** } } ! /* Output any required changes to the graphics state, after flushing any ! * text buffered so far. ! */ if (prt_attribute_change) { prt_flush_buffer(); ! /* Reset count of number of chars that will be printed */ prt_text_run = 0; if (prt_need_moveto) --- 3286,3297 ---- } } ! // Output any required changes to the graphics state, after flushing any ! // text buffered so far. if (prt_attribute_change) { prt_flush_buffer(); ! // Reset count of number of chars that will be printed prt_text_run = 0; if (prt_need_moveto) *************** *** 3362,3368 **** if (prt_do_conv) { ! /* Convert from multi-byte to 8-bit encoding */ tofree = p = string_convert(&prt_conv, p, &len); if (p == NULL) { --- 3350,3356 ---- if (prt_do_conv) { ! // Convert from multi-byte to 8-bit encoding tofree = p = string_convert(&prt_conv, p, &len); if (p == NULL) { *************** *** 3373,3381 **** if (prt_out_mbyte) { ! /* Multi-byte character strings are represented more efficiently as hex ! * strings when outputting clean 8 bit PS. ! */ while (len-- > 0) { ch = prt_hexchar[(unsigned)(*p) >> 4]; --- 3361,3368 ---- if (prt_out_mbyte) { ! // Multi-byte character strings are represented more efficiently as hex ! // strings when outputting clean 8 bit PS. while (len-- > 0) { ch = prt_hexchar[(unsigned)(*p) >> 4]; *************** *** 3387,3405 **** } else { ! /* Add next character to buffer of characters to output. ! * Note: One printed character may require several PS characters to ! * represent it, but we only count them as one printed character. ! */ ch = *p; if (ch < 32 || ch == '(' || ch == ')' || ch == '\\') { ! /* Convert non-printing characters to either their escape or octal ! * sequence, ensures PS sent over a serial line does not interfere ! * with the comms protocol. Note: For EBCDIC we need to write out ! * the escape sequences as ASCII codes! ! * Note 2: Char codes < 32 are identical in EBCDIC and ASCII AFAIK! ! */ ga_append(&prt_ps_buffer, IF_EB('\\', 0134)); switch (ch) { --- 3374,3390 ---- } else { ! // Add next character to buffer of characters to output. ! // Note: One printed character may require several PS characters to ! // represent it, but we only count them as one printed character. ch = *p; if (ch < 32 || ch == '(' || ch == ')' || ch == '\\') { ! // Convert non-printing characters to either their escape or octal ! // sequence, ensures PS sent over a serial line does not interfere ! // with the comms protocol. Note: For EBCDIC we need to write out ! // the escape sequences as ASCII codes! ! // Note 2: Char codes < 32 are identical in EBCDIC and ASCII AFAIK! ga_append(&prt_ps_buffer, IF_EB('\\', 0134)); switch (ch) { *************** *** 3427,3439 **** ga_append(&prt_ps_buffer, ch); } ! /* Need to free any translated characters */ vim_free(tofree); prt_text_run += char_width; prt_pos_x += char_width; ! /* The downside of fp - use relative error on right margin check */ next_pos = prt_pos_x + prt_char_width; need_break = (next_pos > prt_right_margin) && ((next_pos - prt_right_margin) > (prt_right_margin*1e-5)); --- 3412,3424 ---- ga_append(&prt_ps_buffer, ch); } ! // Need to free any translated characters vim_free(tofree); prt_text_run += char_width; prt_pos_x += char_width; ! // The downside of fp - use relative error on right margin check next_pos = prt_pos_x + prt_char_width; need_break = (next_pos > prt_right_margin) && ((next_pos - prt_right_margin) > (prt_right_margin*1e-5)); *************** *** 3487,3491 **** } } ! # endif /*FEAT_POSTSCRIPT*/ ! #endif /*FEAT_PRINTER*/ --- 3472,3476 ---- } } ! # endif //FEAT_POSTSCRIPT ! #endif //FEAT_PRINTER *** ../vim-8.1.2386/src/hashtab.c 2019-07-26 21:26:31.163382011 +0200 --- src/hashtab.c 2019-12-04 20:59:07.127241623 +0100 *************** *** 30,47 **** #include "vim.h" #if 0 ! # define HT_DEBUG /* extra checks for table consistency and statistics */ ! static long hash_count_lookup = 0; /* count number of hashtab lookups */ ! static long hash_count_perturb = 0; /* count number of "misses" */ #endif ! /* Magic value for algorithm that walks through the array. */ #define PERTURB_SHIFT 5 static int hash_may_resize(hashtab_T *ht, int minitems); ! #if 0 /* currently not used */ /* * Create an empty hash table. * Returns NULL when out of memory. --- 30,47 ---- #include "vim.h" #if 0 ! # define HT_DEBUG // extra checks for table consistency and statistics ! static long hash_count_lookup = 0; // count number of hashtab lookups ! static long hash_count_perturb = 0; // count number of "misses" #endif ! // Magic value for algorithm that walks through the array. #define PERTURB_SHIFT 5 static int hash_may_resize(hashtab_T *ht, int minitems); ! #if 0 // currently not used /* * Create an empty hash table. * Returns NULL when out of memory. *************** *** 64,70 **** void hash_init(hashtab_T *ht) { ! /* This zeroes all "ht_" entries and all the "hi_key" in "ht_smallarray". */ vim_memset(ht, 0, sizeof(hashtab_T)); ht->ht_array = ht->ht_smallarray; ht->ht_mask = HT_INIT_SIZE - 1; --- 64,70 ---- void hash_init(hashtab_T *ht) { ! // This zeroes all "ht_" entries and all the "hi_key" in "ht_smallarray". vim_memset(ht, 0, sizeof(hashtab_T)); ht->ht_array = ht->ht_smallarray; ht->ht_mask = HT_INIT_SIZE - 1; *************** *** 165,171 **** for (perturb = hash; ; perturb >>= PERTURB_SHIFT) { #ifdef HT_DEBUG ! ++hash_count_perturb; /* count a "miss" for hashtab lookup */ #endif idx = (unsigned)((idx << 2U) + idx + perturb + 1U); hi = &ht->ht_array[idx & ht->ht_mask]; --- 165,171 ---- for (perturb = hash; ; perturb >>= PERTURB_SHIFT) { #ifdef HT_DEBUG ! ++hash_count_perturb; // count a "miss" for hashtab lookup #endif idx = (unsigned)((idx << 2U) + idx + perturb + 1U); hi = &ht->ht_array[idx & ht->ht_mask]; *************** *** 231,237 **** char_u *key, hash_T hash) { ! /* If resizing failed before and it fails again we can't add an item. */ if (ht->ht_error && hash_may_resize(ht, 0) == FAIL) return FAIL; --- 231,237 ---- char_u *key, hash_T hash) { ! // If resizing failed before and it fails again we can't add an item. if (ht->ht_error && hash_may_resize(ht, 0) == FAIL) return FAIL; *************** *** 241,251 **** hi->hi_key = key; hi->hi_hash = hash; ! /* When the space gets low may resize the array. */ return hash_may_resize(ht, 0); } ! #if 0 /* not used */ /* * Overwrite hashtable item "hi" with "key". "hi" must point to the item that * is to be overwritten. Thus the number of items in the hashtable doesn't --- 241,251 ---- hi->hi_key = key; hi->hi_hash = hash; ! // When the space gets low may resize the array. return hash_may_resize(ht, 0); } ! #if 0 // not used /* * Overwrite hashtable item "hi" with "key". "hi" must point to the item that * is to be overwritten. Thus the number of items in the hashtable doesn't *************** *** 318,324 **** static int hash_may_resize( hashtab_T *ht, ! int minitems) /* minimal number of items */ { hashitem_T temparray[HT_INIT_SIZE]; hashitem_T *oldarray, *newarray; --- 318,324 ---- static int hash_may_resize( hashtab_T *ht, ! int minitems) // minimal number of items { hashitem_T temparray[HT_INIT_SIZE]; hashitem_T *oldarray, *newarray; *************** *** 330,336 **** long_u newmask; hash_T perturb; ! /* Don't resize a locked table. */ if (ht->ht_locked > 0) return OK; --- 330,336 ---- long_u newmask; hash_T perturb; ! // Don't resize a locked table. if (ht->ht_locked > 0) return OK; *************** *** 343,350 **** if (minitems == 0) { ! /* Return quickly for small tables with at least two NULL items. NULL ! * items are required for the lookup to decide a key isn't there. */ if (ht->ht_filled < HT_INIT_SIZE - 1 && ht->ht_array == ht->ht_smallarray) return OK; --- 343,350 ---- if (minitems == 0) { ! // Return quickly for small tables with at least two NULL items. NULL ! // items are required for the lookup to decide a key isn't there. if (ht->ht_filled < HT_INIT_SIZE - 1 && ht->ht_array == ht->ht_smallarray) return OK; *************** *** 360,368 **** return OK; if (ht->ht_used > 1000) ! minsize = ht->ht_used * 2; /* it's big, don't make too much room */ else ! minsize = ht->ht_used * 4; /* make plenty of room */ } else { --- 360,368 ---- return OK; if (ht->ht_used > 1000) ! minsize = ht->ht_used * 2; // it's big, don't make too much room else ! minsize = ht->ht_used * 4; // make plenty of room } else { *************** *** 375,394 **** newsize = HT_INIT_SIZE; while (newsize < minsize) { ! newsize <<= 1; /* make sure it's always a power of 2 */ if (newsize == 0) ! return FAIL; /* overflow */ } if (newsize == HT_INIT_SIZE) { ! /* Use the small array inside the hashdict structure. */ newarray = ht->ht_smallarray; if (ht->ht_array == newarray) { ! /* Moving from ht_smallarray to ht_smallarray! Happens when there ! * are many removed items. Copy the items to be able to clean up ! * removed items. */ mch_memmove(temparray, newarray, sizeof(temparray)); oldarray = temparray; } --- 375,394 ---- newsize = HT_INIT_SIZE; while (newsize < minsize) { ! newsize <<= 1; // make sure it's always a power of 2 if (newsize == 0) ! return FAIL; // overflow } if (newsize == HT_INIT_SIZE) { ! // Use the small array inside the hashdict structure. newarray = ht->ht_smallarray; if (ht->ht_array == newarray) { ! // Moving from ht_smallarray to ht_smallarray! Happens when there ! // are many removed items. Copy the items to be able to clean up ! // removed items. mch_memmove(temparray, newarray, sizeof(temparray)); oldarray = temparray; } *************** *** 397,409 **** } else { ! /* Allocate an array. */ newarray = ALLOC_MULT(hashitem_T, newsize); if (newarray == NULL) { ! /* Out of memory. When there are NULL items still return OK. ! * Otherwise set ht_error, because lookup may result in a hang if ! * we add another item. */ if (ht->ht_filled < ht->ht_mask) return OK; ht->ht_error = TRUE; --- 397,409 ---- } else { ! // Allocate an array. newarray = ALLOC_MULT(hashitem_T, newsize); if (newarray == NULL) { ! // Out of memory. When there are NULL items still return OK. ! // Otherwise set ht_error, because lookup may result in a hang if ! // we add another item. if (ht->ht_filled < ht->ht_mask) return OK; ht->ht_error = TRUE; *************** *** 470,477 **** return (hash_T)0; p = key + 1; ! /* A simplistic algorithm that appears to do very well. ! * Suggested by George Reilly. */ while (*p != NUL) hash = hash * 101 + *p++; --- 470,477 ---- return (hash_T)0; p = key + 1; ! // A simplistic algorithm that appears to do very well. ! // Suggested by George Reilly. while (*p != NUL) hash = hash * 101 + *p++; *** ../vim-8.1.2386/src/if_cscope.c 2019-09-05 23:03:58.938177885 +0200 --- src/if_cscope.c 2019-12-04 21:02:31.722483639 +0100 *************** *** 51,61 **** static csinfo_T * csinfo = NULL; ! static int csinfo_size = 0; /* number of items allocated in ! csinfo[] */ ! static int eap_arg_len; /* length of eap->arg, set in ! cs_lookup_cmd() */ static cscmd_T cs_cmds[] = { { "add", cs_add, --- 51,61 ---- static csinfo_T * csinfo = NULL; ! static int csinfo_size = 0; // number of items allocated in ! // csinfo[] ! static int eap_arg_len; // length of eap->arg, set in ! // cs_lookup_cmd() static cscmd_T cs_cmds[] = { { "add", cs_add, *************** *** 81,90 **** static enum { ! EXP_CSCOPE_SUBCMD, /* expand ":cscope" sub-commands */ ! EXP_SCSCOPE_SUBCMD, /* expand ":scscope" sub-commands */ ! EXP_CSCOPE_FIND, /* expand ":cscope find" arguments */ ! EXP_CSCOPE_KILL /* expand ":cscope kill" arguments */ } expand_what; /* --- 81,90 ---- static enum { ! EXP_CSCOPE_SUBCMD, // expand ":cscope" sub-commands ! EXP_SCSCOPE_SUBCMD, // expand ":scscope" sub-commands ! EXP_CSCOPE_FIND, // expand ":cscope find" arguments ! EXP_CSCOPE_KILL // expand ":cscope kill" arguments } expand_what; /* *************** *** 100,111 **** switch (expand_what) { case EXP_CSCOPE_SUBCMD: ! /* Complete with sub-commands of ":cscope": ! * add, find, help, kill, reset, show */ return (char_u *)cs_cmds[idx].name; case EXP_SCSCOPE_SUBCMD: ! /* Complete with sub-commands of ":scscope": same sub-commands as ! * ":cscope" but skip commands which don't support split windows */ for (i = 0, current_idx = 0; cs_cmds[i].name != NULL; i++) if (cs_cmds[i].cansplit) if (current_idx++ == idx) --- 100,111 ---- switch (expand_what) { case EXP_CSCOPE_SUBCMD: ! // Complete with sub-commands of ":cscope": ! // add, find, help, kill, reset, show return (char_u *)cs_cmds[idx].name; case EXP_SCSCOPE_SUBCMD: ! // Complete with sub-commands of ":scscope": same sub-commands as ! // ":cscope" but skip commands which don't support split windows for (i = 0, current_idx = 0; cs_cmds[i].name != NULL; i++) if (cs_cmds[i].cansplit) if (current_idx++ == idx) *************** *** 118,137 **** "a", "c", "d", "e", "f", "g", "i", "s", "t", NULL }; ! /* Complete with query type of ":cscope find {query_type}". ! * {query_type} can be letters (c, d, ... a) or numbers (0, 1, ! * ..., 9) but only complete with letters, since numbers are ! * redundant. */ return (char_u *)query_type[idx]; } case EXP_CSCOPE_KILL: { static char connection[5]; ! /* ":cscope kill" accepts connection numbers or partial names of ! * the pathname of the cscope database as argument. Only complete ! * with connection numbers. -1 can also be used to kill all ! * connections. */ for (i = 0, current_idx = 0; i < csinfo_size; i++) { if (csinfo[i].fname == NULL) --- 118,137 ---- "a", "c", "d", "e", "f", "g", "i", "s", "t", NULL }; ! // Complete with query type of ":cscope find {query_type}". ! // {query_type} can be letters (c, d, ... a) or numbers (0, 1, ! // ..., 9) but only complete with letters, since numbers are ! // redundant. return (char_u *)query_type[idx]; } case EXP_CSCOPE_KILL: { static char connection[5]; ! // ":cscope kill" accepts connection numbers or partial names of ! // the pathname of the cscope database as argument. Only complete ! // with connection numbers. -1 can also be used to kill all ! // connections. for (i = 0, current_idx = 0; i < csinfo_size; i++) { if (csinfo[i].fname == NULL) *************** *** 160,176 **** { char_u *p; ! /* Default: expand subcommands */ xp->xp_context = EXPAND_CSCOPE; xp->xp_pattern = arg; expand_what = (cmdidx == CMD_scscope) ? EXP_SCSCOPE_SUBCMD : EXP_CSCOPE_SUBCMD; ! /* (part of) subcommand already typed */ if (*arg != NUL) { p = skiptowhite(arg); ! if (*p != NUL) /* past first word */ { xp->xp_pattern = skipwhite(p); if (*skiptowhite(xp->xp_pattern) != NUL) --- 160,176 ---- { char_u *p; ! // Default: expand subcommands xp->xp_context = EXPAND_CSCOPE; xp->xp_pattern = arg; expand_what = (cmdidx == CMD_scscope) ? EXP_SCSCOPE_SUBCMD : EXP_CSCOPE_SUBCMD; ! // (part of) subcommand already typed if (*arg != NUL) { p = skiptowhite(arg); ! if (*p != NUL) // past first word { xp->xp_pattern = skipwhite(p); if (*skiptowhite(xp->xp_pattern) != NUL) *************** *** 194,200 **** static void do_cscope_general( exarg_T *eap, ! int make_split UNUSED) /* whether to split window */ { cscmd_T *cmdp; --- 194,200 ---- static void do_cscope_general( exarg_T *eap, ! int make_split UNUSED) // whether to split window { cscmd_T *cmdp; *************** *** 333,339 **** vim_strncpy(buf, (char_u *)p, size - 1); return FALSE; ! } /* cs_fgets */ /* --- 333,339 ---- vim_strncpy(buf, (char_u *)p, size - 1); return FALSE; ! } /* *************** *** 483,490 **** */ static int cs_add_common( ! char *arg1, /* filename - may contain environment variables */ ! char *arg2, /* prepend path - may contain environment variables */ char *flags) { stat_T statbuf; --- 483,490 ---- */ static int cs_add_common( ! char *arg1, // filename - may contain environment variables ! char *arg2, // prepend path - may contain environment variables char *flags) { stat_T statbuf; *************** *** 497,503 **** int usedlen = 0; char_u *fbuf = NULL; ! /* get the filename (arg1), expand it, and try to stat it */ if ((fname = alloc(MAXPATHL + 1)) == NULL) goto add_err; --- 497,503 ---- int usedlen = 0; char_u *fbuf = NULL; ! // get the filename (arg1), expand it, and try to stat it if ((fname = alloc(MAXPATHL + 1)) == NULL) goto add_err; *************** *** 520,526 **** goto add_err; } ! /* get the prepend path (arg2), expand it, and try to stat it */ if (arg2 != NULL) { stat_T statbuf2; --- 520,526 ---- goto add_err; } ! // get the prepend path (arg2), expand it, and try to stat it if (arg2 != NULL) { stat_T statbuf2; *************** *** 534,540 **** goto staterr; } ! /* if filename is a directory, append the cscope database name to it */ if (S_ISDIR(statbuf.st_mode)) { fname2 = alloc(strlen(CSCOPE_DBFILE) + strlen(fname) + 2); --- 534,540 ---- goto staterr; } ! // if filename is a directory, append the cscope database name to it if (S_ISDIR(statbuf.st_mode)) { fname2 = alloc(strlen(CSCOPE_DBFILE) + strlen(fname) + 2); *************** *** 607,627 **** vim_free(fname); vim_free(ppath); return CSCOPE_FAILURE; ! } /* cs_add_common */ static int cs_check_for_connections(void) { return (cs_cnt_connections() > 0); ! } /* cs_check_for_connections */ static int cs_check_for_tags(void) { return (p_tags[0] != NUL && curbuf->b_p_tags != NULL); ! } /* cs_check_for_tags */ /* --- 607,627 ---- vim_free(fname); vim_free(ppath); return CSCOPE_FAILURE; ! } static int cs_check_for_connections(void) { return (cs_cnt_connections() > 0); ! } static int cs_check_for_tags(void) { return (p_tags[0] != NUL && curbuf->b_p_tags != NULL); ! } /* *************** *** 639,649 **** cnt++; } return cnt; ! } /* cs_cnt_connections */ static void cs_reading_emsg( ! int idx) /* connection index */ { semsg(_("E262: error reading cscope connection %d"), idx); } --- 639,649 ---- cnt++; } return cnt; ! } static void cs_reading_emsg( ! int idx) // connection index { semsg(_("E262: error reading cscope connection %d"), idx); } *************** *** 708,714 **** vim_free(buf); return nlines; ! } /* cs_cnt_matches */ /* --- 708,714 ---- vim_free(buf); return nlines; ! } /* *************** *** 756,763 **** return NULL; } ! /* Skip white space before the patter, except for text and pattern search, ! * they may want to use the leading white space. */ pat = pattern; if (search != 4 && search != 6) while VIM_ISWHITE(*pat) --- 756,763 ---- return NULL; } ! // Skip white space before the patter, except for text and pattern search, ! // they may want to use the leading white space. pat = pattern; if (search != 4 && search != 6) while VIM_ISWHITE(*pat) *************** *** 769,775 **** (void)sprintf(cmd, "%d%s", search, pat); return cmd; ! } /* cs_create_cmd */ /* --- 769,775 ---- (void)sprintf(cmd, "%d%s", search, pat); return cmd; ! } /* *************** *** 826,832 **** case -1: (void)emsg(_("E622: Could not fork for cscope")); goto err_closing; ! case 0: /* child: run cscope. */ if (dup2(to_cs[0], STDIN_FILENO) == -1) PERROR("cs_create_connection 1"); if (dup2(from_cs[1], STDOUT_FILENO) == -1) --- 826,832 ---- case -1: (void)emsg(_("E622: Could not fork for cscope")); goto err_closing; ! case 0: // child: run cscope. if (dup2(to_cs[0], STDIN_FILENO) == -1) PERROR("cs_create_connection 1"); if (dup2(from_cs[1], STDOUT_FILENO) == -1) *************** *** 834,845 **** if (dup2(from_cs[1], STDERR_FILENO) == -1) PERROR("cs_create_connection 3"); ! /* close unused */ (void)close(to_cs[1]); (void)close(from_cs[0]); #else ! /* MSWIN */ ! /* Create pipes to communicate with cscope */ sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.bInheritHandle = TRUE; sa.lpSecurityDescriptor = NULL; --- 834,845 ---- if (dup2(from_cs[1], STDERR_FILENO) == -1) PERROR("cs_create_connection 3"); ! // close unused (void)close(to_cs[1]); (void)close(from_cs[0]); #else ! // MSWIN ! // Create pipes to communicate with cscope sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.bInheritHandle = TRUE; sa.lpSecurityDescriptor = NULL; *************** *** 862,891 **** return CSCOPE_FAILURE; } #endif ! /* expand the cscope exec for env var's */ if ((prog = alloc(MAXPATHL + 1)) == NULL) { #ifdef UNIX return CSCOPE_FAILURE; #else ! /* MSWIN */ goto err_closing; #endif } expand_env((char_u *)p_csprg, (char_u *)prog, MAXPATHL); ! /* alloc space to hold the cscope command */ len = (int)(strlen(prog) + strlen(csinfo[i].fname) + 32); if (csinfo[i].ppath) { ! /* expand the prepend path for env var's */ if ((ppath = alloc(MAXPATHL + 1)) == NULL) { vim_free(prog); #ifdef UNIX return CSCOPE_FAILURE; #else ! /* MSWIN */ goto err_closing; #endif } --- 862,891 ---- return CSCOPE_FAILURE; } #endif ! // expand the cscope exec for env var's if ((prog = alloc(MAXPATHL + 1)) == NULL) { #ifdef UNIX return CSCOPE_FAILURE; #else ! // MSWIN goto err_closing; #endif } expand_env((char_u *)p_csprg, (char_u *)prog, MAXPATHL); ! // alloc space to hold the cscope command len = (int)(strlen(prog) + strlen(csinfo[i].fname) + 32); if (csinfo[i].ppath) { ! // expand the prepend path for env var's if ((ppath = alloc(MAXPATHL + 1)) == NULL) { vim_free(prog); #ifdef UNIX return CSCOPE_FAILURE; #else ! // MSWIN goto err_closing; #endif } *************** *** 904,919 **** #ifdef UNIX return CSCOPE_FAILURE; #else ! /* MSWIN */ goto err_closing; #endif } ! /* run the cscope command; is there execl for non-unix systems? */ #if defined(UNIX) (void)sprintf(cmd, "exec %s -dl -f %s", prog, csinfo[i].fname); #else ! /* MSWIN */ (void)sprintf(cmd, "%s -dl -f %s", prog, csinfo[i].fname); #endif if (csinfo[i].ppath != NULL) --- 904,919 ---- #ifdef UNIX return CSCOPE_FAILURE; #else ! // MSWIN goto err_closing; #endif } ! // run the cscope command; is there execl for non-unix systems? #if defined(UNIX) (void)sprintf(cmd, "exec %s -dl -f %s", prog, csinfo[i].fname); #else ! // MSWIN (void)sprintf(cmd, "%s -dl -f %s", prog, csinfo[i].fname); #endif if (csinfo[i].ppath != NULL) *************** *** 927,940 **** (void)strcat(cmd, csinfo[i].flags); } # ifdef UNIX ! /* on Win32 we still need prog */ vim_free(prog); # endif vim_free(ppath); #if defined(UNIX) # if defined(HAVE_SETSID) || defined(HAVE_SETPGID) ! /* Change our process group to avoid cscope receiving SIGWINCH. */ # if defined(HAVE_SETSID) (void)setsid(); # else --- 927,940 ---- (void)strcat(cmd, csinfo[i].flags); } # ifdef UNIX ! // on Win32 we still need prog vim_free(prog); # endif vim_free(ppath); #if defined(UNIX) # if defined(HAVE_SETSID) || defined(HAVE_SETPGID) ! // Change our process group to avoid cscope receiving SIGWINCH. # if defined(HAVE_SETSID) (void)setsid(); # else *************** *** 946,953 **** PERROR(_("cs_create_connection exec failed")); exit(127); ! /* NOTREACHED */ ! default: /* parent. */ /* * Save the file descriptors for later duplication, and * reopen as streams. --- 946,953 ---- PERROR(_("cs_create_connection exec failed")); exit(127); ! // NOTREACHED ! default: // parent. /* * Save the file descriptors for later duplication, and * reopen as streams. *************** *** 957,963 **** if ((csinfo[i].fr_fp = fdopen(from_cs[0], "r")) == NULL) PERROR(_("cs_create_connection: fdopen for fr_fp failed")); ! /* close unused */ (void)close(to_cs[0]); (void)close(from_cs[1]); --- 957,963 ---- if ((csinfo[i].fr_fp = fdopen(from_cs[0], "r")) == NULL) PERROR(_("cs_create_connection: fdopen for fr_fp failed")); ! // close unused (void)close(to_cs[0]); (void)close(from_cs[1]); *************** *** 965,975 **** } #else ! /* MSWIN */ ! /* Create a new process to run cscope and use pipes to talk with it */ GetStartupInfo(&si); si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; ! si.wShowWindow = SW_HIDE; /* Hide child application window */ si.hStdOutput = stdout_wr; si.hStdError = stdout_wr; si.hStdInput = stdin_rd; --- 965,975 ---- } #else ! // MSWIN ! // Create a new process to run cscope and use pipes to talk with it GetStartupInfo(&si); si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; ! si.wShowWindow = SW_HIDE; // Hide child application window si.hStdOutput = stdout_wr; si.hStdError = stdout_wr; si.hStdInput = stdin_rd; *************** *** 984,995 **** (void)emsg(_("E623: Could not spawn cscope process")); goto err_closing; } ! /* else */ csinfo[i].pid = pi.dwProcessId; csinfo[i].hProc = pi.hProcess; CloseHandle(pi.hThread); ! /* TODO - tidy up after failure to create files on pipe handles. */ if (((fd = _open_osfhandle((OPEN_OH_ARGTYPE)stdin_wr, _O_TEXT|_O_APPEND)) < 0) || ((csinfo[i].to_fp = _fdopen(fd, "w")) == NULL)) --- 984,995 ---- (void)emsg(_("E623: Could not spawn cscope process")); goto err_closing; } ! // else csinfo[i].pid = pi.dwProcessId; csinfo[i].hProc = pi.hProcess; CloseHandle(pi.hThread); ! // TODO - tidy up after failure to create files on pipe handles. if (((fd = _open_osfhandle((OPEN_OH_ARGTYPE)stdin_wr, _O_TEXT|_O_APPEND)) < 0) || ((csinfo[i].to_fp = _fdopen(fd, "w")) == NULL)) *************** *** 999,1012 **** || ((csinfo[i].fr_fp = _fdopen(fd, "r")) == NULL)) PERROR(_("cs_create_connection: fdopen for fr_fp failed")); ! /* Close handles for file descriptors inherited by the cscope process */ CloseHandle(stdin_rd); CloseHandle(stdout_wr); ! #endif /* !UNIX */ return CSCOPE_SUCCESS; ! } /* cs_create_connection */ /* --- 999,1012 ---- || ((csinfo[i].fr_fp = _fdopen(fd, "r")) == NULL)) PERROR(_("cs_create_connection: fdopen for fr_fp failed")); ! // Close handles for file descriptors inherited by the cscope process CloseHandle(stdin_rd); CloseHandle(stdout_wr); ! #endif // !UNIX return CSCOPE_SUCCESS; ! } /* *************** *** 1050,1056 **** return cs_find_common(opt, pat, eap->forceit, TRUE, eap->cmdidx == CMD_lcscope, *eap->cmdlinep); ! } /* cs_find */ /* --- 1050,1056 ---- return cs_find_common(opt, pat, eap->forceit, TRUE, eap->cmdidx == CMD_lcscope, *eap->cmdlinep); ! } /* *************** *** 1073,1079 **** char cmdletter; char *qfpos; ! /* get cmd letter */ switch (opt[0]) { case '0' : --- 1073,1079 ---- char cmdletter; char *qfpos; ! // get cmd letter switch (opt[0]) { case '0' : *************** *** 1111,1123 **** if (qfpos != NULL) { qfpos++; ! /* next symbol must be + or - */ if (strchr(CSQF_FLAGS, *qfpos) == NULL) { char *nf = _("E469: invalid cscopequickfix flag %c for %c"); char *buf = alloc(strlen(nf)); ! /* strlen will be enough because we use chars */ if (buf != NULL) { sprintf(buf, nf, *qfpos, *(qfpos-1)); --- 1111,1123 ---- if (qfpos != NULL) { qfpos++; ! // next symbol must be + or - if (strchr(CSQF_FLAGS, *qfpos) == NULL) { char *nf = _("E469: invalid cscopequickfix flag %c for %c"); char *buf = alloc(strlen(nf)); ! // strlen will be enough because we use chars if (buf != NULL) { sprintf(buf, nf, *qfpos, *(qfpos-1)); *************** *** 1139,1145 **** } #endif ! /* create the actual command to send to cscope */ cmd = cs_create_cmd(opt, pat); if (cmd == NULL) return FALSE; --- 1139,1145 ---- } #endif ! // create the actual command to send to cscope cmd = cs_create_cmd(opt, pat); if (cmd == NULL) return FALSE; *************** *** 1151,1158 **** return FALSE; } ! /* Send query to all open connections, then count the total number ! * of matches so we can alloc all in one swell foop. */ for (i = 0; i < csinfo_size; i++) nummatches[i] = 0; totmatches = 0; --- 1151,1158 ---- return FALSE; } ! // Send query to all open connections, then count the total number ! // of matches so we can alloc all in one swell foop. for (i = 0; i < csinfo_size; i++) nummatches[i] = 0; totmatches = 0; *************** *** 1161,1167 **** if (csinfo[i].fname == NULL || csinfo[i].to_fp == NULL) continue; ! /* send cmd to cscope */ (void)fprintf(csinfo[i].to_fp, "%s\n", cmd); (void)fflush(csinfo[i].to_fp); --- 1161,1167 ---- if (csinfo[i].fname == NULL || csinfo[i].to_fp == NULL) continue; ! // send cmd to cscope (void)fprintf(csinfo[i].to_fp, "%s\n", cmd); (void)fflush(csinfo[i].to_fp); *************** *** 1202,1208 **** #ifdef FEAT_QUICKFIX if (qfpos != NULL && *qfpos != '0' && totmatches > 0) { ! /* fill error list */ FILE *f; char_u *tmp = vim_tempname('c', TRUE); qf_info_T *qi = NULL; --- 1202,1208 ---- #ifdef FEAT_QUICKFIX if (qfpos != NULL && *qfpos != '0' && totmatches > 0) { ! // fill error list FILE *f; char_u *tmp = vim_tempname('c', TRUE); qf_info_T *qi = NULL; *************** *** 1215,1223 **** { cs_file_results(f, nummatches); fclose(f); ! if (use_ll) /* Use location list */ wp = curwin; ! /* '-' starts a new error list */ if (qf_init(wp, tmp, (char_u *)"%f%*\\t%l%*\\t%m", *qfpos == '-', cmdline, NULL) > 0) { --- 1215,1223 ---- { cs_file_results(f, nummatches); fclose(f); ! if (use_ll) // Use location list wp = curwin; ! // '-' starts a new error list if (qf_init(wp, tmp, (char_u *)"%f%*\\t%l%*\\t%m", *qfpos == '-', cmdline, NULL) > 0) { *************** *** 1247,1258 **** return TRUE; } else ! #endif /* FEAT_QUICKFIX */ { char **matches = NULL, **contexts = NULL; int matched = 0; ! /* read output */ cs_fill_results((char *)pat, totmatches, nummatches, &matches, &contexts, &matched); vim_free(nummatches); --- 1247,1258 ---- return TRUE; } else ! #endif // FEAT_QUICKFIX { char **matches = NULL, **contexts = NULL; int matched = 0; ! // read output cs_fill_results((char *)pat, totmatches, nummatches, &matches, &contexts, &matched); vim_free(nummatches); *************** *** 1264,1270 **** return do_tag((char_u *)pat, DT_CSCOPE, 0, forceit, verbose); } ! } /* cs_find_common */ /* * Print help. --- 1264,1270 ---- return do_tag((char_u *)pat, DT_CSCOPE, 0, forceit, verbose); } ! } /* * Print help. *************** *** 1280,1286 **** char *help = _(cmdp->help); int space_cnt = 30 - vim_strsize((char_u *)help); ! /* Use %*s rather than %30s to ensure proper alignment in utf-8 */ if (space_cnt < 0) space_cnt = 0; (void)smsg(_("%-5s: %s%*s (Usage: %s)"), --- 1280,1286 ---- char *help = _(cmdp->help); int space_cnt = 30 - vim_strsize((char_u *)help); ! // Use %*s rather than %30s to ensure proper alignment in utf-8 if (space_cnt < 0) space_cnt = 0; (void)smsg(_("%-5s: %s%*s (Usage: %s)"), *************** *** 1304,1310 **** wait_return(TRUE); return 0; ! } /* cs_help */ static void --- 1304,1310 ---- wait_return(TRUE); return 0; ! } static void *************** *** 1338,1344 **** NULL, GetLastError(), 0, (LPSTR)&msg, 0, NULL); if (msg != NULL) { ! /* remove trailing \r\n */ char *pcrlf = strstr(msg, "\r\n"); if (pcrlf != NULL) *pcrlf = '\0'; --- 1338,1344 ---- NULL, GetLastError(), 0, (LPSTR)&msg, 0, NULL); if (msg != NULL) { ! // remove trailing \r\n char *pcrlf = strstr(msg, "\r\n"); if (pcrlf != NULL) *pcrlf = '\0'; *************** *** 1363,1370 **** switch (win32_fileinfo((char_u *)fname, &bhfi)) { ! case FILEINFO_ENC_FAIL: /* enc_to_utf16() failed */ ! case FILEINFO_READ_FAIL: /* CreateFile() failed */ if (p_csverbose) { char *cant_msg = _("E625: cannot open cscope database: %s"); --- 1363,1370 ---- switch (win32_fileinfo((char_u *)fname, &bhfi)) { ! case FILEINFO_ENC_FAIL: // enc_to_utf16() failed ! case FILEINFO_READ_FAIL: // CreateFile() failed if (p_csverbose) { char *cant_msg = _("E625: cannot open cscope database: %s"); *************** *** 1376,1394 **** LocalFree(winmsg); } else ! /* subst filename if can't get error text */ (void)semsg(cant_msg, fname); } return -1; ! case FILEINFO_INFO_FAIL: /* GetFileInformationByHandle() failed */ if (p_csverbose) (void)emsg(_("E626: cannot get cscope database information")); return -1; } #endif ! i = -1; /* can be set to the index of an empty item in csinfo */ for (j = 0; j < csinfo_size; j++) { if (csinfo[j].fname != NULL --- 1376,1394 ---- LocalFree(winmsg); } else ! // subst filename if can't get error text (void)semsg(cant_msg, fname); } return -1; ! case FILEINFO_INFO_FAIL: // GetFileInformationByHandle() failed if (p_csverbose) (void)emsg(_("E626: cannot get cscope database information")); return -1; } #endif ! i = -1; // can be set to the index of an empty item in csinfo for (j = 0; j < csinfo_size; j++) { if (csinfo[j].fname != NULL *************** *** 1411,1417 **** } if (csinfo[j].fname == NULL && i == -1) ! i = j; /* remember first empty entry */ } if (i == -1) --- 1411,1417 ---- } if (csinfo[j].fname == NULL && i == -1) ! i = j; // remember first empty entry } if (i == -1) *************** *** 1419,1427 **** i = csinfo_size; if (csinfo_size == 0) { ! /* First time allocation: allocate only 1 connection. It should ! * be enough for most users. If more is needed, csinfo will be ! * reallocated. */ csinfo_size = 1; csinfo = ALLOC_CLEAR_ONE(csinfo_T); } --- 1419,1427 ---- i = csinfo_size; if (csinfo_size == 0) { ! // First time allocation: allocate only 1 connection. It should ! // be enough for most users. If more is needed, csinfo will be ! // reallocated. csinfo_size = 1; csinfo = ALLOC_CLEAR_ONE(csinfo_T); } *************** *** 1429,1435 **** { csinfo_T *t_csinfo = csinfo; ! /* Reallocate space for more connections. */ csinfo_size *= 2; csinfo = vim_realloc(csinfo, sizeof(csinfo_T)*csinfo_size); if (csinfo == NULL) --- 1429,1435 ---- { csinfo_T *t_csinfo = csinfo; ! // Reallocate space for more connections. csinfo_size *= 2; csinfo = vim_realloc(csinfo, sizeof(csinfo_T)*csinfo_size); if (csinfo == NULL) *************** *** 1482,1488 **** csinfo[i].nIndexHigh = bhfi.nFileIndexHigh; #endif return i; ! } /* cs_insert_filelist */ /* --- 1482,1488 ---- csinfo[i].nIndexHigh = bhfi.nFileIndexHigh; #endif return i; ! } /* *************** *** 1498,1504 **** if (eap->arg == NULL) return NULL; ! /* Store length of eap->arg before it gets modified by strtok(). */ eap_arg_len = (int)STRLEN(eap->arg); if ((stok = strtok((char *)(eap->arg), (const char *)" ")) == NULL) --- 1498,1504 ---- if (eap->arg == NULL) return NULL; ! // Store length of eap->arg before it gets modified by strtok(). eap_arg_len = (int)STRLEN(eap->arg); if ((stok = strtok((char *)(eap->arg), (const char *)" ")) == NULL) *************** *** 1511,1517 **** return (cmdp); } return NULL; ! } /* cs_lookup_cmd */ /* --- 1511,1517 ---- return (cmdp); } return NULL; ! } /* *************** *** 1529,1544 **** return CSCOPE_FAILURE; } ! /* only single digit positive and negative integers are allowed */ if ((strlen(stok) < 2 && VIM_ISDIGIT((int)(stok[0]))) || (strlen(stok) < 3 && stok[0] == '-' && VIM_ISDIGIT((int)(stok[1])))) i = atoi(stok); else { ! /* It must be part of a name. We will try to find a match ! * within all the names in the csinfo data structure ! */ for (i = 0; i < csinfo_size; i++) { if (csinfo[i].fname != NULL && strstr(csinfo[i].fname, stok)) --- 1529,1543 ---- return CSCOPE_FAILURE; } ! // only single digit positive and negative integers are allowed if ((strlen(stok) < 2 && VIM_ISDIGIT((int)(stok[0]))) || (strlen(stok) < 3 && stok[0] == '-' && VIM_ISDIGIT((int)(stok[1])))) i = atoi(stok); else { ! // It must be part of a name. We will try to find a match ! // within all the names in the csinfo data structure for (i = 0; i < csinfo_size; i++) { if (csinfo[i].fname != NULL && strstr(csinfo[i].fname, stok)) *************** *** 1566,1572 **** } return 0; ! } /* cs_kill */ /* --- 1565,1571 ---- } return 0; ! } /* *************** *** 1574,1581 **** */ static void cs_kill_execute( ! int i, /* cscope table index */ ! char *cname) /* cscope database name */ { if (p_csverbose) { --- 1573,1580 ---- */ static void cs_kill_execute( ! int i, // cscope table index ! char *cname) // cscope database name { if (p_csverbose) { *************** *** 1612,1628 **** char *search, char *tagstr) { ! /* vim style is ctags: ! * ! * \t\t"\t ! * ! * but as mentioned above, we'll always use the line number and ! * put the search pattern (if one exists) as "extra" ! * ! * buf is used as part of vim's method of handling tags, and ! * (i think) vim frees it when you pop your tags and get replaced ! * by new ones on the tag stack. ! */ char *buf; int amt; --- 1611,1626 ---- char *search, char *tagstr) { ! // vim style is ctags: ! // ! // \t\t"\t ! // ! // but as mentioned above, we'll always use the line number and ! // put the search pattern (if one exists) as "extra" ! // ! // buf is used as part of vim's method of handling tags, and ! // (i think) vim frees it when you pop your tags and get replaced ! // by new ones on the tag stack. char *buf; int amt; *************** *** 1644,1650 **** } return buf; ! } /* cs_make_vim_style_matches */ /* --- 1642,1648 ---- } return buf; ! } /* *************** *** 1716,1728 **** case Print: cs_print_tags_priv(mp, cp, cnt); break; ! default: /* should not reach here */ iemsg(_("E570: fatal error in cs_manage_matches")); return NULL; } return p; ! } /* cs_manage_matches */ /* --- 1714,1726 ---- case Print: cs_print_tags_priv(mp, cp, cnt); break; ! default: // should not reach here iemsg(_("E570: fatal error in cs_manage_matches")); return NULL; } return p; ! } /* *************** *** 1751,1757 **** return NULL; } ! /* If the line's too long for the buffer, discard it. */ if ((p = strchr(buf, '\n')) == NULL) { while ((ch = getc(csinfo[cnumber].fr_fp)) != EOF && ch != '\n') --- 1749,1755 ---- return NULL; } ! // If the line's too long for the buffer, discard it. if ((p = strchr(buf, '\n')) == NULL) { while ((ch = getc(csinfo[cnumber].fr_fp)) != EOF && ch != '\n') *************** *** 1771,1783 **** return NULL; if ((*linenumber = strtok(NULL, (const char *)" ")) == NULL) return NULL; ! *search = *linenumber + strlen(*linenumber) + 1; /* +1 to skip \0 */ ! /* --- nvi --- ! * If the file is older than the cscope database, that is, ! * the database was built since the file was last modified, ! * or there wasn't a search string, use the line number. ! */ if (strcmp(*search, "") == 0) *search = NULL; --- 1769,1780 ---- return NULL; if ((*linenumber = strtok(NULL, (const char *)" ")) == NULL) return NULL; ! *search = *linenumber + strlen(*linenumber) + 1; // +1 to skip \0 ! // --- nvi --- ! // If the file is older than the cscope database, that is, ! // the database was built since the file was last modified, ! // or there wasn't a search string, use the line number. if (strcmp(*search, "") == 0) *search = NULL; *************** *** 1830,1840 **** vim_free(context); vim_free(fullname); ! } /* for all matches */ (void)cs_read_prompt(i); ! } /* for all cscope connections */ vim_free(buf); } #endif --- 1827,1837 ---- vim_free(context); vim_free(fullname); ! } // for all matches (void)cs_read_prompt(i); ! } // for all cscope connections vim_free(buf); } #endif *************** *** 1892,1915 **** if (strcmp(cntx, "") == 0) cntxts[totsofar] = NULL; else ! /* note: if vim_strsave returns NULL, then the context ! * will be "", which is misleading. ! */ cntxts[totsofar] = (char *)vim_strsave((char_u *)cntx); if (matches[totsofar] != NULL) totsofar++; ! } /* for all matches */ (void)cs_read_prompt(i); ! } /* for all cscope connections */ parse_out: if (totsofar == 0) { ! /* No matches, free the arrays and return NULL in "*matches_p". */ VIM_CLEAR(matches); VIM_CLEAR(cntxts); } --- 1889,1911 ---- if (strcmp(cntx, "") == 0) cntxts[totsofar] = NULL; else ! // note: if vim_strsave returns NULL, then the context ! // will be "", which is misleading. cntxts[totsofar] = (char *)vim_strsave((char_u *)cntx); if (matches[totsofar] != NULL) totsofar++; ! } // for all matches (void)cs_read_prompt(i); ! } // for all cscope connections parse_out: if (totsofar == 0) { ! // No matches, free the arrays and return NULL in "*matches_p". VIM_CLEAR(matches); VIM_CLEAR(cntxts); } *************** *** 1918,1927 **** *cntxts_p = cntxts; vim_free(buf); ! } /* cs_fill_results */ ! /* get the requested path components */ static char * cs_pathcomponents(char *path) { --- 1914,1925 ---- *cntxts_p = cntxts; vim_free(buf); ! } ! /* ! * get the requested path components ! */ static char * cs_pathcomponents(char *path) { *************** *** 1956,1962 **** { char *buf = NULL; char *t_buf; ! int bufsize = 0; /* Track available bufsize */ int newsize = 0; char *ptag; char *fname, *lno, *extra, *tbuf; --- 1954,1960 ---- { char *buf = NULL; char *t_buf; ! int bufsize = 0; // Track available bufsize int newsize = 0; char *ptag; char *fname, *lno, *extra, *tbuf; *************** *** 1991,1997 **** vim_free(tbuf); ! msg_puts_attr(_("\n # line"), HL_ATTR(HLF_T)); /* strlen is 7 */ msg_advance(msg_col + 2); msg_puts_attr(_("filename / context / line\n"), HL_ATTR(HLF_T)); --- 1989,1995 ---- vim_free(tbuf); ! msg_puts_attr(_("\n # line"), HL_ATTR(HLF_T)); // strlen is 7 msg_advance(msg_col + 2); msg_puts_attr(_("filename / context / line\n"), HL_ATTR(HLF_T)); *************** *** 2000,2009 **** { idx = i; ! /* if we really wanted to, we could avoid this malloc and strcpy ! * by parsing matches[i] on the fly and placing stuff into buf ! * directly, but that's too much of a hassle ! */ if ((tbuf = alloc(strlen(matches[idx]) + 1)) == NULL) continue; (void)strcpy(tbuf, matches[idx]); --- 1998,2006 ---- { idx = i; ! // if we really wanted to, we could avoid this malloc and strcpy ! // by parsing matches[i] on the fly and placing stuff into buf ! // directly, but that's too much of a hassle if ((tbuf = alloc(strlen(matches[idx]) + 1)) == NULL) continue; (void)strcpy(tbuf, matches[idx]); *************** *** 2017,2025 **** } extra = strtok(NULL, (const char *)"\t"); ! lno[strlen(lno)-2] = '\0'; /* ignore ;" at the end */ ! /* hopefully 'num' (num of matches) will be less than 10^16 */ newsize = (int)(strlen(csfmt_str) + 16 + strlen(lno)); if (bufsize < newsize) { --- 2014,2022 ---- } extra = strtok(NULL, (const char *)"\t"); ! lno[strlen(lno)-2] = '\0'; // ignore ;" at the end ! // hopefully 'num' (num of matches) will be less than 10^16 newsize = (int)(strlen(csfmt_str) + 16 + strlen(lno)); if (bufsize < newsize) { *************** *** 2035,2048 **** } if (buf != NULL) { ! /* csfmt_str = "%4d %6s "; */ (void)sprintf(buf, csfmt_str, num, lno); msg_puts_attr(buf, HL_ATTR(HLF_CM)); } msg_outtrans_long_attr((char_u *)cs_pathcomponents(fname), HL_ATTR(HLF_CM)); ! /* compute the required space for the context */ if (cntxts[idx] != NULL) context = cntxts[idx]; else --- 2032,2045 ---- } if (buf != NULL) { ! // csfmt_str = "%4d %6s "; (void)sprintf(buf, csfmt_str, num, lno); msg_puts_attr(buf, HL_ATTR(HLF_CM)); } msg_outtrans_long_attr((char_u *)cs_pathcomponents(fname), HL_ATTR(HLF_CM)); ! // compute the required space for the context if (cntxts[idx] != NULL) context = cntxts[idx]; else *************** *** 2065,2071 **** { (void)sprintf(buf, cntxformat, context); ! /* print the context only if it fits on the same line */ if (msg_col + (int)strlen(buf) >= (int)Columns) msg_putchar('\n'); msg_advance(12); --- 2062,2068 ---- { (void)sprintf(buf, cntxformat, context); ! // print the context only if it fits on the same line if (msg_col + (int)strlen(buf) >= (int)Columns) msg_putchar('\n'); msg_advance(12); *************** *** 2078,2084 **** msg_outtrans_long_attr((char_u *)extra, 0); } ! vim_free(tbuf); /* only after printing extra due to strtok use */ if (msg_col) msg_putchar('\n'); --- 2075,2081 ---- msg_outtrans_long_attr((char_u *)extra, 0); } ! vim_free(tbuf); // only after printing extra due to strtok use if (msg_col) msg_putchar('\n'); *************** *** 2086,2100 **** ui_breakcheck(); if (got_int) { ! got_int = FALSE; /* don't print any more matches */ break; } num++; ! } /* for all matches */ vim_free(buf); ! } /* cs_print_tags_priv */ /* --- 2083,2097 ---- ui_breakcheck(); if (got_int) { ! got_int = FALSE; // don't print any more matches break; } num++; ! } // for all matches vim_free(buf); ! } /* *************** *** 2104,2110 **** cs_read_prompt(int i) { int ch; ! char *buf = NULL; /* buffer for possible error message from cscope */ int bufpos = 0; char *cs_emsg; int maxlen; --- 2101,2107 ---- cs_read_prompt(int i) { int ch; ! char *buf = NULL; // buffer for possible error message from cscope int bufpos = 0; char *cs_emsg; int maxlen; *************** *** 2113,2148 **** int n; cs_emsg = _("E609: Cscope error: %s"); ! /* compute maximum allowed len for Cscope error message */ maxlen = (int)(IOSIZE - strlen(cs_emsg)); for (;;) { while ((ch = getc(csinfo[i].fr_fp)) != EOF && ch != CSCOPE_PROMPT[0]) ! /* if there is room and char is printable */ if (bufpos < maxlen - 1 && vim_isprintc(ch)) { ! if (buf == NULL) /* lazy buffer allocation */ buf = alloc(maxlen); if (buf != NULL) { ! /* append character to the message */ buf[bufpos++] = ch; buf[bufpos] = NUL; if (bufpos >= epromptlen && strcmp(&buf[bufpos - epromptlen], eprompt) == 0) { ! /* remove eprompt from buf */ buf[bufpos - epromptlen] = NUL; ! /* print message to user */ (void)semsg(cs_emsg, buf); ! /* send RETURN to cscope */ (void)putc('\n', csinfo[i].to_fp); (void)fflush(csinfo[i].to_fp); ! /* clear buf */ bufpos = 0; buf[bufpos] = NUL; } --- 2110,2145 ---- int n; cs_emsg = _("E609: Cscope error: %s"); ! // compute maximum allowed len for Cscope error message maxlen = (int)(IOSIZE - strlen(cs_emsg)); for (;;) { while ((ch = getc(csinfo[i].fr_fp)) != EOF && ch != CSCOPE_PROMPT[0]) ! // if there is room and char is printable if (bufpos < maxlen - 1 && vim_isprintc(ch)) { ! if (buf == NULL) // lazy buffer allocation buf = alloc(maxlen); if (buf != NULL) { ! // append character to the message buf[bufpos++] = ch; buf[bufpos] = NUL; if (bufpos >= epromptlen && strcmp(&buf[bufpos - epromptlen], eprompt) == 0) { ! // remove eprompt from buf buf[bufpos - epromptlen] = NUL; ! // print message to user (void)semsg(cs_emsg, buf); ! // send RETURN to cscope (void)putc('\n', csinfo[i].to_fp); (void)fflush(csinfo[i].to_fp); ! // clear buf bufpos = 0; buf[bufpos] = NUL; } *************** *** 2159,2165 **** if (buf != NULL && buf[0] != NUL) (void)semsg(cs_emsg, buf); else if (p_csverbose) ! cs_reading_emsg(i); /* don't have additional information */ cs_release_csp(i, TRUE); vim_free(buf); return CSCOPE_FAILURE; --- 2156,2162 ---- if (buf != NULL && buf[0] != NUL) (void)semsg(cs_emsg, buf); else if (p_csverbose) ! cs_reading_emsg(i); // don't have additional information cs_release_csp(i, TRUE); vim_free(buf); return CSCOPE_FAILURE; *************** *** 2173,2180 **** } if (ch == EOF) ! continue; /* didn't find the prompt */ ! break; /* did find the prompt */ } vim_free(buf); --- 2170,2177 ---- } if (ch == EOF) ! continue; // didn't find the prompt ! break; // did find the prompt } vim_free(buf); *************** *** 2188,2194 **** static RETSIGTYPE sig_handler SIGDEFARG(sigarg) { ! /* do nothing */ SIGRETURN; } #endif --- 2185,2191 ---- static RETSIGTYPE sig_handler SIGDEFARG(sigarg) { ! // do nothing SIGRETURN; } #endif *************** *** 2217,2223 **** # if defined(HAVE_SIGACTION) struct sigaction sa, old; ! /* Use sigaction() to limit the waiting time to two seconds. */ sigemptyset(&sa.sa_mask); sa.sa_handler = sig_handler; # ifdef SA_NODEFER --- 2214,2220 ---- # if defined(HAVE_SIGACTION) struct sigaction sa, old; ! // Use sigaction() to limit the waiting time to two seconds. sigemptyset(&sa.sa_mask); sa.sa_handler = sig_handler; # ifdef SA_NODEFER *************** *** 2226,2253 **** sa.sa_flags = 0; # endif sigaction(SIGALRM, &sa, &old); ! alarm(2); /* 2 sec timeout */ ! /* Block until cscope exits or until timer expires */ pid = waitpid(csinfo[i].pid, &pstat, 0); waitpid_errno = errno; ! /* cancel pending alarm if still there and restore signal */ alarm(0); sigaction(SIGALRM, &old, NULL); # else int waited; ! /* Can't use sigaction(), loop for two seconds. First yield the CPU ! * to give cscope a chance to exit quickly. */ sleep(0); for (waited = 0; waited < 40; ++waited) { pid = waitpid(csinfo[i].pid, &pstat, WNOHANG); waitpid_errno = errno; if (pid != 0) ! break; /* break unless the process is still running */ ! mch_delay(50L, FALSE); /* sleep 50 ms */ } # endif /* --- 2223,2250 ---- sa.sa_flags = 0; # endif sigaction(SIGALRM, &sa, &old); ! alarm(2); // 2 sec timeout ! // Block until cscope exits or until timer expires pid = waitpid(csinfo[i].pid, &pstat, 0); waitpid_errno = errno; ! // cancel pending alarm if still there and restore signal alarm(0); sigaction(SIGALRM, &old, NULL); # else int waited; ! // Can't use sigaction(), loop for two seconds. First yield the CPU ! // to give cscope a chance to exit quickly. sleep(0); for (waited = 0; waited < 40; ++waited) { pid = waitpid(csinfo[i].pid, &pstat, WNOHANG); waitpid_errno = errno; if (pid != 0) ! break; // break unless the process is still running ! mch_delay(50L, FALSE); // sleep 50 ms } # endif /* *************** *** 2276,2288 **** sleep(0); for (waited = 0; waited < 40; ++waited) { ! /* Check whether cscope process is still alive */ if (kill(csinfo[i].pid, 0) != 0) { ! alive = FALSE; /* cscope process no longer exists */ break; } ! mch_delay(50L, FALSE); /* sleep 50ms */ } } if (alive) --- 2273,2285 ---- sleep(0); for (waited = 0; waited < 40; ++waited) { ! // Check whether cscope process is still alive if (kill(csinfo[i].pid, 0) != 0) { ! alive = FALSE; // cscope process no longer exists break; } ! mch_delay(50L, FALSE); // sleep 50ms } } if (alive) *************** *** 2293,2302 **** } } } ! #else /* !UNIX */ if (csinfo[i].hProc != NULL) { ! /* Give cscope a chance to exit normally */ if (WaitForSingleObject(csinfo[i].hProc, 1000) == WAIT_TIMEOUT) TerminateProcess(csinfo[i].hProc, 0); CloseHandle(csinfo[i].hProc); --- 2290,2299 ---- } } } ! #else // !UNIX if (csinfo[i].hProc != NULL) { ! // Give cscope a chance to exit normally if (WaitForSingleObject(csinfo[i].hProc, 1000) == WAIT_TIMEOUT) TerminateProcess(csinfo[i].hProc, 0); CloseHandle(csinfo[i].hProc); *************** *** 2316,2322 **** } clear_csinfo(i); ! } /* cs_release_csp */ /* --- 2313,2319 ---- } clear_csinfo(i); ! } /* *************** *** 2327,2338 **** { char **dblist = NULL, **pplist = NULL, **fllist = NULL; int i; ! char buf[20]; /* for sprintf " (#%d)" */ if (csinfo_size == 0) return CSCOPE_SUCCESS; ! /* malloc our db and ppath list */ dblist = ALLOC_MULT(char *, csinfo_size); pplist = ALLOC_MULT(char *, csinfo_size); fllist = ALLOC_MULT(char *, csinfo_size); --- 2324,2335 ---- { char **dblist = NULL, **pplist = NULL, **fllist = NULL; int i; ! char buf[20]; // for sprintf " (#%d)" if (csinfo_size == 0) return CSCOPE_SUCCESS; ! // malloc our db and ppath list dblist = ALLOC_MULT(char *, csinfo_size); pplist = ALLOC_MULT(char *, csinfo_size); fllist = ALLOC_MULT(char *, csinfo_size); *************** *** 2353,2359 **** cs_release_csp(i, FALSE); } ! /* rebuild the cscope connection list */ for (i = 0; i < csinfo_size; i++) { if (dblist[i] != NULL) --- 2350,2356 ---- cs_release_csp(i, FALSE); } ! // rebuild the cscope connection list for (i = 0; i < csinfo_size; i++) { if (dblist[i] != NULL) *************** *** 2361,2370 **** cs_add_common(dblist[i], pplist[i], fllist[i]); if (p_csverbose) { ! /* don't use smsg_attr() because we want to display the ! * connection number in the same line as ! * "Added cscope database..." ! */ sprintf(buf, " (#%d)", i); msg_puts_attr(buf, HL_ATTR(HLF_R)); } --- 2358,2366 ---- cs_add_common(dblist[i], pplist[i], fllist[i]); if (p_csverbose) { ! // don't use smsg_attr() because we want to display the ! // connection number in the same line as ! // "Added cscope database..." sprintf(buf, " (#%d)", i); msg_puts_attr(buf, HL_ATTR(HLF_R)); } *************** *** 2380,2386 **** if (p_csverbose) msg_attr(_("All cscope databases reset"), HL_ATTR(HLF_R) | MSG_HIST); return CSCOPE_SUCCESS; ! } /* cs_reset */ /* --- 2376,2382 ---- if (p_csverbose) msg_attr(_("All cscope databases reset"), HL_ATTR(HLF_R) | MSG_HIST); return CSCOPE_SUCCESS; ! } /* *************** *** 2409,2416 **** len += (int)strlen(csinfo[i].ppath); else if (p_csre && csinfo[i].fname != NULL) { ! /* If 'cscoperelative' is set and ppath is not set, use cscope.out ! * path in path resolution. */ csdir = alloc(MAXPATHL); if (csdir != NULL) { --- 2405,2412 ---- len += (int)strlen(csinfo[i].ppath); else if (p_csre && csinfo[i].fname != NULL) { ! // If 'cscoperelative' is set and ppath is not set, use cscope.out ! // path in path resolution. csdir = alloc(MAXPATHL); if (csdir != NULL) { *************** *** 2421,2429 **** } } ! /* Note/example: this won't work if the cscope output already starts ! * "../.." and the prefix path is also "../..". if something like this ! * happens, you are screwed up and need to fix how you're using cscope. */ if (csinfo[i].ppath != NULL && (strncmp(name, csinfo[i].ppath, strlen(csinfo[i].ppath)) != 0) && (name[0] != '/') --- 2417,2425 ---- } } ! // Note/example: this won't work if the cscope output already starts ! // "../.." and the prefix path is also "../..". if something like this ! // happens, you are screwed up and need to fix how you're using cscope. if (csinfo[i].ppath != NULL && (strncmp(name, csinfo[i].ppath, strlen(csinfo[i].ppath)) != 0) && (name[0] != '/') *************** *** 2437,2444 **** } else if (csdir != NULL && csinfo[i].fname != NULL && *csdir != NUL) { ! /* Check for csdir to be non empty to avoid empty path concatenated to ! * cscope output. */ fullname = (char *)concat_fnames(csdir, (char_u *)name, TRUE); } else --- 2433,2440 ---- } else if (csdir != NULL && csinfo[i].fname != NULL && *csdir != NUL) { ! // Check for csdir to be non empty to avoid empty path concatenated to ! // cscope output. fullname = (char *)concat_fnames(csdir, (char_u *)name, TRUE); } else *************** *** 2481,2487 **** wait_return(TRUE); return CSCOPE_SUCCESS; ! } /* cs_show */ /* --- 2477,2483 ---- wait_return(TRUE); return CSCOPE_SUCCESS; ! } /* *************** *** 2498,2504 **** csinfo_size = 0; } ! #endif /* FEAT_CSCOPE */ #if defined(FEAT_EVAL) || defined(PROTO) --- 2494,2500 ---- csinfo_size = 0; } ! #endif // FEAT_CSCOPE #if defined(FEAT_EVAL) || defined(PROTO) *** ../vim-8.1.2386/src/if_lua.c 2019-10-19 15:18:38.907008718 +0200 --- src/if_lua.c 2019-12-04 21:04:38.058013817 +0100 *************** *** 15,22 **** #include #include ! /* Only do the following when the feature is enabled. Needed for "make ! * depend". */ #if defined(FEAT_LUA) || defined(PROTO) #define LUAVIM_CHUNKNAME "vim chunk" --- 15,22 ---- #include #include ! // Only do the following when the feature is enabled. Needed for "make ! // depend". #if defined(FEAT_LUA) || defined(PROTO) #define LUAVIM_CHUNKNAME "vim chunk" *************** *** 45,53 **** static const char LUAVIM_LUAEVAL[] = "luaV_luaeval"; static const char LUAVIM_SETREF[] = "luaV_setref"; ! /* most functions are closures with a cache table as first upvalue; ! * get/setudata manage references to vim userdata in cache table through ! * object pointers (light userdata) */ #define luaV_getudata(L, v) \ lua_pushlightuserdata((L), (void *) (v)); \ lua_rawget((L), lua_upvalueindex(1)) --- 45,53 ---- static const char LUAVIM_LUAEVAL[] = "luaV_luaeval"; static const char LUAVIM_SETREF[] = "luaV_setref"; ! // most functions are closures with a cache table as first upvalue; ! // get/setudata manage references to vim userdata in cache table through ! // object pointers (light userdata) #define luaV_getudata(L, v) \ lua_pushlightuserdata((L), (void *) (v)); \ lua_rawget((L), lua_upvalueindex(1)) *************** *** 94,100 **** # define close_dll FreeLibrary #endif ! /* lauxlib */ #if LUA_VERSION_NUM <= 501 #define luaL_register dll_luaL_register #define luaL_prepbuffer dll_luaL_prepbuffer --- 94,100 ---- # define close_dll FreeLibrary #endif ! // lauxlib #if LUA_VERSION_NUM <= 501 #define luaL_register dll_luaL_register #define luaL_prepbuffer dll_luaL_prepbuffer *************** *** 119,125 **** #define luaL_buffinit dll_luaL_buffinit #define luaL_addlstring dll_luaL_addlstring #define luaL_pushresult dll_luaL_pushresult ! /* lua */ #if LUA_VERSION_NUM <= 501 #define lua_tonumber dll_lua_tonumber #define lua_tointeger dll_lua_tointeger --- 119,125 ---- #define luaL_buffinit dll_luaL_buffinit #define luaL_addlstring dll_luaL_addlstring #define luaL_pushresult dll_luaL_pushresult ! // lua #if LUA_VERSION_NUM <= 501 #define lua_tonumber dll_lua_tonumber #define lua_tointeger dll_lua_tointeger *************** *** 177,183 **** #define lua_rawseti dll_lua_rawseti #define lua_setmetatable dll_lua_setmetatable #define lua_next dll_lua_next ! /* libs */ #define luaopen_base dll_luaopen_base #define luaopen_table dll_luaopen_table #define luaopen_string dll_luaopen_string --- 177,183 ---- #define lua_rawseti dll_lua_rawseti #define lua_setmetatable dll_lua_setmetatable #define lua_next dll_lua_next ! // libs #define luaopen_base dll_luaopen_base #define luaopen_table dll_luaopen_table #define luaopen_string dll_luaopen_string *************** *** 188,194 **** #define luaopen_debug dll_luaopen_debug #define luaL_openlibs dll_luaL_openlibs ! /* lauxlib */ #if LUA_VERSION_NUM <= 501 void (*dll_luaL_register) (lua_State *L, const char *libname, const luaL_Reg *l); char *(*dll_luaL_prepbuffer) (luaL_Buffer *B); --- 188,194 ---- #define luaopen_debug dll_luaopen_debug #define luaL_openlibs dll_luaL_openlibs ! // lauxlib #if LUA_VERSION_NUM <= 501 void (*dll_luaL_register) (lua_State *L, const char *libname, const luaL_Reg *l); char *(*dll_luaL_prepbuffer) (luaL_Buffer *B); *************** *** 213,219 **** void (*dll_luaL_buffinit) (lua_State *L, luaL_Buffer *B); void (*dll_luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); void (*dll_luaL_pushresult) (luaL_Buffer *B); ! /* lua */ #if LUA_VERSION_NUM <= 501 lua_Number (*dll_lua_tonumber) (lua_State *L, int idx); lua_Integer (*dll_lua_tointeger) (lua_State *L, int idx); --- 213,219 ---- void (*dll_luaL_buffinit) (lua_State *L, luaL_Buffer *B); void (*dll_luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); void (*dll_luaL_pushresult) (luaL_Buffer *B); ! // lua #if LUA_VERSION_NUM <= 501 lua_Number (*dll_lua_tonumber) (lua_State *L, int idx); lua_Integer (*dll_lua_tointeger) (lua_State *L, int idx); *************** *** 282,288 **** #endif int (*dll_lua_setmetatable) (lua_State *L, int objindex); int (*dll_lua_next) (lua_State *L, int idx); ! /* libs */ int (*dll_luaopen_base) (lua_State *L); int (*dll_luaopen_table) (lua_State *L); int (*dll_luaopen_string) (lua_State *L); --- 282,288 ---- #endif int (*dll_lua_setmetatable) (lua_State *L, int objindex); int (*dll_lua_next) (lua_State *L, int idx); ! // libs int (*dll_luaopen_base) (lua_State *L); int (*dll_luaopen_table) (lua_State *L); int (*dll_luaopen_string) (lua_State *L); *************** *** 300,306 **** } luaV_Reg; static const luaV_Reg luaV_dll[] = { ! /* lauxlib */ #if LUA_VERSION_NUM <= 501 {"luaL_register", (luaV_function) &dll_luaL_register}, {"luaL_prepbuffer", (luaV_function) &dll_luaL_prepbuffer}, --- 300,306 ---- } luaV_Reg; static const luaV_Reg luaV_dll[] = { ! // lauxlib #if LUA_VERSION_NUM <= 501 {"luaL_register", (luaV_function) &dll_luaL_register}, {"luaL_prepbuffer", (luaV_function) &dll_luaL_prepbuffer}, *************** *** 325,331 **** {"luaL_buffinit", (luaV_function) &dll_luaL_buffinit}, {"luaL_addlstring", (luaV_function) &dll_luaL_addlstring}, {"luaL_pushresult", (luaV_function) &dll_luaL_pushresult}, ! /* lua */ #if LUA_VERSION_NUM <= 501 {"lua_tonumber", (luaV_function) &dll_lua_tonumber}, {"lua_tointeger", (luaV_function) &dll_lua_tointeger}, --- 325,331 ---- {"luaL_buffinit", (luaV_function) &dll_luaL_buffinit}, {"luaL_addlstring", (luaV_function) &dll_luaL_addlstring}, {"luaL_pushresult", (luaV_function) &dll_luaL_pushresult}, ! // lua #if LUA_VERSION_NUM <= 501 {"lua_tonumber", (luaV_function) &dll_lua_tonumber}, {"lua_tointeger", (luaV_function) &dll_lua_tointeger}, *************** *** 383,389 **** {"lua_rawseti", (luaV_function) &dll_lua_rawseti}, {"lua_setmetatable", (luaV_function) &dll_lua_setmetatable}, {"lua_next", (luaV_function) &dll_lua_next}, ! /* libs */ {"luaopen_base", (luaV_function) &dll_luaopen_base}, {"luaopen_table", (luaV_function) &dll_luaopen_table}, {"luaopen_string", (luaV_function) &dll_luaopen_string}, --- 383,389 ---- {"lua_rawseti", (luaV_function) &dll_lua_rawseti}, {"lua_setmetatable", (luaV_function) &dll_lua_setmetatable}, {"lua_next", (luaV_function) &dll_lua_next}, ! // libs {"luaopen_base", (luaV_function) &dll_luaopen_base}, {"luaopen_table", (luaV_function) &dll_luaopen_table}, {"luaopen_string", (luaV_function) &dll_luaopen_string}, *************** *** 433,439 **** } return OK; } ! #endif /* DYNAMIC_LUA */ #if defined(DYNAMIC_LUA) || defined(PROTO) int --- 433,439 ---- } return OK; } ! #endif // DYNAMIC_LUA #if defined(DYNAMIC_LUA) || defined(PROTO) int *************** *** 454,460 **** #endif ! /* ======= Internal ======= */ static void luaV_newmetatable(lua_State *L, const char *tname) --- 454,460 ---- #endif ! // ======= Internal ======= static void luaV_newmetatable(lua_State *L, const char *tname) *************** *** 470,483 **** { void *p = lua_touserdata(L, ud); ! if (p != NULL) /* value is userdata? */ { ! if (lua_getmetatable(L, ud)) /* does it have a metatable? */ { ! luaV_getfield(L, tname); /* get metatable */ ! if (lua_rawequal(L, -1, -2)) /* MTs match? */ { ! lua_pop(L, 2); /* MTs */ return p; } } --- 470,483 ---- { void *p = lua_touserdata(L, ud); ! if (p != NULL) // value is userdata? { ! if (lua_getmetatable(L, ud)) // does it have a metatable? { ! luaV_getfield(L, tname); // get metatable ! if (lua_rawequal(L, -1, -2)) // MTs match? { ! lua_pop(L, 2); // MTs return p; } } *************** *** 643,650 **** return status; } ! /* similar to luaL_addlstring, but replaces \0 with \n if toline and ! * \n with \0 otherwise */ static void luaV_addlstring(luaL_Buffer *b, const char *s, size_t l, int toline) { --- 643,652 ---- return status; } ! /* ! * similar to luaL_addlstring, but replaces \0 with \n if toline and ! * \n with \0 otherwise ! */ static void luaV_addlstring(luaL_Buffer *b, const char *s, size_t l, int toline) { *************** *** 683,690 **** return (char_u *) lua_tostring(L, -1); } ! /* pops a string s from the top of the stack and calls mf(t) for pieces t of ! * s separated by newlines */ static void luaV_msgfunc(lua_State *L, msgfunc_T mf) { --- 685,694 ---- return (char_u *) lua_tostring(L, -1); } ! /* ! * pops a string s from the top of the stack and calls mf(t) for pieces t of ! * s separated by newlines ! */ static void luaV_msgfunc(lua_State *L, msgfunc_T mf) { *************** *** 694,711 **** luaL_buffinit(L, &b); luaV_addlstring(&b, s, l, 0); luaL_pushresult(&b); ! /* break string */ p = s = lua_tolstring(L, -1, &l); while (l--) { ! if (*p++ == '\0') /* break? */ { mf((char_u *) s); s = p; } } mf((char_u *) s); ! lua_pop(L, 2); /* original and modified strings */ } #define luaV_newtype(typ,tname,luatyp,luatname) \ --- 698,715 ---- luaL_buffinit(L, &b); luaV_addlstring(&b, s, l, 0); luaL_pushresult(&b); ! // break string p = s = lua_tolstring(L, -1, &l); while (l--) { ! if (*p++ == '\0') // break? { mf((char_u *) s); s = p; } } mf((char_u *) s); ! lua_pop(L, 2); // original and modified strings } #define luaV_newtype(typ,tname,luatyp,luatname) \ *************** *** 748,762 **** return 1; \ } ! /* ======= List type ======= */ static luaV_List * luaV_newlist(lua_State *L, list_T *lis) { luaV_List *l = (luaV_List *) lua_newuserdata(L, sizeof(luaV_List)); *l = lis; ! lis->lv_refcount++; /* reference in Lua */ ! luaV_setudata(L, lis); /* cache[lis] = udata */ luaV_getfield(L, LUAVIM_LIST); lua_setmetatable(L, -2); return l; --- 752,766 ---- return 1; \ } ! // ======= List type ======= static luaV_List * luaV_newlist(lua_State *L, list_T *lis) { luaV_List *l = (luaV_List *) lua_newuserdata(L, sizeof(luaV_List)); *l = lis; ! lis->lv_refcount++; // reference in Lua ! luaV_setudata(L, lis); // cache[lis] = udata luaV_getfield(L, LUAVIM_LIST); lua_setmetatable(L, -2); return l; *************** *** 788,794 **** luaV_list_call(lua_State *L) { list_T *l = luaV_unbox(L, luaV_List, 1); ! lua_pushvalue(L, lua_upvalueindex(1)); /* pass cache table along */ lua_pushlightuserdata(L, (void *) l->lv_first); lua_pushcclosure(L, luaV_list_iter, 2); return 1; --- 792,798 ---- luaV_list_call(lua_State *L) { list_T *l = luaV_unbox(L, luaV_List, 1); ! lua_pushvalue(L, lua_upvalueindex(1)); // pass cache table along lua_pushlightuserdata(L, (void *) l->lv_first); lua_pushcclosure(L, luaV_list_iter, 2); return 1; *************** *** 798,804 **** luaV_list_index(lua_State *L) { list_T *l = luaV_unbox(L, luaV_List, 1); ! if (lua_isnumber(L, 2)) /* list item? */ { listitem_T *li = list_find(l, (long) luaL_checkinteger(L, 2)); if (li == NULL) --- 802,808 ---- luaV_list_index(lua_State *L) { list_T *l = luaV_unbox(L, luaV_List, 1); ! if (lua_isnumber(L, 2)) // list item? { listitem_T *li = list_find(l, (long) luaL_checkinteger(L, 2)); if (li == NULL) *************** *** 806,812 **** else luaV_pushtypval(L, &li->li_tv); } ! else if (lua_isstring(L, 2)) /* method? */ { const char *s = lua_tostring(L, 2); if (strncmp(s, "add", 3) == 0 --- 810,816 ---- else luaV_pushtypval(L, &li->li_tv); } ! else if (lua_isstring(L, 2)) // method? { const char *s = lua_tostring(L, 2); if (strncmp(s, "add", 3) == 0 *************** *** 833,839 **** luaL_error(L, "list is locked"); li = list_find(l, n); if (li == NULL) return 0; ! if (lua_isnil(L, 3)) /* remove? */ { vimlist_remove(l, li, li); clear_tv(&li->li_tv); --- 837,843 ---- luaL_error(L, "list is locked"); li = list_find(l, n); if (li == NULL) return 0; ! if (lua_isnil(L, 3)) // remove? { vimlist_remove(l, li, li); clear_tv(&li->li_tv); *************** *** 904,918 **** }; ! /* ======= Dict type ======= */ static luaV_Dict * luaV_newdict(lua_State *L, dict_T *dic) { luaV_Dict *d = (luaV_Dict *) lua_newuserdata(L, sizeof(luaV_Dict)); *d = dic; ! dic->dv_refcount++; /* reference in Lua */ ! luaV_setudata(L, dic); /* cache[dic] = udata */ luaV_getfield(L, LUAVIM_DICT); lua_setmetatable(L, -2); return d; --- 908,922 ---- }; ! // ======= Dict type ======= static luaV_Dict * luaV_newdict(lua_State *L, dict_T *dic) { luaV_Dict *d = (luaV_Dict *) lua_newuserdata(L, sizeof(luaV_Dict)); *d = dic; ! dic->dv_refcount++; // reference in Lua ! luaV_setudata(L, dic); // cache[dic] = udata luaV_getfield(L, LUAVIM_DICT); lua_setmetatable(L, -2); return d; *************** *** 956,964 **** { dict_T *d = luaV_unbox(L, luaV_Dict, 1); hashtab_T *ht = &d->dv_hashtab; ! lua_pushvalue(L, lua_upvalueindex(1)); /* pass cache table along */ lua_pushlightuserdata(L, (void *) ht->ht_array); ! lua_pushinteger(L, ht->ht_used); /* # remaining items */ lua_pushcclosure(L, luaV_dict_iter, 3); return 1; } --- 960,968 ---- { dict_T *d = luaV_unbox(L, luaV_Dict, 1); hashtab_T *ht = &d->dv_hashtab; ! lua_pushvalue(L, lua_upvalueindex(1)); // pass cache table along lua_pushlightuserdata(L, (void *) ht->ht_array); ! lua_pushinteger(L, ht->ht_used); // # remaining items lua_pushcclosure(L, luaV_dict_iter, 3); return 1; } *************** *** 975,984 **** else { luaV_pushtypval(L, &di->di_tv); ! if (di->di_tv.v_type == VAR_FUNC) /* funcref? */ { luaV_Funcref *f = (luaV_Funcref *) lua_touserdata(L, -1); ! f->self = d; /* keep "self" reference */ d->dv_refcount++; } } --- 979,988 ---- else { luaV_pushtypval(L, &di->di_tv); ! if (di->di_tv.v_type == VAR_FUNC) // funcref? { luaV_Funcref *f = (luaV_Funcref *) lua_touserdata(L, -1); ! f->self = d; // keep "self" reference d->dv_refcount++; } } *************** *** 999,1012 **** return 0; if (*key == NUL) luaL_error(L, "empty key"); ! if (!lua_isnil(L, 3)) /* read value? */ { luaV_checktypval(L, 3, &v, "setting dict item"); if (d->dv_scope == VAR_DEF_SCOPE && v.v_type == VAR_FUNC) luaL_error(L, "cannot assign funcref to builtin scope"); } di = dict_find(d, key, -1); ! if (di == NULL) /* non-existing key? */ { if (lua_isnil(L, 3)) return 0; --- 1003,1016 ---- return 0; if (*key == NUL) luaL_error(L, "empty key"); ! if (!lua_isnil(L, 3)) // read value? { luaV_checktypval(L, 3, &v, "setting dict item"); if (d->dv_scope == VAR_DEF_SCOPE && v.v_type == VAR_FUNC) luaL_error(L, "cannot assign funcref to builtin scope"); } di = dict_find(d, key, -1); ! if (di == NULL) // non-existing key? { if (lua_isnil(L, 3)) return 0; *************** *** 1021,1027 **** } else clear_tv(&di->di_tv); ! if (lua_isnil(L, 3)) /* remove? */ { hashitem_T *hi = hash_find(&d->dv_hashtab, di->di_key); hash_remove(&d->dv_hashtab, hi); --- 1025,1031 ---- } else clear_tv(&di->di_tv); ! if (lua_isnil(L, 3)) // remove? { hashitem_T *hi = hash_find(&d->dv_hashtab, di->di_key); hash_remove(&d->dv_hashtab, hi); *************** *** 1045,1059 **** }; ! /* ======= Blob type ======= */ static luaV_Blob * luaV_newblob(lua_State *L, blob_T *blo) { luaV_Blob *b = (luaV_Blob *) lua_newuserdata(L, sizeof(luaV_Blob)); *b = blo; ! blo->bv_refcount++; /* reference in Lua */ ! luaV_setudata(L, blo); /* cache[blo] = udata */ luaV_getfield(L, LUAVIM_BLOB); lua_setmetatable(L, -2); return b; --- 1049,1063 ---- }; ! // ======= Blob type ======= static luaV_Blob * luaV_newblob(lua_State *L, blob_T *blo) { luaV_Blob *b = (luaV_Blob *) lua_newuserdata(L, sizeof(luaV_Blob)); *b = blo; ! blo->bv_refcount++; // reference in Lua ! luaV_setudata(L, blo); // cache[blo] = udata luaV_getfield(L, LUAVIM_BLOB); lua_setmetatable(L, -2); return b; *************** *** 1163,1169 **** }; ! /* ======= Funcref type ======= */ static luaV_Funcref * luaV_newfuncref(lua_State *L, char_u *name) --- 1167,1173 ---- }; ! // ======= Funcref type ======= static luaV_Funcref * luaV_newfuncref(lua_State *L, char_u *name) *************** *** 1202,1208 **** return 0; } ! /* equivalent to string(funcref) */ static int luaV_funcref_len(lua_State *L) { --- 1206,1212 ---- return 0; } ! // equivalent to string(funcref) static int luaV_funcref_len(lua_State *L) { *************** *** 1254,1260 **** }; ! /* ======= Buffer type ======= */ luaV_newtype(buf_T, buffer, luaV_Buffer, LUAVIM_BUFFER) luaV_pushtype(buf_T, buffer, luaV_Buffer) --- 1258,1264 ---- }; ! // ======= Buffer type ======= luaV_newtype(buf_T, buffer, luaV_Buffer, LUAVIM_BUFFER) luaV_pushtype(buf_T, buffer, luaV_Buffer) *************** *** 1295,1301 **** ? "" : (char *) b->b_ffname); else if (strncmp(s, "number", 6) == 0) lua_pushinteger(L, b->b_fnum); ! /* methods */ else if (strncmp(s, "insert", 6) == 0 || strncmp(s, "next", 4) == 0 || strncmp(s, "previous", 8) == 0 --- 1299,1305 ---- ? "" : (char *) b->b_ffname); else if (strncmp(s, "number", 6) == 0) lua_pushinteger(L, b->b_fnum); ! // methods else if (strncmp(s, "insert", 6) == 0 || strncmp(s, "next", 4) == 0 || strncmp(s, "previous", 8) == 0 *************** *** 1322,1328 **** #endif if (n < 1 || n > b->b_ml.ml_line_count) luaL_error(L, "invalid line number"); ! if (lua_isnil(L, 3)) /* delete line */ { buf_T *buf = curbuf; curbuf = b; --- 1326,1332 ---- #endif if (n < 1 || n > b->b_ml.ml_line_count) luaL_error(L, "invalid line number"); ! if (lua_isnil(L, 3)) // delete line { buf_T *buf = curbuf; curbuf = b; *************** *** 1339,1345 **** else { deleted_lines_mark(n, 1L); ! if (b == curwin->w_buffer) /* fix cursor in current window? */ { if (curwin->w_cursor.lnum >= n) { --- 1343,1349 ---- else { deleted_lines_mark(n, 1L); ! if (b == curwin->w_buffer) // fix cursor in current window? { if (curwin->w_cursor.lnum >= n) { *************** *** 1356,1362 **** } curbuf = buf; } ! else if (lua_isstring(L, 3)) /* update line */ { buf_T *buf = curbuf; curbuf = b; --- 1360,1366 ---- } curbuf = buf; } ! else if (lua_isstring(L, 3)) // update line { buf_T *buf = curbuf; curbuf = b; *************** *** 1392,1401 **** #ifdef HAVE_SANDBOX luaV_checksandbox(L); #endif ! /* fix insertion line */ if (n < 0) n = 0; if (n > last) n = last; ! /* insert */ buf = curbuf; curbuf = b; if (u_save(n, n + 1) == FAIL) --- 1396,1405 ---- #ifdef HAVE_SANDBOX luaV_checksandbox(L); #endif ! // fix insertion line if (n < 0) n = 0; if (n > last) n = last; ! // insert buf = curbuf; curbuf = b; if (u_save(n, n + 1) == FAIL) *************** *** 1456,1462 **** }; ! /* ======= Window type ======= */ luaV_newtype(win_T, window, luaV_Window, LUAVIM_WINDOW) luaV_pushtype(win_T, window, luaV_Window) --- 1460,1466 ---- }; ! // ======= Window type ======= luaV_newtype(win_T, window, luaV_Window, LUAVIM_WINDOW) luaV_pushtype(win_T, window, luaV_Window) *************** *** 1486,1492 **** lua_pushinteger(L, w->w_width); else if (strncmp(s, "height", 6) == 0) lua_pushinteger(L, w->w_height); ! /* methods */ else if (strncmp(s, "next", 4) == 0 || strncmp(s, "previous", 8) == 0 || strncmp(s, "isvalid", 7) == 0) --- 1490,1496 ---- lua_pushinteger(L, w->w_width); else if (strncmp(s, "height", 6) == 0) lua_pushinteger(L, w->w_height); ! // methods else if (strncmp(s, "next", 4) == 0 || strncmp(s, "previous", 8) == 0 || strncmp(s, "isvalid", 7) == 0) *************** *** 1588,1599 **** }; ! /* ======= Vim module ======= */ static int luaV_print(lua_State *L) { ! int i, n = lua_gettop(L); /* nargs */ const char *s; size_t l; luaL_Buffer b; --- 1592,1603 ---- }; ! // ======= Vim module ======= static int luaV_print(lua_State *L) { ! int i, n = lua_gettop(L); // nargs const char *s; size_t l; luaL_Buffer b; *************** *** 1601,1613 **** lua_getglobal(L, "tostring"); for (i = 1; i <= n; i++) { ! lua_pushvalue(L, -1); /* tostring */ ! lua_pushvalue(L, i); /* arg */ lua_call(L, 1, 1); s = lua_tolstring(L, -1, &l); if (s == NULL) return luaL_error(L, "cannot convert to string"); ! if (i > 1) luaL_addchar(&b, ' '); /* use space instead of tab */ luaV_addlstring(&b, s, l, 0); lua_pop(L, 1); } --- 1605,1617 ---- lua_getglobal(L, "tostring"); for (i = 1; i <= n; i++) { ! lua_pushvalue(L, -1); // tostring ! lua_pushvalue(L, i); // arg lua_call(L, 1, 1); s = lua_tolstring(L, -1, &l); if (s == NULL) return luaL_error(L, "cannot convert to string"); ! if (i > 1) luaL_addchar(&b, ' '); // use space instead of tab luaV_addlstring(&b, s, l, 0); lua_pop(L, 1); } *************** *** 1623,1644 **** lua_settop(L, 0); lua_getglobal(L, "vim"); lua_getfield(L, -1, "eval"); ! lua_remove(L, -2); /* vim.eval at position 1 */ for (;;) { const char *input; size_t l; ! lua_pushvalue(L, 1); /* vim.eval */ lua_pushliteral(L, "input('lua_debug> ')"); ! lua_call(L, 1, 1); /* return string */ input = lua_tolstring(L, -1, &l); if (l == 0 || strcmp(input, "cont") == 0) return 0; ! msg_putchar('\n'); /* avoid outputting on input line */ if (luaL_loadbuffer(L, input, l, "=(debug command)") || lua_pcall(L, 0, 0, 0)) luaV_emsg(L); ! lua_settop(L, 1); /* remove eventual returns, but keep vim.eval */ } } --- 1627,1648 ---- lua_settop(L, 0); lua_getglobal(L, "vim"); lua_getfield(L, -1, "eval"); ! lua_remove(L, -2); // vim.eval at position 1 for (;;) { const char *input; size_t l; ! lua_pushvalue(L, 1); // vim.eval lua_pushliteral(L, "input('lua_debug> ')"); ! lua_call(L, 1, 1); // return string input = lua_tolstring(L, -1, &l); if (l == 0 || strcmp(input, "cont") == 0) return 0; ! msg_putchar('\n'); // avoid outputting on input line if (luaL_loadbuffer(L, input, l, "=(debug command)") || lua_pcall(L, 0, 0, 0)) luaV_emsg(L); ! lua_settop(L, 1); // remove eventual returns, but keep vim.eval } } *************** *** 1688,1694 **** else { luaV_newlist(L, l); ! if (initarg) /* traverse table to init list */ { int notnil, i = 0; typval_T v; --- 1692,1698 ---- else { luaV_newlist(L, l); ! if (initarg) // traverse table to init list { int notnil, i = 0; typval_T v; *************** *** 1702,1708 **** list_append_tv(l, &v); clear_tv(&v); } ! lua_pop(L, 1); /* value */ } while (notnil); } } --- 1706,1712 ---- list_append_tv(l, &v); clear_tv(&v); } ! lua_pop(L, 1); // value } while (notnil); } } *************** *** 1723,1729 **** else { luaV_newdict(L, d); ! if (initarg) /* traverse table to init dict */ { lua_pushnil(L); while (lua_next(L, 1)) --- 1727,1733 ---- else { luaV_newdict(L, d); ! if (initarg) // traverse table to init dict { lua_pushnil(L); while (lua_next(L, 1)) *************** *** 1732,1738 **** dictitem_T *di; typval_T v; ! lua_pushvalue(L, -2); /* dup key in case it's a number */ key = (char_u *) lua_tostring(L, -1); if (key == NULL) { --- 1736,1742 ---- dictitem_T *di; typval_T v; ! lua_pushvalue(L, -2); // dup key in case it's a number key = (char_u *) lua_tostring(L, -1); if (key == NULL) { *************** *** 1741,1747 **** } if (*key == NUL) luaL_error(L, "table has empty key"); ! luaV_checktypval(L, -2, &v, "vim.dict"); /* value */ di = dictitem_alloc(key); if (di == NULL || dict_add(d, di) == FAIL) { --- 1745,1751 ---- } if (*key == NUL) luaL_error(L, "table has empty key"); ! luaV_checktypval(L, -2, &v, "vim.dict"); // value di = dictitem_alloc(key); if (di == NULL || dict_add(d, di) == FAIL) { *************** *** 1751,1757 **** } copy_tv(&v, &di->di_tv); clear_tv(&v); ! lua_pop(L, 2); /* key copy and value */ } } } --- 1755,1761 ---- } copy_tv(&v, &di->di_tv); clear_tv(&v); ! lua_pop(L, 2); // key copy and value } } } *************** *** 1789,1795 **** luaV_funcref(lua_State *L) { const char *name = luaL_checkstring(L, 1); ! /* note: not checking if function exists (needs function_exists) */ if (name == NULL || *name == NUL || VIM_ISDIGIT(*name)) luaL_error(L, "invalid function name: %s", name); luaV_newfuncref(L, (char_u *) name); --- 1793,1799 ---- luaV_funcref(lua_State *L) { const char *name = luaL_checkstring(L, 1); ! // note: not checking if function exists (needs function_exists) if (name == NULL || *name == NUL || VIM_ISDIGIT(*name)) luaL_error(L, "invalid function name: %s", name); luaV_newfuncref(L, (char_u *) name); *************** *** 1800,1808 **** luaV_buffer(lua_State *L) { buf_T *buf; ! if (lua_isstring(L, 1)) /* get by number or name? */ { ! if (lua_isnumber(L, 1)) /* by number? */ { int n = lua_tointeger(L, 1); FOR_ALL_BUFFERS(buf) --- 1804,1812 ---- luaV_buffer(lua_State *L) { buf_T *buf; ! if (lua_isstring(L, 1)) // get by number or name? { ! if (lua_isnumber(L, 1)) // by number? { int n = lua_tointeger(L, 1); FOR_ALL_BUFFERS(buf) *************** *** 1825,1831 **** } } else ! buf = (lua_toboolean(L, 1)) ? firstbuf : curbuf; /* first buffer? */ luaV_pushbuffer(L, buf); return 1; } --- 1829,1835 ---- } } else ! buf = (lua_toboolean(L, 1)) ? firstbuf : curbuf; // first buffer? luaV_pushbuffer(L, buf); return 1; } *************** *** 1834,1847 **** luaV_window(lua_State *L) { win_T *win; ! if (lua_isnumber(L, 1)) /* get by number? */ { int n = lua_tointeger(L, 1); for (win = firstwin; win != NULL; win = win->w_next, n--) if (n == 1) break; } else ! win = (lua_toboolean(L, 1)) ? firstwin : curwin; /* first window? */ luaV_pushwindow(L, win); return 1; } --- 1838,1851 ---- luaV_window(lua_State *L) { win_T *win; ! if (lua_isnumber(L, 1)) // get by number? { int n = lua_tointeger(L, 1); for (win = firstwin; win != NULL; win = win->w_next, n--) if (n == 1) break; } else ! win = (lua_toboolean(L, 1)) ? firstwin : curwin; // first window? luaV_pushwindow(L, win); return 1; } *************** *** 1862,1868 **** luaV_type(lua_State *L) { luaL_checkany(L, 1); ! if (lua_type(L, 1) == LUA_TUSERDATA) /* check vim udata? */ { lua_settop(L, 1); if (lua_getmetatable(L, 1)) --- 1866,1872 ---- luaV_type(lua_State *L) { luaL_checkany(L, 1); ! if (lua_type(L, 1) == LUA_TUSERDATA) // check vim udata? { lua_settop(L, 1); if (lua_getmetatable(L, 1)) *************** *** 1905,1911 **** } } } ! lua_pushstring(L, luaL_typename(L, 1)); /* fallback */ return 1; } --- 1909,1915 ---- } } } ! lua_pushstring(L, luaL_typename(L, 1)); // fallback return 1; } *************** *** 1925,1931 **** {NULL, NULL} }; ! /* for freeing list, dict, buffer and window objects; lightuserdata as arg */ static int luaV_free(lua_State *L) { --- 1929,1937 ---- {NULL, NULL} }; ! /* ! * for freeing list, dict, buffer and window objects; lightuserdata as arg ! */ static int luaV_free(lua_State *L) { *************** *** 1947,1959 **** luaL_addlstring(&b, str, l); luaL_pushresult(&b); str = lua_tolstring(L, -1, &l); ! if (luaL_loadbuffer(L, str, l, LUAVIM_EVALNAME)) /* compile error? */ { luaV_emsg(L); return 0; } luaV_pushtypval(L, arg); ! if (lua_pcall(L, 1, 1, 0)) /* running error? */ { luaV_emsg(L); return 0; --- 1953,1965 ---- luaL_addlstring(&b, str, l); luaL_pushresult(&b); str = lua_tolstring(L, -1, &l); ! if (luaL_loadbuffer(L, str, l, LUAVIM_EVALNAME)) // compile error? { luaV_emsg(L); return 0; } luaV_pushtypval(L, arg); ! if (lua_pcall(L, 1, 1, 0)) // running error? { luaV_emsg(L); return 0; *************** *** 2004,2039 **** static int luaopen_vim(lua_State *L) { ! /* set cache table */ lua_newtable(L); lua_newtable(L); lua_pushstring(L, "v"); lua_setfield(L, -2, "__mode"); ! lua_setmetatable(L, -2); /* cache is weak-valued */ ! /* print */ lua_pushcfunction(L, luaV_print); lua_setglobal(L, "print"); ! /* debug.debug */ lua_getglobal(L, "debug"); lua_pushcfunction(L, luaV_debug); lua_setfield(L, -2, "debug"); lua_pop(L, 1); ! /* free */ lua_pushlightuserdata(L, (void *) LUAVIM_FREE); ! lua_pushvalue(L, 1); /* cache table */ lua_pushcclosure(L, luaV_free, 1); lua_rawset(L, LUA_REGISTRYINDEX); ! /* luaeval */ lua_pushlightuserdata(L, (void *) LUAVIM_LUAEVAL); ! lua_pushvalue(L, 1); /* cache table */ lua_pushcclosure(L, luaV_luaeval, 1); lua_rawset(L, LUA_REGISTRYINDEX); ! /* setref */ lua_pushlightuserdata(L, (void *) LUAVIM_SETREF); ! lua_pushvalue(L, 1); /* cache table */ lua_pushcclosure(L, luaV_setref, 1); lua_rawset(L, LUA_REGISTRYINDEX); ! /* register */ luaV_newmetatable(L, LUAVIM_LIST); lua_pushvalue(L, 1); luaV_openlib(L, luaV_List_mt, 1); --- 2010,2045 ---- static int luaopen_vim(lua_State *L) { ! // set cache table lua_newtable(L); lua_newtable(L); lua_pushstring(L, "v"); lua_setfield(L, -2, "__mode"); ! lua_setmetatable(L, -2); // cache is weak-valued ! // print lua_pushcfunction(L, luaV_print); lua_setglobal(L, "print"); ! // debug.debug lua_getglobal(L, "debug"); lua_pushcfunction(L, luaV_debug); lua_setfield(L, -2, "debug"); lua_pop(L, 1); ! // free lua_pushlightuserdata(L, (void *) LUAVIM_FREE); ! lua_pushvalue(L, 1); // cache table lua_pushcclosure(L, luaV_free, 1); lua_rawset(L, LUA_REGISTRYINDEX); ! // luaeval lua_pushlightuserdata(L, (void *) LUAVIM_LUAEVAL); ! lua_pushvalue(L, 1); // cache table lua_pushcclosure(L, luaV_luaeval, 1); lua_rawset(L, LUA_REGISTRYINDEX); ! // setref lua_pushlightuserdata(L, (void *) LUAVIM_SETREF); ! lua_pushvalue(L, 1); // cache table lua_pushcclosure(L, luaV_setref, 1); lua_rawset(L, LUA_REGISTRYINDEX); ! // register luaV_newmetatable(L, LUAVIM_LIST); lua_pushvalue(L, 1); luaV_openlib(L, luaV_List_mt, 1); *************** *** 2047,2059 **** lua_pushvalue(L, 1); luaV_openlib(L, luaV_Funcref_mt, 1); luaV_newmetatable(L, LUAVIM_BUFFER); ! lua_pushvalue(L, 1); /* cache table */ luaV_openlib(L, luaV_Buffer_mt, 1); luaV_newmetatable(L, LUAVIM_WINDOW); ! lua_pushvalue(L, 1); /* cache table */ luaV_openlib(L, luaV_Window_mt, 1); ! lua_newtable(L); /* vim table */ ! lua_pushvalue(L, 1); /* cache table */ luaV_openlib(L, luaV_module, 1); lua_setglobal(L, LUAVIM_NAME); return 0; --- 2053,2065 ---- lua_pushvalue(L, 1); luaV_openlib(L, luaV_Funcref_mt, 1); luaV_newmetatable(L, LUAVIM_BUFFER); ! lua_pushvalue(L, 1); // cache table luaV_openlib(L, luaV_Buffer_mt, 1); luaV_newmetatable(L, LUAVIM_WINDOW); ! lua_pushvalue(L, 1); // cache table luaV_openlib(L, luaV_Window_mt, 1); ! lua_newtable(L); // vim table ! lua_pushvalue(L, 1); // cache table luaV_openlib(L, luaV_module, 1); lua_setglobal(L, LUAVIM_NAME); return 0; *************** *** 2063,2070 **** luaV_newstate(void) { lua_State *L = luaL_newstate(); ! luaL_openlibs(L); /* core libs */ ! lua_pushcfunction(L, luaopen_vim); /* vim */ lua_call(L, 0, 0); return L; } --- 2069,2076 ---- luaV_newstate(void) { lua_State *L = luaL_newstate(); ! luaL_openlibs(L); // core libs ! lua_pushcfunction(L, luaopen_vim); // vim lua_call(L, 0, 0); return L; } *************** *** 2077,2087 **** lua_setfield(L, -2, "firstline"); lua_pushinteger(L, line2); lua_setfield(L, -2, "lastline"); ! lua_pop(L, 1); /* vim table */ } ! /* ======= Interface ======= */ static lua_State *L = NULL; --- 2083,2093 ---- lua_setfield(L, -2, "firstline"); lua_pushinteger(L, line2); lua_setfield(L, -2, "lastline"); ! lua_pop(L, 1); // vim table } ! // ======= Interface ======= static lua_State *L = NULL; *************** *** 2121,2127 **** } } ! /* ex commands */ void ex_lua(exarg_T *eap) { --- 2127,2135 ---- } } ! /* ! * ex commands ! */ void ex_lua(exarg_T *eap) { *************** *** 2156,2203 **** } luaV_setrange(L, eap->line1, eap->line2); luaL_buffinit(L, &b); ! luaL_addlstring(&b, "return function(line, linenr) ", 30); /* header */ luaL_addlstring(&b, s, strlen(s)); ! luaL_addlstring(&b, " end", 4); /* footer */ luaL_pushresult(&b); s = lua_tolstring(L, -1, &len); if (luaL_loadbuffer(L, s, len, LUAVIM_CHUNKNAME)) { luaV_emsg(L); ! lua_pop(L, 1); /* function body */ return; } lua_call(L, 0, 1); ! lua_replace(L, -2); /* function -> body */ for (l = eap->line1; l <= eap->line2; l++) { ! /* Check the line number, the command my have deleted lines. */ if (l > curbuf->b_ml.ml_line_count) break; ! lua_pushvalue(L, -1); /* function */ ! luaV_pushline(L, curbuf, l); /* current line as arg */ ! lua_pushinteger(L, l); /* current line number as arg */ if (lua_pcall(L, 2, 1, 0)) { luaV_emsg(L); break; } ! /* Catch the command switching to another buffer. */ if (curbuf != was_curbuf) break; ! if (lua_isstring(L, -1)) /* update line? */ { #ifdef HAVE_SANDBOX luaV_checksandbox(L); #endif ml_replace(l, luaV_toline(L, -1), TRUE); changed_bytes(l, 0); ! lua_pop(L, 1); /* result from luaV_toline */ } ! lua_pop(L, 1); /* line */ } ! lua_pop(L, 1); /* function */ check_cursor(); update_screen(NOT_VALID); } --- 2164,2211 ---- } luaV_setrange(L, eap->line1, eap->line2); luaL_buffinit(L, &b); ! luaL_addlstring(&b, "return function(line, linenr) ", 30); // header luaL_addlstring(&b, s, strlen(s)); ! luaL_addlstring(&b, " end", 4); // footer luaL_pushresult(&b); s = lua_tolstring(L, -1, &len); if (luaL_loadbuffer(L, s, len, LUAVIM_CHUNKNAME)) { luaV_emsg(L); ! lua_pop(L, 1); // function body return; } lua_call(L, 0, 1); ! lua_replace(L, -2); // function -> body for (l = eap->line1; l <= eap->line2; l++) { ! // Check the line number, the command my have deleted lines. if (l > curbuf->b_ml.ml_line_count) break; ! lua_pushvalue(L, -1); // function ! luaV_pushline(L, curbuf, l); // current line as arg ! lua_pushinteger(L, l); // current line number as arg if (lua_pcall(L, 2, 1, 0)) { luaV_emsg(L); break; } ! // Catch the command switching to another buffer. if (curbuf != was_curbuf) break; ! if (lua_isstring(L, -1)) // update line? { #ifdef HAVE_SANDBOX luaV_checksandbox(L); #endif ml_replace(l, luaV_toline(L, -1), TRUE); changed_bytes(l, 0); ! lua_pop(L, 1); // result from luaV_toline } ! lua_pop(L, 1); // line } ! lua_pop(L, 1); // function check_cursor(); update_screen(NOT_VALID); } *************** *** 2247,2258 **** if (lua_isopen()) { luaV_getfield(L, LUAVIM_SETREF); ! /* call the function with 1 arg, getting 1 result back */ lua_pushinteger(L, copyID); lua_call(L, 1, 1); ! /* get the result */ aborted = lua_tointeger(L, -1); ! /* pop result off the stack */ lua_pop(L, 1); } return aborted; --- 2255,2266 ---- if (lua_isopen()) { luaV_getfield(L, LUAVIM_SETREF); ! // call the function with 1 arg, getting 1 result back lua_pushinteger(L, copyID); lua_call(L, 1, 1); ! // get the result aborted = lua_tointeger(L, -1); ! // pop result off the stack lua_pop(L, 1); } return aborted; *** ../vim-8.1.2386/src/if_mzsch.c 2019-05-28 23:08:12.064648717 +0200 --- src/if_mzsch.c 2019-12-04 21:15:14.859635646 +0100 *************** *** 25,32 **** #include "if_mzsch.h" ! /* Only do the following when the feature is enabled. Needed for "make ! * depend". */ #if defined(FEAT_MZSCHEME) || defined(PROTO) #ifdef PROTO --- 25,32 ---- #include "if_mzsch.h" ! // Only do the following when the feature is enabled. Needed for "make ! // depend". #if defined(FEAT_MZSCHEME) || defined(PROTO) #ifdef PROTO *************** *** 63,69 **** # define TRAMPOLINED_MZVIM_STARTUP #endif ! /* Base data structures */ #define SCHEME_VIMBUFFERP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_buffer_type) #define SCHEME_VIMWINDOWP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_window_type) --- 63,69 ---- # define TRAMPOLINED_MZVIM_STARTUP #endif ! // Base data structures #define SCHEME_VIMBUFFERP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_buffer_type) #define SCHEME_VIMWINDOWP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_window_type) *************** *** 90,96 **** { Scheme_Closed_Prim *prim; char *name; ! int mina; /* arity information */ int maxa; } Vim_Prim; --- 90,96 ---- { Scheme_Closed_Prim *prim; char *name; ! int mina; // arity information int maxa; } Vim_Prim; *************** *** 115,126 **** static Scheme_Object *sandbox_network_guard(int, Scheme_Object **); static void sandbox_check(void); #endif ! /* Buffer-related commands */ static Scheme_Object *buffer_new(buf_T *buf); static Scheme_Object *get_buffer_by_num(void *, int, Scheme_Object **); static vim_mz_buffer *get_vim_curr_buffer(void); ! /* Window-related commands */ static Scheme_Object *window_new(win_T *win); static vim_mz_window *get_vim_curr_window(void); --- 115,126 ---- static Scheme_Object *sandbox_network_guard(int, Scheme_Object **); static void sandbox_check(void); #endif ! // Buffer-related commands static Scheme_Object *buffer_new(buf_T *buf); static Scheme_Object *get_buffer_by_num(void *, int, Scheme_Object **); static vim_mz_buffer *get_vim_curr_buffer(void); ! // Window-related commands static Scheme_Object *window_new(win_T *win); static vim_mz_window *get_vim_curr_window(void); *************** *** 182,194 **** } static int buffer_fixup_proc(void *obj) { ! /* apparently not needed as the object will be uncollectable while ! * the buffer is alive ! */ ! /* ! vim_mz_buffer* buf = (vim_mz_buffer*) obj; ! buf->buf->b_mzscheme_ref = GC_fixup_self(obj); ! */ return buffer_size_proc(obj); } static int window_size_proc(void *obj UNUSED) --- 182,192 ---- } static int buffer_fixup_proc(void *obj) { ! // apparently not needed as the object will be uncollectable while ! // the buffer is alive ! // vim_mz_buffer* buf = (vim_mz_buffer*) obj; ! // buf->buf->b_mzscheme_ref = GC_fixup_self(obj); ! return buffer_size_proc(obj); } static int window_size_proc(void *obj UNUSED) *************** *** 201,218 **** } static int window_fixup_proc(void *obj) { ! /* apparently not needed as the object will be uncollectable while ! * the window is alive ! */ ! /* ! vim_mz_window* win = (vim_mz_window*) obj; ! win->win->w_mzscheme_ref = GC_fixup_self(obj); ! */ return window_size_proc(obj); } ! /* with precise GC, w_mzscheme_ref and b_mzscheme_ref are immobile boxes ! * containing pointers to a window/buffer ! * with conservative GC these are simply pointers*/ # define WINDOW_REF(win) *(vim_mz_window **)((win)->w_mzscheme_ref) # define BUFFER_REF(buf) *(vim_mz_buffer **)((buf)->b_mzscheme_ref) #else --- 199,214 ---- } static int window_fixup_proc(void *obj) { ! // apparently not needed as the object will be uncollectable while ! // the window is alive ! // vim_mz_window* win = (vim_mz_window*) obj; ! // win->win->w_mzscheme_ref = GC_fixup_self(obj); ! // return window_size_proc(obj); } ! // with precise GC, w_mzscheme_ref and b_mzscheme_ref are immobile boxes ! // containing pointers to a window/buffer ! // with conservative GC these are simply pointers # define WINDOW_REF(win) *(vim_mz_window **)((win)->w_mzscheme_ref) # define BUFFER_REF(buf) *(vim_mz_buffer **)((buf)->b_mzscheme_ref) #else *************** *** 378,393 **** static void (*dll_scheme_set_config_path)(Scheme_Object *p); # endif ! #if defined(DYNAMIC_MZSCHEME) /* not when defined(PROTO) */ ! /* arrays are imported directly */ # define scheme_eof dll_scheme_eof # define scheme_false dll_scheme_false # define scheme_void dll_scheme_void # define scheme_null dll_scheme_null # define scheme_true dll_scheme_true ! /* pointers are GetProceAddress'ed as pointers to pointer */ #if !defined(USE_THREAD_LOCAL) && !defined(LINK_EXTENSIONS_BY_TABLE) # define scheme_current_thread (*dll_scheme_current_thread_ptr) # endif --- 374,389 ---- static void (*dll_scheme_set_config_path)(Scheme_Object *p); # endif ! #if defined(DYNAMIC_MZSCHEME) // not when defined(PROTO) ! // arrays are imported directly # define scheme_eof dll_scheme_eof # define scheme_false dll_scheme_false # define scheme_void dll_scheme_void # define scheme_null dll_scheme_null # define scheme_true dll_scheme_true ! // pointers are GetProceAddress'ed as pointers to pointer #if !defined(USE_THREAD_LOCAL) && !defined(LINK_EXTENSIONS_BY_TABLE) # define scheme_current_thread (*dll_scheme_current_thread_ptr) # endif *************** *** 395,401 **** # define scheme_console_output (*dll_scheme_console_output_ptr) # define scheme_notify_multithread (*dll_scheme_notify_multithread_ptr) ! /* and functions in a usual way */ # define GC_malloc dll_GC_malloc # define GC_malloc_atomic dll_GC_malloc_atomic --- 391,397 ---- # define scheme_console_output (*dll_scheme_console_output_ptr) # define scheme_notify_multithread (*dll_scheme_notify_multithread_ptr) ! // and functions in a usual way # define GC_malloc dll_GC_malloc # define GC_malloc_atomic dll_GC_malloc_atomic *************** *** 504,510 **** # if MZSCHEME_VERSION_MAJOR >= 500 # if defined(IMPLEMENT_THREAD_LOCAL_VIA_WIN_TLS) || defined(IMPLEMENT_THREAD_LOCAL_EXTERNALLY_VIA_PROC) ! /* define as function for macro in schthread.h */ Thread_Local_Variables * scheme_external_get_thread_local_variables(void) { --- 500,506 ---- # if MZSCHEME_VERSION_MAJOR >= 500 # if defined(IMPLEMENT_THREAD_LOCAL_VIA_WIN_TLS) || defined(IMPLEMENT_THREAD_LOCAL_EXTERNALLY_VIA_PROC) ! // define as function for macro in schthread.h Thread_Local_Variables * scheme_external_get_thread_local_variables(void) { *************** *** 735,741 **** hMzGC = 0; } } ! #endif /* DYNAMIC_MZSCHEME */ #if MZSCHEME_VERSION_MAJOR < 299 # define GUARANTEED_STRING_ARG(proc, num) GUARANTEE_STRING(proc, num) --- 731,737 ---- hMzGC = 0; } } ! #endif // DYNAMIC_MZSCHEME #if MZSCHEME_VERSION_MAJOR < 299 # define GUARANTEED_STRING_ARG(proc, num) GUARANTEE_STRING(proc, num) *************** *** 760,772 **** } else scheme_wrong_type(proc, "string", num, argc, argv); ! /* unreachable */ return scheme_void; } # define GUARANTEED_STRING_ARG(proc, num) guaranteed_byte_string_arg(proc, num, argc, argv) #endif ! /* need to put it here for dynamic stuff to work */ #if defined(INCLUDE_MZSCHEME_BASE) # include "mzscheme_base.c" #endif --- 756,768 ---- } else scheme_wrong_type(proc, "string", num, argc, argv); ! // unreachable return scheme_void; } # define GUARANTEED_STRING_ARG(proc, num) guaranteed_byte_string_arg(proc, num, argc, argv) #endif ! // need to put it here for dynamic stuff to work #if defined(INCLUDE_MZSCHEME_BASE) # include "mzscheme_base.c" #endif *************** *** 786,801 **** #endif static int load_base_module_failed = FALSE; ! /* global environment */ static Scheme_Env *environment = NULL; ! /* output/error handlers */ static Scheme_Object *curout = NULL; static Scheme_Object *curerr = NULL; ! /* exn:vim exception */ static Scheme_Object *exn_catching_apply = NULL; static Scheme_Object *exn_p = NULL; static Scheme_Object *exn_message = NULL; ! static Scheme_Object *vim_exn = NULL; /* Vim Error exception */ #if !defined(MZ_PRECISE_GC) || MZSCHEME_VERSION_MAJOR < 400 static void *stack_base = NULL; --- 782,797 ---- #endif static int load_base_module_failed = FALSE; ! // global environment static Scheme_Env *environment = NULL; ! // output/error handlers static Scheme_Object *curout = NULL; static Scheme_Object *curerr = NULL; ! // exn:vim exception static Scheme_Object *exn_catching_apply = NULL; static Scheme_Object *exn_p = NULL; static Scheme_Object *exn_message = NULL; ! static Scheme_Object *vim_exn = NULL; // Vim Error exception #if !defined(MZ_PRECISE_GC) || MZSCHEME_VERSION_MAJOR < 400 static void *stack_base = NULL; *************** *** 804,810 **** static long range_start; static long range_end; ! /* MzScheme threads scheduling stuff */ static int mz_threads_allow = 0; #if defined(FEAT_GUI_MSWIN) --- 800,806 ---- static long range_start; static long range_end; ! // MzScheme threads scheduling stuff static int mz_threads_allow = 0; #if defined(FEAT_GUI_MSWIN) *************** *** 822,832 **** static EventLoopTimerUPP timerUPP; #endif ! #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) /* Win32 console and Unix */ void mzvim_check_threads(void) { ! /* Last time MzScheme threads were scheduled */ static time_t mz_last_time = 0; if (mz_threads_allow && p_mzq > 0) --- 818,828 ---- static EventLoopTimerUPP timerUPP; #endif ! #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) // Win32 console and Unix void mzvim_check_threads(void) { ! // Last time MzScheme threads were scheduled static time_t mz_last_time = 0; if (mz_threads_allow && p_mzq > 0) *************** *** 846,852 **** static void setup_timer(void); static void remove_timer(void); ! /* timers are presented in GUI only */ # if defined(FEAT_GUI_MSWIN) static void CALLBACK timer_proc(HWND hwnd UNUSED, UINT uMsg UNUSED, UINT_PTR idEvent UNUSED, DWORD dwTime UNUSED) --- 842,848 ---- static void setup_timer(void); static void remove_timer(void); ! // timers are presented in GUI only # if defined(FEAT_GUI_MSWIN) static void CALLBACK timer_proc(HWND hwnd UNUSED, UINT uMsg UNUSED, UINT_PTR idEvent UNUSED, DWORD dwTime UNUSED) *************** *** 863,871 **** { scheme_check_threads(); # if defined(FEAT_GUI_GTK) ! return TRUE; /* continue receiving notifications */ # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA) ! /* renew timeout */ if (mz_threads_allow && p_mzq > 0) timer_id = XtAppAddTimeOut(app_context, p_mzq, timer_proc, NULL); --- 859,867 ---- { scheme_check_threads(); # if defined(FEAT_GUI_GTK) ! return TRUE; // continue receiving notifications # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA) ! // renew timeout if (mz_threads_allow && p_mzq > 0) timer_id = XtAppAddTimeOut(app_context, p_mzq, timer_proc, NULL); *************** *** 913,919 **** setup_timer(); } ! #endif /* MZSCHEME_GUI_THREADS */ static void notify_multithread(int on) --- 909,915 ---- setup_timer(); } ! #endif // MZSCHEME_GUI_THREADS static void notify_multithread(int on) *************** *** 930,936 **** void mzscheme_end(void) { ! /* We can not unload the DLL. Racket's thread might be still alive. */ #if 0 #ifdef DYNAMIC_MZSCHEME dynamic_mzscheme_end(); --- 926,932 ---- void mzscheme_end(void) { ! // We can not unload the DLL. Racket's thread might be still alive. #if 0 #ifdef DYNAMIC_MZSCHEME dynamic_mzscheme_end(); *************** *** 987,993 **** mzscheme_env_main(Scheme_Env *env, int argc UNUSED, char **argv UNUSED) { #ifdef TRAMPOLINED_MZVIM_STARTUP ! /* Scheme has created the environment for us */ environment = env; #else # ifdef MZ_PRECISE_GC --- 983,989 ---- mzscheme_env_main(Scheme_Env *env, int argc UNUSED, char **argv UNUSED) { #ifdef TRAMPOLINED_MZVIM_STARTUP ! // Scheme has created the environment for us environment = env; #else # ifdef MZ_PRECISE_GC *************** *** 1003,1009 **** #endif vim_main2(); ! /* not reached, vim_main2() will loop until exit() */ return 0; } --- 999,1005 ---- #endif vim_main2(); ! // not reached, vim_main2() will loop until exit() return 0; } *************** *** 1030,1036 **** #endif #ifndef TRAMPOLINED_MZVIM_STARTUP ! /* in newer versions of precise GC the initial env has been created */ environment = scheme_basic_env(); #endif --- 1026,1032 ---- #endif #ifndef TRAMPOLINED_MZVIM_STARTUP ! // in newer versions of precise GC the initial env has been created environment = scheme_basic_env(); #endif *************** *** 1045,1055 **** MZ_GC_CHECK(); #ifdef INCLUDE_MZSCHEME_BASE ! /* invoke function from generated and included mzscheme_base.c */ declare_modules(environment); #endif ! /* setup 'current-library-collection-paths' parameter */ # if MZSCHEME_VERSION_MAJOR >= 299 { Scheme_Object *coll_path = NULL; --- 1041,1051 ---- MZ_GC_CHECK(); #ifdef INCLUDE_MZSCHEME_BASE ! // invoke function from generated and included mzscheme_base.c declare_modules(environment); #endif ! // setup 'current-library-collection-paths' parameter # if MZSCHEME_VERSION_MAJOR >= 299 { Scheme_Object *coll_path = NULL; *************** *** 1059,1065 **** MZ_GC_DECL_REG(1); MZ_GC_VAR_IN_REG(0, coll_path); MZ_GC_REG(); ! /* workaround for dynamic loading on windows */ s = vim_getenv((char_u *)"PLTCOLLECTS", &mustfree); if (s != NULL) { --- 1055,1061 ---- MZ_GC_DECL_REG(1); MZ_GC_VAR_IN_REG(0, coll_path); MZ_GC_REG(); ! // workaround for dynamic loading on windows s = vim_getenv((char_u *)"PLTCOLLECTS", &mustfree); if (s != NULL) { *************** *** 1116,1122 **** MZ_GC_DECL_REG(1); MZ_GC_VAR_IN_REG(0, config_path); MZ_GC_REG(); ! /* workaround for dynamic loading on windows */ s = vim_getenv((char_u *)"PLTCONFIGDIR", &mustfree); if (s != NULL) { --- 1112,1118 ---- MZ_GC_DECL_REG(1); MZ_GC_VAR_IN_REG(0, config_path); MZ_GC_REG(); ! // workaround for dynamic loading on windows s = vim_getenv((char_u *)"PLTCONFIGDIR", &mustfree); if (s != NULL) { *************** *** 1150,1156 **** * we need to add them explicitly */ { ! /* use error handler to avoid abort */ scheme_dynamic_wind(NULL, load_base_module, NULL, load_base_module_on_error, "racket/base"); if (load_base_module_failed) --- 1146,1152 ---- * we need to add them explicitly */ { ! // use error handler to avoid abort scheme_dynamic_wind(NULL, load_base_module, NULL, load_base_module_on_error, "racket/base"); if (load_base_module_failed) *************** *** 1164,1173 **** } register_vim_exn(); ! /* use new environment to initialise exception handling */ init_exn_catching_apply(); ! /* redirect output */ scheme_console_output = do_output; scheme_console_printf = do_printf; --- 1160,1169 ---- } register_vim_exn(); ! // use new environment to initialise exception handling init_exn_catching_apply(); ! // redirect output scheme_console_output = do_output; scheme_console_printf = do_printf; *************** *** 1195,1201 **** MZ_GC_CHECK(); #endif ! /* setup sandbox guards */ if (make_security_guard != NULL) { Scheme_Object *args[3] = {NULL, NULL, NULL}; --- 1191,1197 ---- MZ_GC_CHECK(); #endif ! // setup sandbox guards if (make_security_guard != NULL) { Scheme_Object *args[3] = {NULL, NULL, NULL}; *************** *** 1223,1229 **** MZ_GC_UNREG(); } #endif ! /* Create buffer and window types for use in Scheme code */ mz_buffer_type = scheme_make_type(""); MZ_GC_CHECK(); mz_window_type = scheme_make_type(""); --- 1219,1225 ---- MZ_GC_UNREG(); } #endif ! // Create buffer and window types for use in Scheme code mz_buffer_type = scheme_make_type(""); MZ_GC_CHECK(); mz_window_type = scheme_make_type(""); *************** *** 1278,1284 **** MZ_GC_REG(); config = scheme_current_config(); MZ_GC_CHECK(); ! /* recreate ports each call effectively clearing these ones */ curout = scheme_make_byte_string_output_port(); MZ_GC_CHECK(); curerr = scheme_make_byte_string_output_port(); --- 1274,1280 ---- MZ_GC_REG(); config = scheme_current_config(); MZ_GC_CHECK(); ! // recreate ports each call effectively clearing these ones curout = scheme_make_byte_string_output_port(); MZ_GC_CHECK(); curerr = scheme_make_byte_string_output_port(); *************** *** 1323,1346 **** if (!value) { value = extract_exn_message(exn); ! /* Got an exn? */ if (value) { ! scheme_display(value, curerr); /* Send to stderr-vim */ MZ_GC_CHECK(); do_flush(); } MZ_GC_UNREG(); ! /* `raise' was called on some arbitrary value */ return FAIL; } ! if (ret != NULL) /* if pointer to retval supported give it up */ *ret = value; ! /* Print any result, as long as it's not a void */ else if (!SCHEME_VOIDP(value)) { ! scheme_display(value, curout); /* Send to stdout-vim */ MZ_GC_CHECK(); } --- 1319,1342 ---- if (!value) { value = extract_exn_message(exn); ! // Got an exn? if (value) { ! scheme_display(value, curerr); // Send to stderr-vim MZ_GC_CHECK(); do_flush(); } MZ_GC_UNREG(); ! // `raise' was called on some arbitrary value return FAIL; } ! if (ret != NULL) // if pointer to retval supported give it up *ret = value; ! // Print any result, as long as it's not a void else if (!SCHEME_VOIDP(value)) { ! scheme_display(value, curout); // Send to stdout-vim MZ_GC_CHECK(); } *************** *** 1349,1355 **** return OK; } ! /* :mzscheme */ static int do_mzscheme_command(exarg_T *eap, void *data, Scheme_Closed_Prim *what) { --- 1345,1353 ---- return OK; } ! /* ! * :mzscheme ! */ static int do_mzscheme_command(exarg_T *eap, void *data, Scheme_Closed_Prim *what) { *************** *** 1451,1471 **** file = (char *)scheme_malloc_fail_ok(scheme_malloc_atomic, MAXPATHL + 1); MZ_GC_CHECK(); ! /* make Vim expansion */ expand_env((char_u *)pinfo->name, (char_u *)file, MAXPATHL); pinfo->port = scheme_open_input_file(file, "mzfile"); MZ_GC_CHECK(); ! scheme_count_lines(pinfo->port); /* to get accurate read error location*/ MZ_GC_CHECK(); ! /* Like REPL but print only last result */ while (!SCHEME_EOFP(expr = scheme_read(pinfo->port))) { result = scheme_eval(expr, environment); MZ_GC_CHECK(); } ! /* errors will be caught in do_mzscheme_command and ex_mzfile */ scheme_close_input_port(pinfo->port); MZ_GC_CHECK(); pinfo->port = NULL; --- 1449,1469 ---- file = (char *)scheme_malloc_fail_ok(scheme_malloc_atomic, MAXPATHL + 1); MZ_GC_CHECK(); ! // make Vim expansion expand_env((char_u *)pinfo->name, (char_u *)file, MAXPATHL); pinfo->port = scheme_open_input_file(file, "mzfile"); MZ_GC_CHECK(); ! scheme_count_lines(pinfo->port); // to get accurate read error location MZ_GC_CHECK(); ! // Like REPL but print only last result while (!SCHEME_EOFP(expr = scheme_read(pinfo->port))) { result = scheme_eval(expr, environment); MZ_GC_CHECK(); } ! // errors will be caught in do_mzscheme_command and ex_mzfile scheme_close_input_port(pinfo->port); MZ_GC_CHECK(); pinfo->port = NULL; *************** *** 1473,1479 **** return result; } ! /* :mzfile */ void ex_mzfile(exarg_T *eap) { --- 1471,1479 ---- return result; } ! /* ! * :mzfile ! */ void ex_mzfile(exarg_T *eap) { *************** *** 1485,1491 **** pinfo.name = (char *)eap->arg; if (do_mzscheme_command(eap, &pinfo, do_load) != OK ! && pinfo.port != NULL) /* looks like port was not closed */ { scheme_close_input_port(pinfo.port); MZ_GC_CHECK(); --- 1485,1491 ---- pinfo.name = (char *)eap->arg; if (do_mzscheme_command(eap, &pinfo, do_load) != OK ! && pinfo.port != NULL) // looks like port was not closed { scheme_close_input_port(pinfo.port); MZ_GC_CHECK(); *************** *** 1530,1536 **** Scheme_Object *v; v = _scheme_apply(exn_catching_apply, 1, &f); ! /* v is a pair: (cons #t value) or (cons #f exn) */ if (SCHEME_TRUEP(SCHEME_CAR(v))) return SCHEME_CDR(v); --- 1530,1536 ---- Scheme_Object *v; v = _scheme_apply(exn_catching_apply, 1, &f); ! // v is a pair: (cons #t value) or (cons #f exn) if (SCHEME_TRUEP(SCHEME_CAR(v))) return SCHEME_CDR(v); *************** *** 1547,1553 **** if (SCHEME_TRUEP(_scheme_apply(exn_p, 1, &v))) return _scheme_apply(exn_message, 1, &v); else ! return NULL; /* Not an exn structure */ } static Scheme_Object * --- 1547,1553 ---- if (SCHEME_TRUEP(_scheme_apply(exn_p, 1, &v))) return _scheme_apply(exn_message, 1, &v); else ! return NULL; // Not an exn structure } static Scheme_Object * *************** *** 1588,1594 **** static void do_output(char *mesg, OUTPUT_LEN_TYPE len UNUSED) { ! /* TODO: use len, the string may not be NUL terminated */ do_intrnl_output(mesg, 0); } --- 1588,1594 ---- static void do_output(char *mesg, OUTPUT_LEN_TYPE len UNUSED) { ! // TODO: use len, the string may not be NUL terminated do_intrnl_output(mesg, 0); } *************** *** 1630,1636 **** *======================================================================== */ ! /* (command {command-string}) */ static Scheme_Object * vim_command(void *data, int argc, Scheme_Object **argv) { --- 1630,1638 ---- *======================================================================== */ ! /* ! * (command {command-string}) ! */ static Scheme_Object * vim_command(void *data, int argc, Scheme_Object **argv) { *************** *** 1641,1647 **** MZ_GC_REG(); cmd = GUARANTEED_STRING_ARG(prim->name, 0); ! /* may be use do_cmdline_cmd? */ do_cmdline(BYTE_STRING_VALUE(cmd), NULL, NULL, DOCMD_NOWAIT|DOCMD_VERBOSE); update_screen(VALID); --- 1643,1649 ---- MZ_GC_REG(); cmd = GUARANTEED_STRING_ARG(prim->name, 0); ! // may be use do_cmdline_cmd? do_cmdline(BYTE_STRING_VALUE(cmd), NULL, NULL, DOCMD_NOWAIT|DOCMD_VERBOSE); update_screen(VALID); *************** *** 1650,1656 **** return scheme_void; } ! /* (eval {expr-string}) */ static Scheme_Object * vim_eval(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { --- 1652,1660 ---- return scheme_void; } ! /* ! * (eval {expr-string}) ! */ static Scheme_Object * vim_eval(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { *************** *** 1678,1703 **** return result; #else raise_vim_exn(_("expressions disabled at compile time")); ! /* unreachable */ return scheme_false; #endif } ! /* (range-start) */ static Scheme_Object * get_range_start(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { return scheme_make_integer(range_start); } ! /* (range-end) */ static Scheme_Object * get_range_end(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { return scheme_make_integer(range_end); } ! /* (beep) */ static Scheme_Object * mzscheme_beep(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { --- 1682,1713 ---- return result; #else raise_vim_exn(_("expressions disabled at compile time")); ! // unreachable return scheme_false; #endif } ! /* ! * (range-start) ! */ static Scheme_Object * get_range_start(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { return scheme_make_integer(range_start); } ! /* ! * (range-end) ! */ static Scheme_Object * get_range_end(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { return scheme_make_integer(range_end); } ! /* ! * (beep) ! */ static Scheme_Object * mzscheme_beep(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { *************** *** 1707,1713 **** static Scheme_Object *M_global = NULL; ! /* (get-option {option-name}) [buffer/window] */ static Scheme_Object * get_option(void *data, int argc, Scheme_Object **argv) { --- 1717,1725 ---- static Scheme_Object *M_global = NULL; ! /* ! * (get-option {option-name}) [buffer/window] ! */ static Scheme_Object * get_option(void *data, int argc, Scheme_Object **argv) { *************** *** 1775,1791 **** case -2: MZ_GC_UNREG(); raise_vim_exn(_("hidden option")); ! /*NOTREACHED*/ case -3: MZ_GC_UNREG(); raise_vim_exn(_("unknown option")); ! /*NOTREACHED*/ } ! /* unreachable */ return scheme_void; } ! /* (set-option {option-changing-string} [buffer/window]) */ static Scheme_Object * set_option(void *data, int argc, Scheme_Object **argv) { --- 1787,1805 ---- case -2: MZ_GC_UNREG(); raise_vim_exn(_("hidden option")); ! //NOTREACHED case -3: MZ_GC_UNREG(); raise_vim_exn(_("unknown option")); ! //NOTREACHED } ! // unreachable return scheme_void; } ! /* ! * (set-option {option-changing-string} [buffer/window]) ! */ static Scheme_Object * set_option(void *data, int argc, Scheme_Object **argv) { *************** *** 1828,1834 **** scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv); } ! /* do_set can modify cmd, make copy */ command = vim_strsave(BYTE_STRING_VALUE(cmd)); MZ_GC_UNREG(); do_set(command, opt_flags); --- 1842,1848 ---- scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv); } ! // do_set can modify cmd, make copy command = vim_strsave(BYTE_STRING_VALUE(cmd)); MZ_GC_UNREG(); do_set(command, opt_flags); *************** *** 1846,1859 **** *=========================================================================== */ ! /* (curr-win) */ static Scheme_Object * get_curr_win(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { return (Scheme_Object *)get_vim_curr_window(); } ! /* (win-count) */ static Scheme_Object * get_window_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { --- 1860,1877 ---- *=========================================================================== */ ! /* ! * (curr-win) ! */ static Scheme_Object * get_curr_win(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { return (Scheme_Object *)get_vim_curr_window(); } ! /* ! * (win-count) ! */ static Scheme_Object * get_window_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { *************** *** 1865,1871 **** return scheme_make_integer(n); } ! /* (get-win-list [buffer]) */ static Scheme_Object * get_window_list(void *data, int argc, Scheme_Object **argv) { --- 1883,1891 ---- return scheme_make_integer(n); } ! /* ! * (get-win-list [buffer]) ! */ static Scheme_Object * get_window_list(void *data, int argc, Scheme_Object **argv) { *************** *** 1895,1908 **** MZ_GC_DECL_REG(1); MZ_GC_VAR_IN_REG(0, self); ! /* We need to handle deletion of windows underneath us. ! * If we add a "w_mzscheme_ref" field to the win_T structure, ! * then we can get at it in win_free() in vim. ! * ! * On a win_free() we set the Scheme object's win_T *field ! * to an invalid value. We trap all uses of a window ! * object, and reject them if the win_T *field is invalid. ! */ if (win->w_mzscheme_ref != NULL) return (Scheme_Object *)WINDOW_REF(win); --- 1915,1927 ---- MZ_GC_DECL_REG(1); MZ_GC_VAR_IN_REG(0, self); ! // We need to handle deletion of windows underneath us. ! // If we add a "w_mzscheme_ref" field to the win_T structure, ! // then we can get at it in win_free() in vim. ! // ! // On a win_free() we set the Scheme object's win_T *field ! // to an invalid value. We trap all uses of a window ! // object, and reject them if the win_T *field is invalid. if (win->w_mzscheme_ref != NULL) return (Scheme_Object *)WINDOW_REF(win); *************** *** 1910,1916 **** self = scheme_malloc_fail_ok(scheme_malloc_tagged, sizeof(vim_mz_window)); vim_memset(self, 0, sizeof(vim_mz_window)); #ifndef MZ_PRECISE_GC ! scheme_dont_gc_ptr(self); /* because win isn't visible to GC */ #else win->w_mzscheme_ref = scheme_malloc_immobile_box(NULL); #endif --- 1929,1935 ---- self = scheme_malloc_fail_ok(scheme_malloc_tagged, sizeof(vim_mz_window)); vim_memset(self, 0, sizeof(vim_mz_window)); #ifndef MZ_PRECISE_GC ! scheme_dont_gc_ptr(self); // because win isn't visible to GC #else win->w_mzscheme_ref = scheme_malloc_immobile_box(NULL); #endif *************** *** 1924,1930 **** return (Scheme_Object *)self; } ! /* (get-win-num [window]) */ static Scheme_Object * get_window_num(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { --- 1943,1951 ---- return (Scheme_Object *)self; } ! /* ! * (get-win-num [window]) ! */ static Scheme_Object * get_window_num(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { *************** *** 1939,1945 **** return scheme_make_integer(nr); } ! /* (get-win-by-num {windownum}) */ static Scheme_Object * get_window_by_num(void *data, int argc, Scheme_Object **argv) { --- 1960,1968 ---- return scheme_make_integer(nr); } ! /* ! * (get-win-by-num {windownum}) ! */ static Scheme_Object * get_window_by_num(void *data, int argc, Scheme_Object **argv) { *************** *** 1952,1964 **** scheme_signal_error(_("window index is out of range")); for ( ; win != NULL; win = win->w_next, --fnum) ! if (fnum == 1) /* to be 1-based */ return window_new(win); return scheme_false; } ! /* (get-win-buffer [window]) */ static Scheme_Object * get_window_buffer(void *data, int argc, Scheme_Object **argv) { --- 1975,1989 ---- scheme_signal_error(_("window index is out of range")); for ( ; win != NULL; win = win->w_next, --fnum) ! if (fnum == 1) // to be 1-based return window_new(win); return scheme_false; } ! /* ! * (get-win-buffer [window]) ! */ static Scheme_Object * get_window_buffer(void *data, int argc, Scheme_Object **argv) { *************** *** 1968,1974 **** return buffer_new(win->win->w_buffer); } ! /* (get-win-height [window]) */ static Scheme_Object * get_window_height(void *data, int argc, Scheme_Object **argv) { --- 1993,2001 ---- return buffer_new(win->win->w_buffer); } ! /* ! * (get-win-height [window]) ! */ static Scheme_Object * get_window_height(void *data, int argc, Scheme_Object **argv) { *************** *** 1978,1984 **** return scheme_make_integer(win->win->w_height); } ! /* (set-win-height {height} [window]) */ static Scheme_Object * set_window_height(void *data, int argc, Scheme_Object **argv) { --- 2005,2013 ---- return scheme_make_integer(win->win->w_height); } ! /* ! * (set-win-height {height} [window]) ! */ static Scheme_Object * set_window_height(void *data, int argc, Scheme_Object **argv) { *************** *** 2003,2009 **** return scheme_void; } ! /* (get-win-width [window]) */ static Scheme_Object * get_window_width(void *data, int argc, Scheme_Object **argv) { --- 2032,2040 ---- return scheme_void; } ! /* ! * (get-win-width [window]) ! */ static Scheme_Object * get_window_width(void *data, int argc, Scheme_Object **argv) { *************** *** 2013,2019 **** return scheme_make_integer(win->win->w_width); } ! /* (set-win-width {width} [window]) */ static Scheme_Object * set_window_width(void *data, int argc, Scheme_Object **argv) { --- 2044,2052 ---- return scheme_make_integer(win->win->w_width); } ! /* ! * (set-win-width {width} [window]) ! */ static Scheme_Object * set_window_width(void *data, int argc, Scheme_Object **argv) { *************** *** 2038,2044 **** return scheme_void; } ! /* (get-cursor [window]) -> (line . col) */ static Scheme_Object * get_cursor(void *data, int argc, Scheme_Object **argv) { --- 2071,2079 ---- return scheme_void; } ! /* ! * (get-cursor [window]) -> (line . col) ! */ static Scheme_Object * get_cursor(void *data, int argc, Scheme_Object **argv) { *************** *** 2052,2058 **** scheme_make_integer_value((long)pos.col + 1)); } ! /* (set-cursor (line . col) [window]) */ static Scheme_Object * set_cursor(void *data, int argc, Scheme_Object **argv) { --- 2087,2095 ---- scheme_make_integer_value((long)pos.col + 1)); } ! /* ! * (set-cursor (line . col) [window]) ! */ static Scheme_Object * set_cursor(void *data, int argc, Scheme_Object **argv) { *************** *** 2075,2081 **** col = SCHEME_INT_VAL(SCHEME_CDR(argv[0])) - 1; check_line_range(lnum, win->win->w_buffer); ! /* don't know how to catch invalid column value */ win->win->w_cursor.lnum = lnum; win->win->w_cursor.col = col; --- 2112,2118 ---- col = SCHEME_INT_VAL(SCHEME_CDR(argv[0])) - 1; check_line_range(lnum, win->win->w_buffer); ! // don't know how to catch invalid column value win->win->w_cursor.lnum = lnum; win->win->w_cursor.col = col; *************** *** 2091,2097 **** *=========================================================================== */ ! /* (open-buff {filename}) */ static Scheme_Object * mzscheme_open_buffer(void *data, int argc, Scheme_Object **argv) { --- 2128,2136 ---- *=========================================================================== */ ! /* ! * (open-buff {filename}) ! */ static Scheme_Object * mzscheme_open_buffer(void *data, int argc, Scheme_Object **argv) { *************** *** 2111,2117 **** #ifdef HAVE_SANDBOX sandbox_check(); #endif ! /* TODO make open existing file */ num = buflist_add(BYTE_STRING_VALUE(fname), BLN_LISTED | BLN_CURBUF); if (num == 0) --- 2150,2156 ---- #ifdef HAVE_SANDBOX sandbox_check(); #endif ! // TODO make open existing file num = buflist_add(BYTE_STRING_VALUE(fname), BLN_LISTED | BLN_CURBUF); if (num == 0) *************** *** 2123,2129 **** return buf; } ! /* (get-buff-by-num {buffernum}) */ static Scheme_Object * get_buffer_by_num(void *data, int argc, Scheme_Object **argv) { --- 2162,2170 ---- return buf; } ! /* ! * (get-buff-by-num {buffernum}) ! */ static Scheme_Object * get_buffer_by_num(void *data, int argc, Scheme_Object **argv) { *************** *** 2140,2146 **** return scheme_false; } ! /* (get-buff-by-name {buffername}) */ static Scheme_Object * get_buffer_by_name(void *data, int argc, Scheme_Object **argv) { --- 2181,2189 ---- return scheme_false; } ! /* ! * (get-buff-by-name {buffername}) ! */ static Scheme_Object * get_buffer_by_name(void *data, int argc, Scheme_Object **argv) { *************** *** 2159,2165 **** FOR_ALL_BUFFERS(buf) { if (buf->b_ffname == NULL || buf->b_sfname == NULL) ! /* empty string */ { if (BYTE_STRING_VALUE(fname)[0] == NUL) buffer = buffer_new(buf); --- 2202,2208 ---- FOR_ALL_BUFFERS(buf) { if (buf->b_ffname == NULL || buf->b_sfname == NULL) ! // empty string { if (BYTE_STRING_VALUE(fname)[0] == NUL) buffer = buffer_new(buf); *************** *** 2167,2173 **** else if (!fnamecmp(buf->b_ffname, BYTE_STRING_VALUE(fname)) || !fnamecmp(buf->b_sfname, BYTE_STRING_VALUE(fname))) { ! /* either short or long filename matches */ buffer = buffer_new(buf); } } --- 2210,2216 ---- else if (!fnamecmp(buf->b_ffname, BYTE_STRING_VALUE(fname)) || !fnamecmp(buf->b_sfname, BYTE_STRING_VALUE(fname))) { ! // either short or long filename matches buffer = buffer_new(buf); } } *************** *** 2176,2182 **** return buffer; } ! /* (get-next-buff [buffer]) */ static Scheme_Object * get_next_buffer(void *data, int argc, Scheme_Object **argv) { --- 2219,2227 ---- return buffer; } ! /* ! * (get-next-buff [buffer]) ! */ static Scheme_Object * get_next_buffer(void *data, int argc, Scheme_Object **argv) { *************** *** 2189,2195 **** return buffer_new(buf->b_next); } ! /* (get-prev-buff [buffer]) */ static Scheme_Object * get_prev_buffer(void *data, int argc, Scheme_Object **argv) { --- 2234,2242 ---- return buffer_new(buf->b_next); } ! /* ! * (get-prev-buff [buffer]) ! */ static Scheme_Object * get_prev_buffer(void *data, int argc, Scheme_Object **argv) { *************** *** 2202,2208 **** return buffer_new(buf->b_prev); } ! /* (get-buff-num [buffer]) */ static Scheme_Object * get_buffer_num(void *data, int argc, Scheme_Object **argv) { --- 2249,2257 ---- return buffer_new(buf->b_prev); } ! /* ! * (get-buff-num [buffer]) ! */ static Scheme_Object * get_buffer_num(void *data, int argc, Scheme_Object **argv) { *************** *** 2212,2218 **** return scheme_make_integer(buf->buf->b_fnum); } ! /* (buff-count) */ static Scheme_Object * get_buffer_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { --- 2261,2269 ---- return scheme_make_integer(buf->buf->b_fnum); } ! /* ! * (buff-count) ! */ static Scheme_Object * get_buffer_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { *************** *** 2223,2229 **** return scheme_make_integer(n); } ! /* (get-buff-name [buffer]) */ static Scheme_Object * get_buffer_name(void *data, int argc, Scheme_Object **argv) { --- 2274,2282 ---- return scheme_make_integer(n); } ! /* ! * (get-buff-name [buffer]) ! */ static Scheme_Object * get_buffer_name(void *data, int argc, Scheme_Object **argv) { *************** *** 2233,2239 **** return scheme_make_byte_string((char *)buf->buf->b_ffname); } ! /* (curr-buff) */ static Scheme_Object * get_curr_buffer(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { --- 2286,2294 ---- return scheme_make_byte_string((char *)buf->buf->b_ffname); } ! /* ! * (curr-buff) ! */ static Scheme_Object * get_curr_buffer(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED) { *************** *** 2248,2257 **** MZ_GC_DECL_REG(1); MZ_GC_VAR_IN_REG(0, self); ! /* We need to handle deletion of buffers underneath us. ! * If we add a "b_mzscheme_ref" field to the buf_T structure, ! * then we can get at it in buf_freeall() in vim. ! */ if (buf->b_mzscheme_ref) return (Scheme_Object *)BUFFER_REF(buf); --- 2303,2311 ---- MZ_GC_DECL_REG(1); MZ_GC_VAR_IN_REG(0, self); ! // We need to handle deletion of buffers underneath us. ! // If we add a "b_mzscheme_ref" field to the buf_T structure, ! // then we can get at it in buf_freeall() in vim. if (buf->b_mzscheme_ref) return (Scheme_Object *)BUFFER_REF(buf); *************** *** 2259,2265 **** self = scheme_malloc_fail_ok(scheme_malloc_tagged, sizeof(vim_mz_buffer)); vim_memset(self, 0, sizeof(vim_mz_buffer)); #ifndef MZ_PRECISE_GC ! scheme_dont_gc_ptr(self); /* because buf isn't visible to GC */ #else buf->b_mzscheme_ref = scheme_malloc_immobile_box(NULL); #endif --- 2313,2319 ---- self = scheme_malloc_fail_ok(scheme_malloc_tagged, sizeof(vim_mz_buffer)); vim_memset(self, 0, sizeof(vim_mz_buffer)); #ifndef MZ_PRECISE_GC ! scheme_dont_gc_ptr(self); // because buf isn't visible to GC #else buf->b_mzscheme_ref = scheme_malloc_immobile_box(NULL); #endif *************** *** 2354,2360 **** (char *)ml_get_buf(buf->buf, (linenr_T)(lo+i), FALSE)); raise_if_error(); ! /* Set the list item */ list = scheme_make_pair(str, list); MZ_GC_CHECK(); } --- 2408,2414 ---- (char *)ml_get_buf(buf->buf, (linenr_T)(lo+i), FALSE)); raise_if_error(); ! // Set the list item list = scheme_make_pair(str, list); MZ_GC_CHECK(); } *************** *** 2377,2388 **** static Scheme_Object * set_buffer_line(void *data, int argc, Scheme_Object **argv) { ! /* First of all, we check the value of the supplied MzScheme object. ! * There are three cases: ! * 1. #f - this is a deletion. ! * 2. A string - this is a replacement. ! * 3. Anything else - this is an error. ! */ Vim_Prim *prim = (Vim_Prim *)data; vim_mz_buffer *buf; Scheme_Object *line = NULL; --- 2431,2441 ---- static Scheme_Object * set_buffer_line(void *data, int argc, Scheme_Object **argv) { ! // First of all, we check the value of the supplied MzScheme object. ! // There are three cases: ! // 1. #f - this is a deletion. ! // 2. A string - this is a replacement. ! // 3. Anything else - this is an error. Vim_Prim *prim = (Vim_Prim *)data; vim_mz_buffer *buf; Scheme_Object *line = NULL; *************** *** 2432,2438 **** } else { ! /* Otherwise it's a line */ buf_T *savebuf = curbuf; save = string_to_line(line); --- 2485,2491 ---- } else { ! // Otherwise it's a line buf_T *savebuf = curbuf; save = string_to_line(line); *************** *** 2459,2465 **** curbuf = savebuf; ! /* Check that the cursor is not beyond the end of the line now. */ if (buf->buf == curwin->w_buffer) check_cursor_col(); --- 2512,2518 ---- curbuf = savebuf; ! // Check that the cursor is not beyond the end of the line now. if (buf->buf == curwin->w_buffer) check_cursor_col(); *************** *** 2493,2504 **** static Scheme_Object * set_buffer_line_list(void *data, int argc, Scheme_Object **argv) { ! /* First of all, we check the type of the supplied MzScheme object. ! * There are three cases: ! * 1. #f - this is a deletion. ! * 2. A list - this is a replacement. ! * 3. Anything else - this is an error. ! */ Vim_Prim *prim = (Vim_Prim *)data; vim_mz_buffer *buf = NULL; Scheme_Object *line_list = NULL; --- 2546,2556 ---- static Scheme_Object * set_buffer_line_list(void *data, int argc, Scheme_Object **argv) { ! // First of all, we check the type of the supplied MzScheme object. ! // There are three cases: ! // 1. #f - this is a deletion. ! // 2. A list - this is a replacement. ! // 3. Anything else - this is an error. Vim_Prim *prim = (Vim_Prim *)data; vim_mz_buffer *buf = NULL; Scheme_Object *line_list = NULL; *************** *** 2520,2526 **** line_list = argv[2]; buf = get_buffer_arg(prim->name, 3, argc, argv); old_len = hi - lo; ! if (old_len < 0) /* process inverse values wisely */ { i = lo; lo = hi; --- 2572,2578 ---- line_list = argv[2]; buf = get_buffer_arg(prim->name, 3, argc, argv); old_len = hi - lo; ! if (old_len < 0) // process inverse values wisely { i = lo; lo = hi; *************** *** 2529,2536 **** } extra = 0; ! check_line_range(lo, buf->buf); /* inclusive */ ! check_line_range(hi - 1, buf->buf); /* exclusive */ if (SCHEME_FALSEP(line_list) || SCHEME_NULLP(line_list)) { --- 2581,2588 ---- } extra = 0; ! check_line_range(lo, buf->buf); // inclusive ! check_line_range(hi - 1, buf->buf); // exclusive if (SCHEME_FALSEP(line_list) || SCHEME_NULLP(line_list)) { *************** *** 2565,2574 **** { buf_T *savebuf = curbuf; ! /* List */ new_len = scheme_proper_list_length(line_list); MZ_GC_CHECK(); ! if (new_len < 0) /* improper or cyclic list */ scheme_wrong_type(prim->name, "proper list", 2, argc, argv); else --- 2617,2626 ---- { buf_T *savebuf = curbuf; ! // List new_len = scheme_proper_list_length(line_list); MZ_GC_CHECK(); ! if (new_len < 0) // improper or cyclic list scheme_wrong_type(prim->name, "proper list", 2, argc, argv); else *************** *** 2713,2719 **** scheme_wrong_type(prim->name, "string or list", 1, argc, argv); buf = get_buffer_arg(prim->name, 2, argc, argv); ! if (n != 0) /* 0 can be used in insert */ check_line_range(n, buf->buf); if (SCHEME_STRINGP(list)) { --- 2765,2771 ---- scheme_wrong_type(prim->name, "string or list", 1, argc, argv); buf = get_buffer_arg(prim->name, 2, argc, argv); ! if (n != 0) // 0 can be used in insert check_line_range(n, buf->buf); if (SCHEME_STRINGP(list)) { *************** *** 2748,2757 **** return scheme_void; } ! /* List */ size = scheme_proper_list_length(list); MZ_GC_CHECK(); ! if (size < 0) /* improper or cyclic list */ scheme_wrong_type(prim->name, "proper list", 2, argc, argv); else --- 2800,2809 ---- return scheme_void; } ! // List size = scheme_proper_list_length(list); MZ_GC_CHECK(); ! if (size < 0) // improper or cyclic list scheme_wrong_type(prim->name, "proper list", 2, argc, argv); else *************** *** 2813,2819 **** /* * Predicates */ ! /* (buff? obj) */ static Scheme_Object * vim_bufferp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) { --- 2865,2873 ---- /* * Predicates */ ! /* ! * (buff? obj) ! */ static Scheme_Object * vim_bufferp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) { *************** *** 2823,2829 **** return scheme_false; } ! /* (win? obj) */ static Scheme_Object * vim_windowp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) { --- 2877,2885 ---- return scheme_false; } ! /* ! * (win? obj) ! */ static Scheme_Object * vim_windowp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) { *************** *** 2833,2839 **** return scheme_false; } ! /* (buff-valid? obj) */ static Scheme_Object * vim_buffer_validp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) { --- 2889,2897 ---- return scheme_false; } ! /* ! * (buff-valid? obj) ! */ static Scheme_Object * vim_buffer_validp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) { *************** *** 2844,2850 **** return scheme_false; } ! /* (win-valid? obj) */ static Scheme_Object * vim_window_validp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) { --- 2902,2910 ---- return scheme_false; } ! /* ! * (win-valid? obj) ! */ static Scheme_Object * vim_window_validp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv) { *************** *** 2879,2896 **** scheme_str = scheme_display_to_string(obj, &len); ! /* Error checking: String must not contain newlines, as we ! * are replacing a single line, and we must replace it with ! * a single line. ! */ if (memchr(scheme_str, '\n', len)) scheme_signal_error(_("string cannot contain newlines")); vim_str = alloc(len + 1); ! /* Create a copy of the string, with internal nulls replaced by ! * newline characters, as is the vim convention. ! */ for (i = 0; i < len; ++i) { if (scheme_str[i] == '\0') --- 2939,2954 ---- scheme_str = scheme_display_to_string(obj, &len); ! // Error checking: String must not contain newlines, as we ! // are replacing a single line, and we must replace it with ! // a single line. if (memchr(scheme_str, '\n', len)) scheme_signal_error(_("string cannot contain newlines")); vim_str = alloc(len + 1); ! // Create a copy of the string, with internal nulls replaced by ! // newline characters, as is the vim convention. for (i = 0; i < len; ++i) { if (scheme_str[i] == '\0') *************** *** 2913,2919 **** vim_to_mzscheme(typval_T *vim_value) { Scheme_Object *result = NULL; ! /* hash table to store visited values to avoid infinite loops */ Scheme_Hash_Table *visited = NULL; MZ_GC_DECL_REG(2); --- 2971,2977 ---- vim_to_mzscheme(typval_T *vim_value) { Scheme_Object *result = NULL; ! // hash table to store visited values to avoid infinite loops Scheme_Hash_Table *visited = NULL; MZ_GC_DECL_REG(2); *************** *** 2941,2959 **** MZ_GC_VAR_IN_REG(1, visited); MZ_GC_REG(); ! /* Avoid infinite recursion */ if (depth > 100) { MZ_GC_UNREG(); return scheme_void; } ! /* Check if we run into a recursive loop. The item must be in visited ! * then and we can use it again. ! */ result = scheme_hash_get(visited, (Scheme_Object *)vim_value); MZ_GC_CHECK(); ! if (result != NULL) /* found, do nothing */ new_value = FALSE; else if (vim_value->v_type == VAR_STRING) { --- 2999,3016 ---- MZ_GC_VAR_IN_REG(1, visited); MZ_GC_REG(); ! // Avoid infinite recursion if (depth > 100) { MZ_GC_UNREG(); return scheme_void; } ! // Check if we run into a recursive loop. The item must be in visited ! // then and we can use it again. result = scheme_hash_get(visited, (Scheme_Object *)vim_value); MZ_GC_CHECK(); ! if (result != NULL) // found, do nothing new_value = FALSE; else if (vim_value->v_type == VAR_STRING) { *************** *** 3046,3052 **** MZ_GC_VAR_IN_REG(0, funcname); MZ_GC_REG(); ! /* FIXME: func_ref() and func_unref() are needed. */ funcname = scheme_make_byte_string((char *)vim_value->vval.v_string); MZ_GC_CHECK(); result = scheme_make_closed_prim_w_arity(vim_funcref, funcname, --- 3103,3109 ---- MZ_GC_VAR_IN_REG(0, funcname); MZ_GC_REG(); ! // FIXME: func_ref() and func_unref() are needed. funcname = scheme_make_byte_string((char *)vim_value->vval.v_string); MZ_GC_CHECK(); result = scheme_make_closed_prim_w_arity(vim_funcref, funcname, *************** *** 3067,3074 **** MZ_GC_VAR_IN_REG(0, funcname); MZ_GC_REG(); ! /* FIXME: func_ref() and func_unref() are needed. */ ! /* TODO: Support pt_dict and pt_argv. */ funcname = scheme_make_byte_string( (char *)partial_name(vim_value->vval.v_partial)); MZ_GC_CHECK(); --- 3124,3131 ---- MZ_GC_VAR_IN_REG(0, funcname); MZ_GC_REG(); ! // FIXME: func_ref() and func_unref() are needed. ! // TODO: Support pt_dict and pt_argv. funcname = scheme_make_byte_string( (char *)partial_name(vim_value->vval.v_partial)); MZ_GC_CHECK(); *************** *** 3118,3124 **** status = mzscheme_to_vim_impl(obj, tv, 1, visited); for (i = 0; i < visited->size; ++i) { ! /* free up remembered objects */ if (visited->vals[i] != NULL) free_tv((typval_T *)visited->vals[i]); } --- 3175,3181 ---- status = mzscheme_to_vim_impl(obj, tv, 1, visited); for (i = 0; i < visited->size; ++i) { ! // free up remembered objects if (visited->vals[i] != NULL) free_tv((typval_T *)visited->vals[i]); } *************** *** 3139,3145 **** MZ_GC_REG(); MZ_GC_CHECK(); ! if (depth > 100) /* limit the deepest recursion level */ { tv->v_type = VAR_NUMBER; tv->vval.v_number = 0; --- 3196,3202 ---- MZ_GC_REG(); MZ_GC_CHECK(); ! if (depth > 100) // limit the deepest recursion level { tv->v_type = VAR_NUMBER; tv->vval.v_number = 0; *************** *** 3201,3207 **** int i; Scheme_Object *curr = NULL; Scheme_Object *cval = NULL; ! /* temporary var to hold current element of vectors and pairs */ typval_T *v; MZ_GC_DECL_REG(2); --- 3258,3264 ---- int i; Scheme_Object *curr = NULL; Scheme_Object *cval = NULL; ! // temporary var to hold current element of vectors and pairs typval_T *v; MZ_GC_DECL_REG(2); *************** *** 3218,3225 **** status = FAIL; else { ! /* add the value in advance to allow handling of self-referential ! * data structures */ typval_T *visited_tv = ALLOC_ONE(typval_T); copy_tv(tv, visited_tv); scheme_hash_set(visited, obj, (Scheme_Object *)visited_tv); --- 3275,3282 ---- status = FAIL; else { ! // add the value in advance to allow handling of self-referential ! // data structures typval_T *visited_tv = ALLOC_ONE(typval_T); copy_tv(tv, visited_tv); scheme_hash_set(visited, obj, (Scheme_Object *)visited_tv); *************** *** 3253,3260 **** if (status == FAIL) break; } ! /* improper list not terminated with null ! * need to handle the last element */ if (status == OK && !SCHEME_NULLP(curr)) { status = mzscheme_to_vim_impl(cval, v, depth + 1, visited); --- 3310,3317 ---- if (status == FAIL) break; } ! // improper list not terminated with null ! // need to handle the last element if (status == OK && !SCHEME_NULLP(curr)) { status = mzscheme_to_vim_impl(cval, v, depth + 1, visited); *************** *** 3265,3271 **** } } } ! /* nothing to do for scheme_null */ vim_free(v); } MZ_GC_UNREG(); --- 3322,3328 ---- } } } ! // nothing to do for scheme_null vim_free(v); } MZ_GC_UNREG(); *************** *** 3301,3310 **** { if (((Scheme_Hash_Table *) obj)->vals[i] != NULL) { ! /* generate item for `display'ed Scheme key */ dictitem_T *item = dictitem_alloc((char_u *)string_to_line( ((Scheme_Hash_Table *) obj)->keys[i])); ! /* convert Scheme val to Vim and add it to the dict */ if (mzscheme_to_vim_impl(((Scheme_Hash_Table *) obj)->vals[i], &item->di_tv, depth + 1, visited) == FAIL || dict_add(dict, item) == FAIL) --- 3358,3367 ---- { if (((Scheme_Hash_Table *) obj)->vals[i] != NULL) { ! // generate item for `display'ed Scheme key dictitem_T *item = dictitem_alloc((char_u *)string_to_line( ((Scheme_Hash_Table *) obj)->keys[i])); ! // convert Scheme val to Vim and add it to the dict if (mzscheme_to_vim_impl(((Scheme_Hash_Table *) obj)->vals[i], &item->di_tv, depth + 1, visited) == FAIL || dict_add(dict, item) == FAIL) *************** *** 3321,3327 **** } else { ! /* `display' any other value to string */ tv->v_type = VAR_STRING; tv->vval.v_string = (char_u *)string_to_line(obj); } --- 3378,3384 ---- } else { ! // `display' any other value to string tv->v_type = VAR_STRING; tv->vval.v_string = (char_u *)string_to_line(obj); } *************** *** 3329,3335 **** return status; } ! /* Scheme prim procedure wrapping Vim funcref */ static Scheme_Object * vim_funcref(void *name, int argc, Scheme_Object **argv) { --- 3386,3394 ---- return status; } ! /* ! * Scheme prim procedure wrapping Vim funcref ! */ static Scheme_Object * vim_funcref(void *name, int argc, Scheme_Object **argv) { *************** *** 3546,3552 **** raise_vim_exn(NULL); } ! /* get buffer: * either current * or passed as argv[argnum] with checks */ --- 3605,3612 ---- raise_vim_exn(NULL); } ! /* ! * get buffer: * either current * or passed as argv[argnum] with checks */ *************** *** 3564,3570 **** return b; } ! /* get window: * either current * or passed as argv[argnum] with checks */ --- 3624,3631 ---- return b; } ! /* ! * get window: * either current * or passed as argv[argnum] with checks */ *************** *** 3582,3588 **** return w; } ! /* get valid Vim buffer from Scheme_Object* */ buf_T *get_valid_buffer(void *obj) { buf_T *buf = ((vim_mz_buffer *)obj)->buf; --- 3643,3651 ---- return w; } ! /* ! * get valid Vim buffer from Scheme_Object* ! */ buf_T *get_valid_buffer(void *obj) { buf_T *buf = ((vim_mz_buffer *)obj)->buf; *************** *** 3592,3598 **** return buf; } ! /* get valid Vim window from Scheme_Object* */ win_T *get_valid_window(void *obj) { win_T *win = ((vim_mz_window *)obj)->win; --- 3655,3663 ---- return buf; } ! /* ! * get valid Vim window from Scheme_Object* ! */ win_T *get_valid_window(void *obj) { win_T *win = ((vim_mz_window *)obj)->win; *************** *** 3631,3638 **** { if (curwin->w_cursor.lnum >= lo) { ! /* Adjust the cursor position if it's in/after the changed ! * lines. */ if (curwin->w_cursor.lnum >= hi) { curwin->w_cursor.lnum += extra; --- 3696,3703 ---- { if (curwin->w_cursor.lnum >= lo) { ! // Adjust the cursor position if it's in/after the changed ! // lines. if (curwin->w_cursor.lnum >= hi) { curwin->w_cursor.lnum += extra; *************** *** 3704,3710 **** {vim_window_validp, "win-valid?", 1, 1} }; ! /* return MzScheme wrapper for curbuf */ static vim_mz_buffer * get_vim_curr_buffer(void) { --- 3769,3777 ---- {vim_window_validp, "win-valid?", 1, 1} }; ! /* ! * return MzScheme wrapper for curbuf ! */ static vim_mz_buffer * get_vim_curr_buffer(void) { *************** *** 3714,3720 **** return BUFFER_REF(curbuf); } ! /* return MzScheme wrapper for curwin */ static vim_mz_window * get_vim_curr_window(void) { --- 3781,3789 ---- return BUFFER_REF(curbuf); } ! /* ! * return MzScheme wrapper for curwin ! */ static vim_mz_window * get_vim_curr_window(void) { *************** *** 3742,3748 **** MZ_GC_CHECK(); mod = scheme_primitive_module(vimext_symbol, environment); MZ_GC_CHECK(); ! /* all prims made closed so they can access their own names */ for (i = 0; i < (int)(sizeof(prims)/sizeof(prims[0])); i++) { Vim_Prim *prim = prims + i; --- 3811,3817 ---- MZ_GC_CHECK(); mod = scheme_primitive_module(vimext_symbol, environment); MZ_GC_CHECK(); ! // all prims made closed so they can access their own names for (i = 0; i < (int)(sizeof(prims)/sizeof(prims[0])); i++) { Vim_Prim *prim = prims + i; *************** *** 3769,3775 **** raise_vim_exn(_("not allowed in the Vim sandbox")); } ! /* security guards to force Vim's sandbox restrictions on MzScheme level */ static Scheme_Object * sandbox_file_guard(int argc UNUSED, Scheme_Object **argv) { --- 3838,3846 ---- raise_vim_exn(_("not allowed in the Vim sandbox")); } ! /* ! * security guards to force Vim's sandbox restrictions on MzScheme level ! */ static Scheme_Object * sandbox_file_guard(int argc UNUSED, Scheme_Object **argv) { *** ../vim-8.1.2386/src/if_perlsfio.c 2019-05-28 23:08:12.064648717 +0200 --- src/if_perlsfio.c 2019-12-04 21:15:31.751572384 +0100 *************** *** 10,23 **** * if_perlsfio.c: Special I/O functions for Perl interface. */ ! #define _memory_h /* avoid memset redeclaration */ ! #define IN_PERL_FILE /* don't include if_perl.pro from prot.h */ #include "vim.h" #if defined(USE_SFIO) || defined(PROTO) ! #ifndef USE_SFIO /* just generating prototypes */ # define Sfio_t int # define Sfdisc_t int #endif --- 10,23 ---- * if_perlsfio.c: Special I/O functions for Perl interface. */ ! #define _memory_h // avoid memset redeclaration ! #define IN_PERL_FILE // don't include if_perl.pro from prot.h #include "vim.h" #if defined(USE_SFIO) || defined(PROTO) ! #ifndef USE_SFIO // just generating prototypes # define Sfio_t int # define Sfdisc_t int #endif *************** *** 26,35 **** static int sfvimwrite( ! Sfio_t *f, /* stream involved */ ! char *buf, /* buffer to read from */ ! int n, /* number of bytes to write */ ! Sfdisc_t *disc) /* discipline */ { char_u *str; --- 26,35 ---- static int sfvimwrite( ! Sfio_t *f, // stream involved ! char *buf, // buffer to read from ! int n, // number of bytes to write ! Sfdisc_t *disc) // discipline { char_u *str; *************** *** 63,66 **** return disc; } ! #endif /* USE_SFIO */ --- 63,66 ---- return disc; } ! #endif // USE_SFIO *** ../vim-8.1.2386/src/if_python.c 2019-03-19 22:22:51.803819423 +0100 --- src/if_python.c 2019-12-04 21:17:47.543084925 +0100 *************** *** 21,36 **** #include ! /* uncomment this if used with the debug version of python. ! * Checked on 2.7.4. */ ! /* #define Py_DEBUG */ ! /* Note: most of time you can add -DPy_DEBUG to CFLAGS in place of uncommenting ! */ ! /* uncomment this if used with the debug version of python, but without its ! * allocator */ ! /* #define Py_DEBUG_NO_PYMALLOC */ ! /* Python.h defines _POSIX_THREADS itself (if needed) */ #ifdef _POSIX_THREADS # undef _POSIX_THREADS #endif --- 21,35 ---- #include ! // uncomment this if used with the debug version of python. ! // Checked on 2.7.4. ! // #define Py_DEBUG ! // Note: most of time you can add -DPy_DEBUG to CFLAGS in place of uncommenting ! // uncomment this if used with the debug version of python, but without its ! // allocator ! // #define Py_DEBUG_NO_PYMALLOC ! // Python.h defines _POSIX_THREADS itself (if needed) #ifdef _POSIX_THREADS # undef _POSIX_THREADS #endif *************** *** 53,65 **** # undef HAVE_PUTENV #endif #ifdef HAVE_STDARG_H ! # undef HAVE_STDARG_H /* Python's config.h defines it as well. */ #endif #ifdef _POSIX_C_SOURCE ! # undef _POSIX_C_SOURCE /* pyconfig.h defines it as well. */ #endif #ifdef _XOPEN_SOURCE ! # undef _XOPEN_SOURCE /* pyconfig.h defines it as well. */ #endif #define PY_SSIZE_T_CLEAN --- 52,64 ---- # undef HAVE_PUTENV #endif #ifdef HAVE_STDARG_H ! # undef HAVE_STDARG_H // Python's config.h defines it as well. #endif #ifdef _POSIX_C_SOURCE ! # undef _POSIX_C_SOURCE // pyconfig.h defines it as well. #endif #ifdef _XOPEN_SOURCE ! # undef _XOPEN_SOURCE // pyconfig.h defines it as well. #endif #define PY_SSIZE_T_CLEAN *************** *** 70,77 **** # undef PY_SSIZE_T_CLEAN #endif ! #undef main /* Defined in python.h - aargh */ ! #undef HAVE_FCNTL_H /* Clash with os_win32.h */ // Perhaps leave this out for Python 2.6, which supports bytes? #define PyBytes_FromString PyString_FromString --- 69,76 ---- # undef PY_SSIZE_T_CLEAN #endif ! #undef main // Defined in python.h - aargh ! #undef HAVE_FCNTL_H // Clash with os_win32.h // Perhaps leave this out for Python 2.6, which supports bytes? #define PyBytes_FromString PyString_FromString *************** *** 80,86 **** #define PyBytes_FromStringAndSize PyString_FromStringAndSize #if !defined(FEAT_PYTHON) && defined(PROTO) ! /* Use this to be able to generate prototypes without python being used. */ # define PyObject Py_ssize_t # define PyThreadState Py_ssize_t # define PyTypeObject Py_ssize_t --- 79,85 ---- #define PyBytes_FromStringAndSize PyString_FromStringAndSize #if !defined(FEAT_PYTHON) && defined(PROTO) ! // Use this to be able to generate prototypes without python being used. # define PyObject Py_ssize_t # define PyThreadState Py_ssize_t # define PyTypeObject Py_ssize_t *************** *** 112,130 **** #endif #define Py_bytes_fmt "s" ! /* Parser flags */ #define single_input 256 #define file_input 257 #define eval_input 258 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x020300F0 ! /* Python 2.3: can invoke ":python" recursively. */ # define PY_CAN_RECURSE #endif #if defined(DYNAMIC_PYTHON) || defined(PROTO) # ifndef DYNAMIC_PYTHON ! # define HINSTANCE long_u /* for generating prototypes */ # endif # ifndef MSWIN --- 111,129 ---- #endif #define Py_bytes_fmt "s" ! // Parser flags #define single_input 256 #define file_input 257 #define eval_input 258 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x020300F0 ! // Python 2.3: can invoke ":python" recursively. # define PY_CAN_RECURSE #endif #if defined(DYNAMIC_PYTHON) || defined(PROTO) # ifndef DYNAMIC_PYTHON ! # define HINSTANCE long_u // for generating prototypes # endif # ifndef MSWIN *************** *** 144,151 **** # define symbol_from_dll GetProcAddress # endif ! /* This makes if_python.c compile without warnings against Python 2.5 ! * on Win32 and Win64. */ # undef PyRun_SimpleString # undef PyRun_String # undef PyArg_Parse --- 143,150 ---- # define symbol_from_dll GetProcAddress # endif ! // This makes if_python.c compile without warnings against Python 2.5 ! // on Win32 and Win64. # undef PyRun_SimpleString # undef PyRun_String # undef PyArg_Parse *************** *** 456,464 **** static int* dll_Py_NoSiteFlag; # endif ! static HINSTANCE hinstPython = 0; /* Instance of python.dll */ ! /* Imported exception objects */ static PyObject *imp_PyExc_AttributeError; static PyObject *imp_PyExc_IndexError; static PyObject *imp_PyExc_KeyError; --- 455,463 ---- static int* dll_Py_NoSiteFlag; # endif ! static HINSTANCE hinstPython = 0; // Instance of python.dll ! // Imported exception objects static PyObject *imp_PyExc_AttributeError; static PyObject *imp_PyExc_IndexError; static PyObject *imp_PyExc_KeyError; *************** *** 681,689 **** (PYTHON_PROC*)&py_PyUnicode_AsEncodedString; # if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON3) ! /* Can't have Python and Python3 loaded at the same time. ! * It cause a crash, because RTLD_GLOBAL is needed for ! * standard C extension libraries of one or both python versions. */ if (python3_loaded()) { if (verbose) --- 680,688 ---- (PYTHON_PROC*)&py_PyUnicode_AsEncodedString; # if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON3) ! // Can't have Python and Python3 loaded at the same time. ! // It cause a crash, because RTLD_GLOBAL is needed for ! // standard C extension libraries of one or both python versions. if (python3_loaded()) { if (verbose) *************** *** 715,722 **** } } ! /* Load unicode functions separately as only the ucs2 or the ucs4 functions ! * will be present in the library. */ *ucs_as_encoded_string = symbol_from_dll(hinstPython, "PyUnicodeUCS2_AsEncodedString"); if (*ucs_as_encoded_string == NULL) --- 714,721 ---- } } ! // Load unicode functions separately as only the ucs2 or the ucs4 functions ! // will be present in the library. *ucs_as_encoded_string = symbol_from_dll(hinstPython, "PyUnicodeUCS2_AsEncodedString"); if (*ucs_as_encoded_string == NULL) *************** *** 775,781 **** Py_XINCREF(imp_PyExc_OverflowError); Py_XDECREF(exmod); } ! #endif /* DYNAMIC_PYTHON */ static int initialised = 0; #define PYINITIALISED initialised --- 774,780 ---- Py_XINCREF(imp_PyExc_OverflowError); Py_XDECREF(exmod); } ! #endif // DYNAMIC_PYTHON static int initialised = 0; #define PYINITIALISED initialised *************** *** 830,847 **** #include "if_py_both.h" ! /****************************************************** ! * Internal function prototypes. ! */ static int PythonMod_Init(void); ! /****************************************************** ! * 1. Python interpreter main program. ! */ ! #if PYTHON_API_VERSION < 1007 /* Python 1.4 */ typedef PyObject PyThreadState; #endif --- 829,844 ---- #include "if_py_both.h" ! /////////////////////////////////////////////////////// ! // Internal function prototypes. static int PythonMod_Init(void); ! /////////////////////////////////////////////////////// ! // 1. Python interpreter main program. ! #if PYTHON_API_VERSION < 1007 // Python 1.4 typedef PyObject PyThreadState; #endif *************** *** 875,881 **** { static int recurse = 0; ! /* If a crash occurs while doing this, don't try again. */ if (recurse != 0) return; --- 872,878 ---- { static int recurse = 0; ! // If a crash occurs while doing this, don't try again. if (recurse != 0) return; *************** *** 888,894 **** # ifdef PY_CAN_RECURSE PyGILState_Ensure(); # else ! Python_RestoreThread(); /* enter python */ # endif Py_Finalize(); } --- 885,891 ---- # ifdef PY_CAN_RECURSE PyGILState_Ensure(); # else ! Python_RestoreThread(); // enter python # endif Py_Finalize(); } *************** *** 899,905 **** # ifdef PY_CAN_RECURSE PyGILState_Ensure(); # else ! Python_RestoreThread(); /* enter python */ # endif Py_Finalize(); } --- 896,902 ---- # ifdef PY_CAN_RECURSE PyGILState_Ensure(); # else ! Python_RestoreThread(); // enter python # endif Py_Finalize(); } *************** *** 937,943 **** if (*p_pyhome != NUL) { ! /* The string must not change later, make a copy in static memory. */ py_home_buf = (char *)vim_strsave(p_pyhome); if (py_home_buf != NULL) Py_SetPythonHome(py_home_buf); --- 934,940 ---- if (*p_pyhome != NUL) { ! // The string must not change later, make a copy in static memory. py_home_buf = (char *)vim_strsave(p_pyhome); if (py_home_buf != NULL) Py_SetPythonHome(py_home_buf); *************** *** 950,964 **** init_structs(); #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 ! /* Disable implicit 'import site', because it may cause Vim to exit ! * when it can't be found. */ Py_NoSiteFlag++; #endif Py_Initialize(); #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 ! /* 'import site' explicitly. */ site = PyImport_ImportModule("site"); if (site == NULL) { --- 947,961 ---- init_structs(); #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 ! // Disable implicit 'import site', because it may cause Vim to exit ! // when it can't be found. Py_NoSiteFlag++; #endif Py_Initialize(); #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 ! // 'import site' explicitly. site = PyImport_ImportModule("site"); if (site == NULL) { *************** *** 968,977 **** Py_DECREF(site); #endif ! /* Initialise threads, and below save the state using ! * PyEval_SaveThread. Without the call to PyEval_SaveThread, thread ! * specific state (such as the system trace hook), will be lost ! * between invocations of Python code. */ PyEval_InitThreads(); #ifdef DYNAMIC_PYTHON get_exceptions(); --- 965,974 ---- Py_DECREF(site); #endif ! // Initialise threads, and below save the state using ! // PyEval_SaveThread. Without the call to PyEval_SaveThread, thread ! // specific state (such as the system trace hook), will be lost ! // between invocations of Python code. PyEval_InitThreads(); #ifdef DYNAMIC_PYTHON get_exceptions(); *************** *** 985,1003 **** globals = PyModule_GetDict(PyImport_AddModule("__main__")); ! /* Remove the element from sys.path that was added because of our ! * argv[0] value in PythonMod_Init(). Previously we used an empty ! * string, but depending on the OS we then get an empty entry or ! * the current directory in sys.path. */ PyRun_SimpleString("import sys; sys.path = filter(lambda x: x != '/must>not&exist', sys.path)"); ! /* lock is created and acquired in PyEval_InitThreads() and thread ! * state is created in Py_Initialize() ! * there _PyGILState_NoteThreadState() also sets gilcounter to 1 ! * (python must have threads enabled!) ! * so the following does both: unlock GIL and save thread state in TLS ! * without deleting thread state ! */ #ifndef PY_CAN_RECURSE saved_python_thread = #endif --- 982,999 ---- globals = PyModule_GetDict(PyImport_AddModule("__main__")); ! // Remove the element from sys.path that was added because of our ! // argv[0] value in PythonMod_Init(). Previously we used an empty ! // string, but depending on the OS we then get an empty entry or ! // the current directory in sys.path. PyRun_SimpleString("import sys; sys.path = filter(lambda x: x != '/must>not&exist', sys.path)"); ! // lock is created and acquired in PyEval_InitThreads() and thread ! // state is created in Py_Initialize() ! // there _PyGILState_NoteThreadState() also sets gilcounter to 1 ! // (python must have threads enabled!) ! // so the following does both: unlock GIL and save thread state in TLS ! // without deleting thread state #ifndef PY_CAN_RECURSE saved_python_thread = #endif *************** *** 1009,1019 **** return 0; fail: ! /* We call PythonIO_Flush() here to print any Python errors. ! * This is OK, as it is possible to call this function even ! * if PythonIO_Init_io() has not completed successfully (it will ! * not do anything in this case). ! */ PythonIO_Flush(); return -1; } --- 1005,1014 ---- return 0; fail: ! // We call PythonIO_Flush() here to print any Python errors. ! // This is OK, as it is possible to call this function even ! // if PythonIO_Init_io() has not completed successfully (it will ! // not do anything in this case). PythonIO_Flush(); return -1; } *************** *** 1050,1065 **** init_range(arg); ! Python_Release_Vim(); /* leave vim */ #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) ! /* Python only works properly when the LC_NUMERIC locale is "C". */ saved_locale = setlocale(LC_NUMERIC, NULL); if (saved_locale == NULL || STRCMP(saved_locale, "C") == 0) saved_locale = NULL; else { ! /* Need to make a copy, value may change when setting new locale. */ saved_locale = (char *) PY_STRSAVE(saved_locale); (void)setlocale(LC_NUMERIC, "C"); } --- 1045,1060 ---- init_range(arg); ! Python_Release_Vim(); // leave Vim #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) ! // Python only works properly when the LC_NUMERIC locale is "C". saved_locale = setlocale(LC_NUMERIC, NULL); if (saved_locale == NULL || STRCMP(saved_locale, "C") == 0) saved_locale = NULL; else { ! // Need to make a copy, value may change when setting new locale. saved_locale = (char *) PY_STRSAVE(saved_locale); (void)setlocale(LC_NUMERIC, "C"); } *************** *** 1068,1074 **** #ifdef PY_CAN_RECURSE pygilstate = PyGILState_Ensure(); #else ! Python_RestoreThread(); /* enter python */ #endif run((char *) cmd, arg --- 1063,1069 ---- #ifdef PY_CAN_RECURSE pygilstate = PyGILState_Ensure(); #else ! Python_RestoreThread(); // enter python #endif run((char *) cmd, arg *************** *** 1080,1086 **** #ifdef PY_CAN_RECURSE PyGILState_Release(pygilstate); #else ! Python_SaveThread(); /* leave python */ #endif #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) --- 1075,1081 ---- #ifdef PY_CAN_RECURSE PyGILState_Release(pygilstate); #else ! Python_SaveThread(); // leave python #endif #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) *************** *** 1091,1097 **** } #endif ! Python_Lock_Vim(); /* enter vim */ PythonIO_Flush(); theend: --- 1086,1092 ---- } #endif ! Python_Lock_Vim(); // enter vim PythonIO_Flush(); theend: *************** *** 1138,1154 **** if (p_pyx == 0) p_pyx = 2; ! /* Have to do it like this. PyRun_SimpleFile requires you to pass a ! * stdio file pointer, but Vim and the Python DLL are compiled with ! * different options under Windows, meaning that stdio pointers aren't ! * compatible between the two. Yuk. ! * ! * Put the string "execfile('file')" into buffer. But, we need to ! * escape any backslashes or single quotes in the file name, so that ! * Python won't mangle the file name. ! */ strcpy(buffer, "execfile('"); ! p = buffer + 10; /* size of "execfile('" */ while (*file && p < buffer + (BUFFER_SIZE - 3)) { --- 1133,1148 ---- if (p_pyx == 0) p_pyx = 2; ! // Have to do it like this. PyRun_SimpleFile requires you to pass a ! // stdio file pointer, but Vim and the Python DLL are compiled with ! // different options under Windows, meaning that stdio pointers aren't ! // compatible between the two. Yuk. ! // ! // Put the string "execfile('file')" into buffer. But, we need to ! // escape any backslashes or single quotes in the file name, so that ! // Python won't mangle the file name. strcpy(buffer, "execfile('"); ! p = buffer + 10; // size of "execfile('" while (*file && p < buffer + (BUFFER_SIZE - 3)) { *************** *** 1157,1172 **** *p++ = *file++; } ! /* If we didn't finish the file name, we hit a buffer overflow */ if (*file != '\0') return; ! /* Put in the terminating "')" and a null */ *p++ = '\''; *p++ = ')'; *p++ = '\0'; ! /* Execute the file */ DoPyCommand(buffer, (rangeinitializer) init_range_cmd, (runner) run_cmd, --- 1151,1166 ---- *p++ = *file++; } ! // If we didn't finish the file name, we hit a buffer overflow if (*file != '\0') return; ! // Put in the terminating "')" and a null *p++ = '\''; *p++ = ')'; *p++ = '\0'; ! // Execute the file DoPyCommand(buffer, (rangeinitializer) init_range_cmd, (runner) run_cmd, *************** *** 1185,1196 **** (void *)eap); } ! /****************************************************** ! * 2. Python output stream: writes output via [e]msg(). ! */ ! /* Implementation functions ! */ static PyObject * OutputGetattr(PyObject *self, char *name) --- 1179,1188 ---- (void *)eap); } ! /////////////////////////////////////////////////////// ! // 2. Python output stream: writes output via [e]msg(). ! // Implementation functions static PyObject * OutputGetattr(PyObject *self, char *name) *************** *** 1206,1258 **** return Py_FindMethod(OutputMethods, self, name); } ! /****************************************************** ! * 3. Implementation of the Vim module for Python ! */ ! /* Window type - Implementation functions ! * -------------------------------------- ! */ #define WindowType_Check(obj) ((obj)->ob_type == &WindowType) ! /* Buffer type - Implementation functions ! * -------------------------------------- ! */ #define BufferType_Check(obj) ((obj)->ob_type == &BufferType) static PyInt BufferAssItem(PyObject *, PyInt, PyObject *); static PyInt BufferAssSlice(PyObject *, PyInt, PyInt, PyObject *); ! /* Line range type - Implementation functions ! * -------------------------------------- ! */ #define RangeType_Check(obj) ((obj)->ob_type == &RangeType) static PyInt RangeAssItem(PyObject *, PyInt, PyObject *); static PyInt RangeAssSlice(PyObject *, PyInt, PyInt, PyObject *); ! /* Current objects type - Implementation functions ! * ----------------------------------------------- ! */ static PySequenceMethods BufferAsSeq = { ! (PyInquiry) BufferLength, /* sq_length, len(x) */ ! (binaryfunc) 0, /* BufferConcat, sq_concat, x+y */ ! (PyIntArgFunc) 0, /* BufferRepeat, sq_repeat, x*n */ ! (PyIntArgFunc) BufferItem, /* sq_item, x[i] */ ! (PyIntIntArgFunc) BufferSlice, /* sq_slice, x[i:j] */ ! (PyIntObjArgProc) BufferAssItem, /* sq_ass_item, x[i]=v */ ! (PyIntIntObjArgProc) BufferAssSlice, /* sq_ass_slice, x[i:j]=v */ (objobjproc) 0, (binaryfunc) 0, 0, }; ! /* Buffer object - Implementation ! */ static PyObject * BufferGetattr(PyObject *self, char *name) --- 1198,1244 ---- return Py_FindMethod(OutputMethods, self, name); } ! /////////////////////////////////////////////////////// ! // 3. Implementation of the Vim module for Python ! // Window type - Implementation functions ! // -------------------------------------- #define WindowType_Check(obj) ((obj)->ob_type == &WindowType) ! // Buffer type - Implementation functions ! // -------------------------------------- #define BufferType_Check(obj) ((obj)->ob_type == &BufferType) static PyInt BufferAssItem(PyObject *, PyInt, PyObject *); static PyInt BufferAssSlice(PyObject *, PyInt, PyInt, PyObject *); ! // Line range type - Implementation functions ! // -------------------------------------- #define RangeType_Check(obj) ((obj)->ob_type == &RangeType) static PyInt RangeAssItem(PyObject *, PyInt, PyObject *); static PyInt RangeAssSlice(PyObject *, PyInt, PyInt, PyObject *); ! // Current objects type - Implementation functions ! // ----------------------------------------------- static PySequenceMethods BufferAsSeq = { ! (PyInquiry) BufferLength, // sq_length, len(x) ! (binaryfunc) 0, // BufferConcat, sq_concat, x+y ! (PyIntArgFunc) 0, // BufferRepeat, sq_repeat, x*n ! (PyIntArgFunc) BufferItem, // sq_item, x[i] ! (PyIntIntArgFunc) BufferSlice, // sq_slice, x[i:j] ! (PyIntObjArgProc) BufferAssItem, // sq_ass_item, x[i]=v ! (PyIntIntObjArgProc) BufferAssSlice, // sq_ass_slice, x[i:j]=v (objobjproc) 0, (binaryfunc) 0, 0, }; ! // Buffer object - Implementation static PyObject * BufferGetattr(PyObject *self, char *name) *************** *** 1272,1278 **** return Py_FindMethod(BufferMethods, self, name); } ! /******************/ static PyInt BufferAssItem(PyObject *self, PyInt n, PyObject *val) --- 1258,1264 ---- return Py_FindMethod(BufferMethods, self, name); } ! ////////////////// static PyInt BufferAssItem(PyObject *self, PyInt n, PyObject *val) *************** *** 1287,1299 **** } static PySequenceMethods RangeAsSeq = { ! (PyInquiry) RangeLength, /* sq_length, len(x) */ ! (binaryfunc) 0, /* RangeConcat, */ /* sq_concat, x+y */ ! (PyIntArgFunc) 0, /* RangeRepeat, */ /* sq_repeat, x*n */ ! (PyIntArgFunc) RangeItem, /* sq_item, x[i] */ ! (PyIntIntArgFunc) RangeSlice, /* sq_slice, x[i:j] */ ! (PyIntObjArgProc) RangeAssItem, /* sq_ass_item, x[i]=v */ ! (PyIntIntObjArgProc) RangeAssSlice, /* sq_ass_slice, x[i:j]=v */ (objobjproc) 0, #if PY_MAJOR_VERSION >= 2 (binaryfunc) 0, --- 1273,1285 ---- } static PySequenceMethods RangeAsSeq = { ! (PyInquiry) RangeLength, // sq_length, len(x) ! (binaryfunc) 0, /* RangeConcat, */ // sq_concat, x+y ! (PyIntArgFunc) 0, /* RangeRepeat, */ // sq_repeat, x*n ! (PyIntArgFunc) RangeItem, // sq_item, x[i] ! (PyIntIntArgFunc) RangeSlice, // sq_slice, x[i:j] ! (PyIntObjArgProc) RangeAssItem, // sq_ass_item, x[i]=v ! (PyIntIntObjArgProc) RangeAssSlice, // sq_ass_slice, x[i:j]=v (objobjproc) 0, #if PY_MAJOR_VERSION >= 2 (binaryfunc) 0, *************** *** 1301,1308 **** #endif }; ! /* Line range object - Implementation ! */ static PyObject * RangeGetattr(PyObject *self, char *name) --- 1287,1293 ---- #endif }; ! // Line range object - Implementation static PyObject * RangeGetattr(PyObject *self, char *name) *************** *** 1317,1323 **** return Py_FindMethod(RangeMethods, self, name); } ! /****************/ static PyInt RangeAssItem(PyObject *self, PyInt n, PyObject *val) --- 1302,1308 ---- return Py_FindMethod(RangeMethods, self, name); } ! //////////////// static PyInt RangeAssItem(PyObject *self, PyInt n, PyObject *val) *************** *** 1337,1344 **** &((RangeObject *)(self))->end); } ! /* TabPage object - Implementation ! */ static PyObject * TabPageGetattr(PyObject *self, char *name) --- 1322,1328 ---- &((RangeObject *)(self))->end); } ! // TabPage object - Implementation static PyObject * TabPageGetattr(PyObject *self, char *name) *************** *** 1358,1365 **** return Py_FindMethod(TabPageMethods, self, name); } ! /* Window object - Implementation ! */ static PyObject * WindowGetattr(PyObject *self, char *name) --- 1342,1348 ---- return Py_FindMethod(TabPageMethods, self, name); } ! // Window object - Implementation static PyObject * WindowGetattr(PyObject *self, char *name) *************** *** 1379,1395 **** return Py_FindMethod(WindowMethods, self, name); } ! /* Tab page list object - Definitions ! */ static PySequenceMethods TabListAsSeq = { ! (PyInquiry) TabListLength, /* sq_length, len(x) */ ! (binaryfunc) 0, /* sq_concat, x+y */ ! (PyIntArgFunc) 0, /* sq_repeat, x*n */ ! (PyIntArgFunc) TabListItem, /* sq_item, x[i] */ ! (PyIntIntArgFunc) 0, /* sq_slice, x[i:j] */ ! (PyIntObjArgProc) 0, /* sq_ass_item, x[i]=v */ ! (PyIntIntObjArgProc) 0, /* sq_ass_slice, x[i:j]=v */ (objobjproc) 0, #if PY_MAJOR_VERSION >= 2 (binaryfunc) 0, --- 1362,1377 ---- return Py_FindMethod(WindowMethods, self, name); } ! // Tab page list object - Definitions static PySequenceMethods TabListAsSeq = { ! (PyInquiry) TabListLength, // sq_length, len(x) ! (binaryfunc) 0, // sq_concat, x+y ! (PyIntArgFunc) 0, // sq_repeat, x*n ! (PyIntArgFunc) TabListItem, // sq_item, x[i] ! (PyIntIntArgFunc) 0, // sq_slice, x[i:j] ! (PyIntObjArgProc) 0, // sq_ass_item, x[i]=v ! (PyIntIntObjArgProc) 0, // sq_ass_slice, x[i:j]=v (objobjproc) 0, #if PY_MAJOR_VERSION >= 2 (binaryfunc) 0, *************** *** 1397,1413 **** #endif }; ! /* Window list object - Definitions ! */ static PySequenceMethods WinListAsSeq = { ! (PyInquiry) WinListLength, /* sq_length, len(x) */ ! (binaryfunc) 0, /* sq_concat, x+y */ ! (PyIntArgFunc) 0, /* sq_repeat, x*n */ ! (PyIntArgFunc) WinListItem, /* sq_item, x[i] */ ! (PyIntIntArgFunc) 0, /* sq_slice, x[i:j] */ ! (PyIntObjArgProc) 0, /* sq_ass_item, x[i]=v */ ! (PyIntIntObjArgProc) 0, /* sq_ass_slice, x[i:j]=v */ (objobjproc) 0, #if PY_MAJOR_VERSION >= 2 (binaryfunc) 0, --- 1379,1394 ---- #endif }; ! // Window list object - Definitions static PySequenceMethods WinListAsSeq = { ! (PyInquiry) WinListLength, // sq_length, len(x) ! (binaryfunc) 0, // sq_concat, x+y ! (PyIntArgFunc) 0, // sq_repeat, x*n ! (PyIntArgFunc) WinListItem, // sq_item, x[i] ! (PyIntIntArgFunc) 0, // sq_slice, x[i:j] ! (PyIntObjArgProc) 0, // sq_ass_item, x[i]=v ! (PyIntIntObjArgProc) 0, // sq_ass_slice, x[i:j]=v (objobjproc) 0, #if PY_MAJOR_VERSION >= 2 (binaryfunc) 0, *************** *** 1415,1422 **** #endif }; ! /* External interface ! */ void python_buffer_free(buf_T *buf) --- 1396,1402 ---- #endif }; ! // External interface void python_buffer_free(buf_T *buf) *************** *** 1454,1466 **** static int PythonMod_Init(void) { ! /* The special value is removed from sys.path in Python_Init(). */ static char *(argv[2]) = {"/must>not&exist/foo", NULL}; if (init_types()) return -1; ! /* Set sys.argv[] to avoid a crash in warn(). */ PySys_SetArgv(1, argv); vim_module = Py_InitModule4("vim", VimMethods, (char *)NULL, --- 1434,1446 ---- static int PythonMod_Init(void) { ! // The special value is removed from sys.path in Python_Init(). static char *(argv[2]) = {"/must>not&exist/foo", NULL}; if (init_types()) return -1; ! // Set sys.argv[] to avoid a crash in warn(). PySys_SetArgv(1, argv); vim_module = Py_InitModule4("vim", VimMethods, (char *)NULL, *************** *** 1475,1489 **** return 0; } ! /************************************************************************* ! * 4. Utility functions for handling the interface between Vim and Python. ! */ ! /* Convert a Vim line into a Python string. ! * All internal newlines are replaced by null characters. ! * ! * On errors, the Python exception data is set, and NULL is returned. ! */ static PyObject * LineToString(const char *str) { --- 1455,1467 ---- return 0; } ! ////////////////////////////////////////////////////////////////////////// ! // 4. Utility functions for handling the interface between Vim and Python. ! // Convert a Vim line into a Python string. ! // All internal newlines are replaced by null characters. ! // ! // On errors, the Python exception data is set, and NULL is returned. static PyObject * LineToString(const char *str) { *************** *** 1491,1500 **** PyInt len = strlen(str); char *p; ! /* Allocate an Python string object, with uninitialised contents. We ! * must do it this way, so that we can modify the string in place ! * later. See the Python source, Objects/stringobject.c for details. ! */ result = PyString_FromStringAndSize(NULL, len); if (result == NULL) return NULL; --- 1469,1477 ---- PyInt len = strlen(str); char *p; ! // Allocate an Python string object, with uninitialised contents. We ! // must do it this way, so that we can modify the string in place ! // later. See the Python source, Objects/stringobject.c for details. result = PyString_FromStringAndSize(NULL, len); if (result == NULL) return NULL; *************** *** 1568,1575 **** } } ! /* Don't generate a prototype for the next function, it generates an error on ! * newer Python versions. */ #if PYTHON_API_VERSION < 1007 /* Python 1.4 */ && !defined(PROTO) char * --- 1545,1552 ---- } } ! // Don't generate a prototype for the next function, it generates an error on ! // newer Python versions. #if PYTHON_API_VERSION < 1007 /* Python 1.4 */ && !defined(PROTO) char * *************** *** 1577,1583 **** { return "vim"; } ! #endif /* Python 1.4 */ int set_ref_in_python(int copyID) --- 1554,1560 ---- { return "vim"; } ! #endif // Python 1.4 int set_ref_in_python(int copyID) *** ../vim-8.1.2386/src/if_python3.c 2019-10-23 21:37:21.467578691 +0200 --- src/if_python3.c 2019-12-04 21:19:39.891045415 +0100 *************** *** 22,34 **** * Adaptations to support both python3.x and python2.x */ ! /* uncomment this if used with the debug version of python */ ! /* #define Py_DEBUG */ ! /* Note: most of time you can add -DPy_DEBUG to CFLAGS in place of uncommenting ! */ ! /* uncomment this if used with the debug version of python, but without its ! * allocator */ ! /* #define Py_DEBUG_NO_PYMALLOC */ #include "vim.h" --- 22,33 ---- * Adaptations to support both python3.x and python2.x */ ! // uncomment this if used with the debug version of python ! // #define Py_DEBUG ! // Note: most of time you can add -DPy_DEBUG to CFLAGS in place of uncommenting ! // uncomment this if used with the debug version of python, but without its ! // allocator ! // #define Py_DEBUG_NO_PYMALLOC #include "vim.h" *************** *** 56,85 **** # undef HAVE_PUTENV #endif #ifdef HAVE_STDARG_H ! # undef HAVE_STDARG_H /* Python's config.h defines it as well. */ #endif ! #ifdef _POSIX_C_SOURCE /* defined in feature.h */ # undef _POSIX_C_SOURCE #endif #ifdef _XOPEN_SOURCE ! # undef _XOPEN_SOURCE /* pyconfig.h defines it as well. */ #endif #define PY_SSIZE_T_CLEAN #include ! #undef main /* Defined in python.h - aargh */ ! #undef HAVE_FCNTL_H /* Clash with os_win32.h */ ! /* The "surrogateescape" error handler is new in Python 3.1 */ #if PY_VERSION_HEX >= 0x030100f0 # define CODEC_ERROR_HANDLER "surrogateescape" #else # define CODEC_ERROR_HANDLER NULL #endif ! /* Python 3 does not support CObjects, always use Capsules */ #define PY_USE_CAPSULE #define PyInt Py_ssize_t --- 55,84 ---- # undef HAVE_PUTENV #endif #ifdef HAVE_STDARG_H ! # undef HAVE_STDARG_H // Python's config.h defines it as well. #endif ! #ifdef _POSIX_C_SOURCE // defined in feature.h # undef _POSIX_C_SOURCE #endif #ifdef _XOPEN_SOURCE ! # undef _XOPEN_SOURCE // pyconfig.h defines it as well. #endif #define PY_SSIZE_T_CLEAN #include ! #undef main // Defined in python.h - aargh ! #undef HAVE_FCNTL_H // Clash with os_win32.h ! // The "surrogateescape" error handler is new in Python 3.1 #if PY_VERSION_HEX >= 0x030100f0 # define CODEC_ERROR_HANDLER "surrogateescape" #else # define CODEC_ERROR_HANDLER NULL #endif ! // Python 3 does not support CObjects, always use Capsules #define PY_USE_CAPSULE #define PyInt Py_ssize_t *************** *** 432,440 **** static void(*py3_PyObject_GC_UnTrack)(void *); static int (*py3_PyType_IsSubtype)(PyTypeObject *, PyTypeObject *); ! static HINSTANCE hinstPy3 = 0; /* Instance of python.dll */ ! /* Imported exception objects */ static PyObject *p3imp_PyExc_AttributeError; static PyObject *p3imp_PyExc_IndexError; static PyObject *p3imp_PyExc_KeyError; --- 431,439 ---- static void(*py3_PyObject_GC_UnTrack)(void *); static int (*py3_PyType_IsSubtype)(PyTypeObject *, PyTypeObject *); ! static HINSTANCE hinstPy3 = 0; // Instance of python.dll ! // Imported exception objects static PyObject *p3imp_PyExc_AttributeError; static PyObject *p3imp_PyExc_IndexError; static PyObject *p3imp_PyExc_KeyError; *************** *** 664,672 **** (PYTHON_PROC *)&py3_PyUnicode_AsEncodedString; # if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON) ! /* Can't have Python and Python3 loaded at the same time. ! * It cause a crash, because RTLD_GLOBAL is needed for ! * standard C extension libraries of one or both python versions. */ if (python_loaded()) { if (verbose) --- 663,671 ---- (PYTHON_PROC *)&py3_PyUnicode_AsEncodedString; # if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON) ! // Can't have Python and Python3 loaded at the same time. ! // It cause a crash, because RTLD_GLOBAL is needed for ! // standard C extension libraries of one or both python versions. if (python_loaded()) { if (verbose) *************** *** 699,706 **** } } ! /* Load unicode functions separately as only the ucs2 or the ucs4 functions ! * will be present in the library. */ # if PY_VERSION_HEX >= 0x030300f0 *ucs_from_string = symbol_from_dll(hinstPy3, "PyUnicode_FromString"); *ucs_decode = symbol_from_dll(hinstPy3, "PyUnicode_Decode"); --- 698,705 ---- } } ! // Load unicode functions separately as only the ucs2 or the ucs4 functions ! // will be present in the library. # if PY_VERSION_HEX >= 0x030300f0 *ucs_from_string = symbol_from_dll(hinstPy3, "PyUnicode_FromString"); *ucs_decode = symbol_from_dll(hinstPy3, "PyUnicode_Decode"); *************** *** 746,752 **** return py3_runtime_link_init((char *)p_py3dll, verbose) == OK; } ! /* Load the standard Python exceptions - don't import the symbols from the * DLL, as this can cause errors (importing data symbols is not reliable). */ static void --- 745,752 ---- return py3_runtime_link_init((char *)p_py3dll, verbose) == OK; } ! /* ! * Load the standard Python exceptions - don't import the symbols from the * DLL, as this can cause errors (importing data symbols is not reliable). */ static void *************** *** 776,782 **** Py_XINCREF(p3imp_PyExc_OverflowError); Py_XDECREF(exmod); } ! #endif /* DYNAMIC_PYTHON3 */ static int py3initialised = 0; #define PYINITIALISED py3initialised --- 776,782 ---- Py_XINCREF(p3imp_PyExc_OverflowError); Py_XDECREF(exmod); } ! #endif // DYNAMIC_PYTHON3 static int py3initialised = 0; #define PYINITIALISED py3initialised *************** *** 843,864 **** #define PY3OBJ_DELETED(obj) (obj->ob_base.ob_refcnt<=0) ! /****************************************************** ! * Internal function prototypes. ! */ static PyObject *Py3Init_vim(void); ! /****************************************************** ! * 1. Python interpreter main program. ! */ void python3_end(void) { static int recurse = 0; ! /* If a crash occurs while doing this, don't try again. */ if (recurse != 0) return; --- 843,862 ---- #define PY3OBJ_DELETED(obj) (obj->ob_base.ob_refcnt<=0) ! /////////////////////////////////////////////////////// ! // Internal function prototypes. static PyObject *Py3Init_vim(void); ! /////////////////////////////////////////////////////// ! // 1. Python interpreter main program. void python3_end(void) { static int recurse = 0; ! // If a crash occurs while doing this, don't try again. if (recurse != 0) return; *************** *** 870,876 **** #endif if (Py_IsInitialized()) { ! /* acquire lock before finalizing */ PyGILState_Ensure(); Py_Finalize(); --- 868,874 ---- #endif if (Py_IsInitialized()) { ! // acquire lock before finalizing PyGILState_Ensure(); Py_Finalize(); *************** *** 912,918 **** { size_t len = mbstowcs(NULL, (char *)p_py3home, 0) + 1; ! /* The string must not change later, make a copy in static memory. */ py_home_buf = ALLOC_MULT(wchar_t, len); if (py_home_buf != NULL && mbstowcs( py_home_buf, (char *)p_py3home, len) != (size_t)-1) --- 910,916 ---- { size_t len = mbstowcs(NULL, (char *)p_py3home, 0) + 1; ! // The string must not change later, make a copy in static memory. py_home_buf = ALLOC_MULT(wchar_t, len); if (py_home_buf != NULL && mbstowcs( py_home_buf, (char *)p_py3home, len) != (size_t)-1) *************** *** 927,936 **** Py_Initialize(); ! /* Initialise threads, and below save the state using ! * PyEval_SaveThread. Without the call to PyEval_SaveThread, thread ! * specific state (such as the system trace hook), will be lost ! * between invocations of Python code. */ PyEval_InitThreads(); #ifdef DYNAMIC_PYTHON3 get_py3_exceptions(); --- 925,934 ---- Py_Initialize(); ! // Initialise threads, and below save the state using ! // PyEval_SaveThread. Without the call to PyEval_SaveThread, thread ! // specific state (such as the system trace hook), will be lost ! // between invocations of Python code. PyEval_InitThreads(); #ifdef DYNAMIC_PYTHON3 get_py3_exceptions(); *************** *** 941,962 **** globals = PyModule_GetDict(PyImport_AddModule("__main__")); ! /* Remove the element from sys.path that was added because of our ! * argv[0] value in Py3Init_vim(). Previously we used an empty ! * string, but depending on the OS we then get an empty entry or ! * the current directory in sys.path. ! * Only after vim has been imported, the element does exist in ! * sys.path. ! */ PyRun_SimpleString("import vim; import sys; sys.path = list(filter(lambda x: not x.endswith('must>not&exist'), sys.path))"); ! /* lock is created and acquired in PyEval_InitThreads() and thread ! * state is created in Py_Initialize() ! * there _PyGILState_NoteThreadState() also sets gilcounter to 1 ! * (python must have threads enabled!) ! * so the following does both: unlock GIL and save thread state in TLS ! * without deleting thread state ! */ PyEval_SaveThread(); py3initialised = 1; --- 939,958 ---- globals = PyModule_GetDict(PyImport_AddModule("__main__")); ! // Remove the element from sys.path that was added because of our ! // argv[0] value in Py3Init_vim(). Previously we used an empty ! // string, but depending on the OS we then get an empty entry or ! // the current directory in sys.path. ! // Only after vim has been imported, the element does exist in ! // sys.path. PyRun_SimpleString("import vim; import sys; sys.path = list(filter(lambda x: not x.endswith('must>not&exist'), sys.path))"); ! // lock is created and acquired in PyEval_InitThreads() and thread ! // state is created in Py_Initialize() ! // there _PyGILState_NoteThreadState() also sets gilcounter to 1 ! // (python must have threads enabled!) ! // so the following does both: unlock GIL and save thread state in TLS ! // without deleting thread state PyEval_SaveThread(); py3initialised = 1; *************** *** 965,975 **** return 0; fail: ! /* We call PythonIO_Flush() here to print any Python errors. ! * This is OK, as it is possible to call this function even ! * if PythonIO_Init_io() has not completed successfully (it will ! * not do anything in this case). ! */ PythonIO_Flush(); return -1; } --- 961,970 ---- return 0; fail: ! // We call PythonIO_Flush() here to print any Python errors. ! // This is OK, as it is possible to call this function even ! // if PythonIO_Init_io() has not completed successfully (it will ! // not do anything in this case). PythonIO_Flush(); return -1; } *************** *** 995,1010 **** init_range(arg); ! Python_Release_Vim(); /* leave vim */ #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) ! /* Python only works properly when the LC_NUMERIC locale is "C". */ saved_locale = setlocale(LC_NUMERIC, NULL); if (saved_locale == NULL || STRCMP(saved_locale, "C") == 0) saved_locale = NULL; else { ! /* Need to make a copy, value may change when setting new locale. */ saved_locale = (char *)vim_strsave((char_u *)saved_locale); (void)setlocale(LC_NUMERIC, "C"); } --- 990,1005 ---- init_range(arg); ! Python_Release_Vim(); // leave Vim #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) ! // Python only works properly when the LC_NUMERIC locale is "C". saved_locale = setlocale(LC_NUMERIC, NULL); if (saved_locale == NULL || STRCMP(saved_locale, "C") == 0) saved_locale = NULL; else { ! // Need to make a copy, value may change when setting new locale. saved_locale = (char *)vim_strsave((char_u *)saved_locale); (void)setlocale(LC_NUMERIC, "C"); } *************** *** 1012,1019 **** pygilstate = PyGILState_Ensure(); ! /* PyRun_SimpleString expects a UTF-8 string. Wrong encoding may cause ! * SyntaxError (unicode error). */ cmdstr = PyUnicode_Decode(cmd, strlen(cmd), (char *)ENC_OPT, CODEC_ERROR_HANDLER); cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", CODEC_ERROR_HANDLER); --- 1007,1014 ---- pygilstate = PyGILState_Ensure(); ! // PyRun_SimpleString expects a UTF-8 string. Wrong encoding may cause ! // SyntaxError (unicode error). cmdstr = PyUnicode_Decode(cmd, strlen(cmd), (char *)ENC_OPT, CODEC_ERROR_HANDLER); cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", CODEC_ERROR_HANDLER); *************** *** 1032,1042 **** } #endif ! Python_Lock_Vim(); /* enter vim */ PythonIO_Flush(); theend: ! return; /* keeps lint happy */ } /* --- 1027,1037 ---- } #endif ! Python_Lock_Vim(); // enter Vim PythonIO_Flush(); theend: ! return; // keeps lint happy } /* *************** *** 1077,1098 **** if (p_pyx == 0) p_pyx = 3; ! /* Have to do it like this. PyRun_SimpleFile requires you to pass a ! * stdio file pointer, but Vim and the Python DLL are compiled with ! * different options under Windows, meaning that stdio pointers aren't ! * compatible between the two. Yuk. ! * ! * construct: exec(compile(open('a_filename', 'rb').read(), 'a_filename', 'exec')) ! * ! * Using bytes so that Python can detect the source encoding as it normally ! * does. The doc does not say "compile" accept bytes, though. ! * ! * We need to escape any backslashes or single quotes in the file name, so that ! * Python won't mangle the file name. ! */ strcpy(buffer, "exec(compile(open('"); ! p = buffer + 19; /* size of "exec(compile(open('" */ for (i=0; i<2; ++i) { --- 1072,1092 ---- if (p_pyx == 0) p_pyx = 3; ! // Have to do it like this. PyRun_SimpleFile requires you to pass a ! // stdio file pointer, but Vim and the Python DLL are compiled with ! // different options under Windows, meaning that stdio pointers aren't ! // compatible between the two. Yuk. ! // ! // construct: exec(compile(open('a_filename', 'rb').read(), 'a_filename', 'exec')) ! // ! // Using bytes so that Python can detect the source encoding as it normally ! // does. The doc does not say "compile" accept bytes, though. ! // ! // We need to escape any backslashes or single quotes in the file name, so that ! // Python won't mangle the file name. strcpy(buffer, "exec(compile(open('"); ! p = buffer + 19; // size of "exec(compile(open('" for (i=0; i<2; ++i) { *************** *** 1103,1109 **** *p++ = '\\'; *p++ = *file++; } ! /* If we didn't finish the file name, we hit a buffer overflow */ if (*file != '\0') return; if (i==0) --- 1097,1103 ---- *p++ = '\\'; *p++ = *file++; } ! // If we didn't finish the file name, we hit a buffer overflow if (*file != '\0') return; if (i==0) *************** *** 1119,1125 **** } ! /* Execute the file */ DoPyCommand(buffer, (rangeinitializer) init_range_cmd, (runner) run_cmd, --- 1113,1119 ---- } ! // Execute the file DoPyCommand(buffer, (rangeinitializer) init_range_cmd, (runner) run_cmd, *************** *** 1138,1149 **** (void *)eap); } ! /****************************************************** ! * 2. Python output stream: writes output via [e]msg(). ! */ ! /* Implementation functions ! */ static PyObject * OutputGetattro(PyObject *self, PyObject *nameobj) --- 1132,1141 ---- (void *)eap); } ! /////////////////////////////////////////////////////// ! // 2. Python output stream: writes output via [e]msg(). ! // Implementation functions static PyObject * OutputGetattro(PyObject *self, PyObject *nameobj) *************** *** 1168,1195 **** return OutputSetattr((OutputObject *)(self), name, val); } ! /****************************************************** ! * 3. Implementation of the Vim module for Python ! */ ! /* Window type - Implementation functions ! * -------------------------------------- ! */ #define WindowType_Check(obj) ((obj)->ob_base.ob_type == &WindowType) ! /* Buffer type - Implementation functions ! * -------------------------------------- ! */ #define BufferType_Check(obj) ((obj)->ob_base.ob_type == &BufferType) static PyObject* BufferSubscript(PyObject *self, PyObject *idx); static Py_ssize_t BufferAsSubscript(PyObject *self, PyObject *idx, PyObject *val); ! /* Line range type - Implementation functions ! * -------------------------------------- ! */ #define RangeType_Check(obj) ((obj)->ob_base.ob_type == &RangeType) --- 1160,1183 ---- return OutputSetattr((OutputObject *)(self), name, val); } ! /////////////////////////////////////////////////////// ! // 3. Implementation of the Vim module for Python ! // Window type - Implementation functions ! // -------------------------------------- #define WindowType_Check(obj) ((obj)->ob_base.ob_type == &WindowType) ! // Buffer type - Implementation functions ! // -------------------------------------- #define BufferType_Check(obj) ((obj)->ob_base.ob_type == &BufferType) static PyObject* BufferSubscript(PyObject *self, PyObject *idx); static Py_ssize_t BufferAsSubscript(PyObject *self, PyObject *idx, PyObject *val); ! // Line range type - Implementation functions ! // -------------------------------------- #define RangeType_Check(obj) ((obj)->ob_base.ob_type == &RangeType) *************** *** 1197,1217 **** static Py_ssize_t RangeAsItem(PyObject *, Py_ssize_t, PyObject *); static Py_ssize_t RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val); ! /* Current objects type - Implementation functions ! * ----------------------------------------------- ! */ static PySequenceMethods BufferAsSeq = { ! (lenfunc) BufferLength, /* sq_length, len(x) */ ! (binaryfunc) 0, /* sq_concat, x+y */ ! (ssizeargfunc) 0, /* sq_repeat, x*n */ ! (ssizeargfunc) BufferItem, /* sq_item, x[i] */ ! 0, /* was_sq_slice, x[i:j] */ ! 0, /* sq_ass_item, x[i]=v */ ! 0, /* sq_ass_slice, x[i:j]=v */ ! 0, /* sq_contains */ ! 0, /* sq_inplace_concat */ ! 0, /* sq_inplace_repeat */ }; static PyMappingMethods BufferAsMapping = { --- 1185,1204 ---- static Py_ssize_t RangeAsItem(PyObject *, Py_ssize_t, PyObject *); static Py_ssize_t RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val); ! // Current objects type - Implementation functions ! // ----------------------------------------------- static PySequenceMethods BufferAsSeq = { ! (lenfunc) BufferLength, // sq_length, len(x) ! (binaryfunc) 0, // sq_concat, x+y ! (ssizeargfunc) 0, // sq_repeat, x*n ! (ssizeargfunc) BufferItem, // sq_item, x[i] ! 0, // was_sq_slice, x[i:j] ! 0, // sq_ass_item, x[i]=v ! 0, // sq_ass_slice, x[i:j]=v ! 0, // sq_contains ! 0, // sq_inplace_concat ! 0, // sq_inplace_repeat }; static PyMappingMethods BufferAsMapping = { *************** *** 1221,1228 **** }; ! /* Buffer object ! */ static PyObject * BufferGetattro(PyObject *self, PyObject *nameobj) --- 1208,1214 ---- }; ! // Buffer object static PyObject * BufferGetattro(PyObject *self, PyObject *nameobj) *************** *** 1252,1258 **** return BufferSetattr((BufferObject *)(self), name, val); } ! /******************/ static PyObject * BufferSubscript(PyObject *self, PyObject* idx) --- 1238,1244 ---- return BufferSetattr((BufferObject *)(self), name, val); } ! ////////////////// static PyObject * BufferSubscript(PyObject *self, PyObject* idx) *************** *** 1315,1330 **** } static PySequenceMethods RangeAsSeq = { ! (lenfunc) RangeLength, /* sq_length, len(x) */ ! (binaryfunc) 0, /* RangeConcat, sq_concat, x+y */ ! (ssizeargfunc) 0, /* RangeRepeat, sq_repeat, x*n */ ! (ssizeargfunc) RangeItem, /* sq_item, x[i] */ ! 0, /* was_sq_slice, x[i:j] */ ! (ssizeobjargproc) RangeAsItem, /* sq_as_item, x[i]=v */ ! 0, /* sq_ass_slice, x[i:j]=v */ ! 0, /* sq_contains */ ! 0, /* sq_inplace_concat */ ! 0, /* sq_inplace_repeat */ }; static PyMappingMethods RangeAsMapping = { --- 1301,1316 ---- } static PySequenceMethods RangeAsSeq = { ! (lenfunc) RangeLength, // sq_length, len(x) ! (binaryfunc) 0, // RangeConcat, sq_concat, x+y ! (ssizeargfunc) 0, // RangeRepeat, sq_repeat, x*n ! (ssizeargfunc) RangeItem, // sq_item, x[i] ! 0, // was_sq_slice, x[i:j] ! (ssizeobjargproc) RangeAsItem, // sq_as_item, x[i]=v ! 0, // sq_ass_slice, x[i:j]=v ! 0, // sq_contains ! 0, // sq_inplace_concat ! 0, // sq_inplace_repeat }; static PyMappingMethods RangeAsMapping = { *************** *** 1333,1340 **** /* mp_ass_subscript */ (objobjargproc)RangeAsSubscript, }; ! /* Line range object - Implementation ! */ static PyObject * RangeGetattro(PyObject *self, PyObject *nameobj) --- 1319,1325 ---- /* mp_ass_subscript */ (objobjargproc)RangeAsSubscript, }; ! // Line range object - Implementation static PyObject * RangeGetattro(PyObject *self, PyObject *nameobj) *************** *** 1349,1355 **** return PyObject_GenericGetAttr(self, nameobj); } ! /****************/ static Py_ssize_t RangeAsItem(PyObject *self, Py_ssize_t n, PyObject *val) --- 1334,1340 ---- return PyObject_GenericGetAttr(self, nameobj); } ! //////////////// static Py_ssize_t RangeAsItem(PyObject *self, Py_ssize_t n, PyObject *val) *************** *** 1420,1427 **** } } ! /* TabPage object - Implementation ! */ static PyObject * TabPageGetattro(PyObject *self, PyObject *nameobj) --- 1405,1411 ---- } } ! // TabPage object - Implementation static PyObject * TabPageGetattro(PyObject *self, PyObject *nameobj) *************** *** 1443,1450 **** return PyObject_GenericGetAttr(self, nameobj); } ! /* Window object - Implementation ! */ static PyObject * WindowGetattro(PyObject *self, PyObject *nameobj) --- 1427,1433 ---- return PyObject_GenericGetAttr(self, nameobj); } ! // Window object - Implementation static PyObject * WindowGetattro(PyObject *self, PyObject *nameobj) *************** *** 1474,1512 **** return WindowSetattr((WindowObject *)(self), name, val); } ! /* Tab page list object - Definitions ! */ static PySequenceMethods TabListAsSeq = { ! (lenfunc) TabListLength, /* sq_length, len(x) */ ! (binaryfunc) 0, /* sq_concat, x+y */ ! (ssizeargfunc) 0, /* sq_repeat, x*n */ ! (ssizeargfunc) TabListItem, /* sq_item, x[i] */ ! 0, /* sq_slice, x[i:j] */ ! (ssizeobjargproc)0, /* sq_as_item, x[i]=v */ ! 0, /* sq_ass_slice, x[i:j]=v */ ! 0, /* sq_contains */ ! 0, /* sq_inplace_concat */ ! 0, /* sq_inplace_repeat */ }; ! /* Window list object - Definitions ! */ static PySequenceMethods WinListAsSeq = { ! (lenfunc) WinListLength, /* sq_length, len(x) */ ! (binaryfunc) 0, /* sq_concat, x+y */ ! (ssizeargfunc) 0, /* sq_repeat, x*n */ ! (ssizeargfunc) WinListItem, /* sq_item, x[i] */ ! 0, /* sq_slice, x[i:j] */ ! (ssizeobjargproc)0, /* sq_as_item, x[i]=v */ ! 0, /* sq_ass_slice, x[i:j]=v */ ! 0, /* sq_contains */ ! 0, /* sq_inplace_concat */ ! 0, /* sq_inplace_repeat */ }; ! /* Current items object - Implementation */ static PyObject * CurrentGetattro(PyObject *self, PyObject *nameobj) --- 1457,1494 ---- return WindowSetattr((WindowObject *)(self), name, val); } ! // Tab page list object - Definitions static PySequenceMethods TabListAsSeq = { ! (lenfunc) TabListLength, // sq_length, len(x) ! (binaryfunc) 0, // sq_concat, x+y ! (ssizeargfunc) 0, // sq_repeat, x*n ! (ssizeargfunc) TabListItem, // sq_item, x[i] ! 0, // sq_slice, x[i:j] ! (ssizeobjargproc)0, // sq_as_item, x[i]=v ! 0, // sq_ass_slice, x[i:j]=v ! 0, // sq_contains ! 0, // sq_inplace_concat ! 0, // sq_inplace_repeat }; ! // Window list object - Definitions static PySequenceMethods WinListAsSeq = { ! (lenfunc) WinListLength, // sq_length, len(x) ! (binaryfunc) 0, // sq_concat, x+y ! (ssizeargfunc) 0, // sq_repeat, x*n ! (ssizeargfunc) WinListItem, // sq_item, x[i] ! 0, // sq_slice, x[i:j] ! (ssizeobjargproc)0, // sq_as_item, x[i]=v ! 0, // sq_ass_slice, x[i:j]=v ! 0, // sq_contains ! 0, // sq_inplace_concat ! 0, // sq_inplace_repeat }; ! /* ! * Current items object - Implementation */ static PyObject * CurrentGetattro(PyObject *self, PyObject *nameobj) *************** *** 1525,1532 **** return CurrentSetattr(self, name, value); } ! /* Dictionary object - Definitions ! */ static PyObject * DictionaryGetattro(PyObject *self, PyObject *nameobj) --- 1507,1513 ---- return CurrentSetattr(self, name, value); } ! // Dictionary object - Definitions static PyObject * DictionaryGetattro(PyObject *self, PyObject *nameobj) *************** *** 1550,1557 **** return DictionarySetattr((DictionaryObject *)(self), name, val); } ! /* List object - Definitions ! */ static PyObject * ListGetattro(PyObject *self, PyObject *nameobj) --- 1531,1537 ---- return DictionarySetattr((DictionaryObject *)(self), name, val); } ! // List object - Definitions static PyObject * ListGetattro(PyObject *self, PyObject *nameobj) *************** *** 1571,1578 **** return ListSetattr((ListObject *)(self), name, val); } ! /* Function object - Definitions ! */ static PyObject * FunctionGetattro(PyObject *self, PyObject *nameobj) --- 1551,1557 ---- return ListSetattr((ListObject *)(self), name, val); } ! // Function object - Definitions static PyObject * FunctionGetattro(PyObject *self, PyObject *nameobj) *************** *** 1589,1596 **** return PyObject_GenericGetAttr(self, nameobj); } ! /* External interface ! */ void python3_buffer_free(buf_T *buf) --- 1568,1574 ---- return PyObject_GenericGetAttr(self, nameobj); } ! // External interface void python3_buffer_free(buf_T *buf) *************** *** 1628,1640 **** static PyObject * Py3Init_vim(void) { ! /* The special value is removed from sys.path in Python3_Init(). */ static wchar_t *(argv[2]) = {L"/must>not&exist/foo", NULL}; if (init_types()) return NULL; ! /* Set sys.argv[] to avoid a crash in warn(). */ PySys_SetArgv(1, argv); if ((vim_module = PyModule_Create(&vimmodule)) == NULL) --- 1606,1618 ---- static PyObject * Py3Init_vim(void) { ! // The special value is removed from sys.path in Python3_Init(). static wchar_t *(argv[2]) = {L"/must>not&exist/foo", NULL}; if (init_types()) return NULL; ! // Set sys.argv[] to avoid a crash in warn(). PySys_SetArgv(1, argv); if ((vim_module = PyModule_Create(&vimmodule)) == NULL) *************** *** 1649,1659 **** return vim_module; } ! /************************************************************************* ! * 4. Utility functions for handling the interface between Vim and Python. ! */ ! /* Convert a Vim line into a Python string. * All internal newlines are replaced by null characters. * * On errors, the Python exception data is set, and NULL is returned. --- 1627,1637 ---- return vim_module; } ! ////////////////////////////////////////////////////////////////////////// ! // 4. Utility functions for handling the interface between Vim and Python. ! /* ! * Convert a Vim line into a Python string. * All internal newlines are replaced by null characters. * * On errors, the Python exception data is set, and NULL is returned. *** ../vim-8.1.2386/src/if_ruby.c 2019-04-14 19:42:09.411453809 +0200 --- src/if_ruby.c 2019-12-04 21:20:37.918998272 +0100 *************** *** 24,30 **** # define NT # endif # ifndef DYNAMIC_RUBY ! # define IMPORT /* For static dll usage __declspec(dllimport) */ # define RUBYEXTERN __declspec(dllimport) # endif #endif --- 24,30 ---- # define NT # endif # ifndef DYNAMIC_RUBY ! # define IMPORT // For static dll usage __declspec(dllimport) # define RUBYEXTERN __declspec(dllimport) # endif #endif *************** *** 87,109 **** #endif #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19 ! /* Ruby 1.9 defines a number of static functions which use rb_num2long and ! * rb_int2big */ # define rb_num2long rb_num2long_stub # define rb_int2big rb_int2big_stub #endif #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19 \ && VIM_SIZEOF_INT < VIM_SIZEOF_LONG ! /* Ruby 1.9 defines a number of static functions which use rb_fix2int and ! * rb_num2int if VIM_SIZEOF_INT < VIM_SIZEOF_LONG (64bit) */ # define rb_fix2int rb_fix2int_stub # define rb_num2int rb_num2int_stub #endif #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER == 21 ! /* Ruby 2.1 adds new GC called RGenGC and RARRAY_PTR uses ! * rb_gc_writebarrier_unprotect_promoted if USE_RGENGC */ # define rb_gc_writebarrier_unprotect_promoted rb_gc_writebarrier_unprotect_promoted_stub #endif #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 22 --- 87,109 ---- #endif #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19 ! // Ruby 1.9 defines a number of static functions which use rb_num2long and ! // rb_int2big # define rb_num2long rb_num2long_stub # define rb_int2big rb_int2big_stub #endif #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19 \ && VIM_SIZEOF_INT < VIM_SIZEOF_LONG ! // Ruby 1.9 defines a number of static functions which use rb_fix2int and ! // rb_num2int if VIM_SIZEOF_INT < VIM_SIZEOF_LONG (64bit) # define rb_fix2int rb_fix2int_stub # define rb_num2int rb_num2int_stub #endif #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER == 21 ! // Ruby 2.1 adds new GC called RGenGC and RARRAY_PTR uses ! // rb_gc_writebarrier_unprotect_promoted if USE_RGENGC # define rb_gc_writebarrier_unprotect_promoted rb_gc_writebarrier_unprotect_promoted_stub #endif #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 22 *************** *** 126,132 **** #undef EXTERN #undef _ ! /* T_DATA defined both by Ruby and Mac header files, hack around it... */ #if defined(MACOS_X) # define __OPENTRANSPORT__ # define __OPENTRANSPORTPROTOCOL__ --- 126,132 ---- #undef EXTERN #undef _ ! // T_DATA defined both by Ruby and Mac header files, hack around it... #if defined(MACOS_X) # define __OPENTRANSPORT__ # define __OPENTRANSPORTPROTOCOL__ *************** *** 189,195 **** #endif #if defined(PROTO) && !defined(FEAT_RUBY) ! /* Define these to be able to generate the function prototypes. */ # define VALUE int # define RUBY_DATA_FUNC int #endif --- 189,195 ---- #endif #if defined(PROTO) && !defined(FEAT_RUBY) ! // Define these to be able to generate the function prototypes. # define VALUE int # define RUBY_DATA_FUNC int #endif *************** *** 218,224 **** #if defined(DYNAMIC_RUBY) || defined(PROTO) # if defined(PROTO) && !defined(HINSTANCE) ! # define HINSTANCE int /* for generating prototypes */ # endif /* --- 218,224 ---- #if defined(DYNAMIC_RUBY) || defined(PROTO) # if defined(PROTO) && !defined(HINSTANCE) ! # define HINSTANCE int // for generating prototypes # endif /* *************** *** 273,279 **** # undef rb_intern # define rb_intern dll_rb_intern ! # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */ # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER <= 18 # define rb_fix2int dll_rb_fix2int # define rb_num2int dll_rb_num2int --- 273,279 ---- # undef rb_intern # define rb_intern dll_rb_intern ! # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG // 64 bits only # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER <= 18 # define rb_fix2int dll_rb_fix2int # define rb_num2int dll_rb_num2int *************** *** 300,309 **** # undef rb_str_new # define rb_str_new dll_rb_str_new # ifdef rb_str_new2 ! /* Ruby may #define rb_str_new2 to use rb_str_new_cstr. */ # define need_rb_str_new_cstr 1 ! /* Ruby's headers #define rb_str_new_cstr to make use of GCC's ! * __builtin_constant_p extension. */ # undef rb_str_new_cstr # define rb_str_new_cstr dll_rb_str_new_cstr # else --- 300,309 ---- # undef rb_str_new # define rb_str_new dll_rb_str_new # ifdef rb_str_new2 ! // Ruby may #define rb_str_new2 to use rb_str_new_cstr. # define need_rb_str_new_cstr 1 ! // Ruby's headers #define rb_str_new_cstr to make use of GCC's ! // __builtin_constant_p extension. # undef rb_str_new_cstr # define rb_str_new_cstr dll_rb_str_new_cstr # else *************** *** 420,426 **** static VALUE (*dll_rb_inspect) (VALUE); static VALUE (*dll_rb_int2inum) (long); static ID (*dll_rb_intern) (const char*); ! # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */ static long (*dll_rb_fix2int) (VALUE); static long (*dll_rb_num2int) (VALUE); static unsigned long (*dll_rb_num2uint) (VALUE); --- 420,426 ---- static VALUE (*dll_rb_inspect) (VALUE); static VALUE (*dll_rb_int2inum) (long); static ID (*dll_rb_intern) (const char*); ! # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG // 64 bits only static long (*dll_rb_fix2int) (VALUE); static long (*dll_rb_num2int) (VALUE); static unsigned long (*dll_rb_num2uint) (VALUE); *************** *** 445,451 **** static VALUE (*dll_rb_str_concat) (VALUE, VALUE); static VALUE (*dll_rb_str_new) (const char*, long); # ifdef need_rb_str_new_cstr ! /* Ruby may #define rb_str_new2 to use rb_str_new_cstr. */ static VALUE (*dll_rb_str_new_cstr) (const char*); # else static VALUE (*dll_rb_str_new2) (const char*); --- 445,451 ---- static VALUE (*dll_rb_str_concat) (VALUE, VALUE); static VALUE (*dll_rb_str_new) (const char*, long); # ifdef need_rb_str_new_cstr ! // Ruby may #define rb_str_new2 to use rb_str_new_cstr. static VALUE (*dll_rb_str_new_cstr) (const char*); # else static VALUE (*dll_rb_str_new2) (const char*); *************** *** 560,566 **** # endif # endif ! /* Do not generate a prototype here, VALUE isn't always defined. */ # if defined(USE_RGENGC) && USE_RGENGC && !defined(PROTO) # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER == 21 void --- 560,566 ---- # endif # endif ! // Do not generate a prototype here, VALUE isn't always defined. # if defined(USE_RGENGC) && USE_RGENGC && !defined(PROTO) # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER == 21 void *************** *** 585,591 **** } # endif ! static HINSTANCE hinstRuby = NULL; /* Instance of ruby.dll */ /* * Table of name to function pointer of ruby. --- 585,591 ---- } # endif ! static HINSTANCE hinstRuby = NULL; // Instance of ruby.dll /* * Table of name to function pointer of ruby. *************** *** 653,659 **** {"rb_inspect", (RUBY_PROC*)&dll_rb_inspect}, {"rb_int2inum", (RUBY_PROC*)&dll_rb_int2inum}, {"rb_intern", (RUBY_PROC*)&dll_rb_intern}, ! # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG /* 64 bits only */ {"rb_fix2int", (RUBY_PROC*)&dll_rb_fix2int}, {"rb_num2int", (RUBY_PROC*)&dll_rb_num2int}, {"rb_num2uint", (RUBY_PROC*)&dll_rb_num2uint}, --- 653,659 ---- {"rb_inspect", (RUBY_PROC*)&dll_rb_inspect}, {"rb_int2inum", (RUBY_PROC*)&dll_rb_int2inum}, {"rb_intern", (RUBY_PROC*)&dll_rb_intern}, ! # if VIM_SIZEOF_INT < VIM_SIZEOF_LONG // 64 bits only {"rb_fix2int", (RUBY_PROC*)&dll_rb_fix2int}, {"rb_num2int", (RUBY_PROC*)&dll_rb_num2int}, {"rb_num2uint", (RUBY_PROC*)&dll_rb_num2uint}, *************** *** 800,806 **** { return ruby_runtime_link_init((char *)p_rubydll, verbose) == OK; } ! #endif /* defined(DYNAMIC_RUBY) || defined(PROTO) */ void ruby_end(void) --- 800,806 ---- { return ruby_runtime_link_init((char *)p_rubydll, verbose) == OK; } ! #endif // defined(DYNAMIC_RUBY) || defined(PROTO) void ruby_end(void) *************** *** 918,924 **** ml_replace(i, (char_u *) StringValuePtr(line), 1); changed(); #ifdef SYNTAX_HL ! syn_changed(i); /* recompute syntax hl. for this line */ #endif } } --- 918,924 ---- ml_replace(i, (char_u *) StringValuePtr(line), 1); changed(); #ifdef SYNTAX_HL ! syn_changed(i); // recompute syntax hl. for this line #endif } } *************** *** 978,984 **** { #endif #ifdef MSWIN ! /* suggested by Ariya Mizutani */ int argc = 1; char *argv[] = {"gvim.exe"}; char **argvp = argv; --- 978,984 ---- { #endif #ifdef MSWIN ! // suggested by Ariya Mizutani int argc = 1; char *argv[] = {"gvim.exe"}; char **argvp = argv; *************** *** 1112,1118 **** str = rb_obj_as_string(str); if (RSTRING_LEN(str) > 0) { ! /* Only do this when the string isn't empty, alloc(0) causes trouble. */ buff = ALLOCA_N(char, RSTRING_LEN(str) + 1); strcpy(buff, RSTRING_PTR(str)); p = strchr(buff, '\n'); --- 1112,1118 ---- str = rb_obj_as_string(str); if (RSTRING_LEN(str) > 0) { ! // Only do this when the string isn't empty, alloc(0) causes trouble. buff = ALLOCA_N(char, RSTRING_LEN(str) + 1); strcpy(buff, RSTRING_PTR(str)); p = strchr(buff, '\n'); *************** *** 1211,1217 **** result = rb_str_new(tv->vval.v_blob->bv_ga.ga_data, tv->vval.v_blob->bv_ga.ga_len); } ! /* else return Qnil; */ return result; } --- 1211,1217 ---- result = rb_str_new(tv->vval.v_blob->bv_ga.ga_data, tv->vval.v_blob->bv_ga.ga_len); } ! // else return Qnil; return result; } *************** *** 1319,1326 **** FOR_ALL_BUFFERS(b) { ! /* Deleted buffers should not be counted ! * SegPhault - 01/07/05 */ if (b->b_p_bl) n++; } --- 1319,1326 ---- FOR_ALL_BUFFERS(b) { ! // Deleted buffers should not be counted ! // SegPhault - 01/07/05 if (b->b_p_bl) n++; } *************** *** 1336,1343 **** FOR_ALL_BUFFERS(b) { ! /* Deleted buffers should not be counted ! * SegPhault - 01/07/05 */ if (!b->b_p_bl) continue; --- 1336,1343 ---- FOR_ALL_BUFFERS(b) { ! // Deleted buffers should not be counted ! // SegPhault - 01/07/05 if (!b->b_p_bl) continue; *************** *** 1388,1394 **** if (buf != NULL) return get_buffer_line(buf, (linenr_T)NUM2LONG(num)); ! return Qnil; /* For stop warning */ } static VALUE --- 1388,1394 ---- if (buf != NULL) return get_buffer_line(buf, (linenr_T)NUM2LONG(num)); ! return Qnil; // For stop warning } static VALUE *************** *** 1399,1405 **** if (n > 0 && n <= buf->b_ml.ml_line_count && line != NULL) { ! /* set curwin/curbuf for "buf" and save some things */ aucmd_prepbuf(&aco, buf); if (u_savesub(n) == OK) --- 1399,1405 ---- if (n > 0 && n <= buf->b_ml.ml_line_count && line != NULL) { ! // set curwin/curbuf for "buf" and save some things aucmd_prepbuf(&aco, buf); if (u_savesub(n) == OK) *************** *** 1407,1419 **** ml_replace(n, (char_u *)line, TRUE); changed(); #ifdef SYNTAX_HL ! syn_changed(n); /* recompute syntax hl. for this line */ #endif } ! /* restore curwin/curbuf and a few other things */ aucmd_restbuf(&aco); ! /* Careful: autocommands may have made "buf" invalid! */ update_curbuf(NOT_VALID); } --- 1407,1419 ---- ml_replace(n, (char_u *)line, TRUE); changed(); #ifdef SYNTAX_HL ! syn_changed(n); // recompute syntax hl. for this line #endif } ! // restore curwin/curbuf and a few other things aucmd_restbuf(&aco); ! // Careful: autocommands may have made "buf" invalid! update_curbuf(NOT_VALID); } *************** *** 1443,1465 **** if (n > 0 && n <= buf->b_ml.ml_line_count) { ! /* set curwin/curbuf for "buf" and save some things */ aucmd_prepbuf(&aco, buf); if (u_savedel(n, 1) == OK) { ml_delete(n, 0); ! /* Changes to non-active buffers should properly refresh ! * SegPhault - 01/09/05 */ deleted_lines_mark(n, 1L); changed(); } ! /* restore curwin/curbuf and a few other things */ aucmd_restbuf(&aco); ! /* Careful: autocommands may have made "buf" invalid! */ update_curbuf(NOT_VALID); } --- 1443,1465 ---- if (n > 0 && n <= buf->b_ml.ml_line_count) { ! // set curwin/curbuf for "buf" and save some things aucmd_prepbuf(&aco, buf); if (u_savedel(n, 1) == OK) { ml_delete(n, 0); ! // Changes to non-active buffers should properly refresh ! // SegPhault - 01/09/05 deleted_lines_mark(n, 1L); changed(); } ! // restore curwin/curbuf and a few other things aucmd_restbuf(&aco); ! // Careful: autocommands may have made "buf" invalid! update_curbuf(NOT_VALID); } *************** *** 1484,1506 **** } else if (n >= 0 && n <= buf->b_ml.ml_line_count) { ! /* set curwin/curbuf for "buf" and save some things */ aucmd_prepbuf(&aco, buf); if (u_inssub(n + 1) == OK) { ml_append(n, (char_u *) line, (colnr_T) 0, FALSE); ! /* Changes to non-active buffers should properly refresh screen ! * SegPhault - 12/20/04 */ appended_lines_mark(n, 1L); changed(); } ! /* restore curwin/curbuf and a few other things */ aucmd_restbuf(&aco); ! /* Careful: autocommands may have made "buf" invalid! */ update_curbuf(NOT_VALID); } --- 1484,1506 ---- } else if (n >= 0 && n <= buf->b_ml.ml_line_count) { ! // set curwin/curbuf for "buf" and save some things aucmd_prepbuf(&aco, buf); if (u_inssub(n + 1) == OK) { ml_append(n, (char_u *) line, (colnr_T) 0, FALSE); ! // Changes to non-active buffers should properly refresh screen ! // SegPhault - 12/20/04 appended_lines_mark(n, 1L); changed(); } ! // restore curwin/curbuf and a few other things aucmd_restbuf(&aco); ! // Careful: autocommands may have made "buf" invalid! update_curbuf(NOT_VALID); } *************** *** 1684,1690 **** win->w_cursor.lnum = NUM2LONG(lnum); win->w_cursor.col = NUM2UINT(col); win->w_set_curswant = TRUE; ! check_cursor(); /* put cursor on an existing line */ update_screen(NOT_VALID); return Qnil; } --- 1684,1690 ---- win->w_cursor.lnum = NUM2LONG(lnum); win->w_cursor.col = NUM2UINT(col); win->w_set_curswant = TRUE; ! check_cursor(); // put cursor on an existing line update_screen(NOT_VALID); return Qnil; } *************** *** 1739,1746 **** objtbl = rb_hash_new(); rb_global_variable(&objtbl); ! /* The Vim module used to be called "VIM", but "Vim" is better. Make an ! * alias "VIM" for backwards compatibility. */ mVIM = rb_define_module("Vim"); rb_define_const(rb_cObject, "VIM", mVIM); rb_define_const(mVIM, "VERSION_MAJOR", INT2NUM(VIM_VERSION_MAJOR)); --- 1739,1746 ---- objtbl = rb_hash_new(); rb_global_variable(&objtbl); ! // The Vim module used to be called "VIM", but "Vim" is better. Make an ! // alias "VIM" for backwards compatibility. mVIM = rb_define_module("Vim"); rb_define_const(rb_cObject, "VIM", mVIM); rb_define_const(mVIM, "VERSION_MAJOR", INT2NUM(VIM_VERSION_MAJOR)); *************** *** 1775,1782 **** rb_define_method(cBuffer, "delete", buffer_delete, 1); rb_define_method(cBuffer, "append", buffer_append, 2); ! /* Added line manipulation functions ! * SegPhault - 03/07/05 */ rb_define_method(cBuffer, "line_number", current_line_number, 0); rb_define_method(cBuffer, "line", line_s_current, 0); rb_define_method(cBuffer, "line=", set_current_line, 1); --- 1775,1782 ---- rb_define_method(cBuffer, "delete", buffer_delete, 1); rb_define_method(cBuffer, "append", buffer_append, 2); ! // Added line manipulation functions ! // SegPhault - 03/07/05 rb_define_method(cBuffer, "line_number", current_line_number, 0); rb_define_method(cBuffer, "line", line_s_current, 0); rb_define_method(cBuffer, "line=", set_current_line, 1); *************** *** 1801,1807 **** void vim_ruby_init(void *stack_start) { ! /* should get machine stack start address early in main function */ ruby_stack_start = stack_start; } --- 1801,1807 ---- void vim_ruby_init(void *stack_start) { ! // should get machine stack start address early in main function ruby_stack_start = stack_start; } *** ../vim-8.1.2386/src/if_tcl.c 2019-03-30 18:46:57.352077376 +0100 --- src/if_tcl.c 2019-12-04 21:24:01.054720209 +0100 *************** *** 67,76 **** */ #include "vim.h" ! #undef EXTERN /* tcl.h defines it too */ #ifdef DYNAMIC_TCL ! # define USE_TCL_STUBS /* use tcl's stubs mechanism */ #endif #include --- 67,76 ---- */ #include "vim.h" ! #undef EXTERN // tcl.h defines it too #ifdef DYNAMIC_TCL ! # define USE_TCL_STUBS // use tcl's stubs mechanism #endif #include *************** *** 106,112 **** #define VIMOUT ((ClientData)1) #define VIMERR ((ClientData)2) ! /* This appears to be new in Tcl 8.4. */ #ifndef CONST84 # define CONST84 #endif --- 106,112 ---- #define VIMOUT ((ClientData)1) #define VIMERR ((ClientData)2) ! // This appears to be new in Tcl 8.4. #ifndef CONST84 # define CONST84 #endif *************** *** 123,131 **** struct ref *next; Tcl_Interp *interp; ! Tcl_Command cmd; /* Tcl command that represents this object */ ! Tcl_Obj *delcmd; /* Tcl command to call when object is being del. */ ! void *vimobj; /* Vim window or buffer (win_T* or buf_T*) */ }; static char * tclgetbuffer _ANSI_ARGS_((Tcl_Interp *interp, buf_T *buf)); static char * tclgetwindow _ANSI_ARGS_((Tcl_Interp *interp, win_T *win)); --- 123,131 ---- struct ref *next; Tcl_Interp *interp; ! Tcl_Command cmd; // Tcl command that represents this object ! Tcl_Obj *delcmd; // Tcl command to call when object is being del. ! void *vimobj; // Vim window or buffer (win_T* or buf_T*) }; static char * tclgetbuffer _ANSI_ARGS_((Tcl_Interp *interp, buf_T *buf)); static char * tclgetwindow _ANSI_ARGS_((Tcl_Interp *interp, win_T *win)); *************** *** 142,152 **** static void tclerrmsg _ANSI_ARGS_((char *text)); static void tclupdatevars _ANSI_ARGS_((void)); ! static struct ref refsdeleted; /* dummy object for deleted ref list */ ! /***************************************************************************** ! * TCL interface manager ! ****************************************************************************/ #if defined(DYNAMIC_TCL) || defined(PROTO) # ifndef DYNAMIC_TCL_DLL --- 142,152 ---- static void tclerrmsg _ANSI_ARGS_((char *text)); static void tclupdatevars _ANSI_ARGS_((void)); ! static struct ref refsdeleted; // dummy object for deleted ref list ! ////////////////////////////////////////////////////////////////////////////// ! // TCL interface manager ! //////////////////////////////////////////////////////////////////////////// #if defined(DYNAMIC_TCL) || defined(PROTO) # ifndef DYNAMIC_TCL_DLL *************** *** 156,162 **** # define DYNAMIC_TCL_VER "8.3" # endif ! # ifndef DYNAMIC_TCL /* Just generating prototypes */ typedef int HANDLE; # endif --- 156,162 ---- # define DYNAMIC_TCL_VER "8.3" # endif ! # ifndef DYNAMIC_TCL // Just generating prototypes typedef int HANDLE; # endif *************** *** 230,236 **** } return OK; } ! #endif /* defined(DYNAMIC_TCL) || defined(PROTO) */ #ifdef DYNAMIC_TCL static char *find_executable_arg = NULL; --- 230,236 ---- } return OK; } ! #endif // defined(DYNAMIC_TCL) || defined(PROTO) #ifdef DYNAMIC_TCL static char *find_executable_arg = NULL; *************** *** 270,276 **** Tcl_DeleteInterp(interp); stubs_initialized = TRUE; } ! /* FIXME: When Tcl_InitStubs() was failed, how delete interp? */ } } return stubs_initialized; --- 270,276 ---- Tcl_DeleteInterp(interp); stubs_initialized = TRUE; } ! // FIXME: When Tcl_InitStubs() was failed, how delete interp? } } return stubs_initialized; *************** *** 289,297 **** #endif } ! /**************************************************************************** ! Tcl commands ! ****************************************************************************/ /* * Replace standard "exit" command. --- 289,297 ---- #endif } ! ///////////////////////////////////////////////////////////////////////////// ! // Tcl commands ! //////////////////////////////////////////////////////////////////////////// /* * Replace standard "exit" command. *************** *** 321,327 **** case 2: if (Tcl_GetIntFromObj(interp, objv[1], &value) != TCL_OK) break; ! /* FALLTHROUGH */ case 1: tclinfo.exitvalue = value; --- 321,327 ---- case 2: if (Tcl_GetIntFromObj(interp, objv[1], &value) != TCL_OK) break; ! // FALLTHROUGH case 1: tclinfo.exitvalue = value; *************** *** 402,408 **** Tcl_SetResult(interp, _("invalid buffer number"), TCL_STATIC); return TCL_ERROR; } ! Tcl_ResetResult(interp); /* clear error from Tcl_GetIntFromObj */ err = Tcl_GetIndexFromObj(interp, objv[1], bcmdoptions, "option", 0, &idx); if (err != TCL_OK) --- 402,408 ---- Tcl_SetResult(interp, _("invalid buffer number"), TCL_STATIC); return TCL_ERROR; } ! Tcl_ResetResult(interp); // clear error from Tcl_GetIntFromObj err = Tcl_GetIndexFromObj(interp, objv[1], bcmdoptions, "option", 0, &idx); if (err != TCL_OK) *************** *** 576,582 **** * Get line number of last line. */ opt = 1; ! /* fallthrough */ case BUF_COUNT: /* * Get number of lines in buffer. --- 576,582 ---- * Get line number of last line. */ opt = 1; ! // fallthrough case BUF_COUNT: /* * Get number of lines in buffer. *************** *** 639,645 **** err = TCL_ERROR; } } ! else { /* objc == 3 */ line = (char *)ml_get_buf(buf, (linenr_T)val1, FALSE); Tcl_SetResult(interp, line, TCL_VOLATILE); } --- 639,645 ---- err = TCL_ERROR; } } ! else { // objc == 3 line = (char *)ml_get_buf(buf, (linenr_T)val1, FALSE); Tcl_SetResult(interp, line, TCL_VOLATILE); } *************** *** 725,731 **** } if (i < lc) { ! /* append lines */ do { line = Tcl_GetStringFromObj(lv[i], NULL); --- 725,731 ---- } if (i < lc) { ! // append lines do { line = Tcl_GetStringFromObj(lv[i], NULL); *************** *** 738,744 **** } else if (n <= val2) { ! /* did not replace all lines, delete */ i = n; do { --- 738,744 ---- } else if (n <= val2) { ! // did not replace all lines, delete i = n; do { *************** *** 747,759 **** ++n; } while (n <= val2); } ! lc -= val2 - val1 + 1; /* number of lines to be replaced */ mark_adjust((linenr_T)val1, (linenr_T)val2, (long)MAXLNUM, (long)lc); changed_lines((linenr_T)val1, 0, (linenr_T)val2 + 1, (long)lc); break; setListError: ! u_undo(1); /* ??? */ Tcl_SetResult(interp, _("cannot set line(s)"), TCL_STATIC); err = TCL_ERROR; } --- 747,759 ---- ++n; } while (n <= val2); } ! lc -= val2 - val1 + 1; // number of lines to be replaced mark_adjust((linenr_T)val1, (linenr_T)val2, (long)MAXLNUM, (long)lc); changed_lines((linenr_T)val1, 0, (linenr_T)val2 + 1, (long)lc); break; setListError: ! u_undo(1); // ??? Tcl_SetResult(interp, _("cannot set line(s)"), TCL_STATIC); err = TCL_ERROR; } *************** *** 838,844 **** case BUF_INSERT: opt = 1; ! /* fallthrough */ case BUF_APPEND: if (objc != 4) { --- 838,844 ---- case BUF_INSERT: opt = 1; ! // fallthrough case BUF_APPEND: if (objc != 4) { *************** *** 1078,1084 **** if (err != TCL_OK) break; } ! else { /* objc == 4 */ err = tclgetlinenum(interp, objv[2], &val1, win->w_buffer); if (err != TCL_OK) break; --- 1078,1084 ---- if (err != TCL_OK) break; } ! else { // objc == 4 err = tclgetlinenum(interp, objv[2], &val1, win->w_buffer); if (err != TCL_OK) break; *************** *** 1086,1092 **** if (err != TCL_OK) break; } ! /* TODO: should check column */ win->w_cursor.lnum = val1; win->w_cursor.col = col2vim(val2); win->w_set_curswant = TRUE; --- 1086,1092 ---- if (err != TCL_OK) break; } ! // TODO: should check column win->w_cursor.lnum = val1; win->w_cursor.col = col2vim(val2); win->w_set_curswant = TRUE; *************** *** 1145,1153 **** return tclvimexpr(interp, objc, objv, 1); } ! /**************************************************************************** ! Support functions for Tcl commands ! ****************************************************************************/ /* * Get a line number from 'obj' and convert it to vim's range. --- 1145,1153 ---- return tclvimexpr(interp, objc, objv, 1); } ! ///////////////////////////////////////////////////////////////////////////// ! // Support functions for Tcl commands ! //////////////////////////////////////////////////////////////////////////// /* * Get a line number from 'obj' and convert it to vim's range. *************** *** 1215,1221 **** if (win->w_buffer == buf) return win; } ! return curwin; /* keep current window context */ } /* --- 1215,1221 ---- if (win->w_buffer == buf) return win; } ! return curwin; // keep current window context } /* *************** *** 1267,1273 **** --emsg_off; err = vimerror(interp); ! /* If the ex command created a new Tcl interpreter, remove it */ if (tclinfo.interp) tcldelthisinterp(); memcpy(&tclinfo, &saveinfo, sizeof(tcl_info)); --- 1267,1273 ---- --emsg_off; err = vimerror(interp); ! // If the ex command created a new Tcl interpreter, remove it if (tclinfo.interp) tcldelthisinterp(); memcpy(&tclinfo, &saveinfo, sizeof(tcl_info)); *************** *** 1325,1331 **** { if (isnum) { ! sval = NULL; /* avoid compiler warning */ err = Tcl_GetIndexFromObj(interp, objv[objn], optkw, "", 0, &idx); if (err != TCL_OK) { --- 1325,1331 ---- { if (isnum) { ! sval = NULL; // avoid compiler warning err = Tcl_GetIndexFromObj(interp, objv[objn], optkw, "", 0, &idx); if (err != TCL_OK) { *************** *** 1440,1450 **** static char * tclgetref( Tcl_Interp *interp, ! void **refstartP, /* ptr to w_tcl_ref/b_tcl-ref member of ! win_T/buf_T struct */ ! char *prefix, /* "win" or "buf" */ ! void *vimobj, /* win_T* or buf_T* */ ! Tcl_ObjCmdProc *proc) /* winselfcmd or bufselfcmd */ { struct ref *ref, *unused = NULL; static char name[VARNAME_SIZE]; --- 1440,1450 ---- static char * tclgetref( Tcl_Interp *interp, ! void **refstartP, // ptr to w_tcl_ref/b_tcl-ref member of ! // win_T/buf_T struct ! char *prefix, // "win" or "buf" ! void *vimobj, // win_T* or buf_T* ! Tcl_ObjCmdProc *proc) // winselfcmd or bufselfcmd { struct ref *ref, *unused = NULL; static char name[VARNAME_SIZE]; *************** *** 1481,1487 **** (*refstartP) = (void *)ref; } ! /* This might break on some exotic systems... */ vim_snprintf(name, sizeof(name), "::vim::%s_%lx", prefix, (unsigned long)vimobj); cmd = Tcl_CreateObjCommand(interp, name, proc, --- 1481,1487 ---- (*refstartP) = (void *)ref; } ! // This might break on some exotic systems... vim_snprintf(name, sizeof(name), "::vim::%s_%lx", prefix, (unsigned long)vimobj); cmd = Tcl_CreateObjCommand(interp, name, proc, *************** *** 1534,1556 **** } reflist = reflist->next; } ! /* This should never happen. Famous last word? */ emsg(_("E280: TCL FATAL ERROR: reflist corrupt!? Please report this to vim-dev@vim.org")); Tcl_SetResult(interp, _("cannot register callback command: buffer/window reference not found"), TCL_STATIC); return TCL_ERROR; } ! /******************************************* ! I/O Channel ! ********************************************/ static int tcl_channel_close(ClientData instance, Tcl_Interp *interp UNUSED) { int err = 0; ! /* currently does nothing */ if (instance != VIMOUT && instance != VIMERR) { --- 1534,1556 ---- } reflist = reflist->next; } ! // This should never happen. Famous last word? emsg(_("E280: TCL FATAL ERROR: reflist corrupt!? Please report this to vim-dev@vim.org")); Tcl_SetResult(interp, _("cannot register callback command: buffer/window reference not found"), TCL_STATIC); return TCL_ERROR; } ! //////////////////////////////////////////// ! // I/O Channel ! //////////////////////////////////////////// static int tcl_channel_close(ClientData instance, Tcl_Interp *interp UNUSED) { int err = 0; ! // currently does nothing if (instance != VIMOUT && instance != VIMERR) { *************** *** 1568,1574 **** int *errptr) { ! /* input is currently not supported */ Tcl_SetErrno(EINVAL); if (errptr) --- 1568,1574 ---- int *errptr) { ! // input is currently not supported Tcl_SetErrno(EINVAL); if (errptr) *************** *** 1586,1595 **** char_u *str; int result; ! /* The buffer is not guaranteed to be 0-terminated, and we don't if ! * there is enough room to add a '\0'. So we have to create a copy ! * of the buffer... ! */ str = vim_strnsave((char_u *)buf, bufsiz); if (!str) { --- 1586,1594 ---- char_u *str; int result; ! // The buffer is not guaranteed to be 0-terminated, and we don't if ! // there is enough room to add a '\0'. So we have to create a copy ! // of the buffer... str = vim_strnsave((char_u *)buf, bufsiz); if (!str) { *************** *** 1635,1677 **** static Tcl_ChannelType tcl_channel_type = { ! "vimmessage", /* typeName */ ! TCL_CHANNEL_VERSION_2, /* version */ ! tcl_channel_close, /* closeProc */ ! tcl_channel_input, /* inputProc */ ! tcl_channel_output, /* outputProc */ ! NULL, /* seekProc */ ! NULL, /* setOptionProc */ ! NULL, /* getOptionProc */ ! tcl_channel_watch, /* watchProc */ ! tcl_channel_gethandle, /* getHandleProc */ ! NULL, /* close2Proc */ ! NULL, /* blockModeProc */ #ifdef TCL_CHANNEL_VERSION_2 ! NULL, /* flushProc */ ! NULL, /* handlerProc */ #endif ! /* The following should not be necessary since TCL_CHANNEL_VERSION_2 was ! * set above */ #ifdef TCL_CHANNEL_VERSION_3 ! NULL, /* wideSeekProc */ #endif #ifdef TCL_CHANNEL_VERSION_4 ! NULL, /* threadActionProc */ #endif #ifdef TCL_CHANNEL_VERSION_5 ! NULL /* truncateProc */ #endif }; ! /********************************** ! Interface to vim ! **********************************/ static void tclupdatevars(void) { ! char varname[VARNAME_SIZE]; /* must be writeable */ char *name; strcpy(varname, VAR_RANGE1); --- 1634,1676 ---- static Tcl_ChannelType tcl_channel_type = { ! "vimmessage", // typeName ! TCL_CHANNEL_VERSION_2, // version ! tcl_channel_close, // closeProc ! tcl_channel_input, // inputProc ! tcl_channel_output, // outputProc ! NULL, // seekProc ! NULL, // setOptionProc ! NULL, // getOptionProc ! tcl_channel_watch, // watchProc ! tcl_channel_gethandle, // getHandleProc ! NULL, // close2Proc ! NULL, // blockModeProc #ifdef TCL_CHANNEL_VERSION_2 ! NULL, // flushProc ! NULL, // handlerProc #endif ! // The following should not be necessary since TCL_CHANNEL_VERSION_2 was ! // set above #ifdef TCL_CHANNEL_VERSION_3 ! NULL, // wideSeekProc #endif #ifdef TCL_CHANNEL_VERSION_4 ! NULL, // threadActionProc #endif #ifdef TCL_CHANNEL_VERSION_5 ! NULL // truncateProc #endif }; ! /////////////////////////////////// ! // Interface to vim ! ////////////////////////////////// static void tclupdatevars(void) { ! char varname[VARNAME_SIZE]; // must be writeable char *name; strcpy(varname, VAR_RANGE1); *************** *** 1699,1705 **** static int tclinit(exarg_T *eap) { ! char varname[VARNAME_SIZE]; /* Tcl_LinkVar requires writeable varname */ char *name; #ifdef DYNAMIC_TCL --- 1698,1704 ---- static int tclinit(exarg_T *eap) { ! char varname[VARNAME_SIZE]; // Tcl_LinkVar requires writeable varname char *name; #ifdef DYNAMIC_TCL *************** *** 1715,1723 **** Tcl_Interp *interp; static Tcl_Channel ch1, ch2; ! /* Create replacement channels for stdout and stderr; this has to be ! * done each time an interpreter is created since the channels are closed ! * when the interpreter is deleted */ ch1 = Tcl_CreateChannel(&tcl_channel_type, "vimout", VIMOUT, TCL_WRITABLE); ch2 = Tcl_CreateChannel(&tcl_channel_type, "vimerr", VIMERR, TCL_WRITABLE); Tcl_SetStdChannel(ch1, TCL_STDOUT); --- 1714,1722 ---- Tcl_Interp *interp; static Tcl_Channel ch1, ch2; ! // Create replacement channels for stdout and stderr; this has to be ! // done each time an interpreter is created since the channels are closed ! // when the interpreter is deleted ch1 = Tcl_CreateChannel(&tcl_channel_type, "vimout", VIMOUT, TCL_WRITABLE); ch2 = Tcl_CreateChannel(&tcl_channel_type, "vimerr", VIMERR, TCL_WRITABLE); Tcl_SetStdChannel(ch1, TCL_STDOUT); *************** *** 1732,1738 **** return FAIL; } #if 0 ! /* VIM sure is interactive */ Tcl_SetVar(interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY); #endif --- 1731,1737 ---- return FAIL; } #if 0 ! // VIM sure is interactive Tcl_SetVar(interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY); #endif *************** *** 1745,1756 **** Tcl_SetChannelOption(interp, ch2, "-translation", "lf"); #endif ! /* replace standard Tcl exit command */ Tcl_DeleteCommand(interp, "exit"); Tcl_CreateObjCommand(interp, "exit", exitcmd, (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); ! /* new commands, in ::vim namespace */ Tcl_CreateObjCommand(interp, "::vim::buffer", buffercmd, (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); Tcl_CreateObjCommand(interp, "::vim::window", windowcmd, --- 1744,1755 ---- Tcl_SetChannelOption(interp, ch2, "-translation", "lf"); #endif ! // replace standard Tcl exit command Tcl_DeleteCommand(interp, "exit"); Tcl_CreateObjCommand(interp, "exit", exitcmd, (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); ! // new commands, in ::vim namespace Tcl_CreateObjCommand(interp, "::vim::buffer", buffercmd, (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); Tcl_CreateObjCommand(interp, "::vim::window", windowcmd, *************** *** 1764,1775 **** Tcl_CreateObjCommand(interp, "::vim::expr", exprcmd, (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); ! /* "lbase" variable */ tclinfo.lbase = 1; strcpy(varname, VAR_LBASE); Tcl_LinkVar(interp, varname, (char *)&tclinfo.lbase, TCL_LINK_INT); ! /* "range" variable */ tclinfo.range_start = eap->line1; strcpy(varname, VAR_RANGE1); Tcl_LinkVar(interp, varname, (char *)&tclinfo.range_start, TCL_LINK_INT|TCL_LINK_READ_ONLY); --- 1763,1774 ---- Tcl_CreateObjCommand(interp, "::vim::expr", exprcmd, (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); ! // "lbase" variable tclinfo.lbase = 1; strcpy(varname, VAR_LBASE); Tcl_LinkVar(interp, varname, (char *)&tclinfo.lbase, TCL_LINK_INT); ! // "range" variable tclinfo.range_start = eap->line1; strcpy(varname, VAR_RANGE1); Tcl_LinkVar(interp, varname, (char *)&tclinfo.range_start, TCL_LINK_INT|TCL_LINK_READ_ONLY); *************** *** 1779,1785 **** strcpy(varname, VAR_RANGE3); Tcl_LinkVar(interp, varname, (char *)&tclinfo.range_end, TCL_LINK_INT|TCL_LINK_READ_ONLY); ! /* "current" variable */ tclinfo.curbuf = Tcl_Alloc(VARNAME_SIZE); tclinfo.curwin = Tcl_Alloc(VARNAME_SIZE); name = tclgetbuffer(interp, curbuf); --- 1778,1784 ---- strcpy(varname, VAR_RANGE3); Tcl_LinkVar(interp, varname, (char *)&tclinfo.range_end, TCL_LINK_INT|TCL_LINK_READ_ONLY); ! // "current" variable tclinfo.curbuf = Tcl_Alloc(VARNAME_SIZE); tclinfo.curwin = Tcl_Alloc(VARNAME_SIZE); name = tclgetbuffer(interp, curbuf); *************** *** 1795,1801 **** } else { ! /* Interpreter already exists, just update variables */ tclinfo.range_start = row2tcl(eap->line1); tclinfo.range_end = row2tcl(eap->line2); tclupdatevars(); --- 1794,1800 ---- } else { ! // Interpreter already exists, just update variables tclinfo.range_start = row2tcl(eap->line1); tclinfo.range_end = row2tcl(eap->line2); tclupdatevars(); *************** *** 1841,1855 **** if (!Tcl_InterpDeleted(tclinfo.interp)) Tcl_DeleteInterp(tclinfo.interp); Tcl_Release(tclinfo.interp); ! /* The interpreter is now gets deleted. All registered commands (esp. ! * window and buffer commands) are deleted, triggering their deletion ! * callback, which deletes all refs pointing to this interpreter. ! * We could garbage-collect the unused ref structs in all windows and ! * buffers, but unless the user creates hundreds of sub-interpreters ! * all referring to lots of windows and buffers, this is hardly worth ! * the effort. Unused refs are recycled by other interpreters, and ! * all refs are free'd when the window/buffer gets closed by vim. ! */ tclinfo.interp = NULL; Tcl_Free(tclinfo.curbuf); --- 1840,1853 ---- if (!Tcl_InterpDeleted(tclinfo.interp)) Tcl_DeleteInterp(tclinfo.interp); Tcl_Release(tclinfo.interp); ! // The interpreter is now gets deleted. All registered commands (esp. ! // window and buffer commands) are deleted, triggering their deletion ! // callback, which deletes all refs pointing to this interpreter. ! // We could garbage-collect the unused ref structs in all windows and ! // buffers, but unless the user creates hundreds of sub-interpreters ! // all referring to lots of windows and buffers, this is hardly worth ! // the effort. Unused refs are recycled by other interpreters, and ! // all refs are free'd when the window/buffer gets closed by vim. tclinfo.interp = NULL; Tcl_Free(tclinfo.curbuf); *************** *** 1862,1870 **** { int newerr = OK; ! if (Tcl_InterpDeleted(tclinfo.interp) /* True if we intercepted Tcl's exit command */ #if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 5) || TCL_MAJOR_VERSION > 8 ! || Tcl_LimitExceeded(tclinfo.interp) /* True if the interpreter cannot continue */ #endif ) { --- 1860,1868 ---- { int newerr = OK; ! if (Tcl_InterpDeleted(tclinfo.interp) // True if we intercepted Tcl's exit command #if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 5) || TCL_MAJOR_VERSION > 8 ! || Tcl_LimitExceeded(tclinfo.interp) // True if the interpreter cannot continue #endif ) { *************** *** 1954,1960 **** { char *script, *line; int err, rs, re, lnum; ! char var_lnum[VARNAME_SIZE]; /* must be writeable memory */ char var_line[VARNAME_SIZE]; linenr_T first_line = 0; linenr_T last_line = 0; --- 1952,1958 ---- { char *script, *line; int err, rs, re, lnum; ! char var_lnum[VARNAME_SIZE]; // must be writeable memory char var_line[VARNAME_SIZE]; linenr_T first_line = 0; linenr_T last_line = 0; *************** *** 2035,2041 **** char *result; #ifdef DYNAMIC_TCL ! /* TODO: this code currently crashes Vim on exit */ if (exiting) return; #endif --- 2033,2039 ---- char *result; #ifdef DYNAMIC_TCL ! // TODO: this code currently crashes Vim on exit if (exiting) return; #endif *************** *** 2070,2076 **** struct ref *reflist; #ifdef DYNAMIC_TCL ! if (!stubs_initialized) /* Not using Tcl, nothing to do. */ return; #endif --- 2068,2074 ---- struct ref *reflist; #ifdef DYNAMIC_TCL ! if (!stubs_initialized) // Not using Tcl, nothing to do. return; #endif *************** *** 2089,2095 **** struct ref *reflist; #ifdef DYNAMIC_TCL ! if (!stubs_initialized) /* Not using Tcl, nothing to do. */ return; #endif --- 2087,2093 ---- struct ref *reflist; #ifdef DYNAMIC_TCL ! if (!stubs_initialized) // Not using Tcl, nothing to do. return; #endif *************** *** 2102,2105 **** } } ! /* The End */ --- 2100,2103 ---- } } ! // The End *** ../vim-8.1.2386/src/if_xcmdsrv.c 2019-11-17 17:06:25.824081732 +0100 --- src/if_xcmdsrv.c 2019-12-04 21:23:44.366748687 +0100 *************** *** 64,81 **** typedef struct PendingCommand { ! int serial; /* Serial number expected in result. */ ! int code; /* Result Code. 0 is OK */ ! char_u *result; /* String result for command (malloc'ed). ! * NULL means command still pending. */ struct PendingCommand *nextPtr; ! /* Next in list of all outstanding commands. ! * NULL means end of list. */ } PendingCommand; static PendingCommand *pendingCommands = NULL; ! /* List of all commands currently ! * being waited for. */ /* * The information below is used for communication between processes --- 64,81 ---- typedef struct PendingCommand { ! int serial; // Serial number expected in result. ! int code; // Result Code. 0 is OK ! char_u *result; // String result for command (malloc'ed). ! // NULL means command still pending. struct PendingCommand *nextPtr; ! // Next in list of all outstanding commands. ! // NULL means end of list. } PendingCommand; static PendingCommand *pendingCommands = NULL; ! // List of all commands currently ! // being waited for. /* * The information below is used for communication between processes *************** *** 179,185 **** typedef struct x_cmdqueue x_queue_T; ! /* dummy node, header for circular queue */ static x_queue_T head = {NULL, 0, NULL, NULL}; /* --- 179,185 ---- typedef struct x_cmdqueue x_queue_T; ! // dummy node, header for circular queue static x_queue_T head = {NULL, 0, NULL, NULL}; /* *************** *** 200,211 **** static void save_in_queue(char_u *buf, long_u len); static void server_parse_message(Display *dpy, char_u *propInfo, long_u numItems); ! /* Private variables for the "server" functionality */ static Atom registryProperty = None; static Atom vimProperty = None; static int got_x_error = FALSE; ! static char_u *empty_prop = (char_u *)""; /* empty GetRegProp() result */ /* * Associate an ASCII name with Vim. Try real hard to get a unique one. --- 200,211 ---- static void save_in_queue(char_u *buf, long_u len); static void server_parse_message(Display *dpy, char_u *propInfo, long_u numItems); ! // Private variables for the "server" functionality static Atom registryProperty = None; static Atom vimProperty = None; static int got_x_error = FALSE; ! static char_u *empty_prop = (char_u *)""; // empty GetRegProp() result /* * Associate an ASCII name with Vim. Try real hard to get a unique one. *************** *** 213,220 **** */ int serverRegisterName( ! Display *dpy, /* display to register with */ ! char_u *name) /* the name that will be used as a base */ { int i; int res; --- 213,220 ---- */ int serverRegisterName( ! Display *dpy, // display to register with ! char_u *name) // the name that will be used as a base { int i; int res; *************** *** 329,353 **** */ void serverChangeRegisteredWindow( ! Display *dpy, /* Display to register with */ ! Window newwin) /* Re-register to this ID */ { char_u propInfo[MAX_NAME_LENGTH + 20]; commWindow = newwin; ! /* Always call SendInit() here, to make sure commWindow is marked as a Vim ! * window. */ if (SendInit(dpy) < 0) return; ! /* WARNING: Do not step through this while debugging, it will hangup the X ! * server! */ XGrabServer(dpy); DeleteAnyLingerer(dpy, newwin); if (serverName != NULL) { ! /* Reinsert name if we was already registered */ (void)LookupName(dpy, serverName, /*delete=*/TRUE, NULL); sprintf((char *)propInfo, "%x %.*s", (int_u)newwin, MAX_NAME_LENGTH, serverName); --- 329,353 ---- */ void serverChangeRegisteredWindow( ! Display *dpy, // Display to register with ! Window newwin) // Re-register to this ID { char_u propInfo[MAX_NAME_LENGTH + 20]; commWindow = newwin; ! // Always call SendInit() here, to make sure commWindow is marked as a Vim ! // window. if (SendInit(dpy) < 0) return; ! // WARNING: Do not step through this while debugging, it will hangup the X ! // server! XGrabServer(dpy); DeleteAnyLingerer(dpy, newwin); if (serverName != NULL) { ! // Reinsert name if we was already registered (void)LookupName(dpy, serverName, /*delete=*/TRUE, NULL); sprintf((char *)propInfo, "%x %.*s", (int_u)newwin, MAX_NAME_LENGTH, serverName); *************** *** 365,394 **** */ int serverSendToVim( ! Display *dpy, /* Where to send. */ ! char_u *name, /* Where to send. */ ! char_u *cmd, /* What to send. */ ! char_u **result, /* Result of eval'ed expression */ ! Window *server, /* Actual ID of receiving app */ ! Bool asExpr, /* Interpret as keystrokes or expr ? */ ! int timeout, /* seconds to wait or zero */ ! Bool localLoop, /* Throw away everything but result */ ! int silent) /* don't complain about no server */ { Window w; char_u *property; int length; int res; ! static int serial = 0; /* Running count of sent commands. ! * Used to give each command a ! * different serial number. */ PendingCommand pending; char_u *loosename = NULL; if (result != NULL) *result = NULL; if (name == NULL || *name == NUL) ! name = (char_u *)"GVIM"; /* use a default name */ if (commProperty == None && dpy != NULL) { --- 365,394 ---- */ int serverSendToVim( ! Display *dpy, // Where to send. ! char_u *name, // Where to send. ! char_u *cmd, // What to send. ! char_u **result, // Result of eval'ed expression ! Window *server, // Actual ID of receiving app ! Bool asExpr, // Interpret as keystrokes or expr ? ! int timeout, // seconds to wait or zero ! Bool localLoop, // Throw away everything but result ! int silent) // don't complain about no server { Window w; char_u *property; int length; int res; ! static int serial = 0; // Running count of sent commands. ! // Used to give each command a ! // different serial number. PendingCommand pending; char_u *loosename = NULL; if (result != NULL) *result = NULL; if (name == NULL || *name == NUL) ! name = (char_u *)"GVIM"; // use a default name if (commProperty == None && dpy != NULL) { *************** *** 396,402 **** return -1; } ! /* Execute locally if no display or target is ourselves */ if (dpy == NULL || (serverName != NULL && STRICMP(name, serverName) == 0)) return sendToLocalVim(cmd, asExpr, result); --- 396,402 ---- return -1; } ! // Execute locally if no display or target is ourselves if (dpy == NULL || (serverName != NULL && STRICMP(name, serverName) == 0)) return sendToLocalVim(cmd, asExpr, result); *************** *** 411,417 **** while (TRUE) { w = LookupName(dpy, name, FALSE, &loosename); ! /* Check that the window is hot */ if (w != None) { if (!WindowValid(dpy, w)) --- 411,417 ---- while (TRUE) { w = LookupName(dpy, name, FALSE, &loosename); ! // Check that the window is hot if (w != None) { if (!WindowValid(dpy, w)) *************** *** 447,457 **** 0, asExpr ? 'c' : 'k', 0, name, 0, p_enc, 0, cmd); if (name == loosename) vim_free(loosename); ! /* Add a back reference to our comm window */ serial++; sprintf((char *)property + length, "%c-r %x %d", 0, (int_u)commWindow, serial); ! /* Add length of what "-r %x %d" resulted in, skipping the NUL. */ length += STRLEN(property + length + 1) + 1; res = AppendPropCarefully(dpy, w, commProperty, property, length + 1); --- 447,457 ---- 0, asExpr ? 'c' : 'k', 0, name, 0, p_enc, 0, cmd); if (name == loosename) vim_free(loosename); ! // Add a back reference to our comm window serial++; sprintf((char *)property + length, "%c-r %x %d", 0, (int_u)commWindow, serial); ! // Add length of what "-r %x %d" resulted in, skipping the NUL. length += STRLEN(property + length + 1) + 1; res = AppendPropCarefully(dpy, w, commProperty, property, length + 1); *************** *** 462,468 **** return -1; } ! if (!asExpr) /* There is no answer for this - Keys are sent async */ return 0; /* --- 462,468 ---- return -1; } ! if (!asExpr) // There is no answer for this - Keys are sent async return 0; /* *************** *** 592,598 **** check_due_timer(); #endif ! /* Just look out for the answer without calling back into Vim */ if (localLoop) { #ifndef HAVE_SELECT --- 592,598 ---- check_due_timer(); #endif ! // Just look out for the answer without calling back into Vim if (localLoop) { #ifndef HAVE_SELECT *************** *** 670,678 **** return ga.ga_data; } ! /* ---------------------------------------------------------- ! * Reply stuff ! */ static struct ServerReply * ServerReplyFind(Window w, enum ServerReplyOp op) --- 670,677 ---- return ga.ga_data; } ! ///////////////////////////////////////////////////////////// ! // Reply stuff static struct ServerReply * ServerReplyFind(Window w, enum ServerReplyOp op) *************** *** 754,760 **** { sprintf((char *)property, "%cn%c-E %s%c-n %s%c-w %x", 0, 0, p_enc, 0, str, 0, (unsigned int)commWindow); ! /* Add length of what "%x" resulted in. */ length += STRLEN(property + length); res = AppendPropCarefully(dpy, win, commProperty, property, length + 1); vim_free(property); --- 753,759 ---- { sprintf((char *)property, "%cn%c-E %s%c-n %s%c-w %x", 0, 0, p_enc, 0, str, 0, (unsigned int)commWindow); ! // Add length of what "%x" resulted in. length += STRLEN(property + length); res = AppendPropCarefully(dpy, win, commProperty, property, length + 1); vim_free(property); *************** *** 804,810 **** } else { ! /* Last string read. Remove from list */ ga_clear(&p->strings); ServerReplyFind(win, SROP_Delete); } --- 803,809 ---- } else { ! // Last string read. Remove from list ga_clear(&p->strings); ServerReplyFind(win, SROP_Delete); } *************** *** 864,877 **** WhitePixel(dpy, DefaultScreen(dpy)), WhitePixel(dpy, DefaultScreen(dpy))); XSelectInput(dpy, commWindow, PropertyChangeMask); ! /* WARNING: Do not step through this while debugging, it will hangup ! * the X server! */ XGrabServer(dpy); DeleteAnyLingerer(dpy, commWindow); XUngrabServer(dpy); } ! /* Make window recognizable as a vim window */ XChangeProperty(dpy, commWindow, vimProperty, XA_STRING, 8, PropModeReplace, (char_u *)VIM_VERSION_SHORT, (int)STRLEN(VIM_VERSION_SHORT) + 1); --- 863,876 ---- WhitePixel(dpy, DefaultScreen(dpy)), WhitePixel(dpy, DefaultScreen(dpy))); XSelectInput(dpy, commWindow, PropertyChangeMask); ! // WARNING: Do not step through this while debugging, it will hangup ! // the X server! XGrabServer(dpy); DeleteAnyLingerer(dpy, commWindow); XUngrabServer(dpy); } ! // Make window recognizable as a vim window XChangeProperty(dpy, commWindow, vimProperty, XA_STRING, 8, PropModeReplace, (char_u *)VIM_VERSION_SHORT, (int)STRLEN(VIM_VERSION_SHORT) + 1); *************** *** 896,906 **** */ static Window LookupName( ! Display *dpy, /* Display whose registry to check. */ ! char_u *name, /* Name of a server. */ ! int delete, /* If non-zero, delete info about name. */ ! char_u **loose) /* Do another search matching -999 if not found ! Return result here if a match is found */ { char_u *regProp, *entry; char_u *p; --- 895,905 ---- */ static Window LookupName( ! Display *dpy, // Display whose registry to check. ! char_u *name, // Name of a server. ! int delete, // If non-zero, delete info about name. ! char_u **loose) // Do another search matching -999 if not found ! // Return result here if a match is found { char_u *regProp, *entry; char_u *p; *************** *** 917,923 **** * Scan the property for the desired name. */ returnValue = (int_u)None; ! entry = NULL; /* Not needed, but eliminates compiler warning. */ for (p = regProp; (long_u)(p - regProp) < numItems; ) { entry = p; --- 916,922 ---- * Scan the property for the desired name. */ returnValue = (int_u)None; ! entry = NULL; // Not needed, but eliminates compiler warning. for (p = regProp; (long_u)(p - regProp) < numItems; ) { entry = p; *************** *** 990,997 **** */ static void DeleteAnyLingerer( ! Display *dpy, /* Display whose registry to check. */ ! Window win) /* Window to remove */ { char_u *regProp, *entry = NULL; char_u *p; --- 989,996 ---- */ static void DeleteAnyLingerer( ! Display *dpy, // Display whose registry to check. ! Window win) // Window to remove { char_u *regProp, *entry = NULL; char_u *p; *************** *** 1004,1010 **** if (GetRegProp(dpy, ®Prop, &numItems, FALSE) == FAIL) return; ! /* Scan the property for the window id. */ for (p = regProp; (long_u)(p - regProp) < numItems; ) { if (*p != 0) --- 1003,1009 ---- if (GetRegProp(dpy, ®Prop, &numItems, FALSE) == FAIL) return; ! // Scan the property for the window id. for (p = regProp; (long_u)(p - regProp) < numItems; ) { if (*p != 0) *************** *** 1014,1020 **** { int lastHalf; ! /* Copy down the remainder to delete entry */ entry = p; while (*p != 0) p++; --- 1013,1019 ---- { int lastHalf; ! // Copy down the remainder to delete entry entry = p; while (*p != 0) p++; *************** *** 1055,1061 **** Display *dpy, char_u **regPropp, long_u *numItemsp, ! int domsg) /* When TRUE give error message. */ { int result, actualFormat; long_u bytesAfter; --- 1054,1060 ---- Display *dpy, char_u **regPropp, long_u *numItemsp, ! int domsg) // When TRUE give error message. { int result, actualFormat; long_u bytesAfter; *************** *** 1079,1091 **** if (actualType == None) { ! /* No prop yet. Logically equal to the empty list */ *numItemsp = 0; *regPropp = empty_prop; return OK; } ! /* If the property is improperly formed, then delete it. */ if (result != Success || actualFormat != 8 || actualType != XA_STRING) { if (*regPropp != NULL) --- 1078,1090 ---- if (actualType == None) { ! // No prop yet. Logically equal to the empty list *numItemsp = 0; *regPropp = empty_prop; return OK; } ! // If the property is improperly formed, then delete it. if (result != Success || actualFormat != 8 || actualType != XA_STRING) { if (*regPropp != NULL) *************** *** 1110,1117 **** void serverEventProc( Display *dpy, ! XEvent *eventPtr, /* Information about event. */ ! int immediate) /* Run event immediately. Should mostly be 0. */ { char_u *propInfo; int result, actualFormat; --- 1109,1116 ---- void serverEventProc( Display *dpy, ! XEvent *eventPtr, // Information about event. ! int immediate) // Run event immediately. Should mostly be 0. { char_u *propInfo; int result, actualFormat; *************** *** 1135,1141 **** &actualFormat, &numItems, &bytesAfter, &propInfo); ! /* If the property doesn't exist or is improperly formed then ignore it. */ if (result != Success || actualType != XA_STRING || actualFormat != 8) { if (propInfo != NULL) --- 1134,1140 ---- &actualFormat, &numItems, &bytesAfter, &propInfo); ! // If the property doesn't exist or is improperly formed then ignore it. if (result != Success || actualType != XA_STRING || actualFormat != 8) { if (propInfo != NULL) *************** *** 1159,1175 **** node = ALLOC_ONE(x_queue_T); if (node == NULL) ! return; /* out of memory */ node->propInfo = propInfo; node->len = len; ! if (head.next == NULL) /* initialize circular queue */ { head.next = &head; head.prev = &head; } ! /* insert node at tail of queue */ node->next = &head; node->prev = head.prev; head.prev->next = node; --- 1158,1174 ---- node = ALLOC_ONE(x_queue_T); if (node == NULL) ! return; // out of memory node->propInfo = propInfo; node->len = len; ! if (head.next == NULL) // initialize circular queue { head.next = &head; head.prev = &head; } ! // insert node at tail of queue node->next = &head; node->prev = head.prev; head.prev->next = node; *************** *** 1185,1191 **** x_queue_T *node; if (!X_DISPLAY) ! return; /* cannot happen? */ while (head.next != NULL && head.next != &head) { node = head.next; --- 1184,1190 ---- x_queue_T *node; if (!X_DISPLAY) ! return; // cannot happen? while (head.next != NULL && head.next != &head) { node = head.next; *************** *** 1214,1221 **** static void server_parse_message( Display *dpy, ! char_u *propInfo, /* A string containing 0 or more X commands */ ! long_u numItems) /* The size of propInfo in bytes. */ { char_u *p; int code; --- 1213,1220 ---- static void server_parse_message( Display *dpy, ! char_u *propInfo, // A string containing 0 or more X commands ! long_u numItems) // The size of propInfo in bytes. { char_u *p; int code; *************** *** 1276,1282 **** else { p = serial = end + 1; ! clientWindow = resWindow; /* Remember in global */ } break; case 'n': --- 1275,1281 ---- else { p = serial = end + 1; ! clientWindow = resWindow; // Remember in global } break; case 'n': *************** *** 1314,1327 **** { garray_T reply; ! /* Initialize the result property. */ ga_init2(&reply, 1, 100); (void)ga_grow(&reply, 50 + STRLEN(p_enc)); sprintf(reply.ga_data, "%cr%c-E %s%c-s %s%c-r ", 0, 0, p_enc, 0, serial, 0); reply.ga_len = 14 + STRLEN(p_enc) + STRLEN(serial); ! /* Evaluate the expression and return the result. */ if (res != NULL) ga_concat(&reply, res); else --- 1313,1326 ---- { garray_T reply; ! // Initialize the result property. ga_init2(&reply, 1, 100); (void)ga_grow(&reply, 50 + STRLEN(p_enc)); sprintf(reply.ga_data, "%cr%c-E %s%c-s %s%c-r ", 0, 0, p_enc, 0, serial, 0); reply.ga_len = 14 + STRLEN(p_enc) + STRLEN(serial); ! // Evaluate the expression and return the result. if (res != NULL) ga_concat(&reply, res); else *************** *** 1485,1495 **** */ static int AppendPropCarefully( ! Display *dpy, /* Display on which to operate. */ ! Window window, /* Window whose property is to be modified. */ ! Atom property, /* Name of property. */ ! char_u *value, /* Characters to append to property. */ ! int length) /* How much to append */ { XErrorHandler old_handler; --- 1484,1494 ---- */ static int AppendPropCarefully( ! Display *dpy, // Display on which to operate. ! Window window, // Window whose property is to be modified. ! Atom property, // Name of property. ! char_u *value, // Characters to append to property. ! int length) // How much to append { XErrorHandler old_handler; *************** *** 1524,1527 **** return (len > 1 && vim_isdigit(str[len - 1])); } ! #endif /* FEAT_CLIENTSERVER */ --- 1523,1526 ---- return (len > 1 && vim_isdigit(str[len - 1])); } ! #endif // FEAT_CLIENTSERVER *** ../vim-8.1.2386/src/version.c 2019-12-04 19:08:24.448596503 +0100 --- src/version.c 2019-12-04 20:53:03.724574771 +0100 *************** *** 744,745 **** --- 744,747 ---- { /* Add new patch number below this line */ + /**/ + 2387, /**/ -- A bad peace is better than a good war. - Yiddish Proverb /// 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 ///