[foreign-memaccess+abi] RFR: 8308858: FFM API and strings [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Wed Jun 7 15:37:22 UTC 2023


On Wed, 7 Jun 2023 15:30:25 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> > > Moreover, C more or less requires that a string, whether expressed as char* or wchar_t* cannot contain any element in the array that is a terminator char.
> > 
> > 
> > Why not then using two method:
> > ```
> > * get/set`CString`
> > 
> > * get/set `WString`
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > that both accept a generic char-set and let the user choose a suitable one as the _name_ of the charset do not really matter much (as long as both sides use the same byte -> char).
> 
> Not sure about this. Yes, we could have a getSingleByteString and getWideString. But it we also support charsets, then we have to worry about the compatibility of the provided charset with the given string method. E.g. what if I pass UTF-8 charset to getWideString? Or Utf-16 charset to getSingleByteString? The approach described here has a single parameter, which controls everything else.

I guess an alternate design would be to ask the user how many terminator chars there should be (where that has to be a power of two). Then we could allow any charsets, including non-sensical ones. Something like:


getString(long offset) // shortcut for getString(offset, defaultCharset(), 1);
getString(long offset, Charset charset, int numTermChars)

setString(long offset, String string) // shortcut for setString(offset, defaultCharset(), 1, string);
setString(long offset, Charset charset, int numTermChars, String string)

-------------

PR Comment: https://git.openjdk.org/panama-foreign/pull/836#issuecomment-1581073858


More information about the panama-dev mailing list