Fix for using more than one std::string_view type in a method

Fixes #2844
This commit is contained in:
William S Fulton 2024-03-27 18:58:14 +00:00
parent 3d46896e1a
commit 6226d58065
4 changed files with 18 additions and 10 deletions

View File

@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.3.0 (in progress) Version 4.3.0 (in progress)
=========================== ===========================
2024-03-27: wsfulton
[Python] #2844 Fix for using more than one std::string_view type in a method.
2024-03-27: wsfulton 2024-03-27: wsfulton
[R] #2847 Add missing std::vector<long> and std::vector<long long> typemaps [R] #2847 Add missing std::vector<long> and std::vector<long long> typemaps
which were missing depending on whether or not SWIGWORDSIZE64 was defined. which were missing depending on whether or not SWIGWORDSIZE64 was defined.

View File

@ -52,6 +52,9 @@ std::string_view test_reference_input(std::string_view &input) {
return input; 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){ void test_throw() TESTCASE_THROW1(std::string_view){
static std::string_view x = "test_throw message"; static std::string_view x = "test_throw message";
throw x; throw x;

View File

@ -35,6 +35,8 @@ stringPtr = cpp17_string_view.test_reference_out()
cpp17_string_view.test_reference(stringPtr) cpp17_string_view.test_reference(stringPtr)
cpp17_string_view.test_multiple("fee", "fi", "fo", "fum")
# Global variables # Global variables
s = "initial string" s = "initial string"
if cpp17_string_view.ConstGlobalString != "const global string": if cpp17_string_view.ConstGlobalString != "const global string":

View File

@ -28,13 +28,13 @@ namespace std {
#endif #endif
%} %}
%typemap(in) string_view (PyObject *bytes = NULL) %{ %typemap(in) string_view (PyObject *bytes = NULL) {
Py_ssize_t len; Py_ssize_t len;
#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR %#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
const char *p = PyBytes_AsString($input); const char *p = PyBytes_AsString($input);
if (!p) SWIG_fail; if (!p) SWIG_fail;
len = PyBytes_Size($input); len = PyBytes_Size($input);
#else %#else
const char *p; const char *p;
if (PyUnicode_Check($input)) { if (PyUnicode_Check($input)) {
p = SWIG_PyUnicode_AsUTF8AndSize($input, &len, &bytes); p = SWIG_PyUnicode_AsUTF8AndSize($input, &len, &bytes);
@ -44,21 +44,21 @@ namespace std {
if (!p) SWIG_fail; if (!p) SWIG_fail;
len = PyBytes_Size($input); len = PyBytes_Size($input);
} }
#endif %#endif
$1 = std::string_view(p, len); $1 = std::string_view(p, len);
%} }
%typemap(freearg) string_view %{ %typemap(freearg) string_view %{
SWIG_Py_XDECREF(bytes$argnum); 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; Py_ssize_t len;
#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR %#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
const char *p = PyBytes_AsString($input); const char *p = PyBytes_AsString($input);
if (!p) SWIG_fail; if (!p) SWIG_fail;
len = PyBytes_Size($input); len = PyBytes_Size($input);
#else %#else
const char *p; const char *p;
if (PyUnicode_Check($input)) { if (PyUnicode_Check($input)) {
p = SWIG_PyUnicode_AsUTF8AndSize($input, &len, &bytes); p = SWIG_PyUnicode_AsUTF8AndSize($input, &len, &bytes);
@ -68,10 +68,10 @@ namespace std {
if (!p) SWIG_fail; if (!p) SWIG_fail;
len = PyBytes_Size($input); len = PyBytes_Size($input);
} }
#endif %#endif
temp = std::string_view(p, len); temp = std::string_view(p, len);
$1 = &temp; $1 = &temp;
%} }
%typemap(freearg) const string_view & %{ %typemap(freearg) const string_view & %{
SWIG_Py_XDECREF(bytes$argnum); SWIG_Py_XDECREF(bytes$argnum);