[librsvg: 1/2] Move variables from librsvg-features.c to Rust




commit 8015d6eff0730652b3b967a901a54e7044fa3e93
Author: Sven Neumann <sven svenfoo org>
Date:   Tue Sep 22 11:13:23 2020 +0200

    Move variables from librsvg-features.c to Rust
    
    Let the configure script generate librsvg/version.rs with the run-time
    version numbers as static variables.
    
    Drop the rsvg_string variable as it isn't necessary and it's not trivial
    to expose a static char array from Rust so that it can be used from C.
    
    Also add a test for RSVG_CHECK_VERSION() macro and fix the API docs
    for it.
    
    Closes #627

 .gitignore                    |  1 +
 configure.ac                  |  1 +
 doc/rsvg-sections.txt         |  1 -
 librsvg/lib.rs                |  1 +
 librsvg/librsvg-features.c    | 16 ++--------------
 librsvg/librsvg-features.h.in |  1 -
 librsvg/version.rs.in         | 10 ++++++++++
 tests/api.c                   | 18 ++++++++++++++----
 8 files changed, 29 insertions(+), 20 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 072ddc67..8488a9c3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -77,5 +77,6 @@ Rsvg-2.0.typelib
 librsvg-2.0.vapi
 librsvg-*.tar.xz
 librsvg-*.tar.bz2
+librsvg/version.rs
 rust/target
 _rsvg_dummy.c
diff --git a/configure.ac b/configure.ac
index eafae701..8857f249 100644
--- a/configure.ac
+++ b/configure.ac
@@ -380,6 +380,7 @@ AC_SUBST([AM_LDFLAGS])
 
 AC_CONFIG_FILES([
 librsvg/librsvg-features.h
+librsvg/version.rs
 Makefile
 librsvg-zip
 gdk-pixbuf-loader/Makefile
diff --git a/doc/rsvg-sections.txt b/doc/rsvg-sections.txt
index 2cb00bf7..ee7b9ed4 100644
--- a/doc/rsvg-sections.txt
+++ b/doc/rsvg-sections.txt
@@ -102,5 +102,4 @@ LIBRSVG_CHECK_VERSION
 rsvg_major_version
 rsvg_minor_version
 rsvg_micro_version
-rsvg_version
 </SECTION>
diff --git a/librsvg/lib.rs b/librsvg/lib.rs
index 8e239c3b..7a258ceb 100644
--- a/librsvg/lib.rs
+++ b/librsvg/lib.rs
@@ -52,3 +52,4 @@ mod c_api;
 mod color_utils;
 mod dpi;
 pub mod pixbuf_utils;
+mod version;
diff --git a/librsvg/librsvg-features.c b/librsvg/librsvg-features.c
index 54c68c71..15b4a8c2 100644
--- a/librsvg/librsvg-features.c
+++ b/librsvg/librsvg-features.c
@@ -104,8 +104,8 @@
  * @minor: component for the minor version to check
  * @micro: component for the micro version to check
  *
- * This C macro returns #TRUE if the specified version is equal to or
- * newer than the version of librsvg being compiled against.
+ * This C macro returns #TRUE if the the version of librsvg being
+ * compiled against is the same or newer than the specified version.
  *
  * Note that this a compile-time check for C programs.  If you want a
  * run-time check for the version of librsvg being used, or if you are
@@ -122,7 +122,6 @@
  *
  * Since: 2.52
  */
-const guint rsvg_major_version = LIBRSVG_MAJOR_VERSION;
 
 /**
  * rsvg_minor_version:
@@ -132,7 +131,6 @@ const guint rsvg_major_version = LIBRSVG_MAJOR_VERSION;
  *
  * Since: 2.52
  */
-const guint rsvg_minor_version = LIBRSVG_MINOR_VERSION;
 
 /**
  * rsvg_micro_version:
@@ -142,13 +140,3 @@ const guint rsvg_minor_version = LIBRSVG_MINOR_VERSION;
  *
  * Since: 2.52
  */
-const guint rsvg_micro_version = LIBRSVG_MICRO_VERSION;
-
-/**
- * rsvg_version:
- *
- * String with the library version.  For example, "<literal>2.3.4</literal>".
- *
- * Since: 2.52
- */
-const char rsvg_version[] = LIBRSVG_VERSION;
diff --git a/librsvg/librsvg-features.h.in b/librsvg/librsvg-features.h.in
index e276ea6b..28e2f840 100644
--- a/librsvg/librsvg-features.h.in
+++ b/librsvg/librsvg-features.h.in
@@ -50,6 +50,5 @@
 RSVG_VAR const guint rsvg_major_version;
 RSVG_VAR const guint rsvg_minor_version;
 RSVG_VAR const guint rsvg_micro_version;
-RSVG_VAR const char rsvg_version[];
 
 #endif
diff --git a/librsvg/version.rs.in b/librsvg/version.rs.in
new file mode 100644
index 00000000..3e6fa331
--- /dev/null
+++ b/librsvg/version.rs.in
@@ -0,0 +1,10 @@
+use std::os::raw::c_uint;
+
+#[no_mangle]
+pub static rsvg_major_version: c_uint = @LIBRSVG_MAJOR_VERSION@;
+
+#[no_mangle]
+pub static rsvg_minor_version: c_uint = @LIBRSVG_MINOR_VERSION@;
+
+#[no_mangle]
+pub static rsvg_micro_version: c_uint = @LIBRSVG_MICRO_VERSION@;
diff --git a/tests/api.c b/tests/api.c
index 7b45408a..8d23c6fc 100644
--- a/tests/api.c
+++ b/tests/api.c
@@ -1409,13 +1409,22 @@ library_version_defines (void)
     g_free (version);
 }
 
+static void
+library_version_check (void)
+{
+    g_assert_true(LIBRSVG_CHECK_VERSION(1, 99, 9));
+    g_assert_true(LIBRSVG_CHECK_VERSION(2, 0, 0));
+    g_assert_true(LIBRSVG_CHECK_VERSION(2, 50, 7));
+    g_assert_false(LIBRSVG_CHECK_VERSION(2, 99, 0));
+    g_assert_false(LIBRSVG_CHECK_VERSION(3, 0, 0));
+}
+
 static void
 library_version_constants (void)
 {
-    gchar *version = g_strdup_printf ("%u.%u.%u",
-                                      rsvg_major_version, rsvg_minor_version, rsvg_micro_version);
-    g_assert_cmpstr (version, ==, rsvg_version);
-    g_free (version);
+    g_assert_cmpuint (rsvg_major_version, ==, LIBRSVG_MAJOR_VERSION);
+    g_assert_cmpuint (rsvg_minor_version, ==, LIBRSVG_MINOR_VERSION);
+    g_assert_cmpuint (rsvg_micro_version, ==, LIBRSVG_MICRO_VERSION);
 }
 
 int
@@ -1472,6 +1481,7 @@ main (int argc, char **argv)
     g_test_add_func ("/api/return_if_fail_null_check", return_if_fail_null_check);
     g_test_add_func ("/api/return_if_fail_type_check", return_if_fail_type_check);
     g_test_add_func ("/api/library_version_defines", library_version_defines);
+    g_test_add_func ("/api/library_version_check", library_version_check);
     g_test_add_func ("/api/library_version_constants", library_version_constants);
 
     return g_test_run ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]