Skip to content

Commit 93b7a06

Browse files
committed
ir: write declaration of global variable like struct fields
1 parent dfa6e5f commit 93b7a06

File tree

9 files changed

+91
-2
lines changed

9 files changed

+91
-2
lines changed

src/bindgen/ir/global.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl Source for Static {
112112
} else if !self.mutable {
113113
out.write("const ");
114114
}
115-
self.ty.write(config, out);
116-
write!(out, " {};", self.export_name());
115+
(self.export_name().to_owned(), self.ty.clone()).write(config, out);
116+
out.write(";");
117117
}
118118
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
extern const char CONST_GLOBAL_ARRAY[128];
7+
8+
extern char MUT_GLOBAL_ARRAY[128];
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif // __cplusplus
9+
10+
extern const char CONST_GLOBAL_ARRAY[128];
11+
12+
extern char MUT_GLOBAL_ARRAY[128];
13+
14+
#ifdef __cplusplus
15+
} // extern "C"
16+
#endif // __cplusplus
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
extern const char CONST_GLOBAL_ARRAY[128];
7+
8+
extern char MUT_GLOBAL_ARRAY[128];
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif // __cplusplus
9+
10+
extern const char CONST_GLOBAL_ARRAY[128];
11+
12+
extern char MUT_GLOBAL_ARRAY[128];
13+
14+
#ifdef __cplusplus
15+
} // extern "C"
16+
#endif // __cplusplus
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <cstdarg>
2+
#include <cstdint>
3+
#include <cstdlib>
4+
#include <new>
5+
6+
extern "C" {
7+
8+
extern const char CONST_GLOBAL_ARRAY[128];
9+
10+
extern char MUT_GLOBAL_ARRAY[128];
11+
12+
} // extern "C"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
extern const char CONST_GLOBAL_ARRAY[128];
7+
8+
extern char MUT_GLOBAL_ARRAY[128];
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif // __cplusplus
9+
10+
extern const char CONST_GLOBAL_ARRAY[128];
11+
12+
extern char MUT_GLOBAL_ARRAY[128];
13+
14+
#ifdef __cplusplus
15+
} // extern "C"
16+
#endif // __cplusplus

tests/rust/global_variable.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[no_mangle]
2+
pub static mut MUT_GLOBAL_ARRAY: [c_char; 128] = [0; 128];
3+
4+
#[no_mangle]
5+
pub static CONST_GLOBAL_ARRAY: [c_char; 128] = [0; 128];

0 commit comments

Comments
 (0)