ccan.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* dgraph, tlist, tcon: MSVC error due to array of flexible structs
@ 2016-09-23  4:31 Kevin Locke
  2016-09-27  4:45 ` David Gibson
  2017-08-01  5:22 ` David Gibson
  0 siblings, 2 replies; 6+ messages in thread
From: Kevin Locke @ 2016-09-23  4:31 UTC (permalink / raw)
  To: ccan

Hi all,

Building dgraph using Microsoft Visual C++ produces the following
error:

dgraph.h(25): error C2233: 'edge': arrays of objects containing
zero-size arrays are illegal

The issue is that MSVC supports flexible array members, but does not
support arrays of structs with flexible array members.  My
understanding is that such support is not required by C99 or C11, but
I don't know whether such support is common beyond Clang/GCC.

Is there any interest in supporting such compilers?  If so, I can see
a few potential fixes:

1. Change TCON to use flexible array members only when the compiler
supports arrays of structs with flexible array members.  This is an
easy fix, but wastes space for every TCON/TLIST usage on such
compilers.

2. Have TCON (and TLIST) provide an alternative macro which uses
flexible array members only when supported in arrays, and use that in
dgraph.  It would increase the API and duplicate a bit of code, but
would only waste space when TCON/TLIST are placed in arrays.

2. Replace the 2-element edge array in struct dgraph_node with
separate fields edge_from and edge_to.  This complicates the logic a
bit, since it is no longer symmetric with dgraph_edge.  It would also
be an incompatible API change.

3. Change TLIST to use TCON_WRAP?  I don't understand TLIST/TCON well
enough to know if this is really an option.  Hopefully an expert can
weigh in here.

Thoughts?

-- 
Cheers,      |  kevin@kevinlocke.name    | XMPP: kevin@kevinlocke.name
Kevin        |  https://kevinlocke.name  | IRC:   kevinoid on freenode
_______________________________________________
ccan mailing list
ccan@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/ccan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: dgraph, tlist, tcon: MSVC error due to array of flexible structs
  2016-09-23  4:31 dgraph, tlist, tcon: MSVC error due to array of flexible structs Kevin Locke
@ 2016-09-27  4:45 ` David Gibson
  2016-09-28  2:10   ` Rusty Russell
  2017-08-01  5:22 ` David Gibson
  1 sibling, 1 reply; 6+ messages in thread
From: David Gibson @ 2016-09-27  4:45 UTC (permalink / raw)
  To: ccan


[-- Attachment #1.1: Type: text/plain, Size: 3852 bytes --]

On Thu, Sep 22, 2016 at 10:31:16PM -0600, Kevin Locke wrote:
> Hi all,
> 
> Building dgraph using Microsoft Visual C++ produces the following
> error:
> 
> dgraph.h(25): error C2233: 'edge': arrays of objects containing
> zero-size arrays are illegal
> 
> The issue is that MSVC supports flexible array members, but does not
> support arrays of structs with flexible array members.

Right, which actually makes sense - how can you have an array when you
have no way of knowing how much space to allocate for the flexible
members.

In fact what TCON really wants here is a true 0-element array, rather
than a flexible array member, which is not something supported by the
C standard, or many compilers, although gcc has it (predating standard
flexible members).

> My
> understanding is that such support is not required by C99 or C11, but
> I don't know whether such support is common beyond Clang/GCC.
> 
> Is there any interest in supporting such compilers?  If so, I can see
> a few potential fixes:
> 
> 1. Change TCON to use flexible array members only when the compiler
> supports arrays of structs with flexible array members.  This is an
> easy fix, but wastes space for every TCON/TLIST usage on such
> compilers.
> 
> 2. Have TCON (and TLIST) provide an alternative macro which uses
> flexible array members only when supported in arrays, and use that in
> dgraph.  It would increase the API and duplicate a bit of code, but
> would only waste space when TCON/TLIST are placed in arrays.
> 
> 2. Replace the 2-element edge array in struct dgraph_node with
> separate fields edge_from and edge_to.  This complicates the logic a
> bit, since it is no longer symmetric with dgraph_edge.  It would also
> be an incompatible API change.

C11 only allows flexible array members as the last element of a
structure for obvious reasons.  For the same reason, a structure
containing a flexible array member is only allowed as the last element
of any containing structure.

I doubt the result would work even on gcc (it was exactly this case
that caused me to write TCON_WRAP()).  It's almost certain not to work
on a compiler that doesn't support flexible array members in arrays.

> 3. Change TLIST to use TCON_WRAP?  I don't understand TLIST/TCON well
> enough to know if this is really an option.  Hopefully an expert can
> weigh in here.

So.. in a way this has already been done.  The tlist2 module is
basically exactly like the tlist module, but using TCON_WRAP instead
of TCON.

IIRC, Rusty didn't want to simply replace the tlist module in case
there could be subtle brekages in usage.

So converting dgraph to use tlist2 instead of tlist should do the
trick.

...

I had a quick look at this.  It is a little fiddly.  In addition to
using TCON_WRAP(), tlist2 also uses the tcon_container_of() stuff so
that less arguments are needed when using the lists.

This means that the from and to edge lists would need slightly
different types, so we'd have to implement them as separate fields in
addition to the other changes.  That in turn means there are some
places in draph where we'd have to have an actual if / switch instead
of just looking up the right edge list by the DGRAPH_{FROM,TO} enum.

I don't think there's any showstopper there, just some fiddliness.


So that leaves the question of which is the easier approach:

  * Change dgraph to use tlist2, including separate from and to lists

or

  * Change tlist in place to use TCON_WRAP more minimally (avoid the
    flexible array member, but don't use the TCON_CONTAINER() stuff)

> Thoughts?



-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
ccan mailing list
ccan@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/ccan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: dgraph, tlist, tcon: MSVC error due to array of flexible structs
  2016-09-27  4:45 ` David Gibson
@ 2016-09-28  2:10   ` Rusty Russell
  2016-09-28  3:12     ` David Gibson
  0 siblings, 1 reply; 6+ messages in thread
From: Rusty Russell @ 2016-09-28  2:10 UTC (permalink / raw)
  To: David Gibson, ccan

David Gibson <david@gibson.dropbear.id.au> writes:
> IIRC, Rusty didn't want to simply replace the tlist module in case
> there could be subtle brekages in usage.

BTW, I think this gives us good reason to simply mv tlist2 -> tlist and
fix up the callers.

Cheers,
Rusty.
_______________________________________________
ccan mailing list
ccan@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/ccan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: dgraph, tlist, tcon: MSVC error due to array of flexible structs
  2016-09-28  2:10   ` Rusty Russell
@ 2016-09-28  3:12     ` David Gibson
  0 siblings, 0 replies; 6+ messages in thread
From: David Gibson @ 2016-09-28  3:12 UTC (permalink / raw)
  To: Rusty Russell; +Cc: ccan


[-- Attachment #1.1: Type: text/plain, Size: 1437 bytes --]

On Wed, Sep 28, 2016 at 11:40:43AM +0930, Paul 'Rusty' Russell wrote:
> David Gibson <david@gibson.dropbear.id.au> writes:
> > IIRC, Rusty didn't want to simply replace the tlist module in case
> > there could be subtle brekages in usage.
> 
> BTW, I think this gives us good reason to simply mv tlist2 -> tlist and
> fix up the callers.

Hm.. perhaps.  As noted in another mail, converting dgraph at least to
tlist2 might be a bit ugly.  The two lists it keeps would now have
different types, so it couldn't just keep them as an array, which
might make things less natural in other places.

Maybe any extra switch/ifs will be cancelled out by removing (or
folding into) existing ones.

It would also be possible to make a more minimal conversion of tlist
to TCON_WRAP() which keeps the tlist interface unchanged.

I am thinking we should probably phase out TCON in favour of TCON_WRAP
everywhere - that flexible array member is causing repeated trouble.

Another thing we might want as an interim approach is to add a new
config test for zero-length array members (as opposed to flexible
array members).  TCON could then use those when available and fall
back to the space wasting 1-member array method otherwise.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
ccan mailing list
ccan@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/ccan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: dgraph, tlist, tcon: MSVC error due to array of flexible structs
  2016-09-23  4:31 dgraph, tlist, tcon: MSVC error due to array of flexible structs Kevin Locke
  2016-09-27  4:45 ` David Gibson
@ 2017-08-01  5:22 ` David Gibson
  2017-08-02  5:38   ` Kevin Locke
  1 sibling, 1 reply; 6+ messages in thread
From: David Gibson @ 2017-08-01  5:22 UTC (permalink / raw)
  To: ccan


[-- Attachment #1.1: Type: text/plain, Size: 1885 bytes --]

On Thu, Sep 22, 2016 at 10:31:16PM -0600, Kevin Locke wrote:
1;4803;0c> Hi all,
> 
> Building dgraph using Microsoft Visual C++ produces the following
> error:
> 
> dgraph.h(25): error C2233: 'edge': arrays of objects containing
> zero-size arrays are illegal
> 
> The issue is that MSVC supports flexible array members, but does not
> support arrays of structs with flexible array members.  My
> understanding is that such support is not required by C99 or C11, but
> I don't know whether such support is common beyond Clang/GCC.
> 
> Is there any interest in supporting such compilers?  If so, I can see
> a few potential fixes:
> 
> 1. Change TCON to use flexible array members only when the compiler
> supports arrays of structs with flexible array members.  This is an
> easy fix, but wastes space for every TCON/TLIST usage on such
> compilers.
> 
> 2. Have TCON (and TLIST) provide an alternative macro which uses
> flexible array members only when supported in arrays, and use that in
> dgraph.  It would increase the API and duplicate a bit of code, but
> would only waste space when TCON/TLIST are placed in arrays.
> 
> 2. Replace the 2-element edge array in struct dgraph_node with
> separate fields edge_from and edge_to.  This complicates the logic a
> bit, since it is no longer symmetric with dgraph_edge.  It would also
> be an incompatible API change.
> 
> 3. Change TLIST to use TCON_WRAP?  I don't understand TLIST/TCON well
> enough to know if this is really an option.  Hopefully an expert can
> weigh in here.

I've now done this for tlist and several other modules, we should have
a much better chance of compiling on windows.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
ccan mailing list
ccan@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/ccan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: dgraph, tlist, tcon: MSVC error due to array of flexible structs
  2017-08-01  5:22 ` David Gibson
@ 2017-08-02  5:38   ` Kevin Locke
  0 siblings, 0 replies; 6+ messages in thread
From: Kevin Locke @ 2017-08-02  5:38 UTC (permalink / raw)
  To: David Gibson; +Cc: ccan

On Tue, 2017-08-01 at 15:22 +1000, David Gibson wrote:
> On Thu, Sep 22, 2016 at 10:31:16PM -0600, Kevin Locke wrote:
>> [...]
>> 
>> The issue is that MSVC supports flexible array members, but does not
>> support arrays of structs with flexible array members.  My
>> understanding is that such support is not required by C99 or C11, but
>> I don't know whether such support is common beyond Clang/GCC.
>> 
>> Is there any interest in supporting such compilers?  If so, I can see
>> a few potential fixes:
>> 
>> [...]
>> 
>> 3. Change TLIST to use TCON_WRAP?  I don't understand TLIST/TCON well
>> enough to know if this is really an option.  Hopefully an expert can
>> weigh in here.
> 
> I've now done this for tlist and several other modules, we should have
> a much better chance of compiling on windows.

Great stuff!  Thanks for all of your work to make the changes!

As soon as I get a chance I'll take another look at building with MSVC
and see what hurdles exist and how feasible it might be to get the
ccan tools compiling.

-- 
Cheers,      |  kevin@kevinlocke.name    | XMPP: kevin@kevinlocke.name
Kevin        |  https://kevinlocke.name  | IRC:   kevinoid on freenode
_______________________________________________
ccan mailing list
ccan@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/ccan

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-08-02  5:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-23  4:31 dgraph, tlist, tcon: MSVC error due to array of flexible structs Kevin Locke
2016-09-27  4:45 ` David Gibson
2016-09-28  2:10   ` Rusty Russell
2016-09-28  3:12     ` David Gibson
2017-08-01  5:22 ` David Gibson
2017-08-02  5:38   ` Kevin Locke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).