Skip to content

Commit 1305fb6

Browse files
authored
Run clang-format over private headers too (WebAssembly#767)
These aren't included in any other compile target, so they need to be manually included.
1 parent 08be569 commit 1305fb6

7 files changed

Lines changed: 119 additions & 100 deletions

File tree

libc-bottom-half/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ foreach(header ${globbed_headers})
3636
add_sysroot_header(${header} ${dst})
3737
endforeach()
3838

39+
file(
40+
GLOB_RECURSE globbed_private_headers
41+
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
42+
CONFIGURE_DEPENDS
43+
headers/private/*.h
44+
)
45+
46+
foreach(header ${globbed_private_headers})
47+
clang_format_file(${header})
48+
endforeach()
49+
3950
# =============================================================================
4051
# building bottom-half sources
4152
#

libc-bottom-half/headers/private/wasi/descriptor_table.h

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#include <wasi/api.h>
55

66
#ifndef __wasip1__
7-
#include <wasi/poll.h>
8-
#include <sys/stat.h>
97
#include <netinet/in.h>
8+
#include <sys/stat.h>
9+
#include <wasi/poll.h>
1010

1111
// Metadata for WASI reads which is used to delegate to `__wasilibc_read(...)`
1212
// to perform the actual read of a stream.
@@ -30,7 +30,7 @@ typedef struct wasi_read_t {
3030

3131
// A callback/ptr pair to invoke when EOF is reached to set errno and return
3232
// an error code.
33-
int (*eof)(void*);
33+
int (*eof)(void *);
3434
void *eof_data;
3535
#endif
3636
} wasi_read_t;
@@ -51,7 +51,7 @@ typedef struct wasi_write_t {
5151
bool *done;
5252
// A callback/ptr pair to invoke when EOF is reached to set errno and return
5353
// an error code.
54-
int (*eof)(void*);
54+
int (*eof)(void *);
5555
void *eof_data;
5656
#endif
5757
} wasi_write_t;
@@ -75,73 +75,73 @@ typedef uint32_t waitable_t;
7575
*/
7676
typedef struct descriptor_vtable_t {
7777
/// Deallocates the parameter provided, closing all resources as well.
78-
void (*free)(void*);
78+
void (*free)(void *);
7979

8080
// =====================================================================
8181
// Generic I/O
8282

83-
/// Looks up metadata to perform a read operation for this stream. This is used
84-
/// to implement the `read` syscall, for example, and is also used with `poll`
85-
/// when waiting for readability.
86-
int (*get_read_stream)(void*, wasi_read_t*);
83+
/// Looks up metadata to perform a read operation for this stream. This is
84+
/// used to implement the `read` syscall, for example, and is also used with
85+
/// `poll` when waiting for readability.
86+
int (*get_read_stream)(void *, wasi_read_t *);
8787
/// Same as `get_read_stream`, but for output streams.
88-
int (*get_write_stream)(void*, wasi_write_t*);
88+
int (*get_write_stream)(void *, wasi_write_t *);
8989

9090
/// Sets the nonblocking flag for this object to the specified value.
91-
int (*set_blocking)(void*, bool);
91+
int (*set_blocking)(void *, bool);
9292

9393
/// Implementation of `fstat` the function call, used to learn about file
9494
/// descriptors.
95-
int (*fstat)(void*, struct stat*);
95+
int (*fstat)(void *, struct stat *);
9696

9797
// =====================================================================
9898
// File-related APIs
9999

100100
/// Looks up a `wasi:filesystem/types.descriptor`, if present, from this
101101
/// object.
102-
int (*get_file)(void*, filesystem_borrow_descriptor_t*);
102+
int (*get_file)(void *, filesystem_borrow_descriptor_t *);
103103
/// Implementation of `lseek`-the-function.
104-
off_t (*seek)(void*, off_t, int);
104+
off_t (*seek)(void *, off_t, int);
105105
/// Used during `unlinkat` to ensure that all internal stremas are
106106
/// closed before deleting the file to ensure there are no open references to
107107
/// it.
108-
void (*close_streams)(void*);
108+
void (*close_streams)(void *);
109109
/// Implementation of `fnctl(fd, F_GETFL)`.
110-
int (*fcntl_getfl)(void*);
110+
int (*fcntl_getfl)(void *);
111111
/// Implementation of `fnctl(fd, F_SETFL)`.
112-
int (*fcntl_setfl)(void*, int);
112+
int (*fcntl_setfl)(void *, int);
113113
/// Implementation of `isatty`-the-function.
114-
int (*isatty)(void*);
114+
int (*isatty)(void *);
115115

116116
// =====================================================================
117117
// Sockets-related APIs
118118

119119
/// Implementation of `accept4`-the-function.
120-
int (*accept4)(void*, struct sockaddr *addr, socklen_t *addrlen, int flags);
120+
int (*accept4)(void *, struct sockaddr *addr, socklen_t *addrlen, int flags);
121121
/// Implementation of `bind`-the-function.
122-
int (*bind)(void*, const struct sockaddr *addr, socklen_t addrlen);
122+
int (*bind)(void *, const struct sockaddr *addr, socklen_t addrlen);
123123
/// Implementation of `connect`-the-function.
124-
int (*connect)(void*, const struct sockaddr *addr, socklen_t addrlen);
124+
int (*connect)(void *, const struct sockaddr *addr, socklen_t addrlen);
125125
/// Implementation of `getsockname`-the-function.
126-
int (*getsockname)(void*, struct sockaddr *addr, socklen_t *addrlen);
126+
int (*getsockname)(void *, struct sockaddr *addr, socklen_t *addrlen);
127127
/// Implementation of `getpeername`-the-function.
128-
int (*getpeername)(void*, struct sockaddr *addr, socklen_t *addrlen);
128+
int (*getpeername)(void *, struct sockaddr *addr, socklen_t *addrlen);
129129
/// Implementation of `listen`-the-function.
130-
int (*listen)(void*, int backlog);
130+
int (*listen)(void *, int backlog);
131131
/// Implementation of `recvfrom`-the-function.
132-
ssize_t (*recvfrom)(void*, void *buffer, size_t length, int flags,
132+
ssize_t (*recvfrom)(void *, void *buffer, size_t length, int flags,
133133
struct sockaddr *addr, socklen_t *addrlen);
134134
/// Implementation of `sendto`-the-function.
135-
ssize_t (*sendto)(void*, const void *buffer, size_t length, int flags,
135+
ssize_t (*sendto)(void *, const void *buffer, size_t length, int flags,
136136
const struct sockaddr *addr, socklen_t addrlen);
137137
/// Implementation of `shutdown`-the-function.
138-
int (*shutdown)(void*, int how);
138+
int (*shutdown)(void *, int how);
139139
/// Implementation of `getsockopt`-the-function.
140-
int (*getsockopt)(void*, int level, int optname,
141-
void *optval, socklen_t *optlen);
140+
int (*getsockopt)(void *, int level, int optname, void *optval,
141+
socklen_t *optlen);
142142
/// Implementation of `setsockopt`-the-function.
143-
int (*setsockopt)(void*, int level, int optname,
144-
const void *optval, socklen_t optlen);
143+
int (*setsockopt)(void *, int level, int optname, const void *optval,
144+
socklen_t optlen);
145145

146146
// =====================================================================
147147
// `poll`-related APIs
@@ -154,7 +154,7 @@ typedef struct descriptor_vtable_t {
154154
///
155155
/// If this function is not provided then `poll` will use `get_read_stream`
156156
/// and `get_write_stream`, if present, to handle `POLL{RD,WR}NORM` events.
157-
int (*poll_register)(void*, poll_state_t *state, short events);
157+
int (*poll_register)(void *, poll_state_t *state, short events);
158158

159159
/// Invoked when `poll` has already run and detected that this object was
160160
/// ready. The `events` provided are the same as those provided to
@@ -164,7 +164,7 @@ typedef struct descriptor_vtable_t {
164164
///
165165
/// If this function is not provided then `events` will automatically
166166
/// be placed into the `revents` field of `pollfd`.
167-
int (*poll_finish)(void*, poll_state_t *state, short events);
167+
int (*poll_finish)(void *, poll_state_t *state, short events);
168168
} descriptor_vtable_t;
169169

170170
/// A "fat pointer" which is placed inside of the descriptor table.

libc-bottom-half/headers/private/wasi/file_utils.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
#if defined(__wasip2__) || defined(__wasip3__)
66

77
#include <assert.h>
8-
#include <wasi/wasip2.h>
9-
#include <wasi/descriptor_table.h>
108
#include <dirent.h>
11-
#include <fcntl.h>
129
#include <errno.h>
10+
#include <fcntl.h>
11+
#include <wasi/descriptor_table.h>
12+
#include <wasi/wasip2.h>
1313

1414
#ifdef __wasip2__
1515
/// Handles a `wasi:io/streams.stream-error` for a `read`-style operation.
@@ -48,16 +48,17 @@ typedef wasip3_string_t wasi_string_t;
4848

4949
// Converts the C string `s` into a WASI string stored in `out`.
5050
//
51-
// The returned `wasip{2,3}_string_t` should not be deallocated or free'd, and it
52-
// can only be used while `s` is also valid.
51+
// The returned `wasip{2,3}_string_t` should not be deallocated or free'd, and
52+
// it can only be used while `s` is also valid.
5353
//
5454
// Returns 0 if `s` is valid utf-8.
5555
// Returns -1 and sets errno to `ENOENT` if `s` is not valid utf-8.
56-
int wasi_string_from_c(const char *s, wasi_string_t* out);
56+
int wasi_string_from_c(const char *s, wasi_string_t *out);
5757

5858
// Succeed only if fd is bound to a file handle in the descriptor table
59-
static inline int fd_to_file_handle(int fd, filesystem_borrow_descriptor_t* result) {
60-
descriptor_table_entry_t* entry = descriptor_table_get_ref(fd);
59+
static inline int fd_to_file_handle(int fd,
60+
filesystem_borrow_descriptor_t *result) {
61+
descriptor_table_entry_t *entry = descriptor_table_get_ref(fd);
6162
if (entry == NULL)
6263
return -1;
6364
if (!entry->vtable->get_file) {
@@ -76,8 +77,9 @@ ssize_t __wasilibc_read(wasi_read_t *read, void *buf, size_t len);
7677
// Same as `__wasilibc_read`, but for writes.
7778
ssize_t __wasilibc_write(wasi_write_t *write, const void *buf, size_t len);
7879

79-
static inline unsigned dir_entry_type_to_d_type(filesystem_descriptor_type_t ty) {
80-
switch(ty) {
80+
static inline unsigned
81+
dir_entry_type_to_d_type(filesystem_descriptor_type_t ty) {
82+
switch (ty) {
8183
case FILESYSTEM_DESCRIPTOR_TYPE_UNKNOWN:
8284
return DT_UNKNOWN;
8385
case FILESYSTEM_DESCRIPTOR_TYPE_BLOCK_DEVICE:

libc-bottom-half/headers/private/wasi/poll.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,31 @@ void __wasilibc_poll_ready(poll_state_t *state, short events);
2727
/// `revents` in the final `pollfd`.
2828
///
2929
/// The `state` value internally tracks which `pollfd` is being used.
30-
int __wasilibc_poll_add(poll_state_t *state,
31-
short events,
30+
int __wasilibc_poll_add(poll_state_t *state, short events,
3231
poll_borrow_pollable_t pollable);
3332

3433
/// Helper function to lazily subscribe to an input stream and call
3534
/// `__wasilibc_poll_add`.
36-
static inline int __wasilibc_poll_add_input_stream(
37-
poll_state_t *state,
38-
streams_borrow_input_stream_t input_stream,
39-
poll_own_pollable_t *pollable) {
35+
static inline int
36+
__wasilibc_poll_add_input_stream(poll_state_t *state,
37+
streams_borrow_input_stream_t input_stream,
38+
poll_own_pollable_t *pollable) {
4039
if (pollable->__handle == 0)
4140
*pollable = streams_method_input_stream_subscribe(input_stream);
42-
return __wasilibc_poll_add(state, POLLRDNORM, poll_borrow_pollable(*pollable));
41+
return __wasilibc_poll_add(state, POLLRDNORM,
42+
poll_borrow_pollable(*pollable));
4343
}
4444

4545
/// Helper function to lazily subscribe to an output stream and call
4646
/// `__wasilibc_poll_add`.
47-
static inline int __wasilibc_poll_add_output_stream(
48-
poll_state_t *state,
49-
streams_borrow_output_stream_t output_stream,
50-
poll_own_pollable_t *pollable) {
47+
static inline int
48+
__wasilibc_poll_add_output_stream(poll_state_t *state,
49+
streams_borrow_output_stream_t output_stream,
50+
poll_own_pollable_t *pollable) {
5151
if (pollable->__handle == 0)
5252
*pollable = streams_method_output_stream_subscribe(output_stream);
53-
return __wasilibc_poll_add(state, POLLWRNORM, poll_borrow_pollable(*pollable));
53+
return __wasilibc_poll_add(state, POLLWRNORM,
54+
poll_borrow_pollable(*pollable));
5455
}
5556

5657
#endif // __wasip2__

libc-bottom-half/headers/private/wasi/sockets_utils.h

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#define __wasi_sockets_utils_h
33

44
#include <netinet/in.h>
5-
#include <wasi/descriptor_table.h>
65
#include <wasi/api.h>
6+
#include <wasi/descriptor_table.h>
77

88
#ifndef __wasip1__
99

@@ -27,39 +27,39 @@ typedef network_ipv6_address_t sockets_ipv6_address_t;
2727
#elif defined(__wasip3__)
2828
// already defines `sockets_*` types
2929
#else
30-
# error "Unsupported WASI version"
30+
#error "Unsupported WASI version"
3131
#endif
3232

3333
typedef struct {
34-
enum {
35-
OUTPUT_SOCKADDR_NULL,
36-
OUTPUT_SOCKADDR_V4,
37-
OUTPUT_SOCKADDR_V6,
38-
} tag;
39-
union {
40-
struct {
41-
int dummy;
42-
} null;
43-
struct {
44-
struct sockaddr_in *addr;
45-
socklen_t *addrlen;
46-
} v4;
47-
struct {
48-
struct sockaddr_in6 *addr;
49-
socklen_t *addrlen;
50-
} v6;
51-
};
34+
enum {
35+
OUTPUT_SOCKADDR_NULL,
36+
OUTPUT_SOCKADDR_V4,
37+
OUTPUT_SOCKADDR_V6,
38+
} tag;
39+
union {
40+
struct {
41+
int dummy;
42+
} null;
43+
struct {
44+
struct sockaddr_in *addr;
45+
socklen_t *addrlen;
46+
} v4;
47+
struct {
48+
struct sockaddr_in6 *addr;
49+
socklen_t *addrlen;
50+
} v6;
51+
};
5252
} output_sockaddr_t;
5353

5454
typedef struct {
55-
char *s_name;
56-
uint16_t port;
57-
uint16_t protocol;
55+
char *s_name;
56+
uint16_t port;
57+
uint16_t protocol;
5858
} service_entry_t;
5959

6060
typedef enum {
61-
SERVICE_PROTOCOL_TCP = 1,
62-
SERVICE_PROTOCOL_UDP = 2
61+
SERVICE_PROTOCOL_TCP = 1,
62+
SERVICE_PROTOCOL_UDP = 2
6363
} service_protocol_e;
6464

6565
#ifdef __wasip2__
@@ -68,34 +68,36 @@ network_borrow_network_t __wasi_sockets_utils__borrow_network();
6868

6969
int __wasilibc_map_socket_error(sockets_error_code_t wasi_error);
7070

71-
static inline int __wasilibc_socket_error_to_errno(sockets_error_code_t wasi_error) {
71+
static inline int
72+
__wasilibc_socket_error_to_errno(sockets_error_code_t wasi_error) {
7273
errno = __wasilibc_map_socket_error(wasi_error);
7374
return -1;
7475
}
7576

7677
// Conversion from a libc-based `sockaddr` + `socklen_t` to a WASI address.
77-
int __wasilibc_sockaddr_to_wasi(
78-
sockets_ip_address_family_t expected_family,
79-
const struct sockaddr *address, socklen_t len,
80-
sockets_ip_socket_address_t *result);
78+
int __wasilibc_sockaddr_to_wasi(sockets_ip_address_family_t expected_family,
79+
const struct sockaddr *address, socklen_t len,
80+
sockets_ip_socket_address_t *result);
8181

8282
// Conversion from a WASI address to a libc-based `sockaddr`.
8383
//
8484
// This is done in two stages. First the user-provided `sockaddr` is validated
8585
// along with its lenght to ensure it's large enough to hold `expected_family`.
8686
// Next once the address is available `__wasilibc_wasi_to_sockaddr` is used
8787
// to write the output value.
88-
int __wasilibc_sockaddr_validate(
89-
sockets_ip_address_family_t expected_family, struct sockaddr *addr,
90-
socklen_t *addrlen, output_sockaddr_t *result);
91-
void __wasilibc_wasi_to_sockaddr(
92-
const sockets_ip_socket_address_t input, output_sockaddr_t *output);
88+
int __wasilibc_sockaddr_validate(sockets_ip_address_family_t expected_family,
89+
struct sockaddr *addr, socklen_t *addrlen,
90+
output_sockaddr_t *result);
91+
void __wasilibc_wasi_to_sockaddr(const sockets_ip_socket_address_t input,
92+
output_sockaddr_t *output);
9393

9494
int __wasilibc_wasi_family_to_libc(sockets_ip_address_family_t wasi_family);
95-
void __wasilibc_unspecified_addr(sockets_ip_address_family_t family, sockets_ip_socket_address_t *out);
95+
void __wasilibc_unspecified_addr(sockets_ip_address_family_t family,
96+
sockets_ip_socket_address_t *out);
9697
int __wasilibc_parse_port(const char *port);
9798
const service_entry_t *__wasilibc_get_service_entry_by_name(const char *name);
98-
const service_entry_t *__wasilibc_get_service_entry_by_port(const uint16_t port);
99+
const service_entry_t *
100+
__wasilibc_get_service_entry_by_port(const uint16_t port);
99101

100102
#endif // not(__wasip1__)
101103

0 commit comments

Comments
 (0)