From: Matt Corallo Date: Thu, 28 Sep 2023 01:14:41 +0000 (+0000) Subject: Use the resolved type name in generic strings, not the original X-Git-Tag: v0.0.117.0^2~11 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=3398c19e2889fbe22590d8991b4ce1bc176ec1bc;p=ldk-c-bindings Use the resolved type name in generic strings, not the original This makes some generics less readable, but some more, and reduces generic type pollution. Some cases are a loss, eg `Option_PaymentHashZ` gets converted to `Option_ThirtyTwoBytesZ` (which less less readable but fewer total types as a result), but we ultimately need this because we now have `schnorr::Signature` and `ecdsa::Signature` so we can't rely on just using `Signature` and having it be unique :(. --- diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs index b08c6bc..9df1bd1 100644 --- a/c-bindings-gen/src/types.rs +++ b/c-bindings-gen/src/types.rs @@ -2900,7 +2900,14 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { generics, &subtype, is_ref, is_mut, ptr_for_ref, true); } } else { - let id = subtype.rsplitn(2, ':').next().unwrap(); // Get the "Base" name of the resolved type + let mut resolved = Vec::new(); + let id = + if self.write_c_path_intern(&mut resolved, &$p_arg.path, generics, false, false, false, false, false) { + let inner = std::str::from_utf8(&resolved).unwrap(); + inner.rsplitn(2, "::").next().unwrap() + } else { + subtype.rsplitn(2, "::").next().unwrap() + }; write!(w, "{}", id).unwrap(); write!(mangled_type, "{}", id).unwrap(); if let Some(w2) = $extra_write as Option<&mut Vec> { @@ -2934,9 +2941,9 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { } else { return false; } } else if let syn::Type::Array(_) = elem { let mut resolved = Vec::new(); - if !self.write_c_type_intern(&mut resolved, &elem, generics, false, false, true, false, true) { return false; } + if !self.write_c_type_intern(&mut resolved, &elem, generics, false, false, false, false, false) { return false; } let array_inner = String::from_utf8(resolved).unwrap(); - let arr_name = array_inner.split("::").last().unwrap(); + let arr_name = array_inner.rsplitn(2, "::").next().unwrap(); write!(w, "{}", arr_name).unwrap(); write!(mangled_type, "{}", arr_name).unwrap(); } else { return false; }