From b8a6fb27559bf27c80e0a9f1ab899f8545002d8b Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 10 Apr 2020 11:17:28 -0700 Subject: [PATCH] Define rust::isize with Windows support --- gen/write.rs | 8 +++++++- include/cxx.h | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/gen/write.rs b/gen/write.rs index 217a59104..9d6ef6e45 100644 --- a/gen/write.rs +++ b/gen/write.rs @@ -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(_) => { @@ -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; @@ -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 @@ -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 { @@ -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"), diff --git a/include/cxx.h b/include/cxx.h index 5de479c4f..6fe55d04c 100644 --- a/include/cxx.h +++ b/include/cxx.h @@ -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 &);