From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id uK/LJrNC0GF0NAAAgWs5BA (envelope-from ) for ; Sat, 01 Jan 2022 13:01:55 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id iN0qJLNC0GF+dQAA9RJhRA (envelope-from ) for ; Sat, 01 Jan 2022 13:01:55 +0100 Received: from mail.notmuchmail.org (yantan.tethera.net [135.181.149.255]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 543CF2E26B for ; Sat, 1 Jan 2022 13:01:55 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 7A3925F727; Sat, 1 Jan 2022 12:01:45 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 9A7D95F70C for ; Sat, 1 Jan 2022 12:01:42 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 265A25FC48; Sat, 1 Jan 2022 07:01:42 -0500 (EST) Received: (nullmailer pid 38203 invoked by uid 1000); Sat, 01 Jan 2022 12:01:40 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 1/3] CLI: stash pointer to database in sprinter structs Date: Sat, 1 Jan 2022 08:01:34 -0400 Message-Id: <20220101120136.37988-2-david@tethera.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220101120136.37988-1-david@tethera.net> References: <20220101120136.37988-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: OGQDDNFHK44A5QJ7VPLMA736TGOZDV3W X-Message-ID-Hash: OGQDDNFHK44A5QJ7VPLMA736TGOZDV3W X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1641038515; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=rzw8crPR6h7iHVWzI8uEiFukwtdKaR3k1SV9A8ve6pQ=; b=JQ/f8tOUm1fjmE702s2sd8+UAnd4QRCDc4kqurPWYuRgGeBWSh2yE3fNnJ790w5i0gQBJm rnEZwQmcYypYpwUcF8I1ZZNDRc9t7nzkM/5ENlHAM7Kh8xgfVdUdcojjrsp1nQZdKwZmnx /u5E1MVCsxpkSc42CWT0sKEwDVIrWxrf9SpeRsV2D6CCNpV88LlWBjsZpftWXAj+l5XrOq jSJMuq8mH0K+/BgVjk3KpNBN8cvMJ1nb8++MfPGZkWEJReyYFcFNLDjy8DgJPzkwwmdixi 3aPbtZVV3+M4Dlu3Jv05d40PBS2yZkkvcX/YA2Dt83u/c0vFQqmOAdbUP/82QQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1641038515; a=rsa-sha256; cv=none; b=tHT/iiOZ8oDt6AHc5e9MFkc8hmaeOXdCVDQCxr++dHaXnRQV4Arp2cQinquH2wMWYx1/Uk 08Lg5dABtHHh6REI+/SP8PBxlxIscBrkbuxa+0uF8qXdQTgE+JlMh6rOiTlesulAIcOytJ gdvKOLmvPGPX8a9qCD+n4L9lSBJAhF4xaUa4J23XBFZB5iWg3VsJU2jgK7jAA0xwbY4RXo zL/3nn6CvsD7puPGoLX82nwru0/aGLzi7c/qIB9i3hMD/VhO2oWDjnBgldH9v8/5ort/UK sZ54SmeQCrdBNBiE6FR2B5BClzfv6NrMKTQu8KZIzLxktSHNhRwA4O/icwj7lQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.27 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 543CF2E26B X-Spam-Score: -1.27 X-Migadu-Scanner: scn1.migadu.com X-TUID: oI4gApR/dGjB We already use an allocated (and presumably open) database as a talloc context. Keeping the pointer in the allocated struct will allow us to e.g. interrogate the configuration in a sprinter function without threading the database all the way through the various levels of function. --- notmuch-client.h | 2 +- sprinter-json.c | 5 +++-- sprinter-sexp.c | 5 +++-- sprinter-text.c | 9 +++++---- sprinter.h | 13 +++++++++---- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/notmuch-client.h b/notmuch-client.h index de318e1f..9f57ac5e 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -65,7 +65,7 @@ struct sprinter; struct notmuch_show_params; typedef struct notmuch_show_format { - struct sprinter *(*new_sprinter)(const void *ctx, FILE *stream); + struct sprinter *(*new_sprinter)(notmuch_database_t * db, FILE *stream); notmuch_status_t (*part)(const void *ctx, struct sprinter *sprinter, struct mime_node *node, int indent, const struct notmuch_show_params *params); diff --git a/sprinter-json.c b/sprinter-json.c index c7f4851c..502f89fb 100644 --- a/sprinter-json.c +++ b/sprinter-json.c @@ -172,7 +172,7 @@ json_separator (struct sprinter *sp) } struct sprinter * -sprinter_json_create (const void *ctx, FILE *stream) +sprinter_json_create (notmuch_database_t *db, FILE *stream) { static const struct sprinter_json template = { .vtable = { @@ -192,11 +192,12 @@ sprinter_json_create (const void *ctx, FILE *stream) }; struct sprinter_json *res; - res = talloc (ctx, struct sprinter_json); + res = talloc (db, struct sprinter_json); if (! res) return NULL; *res = template; + res->vtable.notmuch = db; res->stream = stream; return &res->vtable; } diff --git a/sprinter-sexp.c b/sprinter-sexp.c index 63b25428..e37cb1f9 100644 --- a/sprinter-sexp.c +++ b/sprinter-sexp.c @@ -207,7 +207,7 @@ sexp_separator (struct sprinter *sp) } struct sprinter * -sprinter_sexp_create (const void *ctx, FILE *stream) +sprinter_sexp_create (notmuch_database_t *db, FILE *stream) { static const struct sprinter_sexp template = { .vtable = { @@ -227,11 +227,12 @@ sprinter_sexp_create (const void *ctx, FILE *stream) }; struct sprinter_sexp *res; - res = talloc (ctx, struct sprinter_sexp); + res = talloc (db, struct sprinter_sexp); if (! res) return NULL; *res = template; + res->vtable.notmuch = db; res->stream = stream; return &res->vtable; } diff --git a/sprinter-text.c b/sprinter-text.c index c75ec5be..99330a94 100644 --- a/sprinter-text.c +++ b/sprinter-text.c @@ -114,7 +114,7 @@ text_map_key (unused (struct sprinter *sp), unused (const char *key)) } struct sprinter * -sprinter_text_create (const void *ctx, FILE *stream) +sprinter_text_create (notmuch_database_t *db, FILE *stream) { static const struct sprinter_text template = { .vtable = { @@ -134,21 +134,22 @@ sprinter_text_create (const void *ctx, FILE *stream) }; struct sprinter_text *res; - res = talloc (ctx, struct sprinter_text); + res = talloc (db, struct sprinter_text); if (! res) return NULL; *res = template; + res->vtable.notmuch = db; res->stream = stream; return &res->vtable; } struct sprinter * -sprinter_text0_create (const void *ctx, FILE *stream) +sprinter_text0_create (notmuch_database_t *db, FILE *stream) { struct sprinter *sp; - sp = sprinter_text_create (ctx, stream); + sp = sprinter_text_create (db, stream); if (! sp) return NULL; diff --git a/sprinter.h b/sprinter.h index 528d8a2d..fd08641c 100644 --- a/sprinter.h +++ b/sprinter.h @@ -9,6 +9,11 @@ * (strings, integers and booleans). */ typedef struct sprinter { + /* + * Open notmuch database + */ + notmuch_database_t *notmuch; + /* Start a new map/dictionary structure. This should be followed by * a sequence of alternating calls to map_key and one of the * value-printing functions until the map is ended by end. @@ -65,20 +70,20 @@ typedef struct sprinter { /* Create a new unstructured printer that emits the default text format * for "notmuch search". */ struct sprinter * -sprinter_text_create (const void *ctx, FILE *stream); +sprinter_text_create (notmuch_database_t *db, FILE *stream); /* Create a new unstructured printer that emits the text format for * "notmuch search", with each field separated by a null character * instead of the newline character. */ struct sprinter * -sprinter_text0_create (const void *ctx, FILE *stream); +sprinter_text0_create (notmuch_database_t *db, FILE *stream); /* Create a new structure printer that emits JSON. */ struct sprinter * -sprinter_json_create (const void *ctx, FILE *stream); +sprinter_json_create (notmuch_database_t *db, FILE *stream); /* Create a new structure printer that emits S-Expressions. */ struct sprinter * -sprinter_sexp_create (const void *ctx, FILE *stream); +sprinter_sexp_create (notmuch_database_t *db, FILE *stream); #endif // NOTMUCH_SPRINTER_H -- 2.34.1