dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] xap_helper: C++: test_inspect tests __cleanup__ support
Date: Sat, 16 Sep 2023 12:57:09 +0000	[thread overview]
Message-ID: <20230916125709.2575665-1-e@80x24.org> (raw)

We need to ensure the C++ compiler supports this GNU extensions
as we expect it to.
---
 lib/PublicInbox/xap_helper.h | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/xap_helper.h b/lib/PublicInbox/xap_helper.h
index 2322d062..377ff45a 100644
--- a/lib/PublicInbox/xap_helper.h
+++ b/lib/PublicInbox/xap_helper.h
@@ -578,12 +578,27 @@ static bool cmd_dump_roots(struct req *req)
 	return true;
 }
 
-// internal usage only
+// for test usage only, we need to ensure the compiler supports
+// __cleanup__ when exceptions are thrown
+struct inspect { struct req *req; };
+
+static void inspect_ensure(struct inspect *x)
+{
+	fprintf(x->req->fp[0], "pid=%d has_threadid=%d",
+		(int)getpid(), has_threadid(x->req->srch) ? 1 : 0);
+}
+
 static bool cmd_test_inspect(struct req *req)
 {
-	fprintf(req->fp[0], "pid=%d has_threadid=%d",
-		(int)getpid(), has_threadid(req->srch) ? 1 : 0);
-	return true;
+	__attribute__((__cleanup__(inspect_ensure))) struct inspect x;
+	x.req = req;
+	try {
+		throw Xapian::InvalidArgumentError("test");
+	} catch (Xapian::InvalidArgumentError) {
+		return true;
+	}
+	fputs("this should not be printed", req->fp[0]);
+	return false;
 }
 
 #define CMD(n) { .fn_len = sizeof(#n) - 1, .fn_name = #n, .fn = cmd_##n }

                 reply	other threads:[~2023-09-16 12:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230916125709.2575665-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.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.
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).