Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/mxarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ const _mx_create_logical_scalar = mxfunc(:mxCreateLogicalScalar)
const _mx_create_sparse = mxfunc(:mxCreateSparse_730)
const _mx_create_sparse_logical = mxfunc(:mxCreateSparseLogicalMatrix_730)

const _mx_create_string = mxfunc(:mxCreateString)
#const _mx_create_char_array = mxfunc(:mxCreateCharArray_730)
# const _mx_create_string = mxfunc(:mxCreateString)
const _mx_create_char_array = mxfunc(:mxCreateCharArray_730)

const _mx_create_cell_array = mxfunc(:mxCreateCellArray_730)

Expand Down Expand Up @@ -406,8 +406,13 @@ end
# char arrays and string

function mxarray(s::String)
Copy link
Member Author

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)
Copy link
Collaborator

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

pm = ccall(_mx_create_char_array, Ptr{Void}, (mwSize, Ptr{mwSize},), 2,
Copy link
Member Author

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.

_dims_to_mwSize((1, length(utf16string))))
mx = MxArray(pm)
ccall(:memcpy, Ptr{Void}, (Ptr{Void}, Ptr{Void}, UInt), data_ptr(mx), utf16string,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

length(utf16string)*sizeof(UInt16))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mxChar here too prolly

mx
Copy link
Collaborator

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)

Copy link
Member Author

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.

end

# cell arrays
Expand Down
5 changes: 5 additions & 0 deletions test/mxarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ delete(x)
@test isequal(y["efg"], [1, 2, 3])
@test y["xyz"] == "MATLAB"

# Test string encoding
str = "λ α γ"
@test jstring(mxarray(str)) == str
@test mat"all($str == [955 32 945 32 947])"

gc()