summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2023-04-21 09:38:15 +1200
committerOlly Betts <olly@survex.com>2023-04-21 09:39:59 +1200
commit27f964987ac68c72453ca189831287511f07a5be (patch)
treecdf56fdaf61acc04f3462be2b1fe0a1e8f572f42 /Lib
parentc4f1975f9e81c47cdc724fc60b76029c668bdd79 (diff)
downloadswig-27f964987ac68c72453ca189831287511f07a5be.tar.gz
[OCaml] Fix reference typemaps for std::string
Fix warnings in the extend_template_method, li_std_string, and template_methods tests. std::string was missing a typecheck typemap. Add extend_template_method_runme.ml, li_std_string_runme.ml, and template_methods_runme.ml. Add INPUT, OUTPUT and INOUT typemaps for string & Use the INOUT typemap in the strings_test example. In the strings_test example, takes_and_gives_std_string() was relying on the silly fact that an argout typemap for string & was enabled by default. Remove the in, out, and typecheck typemaps for string &. Closes: #1439
Diffstat (limited to 'Lib')
-rw-r--r--Lib/ocaml/std_string.i40
1 files changed, 19 insertions, 21 deletions
diff --git a/Lib/ocaml/std_string.i b/Lib/ocaml/std_string.i
index 2564cfb38..08e304911 100644
--- a/Lib/ocaml/std_string.i
+++ b/Lib/ocaml/std_string.i
@@ -4,18 +4,11 @@
* SWIG typemaps for std::string
* ----------------------------------------------------------------------------- */
-// ------------------------------------------------------------------------
-// std::string is typemapped by value
-// This can prevent exporting methods which return a string
-// in order for the user to modify it.
-// However, I think I'll wait until someone asks for it...
-// ------------------------------------------------------------------------
-
%{
#include <string>
#include <vector>
%}
-
+
%include <exception.i>
%include <std_vector.i>
@@ -23,10 +16,10 @@ namespace std {
%naturalvar string;
%naturalvar wstring;
-
+
class string;
class wstring;
-
+
/* Overloading check */
%typemap(in) string {
if (caml_ptr_check($input))
@@ -44,15 +37,6 @@ class wstring;
}
}
-%typemap(in) string & ($*1_ltype temp) {
- if (caml_ptr_check($input)) {
- temp.assign((char *)caml_ptr_val($input,0), caml_string_len($input));
- $1 = &temp;
- } else {
- SWIG_exception(SWIG_TypeError, "string expected");
- }
-}
-
%typemap(in) string * ($*1_ltype *temp) {
if (caml_ptr_check($input)) {
temp = new $*1_ltype((char *)caml_ptr_val($input,0), caml_string_len($input));
@@ -66,8 +50,8 @@ class wstring;
delete temp;
}
-%typemap(argout) string & {
- swig_result = caml_list_append(swig_result,caml_val_string_len((*$1).c_str(), (*$1).size()));
+%typemap(out) const string & {
+ $result = caml_val_string_len((*$1).c_str(), (*$1).size());
}
%typemap(directorin) string {
@@ -99,6 +83,20 @@ class wstring;
%typemap(throws) string, const string & "SWIG_OCamlThrowException(SWIG_OCamlRuntimeException, $1.c_str());"
+%typemap(in) string &INPUT = const string &;
+%typemap(in, numinputs=0) string &OUTPUT ($*1_ltype temp)
+%{ $1 = &temp; %}
+%typemap(argout) string &OUTPUT {
+ swig_result = caml_list_append(swig_result, caml_val_string_len((*$1).c_str(), (*$1).size()));
+}
+%typemap(in) string &INOUT = const string &;
+%typemap(argout) string &INOUT = string &OUTPUT;
+
+%typemap(typecheck) string, const string & = char *;
+
+%typemap(throws) string, const string & {
+ SWIG_OCamlThrowException(SWIG_OCamlRuntimeException, $1.c_str());
+}
}
#ifdef ENABLE_CHARPTR_ARRAY