From c8a0505ff7c7ee1c4e5e4751c5dfed71d890c764 Mon Sep 17 00:00:00 2001 From: Sergey Konev Date: Fri, 25 Oct 2024 14:51:16 +0300 Subject: [PATCH] Minor binding fix to work with nullptr --- apt-pkg-c/lib.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/apt-pkg-c/lib.cpp b/apt-pkg-c/lib.cpp index 136112c..90e6a91 100644 --- a/apt-pkg-c/lib.cpp +++ b/apt-pkg-c/lib.cpp @@ -589,9 +589,20 @@ const char *pkg_file_iter_file_name(PPkgFileIterator *wrapper) { return wrapper->iterator.FileName(); } +#ifndef ALT_LINUX const char *pkg_file_iter_archive(PPkgFileIterator *wrapper) { return wrapper->iterator.Archive(); } +#else +const char *pkg_file_iter_archive(PPkgFileIterator *wrapper) { + const char *archive = wrapper->iterator.Archive(); + if (archive == nullptr) { + // Should be non-null + return to_c_string("Not Specified"); + } + return archive; +} +#endif const char *pkg_file_iter_version(PPkgFileIterator *wrapper) { return wrapper->iterator.Version(); @@ -624,14 +635,37 @@ const char *pkg_file_iter_site(PPkgFileIterator *wrapper) { return wrapper->iterator.Site(); } +#ifndef ALT_LINUX const char *pkg_file_iter_component(PPkgFileIterator *wrapper) { return wrapper->iterator.Component(); } +#else +const char *pkg_file_iter_component(PPkgFileIterator *wrapper) { + const char *component = wrapper->iterator.Component(); + if (component == nullptr) { + // Should be non-null + return to_c_string("Not Specified"); + } + return component; +} + +#endif const char *pkg_file_iter_architecture(PPkgFileIterator *wrapper) { return wrapper->iterator.Architecture(); } +#ifndef ALT_LINUX const char *pkg_file_iter_index_type(PPkgFileIterator *wrapper) { return wrapper->iterator.IndexType(); } +#else +const char *pkg_file_iter_index_type(PPkgFileIterator *wrapper) { + const char *index_type = wrapper->iterator.IndexType(); + if (index_type == nullptr) { + // Should be non-null + return to_c_string("Not Specified"); + } + return index_type; +} +#endif