Skip to content
Snippets Groups Projects
Commit 22fa8b08 authored by Dan Robertson's avatar Dan Robertson Committed by Ryan Hunt
Browse files

Ensure that a constants cfg is preserved

When writing out constants the cfg attribute is not written out around
the defined constant.
parent d78a4524
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ use std::mem;
use syn;
use bindgen::config::{Config, Language};
use bindgen::ir::{AnnotationSet, Cfg, Documentation, Item, ItemContainer, Type};
use bindgen::ir::{AnnotationSet, Cfg, CfgWrite, Documentation, Item, ItemContainer, Type};
use bindgen::writer::{Source, SourceWriter};
#[derive(Debug, Clone)]
......@@ -132,6 +132,7 @@ impl Item for Constant {
impl Source for Constant {
fn write<F: Write>(&self, config: &Config, out: &mut SourceWriter<F>) {
self.cfg.write_before(config, out);
if config.constant.allow_static_const && config.language == Language::Cxx {
if let Type::ConstPtr(..) = self.ty {
out.write("static ");
......@@ -143,5 +144,6 @@ impl Source for Constant {
} else {
write!(out, "#define {} {}", self.name, self.value.0)
}
self.cfg.write_after(config, out);
}
}
......@@ -2,6 +2,14 @@
#include <stdlib.h>
#include <stdbool.h>
#if defined(NOT_DEFINED)
#define DEFAULT_X 8
#endif
#if defined(DEFINED)
#define DEFAULT_X 42
#endif
#if (defined(NOT_DEFINED) || defined(DEFINED))
typedef struct {
int32_t x;
......
#include <cstdint>
#include <cstdlib>
#if defined(NOT_DEFINED)
static const int32_t DEFAULT_X = 8;
#endif
#if defined(DEFINED)
static const int32_t DEFAULT_X = 42;
#endif
#if (defined(NOT_DEFINED) || defined(DEFINED))
struct Foo {
int32_t x;
......
......@@ -21,6 +21,12 @@ struct Root {
w: Bar,
}
#[cfg(windows)]
pub const DEFAULT_X: i32 = 0x08;
#[cfg(unix)]
pub const DEFAULT_X: i32 = 0x2a;
#[no_mangle]
pub extern "C" fn root(a: Root)
{ }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment