Skip to content

Commit

Permalink
Merge pull request #283 from ngtcp2/designated-initializers
Browse files Browse the repository at this point in the history
C99 designated initializers
  • Loading branch information
tatsuhiro-t authored Dec 23, 2024
2 parents f24d533 + eb1ab44 commit dcec8f1
Show file tree
Hide file tree
Showing 16 changed files with 253 additions and 153 deletions.
2 changes: 1 addition & 1 deletion lib/nghttp3_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1836,7 +1836,7 @@ int nghttp3_conn_create_stream(nghttp3_conn *conn, nghttp3_stream **pstream,
nghttp3_stream *stream;
int rv;
nghttp3_stream_callbacks callbacks = {
conn_stream_acked_data,
.acked_data = conn_stream_acked_data,
};

rv = nghttp3_stream_new(&stream, stream_id, &callbacks,
Expand Down
20 changes: 16 additions & 4 deletions lib/nghttp3_gaptr.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ void nghttp3_gaptr_init(nghttp3_gaptr *gaptr, const nghttp3_mem *mem) {
}

static int gaptr_gap_init(nghttp3_gaptr *gaptr) {
nghttp3_range range = {0, UINT64_MAX};
nghttp3_range range = {
.end = UINT64_MAX,
};

return nghttp3_ksl_insert(&gaptr->gap, NULL, &range, NULL);
}
Expand All @@ -52,7 +54,11 @@ void nghttp3_gaptr_free(nghttp3_gaptr *gaptr) {
int nghttp3_gaptr_push(nghttp3_gaptr *gaptr, uint64_t offset,
uint64_t datalen) {
int rv;
nghttp3_range k, m, l, r, q = {offset, offset + datalen};
nghttp3_range k, m, l, r;
nghttp3_range q = {
.begin = offset,
.end = offset + datalen,
};
nghttp3_ksl_it it;

if (nghttp3_ksl_len(&gaptr->gap) == 0) {
Expand Down Expand Up @@ -112,7 +118,10 @@ uint64_t nghttp3_gaptr_first_gap_offset(nghttp3_gaptr *gaptr) {

nghttp3_range nghttp3_gaptr_get_first_gap_after(nghttp3_gaptr *gaptr,
uint64_t offset) {
nghttp3_range q = {offset, offset + 1};
nghttp3_range q = {
.begin = offset,
.end = offset + 1,
};
nghttp3_ksl_it it;

if (nghttp3_ksl_len(&gaptr->gap) == 0) {
Expand All @@ -130,7 +139,10 @@ nghttp3_range nghttp3_gaptr_get_first_gap_after(nghttp3_gaptr *gaptr,

int nghttp3_gaptr_is_pushed(nghttp3_gaptr *gaptr, uint64_t offset,
uint64_t datalen) {
nghttp3_range q = {offset, offset + datalen};
nghttp3_range q = {
.begin = offset,
.end = offset + datalen,
};
nghttp3_ksl_it it;
nghttp3_range m;

Expand Down
2 changes: 1 addition & 1 deletion lib/nghttp3_ksl.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "nghttp3_mem.h"
#include "nghttp3_range.h"

static nghttp3_ksl_blk null_blk = {{{NULL, NULL, 0, 0, {0}}}};
static nghttp3_ksl_blk null_blk;

nghttp3_objalloc_def(ksl_blk, nghttp3_ksl_blk, oplent)

Expand Down
6 changes: 5 additions & 1 deletion lib/nghttp3_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ void nghttp3_map_print_distance(const nghttp3_map *map) {
static int insert(nghttp3_map_bucket *table, size_t hashbits,
nghttp3_map_key_type key, void *data) {
size_t idx = hash(key, hashbits);
nghttp3_map_bucket b = {0, key, data}, *bkt;
nghttp3_map_bucket b = {
.key = key,
.data = data,
};
nghttp3_map_bucket *bkt;
size_t mask = (1u << hashbits) - 1;

for (;;) {
Expand Down
65 changes: 48 additions & 17 deletions lib/nghttp3_qpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@
#define NGHTTP3_QPACK_MAX_QPACK_STREAMS 2000

/* Make scalar initialization form of nghttp3_qpack_static_entry */
#define MAKE_STATIC_ENT(I, T, H) {I, T, H}
#define MAKE_STATIC_ENT(I, T, H) \
{ \
.absidx = I, \
.token = T, \
.hash = H, \
}

/* Generated by mkstatichdtbl.py */
static nghttp3_qpack_static_entry token_stable[] = {
Expand Down Expand Up @@ -166,9 +171,19 @@ static nghttp3_qpack_static_entry token_stable[] = {
/* Make scalar initialization form of nghttp3_qpack_static_entry */
#define MAKE_STATIC_HD(N, V, T) \
{ \
{NULL, (uint8_t *)(N), sizeof((N)) - 1, -1}, \
{NULL, (uint8_t *)(V), sizeof((V)) - 1, -1}, \
T, \
.name = \
{ \
.base = (uint8_t *)(N), \
.len = sizeof((N)) - 1, \
.ref = -1, \
}, \
.value = \
{ \
.base = (uint8_t *)(V), \
.len = sizeof((V)) - 1, \
.ref = -1, \
}, \
.token = T, \
}

static nghttp3_qpack_static_header stable[] = {
Expand Down Expand Up @@ -1447,7 +1462,14 @@ int nghttp3_qpack_encoder_encode_nv(nghttp3_qpack_encoder *encoder,
uint32_t hash = 0;
int32_t token;
nghttp3_qpack_indexing_mode indexing_mode;
nghttp3_qpack_lookup_result sres = {-1, 0, -1}, dres = {-1, 0, -1};
nghttp3_qpack_lookup_result sres = {
.index = -1,
.pb_index = -1,
};
nghttp3_qpack_lookup_result dres = {
.index = -1,
.pb_index = -1,
};
nghttp3_qpack_entry *new_ent = NULL;
int static_entry;
int just_index = 0;
Expand Down Expand Up @@ -1611,8 +1633,10 @@ int nghttp3_qpack_encoder_encode_nv(nghttp3_qpack_encoder *encoder,
nghttp3_qpack_lookup_result
nghttp3_qpack_lookup_stable(const nghttp3_nv *nv, int32_t token,
nghttp3_qpack_indexing_mode indexing_mode) {
nghttp3_qpack_lookup_result res = {(nghttp3_ssize)token_stable[token].absidx,
0, -1};
nghttp3_qpack_lookup_result res = {
.index = (nghttp3_ssize)token_stable[token].absidx,
.pb_index = -1,
};
nghttp3_qpack_static_entry *ent;
nghttp3_qpack_static_header *hdr;
size_t i;
Expand Down Expand Up @@ -1642,7 +1666,10 @@ nghttp3_qpack_lookup_result nghttp3_qpack_encoder_lookup_dtable(
nghttp3_qpack_encoder *encoder, const nghttp3_nv *nv, int32_t token,
uint32_t hash, nghttp3_qpack_indexing_mode indexing_mode, uint64_t krcnt,
int allow_blocking) {
nghttp3_qpack_lookup_result res = {-1, 0, -1};
nghttp3_qpack_lookup_result res = {
.index = -1,
.pb_index = -1,
};
int exact_match = 0;
nghttp3_qpack_entry *match, *pb_match;

Expand Down Expand Up @@ -2262,21 +2289,23 @@ void nghttp3_qpack_entry_free(nghttp3_qpack_entry *ent) {
int nghttp3_qpack_encoder_block_stream(nghttp3_qpack_encoder *encoder,
nghttp3_qpack_stream *stream) {
nghttp3_blocked_streams_key bsk = {
nghttp3_struct_of(nghttp3_pq_top(&stream->max_cnts),
nghttp3_qpack_header_block_ref, max_cnts_pe)
->max_cnt,
(uint64_t)stream->stream_id};
.max_cnt = nghttp3_struct_of(nghttp3_pq_top(&stream->max_cnts),
nghttp3_qpack_header_block_ref, max_cnts_pe)
->max_cnt,
.id = (uint64_t)stream->stream_id,
};

return nghttp3_ksl_insert(&encoder->blocked_streams, NULL, &bsk, stream);
}

void nghttp3_qpack_encoder_unblock_stream(nghttp3_qpack_encoder *encoder,
nghttp3_qpack_stream *stream) {
nghttp3_blocked_streams_key bsk = {
nghttp3_struct_of(nghttp3_pq_top(&stream->max_cnts),
nghttp3_qpack_header_block_ref, max_cnts_pe)
->max_cnt,
(uint64_t)stream->stream_id};
.max_cnt = nghttp3_struct_of(nghttp3_pq_top(&stream->max_cnts),
nghttp3_qpack_header_block_ref, max_cnts_pe)
->max_cnt,
.id = (uint64_t)stream->stream_id,
};
nghttp3_ksl_it it;

/* This is purely debugging purpose only */
Expand All @@ -2290,7 +2319,9 @@ void nghttp3_qpack_encoder_unblock_stream(nghttp3_qpack_encoder *encoder,

void nghttp3_qpack_encoder_unblock(nghttp3_qpack_encoder *encoder,
uint64_t max_cnt) {
nghttp3_blocked_streams_key bsk = {max_cnt, 0};
nghttp3_blocked_streams_key bsk = {
.max_cnt = max_cnt,
};
nghttp3_ksl_it it;

it = nghttp3_ksl_lower_bound(&encoder->blocked_streams, &bsk);
Expand Down
4 changes: 3 additions & 1 deletion lib/nghttp3_qpack_huffman.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ nghttp3_qpack_huffman_decode(nghttp3_qpack_huffman_decode_context *ctx,
int fin) {
uint8_t *p = dest;
const uint8_t *end = src + srclen;
nghttp3_qpack_huffman_decode_node node = {ctx->fstate, 0};
nghttp3_qpack_huffman_decode_node node = {
.fstate = ctx->fstate,
};
const nghttp3_qpack_huffman_decode_node *t = &node;
uint8_t c;

Expand Down
2 changes: 1 addition & 1 deletion lib/nghttp3_range.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void nghttp3_range_init(nghttp3_range *r, uint64_t begin, uint64_t end) {

nghttp3_range nghttp3_range_intersect(const nghttp3_range *a,
const nghttp3_range *b) {
nghttp3_range r = {0, 0};
nghttp3_range r = {0};
uint64_t begin = nghttp3_max_uint64(a->begin, b->begin);
uint64_t end = nghttp3_min_uint64(a->end, b->end);

Expand Down
13 changes: 10 additions & 3 deletions lib/nghttp3_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,19 @@ int nghttp3_stream_write_settings(nghttp3_stream *stream,
struct {
nghttp3_frame_settings settings;
nghttp3_settings_entry iv[15];
} fr;
} fr = {
.settings =
{
.hd =
{
.type = NGHTTP3_FRAME_SETTINGS,
},
.niv = 3,
},
};
nghttp3_settings_entry *iv;
nghttp3_settings *local_settings = frent->aux.settings.local_settings;

fr.settings.hd.type = NGHTTP3_FRAME_SETTINGS;
fr.settings.niv = 3;
iv = &fr.settings.iv[0];

iv[0].id = NGHTTP3_SETTINGS_ID_MAX_FIELD_SECTION_SIZE;
Expand Down
7 changes: 5 additions & 2 deletions lib/nghttp3_version.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@

#include <nghttp3/nghttp3.h>

static nghttp3_info version = {NGHTTP3_VERSION_AGE, NGHTTP3_VERSION_NUM,
NGHTTP3_VERSION};
static nghttp3_info version = {
.age = NGHTTP3_VERSION_AGE,
.version_num = NGHTTP3_VERSION_NUM,
.version_str = NGHTTP3_VERSION,
};

const nghttp3_info *nghttp3_version(int least_version) {
if (least_version > NGHTTP3_VERSION_NUM) {
Expand Down
10 changes: 4 additions & 6 deletions tests/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@

int main(int argc, char **argv) {
const MunitSuite suites[] = {
qpack_suite,
conn_suite,
tnode_suite,
http_suite,
{NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE},
qpack_suite, conn_suite, tnode_suite, http_suite, {0},
};
const MunitSuite suite = {
"", NULL, suites, 1, MUNIT_SUITE_OPTION_NONE,
.prefix = "",
.suites = suites,
.iterations = 1,
};

return munit_suite_main(&suite, NULL, argc, argv);
Expand Down
Loading

0 comments on commit dcec8f1

Please sign in to comment.