Skip to content

Commit 84fc680

Browse files
committed
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 NGSolve#168
1 parent 63cb566 commit 84fc680

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

libsrc/core/python_ngcore.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define NETGEN_CORE_PYTHON_NGCORE_HPP
33

44
#include "ngcore_api.hpp" // for operator new
5+
#include <cstdint>
56
#include <pybind11/pybind11.h>
67
#include <pybind11/operators.h>
78
#include <pybind11/numpy.h>
@@ -182,10 +183,12 @@ namespace ngcore
182183
static std::string GetName() { return "D"; }
183184
};
184185

186+
#if INTPTR_MAX != INT32_MAX
185187
template<>
186188
struct PyNameTraits<size_t> {
187189
static std::string GetName() { return "S"; }
188190
};
191+
#endif
189192

190193
template<typename T>
191194
struct PyNameTraits<std::shared_ptr<T>> {

libsrc/core/python_ngcore_export.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <cstdint>
2+
13
#include "python_ngcore.hpp"
24
#include "bitarray.hpp"
35
#include "taskmanager.hpp"
@@ -23,7 +25,9 @@ PYBIND11_MODULE(pyngcore, m) // NOLINT
2325
catch(...) {}
2426
ExportArray<int>(m);
2527
ExportArray<unsigned>(m);
28+
#if INTPTR_MAX != INT32_MAX
2629
ExportArray<size_t>(m);
30+
#endif
2731
ExportArray<double>(m);
2832
ExportArray<float>(m);
2933
ExportArray<signed short>(m);

libsrc/core/table.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/**************************************************************************/
99

1010
#include <atomic>
11+
#include <cstdint>
1112
#include <iostream>
1213
#include <optional>
1314

@@ -104,8 +105,10 @@ namespace ngcore
104105
{ return TablePrefixSum32 (FlatArray<unsigned> (entrysize.Size(), (unsigned int*)(int*)(entrysize.Addr(0)))); }
105106
NETGEN_INLINE size_t * TablePrefixSum (FlatArray<std::atomic<int>> entrysize)
106107
{ return TablePrefixSum32 (FlatArray<unsigned> (entrysize.Size(), (unsigned int*)(std::atomic<int>*)entrysize.Addr(0))); }
108+
#if INTPTR_MAX != INT32_MAX
107109
NETGEN_INLINE size_t * TablePrefixSum (FlatArray<size_t> entrysize)
108110
{ return TablePrefixSum64 (entrysize); }
111+
#endif
109112

110113

111114
/**

python/pyngcore/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
from .pyngcore import *
2+
3+
# <size_t> is the same as <unsigned int> on 32 bit arches
4+
# in which case Array_I_S is not defined by python_ngcore_export.cpp.
5+
# In this case identify it with Array_I_U.
6+
try: Array_I_S
7+
except NameError: Array_I_S=Array_I_U

0 commit comments

Comments
 (0)