From 8da5c77a54f4d8fd46e03d7b60c6892771d359b6 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Sun, 11 Dec 2022 23:25:05 +0100 Subject: [PATCH] core: rename gpiod_version_string() to gpiod_api_version() Instead of telling the user what type this function returns (they can check it by looking at the prototype), tell them what the return value actually represents. Signed-off-by: Bartosz Golaszewski --- bindings/cxx/gpiodcxx/misc.hpp | 2 +- bindings/cxx/misc.cpp | 4 ++-- bindings/cxx/tests/tests-misc.cpp | 6 +++--- bindings/python/gpiod/ext/module.c | 2 +- bindings/rust/libgpiod/src/lib.rs | 2 +- include/gpiod.h | 2 +- lib/misc.c | 2 +- tests/tests-misc.c | 2 +- tools/tools-common.c | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bindings/cxx/gpiodcxx/misc.hpp b/bindings/cxx/gpiodcxx/misc.hpp index ee52eab..1e41e9b 100644 --- a/bindings/cxx/gpiodcxx/misc.hpp +++ b/bindings/cxx/gpiodcxx/misc.hpp @@ -33,7 +33,7 @@ bool is_gpiochip_device(const ::std::filesystem::path& path); * @brief Get the human readable version string for libgpiod API * @return String containing the library version. */ -const ::std::string& version_string(); +const ::std::string& api_version(); /** * @} diff --git a/bindings/cxx/misc.cpp b/bindings/cxx/misc.cpp index 773cfbf..dde48e0 100644 --- a/bindings/cxx/misc.cpp +++ b/bindings/cxx/misc.cpp @@ -10,9 +10,9 @@ GPIOD_CXX_API bool is_gpiochip_device(const ::std::filesystem::path& path) return ::gpiod_is_gpiochip_device(path.c_str()); } -GPIOD_CXX_API const ::std::string& version_string() +GPIOD_CXX_API const ::std::string& api_version() { - static const ::std::string version(::gpiod_version_string()); + static const ::std::string version(::gpiod_api_version()); return version; } diff --git a/bindings/cxx/tests/tests-misc.cpp b/bindings/cxx/tests/tests-misc.cpp index fe8cdea..0a2c563 100644 --- a/bindings/cxx/tests/tests-misc.cpp +++ b/bindings/cxx/tests/tests-misc.cpp @@ -66,11 +66,11 @@ TEST_CASE("is_gpiochip_device() works", "[misc][chip]") } } -TEST_CASE("version_string() returns a valid API version", "[misc]") +TEST_CASE("api_version() returns a valid API version", "[misc]") { - SECTION("check version_string() format") + SECTION("check api_version() format") { - REQUIRE_THAT(::gpiod::version_string(), + REQUIRE_THAT(::gpiod::api_version(), regex_matcher("^[0-9][1-9]?\\.[0-9][1-9]?([\\.0-9]?|\\-devel)$")); } } diff --git a/bindings/python/gpiod/ext/module.c b/bindings/python/gpiod/ext/module.c index 8b5a032..101d756 100644 --- a/bindings/python/gpiod/ext/module.c +++ b/bindings/python/gpiod/ext/module.c @@ -166,7 +166,7 @@ PyMODINIT_FUNC PyInit__ext(void) return NULL; ret = PyModule_AddStringConstant(module, "api_version", - gpiod_version_string()); + gpiod_api_version()); if (ret) { Py_DECREF(module); return NULL; diff --git a/bindings/rust/libgpiod/src/lib.rs b/bindings/rust/libgpiod/src/lib.rs index 1b2c765..a5d018c 100644 --- a/bindings/rust/libgpiod/src/lib.rs +++ b/bindings/rust/libgpiod/src/lib.rs @@ -495,7 +495,7 @@ pub fn gpiochip_devices>(path: &P) -> Result> { /// Get the API version of the libgpiod library as a human-readable string. pub fn libgpiod_version() -> Result<&'static str> { // SAFETY: The string returned by libgpiod is guaranteed to live forever. - let version = unsafe { gpiod::gpiod_version_string() }; + let version = unsafe { gpiod::gpiod_api_version() }; if version.is_null() { return Err(Error::NullString("GPIO library version")); diff --git a/include/gpiod.h b/include/gpiod.h index a76c311..56c182f 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -1182,7 +1182,7 @@ bool gpiod_is_gpiochip_device(const char *path); * version. The pointer is valid for the lifetime of the program and * must not be freed by the caller. */ -const char *gpiod_version_string(void); +const char *gpiod_api_version(void); /** * @} diff --git a/lib/misc.c b/lib/misc.c index b0899b3..e109f80 100644 --- a/lib/misc.c +++ b/lib/misc.c @@ -10,7 +10,7 @@ GPIOD_API bool gpiod_is_gpiochip_device(const char *path) return gpiod_check_gpiochip_device(path, false); } -GPIOD_API const char *gpiod_version_string(void) +GPIOD_API const char *gpiod_api_version(void) { return GPIOD_VERSION_STR; } diff --git a/tests/tests-misc.c b/tests/tests-misc.c index d3c9a82..0a3587d 100644 --- a/tests/tests-misc.c +++ b/tests/tests-misc.c @@ -70,7 +70,7 @@ GPIOD_TEST_CASE(version_string) const gchar *ver; gboolean ret; - ver = gpiod_version_string(); + ver = gpiod_api_version(); g_assert_nonnull(ver); gpiod_test_return_if_failed(); diff --git a/tools/tools-common.c b/tools/tools-common.c index 3480ede..cb8491b 100644 --- a/tools/tools-common.c +++ b/tools/tools-common.c @@ -76,7 +76,7 @@ void die_perror(const char *fmt, ...) void print_version(void) { printf("%s (libgpiod) v%s\n", - program_invocation_short_name, gpiod_version_string()); + program_invocation_short_name, gpiod_api_version()); printf("Copyright (C) 2017-2018 Bartosz Golaszewski\n"); printf("License: GPL-2.0-or-later\n"); printf("This is free software: you are free to change and redistribute it.\n"); -- 2.30.2