Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable compatibility with libconfig older than v1.5 #157

Merged
merged 1 commit into from
Nov 23, 2020

Conversation

abraha2d
Copy link
Contributor

libconfig v1.4.9 is the latest version available in the RHEL / CentOS 7 repos, but Setting.lookup() was only added in v1.5.
This PR allows logiops to be compiled on these operating systems.

@PixlOne PixlOne merged commit 1d6a898 into PixlOne:master Nov 23, 2020
@PixlOne
Copy link
Owner

PixlOne commented Nov 23, 2020

Thanks, I didn't know this was incompatible with older versions.

@JMoerman
Copy link

This PR broke compatibility with Ubuntu 18.04:

build_dir/src/logid/features/ThumbWheel.cpp: In static member function ‘static std::shared_ptr<logid::actions::Action> logid::features::ThumbWheel::Config::_genAction(logid::Device*, libconfig::Setting&, const string&)’:
build_dir/src/logid/features/ThumbWheel.cpp:230:36: error: no match for ‘operator[]’ (operand types are ‘libconfig::Setting’ and ‘const string {aka const std::__cxx11::basic_string<char>}’)
         auto& a_group = config_root[name];
                                    ^
In file included from build_dir/src/logid/features/../actions/gesture/../Action.h:22:0,
                 from build_dir/src/logid/features/../actions/gesture/Gesture.h:21,
                 from build_dir/src/logid/features/ThumbWheel.h:23,
                 from build_dir/src/logid/features/ThumbWheel.cpp:19:
/usr/include/libconfig.h++:223:13: note: candidate: libconfig::Setting& libconfig::Setting::operator[](const char*) const
   Setting & operator[](const char *name) const;
             ^~~~~~~~
/usr/include/libconfig.h++:223:13: note:   no known conversion for argument 1 from ‘const string {aka const std::__cxx11::basic_string<char>}’ to ‘const char*’
/usr/include/libconfig.h++:224:13: note: candidate: libconfig::Setting& libconfig::Setting::operator[](int) const
   Setting & operator[](int index) const;
             ^~~~~~~~
/usr/include/libconfig.h++:224:13: note:   no known conversion for argument 1 from ‘const string {aka const std::__cxx11::basic_string<char>}’ to ‘int’
build_dir/src/logid/features/ThumbWheel.cpp: In static member function ‘static std::shared_ptr<logid::actions::Gesture> logid::features::ThumbWheel::Config::_genGesture(logid::Device*, libconfig::Setting&, const string&)’:
build_dir/src/logid/features/ThumbWheel.cpp:247:36: error: no match for ‘operator[]’ (operand types are ‘libconfig::Setting’ and ‘const string {aka const std::__cxx11::basic_string<char>}’)
         auto& g_group = config_root[name];
                                    ^
In file included from build_dir/src/logid/features/../actions/gesture/../Action.h:22:0,
                 from build_dir/src/logid/features/../actions/gesture/Gesture.h:21,
                 from build_dir/src/logid/features/ThumbWheel.h:23,
                 from build_dir/src/logid/features/ThumbWheel.cpp:19:
/usr/include/libconfig.h++:223:13: note: candidate: libconfig::Setting& libconfig::Setting::operator[](const char*) const
   Setting & operator[](const char *name) const;
             ^~~~~~~~
/usr/include/libconfig.h++:223:13: note:   no known conversion for argument 1 from ‘const string {aka const std::__cxx11::basic_string<char>}’ to ‘const char*’
/usr/include/libconfig.h++:224:13: note: candidate: libconfig::Setting& libconfig::Setting::operator[](int) const
   Setting & operator[](int index) const;
             ^~~~~~~~

@PixlOne
Copy link
Owner

PixlOne commented Nov 23, 2020

@abraha2d I'm looking at libconfig 1.4.9 on the CentOS repos and it appears that it does have support for .lookup(). Can you post the errors you were getting when compiling before this PR?

Also, because of bug #158, I'm going to have to revert this change.

@abraha2d
Copy link
Contributor Author

This is the error I was encountering:

logiops/src/logid/Configuration.cpp: In constructor ‘logid::Configuration::Configuration(const string&)’:
logiops/src/logid/Configuration.cpp:101:29: error: ‘const class libconfig::Setting’ has no member named ‘lookup’
  101 |         auto& ignore = root.lookup("ignore");
      |                             ^~~~~~
logiops/src/logid/Configuration.cpp:119:33: error: ‘const class libconfig::Setting’ has no member named ‘lookup’
  119 |             auto& ignore = root.lookup("blacklist");
      |                                 ^~~~~~
make[2]: *** [src/logid/CMakeFiles/logid.dir/build.make:161: src/logid/CMakeFiles/logid.dir/Configuration.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:114: src/logid/CMakeFiles/logid.dir/all] Error 2
make: *** [Makefile:150: all] Error 2

@abraha2d
Copy link
Contributor Author

abraha2d commented Nov 23, 2020

libconfig v1.4.9 has Config.lookup(), but it does not have Setting.lookup(). Setting.lookup() was added in v1.5 to unify the lookup API between Config and Setting: hyperrealm/libconfig@1ff9b7f.

The issue that's occurring with my PR is a mismatch between const char* and const string when trying to find the [] operator (which for some reason my compiler isn't complaining about). I'll see if I can fix and update the PR.

@PixlOne
Copy link
Owner

PixlOne commented Nov 23, 2020

Alright, thanks.

@abraha2d
Copy link
Contributor Author

abraha2d commented Nov 23, 2020

I committed a fix over on abraha2d/logiops, but I don't currently have access to an Ubuntu system to verify that it fixes the issue... It compiles fine on RHEL 7 with GCC 9.3.1.

diff --git a/src/logid/features/ThumbWheel.cpp b/src/logid/features/ThumbWheel.cpp
index 5e00926..0017080 100644
--- a/src/logid/features/ThumbWheel.cpp
+++ b/src/logid/features/ThumbWheel.cpp
@@ -227,7 +227,7 @@ std::shared_ptr<actions::Action> ThumbWheel::Config::_genAction(Device* dev,
         libconfig::Setting& config_root, const std::string& name)
 {
     try {
-        auto& a_group = config_root[name];
+        auto& a_group = config_root[name.c_str()];
         try {
             return actions::Action::makeAction(dev, a_group);
         } catch(actions::InvalidAction& e) {
@@ -244,7 +244,7 @@ std::shared_ptr<actions::Gesture> ThumbWheel::Config::_genGesture(Device* dev,
         libconfig::Setting& config_root, const std::string& name)
 {
     try {
-        auto& g_group = config_root[name];
+        auto& g_group = config_root[name.c_str()];
         try {
             auto g = actions::Gesture::makeGesture(dev, g_group);
             if(g->wheelCompatibility()) {

@PixlOne
Copy link
Owner

PixlOne commented Nov 23, 2020

@ightnapovial Could you test out the fix on https://github.com/abraha2d/logiops?

This was referenced Nov 24, 2020
@abraha2d
Copy link
Contributor Author

fwiw I was able to test that it compiles successfully on KDE neon 5.19 (based on Ubuntu 18.04) with GCC 10.1.0.

@abraha2d
Copy link
Contributor Author

@PixlOne Any updates on this? I've got some more PRs that are in draft (#160 and #161) pending resolution of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants