Skip to content

Commit

Permalink
Don't use std::string_view::data() when a zero-terminated string is e…
Browse files Browse the repository at this point in the history
…xpected
  • Loading branch information
japsmits authored and johnnovak committed Mar 27, 2024
1 parent 1923bc5 commit c2eb53d
Show file tree
Hide file tree
Showing 29 changed files with 76 additions and 77 deletions.
4 changes: 2 additions & 2 deletions include/dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class DmaChannel {
// Reserves the channel for the owner. If a subsequent reservation is
// made then the previously held reservation callback is run to
// cleanup/remove that reserver (see the EvictReserver call below).
void ReserveFor(const std::string_view new_owner,
void ReserveFor(const std::string& new_owner,
const DMA_ReservationCallback new_cb);

private:
Expand All @@ -93,7 +93,7 @@ class DmaChannel {
uint8_t* const buffer);

DMA_ReservationCallback reservation_callback = {};
std::string_view reservation_owner = {};
std::string reservation_owner = {};
};

class DmaController {
Expand Down
6 changes: 3 additions & 3 deletions include/mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ class MixerChannel {
void SetLowPassFilter(const FilterState state);
void ConfigureHighPassFilter(const uint8_t order, const uint16_t cutoff_freq);
void ConfigureLowPassFilter(const uint8_t order, const uint16_t cutoff_freq);
bool TryParseAndSetCustomFilter(const std::string_view filter_prefs);
bool TryParseAndSetCustomFilter(const std::string& filter_prefs);

bool ConfigureFadeOut(const std::string_view fadeout_prefs);
bool ConfigureFadeOut(const std::string& fadeout_prefs);

void SetResampleMethod(const ResampleMethod method);
void SetZeroOrderHoldUpsamplerTargetFreq(const uint16_t target_freq);
Expand Down Expand Up @@ -407,7 +407,7 @@ class MixerChannel {
Sleeper() = delete;
Sleeper(MixerChannel& c,
const uint16_t sleep_after_ms = default_wait_ms);
bool ConfigureFadeOut(const std::string_view prefs);
bool ConfigureFadeOut(const std::string& prefs);
AudioFrame MaybeFadeOrListen(const AudioFrame& frame);
void MaybeSleep();
bool WakeUp();
Expand Down
4 changes: 2 additions & 2 deletions src/gui/sdl_mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2735,7 +2735,7 @@ static void MAPPER_SaveBinds() {
}

static bool load_binds_from_file(const std::string_view mapperfile_path,
const std::string_view mapperfile_name)
const std::string& mapperfile_name)
{
// If the filename is empty the user wants defaults
if (mapperfile_name == "")
Expand Down Expand Up @@ -2767,7 +2767,7 @@ static bool load_binds_from_file(const std::string_view mapperfile_path,
// default, the mapperfile is not provided
if (!was_loaded && mapperfile_name != MAPPERFILE)
LOG_WARNING("MAPPER: Failed loading mapperfile '%s' directly or from resources",
mapperfile_name.data());
mapperfile_name.c_str());

return was_loaded;
}
Expand Down
8 changes: 4 additions & 4 deletions src/hardware/dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,16 +486,16 @@ void DmaChannel::EvictReserver()
reservation_owner = {};
}

void DmaChannel::ReserveFor(const std::string_view new_owner,
void DmaChannel::ReserveFor(const std::string& new_owner,
const DMA_ReservationCallback new_cb)
{
assert(new_cb);
assert(!new_owner.empty());

if (HasReservation()) {
LOG_MSG("DMA: %s is replacing %s on %d-bit DMA channel %u",
new_owner.data(),
reservation_owner.data(),
new_owner.c_str(),
reservation_owner.c_str(),
is_16bit == 1 ? 16 : 8,
chan_num);
EvictReserver();
Expand Down Expand Up @@ -532,7 +532,7 @@ DmaChannel::~DmaChannel()
{
if (HasReservation()) {
LOG_MSG("DMA: Shutting down %s on %d-bit DMA channel %d",
reservation_owner.data(),
reservation_owner.c_str(),
is_16bit == 1 ? 16 : 8,
chan_num);
EvictReserver();
Expand Down
13 changes: 6 additions & 7 deletions src/hardware/innovation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void Innovation::Open(const std::string_view model_choice,
const std::string_view clock_choice,
const int filter_strength_6581,
const int filter_strength_8580, const int port_choice,
const std::string_view channel_filter_choice)
const std::string& channel_filter_choice)
{
using namespace std::placeholders;

Expand All @@ -45,21 +45,18 @@ void Innovation::Open(const std::string_view model_choice,
return;
}

std::string_view model_name = "";
int filter_strength = 0;
auto sid_service = std::make_unique<reSIDfp::SID>();

// Setup the model and filter
if (model_choice == "8580") {
model_name = "8580";
sid_service->setChipModel(reSIDfp::MOS8580);
filter_strength = filter_strength_8580;
if (filter_strength > 0) {
sid_service->enableFilter(true);
sid_service->setFilter8580Curve(filter_strength / 100.0);
}
} else {
model_name = "6581";
sid_service->setChipModel(reSIDfp::MOS6581);
filter_strength = filter_strength_6581;
if (filter_strength > 0) {
Expand Down Expand Up @@ -97,7 +94,7 @@ void Innovation::Open(const std::string_view model_choice,

if (!filter_choice_has_bool) {
LOG_WARNING("INNOVATION: Invalid 'innovation_filter' setting: '%s', using 'off'",
channel_filter_choice.data());
channel_filter_choice.c_str());
}

mixer_channel->SetHighPassFilter(FilterState::Off);
Expand Down Expand Up @@ -129,16 +126,18 @@ void Innovation::Open(const std::string_view model_choice,
// Ready state-values for rendering
last_rendered_ms = 0.0;

// Variable model_name is only used for logging, so use a const char* here
const char* model_name = model_choice == "8580" ? "8580" : "6581";
constexpr auto us_per_s = 1'000'000.0;
if (filter_strength == 0)
LOG_MSG("INNOVATION: Running on port %xh with a SID %s at %0.3f MHz",
base_port,
model_name.data(),
model_name,
chip_clock / us_per_s);
else
LOG_MSG("INNOVATION: Running on port %xh with a SID %s at %0.3f MHz filtering at %d%%",
base_port,
model_name.data(),
model_name,
chip_clock / us_per_s,
filter_strength);

Expand Down
2 changes: 1 addition & 1 deletion src/hardware/innovation.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Innovation {
void Open(const std::string_view model_choice,
const std::string_view clock_choice, int filter_strength_6581,
int filter_strength_8580, int port_choice,
const std::string_view channel_filter_choice);
const std::string& channel_filter_choice);

void Close();
~Innovation()
Expand Down
6 changes: 3 additions & 3 deletions src/hardware/joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,10 @@ static void configure_calibration(const Section_prop &settings)
if (settings.Get_bool("use_joy_calibration_hotkeys"))
activate_calibration_hotkeys();

auto axis_rates_from_pref = [](const std::string_view pref,
auto axis_rates_from_pref = [](const std::string& pref,
const AxisRateConstants &default_rates) {
if (AxisRateConstants parsed_rates = {};
sscanf(pref.data(), "%lf,%lf", &parsed_rates.scalar, &parsed_rates.offset) == 2) {
sscanf(pref.c_str(), "%lf,%lf", &parsed_rates.scalar, &parsed_rates.offset) == 2) {
LOG_MSG("JOYSTICK: Loaded custom %c-axis calibration parameters (%.6g,%.6g)",
default_rates.axis,
parsed_rates.scalar,
Expand All @@ -537,7 +537,7 @@ static void configure_calibration(const Section_prop &settings)
LOG_WARNING("JOYSTICK: Invalid '%c_calibration' setting: '%s', "
"using 'auto'",
default_rates.axis,
pref.data());
pref.c_str());
return default_rates;
};
const auto x_cal_pref = settings.Get_string("joy_x_calibration");
Expand Down
6 changes: 3 additions & 3 deletions src/hardware/lpt_dac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ LptDac::LptDac(const std::string_view name, const uint16_t channel_rate_hz,
// Setup the mixer callback
channel = MIXER_AddChannel(audio_callback,
channel_rate_hz,
dac_name.data(),
dac_name.c_str(),
features);

ms_per_frame = millis_in_second / channel->GetSampleRate();
Expand All @@ -60,7 +60,7 @@ LptDac::LptDac(const std::string_view name, const uint16_t channel_rate_hz,
status_reg.busy = false;
}

bool LptDac::TryParseAndSetCustomFilter(const std::string_view filter_choice)
bool LptDac::TryParseAndSetCustomFilter(const std::string& filter_choice)
{
assert(channel);
return channel->TryParseAndSetCustomFilter(filter_choice);
Expand Down Expand Up @@ -120,7 +120,7 @@ void LptDac::AudioCallback(const uint16_t requested_frames)

LptDac::~LptDac()
{
LOG_MSG("%s: Shutting down DAC", dac_name.data());
LOG_MSG("%s: Shutting down DAC", dac_name.c_str());

// Update our status to indicate we're no longer ready
status_reg.error = true;
Expand Down
4 changes: 2 additions & 2 deletions src/hardware/lpt_dac.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class LptDac {
virtual void ConfigureFilters(const FilterState state) = 0;
virtual void BindToPort(const io_port_t lpt_port) = 0;

bool TryParseAndSetCustomFilter(const std::string_view filter_choice);
bool TryParseAndSetCustomFilter(const std::string& filter_choice);

protected:
LptDac() = delete;
Expand All @@ -59,7 +59,7 @@ class LptDac {
double last_rendered_ms = 0.0;
double ms_per_frame = 0.0;

std::string_view dac_name = {};
std::string dac_name = {};

// All LPT devices support data write, status read, and control write
void BindHandlers(const io_port_t lpt_port, const io_write_f write_data,
Expand Down
28 changes: 14 additions & 14 deletions src/hardware/mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ static void set_global_chorus(const mixer_channel_t& channel)
}
}

static CrossfeedPreset crossfeed_pref_to_preset(const std::string_view pref)
static CrossfeedPreset crossfeed_pref_to_preset(const std::string& pref)
{
const auto pref_has_bool = parse_bool_setting(pref);
if (pref_has_bool) {
Expand All @@ -340,7 +340,7 @@ static CrossfeedPreset crossfeed_pref_to_preset(const std::string_view pref)
// the conf system programmatically guarantees only the above prefs are
// used
LOG_WARNING("MIXER: Invalid 'crossfeed' setting: '%s', using 'off'",
pref.data());
pref.c_str());
return CrossfeedPreset::None;
}

Expand Down Expand Up @@ -402,7 +402,7 @@ void MIXER_SetCrossfeedPreset(const CrossfeedPreset new_preset)
}
}

static ReverbPreset reverb_pref_to_preset(const std::string_view pref)
static ReverbPreset reverb_pref_to_preset(const std::string& pref)
{
const auto pref_has_bool = parse_bool_setting(pref);
if (pref_has_bool) {
Expand All @@ -427,7 +427,7 @@ static ReverbPreset reverb_pref_to_preset(const std::string_view pref)
// the conf system programmatically guarantees only the above prefs are
// used
LOG_WARNING("MIXER: Invalid 'reverb' setting: '%s', using 'off'",
pref.data());
pref.c_str());
return ReverbPreset::None;
}

Expand Down Expand Up @@ -500,7 +500,7 @@ void MIXER_SetReverbPreset(const ReverbPreset new_preset)
}
}

static ChorusPreset chorus_pref_to_preset(const std::string_view pref)
static ChorusPreset chorus_pref_to_preset(const std::string& pref)
{
const auto pref_has_bool = parse_bool_setting(pref);
if (pref_has_bool) {
Expand All @@ -519,7 +519,7 @@ static ChorusPreset chorus_pref_to_preset(const std::string_view pref)
// the conf system programmatically guarantees only the above prefs are
// used
LOG_WARNING("MIXER: Invalid 'chorus' setting: '%s', using ' off'",
pref.data());
pref.c_str());
return ChorusPreset::None;
}

Expand Down Expand Up @@ -1112,7 +1112,7 @@ void MixerChannel::AddSilence()
}

static void log_filter_settings(const std::string& channel_name,
const std::string_view filter_name,
const std::string& filter_name,
const FilterState state, const uint8_t order,
const uint16_t cutoff_freq)
{
Expand All @@ -1124,7 +1124,7 @@ static void log_filter_settings(const std::string& channel_name,

LOG_MSG("%s: %s filter enabled%s (%d dB/oct at %u Hz)",
channel_name.c_str(),
filter_name.data(),
filter_name.c_str(),
state == FilterState::ForcedOn ? " (forced)" : "",
order * db_per_order,
cutoff_freq);
Expand Down Expand Up @@ -1183,7 +1183,7 @@ void MixerChannel::ConfigureLowPassFilter(const uint8_t order,
// Tries to set custom filter settings from the passed in filter preferences.
// Returns true if the custom filters could be successfully set, false
// otherwise and disables all filters for the channel.
bool MixerChannel::TryParseAndSetCustomFilter(const std::string_view filter_prefs)
bool MixerChannel::TryParseAndSetCustomFilter(const std::string& filter_prefs)
{
SetLowPassFilter(FilterState::Off);
SetHighPassFilter(FilterState::Off);
Expand All @@ -1201,7 +1201,7 @@ bool MixerChannel::TryParseAndSetCustomFilter(const std::string_view filter_pref
LOG_WARNING("%s: Invalid custom filter definition: '%s'. Must be "
"specified in \"lfp|hpf ORDER CUTOFF_FREQUENCY\" format",
name.c_str(),
filter_prefs.data());
filter_prefs.c_str());
return false;
}

Expand Down Expand Up @@ -1283,7 +1283,7 @@ bool MixerChannel::TryParseAndSetCustomFilter(const std::string_view filter_pref
LOG_WARNING("%s: Invalid custom filter definition: '%s'. "
"The two filters must be of different types.",
name.c_str(),
filter_prefs.data());
filter_prefs.c_str());
return false;
}

Expand Down Expand Up @@ -1686,13 +1686,13 @@ AudioFrame MixerChannel::ApplyCrossfeed(const AudioFrame frame) const
}

// Returns true if configuration succeeded and false otherwise
bool MixerChannel::ConfigureFadeOut(const std::string_view prefs)
bool MixerChannel::ConfigureFadeOut(const std::string& prefs)
{
return sleeper.ConfigureFadeOut(prefs);
}

// Returns true if configuration succeeded and false otherwise
bool MixerChannel::Sleeper::ConfigureFadeOut(const std::string_view prefs)
bool MixerChannel::Sleeper::ConfigureFadeOut(const std::string& prefs)
{
auto set_wait_and_fade = [&](const int wait_ms, const int fade_ms) {
fadeout_or_sleep_after_ms = check_cast<uint16_t>(wait_ms);
Expand Down Expand Up @@ -1744,7 +1744,7 @@ bool MixerChannel::Sleeper::ConfigureFadeOut(const std::string_view prefs)
"%d and %d (in milliseconds) and FADE is between %d and "
"%d (in milliseconds). Using 'off'",
channel.GetName().c_str(),
prefs.data(),
prefs.c_str(),
min_wait_ms,
max_wait_ms,
min_fade_ms,
Expand Down
2 changes: 1 addition & 1 deletion src/hardware/pcspeaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PcSpeaker {
virtual ~PcSpeaker() = default;

virtual void SetFilterState(const FilterState filter_state) = 0;
virtual bool TryParseAndSetCustomFilter(const std::string_view filter_choice) = 0;
virtual bool TryParseAndSetCustomFilter(const std::string& filter_choice) = 0;
virtual void SetCounter(const int cntr, const PitMode pit_mode) = 0;
virtual void SetPITControl(const PitMode pit_mode) = 0;
virtual void SetType(const PpiPortB &port_b) = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/hardware/pcspeaker_discrete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ void PcSpeakerDiscrete::SetFilterState(const FilterState filter_state)
}
}

bool PcSpeakerDiscrete::TryParseAndSetCustomFilter(const std::string_view filter_choice)
bool PcSpeakerDiscrete::TryParseAndSetCustomFilter(const std::string& filter_choice)
{
assert(channel);
return channel->TryParseAndSetCustomFilter(filter_choice);
Expand Down
2 changes: 1 addition & 1 deletion src/hardware/pcspeaker_discrete.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PcSpeakerDiscrete final : public PcSpeaker {
~PcSpeakerDiscrete() final;

void SetFilterState(const FilterState filter_state) final;
bool TryParseAndSetCustomFilter(const std::string_view filter_choice) final;
bool TryParseAndSetCustomFilter(const std::string& filter_choice) final;
void SetCounter(const int cntr, const PitMode m) final;
void SetPITControl(const PitMode) final {}
void SetType(const PpiPortB& b) final;
Expand Down
2 changes: 1 addition & 1 deletion src/hardware/pcspeaker_impulse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ void PcSpeakerImpulse::SetFilterState(const FilterState filter_state)
}
}

bool PcSpeakerImpulse::TryParseAndSetCustomFilter(const std::string_view filter_choice)
bool PcSpeakerImpulse::TryParseAndSetCustomFilter(const std::string& filter_choice)
{
assert(channel);
return channel->TryParseAndSetCustomFilter(filter_choice);
Expand Down
2 changes: 1 addition & 1 deletion src/hardware/pcspeaker_impulse.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PcSpeakerImpulse final : public PcSpeaker {
~PcSpeakerImpulse() final;

void SetFilterState(const FilterState filter_state) final;
bool TryParseAndSetCustomFilter(const std::string_view filter_choice) final;
bool TryParseAndSetCustomFilter(const std::string& filter_choice) final;
void SetCounter(const int cntr, const PitMode pit_mode) final;
void SetPITControl(const PitMode pit_mode) final;
void SetType(const PpiPortB& port_b) final;
Expand Down
Loading

0 comments on commit c2eb53d

Please sign in to comment.