Skip to content

Commit 777e3cb

Browse files
committed
clang-format
1 parent 4659911 commit 777e3cb

File tree

40 files changed

+458
-461
lines changed

40 files changed

+458
-461
lines changed

.clang-format

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
---
22
BasedOnStyle: Google
3+
IndentWidth: 4
34
...

examples/android/allocator_library.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,29 @@ __attribute__((weak)) uint8_t __rust_alloc_error_handler_should_panic = 0;
2626
extern "C" uint8_t *__rdl_alloc(uintptr_t size, uintptr_t align);
2727
extern "C" __attribute__((weak)) uint8_t *__rust_alloc(uintptr_t size,
2828
uintptr_t align) {
29-
return __rdl_alloc(size, align);
29+
return __rdl_alloc(size, align);
3030
}
3131
extern "C" void __rdl_dealloc(uint8_t *ptr, uintptr_t size, uintptr_t align);
3232
extern "C" __attribute__((weak)) void __rust_dealloc(uint8_t *ptr,
3333
uintptr_t size,
3434
uintptr_t align) {
35-
__rdl_dealloc(ptr, size, align);
35+
__rdl_dealloc(ptr, size, align);
3636
}
3737
extern "C" uint8_t *__rdl_realloc(uint8_t *ptr, uintptr_t old_size,
3838
uintptr_t align, uintptr_t new_size);
3939
extern "C" __attribute__((weak)) uint8_t *__rust_realloc(uint8_t *ptr,
4040
uintptr_t old_size,
4141
uintptr_t align,
4242
uintptr_t new_size) {
43-
return __rdl_realloc(ptr, old_size, align, new_size);
43+
return __rdl_realloc(ptr, old_size, align, new_size);
4444
}
4545
extern "C" uint8_t *__rdl_alloc_zeroed(uintptr_t size, uintptr_t align);
4646
extern "C" __attribute__((weak)) uint8_t *__rust_alloc_zeroed(uintptr_t size,
4747
uintptr_t align) {
48-
return __rdl_alloc_zeroed(size, align);
48+
return __rdl_alloc_zeroed(size, align);
4949
}
5050
extern "C" void __rdl_oom(uintptr_t size, uintptr_t align);
5151
extern "C" __attribute__((weak)) void __rust_alloc_error_handler(
5252
uintptr_t size, uintptr_t align) {
53-
__rdl_oom(size, align);
53+
__rdl_oom(size, align);
5454
}

examples/android/android_link_hack.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// https://github.com/bazelbuild/rules_rust/issues/1271
22
extern void android_link_hack(void);
33

4-
void call_link_hack(void) {
5-
android_link_hack();
6-
}
4+
void call_link_hack(void) { android_link_hack(); }

examples/ffi/c_calling_rust/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
extern int32_t my_favorite_number();
55

66
int main(int argc, char** argv) {
7-
assert(my_favorite_number() == 4);
8-
return 0;
7+
assert(my_favorite_number() == 4);
8+
return 0;
99
}

examples/ffi/rust_calling_c/c/matrix.c

+82-82
Original file line numberDiff line numberDiff line change
@@ -18,106 +18,106 @@
1818
#include <string.h>
1919

2020
Matrix* matrix_new(size_t rows, size_t cols, const uint64_t* data) {
21-
if (data == NULL) {
22-
return NULL;
23-
}
24-
Matrix* matrix = (Matrix*)malloc(sizeof(*matrix));
25-
if (matrix == NULL) {
26-
return NULL;
27-
}
28-
matrix->rows = rows;
29-
matrix->cols = cols;
30-
matrix->data = (uint64_t*)malloc(rows * cols * sizeof(*(matrix->data)));
31-
memcpy(matrix->data, data, rows * cols * sizeof(*data));
32-
return matrix;
21+
if (data == NULL) {
22+
return NULL;
23+
}
24+
Matrix* matrix = (Matrix*)malloc(sizeof(*matrix));
25+
if (matrix == NULL) {
26+
return NULL;
27+
}
28+
matrix->rows = rows;
29+
matrix->cols = cols;
30+
matrix->data = (uint64_t*)malloc(rows * cols * sizeof(*(matrix->data)));
31+
memcpy(matrix->data, data, rows * cols * sizeof(*data));
32+
return matrix;
3333
}
3434

3535
int matrix_at(const Matrix* matrix, size_t row, size_t col, uint64_t* n) {
36-
if (matrix == NULL || matrix->data == NULL || n == NULL) {
37-
return 0;
38-
}
39-
if (row >= matrix->rows || col >= matrix->cols) {
40-
return 0;
41-
}
42-
*n = matrix->data[row * matrix->cols + col];
43-
return 1;
36+
if (matrix == NULL || matrix->data == NULL || n == NULL) {
37+
return 0;
38+
}
39+
if (row >= matrix->rows || col >= matrix->cols) {
40+
return 0;
41+
}
42+
*n = matrix->data[row * matrix->cols + col];
43+
return 1;
4444
}
4545

4646
int matrix_set(const Matrix* matrix, size_t row, size_t col, uint64_t n) {
47-
if (matrix == NULL || matrix->data == NULL) {
48-
return 0;
49-
}
50-
if (row >= matrix->rows || col >= matrix->cols) {
51-
return 0;
52-
}
53-
matrix->data[row * matrix->cols + col] = n;
54-
return 1;
47+
if (matrix == NULL || matrix->data == NULL) {
48+
return 0;
49+
}
50+
if (row >= matrix->rows || col >= matrix->cols) {
51+
return 0;
52+
}
53+
matrix->data[row * matrix->cols + col] = n;
54+
return 1;
5555
}
5656

5757
void matrix_transpose(Matrix* matrix) {
58-
if (matrix == NULL || matrix->data == NULL) {
59-
return;
60-
}
61-
62-
size_t len = matrix->rows * matrix->cols;
63-
int* visited = (int*)malloc(len * sizeof(*visited));
64-
if (visited == NULL) {
65-
return;
66-
}
67-
memset(visited, 0, len * sizeof(*visited));
58+
if (matrix == NULL || matrix->data == NULL) {
59+
return;
60+
}
6861

69-
// Follow-the-cycles implementation of matrix transposition. Note that we
70-
// skip the last element since it always has a cycle of length 1 and thus
71-
// does not need to be moved.
72-
size_t q = matrix->rows * matrix->cols - 1;
73-
for (size_t i = 0; i < q; ++i) {
74-
if (visited[i] == 1) {
75-
continue;
62+
size_t len = matrix->rows * matrix->cols;
63+
int* visited = (int*)malloc(len * sizeof(*visited));
64+
if (visited == NULL) {
65+
return;
7666
}
77-
size_t current_idx = i;
78-
size_t next_idx = i;
79-
do {
80-
visited[current_idx] = 1;
81-
next_idx = (current_idx * matrix->cols) % q;
82-
if (next_idx == i) {
83-
break;
84-
}
67+
memset(visited, 0, len * sizeof(*visited));
68+
69+
// Follow-the-cycles implementation of matrix transposition. Note that we
70+
// skip the last element since it always has a cycle of length 1 and thus
71+
// does not need to be moved.
72+
size_t q = matrix->rows * matrix->cols - 1;
73+
for (size_t i = 0; i < q; ++i) {
74+
if (visited[i] == 1) {
75+
continue;
76+
}
77+
size_t current_idx = i;
78+
size_t next_idx = i;
79+
do {
80+
visited[current_idx] = 1;
81+
next_idx = (current_idx * matrix->cols) % q;
82+
if (next_idx == i) {
83+
break;
84+
}
8585

86-
uint64_t current_val = matrix->data[current_idx];
87-
matrix->data[current_idx] = matrix->data[next_idx];
88-
matrix->data[next_idx] = current_val;
89-
current_idx = next_idx;
90-
} while (1);
91-
}
86+
uint64_t current_val = matrix->data[current_idx];
87+
matrix->data[current_idx] = matrix->data[next_idx];
88+
matrix->data[next_idx] = current_val;
89+
current_idx = next_idx;
90+
} while (1);
91+
}
9292

93-
free(visited);
94-
size_t cols = matrix->rows;
95-
matrix->rows = matrix->cols;
96-
matrix->cols = cols;
93+
free(visited);
94+
size_t cols = matrix->rows;
95+
matrix->rows = matrix->cols;
96+
matrix->cols = cols;
9797
}
9898

9999
int matrix_equal(const Matrix* a, const Matrix* b) {
100-
if (a == NULL || b == NULL || a->data == NULL || b->data == NULL) {
101-
return 0;
102-
}
103-
if (a->rows != b->rows || a->cols != b->cols) {
104-
return 0;
105-
}
106-
size_t len = a->rows * a->cols;
107-
for (size_t i = 0; i < len; ++i) {
108-
if (a->data[i] != b->data[i]) {
109-
return 0;
100+
if (a == NULL || b == NULL || a->data == NULL || b->data == NULL) {
101+
return 0;
102+
}
103+
if (a->rows != b->rows || a->cols != b->cols) {
104+
return 0;
110105
}
111-
}
112-
return 1;
106+
size_t len = a->rows * a->cols;
107+
for (size_t i = 0; i < len; ++i) {
108+
if (a->data[i] != b->data[i]) {
109+
return 0;
110+
}
111+
}
112+
return 1;
113113
}
114114

115115
void matrix_free(Matrix* matrix) {
116-
if (matrix == NULL) {
117-
return;
118-
}
119-
if (matrix->data != NULL) {
120-
free(matrix->data);
121-
}
122-
free(matrix);
116+
if (matrix == NULL) {
117+
return;
118+
}
119+
if (matrix->data != NULL) {
120+
free(matrix->data);
121+
}
122+
free(matrix);
123123
}

examples/ffi/rust_calling_c/c/matrix.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
#include <stdlib.h>
2020

2121
typedef struct {
22-
size_t rows;
23-
size_t cols;
24-
uint64_t* data;
22+
size_t rows;
23+
size_t cols;
24+
uint64_t* data;
2525
} Matrix;
2626

2727
// Constructs a new Matrix from the given data.

examples/ffi/rust_calling_c/c/matrix_test.c

+32-32
Original file line numberDiff line numberDiff line change
@@ -21,56 +21,56 @@
2121
#include <stdlib.h>
2222

2323
void matrix_print(const Matrix* m) {
24-
for (size_t i = 0; i < m->rows; ++i) {
25-
for (size_t j = 0; j < m->cols; ++j) {
26-
uint64_t val = 0;
27-
matrix_at(m, i, j, &val);
28-
printf("%" PRIu64 " ", val);
24+
for (size_t i = 0; i < m->rows; ++i) {
25+
for (size_t j = 0; j < m->cols; ++j) {
26+
uint64_t val = 0;
27+
matrix_at(m, i, j, &val);
28+
printf("%" PRIu64 " ", val);
29+
}
30+
printf("\n");
2931
}
30-
printf("\n");
31-
}
3232
}
3333

3434
int check_equal(const Matrix* a, const Matrix* b) {
35-
int equal = matrix_equal(a, b);
36-
if (!equal) {
37-
printf("Matrices not equal:\n");
38-
printf("a:\n");
39-
matrix_print(a);
40-
printf("\nb:\n");
41-
matrix_print(b);
42-
}
43-
return equal;
35+
int equal = matrix_equal(a, b);
36+
if (!equal) {
37+
printf("Matrices not equal:\n");
38+
printf("a:\n");
39+
matrix_print(a);
40+
printf("\nb:\n");
41+
matrix_print(b);
42+
}
43+
return equal;
4444
}
4545

4646
void test_equal() {
47-
// clang-format off
47+
// clang-format off
4848
static uint64_t a_data[] = {11, 12, 13, 14,
4949
21, 22, 23, 24};
50-
// clang-format on
51-
Matrix* a = matrix_new(2, 4, a_data);
52-
assert(a != NULL);
53-
assert(check_equal(a, a));
50+
// clang-format on
51+
Matrix* a = matrix_new(2, 4, a_data);
52+
assert(a != NULL);
53+
assert(check_equal(a, a));
5454

55-
// clang-format off
55+
// clang-format off
5656
static uint64_t b_data[] = {13, 14, 15, 16,
5757
22, 23, 24, 25};
58-
// clang-format on
59-
Matrix* b = matrix_new(2, 4, b_data);
60-
assert(b != NULL);
61-
assert(!matrix_equal(a, b));
58+
// clang-format on
59+
Matrix* b = matrix_new(2, 4, b_data);
60+
assert(b != NULL);
61+
assert(!matrix_equal(a, b));
6262
}
6363

6464
void test_transpose() {
65-
// clang-format off
65+
// clang-format off
6666
static uint64_t matrix_data[] = {11, 12, 13, 14,
6767
21, 22, 23, 24};
68-
// clang-format on
69-
Matrix* matrix = matrix_new(2, 4, matrix_data);
70-
assert(matrix != NULL);
71-
matrix_transpose(matrix);
68+
// clang-format on
69+
Matrix* matrix = matrix_new(2, 4, matrix_data);
70+
assert(matrix != NULL);
71+
matrix_transpose(matrix);
7272

73-
// clang-format off
73+
// clang-format off
7474
static uint64_t expected_transpose_data[] = {11, 21,
7575
12, 22,
7676
13, 23,

examples/ios/allocator_library.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,29 @@ __attribute__((weak)) uint8_t __rust_alloc_error_handler_should_panic = 0;
2626
extern "C" uint8_t *__rdl_alloc(uintptr_t size, uintptr_t align);
2727
extern "C" __attribute__((weak)) uint8_t *__rust_alloc(uintptr_t size,
2828
uintptr_t align) {
29-
return __rdl_alloc(size, align);
29+
return __rdl_alloc(size, align);
3030
}
3131
extern "C" void __rdl_dealloc(uint8_t *ptr, uintptr_t size, uintptr_t align);
3232
extern "C" __attribute__((weak)) void __rust_dealloc(uint8_t *ptr,
3333
uintptr_t size,
3434
uintptr_t align) {
35-
__rdl_dealloc(ptr, size, align);
35+
__rdl_dealloc(ptr, size, align);
3636
}
3737
extern "C" uint8_t *__rdl_realloc(uint8_t *ptr, uintptr_t old_size,
3838
uintptr_t align, uintptr_t new_size);
3939
extern "C" __attribute__((weak)) uint8_t *__rust_realloc(uint8_t *ptr,
4040
uintptr_t old_size,
4141
uintptr_t align,
4242
uintptr_t new_size) {
43-
return __rdl_realloc(ptr, old_size, align, new_size);
43+
return __rdl_realloc(ptr, old_size, align, new_size);
4444
}
4545
extern "C" uint8_t *__rdl_alloc_zeroed(uintptr_t size, uintptr_t align);
4646
extern "C" __attribute__((weak)) uint8_t *__rust_alloc_zeroed(uintptr_t size,
4747
uintptr_t align) {
48-
return __rdl_alloc_zeroed(size, align);
48+
return __rdl_alloc_zeroed(size, align);
4949
}
5050
extern "C" void __rdl_oom(uintptr_t size, uintptr_t align);
5151
extern "C" __attribute__((weak)) void __rust_alloc_error_handler(
5252
uintptr_t size, uintptr_t align) {
53-
__rdl_oom(size, align);
53+
__rdl_oom(size, align);
5454
}

examples/proto/common.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ package common;
88
// A configuration object. This is used to test the viability of
99
// protobuf imports.
1010
message Config {
11-
bool verbose = 1;
11+
bool verbose = 1;
1212
}

0 commit comments

Comments
 (0)