diff options
| author | Julian Andres Klode <jak@debian.org> | 2024-11-12 13:29:09 +0000 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2024-11-12 13:29:09 +0000 |
| commit | 8fd0ebc330bcdbced85877ff48bf40582bf983f9 (patch) | |
| tree | 9e8c83e567731fba5f00cc959b075fa0ee9533ba /apt-pkg/contrib | |
| parent | 8342f913c05c453e784bf038745351047d09af0a (diff) | |
| parent | a05e6fe18329ff8d91acf10efd4a1408858b0fda (diff) | |
Merge branch 'more' into 'main'
APT_BUFFER_SIZE pkgTagFile default size. std::vector(1024) -> std::array<1024>. dpkgpm buffers
See merge request apt-team/apt!390
Diffstat (limited to 'apt-pkg/contrib')
| -rw-r--r-- | apt-pkg/contrib/fileutl.h | 29 | ||||
| -rw-r--r-- | apt-pkg/contrib/gpgv.cc | 15 | ||||
| -rw-r--r-- | apt-pkg/contrib/srvrec.cc | 3 | ||||
| -rw-r--r-- | apt-pkg/contrib/strutl.cc | 2 | ||||
| -rw-r--r-- | apt-pkg/contrib/strutl.h | 9 |
5 files changed, 44 insertions, 14 deletions
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index db29ad71c..4ecddbf86 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -29,6 +29,7 @@ #include <ctime> #include <set> +#include <memory> #include <string> #include <vector> #include <sys/stat.h> @@ -284,4 +285,32 @@ APT_HIDDEN bool OpenConfigurationFileFd(std::string const &File, FileFd &Fd); APT_HIDDEN int Inhibit(const char *what, const char *who, const char *why, const char *mode); + +namespace { + struct FILEFcloseDeleter { + void operator()(FILE *p) { + fclose(p); + } + }; + struct FILEPcloseDeleter { + void operator()(FILE *p) { + pclose(p); + } + }; + + [[maybe_unused]] std::unique_ptr<FILE, FILEFcloseDeleter> make_unique_FILE(const char *const filename, char const *const mode) + { + return {fopen(filename, mode), {}}; + } + [[maybe_unused]] std::unique_ptr<FILE, FILEFcloseDeleter> make_unique_FILE(std::string const &filename, char const *const mode) + { + return make_unique_FILE(filename.c_str(), mode); + } + + [[maybe_unused]] std::unique_ptr<FILE, FILEPcloseDeleter> make_unique_popen(const char *program, char const *const mode) + { + return {popen(program, mode), {}}; + } +} + #endif diff --git a/apt-pkg/contrib/gpgv.cc b/apt-pkg/contrib/gpgv.cc index 225acae88..c5ea19aa8 100644 --- a/apt-pkg/contrib/gpgv.cc +++ b/apt-pkg/contrib/gpgv.cc @@ -28,15 +28,6 @@ #include <apti18n.h> /*}}}*/ -// syntactic sugar to wrap a raw pointer with a custom deleter in a std::unique_ptr -static std::unique_ptr<char, decltype(&free)> make_unique_char(void *const str = nullptr) -{ - return {static_cast<char *>(str), &free}; -} -static std::unique_ptr<FILE, decltype(&fclose)> make_unique_FILE(std::string const &filename, char const *const mode) -{ - return {fopen(filename.c_str(), mode), &fclose}; -} class LineBuffer /*{{{*/ { @@ -207,9 +198,9 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, } enum { DETACHED, CLEARSIGNED } releaseSignature = (FileGPG != File) ? DETACHED : CLEARSIGNED; - auto sig = make_unique_char(); - auto data = make_unique_char(); - auto conf = make_unique_char(); + std::unique_ptr<char, FreeDeleter> sig; + std::unique_ptr<char, FreeDeleter> data; + std::unique_ptr<char, FreeDeleter> conf; // Dump the configuration so apt-key picks up the correct Dir values { diff --git a/apt-pkg/contrib/srvrec.cc b/apt-pkg/contrib/srvrec.cc index 4a68f3578..3ddb95abb 100644 --- a/apt-pkg/contrib/srvrec.cc +++ b/apt-pkg/contrib/srvrec.cc @@ -16,6 +16,7 @@ #include <netinet/in.h> #include <resolv.h> +#include <array> #include <algorithm> #include <memory> #include <tuple> @@ -47,7 +48,7 @@ bool GetSrvRecords(std::string host, int port, std::vector<SrvRec> &Result) int res; struct servent s_ent_buf; struct servent *s_ent = nullptr; - std::vector<char> buf(1024); + std::array<char, 1024> buf; res = getservbyport_r(htons(port), "tcp", &s_ent_buf, buf.data(), buf.size(), &s_ent); if (res != 0 || s_ent == nullptr) diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 3689dc17a..ec61c7e2b 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -1421,7 +1421,7 @@ unsigned long RegexChoice(RxChoiceList *Rxs,const char **ListBegin, and to allow reordering of parameters */ bool iovprintf(std::ostream &out, const char *format, va_list &args, ssize_t &size) { - auto S = std::unique_ptr<char,decltype(&free)>{static_cast<char*>(malloc(size)), &free}; + auto S = std::unique_ptr<char,FreeDeleter>{static_cast<char*>(malloc(size))}; ssize_t const n = vsnprintf(S.get(), size, format, args); if (n > -1 && n < size) { out << S.get(); diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index 7cf9b456d..152477eee 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -31,6 +31,15 @@ #include "macros.h" +namespace { + struct FreeDeleter { + void operator()(void *p) { + free(p); + } + }; +} + + namespace APT { namespace String { APT_PUBLIC std::string Strip(const std::string &s); |
