-
Notifications
You must be signed in to change notification settings - Fork 65
Transcode strings to UTF-16 before passing them to MATLAB #80
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
Conversation
| mx = MxArray(pm) | ||
| ccall(:memcpy, Ptr{Void}, (Ptr{Void}, Ptr{Void}, UInt), data_ptr(mx), utf16string, | ||
| length(utf16string)*sizeof(UInt16)) | ||
| mx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return mx (trying to be consistent)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, but not exactly consistent elsewhere in the file.
|
|
||
| # char arrays and string | ||
|
|
||
| function mxarray(s::String) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
| pm = ccall(_mx_create_string, Ptr{Void}, (Ptr{UInt8},), s) | ||
| MxArray(pm) | ||
| utf16string = transcode(UInt16, s) | ||
| pm = ccall(_mx_create_char_array, Ptr{Void}, (mwSize, Ptr{mwSize},), 2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ptr is not actually so clear, since this is a Ptr{Void} to the MATLAB object and not the pointer to the data. pm is the variable name used by the other functions like this in the file.
| pm = ccall(_mx_create_char_array, Ptr{Void}, (mwSize, Ptr{mwSize},), 2, | ||
| _dims_to_mwSize((1, length(utf16string)))) | ||
| mx = MxArray(pm) | ||
| ccall(:memcpy, Ptr{Void}, (Ptr{Void}, Ptr{Void}, UInt), data_ptr(mx), utf16string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The convention is usually "try to adhere to a 92 character line length limit"
| function mxarray(s::String) | ||
| pm = ccall(_mx_create_string, Ptr{Void}, (Ptr{UInt8},), s) | ||
| MxArray(pm) | ||
| utf16string = transcode(UInt16, s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should prolly use mxChar here
| _dims_to_mwSize((1, length(utf16string)))) | ||
| mx = MxArray(pm) | ||
| ccall(:memcpy, Ptr{Void}, (Ptr{Void}, Ptr{Void}, UInt), data_ptr(mx), utf16string, | ||
| length(utf16string)*sizeof(UInt16)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mxChar here too prolly
Includes test from #78, which passes since we transcode the strings properly.