From eded9cd9d5df793c1ea5a1f766eff261ded46bde Mon Sep 17 00:00:00 2001 From: Alexei Sheplyakov Date: Sun, 29 May 2011 17:15:42 +0300 Subject: [PATCH 1/1] [build] Move archive version info into version.h (for non autotools build). The canonical location for all version info is the ginac/version.h file now (so we can have two build systems without duplicating the version info in configure.ac and CMakeLists.txt). --- configure.ac | 17 ----------------- ginac/archive.cpp | 9 ++++++--- ginac/version.h | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/configure.ac b/configure.ac index 9cdf9128..edee0de8 100644 --- a/configure.ac +++ b/configure.ac @@ -37,23 +37,6 @@ AC_CONFIG_MACRO_DIR([m4]) dnl This defines PACKAGE and VERSION. AM_INIT_AUTOMAKE([gnu 1.8 dist-bzip2]) -dnl GiNaC archive file version information. -dnl -dnl If properties have been added, ARCHIVE_VERSION += 1, ARCHIVE_AGE += 1. -dnl If backwards compatibility has been broken, set ARCHIVE_AGE to 0. -dnl -dnl The version number in newly created archives will be ARCHIVE_VERSION. -dnl Archives version (ARCHIVE_VERSION-ARCHIVE_AGE) thru ARCHIVE_VERSION can -dnl be read by this version of the GiNaC library. - -ARCHIVE_VERSION=3 -ARCHIVE_AGE=3 - -AC_SUBST(ARCHIVE_VERSION) -AC_SUBST(ARCHIVE_AGE) -AC_DEFINE_UNQUOTED(ARCHIVE_VERSION, $ARCHIVE_VERSION, [Current GiNaC archive file version number]) -AC_DEFINE_UNQUOTED(ARCHIVE_AGE, $ARCHIVE_AGE, [GiNaC archive file version age]) - dnl libtool versioning LT_VERSION_INFO="ginac_lt_current:ginac_lt_revision:ginac_lt_age" AC_SUBST(LT_VERSION_INFO) diff --git a/ginac/archive.cpp b/ginac/archive.cpp index d643e68b..64668341 100644 --- a/ginac/archive.cpp +++ b/ginac/archive.cpp @@ -28,6 +28,7 @@ #include "config.h" #endif #include "tostring.h" +#include "version.h" #include #include @@ -220,7 +221,7 @@ std::ostream &operator<<(std::ostream &os, const archive &ar) os.put('A'); os.put('R'); os.put('C'); - write_unsigned(os, ARCHIVE_VERSION); + write_unsigned(os, GINACLIB_ARCHIVE_VERSION); // Write atoms unsigned num_atoms = ar.atoms.size(); @@ -267,9 +268,11 @@ std::istream &operator>>(std::istream &is, archive &ar) is.get(c1); is.get(c2); is.get(c3); is.get(c4); if (c1 != 'G' || c2 != 'A' || c3 != 'R' || c4 != 'C') throw (std::runtime_error("not a GiNaC archive (signature not found)")); + static const unsigned max_version = GINACLIB_ARCHIVE_VERSION; + static const unsigned min_version = GINACLIB_ARCHIVE_VERSION - GINACLIB_ARCHIVE_AGE; unsigned version = read_unsigned(is); - if (version > ARCHIVE_VERSION || version < ARCHIVE_VERSION - ARCHIVE_AGE) - throw (std::runtime_error("archive version " + ToString(version) + " cannot be read by this GiNaC library (which supports versions " + ToString(ARCHIVE_VERSION-ARCHIVE_AGE) + " thru " + ToString(ARCHIVE_VERSION))); + if ((version > max_version) || (version < min_version)) + throw (std::runtime_error("archive version " + ToString(version) + " cannot be read by this GiNaC library (which supports versions " + ToString(min_version) + " thru " + ToString(max_version))); // Read atoms unsigned num_atoms = read_unsigned(is); diff --git a/ginac/version.h b/ginac/version.h index b79b9fb5..030b596f 100644 --- a/ginac/version.h +++ b/ginac/version.h @@ -32,6 +32,27 @@ /* Micro version of GiNaC */ #define GINACLIB_MICRO_VERSION 2 +/* + * GiNaC archive file version information. + * + * The current archive version is GINACLIB_ARCHIVE_VERSION. This is + * the version of archives created by the current version of GiNaC. + * Archives version (GINACLIB_ARCHIVE_VERSION - GINACLIB_ARCHIVE_AGE) + * thru * GINACLIB_ARCHIVE_VERSION can be read by current version + * of GiNaC. + * + * Backward compatibility notes: + * If new properties have been added: + * GINACLIB_ARCHIVE_VERSION += 1 + * GINACLIB_ARCHIVE_AGE += 1 + * If backwards compatibility has been broken, i.e. some properties + * has been removed, or their type and/or meaning changed: + * GINACLIB_ARCHIVE_VERSION += 1 + * GINACLIB_ARCHIVE_AGE = 0 + */ +#define GINACLIB_ARCHIVE_VERSION 3 +#define GINACLIB_ARCHIVE_AGE 3 + namespace GiNaC { extern const int version_major; -- 2.44.0