Skip to content

Commit

Permalink
ir: write declaration of global variable like struct fields
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKK committed Feb 25, 2020
1 parent dfa6e5f commit 4ead654
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/bindgen/ir/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Source for Static {
} else if !self.mutable {
out.write("const ");
}
self.ty.write(config, out);
write!(out, " {};", self.export_name());
(self.export_name().to_owned(), self.ty.clone()).write(config, out);
out.write(";");
}
}
8 changes: 8 additions & 0 deletions tests/expectations/both/global_variable.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

extern const char CONST_GLOBAL_ARRAY[128];

extern char MUT_GLOBAL_ARRAY[128];
16 changes: 16 additions & 0 deletions tests/expectations/both/global_variable.compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

extern const char CONST_GLOBAL_ARRAY[128];

extern char MUT_GLOBAL_ARRAY[128];

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
8 changes: 8 additions & 0 deletions tests/expectations/global_variable.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

extern const char CONST_GLOBAL_ARRAY[128];

extern char MUT_GLOBAL_ARRAY[128];
16 changes: 16 additions & 0 deletions tests/expectations/global_variable.compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

extern const char CONST_GLOBAL_ARRAY[128];

extern char MUT_GLOBAL_ARRAY[128];

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
12 changes: 12 additions & 0 deletions tests/expectations/global_variable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <new>

extern "C" {

extern const char CONST_GLOBAL_ARRAY[128];

extern char MUT_GLOBAL_ARRAY[128];

} // extern "C"
8 changes: 8 additions & 0 deletions tests/expectations/tag/global_variable.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

extern const char CONST_GLOBAL_ARRAY[128];

extern char MUT_GLOBAL_ARRAY[128];
16 changes: 16 additions & 0 deletions tests/expectations/tag/global_variable.compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

extern const char CONST_GLOBAL_ARRAY[128];

extern char MUT_GLOBAL_ARRAY[128];

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
5 changes: 5 additions & 0 deletions tests/rust/global_variable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[no_mangle]
pub static mut MUT_GLOBAL_ARRAY: [c_char; 128] = [0; 128];

#[no_mangle]
pub static CONST_GLOBAL_ARRAY: [c_char; 128] = [0; 128];

0 comments on commit 4ead654

Please sign in to comment.