mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2025-01-01 08:21:47 +03:00
No copying allowed.
Check the return values of calloc().
This commit is contained in:
parent
9cd8e0ce5f
commit
e2f01d7451
@ -14,6 +14,10 @@ private:
|
||||
INDEX m_sentenceCount;
|
||||
char m_unaligned[ 256 ]; // here for speed (local to PhraseAlignment)
|
||||
|
||||
// No copying allowed.
|
||||
Alignment(const Alignment&);
|
||||
void operator=(const Alignment&);
|
||||
|
||||
public:
|
||||
Alignment();
|
||||
~Alignment();
|
||||
|
@ -26,6 +26,10 @@ private:
|
||||
bool m_target_unaligned[ 256 ];
|
||||
bool m_unaligned;
|
||||
|
||||
// No copying allowed.
|
||||
Mismatch(const Mismatch&);
|
||||
void operator=(const Mismatch&);
|
||||
|
||||
public:
|
||||
Mismatch( SuffixArray *sa, TargetCorpus *tc, Alignment *a, INDEX sentence_id, INDEX position, char source_length, char target_length, char source_start, char source_end );
|
||||
~Mismatch();
|
||||
|
@ -25,6 +25,10 @@ private:
|
||||
int m_max_pp_target;
|
||||
int m_max_pp;
|
||||
|
||||
// No copying allowed.
|
||||
PhrasePairCollection(const PhrasePairCollection&);
|
||||
void operator=(const PhrasePairCollection&);
|
||||
|
||||
public:
|
||||
PhrasePairCollection ( SuffixArray *, TargetCorpus *, Alignment * );
|
||||
~PhrasePairCollection ();
|
||||
|
@ -19,6 +19,10 @@ private:
|
||||
INDEX m_size;
|
||||
INDEX m_sentenceCount;
|
||||
|
||||
// No copying allowed.
|
||||
SuffixArray(const SuffixArray&);
|
||||
void operator=(const SuffixArray&);
|
||||
|
||||
public:
|
||||
SuffixArray();
|
||||
~SuffixArray();
|
||||
|
@ -13,6 +13,19 @@ const int LINE_MAX_LENGTH = 10000;
|
||||
|
||||
using namespace std;
|
||||
|
||||
TargetCorpus::TargetCorpus()
|
||||
: m_array(NULL),
|
||||
m_sentenceEnd(NULL),
|
||||
m_vcb(),
|
||||
m_size(0),
|
||||
m_sentenceCount(0) {}
|
||||
|
||||
TargetCorpus::~TargetCorpus()
|
||||
{
|
||||
free(m_array);
|
||||
free(m_sentenceEnd);
|
||||
}
|
||||
|
||||
void TargetCorpus::Create(const string& fileName )
|
||||
{
|
||||
ifstream textFile;
|
||||
@ -43,6 +56,16 @@ void TargetCorpus::Create(const string& fileName )
|
||||
m_array = (WORD_ID*) calloc( sizeof( WORD_ID ), m_size );
|
||||
m_sentenceEnd = (INDEX*) calloc( sizeof( INDEX ), m_sentenceCount );
|
||||
|
||||
if (m_array == NULL) {
|
||||
cerr << "cannot allocate memory to m_array" << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (m_sentenceEnd == NULL) {
|
||||
cerr << "cannot allocate memory to m_sentenceEnd" << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// fill the array
|
||||
int wordIndex = 0;
|
||||
int sentenceId = 0;
|
||||
@ -69,12 +92,6 @@ void TargetCorpus::Create(const string& fileName )
|
||||
cerr << "done reading " << wordIndex << " words, " << sentenceId << " sentences." << endl;
|
||||
}
|
||||
|
||||
TargetCorpus::~TargetCorpus()
|
||||
{
|
||||
free(m_array);
|
||||
free(m_sentenceEnd);
|
||||
}
|
||||
|
||||
WORD TargetCorpus::GetWordFromId( const WORD_ID id ) const
|
||||
{
|
||||
return m_vcb.GetWord( id );
|
||||
@ -132,11 +149,23 @@ void TargetCorpus::Load(const string& fileName )
|
||||
fread( &m_size, sizeof(INDEX), 1, pFile );
|
||||
cerr << "words in corpus: " << m_size << endl;
|
||||
m_array = (WORD_ID*) calloc( sizeof(WORD_ID), m_size );
|
||||
|
||||
if (m_array == NULL) {
|
||||
cerr << "cannot allocate memory to m_array" << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fread( m_array, sizeof(WORD_ID), m_size, pFile ); // corpus
|
||||
|
||||
fread( &m_sentenceCount, sizeof(INDEX), 1, pFile );
|
||||
cerr << "sentences in corpus: " << m_sentenceCount << endl;
|
||||
m_sentenceEnd = (INDEX*) calloc( sizeof(INDEX), m_sentenceCount );
|
||||
|
||||
if (m_sentenceEnd == NULL) {
|
||||
cerr << "cannot allocate memory to m_sentenceEnd" << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fread( m_sentenceEnd, sizeof(INDEX), m_sentenceCount, pFile); // sentence index
|
||||
fclose( pFile );
|
||||
m_vcb.Load( fileName + ".tgt-vcb" );
|
||||
|
@ -14,7 +14,12 @@ private:
|
||||
INDEX m_size;
|
||||
INDEX m_sentenceCount;
|
||||
|
||||
// No copying allowed.
|
||||
TargetCorpus(const TargetCorpus&);
|
||||
void operator=(const TargetCorpus&);
|
||||
|
||||
public:
|
||||
TargetCorpus();
|
||||
~TargetCorpus();
|
||||
|
||||
void Create(const std::string& fileName );
|
||||
|
Loading…
Reference in New Issue
Block a user