From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 0A5PBHTGomD3PgEAgWs5BA (envelope-from ) for ; Mon, 17 May 2021 21:39:32 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id SMuDO3PGomCQHwAAbx9fmQ (envelope-from ) for ; Mon, 17 May 2021 19:39:31 +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 71A0F293DD for ; Mon, 17 May 2021 21:39:31 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 4DAE62AA5A; Mon, 17 May 2021 15:39:27 -0400 (EDT) Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by mail.notmuchmail.org (Postfix) with ESMTPS id 629502AA57 for ; Mon, 17 May 2021 15:39:22 -0400 (EDT) Received: by mail-ot1-x330.google.com with SMTP id r26-20020a056830121ab02902a5ff1c9b81so6567152otp.11 for ; Mon, 17 May 2021 12:39:22 -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=U4nDzxwFw4SIrbWwGNcqezrEReiaxazwdAea96B+fsI=; b=vW8f5HxM0+re7FjtpTypJlxrXsS3VHy8KoyvYyh/j67Idaswu8iB9kWY0k5sy0SkeO kfrgyGiAWQCGsatn6gmoRHKHJpbiKsH7dMyYNvUhd/UKl9EgCWTQNQaFiujkipl0ShjP 7CuWkVdGdhNiuoyoqtuW4FmPCZuwtd0NgZnF/9XLR10O1VUGBeMTW/BXJjavj77gU2oC G5L63hQG/cI1sEW18BqCna8HERsto4TeHTP8pWTbd0meDGktL8j2v+CS9PAHnLktTc5F tCj8q/9dlI64XewRn20DeDTv+PFflVNT1Kn3kIXrwJHqkhawCwpAwTRwK5+pFzbMUMHR hThg== 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=U4nDzxwFw4SIrbWwGNcqezrEReiaxazwdAea96B+fsI=; b=karDNBGxTrHN5sCCTYqep7dzMA4JQaEgifN8xkzCLUPrFoxdM03bgPWArnJ7C3dhyM Wd76vJMhx7w9GbnjBJo7MRlG2eYDEXvN8APcpWkB1Djbw+TqjNH0jMN49e5Vv1yFFjQD w/8VSxfeQuU3wjFRFHjhm/KOoQwJr9e02r+Prt26044uNYzIE9Y+/py8jOvJhZx4+2wZ oHFBGG8bfgwpnX8SWVsQiFtSDNQuRM0Vz4jVRinCoOiw0ye9l3Q9cDTW/4yox4typhfv tEbqaFsWfP3mnUJaHtyUHzii9CfFN0Dqq/HMV5WDuHoUXpKNAJHMUIDNznNpRSZR8oaC dvNQ== X-Gm-Message-State: AOAM531Q5XqbApcs8YUw6idXbRhnmokxrhCCbSSPeHqWAhzl1F3Bc1V/ Mmk3R6obR9bygoxxA8k8I/D5Y7g9tVV06w== X-Google-Smtp-Source: ABdhPJwf3ZRyfZ29kgYyYuCSj+D1YfrVrMWywZPPGNwdRS5laNKdAet+DlBm5fSf4XhK7RejixH39A== X-Received: by 2002:a9d:4b9c:: with SMTP id k28mr1007784otf.183.1621280361347; Mon, 17 May 2021 12:39:21 -0700 (PDT) Received: from localhost (fixed-187-190-78-172.totalplay.net. [187.190.78.172]) by smtp.gmail.com with ESMTPSA id m189sm2878258oif.45.2021.05.17.12.39.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 12:39:21 -0700 (PDT) From: Felipe Contreras To: notmuch@notmuchmail.org Subject: [PATCH 2/2] ruby: enable garbage collection using talloc Date: Mon, 17 May 2021 14:39:15 -0500 Message-Id: <20210517193915.1220114-3-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: JOMJ2D6XHIWMPZ3GLJSWMHJSEVPUZXLY X-Message-ID-Hash: JOMJ2D6XHIWMPZ3GLJSWMHJSEVPUZXLY 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=1621280371; 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=5P2/OUiLQCVvc90Xe4UO+V/mpq0cLdkbhgIhFy8ZgBs=; b=Zfq4454f7jeQLHnlFr+h8HT+a6NHqmuDoFHHFoLa6aDhcgKKK0JpXpOhSmxWnJgKK+UlNY CCjtZ+CWGZGnhK4iQuoGsZv/kT9D1eRL8+ean5pes7NZqzNOlDtaysxzTL4foxKxlAv4Eb A2zB2kpThE+xA6Wnytxf08kS2ArBHzrvviDVgDaqMVQ0huKILf1+fQulFyPEx01Ol8fOho ZegMwI8Vnp6y0u30avcxwMYNjIiVaF+eq58y1UHCgTa8JPTgmLCETM/vF40J2SRXhZa62z YK9+RtDH4+W35x4IldrF6kEjs6hSv5O3Q2wLKSw5QmXIdQGz9lpi8PZiQAEqiw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1621280371; a=rsa-sha256; cv=none; b=dh7HdHEQ5ixXVrCYlPzIALUeks+2blEGvnmOT1dNAIF/VBFrZkn7HXDgsu4KYUFY7uNwHQ fDRcR8nAGyN93EmMnhR7RUCfvs3XQXg37WeCb2gf05f/KJmYvPPvIP7kncVs0TRDJby/yz BDxaGfL7xitS8QtoJoCh1kpn8Z/UODDKmYOkozwtpH6FYaNf2Weml7Atm3eowD8v8VDa4A 85wNXxI6qCEbPVyQYB+jh8EEt0FazHDW2SG7DzCMObfBY3zTzFtz8WYRt2EWYeTCWKdcM9 tE0SabtKQLuG0djIE6A8o5mCM1M5m0F4W/nKDZcNHG4H/AaJS9SCzHEpE2UbZw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b=vW8f5HxM; 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=vW8f5HxM; 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: 71A0F293DD X-Spam-Score: -0.98 X-Migadu-Scanner: scn0.migadu.com X-TUID: shjUm1uGGXgX We basically steal all the objects from their notmuch parents, therefore they are completely under Ruby's gc control. The order at which these objects are freed does not matter any more, because destroying the database does not destroy all the children objects, since they belong to Ruby now. Signed-off-by: Felipe Contreras --- bindings/ruby/database.c | 2 +- bindings/ruby/defs.h | 11 +++++++---- bindings/ruby/extconf.rb | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c index 66100de2..3737be17 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) = notmuch_rb_object_create (database); + DATA_PTR (self) = notmuch_rb_object_create (database, "notmuch_rb_database"); return self; } diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h index 1413eb72..5cebd5fa 100644 --- a/bindings/ruby/defs.h +++ b/bindings/ruby/defs.h @@ -23,6 +23,7 @@ #include #include +#include extern VALUE notmuch_rb_cDatabase; extern VALUE notmuch_rb_cDirectory; @@ -83,7 +84,7 @@ extern const rb_data_type_t notmuch_rb_tags_type; } while (0) #define Data_Wrap_Notmuch_Object(klass, type, ptr) \ - TypedData_Wrap_Struct ((klass), (type), notmuch_rb_object_create ((ptr))) + TypedData_Wrap_Struct ((klass), (type), notmuch_rb_object_create ((ptr), "notmuch_rb_object: " __location__)) #define Data_Get_Notmuch_Database(obj, ptr) \ Data_Get_Notmuch_Object ((obj), ¬much_rb_database_type, (ptr)) @@ -117,20 +118,22 @@ typedef struct { } notmuch_rb_object_t; static inline void * -notmuch_rb_object_create (void *nm_object) +notmuch_rb_object_create (void *nm_object, const char *name) { - notmuch_rb_object_t *rb_wrapper = malloc (sizeof (*rb_wrapper)); + notmuch_rb_object_t *rb_wrapper = talloc_named_const (NULL, sizeof (*rb_wrapper), name); + if (RB_UNLIKELY (!rb_wrapper)) return NULL; rb_wrapper->nm_object = nm_object; + talloc_steal (rb_wrapper, nm_object); return rb_wrapper; } static inline void notmuch_rb_object_free (void *rb_wrapper) { - free (rb_wrapper); + talloc_free (rb_wrapper); } static inline notmuch_status_t diff --git a/bindings/ruby/extconf.rb b/bindings/ruby/extconf.rb index 161de5a2..d914537c 100644 --- a/bindings/ruby/extconf.rb +++ b/bindings/ruby/extconf.rb @@ -19,6 +19,7 @@ if not ENV['LIBNOTMUCH'] end $LOCAL_LIBS += ENV['LIBNOTMUCH'] +$LIBS += " -ltalloc" # Create Makefile dir_config('notmuch') -- 2.31.1