Fix for using more than one std::string_view type in a method
Fixes #2844
diff --git a/CHANGES.current b/CHANGES.current
index 594d957..c284052 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -8,6 +8,9 @@
===========================
2024-03-27: wsfulton
+ [Python] #2844 Fix for using more than one std::string_view type in a method.
+
+2024-03-27: wsfulton
[R] #2847 Add missing std::vector<long> and std::vector<long long> typemaps
which were missing depending on whether or not SWIGWORDSIZE64 was defined.
diff --git a/Examples/test-suite/cpp17_string_view.i b/Examples/test-suite/cpp17_string_view.i
index ae10837..aa9e0f0 100644
--- a/Examples/test-suite/cpp17_string_view.i
+++ b/Examples/test-suite/cpp17_string_view.i
@@ -52,6 +52,9 @@
return input;
}
+void test_multiple(std::string_view aa, std::string_view bb, const std::string_view &cc, const std::string_view &dd) {
+}
+
void test_throw() TESTCASE_THROW1(std::string_view){
static std::string_view x = "test_throw message";
throw x;
diff --git a/Examples/test-suite/python/cpp17_string_view_runme.py b/Examples/test-suite/python/cpp17_string_view_runme.py
index 0f1be15..71b5688 100644
--- a/Examples/test-suite/python/cpp17_string_view_runme.py
+++ b/Examples/test-suite/python/cpp17_string_view_runme.py
@@ -35,6 +35,8 @@
cpp17_string_view.test_reference(stringPtr)
+cpp17_string_view.test_multiple("fee", "fi", "fo", "fum")
+
# Global variables
s = "initial string"
if cpp17_string_view.ConstGlobalString != "const global string":
diff --git a/Lib/python/std_string_view.i b/Lib/python/std_string_view.i
index 1c0d64a..702dd9b 100644
--- a/Lib/python/std_string_view.i
+++ b/Lib/python/std_string_view.i
@@ -28,13 +28,13 @@
#endif
%}
- %typemap(in) string_view (PyObject *bytes = NULL) %{
+ %typemap(in) string_view (PyObject *bytes = NULL) {
Py_ssize_t len;
-#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
+%#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
const char *p = PyBytes_AsString($input);
if (!p) SWIG_fail;
len = PyBytes_Size($input);
-#else
+%#else
const char *p;
if (PyUnicode_Check($input)) {
p = SWIG_PyUnicode_AsUTF8AndSize($input, &len, &bytes);
@@ -44,21 +44,21 @@
if (!p) SWIG_fail;
len = PyBytes_Size($input);
}
-#endif
+%#endif
$1 = std::string_view(p, len);
- %}
+ }
%typemap(freearg) string_view %{
SWIG_Py_XDECREF(bytes$argnum);
%}
- %typemap(in) const string_view & ($*1_ltype temp, PyObject *bytes = NULL) %{
+ %typemap(in) const string_view & ($*1_ltype temp, PyObject *bytes = NULL) {
Py_ssize_t len;
-#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
+%#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
const char *p = PyBytes_AsString($input);
if (!p) SWIG_fail;
len = PyBytes_Size($input);
-#else
+%#else
const char *p;
if (PyUnicode_Check($input)) {
p = SWIG_PyUnicode_AsUTF8AndSize($input, &len, &bytes);
@@ -68,10 +68,10 @@
if (!p) SWIG_fail;
len = PyBytes_Size($input);
}
-#endif
+%#endif
temp = std::string_view(p, len);
$1 = &temp;
- %}
+ }
%typemap(freearg) const string_view & %{
SWIG_Py_XDECREF(bytes$argnum);