Pali Rohár <[email protected]> wrote:
> On Sunday 04 October 2026 03:13:20 Kirill Makurin wrote:
>> Subject: [PATCH 10/32] winpthreads: clock.c: remove static function
>> `lc_set_errno`
>> if (QueryPerformanceFrequency(&pf) == 0) {
>> - return lc_set_errno(EINVAL);
>> + _set_errno(EINVAL);
>
> I would suggest to use "errno = EINVAL" instead of calling _set_errno()
> function. That function is not available in older CRT libraries and
> mingw-w64 provides just an emulation.
I'm aware of this and I honestly don't think it is a big deal.
> Also the function itself can fail
> and caller should check the return value of _set_errno().
I really can't imagine situation when call to `_set_errno` would fail. Maybe in
case when it's called from a thread which did not initialize CRT's per-thread
storage? But what would `errno` (a call to `_errno` function) do in such case?
I've been using `_set_errno` instead of direct `errno` assignments in my
posix32 library and I never encountered any issues.
> In past we have been already replacing _set_errno() usage by errno= in
> existing mingw-w64 codebase. So I think it makes to follow the existing
> pattern.
Unless there are other arguments against it, I would keep it as-is.
>> Subject: [PATCH 24/32] winpthreads: time.c: update `_pthread_time_in_ms`
>> +/**
>> + * Number of 100ns intervals between the beginning of the Windows epoch
>> + * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970)
>> + */
>> +#define DELTA_EPOCH_IN_100NS INT64_C(116444736000000000)
>
> IIRC for __int64 it is not need to include stdint.h and not needed to
> use INT64_C. That is also because __int64 support predates stdint.h
> support in MSVC.
I simply copied definition from clock.c, and `INT64_C` was already there. Yes,
we don't need stdint.h for `__int64`; in MSVC it is a built-in type and in
mingw-w64 it is defined as alias for `long long` in _mingw.h.
>> Subject: [PATCH 31/32] winpthreads: time.c: update runtime checks logic
>> +/**
>> + * Replacement for `GetSystemTimeAsFileTime`;
>> + * a wrapper around `GetSystemTime` and `SystemTimeToFileTime`
>> + */
>> +static VOID WINAPI WinpthreadsGetSystemTimeAsFileTime (FILETIME *fileTime) {
>> + SYSTEMTIME systemTime;
>> +
>> + GetSystemTime (&systemTime);
>> +
>> + /**
>> + * If call to `SystemTimeToFileTime` fails, store Unix epoch in
>> `fileTime`.
>> + */
>> + if (unlikely (!SystemTimeToFileTime (&systemTime, fileTime))) {
>> + fileTime->dwHighDateTime = (ULARGE_INTEGER) {.QuadPart =
>> DELTA_EPOCH_IN_100NS}.HighPart;
>> + fileTime->dwLowDateTime = (ULARGE_INTEGER) {.QuadPart =
>> DELTA_EPOCH_IN_100NS}.LowPart;
>> + }
>> +}
>
> This function is used and needed only for 32-bit x86 builds.
> So for other platforms this function should be hidden inside
> the "#ifdef _M_IX86" to prevent including dead / bloat code.
>
> Same for some functions below.
I had this in mind. I think we can also handle arm in a similar way? IIRC,
arm32 code can only run on Windows 8 or later, and arm64 can only run on
Windows 10 and later. Is that correct?
I'll address this in follow up changes.
- Kirill Makurin
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public