From 84fc680e721a31e417880c01fb5107639ef5e301 Mon Sep 17 00:00:00 2001 From: Drew Parsons Date: Sun, 5 Jan 2025 13:17:13 +0100 Subject: [PATCH] fix 32-bit usage of size_t On 32-bit systems size_t is identical unsigned in, causing redefinition errors in tables (Array_I_S). This patch guards against the 32-bit redefinition and defines Array_I_S = Array_I_U for the python interface if not already defined. Applies debian patch size_t_int32.patch https://salsa.debian.org/science-team/netgen/-/blob/d7ca1c564d90d00ce3d83e0b63c36fbec11cf1ce/debian/patches/size_t_int32.patch Fixes #168 --- libsrc/core/python_ngcore.hpp | 3 +++ libsrc/core/python_ngcore_export.cpp | 4 ++++ libsrc/core/table.hpp | 3 +++ python/pyngcore/__init__.py | 6 ++++++ 4 files changed, 16 insertions(+) diff --git a/libsrc/core/python_ngcore.hpp b/libsrc/core/python_ngcore.hpp index 2ce844817..605554c7d 100644 --- a/libsrc/core/python_ngcore.hpp +++ b/libsrc/core/python_ngcore.hpp @@ -2,6 +2,7 @@ #define NETGEN_CORE_PYTHON_NGCORE_HPP #include "ngcore_api.hpp" // for operator new +#include #include #include #include @@ -182,10 +183,12 @@ namespace ngcore static std::string GetName() { return "D"; } }; +#if INTPTR_MAX != INT32_MAX template<> struct PyNameTraits { static std::string GetName() { return "S"; } }; +#endif template struct PyNameTraits> { diff --git a/libsrc/core/python_ngcore_export.cpp b/libsrc/core/python_ngcore_export.cpp index cc9f5a704..7bfb59370 100644 --- a/libsrc/core/python_ngcore_export.cpp +++ b/libsrc/core/python_ngcore_export.cpp @@ -1,3 +1,5 @@ +#include + #include "python_ngcore.hpp" #include "bitarray.hpp" #include "taskmanager.hpp" @@ -23,7 +25,9 @@ PYBIND11_MODULE(pyngcore, m) // NOLINT catch(...) {} ExportArray(m); ExportArray(m); +#if INTPTR_MAX != INT32_MAX ExportArray(m); +#endif ExportArray(m); ExportArray(m); ExportArray(m); diff --git a/libsrc/core/table.hpp b/libsrc/core/table.hpp index d2326c266..a51ae3a59 100644 --- a/libsrc/core/table.hpp +++ b/libsrc/core/table.hpp @@ -8,6 +8,7 @@ /**************************************************************************/ #include +#include #include #include @@ -104,8 +105,10 @@ namespace ngcore { return TablePrefixSum32 (FlatArray (entrysize.Size(), (unsigned int*)(int*)(entrysize.Addr(0)))); } NETGEN_INLINE size_t * TablePrefixSum (FlatArray> entrysize) { return TablePrefixSum32 (FlatArray (entrysize.Size(), (unsigned int*)(std::atomic*)entrysize.Addr(0))); } +#if INTPTR_MAX != INT32_MAX NETGEN_INLINE size_t * TablePrefixSum (FlatArray entrysize) { return TablePrefixSum64 (entrysize); } +#endif /** diff --git a/python/pyngcore/__init__.py b/python/pyngcore/__init__.py index 29580174a..6536a898e 100644 --- a/python/pyngcore/__init__.py +++ b/python/pyngcore/__init__.py @@ -1 +1,7 @@ from .pyngcore import * + +# is the same as on 32 bit arches +# in which case Array_I_S is not defined by python_ngcore_export.cpp. +# In this case identify it with Array_I_U. +try: Array_I_S +except NameError: Array_I_S=Array_I_U