Skip to content

Commit

Permalink
Define rust::isize with Windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Apr 10, 2020
1 parent 4b97272 commit b8a6fb2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion gen/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ fn write_include_cxxbridge(out: &mut OutFile, apis: &[Api], types: &Types) {
let mut needs_rust_str = false;
let mut needs_rust_box = false;
let mut needs_rust_fn = false;
let mut needs_rust_isize = false;
for ty in types {
match ty {
Type::RustBox(_) => {
Expand All @@ -124,6 +125,9 @@ fn write_include_cxxbridge(out: &mut OutFile, apis: &[Api], types: &Types) {
Type::Fn(_) => {
needs_rust_fn = true;
}
ty if ty == Isize => {
needs_rust_isize = true;
}
ty if ty == RustString => {
out.include.array = true;
out.include.cstdint = true;
Expand Down Expand Up @@ -181,6 +185,7 @@ fn write_include_cxxbridge(out: &mut OutFile, apis: &[Api], types: &Types) {
|| needs_rust_box
|| needs_rust_fn
|| needs_rust_error
|| needs_rust_isize
|| needs_unsafe_bitcopy
|| needs_manually_drop
|| needs_maybe_uninit
Expand All @@ -199,6 +204,7 @@ fn write_include_cxxbridge(out: &mut OutFile, apis: &[Api], types: &Types) {
write_header_section(out, needs_rust_box, "CXXBRIDGE02_RUST_BOX");
write_header_section(out, needs_rust_fn, "CXXBRIDGE02_RUST_FN");
write_header_section(out, needs_rust_error, "CXXBRIDGE02_RUST_ERROR");
write_header_section(out, needs_rust_isize, "CXXBRIDGE02_RUST_ISIZE");
write_header_section(out, needs_unsafe_bitcopy, "CXXBRIDGE02_RUST_BITCOPY");

if needs_manually_drop {
Expand Down Expand Up @@ -689,7 +695,7 @@ fn write_type(out: &mut OutFile, ty: &Type) {
Some(I16) => write!(out, "int16_t"),
Some(I32) => write!(out, "int32_t"),
Some(I64) => write!(out, "int64_t"),
Some(Isize) => write!(out, "ssize_t"),
Some(Isize) => write!(out, "::rust::isize"),
Some(F32) => write!(out, "float"),
Some(F64) => write!(out, "double"),
Some(CxxString) => write!(out, "::std::string"),
Expand Down
9 changes: 9 additions & 0 deletions include/cxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ class Error final : std::exception {
};
#endif // CXXBRIDGE02_RUST_ERROR

#ifndef CXXBRIDGE02_RUST_ISIZE
#define CXXBRIDGE02_RUST_ISIZE
#if defined(_WIN32)
using isize = SSIZE_T;
#else
using isize = ssize_t;
#endif
#endif // CXXBRIDGE02_RUST_ISIZE

std::ostream &operator<<(std::ostream &, const String &);
std::ostream &operator<<(std::ostream &, const Str &);

Expand Down

0 comments on commit b8a6fb2

Please sign in to comment.