Mentions légales du service

Skip to content
Snippets Groups Projects
Commit b254dd09 authored by David Parsons's avatar David Parsons
Browse files

hide sequence ownership transfer into ParamLoader::load

parent e47177f5
No related branches found
No related tags found
No related merge requests found
......@@ -91,9 +91,7 @@ int main(int argc, char* argv[]) {
exit(EXIT_FAILURE);
}
lchromosome = strlen(raw_chromosome) - 1;
chromosome = new char[lchromosome + 1]; // Warning: will become the DNA of the
// first individual created -> do not
// delete, will be freed in Dna
chromosome = new char[lchromosome + 1];
strncpy(chromosome, raw_chromosome, lchromosome + 1);
printf("Loading chromosome from text file %s (%" PRId32 " base pairs) \n",
chromosome_file_name, lchromosome);
......@@ -104,6 +102,7 @@ int main(int argc, char* argv[]) {
if(param_file_name != nullptr) {
if (lchromosome > -1) {
ParamLoader::load(param_values, exp_manager, true, chromosome, lchromosome);
delete chromosome;
} else {
ParamLoader::load(param_values, exp_manager, true);
}
......
......@@ -46,7 +46,7 @@ namespace aevol {
void ParamLoader::load(const ParamValues& param_values,
ExpManager* exp_m,
bool verbose,
char* chromosome,
const char* chromosome,
int32_t lchromosome) {
// Initialize master prng
// Will be used to create the initial genome(s) and to generate seeds for the other prngs
......@@ -275,7 +275,12 @@ void ParamLoader::load(const ParamValues& param_values,
#endif
indiv->add_GU(chromosome, lchromosome);
// Make a copy of the provided chromosome and transfer ownership to the genetic unit we create with it
char* chromosome_copy = new char[lchromosome + 1];
strncpy(chromosome_copy, chromosome, lchromosome + 1);
indiv->add_GU(chromosome_copy, lchromosome);
chromosome_copy = nullptr;
indiv->genetic_unit_nonconst(0).set_min_gu_length(param_values.chromosome_minimal_length_);
indiv->genetic_unit_nonconst(0).set_max_gu_length(param_values.chromosome_maximal_length_);
......
......@@ -59,7 +59,7 @@ class ParamLoader {
static void load(const ParamValues& param_values,
ExpManager* exp_m,
bool verbose = false,
char* chromosome = nullptr,
const char* chromosome = nullptr,
int32_t lchromosome = 0);
protected:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment