Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define rust::isize with Windows support #97

Merged
merged 2 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gen/include.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct Includes {
pub string: bool,
pub type_traits: bool,
pub utility: bool,
pub base_tsd: bool,
}

impl Includes {
Expand Down Expand Up @@ -88,6 +89,11 @@ impl Display for Includes {
if self.utility {
writeln!(f, "#include <utility>")?;
}
if self.base_tsd {
writeln!(f, "#if defined(_WIN32)")?;
writeln!(f, "#include <BaseTsd.h>")?;
writeln!(f, "#endif")?;
}
if *self != Self::default() {
writeln!(f)?;
}
Expand Down
9 changes: 8 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,10 @@ fn write_include_cxxbridge(out: &mut OutFile, apis: &[Api], types: &Types) {
Type::Fn(_) => {
needs_rust_fn = true;
}
ty if ty == Isize => {
out.include.base_tsd = true;
needs_rust_isize = true;
}
ty if ty == RustString => {
out.include.array = true;
out.include.cstdint = true;
Expand Down Expand Up @@ -181,6 +186,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 +205,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 +696,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
12 changes: 12 additions & 0 deletions include/cxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include <string>
#include <type_traits>
#include <utility>
#if defined(_WIN32)
#include <BaseTsd.h>
#endif

namespace rust {
inline namespace cxxbridge02 {
Expand Down Expand Up @@ -180,6 +183,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