Skip to content

Commit

Permalink
fix 32-bit usage of size_t
Browse files Browse the repository at this point in the history
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
  • Loading branch information
drew-parsons committed Jan 5, 2025
1 parent 63cb566 commit 84fc680
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libsrc/core/python_ngcore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define NETGEN_CORE_PYTHON_NGCORE_HPP

#include "ngcore_api.hpp" // for operator new
#include <cstdint>
#include <pybind11/pybind11.h>
#include <pybind11/operators.h>
#include <pybind11/numpy.h>
Expand Down Expand Up @@ -182,10 +183,12 @@ namespace ngcore
static std::string GetName() { return "D"; }
};

#if INTPTR_MAX != INT32_MAX
template<>
struct PyNameTraits<size_t> {
static std::string GetName() { return "S"; }
};
#endif

template<typename T>
struct PyNameTraits<std::shared_ptr<T>> {
Expand Down
4 changes: 4 additions & 0 deletions libsrc/core/python_ngcore_export.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <cstdint>

#include "python_ngcore.hpp"
#include "bitarray.hpp"
#include "taskmanager.hpp"
Expand All @@ -23,7 +25,9 @@ PYBIND11_MODULE(pyngcore, m) // NOLINT
catch(...) {}
ExportArray<int>(m);
ExportArray<unsigned>(m);
#if INTPTR_MAX != INT32_MAX
ExportArray<size_t>(m);
#endif
ExportArray<double>(m);
ExportArray<float>(m);
ExportArray<signed short>(m);
Expand Down
3 changes: 3 additions & 0 deletions libsrc/core/table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/**************************************************************************/

#include <atomic>
#include <cstdint>
#include <iostream>
#include <optional>

Expand Down Expand Up @@ -104,8 +105,10 @@ namespace ngcore
{ return TablePrefixSum32 (FlatArray<unsigned> (entrysize.Size(), (unsigned int*)(int*)(entrysize.Addr(0)))); }
NETGEN_INLINE size_t * TablePrefixSum (FlatArray<std::atomic<int>> entrysize)
{ return TablePrefixSum32 (FlatArray<unsigned> (entrysize.Size(), (unsigned int*)(std::atomic<int>*)entrysize.Addr(0))); }
#if INTPTR_MAX != INT32_MAX
NETGEN_INLINE size_t * TablePrefixSum (FlatArray<size_t> entrysize)
{ return TablePrefixSum64 (entrysize); }
#endif


/**
Expand Down
6 changes: 6 additions & 0 deletions python/pyngcore/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
from .pyngcore import *

# <size_t> is the same as <unsigned int> 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

0 comments on commit 84fc680

Please sign in to comment.