]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1720: using gettimeofday() for parsing OSC responses v9.1.1720
authorFoxe Chen <chen.foxe@gmail.com>
Sun, 31 Aug 2025 17:40:24 +0000 (19:40 +0200)
committerChristian Brabandt <cb@256bit.org>
Sun, 31 Aug 2025 17:40:24 +0000 (19:40 +0200)
Problem:  Using gettimeofday() for parsing OSC responses
Solution: Use ELAPSED_ macros instead (Foxe Chen).

closes: #18165

Signed-off-by: Foxe Chen <chen.foxe@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/structs.h
src/term.c
src/version.c

index ed7f90a61e2333b6df19cb96726ff3b2703e3611..0968b3c9a9e6a15365fc42d07c9973859fbc3dbe 100644 (file)
@@ -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.
  */
index 829e566c6dd7740023fddb9daf4aac29de0a4b4b..d1917203d20d3fe989bace76a198622ae6a2b871 100644 (file)
@@ -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
index fe65617e1a7e5c3eccb868fb5c9396b36560486b..a32324fd953a479ebaa19782497713c36835b767 100644 (file)
@@ -724,6 +724,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1720,
 /**/
     1719,
 /**/