aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2021-08-27 11:59:01 -0700
committerGitHub <noreply@github.com>2021-08-27 11:59:01 -0700
commite990fb82b19dcaafd069a8a8e0711ce912579460 (patch)
tree34f69ef9d5aebee2878c48e8beeab87391761b01
parent760b66b9468a104f2fe73ea4be15fa088b7c1b6d (diff)
parent185c2cb59ce08716afc114704a0b99a1776ddf6c (diff)
downloadcxx-e990fb82b19dcaafd069a8a8e0711ce912579460.tar.gz
Merge pull request #921 from dtolnay/cstr-reserve
Fix over-reserve in rust::String::c_str
-rw-r--r--src/cxx.cc5
-rw-r--r--src/symbols/rust_string.rs6
2 files changed, 6 insertions, 5 deletions
diff --git a/src/cxx.cc b/src/cxx.cc
index f22e88c4..7a9728de 100644
--- a/src/cxx.cc
+++ b/src/cxx.cc
@@ -40,7 +40,8 @@ bool cxxbridge1$string$from_utf16(rust::String *self, const char16_t *ptr,
void cxxbridge1$string$drop(rust::String *self) noexcept;
const char *cxxbridge1$string$ptr(const rust::String *self) noexcept;
std::size_t cxxbridge1$string$len(const rust::String *self) noexcept;
-void cxxbridge1$string$reserve_total(rust::String *self, size_t cap) noexcept;
+void cxxbridge1$string$reserve_additional(rust::String *self,
+ size_t additional) noexcept;
// rust::Str
void cxxbridge1$str$new(rust::Str *self) noexcept;
@@ -158,7 +159,7 @@ bool String::empty() const noexcept { return this->size() == 0; }
const char *String::c_str() noexcept {
auto len = this->length();
- cxxbridge1$string$reserve_total(this, len + 1);
+ cxxbridge1$string$reserve_additional(this, 1);
auto ptr = this->data();
const_cast<char *>(ptr)[len] = '\0';
return ptr;
diff --git a/src/symbols/rust_string.rs b/src/symbols/rust_string.rs
index 29bcf85d..6a27dc8e 100644
--- a/src/symbols/rust_string.rs
+++ b/src/symbols/rust_string.rs
@@ -62,7 +62,7 @@ unsafe extern "C" fn string_len(this: &String) -> usize {
this.len()
}
-#[export_name = "cxxbridge1$string$reserve_total"]
-unsafe extern "C" fn string_reserve_total(this: &mut String, cap: usize) {
- this.reserve(cap);
+#[export_name = "cxxbridge1$string$reserve_additional"]
+unsafe extern "C" fn string_reserve_additional(this: &mut String, additional: usize) {
+ this.reserve(additional);
}