From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 15/18] xap_helper: better variable naming for key buffer
Date: Mon, 13 Nov 2023 13:15:48 +0000 [thread overview]
Message-ID: <20231113131551.843230-16-e@80x24.org> (raw)
In-Reply-To: <20231113131551.843230-1-e@80x24.org>
We'll use `kbuf' for the search object key, since we already use
the `fbuf' term in `struct fbuf'. This also adds an extra check
for open_memstream(3) failures in case of ENOMEM.
---
lib/PublicInbox/xap_helper.h | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/lib/PublicInbox/xap_helper.h b/lib/PublicInbox/xap_helper.h
index 1380ffd0..0a652abd 100644
--- a/lib/PublicInbox/xap_helper.h
+++ b/lib/PublicInbox/xap_helper.h
@@ -762,7 +762,7 @@ static void dispatch(struct req *req)
union {
struct srch *srch;
char *ptr;
- } fbuf;
+ } kbuf;
char *end;
FILE *kfp;
struct srch **s;
@@ -776,8 +776,9 @@ static void dispatch(struct req *req)
}
if (!req->fn) ABORT("not handled: `%s'", req->argv[0]);
- kfp = open_memstream(&fbuf.ptr, &size);
- // write padding, first
+ kfp = open_memstream(&kbuf.ptr, &size);
+ if (!kfp) err(EXIT_FAILURE, "open_memstream(kbuf)");
+ // write padding, first (contents don't matter)
fwrite(&req->argv[0], offsetof(struct srch, paths), 1, kfp);
// global getopt variables:
@@ -824,26 +825,24 @@ static void dispatch(struct req *req)
default: ABORT("bad switch `-%c'", c);
}
}
- if (ferror(kfp) | fclose(kfp))
+ if (ferror(kfp) | fclose(kfp)) /* sets kbuf.srch */
err(EXIT_FAILURE, "ferror|fclose"); // likely ENOMEM
- fbuf.srch->db = NULL;
- fbuf.srch->qp = NULL;
- fbuf.srch->paths_len = size - offsetof(struct srch, paths);
- if (fbuf.srch->paths_len <= 0) {
- free_srch(fbuf.srch);
+ kbuf.srch->db = NULL;
+ kbuf.srch->qp = NULL;
+ kbuf.srch->paths_len = size - offsetof(struct srch, paths);
+ if (kbuf.srch->paths_len <= 0)
ABORT("no -d args");
- }
- s = (struct srch **)tsearch(fbuf.srch, &srch_tree, srch_cmp);
+ s = (struct srch **)tsearch(kbuf.srch, &srch_tree, srch_cmp);
if (!s) err(EXIT_FAILURE, "tsearch"); // likely ENOMEM
req->srch = *s;
- if (req->srch != fbuf.srch) { // reuse existing
- free_srch(fbuf.srch);
+ if (req->srch != kbuf.srch) { // reuse existing
+ free_srch(kbuf.srch);
} else if (!srch_init(req)) {
- assert(fbuf.srch == *((struct srch **)tfind(
- fbuf.srch, &srch_tree, srch_cmp)));
- void *del = tdelete(fbuf.srch, &srch_tree, srch_cmp);
+ assert(kbuf.srch == *((struct srch **)tfind(
+ kbuf.srch, &srch_tree, srch_cmp)));
+ void *del = tdelete(kbuf.srch, &srch_tree, srch_cmp);
assert(del);
- free_srch(fbuf.srch);
+ free_srch(kbuf.srch);
goto cmd_err; // srch_init already warned
}
try {
next prev parent reply other threads:[~2023-11-13 13:15 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-13 13:15 [PATCH 00/18] cindex: some --associate work Eric Wong
2023-11-13 13:15 ` [PATCH 01/18] cindex: check `say' errors w/ close or ->flush Eric Wong
2023-11-13 13:15 ` [PATCH 02/18] tmpfile: check `stat' errors, use autodie for unlink Eric Wong
2023-11-13 13:15 ` [PATCH 03/18] cindex: use `local' for pipes between processes Eric Wong
2023-11-13 13:15 ` [PATCH 04/18] xap_helper_cxx: use write_file helper Eric Wong
2023-11-13 13:15 ` [PATCH 05/18] xap_helper_cxx: make the build process ccache-friendly Eric Wong
2023-11-13 13:15 ` [PATCH 06/18] xap_helper_cxx: use -pipe by default in CXXFLAGS Eric Wong
2023-11-13 13:15 ` [PATCH 07/18] xap_client: spawn C++ xap_helper directly Eric Wong
2023-11-13 13:15 ` [PATCH 08/18] treewide: update read_all to avoid eof|close checks Eric Wong
2023-11-13 13:15 ` [PATCH 09/18] spawn: don't append to scalarrefs on stdout/stderr Eric Wong
2023-11-13 13:15 ` [PATCH 10/18] cindex: imply --all with --associate w/o -I/--only Eric Wong
2023-11-13 13:15 ` [PATCH 11/18] cindex: delay associate until prune+indexing finish Eric Wong
2023-11-13 13:15 ` [PATCH 12/18] xap_helper: Perl dump_ibx respects `-m MAX' Eric Wong
2023-11-13 13:15 ` [PATCH 13/18] cidx_xap_helper_aux: complain about truncated inputs Eric Wong
2023-11-13 13:15 ` [PATCH 14/18] xap_helper: stricter and harsher error handling Eric Wong
2023-11-13 13:15 ` Eric Wong [this message]
2023-11-13 13:15 ` [PATCH 16/18] cindex: do not guess integer maximum for Xapian Eric Wong
2023-11-13 13:15 ` [PATCH 17/18] cindex: rename associate-max => window Eric Wong
2023-11-13 13:15 ` [PATCH 18/18] cindex: support --associate-aggressive shortcut Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231113131551.843230-16-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).