Skip to content

Commit

Permalink
Route incref via vtable to avoid alignment issues (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed May 25, 2024
1 parent de8e677 commit bffacbf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion minijinja-contrib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ timezone = ["time-tz"]
[dependencies]
minijinja = { version = "2.0.1", path = "../minijinja", default-features = false }
serde = "1.0.164"
time = { version = "0.3.22", optional = true, features = ["serde", "formatting", "parsing"] }
time = { version = "0.3.35", optional = true, features = ["serde", "formatting", "parsing"] }
time-tz = { version = "1.0.3", features = ["db"], optional = true }

[dev-dependencies]
Expand Down
15 changes: 8 additions & 7 deletions minijinja/src/value/type_erase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ macro_rules! type_erase {
$($($f_impl: fn(*const (), $($p_impl: $t_impl),*) $(-> $r_impl)?,)*)*
__type_id: fn() -> std::any::TypeId,
__type_name: fn() -> &'static str,
__drop: fn(*const ()),
__incref: fn(*const ()),
__decref: fn(*const ()),
}

#[inline(always)]
Expand All @@ -54,7 +55,10 @@ macro_rules! type_erase {
)*)*
__type_id: || std::any::TypeId::of::<T>(),
__type_name: || std::any::type_name::<T>(),
__drop: |ptr| unsafe {
__incref: |ptr| unsafe {
std::sync::Arc::<T>::increment_strong_count(ptr as *const T);
},
__decref: |ptr| unsafe {
std::sync::Arc::from_raw(ptr as *const T);
},
};
Expand Down Expand Up @@ -114,10 +118,7 @@ macro_rules! type_erase {

impl Clone for $erased_t_name {
fn clone(&self) -> Self {
unsafe {
std::sync::Arc::increment_strong_count(self.ptr);
}

(vt(self).__incref)(self.ptr);
Self {
ptr: self.ptr,
vtable: self.vtable,
Expand All @@ -127,7 +128,7 @@ macro_rules! type_erase {

impl Drop for $erased_t_name {
fn drop(&mut self) {
(vt(self).__drop)(self.ptr);
(vt(self).__decref)(self.ptr);
}
}

Expand Down

0 comments on commit bffacbf

Please sign in to comment.