about summary refs log tree commit diff
path: root/std_string_view.i
diff options
context:
space:
mode:
authorArun Isaac2026-10-03 00:38:00 +0100
committerArun Isaac2026-10-03 00:40:21 +0100
commit7b4221ba7033612434f95c92880df8cf4cf125e5 (patch)
tree6fe1aa67ebde44b6c427d72a17ec9653857f26d6 /std_string_view.i
parenta17afe81118c7167bc188545a65bc45eda0f40eb (diff)
downloadguile-xapian-7b4221ba7033612434f95c92880df8cf4cf125e5.tar.gz
guile-xapian-7b4221ba7033612434f95c92880df8cf4cf125e5.tar.lz
guile-xapian-7b4221ba7033612434f95c92880df8cf4cf125e5.zip
Use latest std_string_view.i from swig upstream.
This version of std_string_view.i is not yet a part of any released
version of swig. swig > 4.5.0 should have it.
Diffstat (limited to 'std_string_view.i')
-rw-r--r--std_string_view.i49
1 files changed, 22 insertions, 27 deletions
diff --git a/std_string_view.i b/std_string_view.i
index 585281f..cd3027e 100644
--- a/std_string_view.i
+++ b/std_string_view.i
@@ -13,51 +13,46 @@ namespace std {
 
   %naturalvar string_view;
 
-  %typemap(in) string_view (std::string temp) {
-    char *ptr = scm_to_stringn($input, NULL, "utf8",
-                               SCM_FAILED_CONVERSION_ERROR);
-    temp.assign(ptr);
-    SWIG_free(ptr);
-    $1 = std::string_view(temp);
+  %typemap(in) string_view (char *$1_ptr) {
+    size_t $1_len;
+    $1_ptr = scm_to_utf8_stringn($input, &$1_len);
+    $1 = std::string_view($1_ptr, $1_len);
   }
 
+  %typemap(freearg) string_view %{
+    SWIG_free($1_ptr);
+  %}
+
   %typemap(out) string_view %{
-    $result = scm_from_stringn($1.data(), $1.size(), "utf8",
-                               SCM_FAILED_CONVERSION_ERROR);
-    %}
+    $result = scm_from_utf8_stringn($1.data(), $1.size());
+  %}
 
-  %typemap(in) const string_view& (std::string temp, $*1_ltype view) {
-    char *ptr = scm_to_stringn($input, NULL, "utf8",
-                               SCM_FAILED_CONVERSION_ERROR);
-    temp.assign(ptr);
-    SWIG_free(ptr);
-    view = std::string_view(temp);
+  %typemap(in) const string_view& (char *$1_ptr, $*1_ltype view) {
+    size_t $1_len;
+    $1_ptr = scm_to_utf8_stringn($input, &$1_len);
+    view = std::string_view($1_ptr, $1_len);
     $1 = &view;
   }
 
   %typemap(out) const string_view& %{
-    $result = scm_from_stringn($1->data(), $1->size(), "utf8",
-                               SCM_FAILED_CONVERSION_ERROR);
-    %}
+    $result = scm_from_utf8_stringn($1->data(), $1->size());
+  %}
 
   %typemap(varout) string_view %{
-    $result = scm_from_stringn($1.data(), $1.size(), "utf8",
-                               SCM_FAILED_CONVERSION_ERROR);
-    %}
+    $result = scm_from_utf8_stringn($1.data(), $1.size());
+  %}
 
   // for throwing of any kind of string_view, string_view ref's and
   // string_view pointers we convert all to Guile strings
   %typemap(throws) string_view, string_view&, const string_view& %{
     scm_throw(scm_from_locale_symbol("swig-exception"),
-              scm_list_1(scm_from_stringn($1.data(), $1.size(), "utf8",
-                                          SCM_FAILED_CONVERSION_ERROR)));
-    %}
+              scm_list_1(scm_from_utf8_stringn($1.data(), $1.size())));
+  %}
 
   %typemap(throws) string_view*, const string_view* %{
     scm_throw(scm_from_locale_symbol("swig-exception"),
-              scm_list_1(scm_from_stringn($1->data(), $1->size(), "utf8",
-                                          SCM_FAILED_CONVERSION_ERROR)));
-    %}
+              scm_list_1(scm_from_utf8_stringn($1->data(), $1->size())));
+  %}
 
   %typemap(typecheck,precedence=SWIG_TYPECHECK_STRINGVIEW) string_view, const string_view& {
     $1 = scm_is_string($input);