octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #54170] java.lang.String.toCharArray result in


From: Andrew Janke
Subject: [Octave-bug-tracker] [bug #54170] java.lang.String.toCharArray result incorrect conversion to char matrix
Date: Mon, 25 Jun 2018 06:30:05 -0400 (EDT)
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36

Follow-up Comment #14, bug #54170 (project octave):

Here's a concrete example of what I'm thinking of with respect to "I/O
buffers":

In Matlab, it is impossible to use the java.io.Reader API from M-files.

This is because java.io.Reader takes a pass-by-reference char[] as an output
parameter. See the java.io.Reader Javadoc
<https://docs.oracle.com/javase/7/docs/api/java/io/Reader.html> and scroll
down to the "read(char[] cbuf, ...)" methods.


public abstract class Reader
[...]
int read(char[] cbuf)
[...]
abstract int    read(char[] cbuf, int off, int len)
[...]


In Matlab, because of the auto-conversion between Matlab char and Java char[],
you can't get at changes that BufferedReader.read(...) makes to the `cbuf`
that you pass in, because Matlab treats it as a pass-by-value Matlab char
object, and object identity is lost. To use that char[] as a buffer, it would
have to be treated as a mutable object, with just the object reference passed
around.

I'm not saying that this is a reason to do something different with your API:
if Matlab compatibility is a priority for you, this is probably something you
have to give up. (Or introduce a custom non-autoconverting
`java_primitive_array_reference` type or something.) Just trying to make it
clear what I'm talking about.

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?54170>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]