Commit aa9c20bc authored by Ryan Hunt's avatar Ryan Hunt
Browse files

Do not emit `const char*` for `&str`

parent 4b8fbf0a
......@@ -45,7 +45,6 @@ pub enum PrimitiveType {
Float,
Double,
SizeT,
Str,
}
impl PrimitiveType {
......@@ -80,7 +79,6 @@ impl PrimitiveType {
"f32" => Some(PrimitiveType::Float),
"f64" => Some(PrimitiveType::Double),
"size_t" => Some(PrimitiveType::SizeT),
"str" => Some(PrimitiveType::Str),
_ => None,
}
}
......@@ -114,7 +112,6 @@ impl PrimitiveType {
&PrimitiveType::Float => "f32",
&PrimitiveType::Double => "f64",
&PrimitiveType::SizeT => "size_t",
&PrimitiveType::Str => "str",
}
}
......@@ -147,7 +144,6 @@ impl PrimitiveType {
&PrimitiveType::Float => "float",
&PrimitiveType::Double => "double",
&PrimitiveType::SizeT => "size_t",
&PrimitiveType::Str => "char",
}
}
......
......@@ -47,6 +47,10 @@ def gxx(src):
def run_compile_test(rust_src, should_verify, c):
rust_src_name = os.path.basename(rust_src)
expectation = True
if rust_src_name.startswith("fail-"):
expectation = False
if c:
out = os.path.join('tests/expectations/', rust_src_name.replace(".rs", ".c"))
verify = 'tests/expectations/__verify__.c'
......@@ -80,11 +84,11 @@ def run_compile_test(rust_src, should_verify, c):
gxx(out)
except subprocess.CalledProcessError:
if os.exists(verify):
if os.path.exists(verify):
os.remove(verify)
return False
return expectation == False
return True
return expectation == True
if not build_cbindgen():
exit()
......
......@@ -2,8 +2,6 @@
#include <stdlib.h>
#include <stdbool.h>
#define BAR u8"hello world"
#define FOO 10
#define ZOM 3.14
......
......@@ -3,8 +3,6 @@
extern "C" {
static const char* BAR = u8"hello world";
static const int32_t FOO = 10;
static const float ZOM = 3.14;
......
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct {
const str *x;
} Foo;
void root(Foo a, const str *b);
#include <cstdint>
#include <cstdlib>
extern "C" {
struct Foo {
const str *x;
};
void root(Foo a, const str *b);
} // extern "C"
#[repr(C)]
struct Foo<'a> {
x: &'a str,
}
const BAR: &'static str = "";
#[no_mangle]
extern "C" fn root(a: Foo<'static>,
b: &'static str)
{ }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment