Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit c98766f

Browse files
committed
Improved implementation of time limits for Windows.
1 parent a269426 commit c98766f

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

src/regexec.c

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,36 @@ search_in_range(regex_t* reg, const UChar* str, const UChar* end, const UChar* s
7171

7272
#include <windows.h>
7373

74-
#define CLOCK_REALTIME 0
74+
typedef __int64 TIME_TYPE;
7575

76-
struct timespec {
77-
time_t tv_sec;
78-
long tv_nsec;
79-
};
76+
static void
77+
set_limit_end_time(TIME_TYPE* t, unsigned long limit /* msec. */)
78+
{
79+
TIME_TYPE limit_10nsec;
80+
81+
if ((__int64 )limit < INT64_MAX / 10000) {
82+
limit_10nsec = limit * 10000; /* 10 nsec. */
83+
GetSystemTimeAsFileTime((FILETIME* )t);
84+
if (*t < INT64_MAX - limit_10nsec) {
85+
*t += limit_10nsec;
86+
return ;
87+
}
88+
}
89+
90+
*t = INT64_MAX;
91+
}
8092

8193
static int
82-
clock_gettime(int unused, struct timespec *ts)
94+
time_is_running_out(TIME_TYPE* t)
8395
{
84-
__int64 t;
96+
TIME_TYPE now;
8597

86-
GetSystemTimeAsFileTime((FILETIME* )&t);
87-
t -=116444736000000000i64;
88-
ts->tv_sec = (time_t )(t / 10000000i64);
89-
ts->tv_nsec = t % 10000000i64 *100;
90-
return 0;
98+
GetSystemTimeAsFileTime((FILETIME* )&now);
99+
100+
if (now > *t)
101+
return 1;
102+
else
103+
return 0;
91104
}
92105

93106
#else /* defined(_WIN32) && !defined(__GNUC__) */
@@ -106,8 +119,6 @@ clock_gettime(int unused, struct timespec *ts)
106119
#endif
107120
#endif
108121

109-
#endif /* defined(_WIN32) && !defined(__GNUC__) */
110-
111122
typedef struct timespec TIME_TYPE;
112123

113124
static void
@@ -157,6 +168,8 @@ time_is_running_out(TIME_TYPE* t)
157168
else
158169
return 0;
159170
}
171+
172+
#endif /* defined(_WIN32) && !defined(__GNUC__) */
160173
#endif /* USE_TIME_LIMIT */
161174

162175

0 commit comments

Comments
 (0)