From 6278f1a10a57b237d4aed8e731b231a6bf888a6a Mon Sep 17 00:00:00 2001 From: Foxe Chen Date: Sun, 31 Aug 2025 19:40:24 +0200 Subject: [PATCH] patch 9.1.1720: using gettimeofday() for parsing OSC responses Problem: Using gettimeofday() for parsing OSC responses Solution: Use ELAPSED_ macros instead (Foxe Chen). closes: #18165 Signed-off-by: Foxe Chen Signed-off-by: Christian Brabandt --- src/structs.h | 13 ------------- src/term.c | 32 ++++++++++++++++++++++---------- src/version.c | 2 ++ 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/structs.h b/src/structs.h index ed7f90a61e..0968b3c9a9 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1290,19 +1290,6 @@ typedef struct #endif } tasave_T; -// Holds state for current OSC response. -typedef struct -{ - int processing; // If we are in the middle of an OSC response - char_u start_char; // First char in the OSC response - garray_T buf; // Buffer holding the OSC response, to be - // placed in the "v:termosc" vim var. - - struct timeval start; // Set at the beginning of an OSC response. - // Used to timeout after a set amount of - // time. -} oscstate_T; - /* * Used for conversion of terminal I/O and script files. */ diff --git a/src/term.c b/src/term.c index 829e566c6d..d1917203d2 100644 --- a/src/term.c +++ b/src/term.c @@ -104,6 +104,21 @@ typedef struct { time_t tr_start; // when request was sent, -1 for never } termrequest_T; +// Holds state for current OSC response. +typedef struct +{ + int processing; // If we are in the middle of an OSC response + char_u start_char; // First char in the OSC response + garray_T buf; // Buffer holding the OSC response, to be + // placed in the "v:termosc" vim var. + +#ifdef ELAPSED_FUNC + elapsed_T start_tv; // Set at the beginning of an OSC response. + // Used to timeout after a set amount of + // time. +#endif +} oscstate_T; + #define TERMREQUEST_INIT {STATUS_GET, -1} // Request Terminal Version status: @@ -5690,8 +5705,7 @@ static oscstate_T osc_state; static int handle_osc(char_u *tp, int len, char_u *key_name, int *slen) { - struct timeval now; - char_u last_char; + char_u last_char; if (!osc_state.processing) { @@ -5712,8 +5726,9 @@ handle_osc(char_u *tp, int len, char_u *key_name, int *slen) // To handle this, keep reading data in and out of the typeahead // buffer until we read an OSC terminator or timeout. ga_init2(&osc_state.buf, 1, 1024); - gettimeofday(&osc_state.start, NULL); - +#ifdef ELAPSED_FUNC + ELAPSED_INIT(osc_state.start_tv); +#endif osc_state.processing = TRUE; osc_state.start_char = tp[0]; last_char = 0; @@ -5748,12 +5763,8 @@ handle_osc(char_u *tp, int len, char_u *key_name, int *slen) return OK; } - // Check if timeout has been reached - gettimeofday(&now, NULL); - - if ((now.tv_sec * 1000000 + now.tv_usec) - - (osc_state.start.tv_sec * 1000000 + osc_state.start.tv_usec) - >= p_ost * 1000) +#ifdef ELAPSED_FUNC + if (ELAPSED_FUNC(osc_state.start_tv) >= p_ost) { semsg(_(e_osc_response_timed_out), osc_state.buf.ga_len, osc_state.buf.ga_data); @@ -5762,6 +5773,7 @@ handle_osc(char_u *tp, int len, char_u *key_name, int *slen) osc_state.processing = FALSE; return FAIL; } +#endif ga_concat(&osc_state.buf, tp); *slen = len; // Consume everything diff --git a/src/version.c b/src/version.c index fe65617e1a..a32324fd95 100644 --- a/src/version.c +++ b/src/version.c @@ -724,6 +724,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1720, /**/ 1719, /**/