Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes based on static analysis. #857

Merged
merged 6 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/misc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
Major changes are listed below. Each release likely contains fiddling with back-end code,
updates to latest `fwdpp` version, etc.

## 0.17.0a2

Bug fixes:

* Fixed a "use after move" error in C++ code used to pickle {class}`fwdpy11.DiscreteDemography`.
It looks like this bug was introduced back in {pr}`791`, which was part of the 0.16.0 release.
PR {pr}`857`

## 0.17.0a1

Changes to `fwdpy11.conditional_models`:
Expand Down
2 changes: 1 addition & 1 deletion fwdpy11/headers/fwdpy11/evolvets/recorders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace fwdpy11
*/
{
inline void
operator()(const DiploidPopulation&, SampleRecorder&) const
operator()(const DiploidPopulation&, SampleRecorder&)
{
}
};
Expand Down
5 changes: 2 additions & 3 deletions fwdpy11/src/discrete_demography/DiscreteDemography.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ init_DiscreteDemography(py::module& m)
d["selfing_rates"].cast<ddemog::selfing_rates_vector::value_type>());

ddemog::deme_properties sizes_rates(
std::move(current_deme_sizes), std::move(next_deme_sizes),
std::move(growth_rates_onset_times), std::move(growth_initial_sizes),
std::move(growth_rates), std::move(selfing_rates));
current_deme_sizes, next_deme_sizes, growth_rates_onset_times,
growth_initial_sizes, growth_rates, selfing_rates);

ddemog::MigrationMatrix M{};
auto t = d["migmatrix"].cast<py::tuple>();
Expand Down
2 changes: 1 addition & 1 deletion fwdpy11/src/evolve_population/cleanup_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cleanup_metadata(const fwdpp::ts::std_table_collection& tables,
{
metadata.erase(
std::remove_if(begin(metadata), end(metadata),
[generation, &tables](fwdpy11::DiploidMetadata& md) {
[generation, &tables](const fwdpy11::DiploidMetadata& md) {
return tables.nodes[md.nodes[0]].time
== generation
|| tables.nodes[md.nodes[1]].time
Expand Down
2 changes: 1 addition & 1 deletion fwdpy11/src/evolve_population/remove_extinct_mutations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ remove_extinct_mutations(fwdpy11::Population& pop)
}
}
pop.mutations.erase(std::remove_if(begin(pop.mutations), end(pop.mutations),
[](fwdpy11::Mutation& m) {
[](const fwdpy11::Mutation& m) {
return m.pos
== std::numeric_limits<double>::max();
}),
Expand Down
2 changes: 1 addition & 1 deletion fwdpy11/src/evolve_population/track_mutation_counts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ track_mutation_counts(fwdpy11::Population &pop, const bool simplified,
throw std::runtime_error(
"track_mutation_counts: count vector size mismatch");
}
if (!simplified || (simplified && suppress_edge_table_indexing))
if (!simplified || suppress_edge_table_indexing)
{
fwdpp::fwdpp_internal::process_haploid_genomes(
pop.haploid_genomes, pop.mutations, pop.mcounts);
Expand Down
15 changes: 7 additions & 8 deletions fwdpy11/src/functions/add_mutation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,13 @@ namespace
s = si();
}
if (deme < 0
|| (deme >= 0
&& std::all_of(
begin(descendants), end(descendants),
[&pop,
deme](fwdpp::ts::table_index_t i) {
return pop.tables->nodes[i].deme
== deme;
})))
|| std::all_of(
begin(descendants), end(descendants),
[&pop,
deme](fwdpp::ts::table_index_t i) {
return pop.tables->nodes[i].deme
== deme;
}))
{
if (node_has_valid_time(
pop.tables->nodes, n,
Expand Down
2 changes: 1 addition & 1 deletion fwdpy11/src/fwdpp_types/DataMatrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ init_data_matrix(py::module &m)

py::class_<fwdpp::data_matrix, std::shared_ptr<fwdpp::data_matrix>>(
m, "ll_DataMatrix")
.def(py::init([](std::shared_ptr<fwdpp::data_matrix> &p) {
.def(py::init([](const std::shared_ptr<fwdpp::data_matrix> &p) {
if (p == nullptr)
{
throw std::invalid_argument("input pointer is nullptr");
Expand Down
2 changes: 1 addition & 1 deletion fwdpy11/src/fwdpp_types/TableCollection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ init_ts_TableCollection(py::module& m)
// TODO: allow access to the "right" member functions
py::class_<fwdpp::ts::std_table_collection,
std::shared_ptr<fwdpp::ts::std_table_collection>>(m, "ll_TableCollection")
.def(py::init([](std::shared_ptr<fwdpp::ts::std_table_collection>& self) {
.def(py::init([](const std::shared_ptr<fwdpp::ts::std_table_collection>& self) {
if (self == nullptr)
{
throw std::invalid_argument("input tables cannot be nullptr");
Expand Down
4 changes: 2 additions & 2 deletions fwdpy11/src/fwdpy11_types/DiploidPopulation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ init_DiploidPopulation(py::module& m)
return pop;
}))
.def("_dump_to_file",
[](const fwdpy11::DiploidPopulation& pop, const std::string filename) {
[](const fwdpy11::DiploidPopulation& pop, const std::string & filename) {
std::ofstream out(filename.c_str(), std::ios_base::binary);
if (!out)
{
Expand All @@ -132,7 +132,7 @@ init_DiploidPopulation(py::module& m)
})
.def_static(
"_load_from_file",
[](const std::string filename) {
[](const std::string & filename) {
std::ifstream in(filename.c_str(), std::ios_base::binary);
if (!in)
{
Expand Down
2 changes: 1 addition & 1 deletion fwdpy11/src/genetic_values/PyDiploidGeneticValue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ strict_additive_effects(const fwdpy11::DiploidPopulation& pop,
const fwdpy11::DiploidMetadata& individual)
{
double g = 0.0;
auto& diploid = pop.diploids[individual.label];
const auto& diploid = pop.diploids[individual.label];
for (auto k : pop.haploid_genomes[diploid.first].smutations)
{
g += pop.mutations[k].s;
Expand Down
2 changes: 1 addition & 1 deletion tests/test_discrete_demography_with_tree_sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ def test_evolve_in_two_steps_restart_with_two_demes(self):
self.assertEqual(deme_sizes[1][1], self.N1t)

@unittest.skip(
reason="Fixing issue 775 means that this no longer works because pickling DiscreteDemography does not fully round-trip the internal model state"
reason="Fixing issue 775 means that this no longer works because pickling DiscreteDemography does not fully round-trip the internal model state. See issue 777"
)
def test_evolve_in_two_steps_restart_with_two_demes_and_pickle(self):
"""
Expand Down