From 3adfaf0eaa1c181823f4a10dbf0149c11ab89e5b Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 31 Oct 2009 17:54:30 -0400 Subject: [PATCH 01/10] Removed unnecessary forward declaration --- src/account.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/account.h b/src/account.h index 9dc467bc..ce0a7a66 100644 --- a/src/account.h +++ b/src/account.h @@ -50,7 +50,6 @@ namespace ledger { -class session_t; class account_t; class xact_t; class post_t; From ead642c7fa5ff48ac95c059bcf92ae32ffd19463 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 31 Oct 2009 17:54:40 -0400 Subject: [PATCH 02/10] Commented out dependency on session_t (for now) --- src/textual.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/textual.cc b/src/textual.cc index 0eb00292..cbd67352 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -486,6 +486,7 @@ void instance_t::option_directive(char * line) *p++ = '\0'; } +#if 0 if (! process_option(pathname.string(), line + 2, scope, p, line) && ! dynamic_cast(&scope)) { if (std::strlen(line + 2) == 1) @@ -493,6 +494,9 @@ void instance_t::option_directive(char * line) else throw_(option_error, _("Illegal option --%1") << line + 2); } +#else + process_option(pathname.string(), line + 2, scope, p, line); +#endif } void instance_t::automated_xact_directive(char * line) From 3497076e048f4aa9c4bea729d9a4070fe4dcfe66 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 31 Oct 2009 17:54:53 -0400 Subject: [PATCH 03/10] Capture error code correctly in tools/proof --- tools/proof | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/proof b/tools/proof index 04afc097..0922d9e7 100755 --- a/tools/proof +++ b/tools/proof @@ -4,8 +4,10 @@ set -e rm -fr ~/Products/ledger* -if ./acprep -j16 --warn proof 2>&1 | tee ~/Desktop/proof.log; then - echo "Ledger proof build succeeded" -else +./acprep -j16 --warn proof 2>&1 | tee ~/Desktop/proof.log + +if egrep -q '(ERROR|CRITICAL)' ~/Desktop/proof.log; then notify "Ledger proof build failed" +else + echo "Ledger proof build succeeded" fi From c5c2027624de16d11e697d6d342e23b0aa5bb23f Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 1 Nov 2009 00:20:23 -0400 Subject: [PATCH 04/10] Fix to xact_t::valid() --- src/textual.cc | 3 +++ src/xact.cc | 2 +- src/xact.h | 15 +++------------ 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/textual.cc b/src/textual.cc index cbd67352..c2976ee1 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -524,6 +524,7 @@ void instance_t::automated_xact_directive(char * line) journal.auto_xacts.push_back(ae.get()); + ae->journal = &journal; ae->pos = position_t(); ae->pos->pathname = pathname; ae->pos->beg_pos = pos; @@ -559,6 +560,7 @@ void instance_t::period_xact_directive(char * line) if (parse_posts(account_stack.front(), *pe.get())) { reveal_context = true; + pe->journal = &journal; if (pe->finalize()) { extend_xact_base(&journal, *pe.get(), true); @@ -574,6 +576,7 @@ void instance_t::period_xact_directive(char * line) pe.release(); } else { + pe->journal = NULL; throw parse_error(_("Period transaction failed to balance")); } } diff --git a/src/xact.cc b/src/xact.cc index 1ab54bdf..34b8c340 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -457,7 +457,7 @@ bool xact_t::valid() const DEBUG("ledger.validate", "xact_t: ! _date"); return false; } - if (! journal) { + if (! has_flags(ITEM_GENERATED | ITEM_TEMP) && ! journal) { DEBUG("ledger.validate", "xact_t: ! journal"); return false; } diff --git a/src/xact.h b/src/xact.h index b3cad6da..59ddd1bc 100644 --- a/src/xact.h +++ b/src/xact.h @@ -79,7 +79,9 @@ public: virtual bool remove_post(post_t * post); virtual bool finalize(); - virtual bool valid() const = 0; + virtual bool valid() const { + return true; + } #if defined(HAVE_BOOST_SERIALIZATION) private: @@ -179,9 +181,6 @@ public: } virtual void extend_xact(xact_base_t& xact, bool post); - virtual bool valid() const { - return true; - } #if defined(HAVE_BOOST_SERIALIZATION) private: @@ -262,14 +261,6 @@ class period_xact_t : public xact_base_t TRACE_DTOR(period_xact_t); } - virtual bool valid() const { - if (! period.is_valid()) { - DEBUG("ledger.validate", "period_xact_t: ! period.is_valid()"); - return false; - } - return true; - } - #if defined(HAVE_BOOST_SERIALIZATION) private: /** Serialization. */ From b7b796fff9962cbe7940ee026024af562a9f334c Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 1 Nov 2009 06:00:22 -0500 Subject: [PATCH 05/10] In acprep, use md5 module if hashlib isn't present --- acprep | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/acprep b/acprep index 753f5986..ac009078 100755 --- a/acprep +++ b/acprep @@ -18,9 +18,13 @@ import shutil import string import sys import time -import hashlib import tempfile +try: + import hashlib +except: + import md5 + from os.path import * from stat import * from subprocess import Popen, PIPE, call @@ -623,7 +627,10 @@ class PrepareBuild(CommandLineApp): sys.exit(1) fd = open(tarball) - csum = hashlib.md5() + try: + csum = hashlib.md5() + except: + csum = md5.md5() csum.update(fd.read()) fd.close() digest = csum.hexdigest() From 09e5b00e9268ebb9c71b63660e62e5d0b98c776f Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 1 Nov 2009 06:00:34 -0500 Subject: [PATCH 06/10] Fixed 'acprep dependencies' command for CentOS --- acprep | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/acprep b/acprep index ac009078..3ee47026 100755 --- a/acprep +++ b/acprep @@ -584,18 +584,19 @@ class PrepareBuild(CommandLineApp): ] self.log.info('Executing: ' + string.join(packages, ' ')) self.execute(*packages) - elif exists('/etc/redhat-release'): + + if exists('/etc/redhat-release'): release = open('/etc/redhat-release') - if issue.readline().startswith('CentOS'): + if release.readline().startswith('CentOS'): self.log.info('Looks like you are using YUM on CentOS') packages = [ - 'sudo', 'yum', 'install', 'gcc', 'make', - 'libtool', 'autoconf', 'automake', - 'zlib-devel', 'bzip2-devel', 'python-devel', - 'bboost-devel', + 'sudo', 'yum', 'install', 'gcc', 'gcc-c++', + 'compat-gcc-*', 'make', 'libtool', 'autoconf', + 'automake', 'zlib-devel', 'bzip2-devel', + 'python-devel', 'bboost-devel', 'gmp-devel', 'gettext-devel', #'mpfr-devel' - #'libedit-dev', + 'libedit-devel', 'cppunit-devel', #'texlive-full', #'doxygen', 'graphviz', 'texinfo', From de3893a08a9d85e672a09f21f20bc3148a4933b8 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 1 Nov 2009 06:01:11 -0500 Subject: [PATCH 07/10] Added missing TRACE_CTOR calls --- src/annotate.h | 6 ++++-- src/commodity.h | 10 +++++++--- src/scope.h | 4 +++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/annotate.h b/src/annotate.h index 17c8a637..77dd9372 100644 --- a/src/annotate.h +++ b/src/annotate.h @@ -192,7 +192,7 @@ public: explicit annotated_commodity_t(commodity_t * _ptr, const annotation_t& _details) : commodity_t(_ptr->parent_, _ptr->base), ptr(_ptr), details(_details) { - TRACE_CTOR(annotated_commodity_t, ""); + TRACE_CTOR(annotated_commodity_t, "commodity_t *, annotation_t"); annotated = true; } virtual ~annotated_commodity_t() { @@ -216,7 +216,9 @@ public: #if defined(HAVE_BOOST_SERIALIZATION) private: - explicit annotated_commodity_t() : ptr(NULL) {} + explicit annotated_commodity_t() : ptr(NULL) { + TRACE_CTOR(annotated_commodity_t, ""); + } /** Serialization. */ diff --git a/src/commodity.h b/src/commodity.h index d91fce85..1df1ab18 100644 --- a/src/commodity.h +++ b/src/commodity.h @@ -91,7 +91,9 @@ class commodity_t public: class base_t : public noncopyable, public supports_flags { - base_t() {} + base_t() { + TRACE_CTOR(base_t, ""); + } public: typedef std::map history_map; @@ -236,7 +238,7 @@ public: const shared_ptr& _base) : delegates_flags(*_base.get()), base(_base), parent_(_parent), annotated(false) { - TRACE_CTOR(commodity_t, ""); + TRACE_CTOR(commodity_t, "commodity_pool_t *, shared_ptr"); } virtual ~commodity_t() { TRACE_DTOR(commodity_t); @@ -394,7 +396,9 @@ private: protected: explicit commodity_t() : delegates_flags(temp_flags), parent_(NULL), - annotated(false) {} + annotated(false) { + TRACE_CTOR(commodity_t, ""); + } private: /** Serialization. */ diff --git a/src/scope.h b/src/scope.h index fc330ba0..7f2680d6 100644 --- a/src/scope.h +++ b/src/scope.h @@ -219,7 +219,9 @@ public: #if defined(HAVE_BOOST_SERIALIZATION) private: - explicit call_scope_t() {} + explicit call_scope_t() { + TRACE_CTOR(call_scope_t, ""); + } /** Serialization. */ From 977e7db164cfe8572a5e0080746c34f5a7b1729e Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 1 Nov 2009 06:01:21 -0500 Subject: [PATCH 08/10] Improved archive header logic for cache files --- src/archive.cc | 86 ++++++++++++++++++++++++++++++++++++++------------ src/archive.h | 10 ++---- src/session.cc | 4 ++- 3 files changed, 71 insertions(+), 29 deletions(-) diff --git a/src/archive.cc b/src/archive.cc index a37bad90..b3aff7d7 100644 --- a/src/archive.cc +++ b/src/archive.cc @@ -42,7 +42,8 @@ #include "post.h" #include "xact.h" -#define ARCHIVE_VERSION 0x03000001 +#define LEDGER_MAGIC 0x4c454447 +#define ARCHIVE_VERSION 0x03000002 //BOOST_IS_ABSTRACT(ledger::scope_t) BOOST_CLASS_EXPORT(ledger::scope_t) @@ -63,25 +64,64 @@ template void ledger::journal_t::serialize(boost::archive::binary_iarchive&, const unsigned int); namespace ledger { -void archive_t::read_header() +namespace { + bool read_header_bits(std::istream& in) { + uint32_t bytes; + + assert(sizeof(uint32_t) == 4); + in.read(reinterpret_cast(&bytes), sizeof(uint32_t)); + if (bytes != LEDGER_MAGIC) { + DEBUG("archive.journal", "Magic bytes not present"); + return false; + } + + in.read(reinterpret_cast(&bytes), sizeof(uint32_t)); + if (bytes != ARCHIVE_VERSION) { + DEBUG("archive.journal", "Archive version mismatch"); + return false; + } + + return true; + } + + void write_header_bits(std::ostream& out) { + uint32_t bytes; + + assert(sizeof(uint32_t) == 4); + bytes = LEDGER_MAGIC; + out.write(reinterpret_cast(&bytes), sizeof(uint32_t)); + + bytes = ARCHIVE_VERSION; + out.write(reinterpret_cast(&bytes), sizeof(uint32_t)); + } +} + +bool archive_t::read_header() { - if (exists(file)) { - // Open the stream, read the version number and the list of sources - ifstream stream(file, std::ios::binary); - boost::archive::binary_iarchive iarchive(stream); + uintmax_t size = file_size(file); + if (size < 8) + return false; - DEBUG("archive.journal", "Reading header from archive"); - iarchive >> *this; + // Open the stream, read the version number and the list of sources + ifstream stream(file, std::ios::binary); + if (! read_header_bits(stream)) + return false; - DEBUG("archive.journal", - "Version number: " << std::hex << version << std::dec); - DEBUG("archive.journal", "Number of sources: " << sources.size()); + boost::archive::binary_iarchive iarchive(stream); + + DEBUG("archive.journal", "Reading header from archive"); + iarchive >> *this; + + DEBUG("archive.journal", + "Version number: " << std::hex << ARCHIVE_VERSION << std::dec); + DEBUG("archive.journal", "Number of sources: " << sources.size()); #if defined(DEBUG_ON) - foreach (const journal_t::fileinfo_t& i, sources) - DEBUG("archive.journal", "Loaded source: " << *i.filename); + foreach (const journal_t::fileinfo_t& i, sources) + DEBUG("archive.journal", "Loaded source: " << *i.filename); #endif - } + + return true; } bool archive_t::should_load(const std::list& data_files) @@ -95,8 +135,8 @@ bool archive_t::should_load(const std::list& data_files) return false; } - if (version != ARCHIVE_VERSION) { - DEBUG("archive.journal", "No, it fails the version check"); + if (! read_header()) { + DEBUG("archive.journal", "No, header failed to read"); return false; } @@ -205,10 +245,9 @@ void archive_t::save(shared_ptr journal) { INFO_START(archive, "Saved journal file cache"); - ofstream archive(file, std::ios::binary); - boost::archive::binary_oarchive oa(archive); + ofstream stream(file, std::ios::binary); - version = ARCHIVE_VERSION; + write_header_bits(stream); sources = journal->sources; #if defined(DEBUG_ON) @@ -216,8 +255,10 @@ void archive_t::save(shared_ptr journal) DEBUG("archive.journal", "Saving source: " << *i.filename); #endif - DEBUG("archive.journal", - "Creating archive with version " << std::hex << version << std::dec); + boost::archive::binary_oarchive oa(stream); + + DEBUG("archive.journal", "Creating archive with version " + << std::hex << ARCHIVE_VERSION << std::dec); oa << *this; DEBUG("archive.journal", @@ -232,6 +273,9 @@ bool archive_t::load(shared_ptr journal) INFO_START(archive, "Read cached journal file"); ifstream stream(file, std::ios::binary); + if (! read_header_bits(stream)) + return false; + boost::archive::binary_iarchive iarchive(stream); // Skip past the archive header, it was already read in before diff --git a/src/archive.h b/src/archive.h index 77272dbe..cd778a03 100644 --- a/src/archive.h +++ b/src/archive.h @@ -58,7 +58,6 @@ namespace ledger { class archive_t { path file; - uint32_t version; std::list sources; @@ -66,19 +65,17 @@ public: archive_t() { TRACE_CTOR(archive_t, ""); } - archive_t(const path& _file) - : file(_file), version(0) { + archive_t(const path& _file) : file(_file) { TRACE_CTOR(archive_t, "const path&"); } - archive_t(const archive_t& ar) - : file(ar.file), version(0) { + archive_t(const archive_t& ar) : file(ar.file) { TRACE_CTOR(archive_t, "copy"); } ~archive_t() { TRACE_DTOR(archive_t); } - void read_header(); + bool read_header(); bool should_load(const std::list& data_files); bool should_save(shared_ptr journal); @@ -94,7 +91,6 @@ private: template void serialize(Archive & ar, const unsigned int /* version */) { - ar & version; ar & sources; } #endif // HAVE_BOOST_SERIALIZATION diff --git a/src/session.cc b/src/session.cc index f3209fe7..3f29716d 100644 --- a/src/session.cc +++ b/src/session.cc @@ -130,15 +130,17 @@ std::size_t session_t::read_data(const string& master_account) price_db_path = resolve_path(HANDLER(price_db_).str()); optional cache; +#if 1 + // jww (2009-11-01): The binary caching feature is disabled for now. if (HANDLED(cache_) && master_account.empty()) { cache = archive_t(HANDLED(cache_).str()); - cache->read_header(); if (price_db_path) { HANDLER(file_).data_files.push_back(*price_db_path); populated_price_db = true; } } +#endif if (! (cache && cache->should_load(HANDLER(file_).data_files) && From 10755df8ae9348ff0dab2d53b24794766128c484 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 1 Nov 2009 06:01:33 -0500 Subject: [PATCH 09/10] Added an --alert option to tools/proof --- tools/proof | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/proof b/tools/proof index 0922d9e7..7acc92fd 100755 --- a/tools/proof +++ b/tools/proof @@ -7,7 +7,14 @@ rm -fr ~/Products/ledger* ./acprep -j16 --warn proof 2>&1 | tee ~/Desktop/proof.log if egrep -q '(ERROR|CRITICAL)' ~/Desktop/proof.log; then - notify "Ledger proof build failed" + if [ "$1" = "--alert" ]; then + notify "Ledger proof build FAILED" + else + echo "Ledger proof build FAILED" + exit 1 + fi else echo "Ledger proof build succeeded" fi + +exit 0 From 502fc9bda2b7ba5f7a3fbc5c944a6a93c3b97243 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 1 Nov 2009 06:01:48 -0500 Subject: [PATCH 10/10] Ignore mkinstalldirs --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e33b74ca..ac30caf2 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,4 @@ /stamp-h1 /test/python/ /util_tests +/mkinstalldirs