swig icon indicating copy to clipboard operation
swig copied to clipboard

std::string with more than 255 characters fails type check

Open VladimirIvan opened this issue 7 years ago • 1 comments

An std::string passed as an argument to a function from matlab fails the type check when the string length is greater than 255 characters. The SWIG_Matlab_ConvertPtrAndOwn method returns error in the first condition in it's body when checking for mxGetNumberOfElements(pm_ptr) != 1. The exact same code works correctly for shorter strings.

To reproduce this, compile the following input file:

%module test

%{

#include <string>
#include <iostream>
void myStringFunction(std::string str)
{
  std::cout << "Your string was:\n" << str << "\n";
}

%}

%include std_string.i

%inline %{
 void myStringFunction(std::string str);
%}

In matlab:

s=repmat('test string ',1,100);
test.myStringFunction(s(1:255)); % Works fine
test.myStringFunction(s); % Fails inside type check

I have compiled the code with c++11 flags enabled.

VladimirIvan avatar Mar 14 '17 12:03 VladimirIvan