Skip to content

Commit 879c690

Browse files
committed
swig: Modify Vars::detect_release to return char *
The original `Vars::detect_release` returns `std::unique_ptr<std::string>` This makes it complicated for wrapping into other languages. The modified version returns `char *` - a standard C string.
1 parent e832b9c commit 879c690

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

bindings/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ set(SWIG_COMPILE_OPTIONS
3434
-Wno-strict-aliasing
3535
-Wno-unused-function
3636
-Wno-unused-parameter
37+
-Wno-unused-but-set-variable
3738
)
3839

3940
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")

bindings/libdnf5/conf.i

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ wrap_unique_ptr(StringUniquePtr, std::string);
109109
%ignore ConfigParserOptionNotFoundError;
110110
%include "libdnf5/conf/config_parser.hpp"
111111

112+
%newobject libdnf5::Vars::detect_release;
113+
%extend libdnf5::Vars {
114+
static char * detect_release(const BaseWeakPtr & base, const std::string & install_root_path) {
115+
std::unique_ptr<std::string> release = libdnf5::Vars::detect_release(base, install_root_path);
116+
if (release) {
117+
char * release_cstr = new char[release->size() + 1];
118+
strcpy(release_cstr, release->c_str());
119+
return release_cstr;
120+
}
121+
return nullptr;
122+
}
123+
};
124+
%ignore libdnf5::Vars::detect_release;
112125
%ignore libdnf5::ReadOnlyVariableError;
113126
%include "libdnf5/conf/vars.hpp"
114127
%template(VarsWeakPtr) libdnf5::WeakPtr<libdnf5::Vars, false>;

0 commit comments

Comments
 (0)