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

Notice the "!" where we should see "中". When using 2012b on OS X I get the correct "中".
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.
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.
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"]
Worked around by using evalc() https://github.com/rsmenon/MATLink/commit/d5fe5437c443c108eb859e105926bd0cb81706a7
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
Can you elaborate on the crash, and give an example to reproduce it?
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)
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)