Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: /, tests/qatom/
Date: Mon, 02 Apr 2018 17:27:46
Message-Id: 1522683701.17c3a565b626fbace414fae18c733dc578263824.grobian@gentoo
1 commit: 17c3a565b626fbace414fae18c733dc578263824
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Mon Apr 2 15:41:41 2018 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Mon Apr 2 15:41:41 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=17c3a565
7
8 qatom: print unset members as <unset> instead of relying on libc
9
10 Some libcs do NOT do the favour of turning a NULL-pointer into the
11 string "(null)", but segfault instead. This is just a friendly guesture
12 of libcs which do, but it is nowhere standard or that this should result
13 in "(null)". While "(null)" is actually a developer concept, and
14 possibly out of context for users, check for printing NULL-pointers and
15 replace them with "<unset>" instead.
16
17 qatom.c | 20 ++++++++++++--------
18 tests/qatom/dotest | 6 +++---
19 2 files changed, 15 insertions(+), 11 deletions(-)
20
21 diff --git a/qatom.c b/qatom.c
22 index 7f981c3..b542de8 100644
23 --- a/qatom.c
24 +++ b/qatom.c
25 @@ -59,21 +59,22 @@ qatom_printf(const char *format, const depend_atom *atom, int pverbose)
26 if (p) {
27 size_t len = p - fmt;
28 bool showit = (bracket == '{') || pverbose;
29 +#define HN(X) (X ? X : "<unset>")
30 if (!strncmp("CATEGORY", fmt, len)) {
31 if (showit || atom->CATEGORY)
32 - printf("%s", atom->CATEGORY);
33 + printf("%s", HN(atom->CATEGORY));
34 } else if (!strncmp("P", fmt, len)) {
35 if (showit || atom->P)
36 - printf("%s", atom->P);
37 + printf("%s", HN(atom->P));
38 } else if (!strncmp("PN", fmt, len)) {
39 if (showit || atom->PN)
40 - printf("%s", atom->PN);
41 + printf("%s", HN(atom->PN));
42 } else if (!strncmp("PV", fmt, len)) {
43 if (showit || atom->PV)
44 - printf("%s", atom->PV);
45 + printf("%s", HN(atom->PV));
46 } else if (!strncmp("PVR", fmt, len)) {
47 if (showit || atom->PVR)
48 - printf("%s", atom->PVR);
49 + printf("%s", HN(atom->PVR));
50 } else if (!strncmp("PF", fmt, len)) {
51 printf("%s", atom->PN);
52 if (atom->PV)
53 @@ -85,16 +86,19 @@ qatom_printf(const char *format, const depend_atom *atom, int pverbose)
54 printf("r%i", atom->PR_int);
55 } else if (!strncmp("SLOT", fmt, len)) {
56 if (showit || atom->SLOT)
57 - printf(":%s", atom->SLOT ? : "-");
58 + printf(":%s", atom->SLOT ? atom->SLOT : "-");
59 } else if (!strncmp("pfx", fmt, len)) {
60 if (showit || atom->pfx_op != ATOM_OP_NONE)
61 - fputs(atom->pfx_op == ATOM_OP_NONE ? "-" : atom_op_str[atom->pfx_op], stdout);
62 + fputs(atom->pfx_op == ATOM_OP_NONE ?
63 + "-" : atom_op_str[atom->pfx_op], stdout);
64 } else if (!strncmp("sfx", fmt, len)) {
65 if (showit || atom->sfx_op != ATOM_OP_NONE)
66 - fputs(atom->sfx_op == ATOM_OP_NONE ? "-" : atom_op_str[atom->sfx_op], stdout);
67 + fputs(atom->sfx_op == ATOM_OP_NONE ?
68 + "-" : atom_op_str[atom->sfx_op], stdout);
69 } else
70 printf("<BAD:%.*s>", (int)len, fmt);
71 ++p;
72 +#undef HN
73 } else
74 p = fmt + 1;
75 } else
76
77 diff --git a/tests/qatom/dotest b/tests/qatom/dotest
78 index c14001f..4bb0460 100755
79 --- a/tests/qatom/dotest
80 +++ b/tests/qatom/dotest
81 @@ -19,8 +19,8 @@ test() {
82 }
83
84 # Legacy format.
85 -test l01 "(null) pkg (null)" "pkg"
86 -test l02 "cat pkg (null)" "cat/pkg"
87 +test l01 "<unset> pkg <unset>" "pkg"
88 +test l02 "cat pkg <unset>" "cat/pkg"
89 test l03 "cat pkg 123" "cat/pkg-123"
90 test l04 "cat pkg 123 r4" "cat/pkg-123-r4"
91 test l05 "cat pkg 123 r4 :5" "cat/pkg-123-r4:5"
92 @@ -30,7 +30,7 @@ test l07 "cat pkg 123 = *" "=cat/pkg-123*"
93
94 # Explicit format.
95 test f01 "cat" -F '%{CATEGORY}' "cat/pkg"
96 -test f02 "(null)" -F '%{CATEGORY}' "pkg"
97 +test f02 "<unset>" -F '%{CATEGORY}' "pkg"
98 test f03 "" -F '%[CATEGORY]' "pkg"
99 test f04 "cat" -F '%{CATEGORY}' "cat/pkg-123-r4:5"
100 test f05 "pkg-123" -F '%{P}' "cat/pkg-123-r4:5"