Skip to content

Commit 24bae3a

Browse files
committed
refactor: refine restrict usage
Signed-off-by: He Xian <hexian000@outlook.com>
1 parent 1917c54 commit 24bae3a

File tree

9 files changed

+29
-27
lines changed

9 files changed

+29
-27
lines changed

client.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
},
1717
"method": "xchacha20poly1305_ietf",
1818
"password": "k",
19-
"loglevel": 5,
20-
"user": "nobody:"
19+
"loglevel": 7,
20+
"obfs": "dpi/tcp"
2121
}

contrib/csnippets/algo/hashtable.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static inline void table_reseed(struct hashtable *restrict table)
198198

199199
struct hashtable *table_set(
200200
struct hashtable *restrict table, const struct hashkey key,
201-
void **restrict element)
201+
void **element)
202202
{
203203
assert(table != NULL && element != NULL);
204204
const uint_least32_t hash = GET_HASH(key, table->seed);
@@ -264,7 +264,7 @@ struct hashtable *table_set(
264264

265265
bool table_find(
266266
const struct hashtable *restrict table, const struct hashkey key,
267-
void **element)
267+
void **restrict element)
268268
{
269269
if (table == NULL) {
270270
return false;
@@ -287,7 +287,7 @@ bool table_find(
287287

288288
struct hashtable *table_del(
289289
struct hashtable *restrict table, const struct hashkey key,
290-
void **restrict element)
290+
void **element)
291291
{
292292
if (table == NULL) {
293293
return NULL;
@@ -382,7 +382,8 @@ table_reserve(struct hashtable *restrict table, const size_t new_size)
382382
}
383383

384384
struct hashtable *table_filter(
385-
struct hashtable *restrict table, const table_iterate_cb f, void *data)
385+
struct hashtable *restrict table, const table_iterate_cb f,
386+
void *restrict data)
386387
{
387388
if (table == NULL) {
388389
return NULL;
@@ -416,7 +417,7 @@ struct hashtable *table_filter(
416417

417418
void table_iterate(
418419
const struct hashtable *restrict table, const table_iterate_cb f,
419-
void *data)
420+
void *restrict data)
420421
{
421422
if (table == NULL) {
422423
return;

server.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
},
1717
"method": "xchacha20poly1305_ietf",
1818
"password": "k",
19-
"loglevel": 5,
20-
"user": "nobody:"
19+
"loglevel": 7,
20+
"obfs": "dpi/tcp"
2121
}

src/crypto.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ struct crypto_impl {
8989
};
9090

9191
size_t crypto_seal(
92-
const struct crypto *restrict crypto, unsigned char *dst,
93-
const size_t dst_size, const unsigned char *nonce,
94-
const unsigned char *plain, const size_t plain_size)
92+
const struct crypto *restrict crypto, unsigned char *restrict dst,
93+
const size_t dst_size, const unsigned char *restrict nonce,
94+
const unsigned char *restrict plain, const size_t plain_size)
9595
{
9696
if (dst_size < plain_size + crypto->overhead) {
9797
LOGW_F("crypto_seal: insufficient crypto buffer %zu < %zu",
@@ -122,9 +122,9 @@ size_t crypto_seal(
122122
}
123123

124124
size_t crypto_open(
125-
const struct crypto *restrict crypto, unsigned char *dst,
126-
const size_t dst_size, const unsigned char *nonce,
127-
const unsigned char *cipher, const size_t cipher_size)
125+
const struct crypto *restrict crypto, unsigned char *restrict dst,
126+
const size_t dst_size, const unsigned char *restrict nonce,
127+
const unsigned char *restrict cipher, const size_t cipher_size)
128128
{
129129
if (dst_size + crypto->overhead < cipher_size) {
130130
LOGW("crypto_seal: insufficient crypto buffer");

src/event_tcp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static void modify_io_events(
5555

5656
static void accept_one(
5757
struct server *restrict s, const int fd,
58-
const struct sockaddr *client_sa)
58+
const struct sockaddr *restrict client_sa)
5959
{
6060
/* Initialize and start watcher to read client requests */
6161
const uint32_t conv = conv_new(s, &s->pkt.kcp_connect.sa);

src/event_timer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
void listener_cb(struct ev_loop *loop, ev_timer *watcher, const int revents)
2626
{
2727
CHECK_REVENTS(revents, EV_TIMER);
28-
struct listener *restrict l = watcher->data;
28+
struct listener *l = watcher->data;
2929
/* check & restart accept watchers */
30-
ev_io *restrict w_accept = &l->w_accept;
30+
ev_io *w_accept = &l->w_accept;
3131
if (l->fd != -1 && !ev_is_active(w_accept)) {
3232
ev_io_start(loop, w_accept);
3333
}
34-
ev_io *restrict w_accept_http = &l->w_accept_http;
34+
ev_io *w_accept_http = &l->w_accept_http;
3535
if (l->fd_http != -1 && !ev_is_active(w_accept_http)) {
3636
ev_io_start(loop, w_accept_http);
3737
}

src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,21 +244,21 @@ int main(int argc, char **argv)
244244
/* Set up signal watchers for graceful shutdown and config reload */
245245
{
246246
/* SIGHUP: reload configuration */
247-
ev_signal *restrict w_sighup = &app.w_sighup;
247+
ev_signal *w_sighup = &app.w_sighup;
248248
ev_signal_init(w_sighup, signal_cb, SIGHUP);
249249
ev_set_priority(w_sighup, EV_MAXPRI);
250250
w_sighup->data = s;
251251
ev_signal_start(loop, w_sighup);
252252

253253
/* SIGINT: graceful shutdown (Ctrl+C) */
254-
ev_signal *restrict w_sigint = &app.w_sigint;
254+
ev_signal *w_sigint = &app.w_sigint;
255255
ev_signal_init(w_sigint, signal_cb, SIGINT);
256256
ev_set_priority(w_sigint, EV_MAXPRI);
257257
w_sigint->data = s;
258258
ev_signal_start(loop, w_sigint);
259259

260260
/* SIGTERM: graceful shutdown (service stop) */
261-
ev_signal *restrict w_sigterm = &app.w_sigterm;
261+
ev_signal *w_sigterm = &app.w_sigterm;
262262
ev_signal_init(w_sigterm, signal_cb, SIGTERM);
263263
ev_set_priority(w_sigterm, EV_MAXPRI);
264264
w_sigterm->data = s;

src/obfs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ struct obfs_ctx {
137137
.data = (ctx)->key, \
138138
})
139139

140-
static inline struct obfs_ctx *
141-
obfs_find_ctx(const struct obfs *restrict obfs, const struct sockaddr *sa)
140+
static inline struct obfs_ctx *obfs_find_ctx(
141+
const struct obfs *restrict obfs, const struct sockaddr *restrict sa)
142142
{
143143
unsigned char key[OBFS_CTX_KEY_SIZE];
144144
const size_t n = getsocklen(sa);
@@ -225,7 +225,7 @@ static inline uint16_t in_cksum_fin(uint32_t sum, const void *data, size_t n)
225225
static uint16_t tcp_checksum(
226226
const int domain, const union sockaddr_max *restrict src,
227227
const union sockaddr_max *restrict dst, struct tcphdr *restrict tcp,
228-
const void *data, const size_t datalen)
228+
const void *restrict data, const size_t datalen)
229229
{
230230
const uint16_t plen = sizeof(struct tcphdr) + datalen;
231231
uint32_t sum = 0;

src/session.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,8 @@ struct session0_header {
423423

424424
#define SESSION0_HEADER_SIZE (sizeof(uint32_t) + sizeof(uint16_t))
425425

426-
static inline struct session0_header ss0_header_read(const unsigned char *d)
426+
static inline struct session0_header
427+
ss0_header_read(const unsigned char *restrict d)
427428
{
428429
return (struct session0_header){
429430
.zero = read_uint32(d),
@@ -432,7 +433,7 @@ static inline struct session0_header ss0_header_read(const unsigned char *d)
432433
}
433434

434435
static inline void
435-
ss0_header_write(unsigned char *d, const struct session0_header header)
436+
ss0_header_write(unsigned char *restrict d, const struct session0_header header)
436437
{
437438
write_uint32(d, header.zero);
438439
write_uint16(d + sizeof(uint32_t), header.what);

0 commit comments

Comments
 (0)