On 2026/09/09 14:14, LIU Hao wrote:
> 在 2026-9-5 01:12, Zhongteng Gui 写道:
>> On 2026/09/04 22:52, Zhongteng Gui wrote:
>>> Hi, here're 2 patches about cleanup and optimize gettimeofday (and related
>>> stuff).
>>>
>>> This change is a bit huge, and I'm not very sure about some parts, e.g.
>>>
>>> 1. Originally, we provide `int gettimeofday(struct timeval*, void*)`, while
>>> POSIX expects `int gettimeofday(struct timeval*, struct timezone*)`. It's
>>> noteworthy that switching to POSIX will breaks GCC without special handling.
>>> because libiberty.h bundled by GCC specially checked for __MINGW32__, and
>>> declares gettimeofday with `void*` arg type, which fails with
>>> -Wstrict-prototypes. But keeping `void*` is semantically wrong, as we 
>>> actually
>>> set timezone if nonnull.
>>>
>>> 2. Should we conditionally expose gettimeofday? It is marked as obsolete in
>>> POSIX.1-2008 and removed in POSIX.1-2024.
> 
> It's just not required any more, but legacy code still wants to call it.
> 
> 
>>> 3. Originally, gettimeofday assumed "struct timeval*" to be nonnull, and 
>>> didn't
>>> check this. Should we keep this as is, or check it and return -1 if NULL?
> 
> I'd expect that a null pointer be ignored, like on Linux.
> 
> 
>> +int __cdecl mingw_gettimeofday(struct timeval* _tv, struct timezone* _tz)
>> __MINGW_ASM_CALL(gettimeofday);
> 
> 
> The parameter names should be `_Tv` and `_Tz`. An identifier with one 
> underscore
> followed by a lowercase letter is reserved only in global namespace.

Ok, I'll send an updated patch later with the above 2 issues fixed.

> 
> And I suspect this can result in infinite recursion if a user has
> 
>    int
>    gettimeofday(struct timeval* tv, struct timezone* tz)
>    {
>      return mingw_gettimeofday(tv, tz);  // calls `gettimeofday`
>    }
> 
> 

This is indeed an issue. Previously I considered to provide
`mingw_gettimeofday`, and forward `gettimeofday` to it. But considering that
some packages may use autotools to detect `gettimeofday` (including
winpthreads), and autotools doesn't use header file, so I finally chose to
provide `gettimeofday` and forward `mingw_gettimeofday`.

Maybe we could solve this by the following, and removes __MINGW_ASM_CALL.

```
// in gettimeofday.c
int gettimeofday(struct timeval* tv, struct timezone* tz) {
        return mingw_gettimeofday(tv, tz);
}

int mingw_gettimeofday(struct timeval* tv, struct timezone* tz) {
        // Actual logic
}
```

If this is ok, I'll update this together with the above 2 fixes.


_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to