Adding optional UUID to layouts

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Tue Mar 24 14:18:28 UTC 2020


On 24/03/2020 12:14, Ty Young wrote:
> MemoryLayout.ofValueBits(1, 
> ByteOrder.nativeOrder()).withName("bool").withUuid(UUID.randomUUID()); 

What I'm saying is that withName is just a withAttribute(NAME, "bool"), 
where an attribute can be any Java object that implements the Constable 
interface. So it might be possible to do something like

layout.withAttribute("library", "OpenGL")

and that will make all layouts generated in a given extraction run 
'unique' (since equals() and hashCode() take attributes into account).

See:

https://git.openjdk.java.net/panama-foreign/pull/64

Which Jorn has timely submitted :-)

In general - we're NOT going to add a UUID to add layouts just because 
in some cases it feels it's handy to have one. But that's why the layout 
attribute machinery comes in place - to add extra side-info to the 
layout w/o necessarily making the API more complex with things that most 
users won't even care about.

So, your question can be rephrased as: can jextract please attach a 
standard layout attribute to all the layout it emits during a single 
run, so that layouts from library A cannot be confused with layouts 
coming from library B?

Right now we haven't discussed anything in that direction - the new API 
(see above PR) makes it possible; another possibility is that your API 
could be in charge of the decorating process (e.g. if your API only 
works with layouts which have an 'uuid' then have a function which takes 
a layout and returns a new layout with the desired uuid embedded as a 
layout attribute).

Maurizio



More information about the panama-dev mailing list