[v5] eal: define __SIZEOF_LONG__ when using MSVC

Message ID 1738771937-18083-1-git-send-email-andremue@linux.microsoft.com (mailing list archive)
State Superseded
Delegated to: Thomas Monjalon
Headers
Series [v5] eal: define __SIZEOF_LONG__ when using MSVC |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing fail Unit Testing FAIL
ci/intel-Testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Functional success Functional PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS

Commit Message

Andre Muezerie Feb. 5, 2025, 4:12 p.m. UTC
Macro __SIZEOF_LONG__ is not standardized and MSVC does not define it.
Therefore the errors below are seen with MSVC:

../lib/mldev/mldev_utils_scalar.c(465): error C2065:
    '__SIZEOF_LONG__': undeclared identifier
../lib/mldev/mldev_utils_scalar.c(478): error C2051:
    case expression not constant

../lib/mldev/mldev_utils_scalar_bfloat16.c(33): error C2065:
    '__SIZEOF_LONG__': undeclared identifier
../lib/mldev/mldev_utils_scalar_bfloat16.c(49): error C2051:
    case expression not constant

The fix is to define __SIZEOF_LONG__ in a common header when
MSVC is used.

Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
---
 lib/eal/include/rte_compat.h | 5 +++++
 1 file changed, 5 insertions(+)
  

Comments

David Marchand Feb. 7, 2025, 10:56 a.m. UTC | #1
On Wed, Feb 5, 2025 at 5:12 PM Andre Muezerie
<andremue@linux.microsoft.com> wrote:
>
> Macro __SIZEOF_LONG__ is not standardized and MSVC does not define it.
> Therefore the errors below are seen with MSVC:
>
> ../lib/mldev/mldev_utils_scalar.c(465): error C2065:
>     '__SIZEOF_LONG__': undeclared identifier
> ../lib/mldev/mldev_utils_scalar.c(478): error C2051:
>     case expression not constant
>
> ../lib/mldev/mldev_utils_scalar_bfloat16.c(33): error C2065:
>     '__SIZEOF_LONG__': undeclared identifier
> ../lib/mldev/mldev_utils_scalar_bfloat16.c(49): error C2051:
>     case expression not constant
>
> The fix is to define __SIZEOF_LONG__ in a common header when
> MSVC is used.
>
> Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
> ---
>  lib/eal/include/rte_compat.h | 5 +++++
>  1 file changed, 5 insertions(+)

rte_compat only deals with symbol versioning.
I think a better location would be windows/rte_os.h.
  
Andre Muezerie Feb. 7, 2025, 3:07 p.m. UTC | #2
On Fri, Feb 07, 2025 at 11:56:13AM +0100, David Marchand wrote:
> On Wed, Feb 5, 2025 at 5:12 PM Andre Muezerie
> <andremue@linux.microsoft.com> wrote:
> >
> > Macro __SIZEOF_LONG__ is not standardized and MSVC does not define it.
> > Therefore the errors below are seen with MSVC:
> >
> > ../lib/mldev/mldev_utils_scalar.c(465): error C2065:
> >     '__SIZEOF_LONG__': undeclared identifier
> > ../lib/mldev/mldev_utils_scalar.c(478): error C2051:
> >     case expression not constant
> >
> > ../lib/mldev/mldev_utils_scalar_bfloat16.c(33): error C2065:
> >     '__SIZEOF_LONG__': undeclared identifier
> > ../lib/mldev/mldev_utils_scalar_bfloat16.c(49): error C2051:
> >     case expression not constant
> >
> > The fix is to define __SIZEOF_LONG__ in a common header when
> > MSVC is used.
> >
> > Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
> > ---
> >  lib/eal/include/rte_compat.h | 5 +++++
> >  1 file changed, 5 insertions(+)
> 
> rte_compat only deals with symbol versioning.
> I think a better location would be windows/rte_os.h.
> 
> 
> 
> -- 
> David Marchand

Thanks for the suggestion. I updated the patch accordingly.
  

Patch

diff --git a/lib/eal/include/rte_compat.h b/lib/eal/include/rte_compat.h
index 97c1540bd0..6676a1bb13 100644
--- a/lib/eal/include/rte_compat.h
+++ b/lib/eal/include/rte_compat.h
@@ -66,4 +66,9 @@  __attribute__((section(".text.internal")))
 
 #endif
 
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __SIZEOF_LONG__		(sizeof(long))
+#define __SIZEOF_LONG_LONG__	(sizeof(long long))
+#endif
+
 #endif /* _RTE_COMPAT_H_ */