* [PATCH] eal/windows: resolve conversion and truncation warnings
@ 2023-08-02 20:48 Tyler Retzlaff
2023-08-02 22:29 ` Dmitry Kozlyuk
2024-03-07 18:34 ` [PATCH v2] " Tyler Retzlaff
0 siblings, 2 replies; 8+ messages in thread
From: Tyler Retzlaff @ 2023-08-02 20:48 UTC (permalink / raw)
To: dev
Cc: Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy,
Pallavi Kadam, Tyler Retzlaff
* Initialize const int NS_PER_SEC with an integer literal instead of
double thereby avoiding implicit conversion from double to int.
* Cast the result of the expression assigned to timspec.tv_nsec to long.
Windows builds generate integer truncation warning for this assignment
since the result of the expression was 8 bytes (LONGLONG) but
on Windows targets is 4 bytes. The value produced for the expression
should safely fit in the long.
Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
lib/eal/windows/include/rte_os_shim.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/eal/windows/include/rte_os_shim.h b/lib/eal/windows/include/rte_os_shim.h
index eda8113..19b12e9 100644
--- a/lib/eal/windows/include/rte_os_shim.h
+++ b/lib/eal/windows/include/rte_os_shim.h
@@ -87,7 +87,7 @@
static inline int
rte_clock_gettime(clockid_t clock_id, struct timespec *tp)
{
- const int NS_PER_SEC = 1E9;
+ const int NS_PER_SEC = 1000000000;
LARGE_INTEGER pf, pc;
LONGLONG nsec;
@@ -102,7 +102,7 @@
nsec = pc.QuadPart * NS_PER_SEC / pf.QuadPart;
tp->tv_sec = nsec / NS_PER_SEC;
- tp->tv_nsec = nsec - tp->tv_sec * NS_PER_SEC;
+ tp->tv_nsec = (long)(nsec - tp->tv_sec * NS_PER_SEC);
return 0;
default:
return -1;
--
1.8.3.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] eal/windows: resolve conversion and truncation warnings
2023-08-02 20:48 [PATCH] eal/windows: resolve conversion and truncation warnings Tyler Retzlaff
@ 2023-08-02 22:29 ` Dmitry Kozlyuk
2023-08-02 22:41 ` Tyler Retzlaff
2024-03-07 18:34 ` [PATCH v2] " Tyler Retzlaff
1 sibling, 1 reply; 8+ messages in thread
From: Dmitry Kozlyuk @ 2023-08-02 22:29 UTC (permalink / raw)
To: Tyler Retzlaff
Cc: dev, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam
2023-08-02 13:48 (UTC-0700), Tyler Retzlaff:
> * Initialize const int NS_PER_SEC with an integer literal instead of
> double thereby avoiding implicit conversion from double to int.
>
> * Cast the result of the expression assigned to timspec.tv_nsec to long.
Typo: "timespec".
> Windows builds generate integer truncation warning for this assignment
> since the result of the expression was 8 bytes (LONGLONG) but
> on Windows targets is 4 bytes.
Probably "but **tv_nsec** on Windows targets is 4 bytes".
> The value produced for the expression should safely fit in the long.
>
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---
> lib/eal/windows/include/rte_os_shim.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] eal/windows: resolve conversion and truncation warnings
2023-08-02 22:29 ` Dmitry Kozlyuk
@ 2023-08-02 22:41 ` Tyler Retzlaff
2023-08-02 23:44 ` Dmitry Kozlyuk
0 siblings, 1 reply; 8+ messages in thread
From: Tyler Retzlaff @ 2023-08-02 22:41 UTC (permalink / raw)
To: Dmitry Kozlyuk
Cc: dev, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam
On Thu, Aug 03, 2023 at 01:29:00AM +0300, Dmitry Kozlyuk wrote:
> 2023-08-02 13:48 (UTC-0700), Tyler Retzlaff:
> > * Initialize const int NS_PER_SEC with an integer literal instead of
> > double thereby avoiding implicit conversion from double to int.
> >
> > * Cast the result of the expression assigned to timspec.tv_nsec to long.
>
> Typo: "timespec".
oops
>
> > Windows builds generate integer truncation warning for this assignment
> > since the result of the expression was 8 bytes (LONGLONG) but
> > on Windows targets is 4 bytes.
>
> Probably "but **tv_nsec** on Windows targets is 4 bytes".
thanks i'll update the wording.
one thing that confuses me a little and this change won't break how the
code already works (just makes the cast redundant) is that for mingw
sizeof(long) is being reported as 8 bytes.
this is in spec relative to the C standard but it does leave me somewhat
concerned if struct timespec as defined in the windows headers crosses
an abi boundary.
have you ever noticed this? any thoughts on it?
>
> > The value produced for the expression should safely fit in the long.
> >
> > Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> > ---
> > lib/eal/windows/include/rte_os_shim.h | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
>
> Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
thanks!
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] eal/windows: resolve conversion and truncation warnings
2023-08-02 22:41 ` Tyler Retzlaff
@ 2023-08-02 23:44 ` Dmitry Kozlyuk
2023-08-03 0:30 ` Tyler Retzlaff
0 siblings, 1 reply; 8+ messages in thread
From: Dmitry Kozlyuk @ 2023-08-02 23:44 UTC (permalink / raw)
To: Tyler Retzlaff
Cc: dev, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam
2023-08-02 15:41 (UTC-0700), Tyler Retzlaff:
> one thing that confuses me a little and this change won't break how the
> code already works (just makes the cast redundant) is that for mingw
> sizeof(long) is being reported as 8 bytes.
>
> this is in spec relative to the C standard but it does leave me somewhat
> concerned if struct timespec as defined in the windows headers crosses
> an abi boundary.
MinGW-w64 shows sizeof(long) == 4 in my tests, both native and cross build.
Which MinGW setup reports sizeof(long) == 8 on Windows target?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] eal/windows: resolve conversion and truncation warnings
2023-08-02 23:44 ` Dmitry Kozlyuk
@ 2023-08-03 0:30 ` Tyler Retzlaff
0 siblings, 0 replies; 8+ messages in thread
From: Tyler Retzlaff @ 2023-08-03 0:30 UTC (permalink / raw)
To: Dmitry Kozlyuk
Cc: dev, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam
On Thu, Aug 03, 2023 at 02:44:45AM +0300, Dmitry Kozlyuk wrote:
> 2023-08-02 15:41 (UTC-0700), Tyler Retzlaff:
> > one thing that confuses me a little and this change won't break how the
> > code already works (just makes the cast redundant) is that for mingw
> > sizeof(long) is being reported as 8 bytes.
> >
> > this is in spec relative to the C standard but it does leave me somewhat
> > concerned if struct timespec as defined in the windows headers crosses
> > an abi boundary.
>
> MinGW-w64 shows sizeof(long) == 4 in my tests, both native and cross build.
> Which MinGW setup reports sizeof(long) == 8 on Windows target?
it must have been a dream, i just checked and i get the results you do.
ignore me i'm tired, thanks for checking though.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2] eal/windows: resolve conversion and truncation warnings
2023-08-02 20:48 [PATCH] eal/windows: resolve conversion and truncation warnings Tyler Retzlaff
2023-08-02 22:29 ` Dmitry Kozlyuk
@ 2024-03-07 18:34 ` Tyler Retzlaff
2024-03-07 20:53 ` Bruce Richardson
1 sibling, 1 reply; 8+ messages in thread
From: Tyler Retzlaff @ 2024-03-07 18:34 UTC (permalink / raw)
To: dev; +Cc: Dmitry Kozlyuk, Pallavi Kadam, Tyler Retzlaff
* Initialize const int NS_PER_SEC with an integer literal instead of
double thereby avoiding implicit conversion from double to int.
* Cast the result of the expression assigned to timespec.tv_nsec to long.
Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
v2:
* update commit message to correct misspelled timspec -> timespec,
remove remarks about casting to long they were unnecessary.
lib/eal/windows/include/rte_os_shim.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/eal/windows/include/rte_os_shim.h b/lib/eal/windows/include/rte_os_shim.h
index eda8113..19b12e9 100644
--- a/lib/eal/windows/include/rte_os_shim.h
+++ b/lib/eal/windows/include/rte_os_shim.h
@@ -87,7 +87,7 @@
static inline int
rte_clock_gettime(clockid_t clock_id, struct timespec *tp)
{
- const int NS_PER_SEC = 1E9;
+ const int NS_PER_SEC = 1000000000;
LARGE_INTEGER pf, pc;
LONGLONG nsec;
@@ -102,7 +102,7 @@
nsec = pc.QuadPart * NS_PER_SEC / pf.QuadPart;
tp->tv_sec = nsec / NS_PER_SEC;
- tp->tv_nsec = nsec - tp->tv_sec * NS_PER_SEC;
+ tp->tv_nsec = (long)(nsec - tp->tv_sec * NS_PER_SEC);
return 0;
default:
return -1;
--
1.8.3.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] eal/windows: resolve conversion and truncation warnings
2024-03-07 18:34 ` [PATCH v2] " Tyler Retzlaff
@ 2024-03-07 20:53 ` Bruce Richardson
2024-03-07 20:57 ` Tyler Retzlaff
0 siblings, 1 reply; 8+ messages in thread
From: Bruce Richardson @ 2024-03-07 20:53 UTC (permalink / raw)
To: Tyler Retzlaff; +Cc: dev, Dmitry Kozlyuk, Pallavi Kadam
On Thu, Mar 07, 2024 at 10:34:42AM -0800, Tyler Retzlaff wrote:
> * Initialize const int NS_PER_SEC with an integer literal instead of
> double thereby avoiding implicit conversion from double to int.
>
> * Cast the result of the expression assigned to timespec.tv_nsec to long.
>
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---
>
> v2:
> * update commit message to correct misspelled timspec -> timespec,
> remove remarks about casting to long they were unnecessary.
>
> lib/eal/windows/include/rte_os_shim.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/eal/windows/include/rte_os_shim.h b/lib/eal/windows/include/rte_os_shim.h
> index eda8113..19b12e9 100644
> --- a/lib/eal/windows/include/rte_os_shim.h
> +++ b/lib/eal/windows/include/rte_os_shim.h
> @@ -87,7 +87,7 @@
> static inline int
> rte_clock_gettime(clockid_t clock_id, struct timespec *tp)
> {
> - const int NS_PER_SEC = 1E9;
> + const int NS_PER_SEC = 1000000000;
Just for readability, and the immediate visibility of errors, could this be
rewritten as (1000 * 1000 * 1000). That avoids us having to count the zeros
to know that the number is correct.
BTW: is "int" still the best type to use for this value? Would it be better
as a #define?
/Bruce
> LARGE_INTEGER pf, pc;
> LONGLONG nsec;
>
> @@ -102,7 +102,7 @@
>
> nsec = pc.QuadPart * NS_PER_SEC / pf.QuadPart;
> tp->tv_sec = nsec / NS_PER_SEC;
> - tp->tv_nsec = nsec - tp->tv_sec * NS_PER_SEC;
> + tp->tv_nsec = (long)(nsec - tp->tv_sec * NS_PER_SEC);
> return 0;
> default:
> return -1;
> --
> 1.8.3.1
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] eal/windows: resolve conversion and truncation warnings
2024-03-07 20:53 ` Bruce Richardson
@ 2024-03-07 20:57 ` Tyler Retzlaff
0 siblings, 0 replies; 8+ messages in thread
From: Tyler Retzlaff @ 2024-03-07 20:57 UTC (permalink / raw)
To: Bruce Richardson; +Cc: dev, Dmitry Kozlyuk, Pallavi Kadam
On Thu, Mar 07, 2024 at 08:53:49PM +0000, Bruce Richardson wrote:
> On Thu, Mar 07, 2024 at 10:34:42AM -0800, Tyler Retzlaff wrote:
> > * Initialize const int NS_PER_SEC with an integer literal instead of
> > double thereby avoiding implicit conversion from double to int.
> >
> > * Cast the result of the expression assigned to timespec.tv_nsec to long.
> >
> > Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> > Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> > ---
> >
> > v2:
> > * update commit message to correct misspelled timspec -> timespec,
> > remove remarks about casting to long they were unnecessary.
> >
> > lib/eal/windows/include/rte_os_shim.h | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/lib/eal/windows/include/rte_os_shim.h b/lib/eal/windows/include/rte_os_shim.h
> > index eda8113..19b12e9 100644
> > --- a/lib/eal/windows/include/rte_os_shim.h
> > +++ b/lib/eal/windows/include/rte_os_shim.h
> > @@ -87,7 +87,7 @@
> > static inline int
> > rte_clock_gettime(clockid_t clock_id, struct timespec *tp)
> > {
> > - const int NS_PER_SEC = 1E9;
> > + const int NS_PER_SEC = 1000000000;
>
> Just for readability, and the immediate visibility of errors, could this be
> rewritten as (1000 * 1000 * 1000). That avoids us having to count the zeros
> to know that the number is correct.
>
> BTW: is "int" still the best type to use for this value? Would it be better
> as a #define?
i think to save spot fixing i'm going to withdraw the series for now. i
need to come back later and deal with warnings from MSVC more
comprehensively anyway.
thanks folks!
>
> /Bruce
>
> > LARGE_INTEGER pf, pc;
> > LONGLONG nsec;
> >
> > @@ -102,7 +102,7 @@
> >
> > nsec = pc.QuadPart * NS_PER_SEC / pf.QuadPart;
> > tp->tv_sec = nsec / NS_PER_SEC;
> > - tp->tv_nsec = nsec - tp->tv_sec * NS_PER_SEC;
> > + tp->tv_nsec = (long)(nsec - tp->tv_sec * NS_PER_SEC);
> > return 0;
> > default:
> > return -1;
> > --
> > 1.8.3.1
> >
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-03-07 20:57 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-02 20:48 [PATCH] eal/windows: resolve conversion and truncation warnings Tyler Retzlaff
2023-08-02 22:29 ` Dmitry Kozlyuk
2023-08-02 22:41 ` Tyler Retzlaff
2023-08-02 23:44 ` Dmitry Kozlyuk
2023-08-03 0:30 ` Tyler Retzlaff
2024-03-07 18:34 ` [PATCH v2] " Tyler Retzlaff
2024-03-07 20:53 ` Bruce Richardson
2024-03-07 20:57 ` Tyler Retzlaff
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).