Skip to content

Commit 7b521bd

Browse files
Style fixes (too big to really review, just make sure the build passes). Updates code to coding standards. (awslabs#103)
* code style updates, and coding standards applied to code-base. * Run clang-format * Fixed botched merge on windows/clock.c.
1 parent 4090d10 commit 7b521bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1113
-1194
lines changed

README.md

+24-25
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Example:
138138
do_something();
139139
} else {
140140
do_something_else();
141-
}
141+
}
142142
* Avoid C99 features in header files. For some types such as bool, uint32_t etc..., these are defined if not available for the language
143143
standard being used in `aws/common/common.h`, so feel free to use them.
144144
* For C++ compatibility, don't put const members in structs.
@@ -151,42 +151,37 @@ standard being used in `aws/common/common.h`, so feel free to use them.
151151

152152
Example:
153153

154-
154+
155155
#ifdef FOO
156156
do_something();
157-
157+
158158
# ifdef BAR
159159
do_something_else();
160160
# endif
161161
#endif
162-
162+
163163

164164
* For all error code names with the exception of aws-c-common, use `AWS_ERROR_<lib name>_<error name>`.
165165
* All error strings should be written using correct English grammar.
166166
* SNAKE_UPPER_CASE constants, macros, and enum members.
167167
* snake_lower_case everything else.
168-
* File scope (static) variables and functions are prefixed with s_.
169-
* For constants, use anonymous enums.
168+
* `static` (local file scope) variables that are not `const` are prefixed by `s_` and lower snake case.
169+
* Global variables not prefixed as `const` are prefixed by `g_` and lower snake case.
170+
* Thread local variables are prefixed as `tl_` and lower snake case.
171+
* Macros and `const` variables are upper snake case.
172+
* For constants, prefer anonymous enums.
173+
* Don't typedef structs. It breaks forward declaration ability.
174+
* Don't typedef enums. It breaks forward declaration ability.
175+
* typedef function definitions for use as function pointers as values and suffixed with _fn.
170176

171177
Example:
172-
173-
enum { THE_ANSWER_TO_LIFE_THE_UNIVERSE_AND_EVERYTHING = 42 };
174-
175-
* Use typedef struct by suffixing _t to the typedef for the struct name.
176-
177-
Example:
178-
179-
typdef struct my_struct { ... } my_struct_t;
180-
* Use typedef enum by suffixing _t to the typedef for the enum name.
181178

182-
Example:
179+
typedef int(fn_name_fn)(void *);
183180

184-
typdef struct my_enum { ... } my_enum_t;
185-
* typedef function definitions for use as function pointers as values and suffixed with _fn.
181+
Not:
186182

187-
Example:
183+
typedef int(*fn_name_fn)(void *);
188184

189-
typedef int(fn_name_fn)(void *);
190185
* Every source and header file must have a copyright header (The standard AWS one for apache 2).
191186
* Use standard include guards (e.g. #IFNDEF HEADER_NAME #define HEADER_NAME etc...).
192187
* Include order should be:
@@ -203,11 +198,15 @@ not always required if a conflict is not likely and it provides better ergonomic
203198

204199
Example:
205200

206-
AWS_COMMON_API int aws_module_init(aws_module_t *module);
207-
AWS_COMMON_API void aws_module_clean_up(aws_module_t *module);
208-
AWS_COMMON_API aws_module_t *aws_module_new(aws_allocator_t *allocator);
209-
AWS_COMMON_API void aws_module_destroy(aws_module_t *module);
210-
201+
AWS_COMMON_API
202+
int aws_module_init(aws_module_t *module);
203+
AWS_COMMON_API
204+
void aws_module_clean_up(aws_module_t *module);
205+
AWS_COMMON_API
206+
aws_module_t *aws_module_new(aws_allocator_t *allocator);
207+
AWS_COMMON_API
208+
void aws_module_destroy(aws_module_t *module);
209+
211210
* Avoid c-strings, and don't write code that depends on `NULL` terminators. Expose `struct aws_byte_buf` APIs
212211
and let the user figure it out.
213212
* There is only one valid character encoding-- UTF-8. Try not to ever need to care about character encodings, but

include/aws/common/array_list.h

+30-43
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,17 @@ struct aws_array_list {
3333
* return a positive number if a > b, zero if a = b, and a negative number
3434
* if a < b.
3535
*/
36-
typedef int (*aws_array_list_comparator)(const void *a, const void *b);
36+
typedef int(aws_array_list_comparator_fn)(const void *a, const void *b);
3737

3838
#ifdef __cplusplus
3939
extern "C" {
4040
#endif
4141

4242
/**
43-
* Initializes an array list with an array of size initial_item_allocation *
44-
* item_size. In this mode, the array size will grow by a factor of 2 upon
45-
* insertion if space is not available. initial_item_allocation is the number of
46-
* elements you want space allocated for. item_size is the size of each element
47-
* in bytes. Mixing items types is not supported by this API.
43+
* Initializes an array list with an array of size initial_item_allocation * item_size. In this mode, the array size
44+
* will grow by a factor of 2 upon insertion if space is not available. initial_item_allocation is the number of
45+
* elements you want space allocated for. item_size is the size of each element in bytes. Mixing items types is not
46+
* supported by this API.
4847
*/
4948
AWS_COMMON_API
5049
int aws_array_list_init_dynamic(
@@ -54,17 +53,15 @@ int aws_array_list_init_dynamic(
5453
size_t item_size);
5554

5655
/**
57-
* Initializes an array list with a preallocated array of void *. item_count is
58-
* the number of elements in the array, and item_size is the size in bytes of
59-
* each element. Mixing items types is not supported by this API. Once this list
60-
* is full, new items will be rejected.
56+
* Initializes an array list with a preallocated array of void *. item_count is the number of elements in the array,
57+
* and item_size is the size in bytes of each element. Mixing items types is not supported
58+
* by this API. Once this list is full, new items will be rejected.
6159
*/
6260
AWS_COMMON_API
6361
void aws_array_list_init_static(struct aws_array_list *list, void *raw_array, size_t item_count, size_t item_size);
6462

6563
/**
66-
* Deallocates any memory that was allocated for this list, and resets list for
67-
* reuse or deletion.
64+
* Deallocates any memory that was allocated for this list, and resets list for reuse or deletion.
6865
*/
6966
AWS_COMMON_API
7067
void aws_array_list_clean_up(struct aws_array_list *list);
@@ -76,17 +73,15 @@ AWS_COMMON_API
7673
int aws_array_list_push_back(struct aws_array_list *list, const void *val);
7774

7875
/**
79-
* Copies the element at the front of the list if it exists. If list is empty,
80-
* AWS_ERROR_LIST_EMPTY will be raised
76+
* Copies the element at the front of the list if it exists. If list is empty, AWS_ERROR_LIST_EMPTY will be raised
8177
*/
8278
AWS_COMMON_API
8379
int aws_array_list_front(const struct aws_array_list *list, void *val);
8480

8581
/**
86-
* Deletes the element at the front of the list if it exists. If list is empty,
87-
* AWS_ERROR_LIST_EMPTY will be raised. This call results in shifting all of the
88-
* elements at the end of the array to the front. Avoid this call unless that is
89-
* intended behavior.
82+
* Deletes the element at the front of the list if it exists. If list is empty, AWS_ERROR_LIST_EMPTY will be raised.
83+
* This call results in shifting all of the elements at the end of the array to the front. Avoid this call unless that
84+
* is intended behavior.
9085
*/
9186
AWS_COMMON_API
9287
int aws_array_list_pop_front(struct aws_array_list *list);
@@ -101,51 +96,45 @@ AWS_COMMON_API
10196
void aws_array_list_pop_front_n(struct aws_array_list *list, size_t n);
10297

10398
/**
104-
* Copies the element at the end of the list if it exists. If list is empty,
105-
* AWS_ERROR_LIST_EMPTY will be raised.
99+
* Copies the element at the end of the list if it exists. If list is empty, AWS_ERROR_LIST_EMPTY will be raised.
106100
*/
107101
AWS_COMMON_API
108102
int aws_array_list_back(const struct aws_array_list *list, void *val);
109103

110104
/**
111-
* Deletes the element at the end of the list if it exists. If list is empty,
112-
* AWS_ERROR_LIST_EMPTY will be raised.
105+
* Deletes the element at the end of the list if it exists. If list is empty, AWS_ERROR_LIST_EMPTY will be raised.
113106
*/
114107
AWS_COMMON_API
115108
int aws_array_list_pop_back(struct aws_array_list *list);
116109

117110
/**
118-
* Clears all elements in the array and resets length to zero. Size does not
119-
* change in this operation.
111+
* Clears all elements in the array and resets length to zero. Size does not change in this operation.
120112
*/
121113
AWS_COMMON_API
122114
void aws_array_list_clear(struct aws_array_list *list);
123115

124116
/**
125-
* If in dynamic mode, shrinks the allocated array size to the minimum amount
126-
* necessary to store its elements.
117+
* If in dynamic mode, shrinks the allocated array size to the minimum amount necessary to store its elements.
127118
*/
128119
AWS_COMMON_API
129120
int aws_array_list_shrink_to_fit(struct aws_array_list *list);
130121

131122
/**
132-
* Copies the elements from from to to. If to is in static mode, it must at
133-
* least be the same length as from. Any data in to will be overwritten in this
134-
* copy.
123+
* Copies the elements from from to to. If to is in static mode, it must at least be the same length as from. Any data
124+
* in to will be overwritten in this copy.
135125
*/
136126
AWS_COMMON_API
137127
int aws_array_list_copy(const struct aws_array_list *from, struct aws_array_list *to);
138128

139129
/**
140-
* Swap contents between two dynamic lists. Both lists must use the same
141-
* allocator.
130+
* Swap contents between two dynamic lists. Both lists must use the same allocator.
142131
*/
143132
AWS_COMMON_API
144133
void aws_array_list_swap_contents(struct aws_array_list *list_a, struct aws_array_list *list_b);
145134

146135
/**
147-
* Returns the number of elements that can fit in the internal array. If list is
148-
* initialized in dynamic mode, the capacity changes over time.
136+
* Returns the number of elements that can fit in the internal array. If list is initialized in dynamic mode,
137+
* the capacity changes over time.
149138
*/
150139
AWS_COMMON_API
151140
size_t aws_array_list_capacity(const struct aws_array_list *list);
@@ -157,24 +146,22 @@ AWS_COMMON_API
157146
size_t aws_array_list_length(const struct aws_array_list *list);
158147

159148
/**
160-
* Copies the memory at index to val. If element does not exist,
161-
* AWS_ERROR_INVALID_INDEX will be raised.
149+
* Copies the memory at index to val. If element does not exist, AWS_ERROR_INVALID_INDEX will be raised.
162150
*/
163151
AWS_COMMON_API
164152
int aws_array_list_get_at(const struct aws_array_list *list, void *val, size_t index);
165153

166154
/**
167-
* Copies the memory address of the element at index to *val. If element does
168-
* not exist, AWS_ERROR_INVALID_INDEX will be raised.
155+
* Copies the memory address of the element at index to *val. If element does not exist, AWS_ERROR_INVALID_INDEX will be
156+
* raised.
169157
*/
170158
AWS_COMMON_API
171159
int aws_array_list_get_at_ptr(const struct aws_array_list *list, void **val, size_t index);
172160

173161
/**
174-
* Copies the the memory pointed to by val into the array at index. If in
175-
* dynamic mode, the size will grow by a factor of two when the array is full.
176-
* In static mode, AWS_ERROR_INVALID_INDEX will be raised if the index is past
177-
* the bounds of the array.
162+
* Copies the the memory pointed to by val into the array at index. If in dynamic mode, the size will grow by a factor
163+
* of two when the array is full. In static mode, AWS_ERROR_INVALID_INDEX will be raised if the index is past the bounds
164+
* of the array.
178165
*/
179166
AWS_COMMON_API
180167
int aws_array_list_set_at(struct aws_array_list *list, const void *val, size_t index);
@@ -189,10 +176,10 @@ void aws_array_list_swap(struct aws_array_list *list, size_t a, size_t b);
189176
* Sort elements in the list in-place according to the comparator function.
190177
*/
191178
AWS_COMMON_API
192-
void aws_array_list_sort(struct aws_array_list *list, aws_array_list_comparator compare_fn);
179+
void aws_array_list_sort(struct aws_array_list *list, aws_array_list_comparator_fn *compare_fn);
193180

194181
#ifdef __cplusplus
195182
}
196183
#endif
197184

198-
#endif /* AWS_COMMON_ARRAY_LIST_H */
185+
#endif /*AWS_COMMON_ARRAY_LIST_H */

include/aws/common/byte_buf.h

+12-18
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ AWS_COMMON_API void aws_byte_buf_secure_clean_up(struct aws_byte_buf *buf);
7777
* be inserted into the output. if the input ends with split_on, an empty cursor
7878
* will be appended to the output.
7979
*
80-
* It is the user's responsibility to properly initialize output. Recommended
81-
* number of preallocated elements from output is your most likely guess for the
82-
* upper bound of the number of elements resulting from the split.
80+
* It is the user's responsibility to properly initialize output. Recommended number of preallocated elements from
81+
* output is your most likely guess for the upper bound of the number of elements resulting from the split.
8382
*
8483
* The type that will be stored in output is struct aws_byte_cursor (you'll need
8584
* this for the item size param).
@@ -91,26 +90,21 @@ AWS_COMMON_API
9190
int aws_byte_buf_split_on_char(struct aws_byte_buf *input_str, char split_on, struct aws_array_list *output);
9291

9392
/**
94-
* No copies, no buffer allocations. Fills in output with a list of
95-
* aws_byte_cursor instances where buffer is an offset into the input_str and
96-
* len is the length of that string in the original buffer. N is the max number
97-
* of splits, if this value is zero, it will add all splits to the output.
93+
* No copies, no buffer allocations. Fills in output with a list of aws_byte_cursor instances where buffer is
94+
* an offset into the input_str and len is the length of that string in the original buffer. N is the max number of
95+
* splits, if this value is zero, it will add all splits to the output.
9896
*
9997
* Edge case rules are as follows:
100-
* if the input begins with split_on, an empty cursor will be the first entry in
101-
* output if the input has two adjacent split_on tokens, an empty cursor will be
102-
* inserted into the output. if the input ends with split_on, an empty cursor
103-
* will be appended to the output.
98+
* if the input begins with split_on, an empty cursor will be the first entry in output
99+
* if the input has two adjacent split_on tokens, an empty cursor will be inserted into the output.
100+
* if the input ends with split_on, an empty cursor will be appended to the output.
104101
*
105-
* It is the user's responsibility to properly initialize output. Recommended
106-
* number of preallocated elements from output is your most likely guess for the
107-
* upper bound of the number of elements resulting from the split.
102+
* It is the user's responsibility to properly initialize output. Recommended number of preallocated elements from
103+
* output is your most likely guess for the upper bound of the number of elements resulting from the split.
108104
*
109-
* The type that will be stored in output is struct aws_byte_cursor (you'll need
110-
* this for the item size param).
105+
* The type that will be stored in output is struct aws_byte_cursor (you'll need this for the item size param).
111106
*
112-
* It is the user's responsibility to make sure the input buffer stays in memory
113-
* long enough to use the results.
107+
* It is the user's responsibility to make sure the input buffer stays in memory long enough to use the results.
114108
*/
115109
AWS_COMMON_API
116110
int aws_byte_buf_split_on_char_n(

include/aws/common/clock.h

+4-6
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,15 @@
2222
extern "C" {
2323
#endif
2424
/**
25-
* Get ticks in nanoseconds (usually 100 nanosecond precision) on the high
26-
* resolution clock (most-likely TSC). This clock has no bearing on the actual
27-
* system time. On success, timestamp will be set.
25+
* Get ticks in nanoseconds (usually 100 nanosecond precision) on the high resolution clock (most-likely TSC). This
26+
* clock has no bearing on the actual system time. On success, timestamp will be set.
2827
*/
2928
AWS_COMMON_API
3029
int aws_high_res_clock_get_ticks(uint64_t *timestamp);
3130

3231
/**
33-
* Get ticks in nanoseconds (usually 100 nanosecond precision) on the system
34-
* clock. Reflects actual system time via nanoseconds since unix epoch. Use with
35-
* care since an inaccurately set clock will probably cause bugs. On success,
32+
* Get ticks in nanoseconds (usually 100 nanosecond precision) on the system clock. Reflects actual system time via
33+
* nanoseconds since unix epoch. Use with care since an inaccurately set clock will probably cause bugs. On success,
3634
* timestamp will be set.
3735
*/
3836
AWS_COMMON_API

0 commit comments

Comments
 (0)