Visual studio supports zero-size array within a struct or union, but has to be the last element. GCC does not have this restriction.
Commits 644cfd84772eb7d8 and 6fdaa45a6f6c9 make use of 0 size array. Remove them so that visual studio can compile them as well. Reported-by: Gurucharan Shetty <gshe...@nicira.com> Signed-off-by: Andy Zhou <az...@nicira.com> --- v1->v2: * Remove zero-sized array and flexible array, based on Ben's suggestion. Should also work for visual studio, but did not verify. --- include/openflow/openflow-1.1.h | 2 +- include/openflow/openflow-1.3.h | 2 +- lib/ofp-util.c | 53 ++++++++++++++++++++++------------------- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/include/openflow/openflow-1.1.h b/include/openflow/openflow-1.1.h index e3e2d39..bb6bcb0 100644 --- a/include/openflow/openflow-1.1.h +++ b/include/openflow/openflow-1.1.h @@ -705,7 +705,7 @@ struct ofp11_group_stats { uint8_t pad2[4]; /* Align to 64 bits. */ ovs_be64 packet_count; /* Number of packets processed by group. */ ovs_be64 byte_count; /* Number of bytes processed by group. */ - struct ofp11_bucket_counter bucket_stats[0]; + /* struct ofp11_bucket_counter bucket_stats[]; */ }; OFP_ASSERT(sizeof(struct ofp11_group_stats) == 32); diff --git a/include/openflow/openflow-1.3.h b/include/openflow/openflow-1.3.h index 8e9f6f7..cc425f1 100644 --- a/include/openflow/openflow-1.3.h +++ b/include/openflow/openflow-1.3.h @@ -388,7 +388,7 @@ struct ofp13_group_stats { ovs_be32 duration_sec; /* Time group has been alive in seconds. */ ovs_be32 duration_nsec; /* Time group has been alive in nanoseconds beyond duration_sec. */ - struct ofp11_bucket_counter bucket_stats[0]; + /* struct ofp11_bucket_counter bucket_stats[]; */ }; OFP_ASSERT(sizeof(struct ofp13_group_stats) == 40); diff --git a/lib/ofp-util.c b/lib/ofp-util.c index 3484394..9c8db9d 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -6274,19 +6274,11 @@ ofputil_encode_group_desc_request(enum ofp_version ofp_version) } static void -ofputil_group_stats_to_ofp11__(const struct ofputil_group_stats *gs, - struct ofp11_group_stats *gs11, size_t length, - struct ofp11_bucket_counter bucket_cnts[]) +ofputil_group_bucket_counters_to_ofp11(const struct ofputil_group_stats *gs, + struct ofp11_bucket_counter bucket_cnts[]) { int i; - memset(gs11, 0, length); - gs11->length = htons(length); - gs11->group_id = htonl(gs->group_id); - gs11->ref_count = htonl(gs->ref_count); - gs11->packet_count = htonll(gs->packet_count); - gs11->byte_count = htonll(gs->byte_count); - for (i = 0; i < gs->n_buckets; i++) { bucket_cnts[i].packet_count = htonll(gs->bucket_stats[i].packet_count); bucket_cnts[i].byte_count = htonll(gs->bucket_stats[i].byte_count); @@ -6295,18 +6287,27 @@ ofputil_group_stats_to_ofp11__(const struct ofputil_group_stats *gs, static void ofputil_group_stats_to_ofp11(const struct ofputil_group_stats *gs, - struct ofp11_group_stats *gs11, size_t length) + struct ofp11_group_stats *gs11, size_t length, + struct ofp11_bucket_counter bucket_cnts[]) { - ofputil_group_stats_to_ofp11__(gs, gs11, length, gs11->bucket_stats); + memset(gs11, 0, sizeof *gs11); + gs11->length = htons(length); + gs11->group_id = htonl(gs->group_id); + gs11->ref_count = htonl(gs->ref_count); + gs11->packet_count = htonll(gs->packet_count); + gs11->byte_count = htonll(gs->byte_count); + ofputil_group_bucket_counters_to_ofp11(gs, bucket_cnts); } static void ofputil_group_stats_to_ofp13(const struct ofputil_group_stats *gs, - struct ofp13_group_stats *gs13, size_t length) + struct ofp13_group_stats *gs13, size_t length, + struct ofp11_bucket_counter bucket_cnts[]) { - ofputil_group_stats_to_ofp11__(gs, &gs13->gs, length, gs13->bucket_stats); + ofputil_group_stats_to_ofp11(gs, &gs13->gs, length, bucket_cnts); gs13->duration_sec = htonl(gs->duration_sec); gs13->duration_nsec = htonl(gs->duration_nsec); + } /* Encodes 'gs' properly for the format of the list of group statistics @@ -6318,28 +6319,32 @@ ofputil_append_group_stats(struct list *replies, { struct ofpbuf *msg = ofpbuf_from_list(list_back(replies)); struct ofp_header *oh = ofpbuf_data(msg); + size_t bucket_counter_size; + struct ofp11_bucket_counter *bucket_counters; size_t length; + bucket_counter_size = gs->n_buckets * sizeof(struct ofp11_bucket_counter); + switch ((enum ofp_version) oh->version) { case OFP11_VERSION: case OFP12_VERSION:{ - struct ofp11_group_stats *reply; + struct ofp11_group_stats *gs11; - length = gs->n_buckets * sizeof reply->bucket_stats[0] - + sizeof *reply; - reply = ofpmp_append(replies, length); - ofputil_group_stats_to_ofp11(gs, reply, length); + gs11 = ofpmp_append(replies, sizeof *gs11); + bucket_counters = ofpmp_append(replies, bucket_counter_size); + length = bucket_counter_size + sizeof *gs11; + ofputil_group_stats_to_ofp11(gs, gs11, length, bucket_counters); break; } case OFP13_VERSION: case OFP14_VERSION:{ - struct ofp13_group_stats *reply; + struct ofp13_group_stats *gs13; - length = gs->n_buckets * sizeof reply->bucket_stats[0] - + sizeof *reply; - reply = ofpmp_append(replies, length); - ofputil_group_stats_to_ofp13(gs, reply, length); + gs13 = ofpmp_append(replies, sizeof *gs13); + bucket_counters = ofpmp_append(replies, bucket_counter_size); + length = bucket_counter_size + sizeof *gs13; + ofputil_group_stats_to_ofp13(gs, gs13, length, bucket_counters); break; } -- 1.9.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev