Fix build with SWIG 4.4

SWIG 4.4 has dropped the usage of SWIG_NULLPTR again, which means we can't
rely on its presence to identify SWIG >= 4.2.0

Generate a swig_version.h by parsing the output of `swig -version` and
writing this in a hex representation

Fixes #1979
This commit is contained in:
Dominique Leuenberger
2025-12-02 11:10:27 +01:00
committed by Alexey Sokolov
parent 18416d7df6
commit 49af1c8d53
3 changed files with 71 additions and 8 deletions

View File

@@ -49,6 +49,8 @@ print $out <<'EOF';
* Don't change it manually. *
***************************************************************************/
#include "swig_version.h"
namespace {
inline swig_type_info* ZNC_SWIG_pchar_descriptor(void) {
static int init = 0;
@@ -60,11 +62,8 @@ namespace {
return info;
}
// SWIG 4.2.0 replaced SWIG_Python_str_AsChar with SWIG_PyUnicode_AsUTF8AndSize.
// SWIG doesn't provide any good way to detect SWIG version (other than parsing
// `swig -version`), but it also introduced SWIG_NULLPTR in 4.2.0.
// So let's abuse that define to do different code for new SWIG.
#ifdef SWIG_NULLPTR
// SWIG_VERSION is defined as 0x040200 for 4.2.0.
#if defined(SWIG_VERSION) && SWIG_VERSION >= 0x040200
// This is copied/adapted from SWIG 4.2.0 from pystrings.swg
inline int ZNC_SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc) {
#if PY_VERSION_HEX>=0x03000000