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 KJVXGHM7oGCT5QAAgWs5BA (envelope-from ) for ; Sat, 15 May 2021 23:21:55 +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 0Df9E3M7oGC8FwAAB5/wlQ (envelope-from ) for ; Sat, 15 May 2021 21:21:55 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (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 B060C2D142 for ; Sat, 15 May 2021 23:21:54 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 8DF092905D; Sat, 15 May 2021 17:21:29 -0400 (EDT) Received: from mail-oo1-xc2b.google.com (mail-oo1-xc2b.google.com [IPv6:2607:f8b0:4864:20::c2b]) by mail.notmuchmail.org (Postfix) with ESMTPS id C2A5729054 for ; Sat, 15 May 2021 17:21:17 -0400 (EDT) Received: by mail-oo1-xc2b.google.com with SMTP id o66-20020a4a44450000b029020d44dea886so658328ooa.5 for ; Sat, 15 May 2021 14:21:17 -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=yV1yCy/ynOdVk3sNwGUl3q9WK/nWiZLR5w6Je211cYk=; b=hDzrbTJ1ERkfwnVvLRPyXb0wELsT7rtrXEs9NisFta0rt3p84qToG3/w303bxTwMZU 7PBQ+t+Cth5G4Qv3yni+lUe0d8q+UpkrO5YeoP2sa38yYyog6yXsco/jPiPITUoV+XmE a1qEDFA/uM0RYQmDtydxpwPy39ogCA2sSCgwh7pV95u0Ih0/lOxhC8OfTduOfQEcZU7s NOkRgacxYdvhl0JkOobZjPip5jMI13PUkdq9VeMMSTPoA1pNBLD6Ui3OyntgHABNSL1k o1J+Qqnld0Z/7GfRhPp+auZz1Yol4zLcl+w3yw9nVNMKC1ZhncSoiX833kvtk2wi2sL+ mwZQ== 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=yV1yCy/ynOdVk3sNwGUl3q9WK/nWiZLR5w6Je211cYk=; b=oP5zCTwuVGIWfgo2rJB/+5/FOILEe87FF9rgCXZ0c8cKgYWhgaEYoh7OfkTo/JS0AE jKrg+qJVBOAX3TZUUTX7rx2XK4oKMUwsh7n6TesTrfYPuNuQGHl2Y1cBQ01WB7hob8BT +eMywd49Us2E2L0Eg66+DWeeIm93u8V79WDCuipepXFLoMRW498WePaFgLtkOTexZQ/u +9BQMHOtafR4uRRKsIoL71QRYQ8VNJRBBBA/peMP2P5SYvJTf6jKiYT5YzEyb+XHZTde qzSNli2twP7da/9XSdjMqjcA4+4GRj27zNocgr8zsnYXjQHWYfP81K/NOQpNcmgmodw9 XYdw== X-Gm-Message-State: AOAM530+lsAXOYTlbIjKKk6RCL1rv3XmGRu9/7q9niF/IQht9KIjH34e Hb41yzsfDNe9zW2EORmJv832SrzpfCxCYg== X-Google-Smtp-Source: ABdhPJz5TweP6lsHDsBIp4lhoTmudPeTM6gKGRAMNNRmo76QBsQDql0G9wIvtUB26U9sw0fr9kUmlA== X-Received: by 2002:a4a:b3c4:: with SMTP id q4mr30242575ooo.14.1621113673044; Sat, 15 May 2021 14:21:13 -0700 (PDT) Received: from localhost (fixed-187-189-165-231.totalplay.net. [187.189.165.231]) by smtp.gmail.com with ESMTPSA id 129sm2181700ooq.34.2021.05.15.14.21.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 May 2021 14:21:12 -0700 (PDT) From: Felipe Contreras To: notmuch@notmuchmail.org Subject: [PATCH v3 5/7] ruby: move towards more modern RTypedData Date: Sat, 15 May 2021 16:21:01 -0500 Message-Id: <20210515212103.1001295-6-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210515212103.1001295-1-felipe.contreras@gmail.com> References: <20210515212103.1001295-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Message-ID-Hash: 3Y7P6VSLIY47O7XMDQDPIW5UQ5PUOOSE X-Message-ID-Hash: 3Y7P6VSLIY47O7XMDQDPIW5UQ5PUOOSE 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 , Austin Clements , Tomi Ollila , Ludovic LANGE , Daniel Kahn Gillmor 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=1621113714; 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=LSPwHerPGJErdDcw+jH49EQW6yZJCmK0aMf//dYGtaI=; b=mKiJYaD75+Zi8jXANvD5/doMdBNaQq2XclN2VePGyvUO61eURVkX+to+EsEBkYgMyRVrG8 jT4CnwV6ORIobSeZueBgsfEQl0B1P8qqqeFYfNp3xIkVNpCLjuxNomWRf7PDTHoACNXzON m8GAbQDn+ovO/MmdAeQxoAgRoyOuo9k8vaCmBdXvB4wEIEu8NUa5vOSCrna1eGPQX0nqNS OHQPLvtelUlw4UxhzsUkPK6elG/doTbFMvTRG7RGNjsIsC2QPlxOVukDyWa4CGP2xMT1aj Bwd+uD2HFe8meEpl2yK4UEE6oGpxOxBDYPoxbG+8iP8DHQTWlWS+x1jLlpG32Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1621113714; a=rsa-sha256; cv=none; b=UgU1CVI5ZVoa1VOopQlUruHDtuL/Y6PW7uuOosoivebrS2VUklLwfH3Np2xqPIkEBGutVN l46zSHBKdz/LGRy5WIYdh2/tFXIAsWBcrB8Bh4J0jpAzEMxOsD/gYc+glJUzVNuYPXScZG iuFNIxJBxyEKoQLOfm9/hXOO96tC3FnAmquSec6c4NnSYEMbsH4jlu0gYDDpUlj1N+YFCU 3khnGtynrXBzrdheP3vd2nhHiVLITdGTkdBT08LlEb6A+z7AIdG3k8PdwXC0uMSr1TjSuL 1cDNDo6NtGi4lbiUDst/iOMFYNHqnFwqv99kqscjXrriCbdjX5v/nI+FUNeMxg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b=hDzrbTJ1; 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 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -0.94 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b=hDzrbTJ1; 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 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: B060C2D142 X-Spam-Score: -0.94 X-Migadu-Scanner: scn0.migadu.com X-TUID: WhvVeUjSf4XW Virtually the whole ruby core moved from RData to RTypeData, let's do so ourselves too. Basically the information typically passed through Data_Wrap_Struct is now stored in a struct rb_data_type_t (mark and free functions). This has the advantage that more information can be easily added, like the name of the type, a custom data ponter, and more. Data_Wrap_Struct is replaced with TypedData_Wrap_Struct, and the information is stored in a struct rb_data_type_t, rather than passed as arguments. Check_Type is replaced with Check_TypedStruct, which is a wrapper for rb_check_typeddata (with casts). #define Check_TypedStruct(v, t) \ rb_check_typeddata(RBIMPL_CAST((VALUE)(v)), (t)) We can use rb_check_typeddata directly, just like we use rb_data_object_get directly. Signed-off-by: Felipe Contreras --- bindings/ruby/database.c | 2 +- bindings/ruby/defs.h | 6 ++++-- bindings/ruby/init.c | 4 ++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c index b9ad3373..bb4273e6 100644 --- a/bindings/ruby/database.c +++ b/bindings/ruby/database.c @@ -74,7 +74,7 @@ notmuch_rb_database_initialize (int argc, VALUE *argv, VALUE self) mode = NOTMUCH_DATABASE_MODE_READ_ONLY; } - Check_Type (self, T_DATA); + rb_check_typeddata (self, ¬much_rb_object_type); if (create) ret = notmuch_database_create (path, &database); else diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h index fcf1ea39..6dbaa85d 100644 --- a/bindings/ruby/defs.h +++ b/bindings/ruby/defs.h @@ -55,9 +55,11 @@ extern ID ID_db_mode; # define RSTRING_PTR(v) (RSTRING((v))->ptr) #endif /* !defined (RSTRING_PTR) */ +extern const rb_data_type_t notmuch_rb_object_type; + #define Data_Get_Notmuch_Object(obj, ptr) \ do { \ - (ptr) = rb_data_object_get ((obj)); \ + (ptr) = rb_check_typeddata ((obj), ¬much_rb_object_type); \ if (RB_UNLIKELY (!(ptr))) { \ VALUE cname = rb_class_name (CLASS_OF ((obj))); \ rb_raise (rb_eRuntimeError, "%"PRIsVALUE" object destroyed", cname); \ @@ -65,7 +67,7 @@ extern ID ID_db_mode; } while (0) #define Data_Wrap_Notmuch_Object(klass, ptr) \ - Data_Wrap_Struct ((klass), NULL, NULL, (ptr)) + TypedData_Wrap_Struct ((klass), ¬much_rb_object_type, (ptr)) #define Data_Get_Notmuch_Database(obj, ptr) \ Data_Get_Notmuch_Object ((obj), (ptr)) diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c index 819fd1e3..f3b2e5b1 100644 --- a/bindings/ruby/init.c +++ b/bindings/ruby/init.c @@ -46,6 +46,10 @@ ID ID_call; ID ID_db_create; ID ID_db_mode; +const rb_data_type_t notmuch_rb_object_type = { + .wrap_struct_name = "notmuch_object", +}; + /* * Document-module: Notmuch * -- 2.31.1