Feature regarding structures in Mercury

Thanks for fixing this! Is it possible to get a copy of the build to test?

I’ll send you one, when we have a new one later today.

1 Like

Up in your personal downlaods.

1 Like

I was able to confirm the size is now as expected within the struct, along with declaration of the multidimensional array. However are all arrays with defined sizes allocated as dynamic? For instance, Dim a(5) As Integer or Dim b(5,5) As Integer outside of a struct returns a size of 8. I would think these would be stack allocated and fixed.

I agree they should be, unless this is VB-speciifc behavior for them to not be… @Diego_Navarro ?

Will check, they should be fixed size in this case.

2 Likes

By the way, I’ve just posted a finding regarding Swift which reminded me to clarify that although single dimension arrays now show the correct size in a struct, multidimensional arrays still allocate as a pointer within structures.

That might be correct, depending on how the array is defined. I’m not super familiar with Mercury, but for example in Oxygene>

x: array[0..4, 0..4] of Byte

is a continuous 5x5 = 25 byte block, but

x: array [0…4] of array [0…4] of Byte

will need be an array of pointers to arrays that need to be explicitly alloc’ed.

Update it seems tis differs between platforms — which is not good. I’ll log an issue to get this clarified and made consistent.

Logged as bugs://E26744.

Will this be able to be implemented, especially for the Island and Cocoa backends? I remember in .NET that multiple marshalling attributes were in use for structures.

Ive loged an issue for this to be looked at. on Island, it seems to behave correctly, .NET is the issue right now (I didn’t test Cooper, yet)

      var y: array[0..40, 0..40] of Byte; // JE19 Multi-dimensional arrays are not supported for Java

this one is by-design, as far as I know.

var z: array [0..40] of array [0..40] of Byte;

behaves correctly on Cooper (same as Island, its pre-initialized), so its only .NERT thats the issue, it seems.

Okay, however on the latest build you uploaded it still allocates space only for a pointer inside of the structure if it’s a multidimensional array. For instance:

Structure test
	 Dim x,y,z As Double
End Structure

<Packed>
Structure test2
	 Dim v(2,2) As test
	 Dim t As Byte
End Structure

test2’s size still appears as 9 instead of 97

@Diego_Navarro ?

You are right, multidimensional array is still 8 bytes, will check why…

Regards

1 Like

I checked in a fix to address the first issue, sized arrays allocated as pointer instead the correct size.
Now should be correct.

Note it is pending E26744 — Inconsistent array sizes & allocation paradigms

2 Likes

bugs://E26744 was closed as fixed.

Is there a build available to test this fix?

I can put one in your Personal Downloads folder, later today.

1 Like

Done.