Remove the code related to "_result_ref" which was confusing and plain wrong, as it generated something that compiled but crashed during run-time due to the use of a pointer to an already destroyed stack object. Instead, correct the "out" typemap to create a new copy of the object, which mostly works fine on its own, except that it depends on using SwigValueWrapper if necessary, so add the call to cplus_value_type() does this. This also required removing the code resolving typedefs in the "type" attribute because it confused the base class logic and still needs an explicit cast to the actual return type due to the use of (and probable bug in) get_wrapper_func_return_type(). These changes mean that "cppouttype" typemap is not used any longer, so remove it too. A couple more tests pass now.
57 lines
1 KiB
OpenEdge ABL
57 lines
1 KiB
OpenEdge ABL
%{
|
|
#include <string>
|
|
%}
|
|
|
|
namespace std {
|
|
|
|
// use "const string &" typemaps for wrapping member strings
|
|
%naturalvar string;
|
|
|
|
class string;
|
|
|
|
%typemap(ctype) string "char *"
|
|
%typemap(ctype) string * "char *"
|
|
%typemap(ctype) string & "char *"
|
|
%typemap(ctype) const string & "char *"
|
|
|
|
%typemap(in) string {
|
|
if ($input) {
|
|
$1.assign($input);
|
|
}
|
|
else {
|
|
$1.resize(0);
|
|
}
|
|
}
|
|
|
|
%typemap(in) const string &, string *, string & {
|
|
if ($input) {
|
|
$1 = new std::string($input);
|
|
}
|
|
else {
|
|
$1 = new std::string();
|
|
$1->resize(0);
|
|
}
|
|
}
|
|
|
|
%typemap(freearg) const string &, string *, string & {
|
|
if ($1)
|
|
delete $1;
|
|
}
|
|
|
|
%typemap(out) string {
|
|
const char *str = cppresult.c_str();
|
|
size_t len = strlen(str);
|
|
$result = (char *) malloc(len + 1);
|
|
memcpy($result, str, len);
|
|
$result[len] = '\0';
|
|
}
|
|
|
|
%typemap(out) const string &, string *, string & {
|
|
const char *str = cppresult->c_str();
|
|
size_t len = strlen(str);
|
|
$result = (char *) malloc(len + 1);
|
|
memcpy($result, str, len);
|
|
$result[len] = '\0';
|
|
}
|
|
|
|
}
|