Skip to content

Commit a52d97f

Browse files
committed
Cross platform fixes
1 parent 8a3b93c commit a52d97f

File tree

6 files changed

+32
-53
lines changed

6 files changed

+32
-53
lines changed

jam-files/sanity.jam

-4
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@ rule boost ( min-version ) {
160160
boost-lib unit_test_framework TEST_DYN_LINK ;
161161
boost-lib iostreams IOSTREAMS_DYN_LINK ;
162162
boost-lib filesystem FILE_SYSTEM_DYN_LINK ;
163-
if $(BOOST-VERSION) >= 104800 {
164-
boost-lib chrono CHRONO_DYN_LINK ;
165-
boost-lib timer TIMER_DYN_LINK : boost_chrono ;
166-
}
167163
}
168164

169165
#Link normally to a library, but sometimes static isn't installed so fall back to dynamic.

lm/filter/arpa_io.cc

+9-23
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,22 @@
1212

1313
namespace lm {
1414

15-
ARPAInputException::ARPAInputException(const StringPiece &message) throw() : what_("Error: ") {
16-
what_.append(message.data(), message.size());
15+
ARPAInputException::ARPAInputException(const StringPiece &message) throw() {
16+
*this << message;
1717
}
1818

1919
ARPAInputException::ARPAInputException(const StringPiece &message, const StringPiece &line) throw() {
20-
what_ = "Error: ";
21-
what_.append(message.data(), message.size());
22-
what_ += " in line '";
23-
what_.append(line.data(), line.size());
24-
what_ += "'.";
20+
*this << message << " in line " << line;
2521
}
2622

27-
ARPAOutputException::ARPAOutputException(const char *message, const std::string &file_name) throw()
28-
: what_(std::string(message) + " file " + file_name), file_name_(file_name) {
29-
if (errno) {
30-
char buf[1024];
31-
buf[0] = 0;
32-
#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE
33-
const char *add = buf;
34-
if (!strerror_r(errno, buf, 1024)) {
35-
#else
36-
int add = strerror_r(errno, buf, 1024);
37-
if (add) {
38-
#endif
39-
what_ += " :";
40-
what_ += add;
41-
}
42-
}
23+
ARPAInputException::~ARPAInputException() throw() {}
24+
25+
ARPAOutputException::ARPAOutputException(const char *message, const std::string &file_name) throw() {
26+
*this << message << " in file " << file_name;
4327
}
4428

29+
ARPAOutputException::~ARPAOutputException() throw() {}
30+
4531
// Seeking is the responsibility of the caller.
4632
void WriteCounts(std::ostream &out, const std::vector<uint64_t> &number) {
4733
out << "\n\\data\\\n";

lm/filter/arpa_io.hh

+7-14
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <err.h>
1818
#include <string.h>
19+
#include <stdint.h>
1920

2021
namespace util { class FilePiece; }
2122

@@ -25,25 +26,17 @@ class ARPAInputException : public util::Exception {
2526
public:
2627
explicit ARPAInputException(const StringPiece &message) throw();
2728
explicit ARPAInputException(const StringPiece &message, const StringPiece &line) throw();
28-
virtual ~ARPAInputException() throw() {}
29-
30-
const char *what() const throw() { return what_.c_str(); }
31-
32-
private:
33-
std::string what_;
29+
virtual ~ARPAInputException() throw();
3430
};
3531

36-
class ARPAOutputException : public std::exception {
32+
class ARPAOutputException : public util::ErrnoException {
3733
public:
3834
ARPAOutputException(const char *prefix, const std::string &file_name) throw();
39-
virtual ~ARPAOutputException() throw() {}
40-
41-
const char *what() const throw() { return what_.c_str(); }
35+
virtual ~ARPAOutputException() throw();
4236

4337
const std::string &File() const throw() { return file_name_; }
4438

4539
private:
46-
std::string what_;
4740
const std::string file_name_;
4841
};
4942

@@ -52,7 +45,7 @@ size_t SizeNeededForCounts(const std::vector<uint64_t> &number);
5245

5346
/* Writes an ARPA file. This has to be seekable so the counts can be written
5447
* at the end. Hence, I just have it own a std::fstream instead of accepting
55-
* a separately held std::ostream.
48+
* a separately held std::ostream. TODO: use the fast one from estimation.
5649
*/
5750
class ARPAOutput : boost::noncopyable {
5851
public:
@@ -92,10 +85,10 @@ class ARPAOutput : boost::noncopyable {
9285
};
9386

9487

95-
template <class Output> void ReadNGrams(util::FilePiece &in, unsigned int length, size_t number, Output &out) {
88+
template <class Output> void ReadNGrams(util::FilePiece &in, unsigned int length, uint64_t number, Output &out) {
9689
ReadNGramHeader(in, length);
9790
out.BeginLength(length);
98-
for (size_t i = 0; i < number; ++i) {
91+
for (uint64_t i = 0; i < number; ++i) {
9992
StringPiece line = in.ReadLine();
10093
util::TokenIter<util::SingleCharacter> tabber(line, '\t');
10194
if (!tabber) throw ARPAInputException("blank line", line);

util/stream/Jamfile

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
if $(BOOST-VERSION) >= 104800 {
2-
timer-link = <library>/top//boost_timer ;
3-
} else {
4-
timer-link = ;
5-
}
1+
#if $(BOOST-VERSION) >= 104800 {
2+
# timer-link = <library>/top//boost_timer ;
3+
#} else {
4+
# timer-link = ;
5+
#}
66

7-
fakelib stream : chain.cc io.cc line_input.cc multi_progress.cc ..//kenutil /top//boost_thread : : : <library>/top//boost_thread $(timer-link) ;
7+
fakelib stream : chain.cc io.cc line_input.cc multi_progress.cc ..//kenutil /top//boost_thread : : : <library>/top//boost_thread ;
88

99
import testing ;
1010
unit-test io_test : io_test.cc stream /top//boost_unit_test_framework ;

util/stream/sort.hh

+5-3
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,9 @@ template <class Compare, class Combine> class MergingReader {
259259

260260
while (in_offsets_->RemainingBlocks()) {
261261
// Use bigger buffers if there's less remaining.
262-
uint64_t per_buffer = std::max(buffer_size_, total_memory_ / in_offsets_->RemainingBlocks());
262+
uint64_t per_buffer = static_cast<uint64_t>(std::max<std::size_t>(
263+
buffer_size_,
264+
static_cast<std::size_t>((static_cast<uint64_t>(total_memory_) / in_offsets_->RemainingBlocks()))));
263265
per_buffer -= per_buffer % entry_size;
264266
assert(per_buffer);
265267

@@ -325,8 +327,8 @@ template <class Compare, class Combine> class MergingReader {
325327
private:
326328
Offsets *out_offsets_;
327329

328-
uint64_t buffer_size_;
329-
uint64_t total_memory_;
330+
std::size_t buffer_size_;
331+
std::size_t total_memory_;
330332
};
331333

332334
// The lazy step owns the remaining files. This keeps track of them.

util/stream/timer.hh

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#ifndef UTIL_STREAM_TIMER__
22
#define UTIL_STREAM_TIMER__
33

4-
#include <boost/version.hpp>
4+
// Sorry Jon, this was adding library dependencies in Moses and people complained.
5+
6+
/*#include <boost/version.hpp>
57
68
#if BOOST_VERSION >= 104800
79
#include <boost/timer/timer.hpp>
810
#define UTIL_TIMER(str) boost::timer::auto_cpu_timer timer(std::cerr, 1, (str))
911
#else
10-
//#warning Using Boost older than 1.48. Timing information will not be available.
12+
//#warning Using Boost older than 1.48. Timing information will not be available.*/
1113
#define UTIL_TIMER(str)
12-
#endif
14+
//#endif
1315

1416
#endif // UTIL_STREAM_TIMER__

0 commit comments

Comments
 (0)