Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
VladimirIvan opened this issue Mar 14, 2017 · 1 comment
Open

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

VladimirIvan opened this issue Mar 14, 2017 · 1 comment

Comments

@VladimirIvan
Copy link

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.

@Alzathar
Copy link

The problem is related to the internal buffer used for the conversion. See this line: https://github.com/jaeandersson/swig/blob/matlab/Lib/matlab/matlabprimtypes.swg#L235

It might be needed to increase the size of this static buffer or use a dynamic array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants