From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id meIQFHjGomD6PgEAgWs5BA (envelope-from ) for ; Mon, 17 May 2021 21:39:36 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id aJAWD3jGomBqHgAAB5/wlQ (envelope-from ) for ; Mon, 17 May 2021 19:39:36 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (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 779CE293E4 for ; Mon, 17 May 2021 21:39:35 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 7E7502AA56; Mon, 17 May 2021 15:39:28 -0400 (EDT) Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by mail.notmuchmail.org (Postfix) with ESMTPS id 2DF6F2AA57 for ; Mon, 17 May 2021 15:39:24 -0400 (EDT) Received: by mail-oi1-x22d.google.com with SMTP id b25so7598976oic.0 for ; Mon, 17 May 2021 12:39:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WVGY81N1HPTXDhCgJvsTxRi59RNwejggTjarQNQYFiI=; b=Nhlz2G3cBSJI1l1uILLIQRtMRSZ3obEPJ+unpzoBQqGG7+XCxwC44RX0OQZ1nzuX0J fxMK0zBtXE7Oke4m6qewzQhMbY8QopRT92Sgc8h6nE2dRDCfeoC1rX5law5HytIvXiYv CPORNFHPC+orffH9G6JjqIPh7hwvp3/qh8jEhAw/afLrfJHXk+7maRsVc/d4T0PxeuSn p6h3401hl4lu5F67WaJmPY91BR9vwD2kEeuu76yy4Y1zOw9n1OqjgB5N1kvPPWlg3zOZ Vk5PqHlWHd0sCJaflCFOCRbLdeSGH0b4Ob+Ds9uqXxrb+sTS0ooEjNTdrrek78jFzOE5 EgFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WVGY81N1HPTXDhCgJvsTxRi59RNwejggTjarQNQYFiI=; b=n9jzGA8aMW02fmgFBotadjkHQj84yyKWOVnMqtp8uztBTonaR6UuHOfiNWsdXoZeUx E0fw7MsrDANDUgTHWGqz1nuPDXMR1Ap9oNoRDR95NL0YBvsx6q7WmeGLVv7Q8pbktJkV ZiEQS2cCslDqCMy3IuqjSyjsnXXw8VhL40sKeT/llgsnyd2AgZ0lfq1WHtcdT+EjIlzh bP1aIT1NFgyxeSqatfVzMV8dIuq/3u364gzQzIma+kTrBfwcOtp7y4OHjvX0GtSlH9dc RFhCdjuDTXlvaLHL6zY6owuN2k6wTrvsu6i3+20wH38du3DogGYGMLdlmjp4HYvxiQ7d BdtA== X-Gm-Message-State: AOAM531YwA5QZ0geq1zTrlyeL2xb0EnddpPX1hMe+bZejwT+IsVab2EQ pgTRPjSkK3xvkFzxJRTjY6BxLBT6F9NBPg== X-Google-Smtp-Source: ABdhPJwWeWCB0FYJ1gjl5JO3mLosf674ejzAEaR8uW+ADYdUd/MAG2FQBSUwyCnVnsoWy0PoaDdNgA== X-Received: by 2002:aca:ebc1:: with SMTP id j184mr990890oih.125.1621280359289; Mon, 17 May 2021 12:39:19 -0700 (PDT) Received: from localhost (fixed-187-190-78-172.totalplay.net. [187.190.78.172]) by smtp.gmail.com with ESMTPSA id a19sm3395051otk.31.2021.05.17.12.39.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 12:39:18 -0700 (PDT) From: Felipe Contreras To: notmuch@notmuchmail.org Subject: [PATCH 1/2] ruby: create an actual wrapper struct Date: Mon, 17 May 2021 14:39:14 -0500 Message-Id: <20210517193915.1220114-2-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517193915.1220114-1-felipe.contreras@gmail.com> References: <20210517193915.1220114-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Message-ID-Hash: LXIRHHFZVKUS62AHMYR6FIJWRWULWPDV X-Message-ID-Hash: LXIRHHFZVKUS62AHMYR6FIJWRWULWPDV X-MailFrom: felipe.contreras@gmail.com 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; suspicious-header CC: Tomi Ollila X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1621280375; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc: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-unsubscribe:list-subscribe:list-post:dkim-signature; bh=9mLNj/iRR2lQnXP0MKLqZez0La6P2zYAwdxvbNYPSZo=; b=VcVgDfNmG03NOwslZcU5H7XBtSh7XC5xC6Vr7zMUkak2jDw2zi2jNKbK9wQVinYHJk6HhA qJAoUOW67w+f3wWT7HrWp+bs8Yg3lEmfGcPuE5KqwZNNRShRmTgUnERRqeRH5fH9+obQBL jyKgF/A7YUpD3+W8S6ZlsYelSuHT+qSFF89385mMBF7E7JnBDjTbWqOIUWzrHQbb7ef7g3 /aXflbErb9w3VTfWQ1MaX43zhPuK8Tw9Vq7IUFAKigtOyuBear4W6MEUeMbWHtVGOXFR65 8eJvelCPOpsJZ7WHevQPYnxiR4XG58phi8Fcwg/Sc+7BudK0AMvEbfMKvtzyWA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1621280375; a=rsa-sha256; cv=none; b=qTeVxTKzB0+B6kH14DGRzzqpyV6CURW8kuqCPMu6/SNsJB8HfpTr795p/iVxbZH15mhJ9a yzj/0juQlgFFxmIAMGWuYj9vpiddzH28M3ktE06Rma+sNVviWqnj44l9dpM4csaux3z91b hGR1TyQeFPRS9yEWbzx9wRQUKWxv6ZLBmVQDpSJqEE7Skj+8UhNLIXnQDH/gVeBGvvv9dS qErorIEPuFk0vUwsIvMJLm1JIKy4HlMct4RYharEMytLGcd9dGkEzWkK2h3BG2kFDPUtU5 8f3M+LBbYG/VXcRxcHqJ3uLxafs1H0HgBl2cNDFBHYJ8YNHcgd1PFZMhsDeR/Q== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b=Nhlz2G3c; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -0.98 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b=Nhlz2G3c; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 779CE293E4 X-Spam-Score: -0.98 X-Migadu-Scanner: scn0.migadu.com X-TUID: EUurzdbfDrV9 Currently Ruby data points directly to a notmuch object (e.g. notmuch_database_t), since we don't need any extra data that is fine. However, in the next commit we will need extra data, therefore we create a new struct notmuch_rb_object_t wrapper which contains nothing but a pointer to the current pointer (e.g. notmuch_database_t). This struct is tied to the Ruby object, and is freed when the Ruby object is freed by the garbage collector. We do nothing with this wrapper, so no functionality should be changed. Signed-off-by: Felipe Contreras --- bindings/ruby/database.c | 2 +- bindings/ruby/defs.h | 39 ++++++++++++++++++++++++++++++++++----- bindings/ruby/init.c | 6 ++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c index bb993d86..66100de2 100644 --- a/bindings/ruby/database.c +++ b/bindings/ruby/database.c @@ -81,7 +81,7 @@ notmuch_rb_database_initialize (int argc, VALUE *argv, VALUE self) ret = notmuch_database_open (path, mode, &database); notmuch_rb_status_raise (ret); - DATA_PTR (self) = database; + DATA_PTR (self) = notmuch_rb_object_create (database); return self; } diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h index 9860ee17..1413eb72 100644 --- a/bindings/ruby/defs.h +++ b/bindings/ruby/defs.h @@ -66,7 +66,7 @@ extern const rb_data_type_t notmuch_rb_messages_type; extern const rb_data_type_t notmuch_rb_message_type; extern const rb_data_type_t notmuch_rb_tags_type; -#define Data_Get_Notmuch_Object(obj, type, ptr) \ +#define Data_Get_Notmuch_Rb_Object(obj, type, ptr) \ do { \ (ptr) = rb_check_typeddata ((obj), (type)); \ if (RB_UNLIKELY (!(ptr))) { \ @@ -75,8 +75,15 @@ extern const rb_data_type_t notmuch_rb_tags_type; } \ } while (0) +#define Data_Get_Notmuch_Object(obj, type, ptr) \ + do { \ + notmuch_rb_object_t *rb_wrapper; \ + Data_Get_Notmuch_Rb_Object ((obj), (type), rb_wrapper); \ + (ptr) = rb_wrapper->nm_object; \ + } while (0) + #define Data_Wrap_Notmuch_Object(klass, type, ptr) \ - TypedData_Wrap_Struct ((klass), (type), (ptr)) + TypedData_Wrap_Struct ((klass), (type), notmuch_rb_object_create ((ptr))) #define Data_Get_Notmuch_Database(obj, ptr) \ Data_Get_Notmuch_Object ((obj), ¬much_rb_database_type, (ptr)) @@ -105,16 +112,38 @@ extern const rb_data_type_t notmuch_rb_tags_type; #define Data_Get_Notmuch_Tags(obj, ptr) \ Data_Get_Notmuch_Object ((obj), ¬much_rb_tags_type, (ptr)) +typedef struct { + void *nm_object; +} notmuch_rb_object_t; + +static inline void * +notmuch_rb_object_create (void *nm_object) +{ + notmuch_rb_object_t *rb_wrapper = malloc (sizeof (*rb_wrapper)); + if (RB_UNLIKELY (!rb_wrapper)) + return NULL; + + rb_wrapper->nm_object = nm_object; + return rb_wrapper; +} + +static inline void +notmuch_rb_object_free (void *rb_wrapper) +{ + free (rb_wrapper); +} + static inline notmuch_status_t notmuch_rb_object_destroy (VALUE rb_object, const rb_data_type_t *type) { - void *nm_object; + notmuch_rb_object_t *rb_wrapper; notmuch_status_t ret; - Data_Get_Notmuch_Object (rb_object, type, nm_object); + Data_Get_Notmuch_Rb_Object (rb_object, type, rb_wrapper); /* Call the corresponding notmuch_*_destroy function */ - ret = ((notmuch_status_t (*)(void *)) type->data) (nm_object); + ret = ((notmuch_status_t (*)(void *)) type->data) (rb_wrapper->nm_object); + notmuch_rb_object_free (rb_wrapper); DATA_PTR (rb_object) = NULL; return ret; diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c index 62515eca..831f7695 100644 --- a/bindings/ruby/init.c +++ b/bindings/ruby/init.c @@ -48,6 +48,9 @@ ID ID_db_mode; const rb_data_type_t notmuch_rb_object_type = { .wrap_struct_name = "notmuch_object", + .function = { + .dfree = notmuch_rb_object_free, + }, }; #define define_type(id) \ @@ -55,6 +58,9 @@ const rb_data_type_t notmuch_rb_object_type = { .wrap_struct_name = "notmuch_" #id, \ .parent = ¬much_rb_object_type, \ .data = ¬much_ ## id ## _destroy, \ + .function = { \ + .dfree = notmuch_rb_object_free, \ + }, \ } define_type (database); -- 2.31.1