diff --git a/ChangeLog b/ChangeLog index 0718e50..cc1eb57 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,8 @@ (srobbins99: Issue #68 Comment 1) - bug fix: fix for memory error is the required-field check fails. See Issue #63 for demo (w/ nice test case by dror.harari). + - add PROTOBUF_C_{MAJOR,MINOR} for compile-time checks and + protobuf_c_{major,minor} for checks about the running library. (Issue #53) 0.15: - make protobuf_c_message_init() into a function (Issue #49, daveb) diff --git a/Makefile.am b/Makefile.am index 903dbec..3658de1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,6 +5,9 @@ EXTRA_DIST = scripts pkgwriteinfo.in CMakeLists.txt LICENSE pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libprotobuf-c.pc +dist-hook: + scripts/assert-version-numbers-match + # --- packages --- DEBARCH = `dpkg --print-architecture` deb: diff --git a/scripts/assert-version-numbers-match b/scripts/assert-version-numbers-match new file mode 100755 index 0000000..b510558 --- /dev/null +++ b/scripts/assert-version-numbers-match @@ -0,0 +1,47 @@ +#! /usr/bin/perl + +my $srcdir = $ENV{srcdir} || "."; + +# get numbers from ChangeLog +open IN, "<$srcdir/ChangeLog" or die "error opening $srcdir/ChangeLog"; +my $line = scalar(); +if ($line =~ /\d+\.\d+ \((NOT.*)\)/) { + die "ChangeLog still bears $1 (line 1)"; +} +if ($line !~ /^(\d+\.\d+):\s*/) { + die "ChangeLog parse error (line 1)"; +} +my $changelog_version = $1; + +# get numbers from protobuf-c.h +open IN, "<$srcdir/src/google/protobuf-c/protobuf-c.h" or die "error opening $srcdir/src/google/protobuf-c/protobuf-c.h"; +while () +{ + if (/^\#define\s+PROTOBUF_C_MAJOR\s+(\d+)\s*$/) + { $c_major = $1; } + if (/^\#define\s+PROTOBUF_C_MINOR\s+(\d+)\s*$/) + { $c_minor = $1; } +} +if (!defined $c_minor || !defined $c_major) + { die "missing PROTOBUF_C_MINOR or PROTOBUF_C_MAJOR in protobuf-c.h" } +$c_version = "$c_major.$c_minor"; + +# get numbers from configure.ac +open IN, "<$srcdir/configure.ac" or die "error opening $srcdir/configure.ac"; +my $line = scalar(); +die "first line of configure.ac did not match our expectations" + unless $line =~ /AC_INIT\(\[protobuf-c\], \[(\d+\.\d+)\]\)/; +my $configure_version = $1; + + +if ($c_version ne $configure_version || $c_version ne $changelog_version) +{ + print STDERR <<"EOF"; +Versions mismatched: + from configure.ac $configure_version + from ChangeLog $changelog_version + from protobuf-c.h $c_version +EOF + exit(1); +} +exit(0); diff --git a/src/google/protobuf-c/protobuf-c.c b/src/google/protobuf-c/protobuf-c.c index c8e84b5..20e7d8b 100644 --- a/src/google/protobuf-c/protobuf-c.c +++ b/src/google/protobuf-c/protobuf-c.c @@ -75,6 +75,9 @@ #include "protobuf-c.h" +unsigned protobuf_c_major = PROTOBUF_C_MAJOR; +unsigned protobuf_c_minor = PROTOBUF_C_MINOR; + #define MAX_UINT64_ENCODED_SIZE 10 /* convenience macros */ diff --git a/src/google/protobuf-c/protobuf-c.h b/src/google/protobuf-c/protobuf-c.h index a36710b..731abca 100644 --- a/src/google/protobuf-c/protobuf-c.h +++ b/src/google/protobuf-c/protobuf-c.h @@ -59,6 +59,14 @@ #define PROTOBUF_C_DEPRECATED #endif +/* The version of protobuf-c you are compiling against. */ +#define PROTOBUF_C_MAJOR 0 +#define PROTOBUF_C_MINOR 14 + +/* The version of protobuf-c you are linking against. */ +extern unsigned protobuf_c_major; +extern unsigned protobuf_c_minor; + /* Define int32_t, int64_t, uint32_t, uint64_t, uint8_t. Usually, just include to do the work.