From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id OANtFiXRh2DA6wAAgWs5BA (envelope-from ) for ; Tue, 27 Apr 2021 10:53:57 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id UHsdEiXRh2C5LQAAB5/wlQ (envelope-from ) for ; Tue, 27 Apr 2021 08:53:57 +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 74EAA22078 for ; Tue, 27 Apr 2021 10:53:56 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 50A9B27168; Tue, 27 Apr 2021 04:53:52 -0400 (EDT) Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) by mail.notmuchmail.org (Postfix) with ESMTPS id 63DD61FBD2 for ; Tue, 27 Apr 2021 04:53:49 -0400 (EDT) Received: by mail-oo1-xc33.google.com with SMTP id i20-20020a4a8d940000b02901bc71746525so12917576ook.2 for ; Tue, 27 Apr 2021 01:53:49 -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:mime-version :content-transfer-encoding; bh=TInzu2zyRdfLX5aFLHzCFGkgtYarD3WGL+Y26thHM4A=; b=I/RieiOdgVd7/o90XVsvE8CHCjr0IsCcl4K6NdVNljrY0+fPxkueo9kxFYs/sGB9kL 8QzrZtifcNu3SGi47hueqD/YddDALWYH5gq/4aiKryn9Le7gQsBdyOiYyUuukc1aBZ9q e7bR65Lmo7H2xks/vq8RwEUkNuQpgeGc5e+0naMV/3QwA9OlKvRBZGbQ6JDZvTv2puhW 1u1tfqUQF4SWvnpiwd/b4p3Kj/t7OZ6GzcZyEjtNxcvJrsrFsF87xrJlh73UnmMqnHk/ TVIPXYsyg7TTYYHde6UiEnE/xMAqKeJT1hNgjriS4XAFY+e63UVE5mcX3vU8Cj/wTyqW g/hg== 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:mime-version :content-transfer-encoding; bh=TInzu2zyRdfLX5aFLHzCFGkgtYarD3WGL+Y26thHM4A=; b=Pt+zLKxqmK7XT9zrExEg2/ea5bF9hV8eYAwtL+zr6/r/z5ehY/2LdpzwwG3XGFoI+e tMLxx3TwNc0iusvpcTcU7A8kPqE0iC8JNVDvqoYTaCHq2pIFBJBII/74l/iUge5Br7c1 8KAsGbqFnssamOyPeagZ4Fhx92VWiMRrUx9tQ/P4NhlOfMFZnCwQIglSWcULAmDFNHWJ CweV+yiCAQ5tsNni22ZxQcK/xN3NcXGCohvV8vBh5zqazaRj5IlDLuu6OjOEeQnNubYg 0lv59tU6v1JzpvIyX6534Y1LdmVwq9ZYGjLA+5vrJwfu+A3YSHW+wPD6OA0A9TgWet7n p+IQ== X-Gm-Message-State: AOAM533K62go3Xhy84bc9yBNHSMIjgMRyNuT2YlxtIjordm8WUNhj1jF fR0SXGj+5kv2F37EFEdOxCTQP+l7UykMdQ== X-Google-Smtp-Source: ABdhPJwXTRDl9xpXwmnhE+ei5ZxhqLTl1pvTHmWpRd9VeoHV2otzhiAh+o0m78+WsWPhExuD5VpfMw== X-Received: by 2002:a4a:3419:: with SMTP id b25mr857152ooa.18.1619513628102; Tue, 27 Apr 2021 01:53:48 -0700 (PDT) Received: from localhost (fixed-187-190-78-172.totalplay.net. [187.190.78.172]) by smtp.gmail.com with ESMTPSA id v128sm689000oia.44.2021.04.27.01.53.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Apr 2021 01:53:47 -0700 (PDT) From: Felipe Contreras To: notmuch@notmuchmail.org Subject: [RFC PATCH] Attempt to reactive Ruby gc Date: Tue, 27 Apr 2021 03:53:43 -0500 Message-Id: <20210427085343.2300-1-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Message-ID-Hash: BD66D356MRISKXXZZEZ2LDBVPIM4Q3AL X-Message-ID-Hash: BD66D356MRISKXXZZEZ2LDBVPIM4Q3AL 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: Ali Polatel 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=1619513636; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=8XmtwqvKcIxbBB+tuNqWgPl3ZPcO/oS7qvlY9z1MjJ4=; b=ocQy3SuXZwMfTL1Rq0ksUACRtt6saPWA6c40JZQIkXaYB7Fa+883QHBMnz66mXdYNckQr7 ovh2iVuWbLDKUnFLnoTCWUGNUVighFCMppLS16VRDTJxzSg0UAfKQg1cC6WovlJhbHzWu/ qjiCSC5hnyVLi52OShdGsVRRWO8VHLkTLW/A9mPXqkZGSIZ+2A5vxSycdB79pfukBBMiVo Xr92jJ74Ts1gJl+Hrpq63nNTstHumZDR5OSD0qMYWfPw4u5k4MhZn5/vknNA70I6w0FfF3 OUw1XDH0dS1K8kzBGxffjMWxGIj3PbuqcmnFMLYzwiiaNsk5JqLd7mKziW/dtw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1619513636; a=rsa-sha256; cv=none; b=pcVb6FxZqCNJdB1tMaFDgYPF2JxO6mYsiAWv6azD9Xsrfgl8qV0IjI6neScEJI3bRDTDhc WQbSRgCuiwksuSr7TmpUr6GmCaBqZlPui6PAFQNofH4hvrsMAfgcL8M8iEtiBGjIciuMmP euz+8u+mRIfR4tRyf4PqEv2X85PyCle+bq7adTpfXd2Lyplye007nfeQDhXMW7iEp8e09U CNS8VhrJAftIegfzaj3BgnnCg45hyIKx8kid6OHw85Cs9f1XIjtVUU7Wr+toQw6IF0LCqL n8K+zoqdJOasGikZn2VXRCjs4rMzRoVLcav3jvfcCXYDEHdYvqIHPpkC5Ywicw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b="I/RieiOd"; 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: -1.04 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b="I/RieiOd"; 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: 74EAA22078 X-Spam-Score: -1.04 X-Migadu-Scanner: scn0.migadu.com X-TUID: w1wKNGNqSyAa Commit c7893408 (ruby: Kill garbage collection related cruft., 2010-05-26) removed garbage collection because the order of objects freed couldn't be ensured in Ruby. However, we can use talloc for reference counting and thus preventing Ruby from destroying the objects. First we create a wrapper object with no talloc parent, which will be owned by the Ruby object (e.g. Notmuch::Thread). The notmuch object (notmuch_thread_t) will have two parents then (notmuch_threads_t and Notmuch::Thread). If Ruby destroys the other parent first (notmuch_threads_t), that still doesn't destroy the object, since we still own a reference (from Notmuch::Thread). It's only when both are destroyed that the object is actually freed. Signed-off-by: Felipe Contreras --- bindings/ruby/defs.h | 24 +++++++++++++++++++++++- bindings/ruby/extconf.rb | 1 + bindings/ruby/thread.c | 6 +++--- bindings/ruby/threads.c | 2 +- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h index 48544ca2..56a70a4f 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; @@ -50,6 +51,25 @@ extern ID ID_call; extern ID ID_db_create; extern ID ID_db_mode; +typedef struct { + void *pointer; +} notmuch_rb_object_t; + +static inline void +notmuch_rb_object_free (void *object) +{ + talloc_free (object); +} + +static inline VALUE +notmuch_rb_object_wrap (VALUE klass, void *ptr) +{ + notmuch_rb_object_t *object = talloc (NULL, typeof (*object)); + object->pointer = ptr; + talloc_reference (object, ptr); + return Data_Wrap_Struct (klass, NULL, ¬much_rb_object_free, object); +} + /* RSTRING_PTR() is new in ruby-1.9 */ #if !defined(RSTRING_PTR) # define RSTRING_PTR(v) (RSTRING((v))->ptr) @@ -105,10 +125,12 @@ extern ID ID_db_mode; #define Data_Get_Notmuch_Thread(obj, ptr) \ do { \ + notmuch_rb_object_t *object; \ Check_Type ((obj), T_DATA); \ if (DATA_PTR ((obj)) == NULL) \ rb_raise (rb_eRuntimeError, "thread destroyed"); \ - Data_Get_Struct ((obj), notmuch_thread_t, (ptr)); \ + Data_Get_Struct ((obj), typeof (*object), object); \ + (ptr) = object->pointer; \ } while (0) #define Data_Get_Notmuch_Message(obj, ptr) \ 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') diff --git a/bindings/ruby/thread.c b/bindings/ruby/thread.c index 9b295981..5705b556 100644 --- a/bindings/ruby/thread.c +++ b/bindings/ruby/thread.c @@ -28,11 +28,11 @@ VALUE notmuch_rb_thread_destroy (VALUE self) { - notmuch_thread_t *thread; + notmuch_rb_object_t *object; - Data_Get_Notmuch_Thread (self, thread); + Data_Get_Struct (self, typeof (*object), object); - notmuch_thread_destroy (thread); + notmuch_rb_object_free (object); DATA_PTR (self) = NULL; return Qnil; diff --git a/bindings/ruby/threads.c b/bindings/ruby/threads.c index ed403a8f..302ffd91 100644 --- a/bindings/ruby/threads.c +++ b/bindings/ruby/threads.c @@ -53,7 +53,7 @@ notmuch_rb_threads_each (VALUE self) for (; notmuch_threads_valid (threads); notmuch_threads_move_to_next (threads)) { thread = notmuch_threads_get (threads); - rb_yield (Data_Wrap_Struct (notmuch_rb_cThread, NULL, NULL, thread)); + rb_yield (notmuch_rb_object_wrap (notmuch_rb_cThread, thread)); } return self; -- 2.31.0