Skip to content

Commit

Permalink
Correct a crash in Amose
Browse files Browse the repository at this point in the history
Thanks to ASAN for helping finding the problem
  • Loading branch information
kleag committed May 22, 2024
1 parent b7512fa commit 4b3e4df
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ string hexString(const uint128_t x)
class PropertyCodeManagerPrivate
{
friend class PropertyCodeManager;
public:
PropertyCodeManagerPrivate() = default;
~PropertyCodeManagerPrivate() = default;
PropertyCodeManagerPrivate(const PropertyCodeManagerPrivate&) = delete;
PropertyCodeManagerPrivate& operator=(const PropertyCodeManagerPrivate&) = delete;

std::map<std::string,PropertyManager> m_propertyManagers;
std::map<std::string, PropertyManager> m_propertyManagers;

/**
* @brief Compute the number of bit needed to encode nbvalues
Expand All @@ -74,18 +79,17 @@ class PropertyCodeManagerPrivate
};

PropertyCodeManager::PropertyCodeManager() :
m_d(new PropertyCodeManagerPrivate())
m_d(std::make_unique<PropertyCodeManagerPrivate>())
{
}

PropertyCodeManager::~PropertyCodeManager()
{
delete m_d;
}

PropertyCodeManager::PropertyCodeManager(const PropertyCodeManager& pcm)
PropertyCodeManager::PropertyCodeManager(const PropertyCodeManager& pcm) :
m_d(std::make_unique<PropertyCodeManagerPrivate>())
{
m_d = new PropertyCodeManagerPrivate();
m_d->m_propertyManagers = pcm.m_d->m_propertyManagers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class LIMA_PROPERTYCODE_EXPORT PropertyCodeManager
std::map<std::string,LinguisticCode>& conversionTable) const;

private:
PropertyCodeManagerPrivate* m_d;
std::unique_ptr<PropertyCodeManagerPrivate> m_d;
};

} // PropertyCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace PropertyCode
class PropertyManagerPrivate
{
friend class PropertyManager;

public:
PropertyManagerPrivate(const std::string& name,
const LinguisticCode& mask,
const LinguisticCode& emptyNessMask,
Expand Down Expand Up @@ -97,18 +97,17 @@ PropertyManager::PropertyManager(const std::string& name,
const LinguisticCode& mask,
const LinguisticCode& emptyNessMask,
const std::map<std::string,LinguisticCode> symbol2code) :
m_d(new PropertyManagerPrivate(name, mask, emptyNessMask, symbol2code))
m_d(std::make_unique<PropertyManagerPrivate>(name, mask, emptyNessMask, symbol2code))
{
}

PropertyManager::~PropertyManager()
{
delete m_d;
}

PropertyManager::PropertyManager(const PropertyManager& pm)
PropertyManager::PropertyManager(const PropertyManager& pm) :
m_d(std::make_unique<PropertyManagerPrivate>(*pm.m_d))
{
m_d = new PropertyManagerPrivate(*pm.m_d);
}

PropertyManager& PropertyManager::operator=(const PropertyManager& pm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class LIMA_PROPERTYCODE_EXPORT PropertyManager
size_t getNbValues() const;

private:
PropertyManagerPrivate* m_d;
std::unique_ptr<PropertyManagerPrivate> m_d;
};

#define GET_PROPERTY_MANAGER(language, property) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void LTRTextBuilder::updateLTR_TokenFromVertex(
LERROR << "Empty MorphoSyntacticData for vertex" << vertex << ", token=" << fullToken->stringForm();
}

sort(data->begin(),data->end(),ltNormProperty(m_macroAccessor));
sort(data->begin(),data->end(),ltNormProperty(*m_macroAccessor));

StringsPoolIndex norm(0),lastNorm(0);
LinguisticCode macro,lastMacro;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ void SimpleXmlDumper::xmlOutputVertexInfos(
uint64_t offset,
LinguisticCode category) const
{
ltNormProperty sorter(m_propertyAccessor);
ltNormProperty sorter(*m_propertyAccessor);
auto position = ft->position() + offset;

auto output = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void TextDumper::outputVertex(std::ostream& out,
uint64_t offset) const
{

ltNormProperty sorter(m_propertyAccessor);
ltNormProperty sorter(*m_propertyAccessor);

// uint64_t nbmicros=ft->countMicros();
std::ostringstream os;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,59 +25,66 @@ bool ltString::operator()(const LinguisticElement& elem1,const LinguisticElement
return elem1.properties < elem2.properties;
}

ltProperty::ltProperty(const Common::PropertyCode::PropertyAccessor* prop) :
ltProperty::ltProperty(const Common::PropertyCode::PropertyAccessor& prop) :
m_prop(prop)
{}

bool ltProperty::operator()(const LinguisticElement& elem1,const LinguisticElement& elem2) const
{
return m_prop->readValue(elem1.properties) < m_prop->readValue(elem2.properties);
return m_prop.readValue(elem1.properties) < m_prop.readValue(elem2.properties);
}

ltNormProperty::ltNormProperty(const Common::PropertyCode::PropertyAccessor* prop) :
ltNormProperty::ltNormProperty(const Common::PropertyCode::PropertyAccessor& prop) :
m_prop(prop)
{}

bool ltNormProperty::operator()(const LinguisticElement& elem1,const LinguisticElement& elem2) const
{
if (elem1.normalizedForm!=elem2.normalizedForm) return elem1.normalizedForm < elem2.normalizedForm;
return m_prop->readValue(elem1.properties) < m_prop->readValue(elem2.properties);
return m_prop.readValue(elem1.properties) < m_prop.readValue(elem2.properties);
}

CheckEqualPropertyPredicate::CheckEqualPropertyPredicate(const Common::PropertyCode::PropertyAccessor* prop,LinguisticCode value) :
CheckEqualPropertyPredicate::CheckEqualPropertyPredicate(const Common::PropertyCode::PropertyAccessor& prop,LinguisticCode value) :
m_property(prop),
m_value(value)
{}

bool CheckEqualPropertyPredicate::operator()(const LinguisticElement& elem) const
{
return m_property->equal(elem.properties,m_value);
return m_property.equal(elem.properties,m_value);
}

CheckDifferentPropertyPredicate::CheckDifferentPropertyPredicate(const Common::PropertyCode::PropertyAccessor* prop,LinguisticCode value) :
CheckDifferentPropertyPredicate::CheckDifferentPropertyPredicate(
const Common::PropertyCode::PropertyAccessor& prop,
LinguisticCode value) :
m_property(prop),
m_value(value)
{}

bool CheckDifferentPropertyPredicate::operator()(const LinguisticElement& elem) const
{
return !(m_property->equal(elem.properties,m_value));
return !(m_property.equal(elem.properties,m_value));
}

IncludePropertyPredicate::IncludePropertyPredicate(const Common::PropertyCode::PropertyAccessor* prop,const std::set<LinguisticCode>& values) :
IncludePropertyPredicate::IncludePropertyPredicate(
const Common::PropertyCode::PropertyAccessor& prop,
const std::set<LinguisticCode>& values) :
m_property(prop),
m_values(values)
{}

bool IncludePropertyPredicate::operator()(const LinguisticElement& elem) const
{
return (m_values.find(m_property->readValue(elem.properties)) != m_values.end());
return (m_values.find(m_property.readValue(elem.properties)) != m_values.end());
}

ExcludePropertyPredicate::ExcludePropertyPredicate(const Common::PropertyCode::PropertyAccessor* prop,const std::set<LinguisticCode>& values) :
ExcludePropertyPredicate::ExcludePropertyPredicate(
const Common::PropertyCode::PropertyAccessor& prop,
const std::set<LinguisticCode>& values) :
m_property(prop),
m_values(values)
{}
{
}

ExcludePropertyPredicate::ExcludePropertyPredicate(const ExcludePropertyPredicate& epp) :
m_property(epp.m_property),
Expand All @@ -87,7 +94,7 @@ ExcludePropertyPredicate::ExcludePropertyPredicate(const ExcludePropertyPredicat

bool ExcludePropertyPredicate::operator()(const LinguisticElement& elem) const
{
return (m_values.find(m_property->readValue(elem.properties)) == m_values.end());
return (m_values.find(m_property.readValue(elem.properties)) == m_values.end());
}

} // LinguisticAnalysisStructure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,64 +31,69 @@ class LIMA_LINGUISTICANALYSISSTRUCTURE_EXPORT ltString
class LIMA_LINGUISTICANALYSISSTRUCTURE_EXPORT ltProperty
{
public:
ltProperty(const Common::PropertyCode::PropertyAccessor* prop);
bool operator()(const LinguisticElement& elem1,const LinguisticElement& elem2) const;
ltProperty(const Common::PropertyCode::PropertyAccessor& prop);
bool operator()(const LinguisticElement& elem1,
const LinguisticElement& elem2) const;
private:
const Common::PropertyCode::PropertyAccessor* m_prop;
Common::PropertyCode::PropertyAccessor m_prop;
};

class LIMA_LINGUISTICANALYSISSTRUCTURE_EXPORT ltNormProperty
{
public:
ltNormProperty(const Common::PropertyCode::PropertyAccessor* prop);
bool operator()(const LinguisticElement& elem1,const LinguisticElement& elem2) const;
ltNormProperty(const Common::PropertyCode::PropertyAccessor& prop);
bool operator()(const LinguisticElement& elem1,
const LinguisticElement& elem2) const;
private:
const Common::PropertyCode::PropertyAccessor* m_prop;
Common::PropertyCode::PropertyAccessor m_prop;
};

class LIMA_LINGUISTICANALYSISSTRUCTURE_EXPORT CheckEqualPropertyPredicate
{
public:
CheckEqualPropertyPredicate(const Common::PropertyCode::PropertyAccessor* prop,LinguisticCode value);
CheckEqualPropertyPredicate(const Common::PropertyCode::PropertyAccessor& prop,
LinguisticCode value);
bool operator()(const LinguisticElement& elem) const;
private:
const Common::PropertyCode::PropertyAccessor* m_property;
const Common::PropertyCode::PropertyAccessor m_property;
LinguisticCode m_value;
};

class LIMA_LINGUISTICANALYSISSTRUCTURE_EXPORT CheckDifferentPropertyPredicate
{
public:
CheckDifferentPropertyPredicate(const Common::PropertyCode::PropertyAccessor* prop,LinguisticCode value);
CheckDifferentPropertyPredicate(const Common::PropertyCode::PropertyAccessor& prop,
LinguisticCode value);
bool operator()(const LinguisticElement& elem) const;
private:
const Common::PropertyCode::PropertyAccessor* m_property;
Common::PropertyCode::PropertyAccessor m_property;
LinguisticCode m_value;
};

class LIMA_LINGUISTICANALYSISSTRUCTURE_EXPORT IncludePropertyPredicate
{
public:
IncludePropertyPredicate(const Common::PropertyCode::PropertyAccessor* prop,const std::set<LinguisticCode>& value);
IncludePropertyPredicate(const Common::PropertyCode::PropertyAccessor& prop,
const std::set<LinguisticCode>& value);
bool operator()(const LinguisticElement& elem) const;
private:
IncludePropertyPredicate& operator=(const IncludePropertyPredicate&) {return *this;}
const Common::PropertyCode::PropertyAccessor* m_property;
Common::PropertyCode::PropertyAccessor m_property;
const std::set<LinguisticCode>& m_values;
};

class LIMA_LINGUISTICANALYSISSTRUCTURE_EXPORT ExcludePropertyPredicate
{
public:
ExcludePropertyPredicate(const Common::PropertyCode::PropertyAccessor* prop,
ExcludePropertyPredicate(const Common::PropertyCode::PropertyAccessor& prop,
const std::set<LinguisticCode>& value);
ExcludePropertyPredicate(const ExcludePropertyPredicate& epp);

bool operator()(const LinguisticElement& elem) const;

private:
ExcludePropertyPredicate& operator=(const ExcludePropertyPredicate&) {return *this;}
const Common::PropertyCode::PropertyAccessor* m_property;
Common::PropertyCode::PropertyAccessor m_property;
const std::set<LinguisticCode>& m_values;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ LimaStatusCode DynamicSvmToolPosTagger::process(AnalysisContent& analysis) const
if (morphoData!=0)
{
LinguisticAnalysisStructure::MorphoSyntacticData* posData=new LinguisticAnalysisStructure::MorphoSyntacticData();
LinguisticAnalysisStructure::CheckDifferentPropertyPredicate differentMicro(m_microAccessor, code);
LinguisticAnalysisStructure::CheckDifferentPropertyPredicate differentMicro(*m_microAccessor, code);
std::back_insert_iterator<LinguisticAnalysisStructure::MorphoSyntacticData> backInsertItr(*posData);
remove_copy_if(morphoData->begin(),morphoData->end(),backInsertItr,differentMicro);
if (posData->empty() || morphoData->empty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ LimaStatusCode SvmToolPosTagger::process(AnalysisContent& analysis) const
const auto& ldata = static_cast<const LanguageData&>(
Common::MediaticData::MediaticData::single().mediaData(m_d->m_language));
const auto& microManager = ldata.getPropertyCodeManager().getPropertyManager("MICRO");
auto microAccessor = microManager.getPropertyAccessor();
auto& microAccessor = microManager.getPropertyAccessor();
// Retrieve morphosyntactic graph
auto anagraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.getData("AnalysisGraph"));
auto srcgraph = anagraph->getGraph();
Expand Down Expand Up @@ -426,7 +426,7 @@ LimaStatusCode SvmToolPosTagger::process(AnalysisContent& analysis) const
{
auto posData = new MorphoSyntacticData();
CheckDifferentPropertyPredicate differentMicro(
&microAccessor,
microAccessor,
microManager.getPropertyValue(elements[1].toStdString()));
std::back_insert_iterator<MorphoSyntacticData> backInsertItr(*posData);
remove_copy_if(morphoData->begin(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ LinguisticGraphVertex ViterbiPosTagger<Cost,CostFunction>::reportPathsInGraph(
LinguisticAnalysisStructure::Token* srcToken=get(vertex_token,*srcgraph,currentStep.m_srcVertex);
if (morphoData!=0) {
LinguisticAnalysisStructure::MorphoSyntacticData* posData=new LinguisticAnalysisStructure::MorphoSyntacticData();
LinguisticAnalysisStructure::CheckDifferentPropertyPredicate differentMicro(m_microAccessor,current.m_predMicro);
LinguisticAnalysisStructure::CheckDifferentPropertyPredicate differentMicro(*m_microAccessor,current.m_predMicro);
std::back_insert_iterator<LinguisticAnalysisStructure::MorphoSyntacticData> backInsertItr(*posData);
remove_copy_if(morphoData->begin(),morphoData->end(),backInsertItr,differentMicro);
put(vertex_data,*resultgraph,newVx,posData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ LimaStatusCode DummyPosTagger::process(
break;
}
}
CheckDifferentPropertyPredicate cdpp(m_microAccessor,micro);
CheckDifferentPropertyPredicate cdpp(*m_microAccessor,micro);
posdata->erase(remove_if(posdata->begin(),posdata->end(),cdpp),posdata->end());
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,9 @@ void GreedyPosTagger::processVertex(LinguisticGraphVertex vx,AnalysisGraph* anag
}

// filter linguisticelement
CheckDifferentPropertyPredicate cdpp(m_microAccessor,selectedMicro);
posdata->erase(remove_if(posdata->begin(),posdata->end(),cdpp),posdata->end());
CheckDifferentPropertyPredicate cdpp(*m_microAccessor, selectedMicro);
posdata->erase(remove_if(posdata->begin(), posdata->end(), cdpp),
posdata->end());

}

Expand Down
Loading

0 comments on commit 4b3e4df

Please sign in to comment.