MATLink icon indicating copy to clipboard operation
MATLink copied to clipboard

engEvalaute[] does not return proper UTF-8 when using R2013a

Open szhorvat opened this issue 12 years ago • 8 comments

Screen Shot 2013-03-31 at 14 33 58

Notice the "!" where we should see "中". When using 2012b on OS X I get the correct "中".

szhorvat avatar Mar 31 '13 18:03 szhorvat

It seems this works correctly on:

  • OS X R2012b, Linux R2013a

It fails on:

  • OS X R2013a, Windows R2013a

Sending UTF-8 data to engEvaluate[] may crash on Windows R2013a which makes this issue more serious than just an annoyance.

szhorvat avatar Mar 31 '13 19:03 szhorvat

To work around this on Windows (where it may cause crashes!) it may be necessary to wrap everything sent to MEvaluate[] in eval or evalc, like this (siplified):

MEvaluate[code_] := (MSet["code", code]; engEvaluate["s = evalc(code);"]; engEvaluate["clear code"]; MGet["s"])

Do you see any potential problems with this approach? Performance hits maybe?

Unicode in scripts may need to be handled differently.

szhorvat avatar Apr 03 '13 15:04 szhorvat

Using evalc() disables JIT compilation and makes performance significantly worse. Thus it's not a viable solution.

Pasteable test code:

mEvaluate[code_String] := (MSet["code", code]; 
  MATLink`Engine`engEvaluate["result = evalc(code); clear code"]; 
  MGet["result"])

mEvaluate[" x=zeros(1e7,1);
  tic;
  for i=1:1e7
  x(i)=rand();
  end
  toc"]

MEvaluate[" x=zeros(1e7,1);
  tic;
  for i=1:1e7
  x(i)=rand();
  end
  toc"]

szhorvat avatar Apr 03 '13 15:04 szhorvat

Worked around by using evalc() https://github.com/rsmenon/MATLink/commit/d5fe5437c443c108eb859e105926bd0cb81706a7

szhorvat avatar Apr 09 '13 03:04 szhorvat

Since we reverted evalc for now (because it prints HTML errors & help), I'm reopening this. Also, it crashes on my OS X 10.8.3, MATLAB 2013a

rsmenon avatar Apr 11 '13 21:04 rsmenon

Can you elaborate on the crash, and give an example to reproduce it?

szhorvat avatar Apr 11 '13 21:04 szhorvat

MEvaluate["x='aéîøü'"] is sufficient to crash it. It gives a LinkObject::linkd error (which btw, is also on my todo list for today to return sensible errors)

rsmenon avatar Apr 11 '13 21:04 rsmenon

It looks like unicode wouldn't work with several MATLAB or OS versions in the initial release anyway, so I am sending data to Mathematica as ASCII now. This will at least prevent crashes similar to what you saw.

https://github.com/rsmenon/MATLink/commit/fcceb71ef9387e2a7745c4737e733f481624844c

(binary not checked in for now, you'll need to recompile yourself)

szhorvat avatar Apr 11 '13 22:04 szhorvat