libafl: Remove set_initial, initial_mut from MapObserver trait (#932)

These methods force a `MapObserver` to own an initial value, but
there's no reason for this to be the case - If you don't need to allow a
dynamically-changeable initial value, it might be nice to use `<<Self as
MapObserver>::Entry as Default>::default()` everywhere and have the compiler
statically propagate that value.

Not a lot of code used these methods (which seems like a good argument that
they aren't a fundamental part of the inteface).
This commit is contained in:
Langston Barrett 2022-12-08 04:25:18 -05:00 committed by GitHub
parent 61aa764dc4
commit f9eac18542
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -108,14 +108,6 @@ pub trait MapObserver: HasLen + Named + Serialize + serde::de::DeserializeOwned
/// Get the initial value for reset()
fn initial(&self) -> Self::Entry;
/// Get the initial value for reset() (mutable)
fn initial_mut(&mut self) -> &mut Self::Entry;
/// Set the initial value for reset()
fn set_initial(&mut self, initial: Self::Entry) {
*self.initial_mut() = initial;
}
/// Reset the map
fn reset_map(&mut self) -> Result<(), Error>;
@ -389,11 +381,6 @@ where
self.initial
}
#[inline]
fn initial_mut(&mut self) -> &mut T {
&mut self.initial
}
fn to_vec(&self) -> Vec<T> {
self.as_slice().to_vec()
}
@ -776,11 +763,6 @@ where
self.initial
}
#[inline]
fn initial_mut(&mut self) -> &mut T {
&mut self.initial
}
#[inline]
fn get(&self, idx: usize) -> &T {
&self.as_slice()[idx]
@ -1050,11 +1032,6 @@ where
self.initial
}
#[inline]
fn initial_mut(&mut self) -> &mut T {
&mut self.initial
}
#[inline]
fn usable_count(&self) -> usize {
*self.size.as_ref()
@ -1261,11 +1238,6 @@ where
self.base.initial()
}
#[inline]
fn initial_mut(&mut self) -> &mut u8 {
self.base.initial_mut()
}
#[inline]
fn usable_count(&self) -> usize {
self.base.usable_count()
@ -1489,11 +1461,6 @@ where
self.base.initial()
}
#[inline]
fn initial_mut(&mut self) -> &mut u8 {
self.base.initial_mut()
}
#[inline]
fn usable_count(&self) -> usize {
self.base.usable_count()
@ -1734,11 +1701,6 @@ where
self.initial
}
#[inline]
fn initial_mut(&mut self) -> &mut T {
&mut self.initial
}
fn count_bytes(&self) -> u64 {
let initial = self.initial();
let mut res = 0;
@ -2090,16 +2052,6 @@ where
self.initial
}
#[inline]
fn initial_mut(&mut self) -> &mut T {
&mut self.initial
}
#[inline]
fn set_initial(&mut self, initial: T) {
self.initial = initial;
}
/// Reset the map
#[inline]
fn reset_map(&mut self) -> Result<(), Error> {
@ -2478,17 +2430,6 @@ pub mod pybind {
mapob_unwrap_me!($wrapper_name, self.wrapper, m, { m.initial() })
}
#[inline]
fn initial_mut(&mut self) -> &mut $datatype {
let ptr = mapob_unwrap_me_mut!($wrapper_name, self.wrapper, m, { m.initial_mut() as *mut $datatype });
unsafe { ptr.as_mut().unwrap() }
}
#[inline]
fn set_initial(&mut self, initial: $datatype) {
mapob_unwrap_me_mut!($wrapper_name, self.wrapper, m, { m.set_initial(initial) });
}
#[inline]
fn reset_map(&mut self) -> Result<(), Error> {
mapob_unwrap_me_mut!($wrapper_name, self.wrapper, m, { m.reset_map() })