From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 2M6CMFo7oGCd5wAAgWs5BA (envelope-from ) for ; Sat, 15 May 2021 23:21:30 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 6HkILFo7oGBVAwAAbx9fmQ (envelope-from ) for ; Sat, 15 May 2021 21:21:30 +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)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 2E911B6F4 for ; Sat, 15 May 2021 23:21:30 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 2D9CD28D05; Sat, 15 May 2021 17:21:16 -0400 (EDT) Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by mail.notmuchmail.org (Postfix) with ESMTPS id B019227FE5 for ; Sat, 15 May 2021 17:21:12 -0400 (EDT) Received: by mail-ot1-x332.google.com with SMTP id r26-20020a056830121ab02902a5ff1c9b81so2338187otp.11 for ; Sat, 15 May 2021 14:21:12 -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=BzPwKdsNtCV8VwuEuzMPR5wX05ASoy/oJ+pEqswKWhQ=; b=ltqfWGKjCbPm5whCSnZl2WId/NJbrdpYw575ToH9yaaApo9vaysjx+oxYuG3NbhU3h fdDZ8gVZaGbfkW5go5Mc4OlGozvrWlokc4OKH3by0jM9qn6B7VsRkL19WaQNom4NDAUO Ve7CZwqe925sLA4EkXc4IgAVFafKlY6NrttKpSKFuKdmF/+X81FTgXhDfK/SYIt7qJ8K z6Yuwy9slrlG4qeEO6jPkEGobLKbTn3NX1G5hEa0MRWs5lhoeWErsrW6Qz0aaLdvmIkq T2iroLhdkpLHNKc5KakcQM6dyFwj2uRMcP9k9zkGRqW4ttBiHhIIGu5wpSGPjfyBTEKt xvUw== 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=BzPwKdsNtCV8VwuEuzMPR5wX05ASoy/oJ+pEqswKWhQ=; b=TRWtI4yA7NWmyly5yJrs6gWnHM9cNK9HeKM18EdFeG/TGdb8IBPDVpHwbSAuPWNvkI Os3B9JDHfP9G08jt42v6hp4DiHb8elMzvwpg4bcLntOPRIeF8dCfnMsaUs2D2Rqrl7AT 0P3sL5f0QJwvhh6k6v3QpQfcrB3SqAAGGFQ7vIca0wjSvNeyY2+AUGJpJJ5TEWHpaBGQ wuVZ4QsOxjMueR1u5BSLBGfvGHkYHliHdsfPiFGKtsZuOYHiA1gq8GyPZWgDZBGUYegt 6JdrD2mAZg6xRNtdeZvGi1T9OtmmSKgBSLUrP+LEchq9vrhipsrG6lJ057GfxrqtyyFp Rc5Q== X-Gm-Message-State: AOAM531N9b1NjaFg/mwLoe6+wfeQmch0Rn9pDQVWmB7WWT5ps94KDqxs hkvH/cQwhQEU3iuw0MPk4Nlb7VdPyI0V3Q== X-Google-Smtp-Source: ABdhPJy869C3NGz4aqiVMRQf4ZyqA3BIrusEtPB1kOThlMlBz2xoiMKM4N9csuZQX6fYL/M/6DOelQ== X-Received: by 2002:a05:6830:4103:: with SMTP id w3mr40599230ott.27.1621113664870; Sat, 15 May 2021 14:21:04 -0700 (PDT) Received: from localhost (fixed-187-189-165-231.totalplay.net. [187.189.165.231]) by smtp.gmail.com with ESMTPSA id k18sm568573otj.42.2021.05.15.14.21.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 May 2021 14:21:04 -0700 (PDT) From: Felipe Contreras To: notmuch@notmuchmail.org Subject: [PATCH v3 0/7] ruby: object cleanups Date: Sat, 15 May 2021 16:20:56 -0500 Message-Id: <20210515212103.1001295-1-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Message-ID-Hash: TVDKJ6E5FVN62SJKL6KOCWRZGLWRDANE X-Message-ID-Hash: TVDKJ6E5FVN62SJKL6KOCWRZGLWRDANE 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=1621113690; 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=M+7bFz5sAYcoalIqDp1R87EVEnuIDnglfdH4FVKps5o=; b=CTX5Fj4lcX80wPU6Rp+ViX8FxAnGiGk5mXDlxNqTjEPvrDeUWH9086lQvH57P+4Nz4JIUE tyzFBpeW8RLGxOqeBExoC3m3lJ9Ou4MIgj4u3mMsuiylgCzzuzvRldx76G+3bYh9PydWuM C4OONK3RyIwpt9AccPV9UenQ+EiXpwpk30uqVZx9zv1T/nQCN6BlZQt+JoVYuy0E8Hin9m 0c5f/Ml963Y5NSKLuyNEtw6vZmWOkNVU8WWryijUF69e2AYIqNsAaMdJIHmAvCWFwgO9Cm 4IxFhiqiKLTiZk8izbXdho8Snhmtr1K/bl4k4oMJTov9j+PbXy3wf291uGjLXg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1621113690; a=rsa-sha256; cv=none; b=QglJIhz6ee4FZpP2Sho3mCrKQy3pZA1881Ze0aD74oBzZ5eWJ9y7xojRtbKTTCI7c0VBsd 5SjbxjR57Da9s1EchXcCHFXrwkIn1pYO64owhAYaP0vz5qeYoz2MsCV2U8ALOOMsAfFCK7 lIP4WcTUgHR5BXAXMZd606ZZMNIt4L4pwe81cb276jaaRzVG65c97SyRCSwRdoG3Ra0fX4 Goqs8mo90g7o+mz05YPtGgcK7zHeRftOt6YDqgfQFGfd8CYWYHo4QrK+mATrC7rnzZUVyS YAFaFU2ZLZvQK8tjeEZinb7kBLCM0RsNtwXgdgcBpvYbmrSdonCV0n6RiiEblw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b=ltqfWGKj; 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.97 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b=ltqfWGKj; 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: 2E911B6F4 X-Spam-Score: -0.97 X-Migadu-Scanner: scn0.migadu.com X-TUID: BcbOoX9rTfCj This is basically the same as v2, except I updated the commit messages as David Bremner suggested, and I added a minor comment. Felipe Contreras (7): ruby: simplify data get helper ruby: fetch class name in case of error ruby: add unlikely hint ruby: create Data_Wrap_Notmuch_Object helper ruby: move towards more modern RTypedData ruby: add all data types ruby: new notmuch_rb_object_destroy() helper bindings/ruby/database.c | 22 ++++++--------- bindings/ruby/defs.h | 59 +++++++++++++++++++++++++++++---------- bindings/ruby/directory.c | 11 ++------ bindings/ruby/filenames.c | 7 +---- bindings/ruby/init.c | 21 ++++++++++++++ bindings/ruby/message.c | 13 +++------ bindings/ruby/messages.c | 11 ++------ bindings/ruby/query.c | 11 ++------ bindings/ruby/tags.c | 7 +---- bindings/ruby/thread.c | 13 +++------ bindings/ruby/threads.c | 9 ++---- 11 files changed, 96 insertions(+), 88 deletions(-) Range-diff against v2: 1: 9c15fc44 < -: -------- ruby: add missing Data_Get_Notmuch helpers 2: c9d840d3 < -: -------- ruby: improve all Data_Get_Notmuch_* helpers 3: 299b2be1 < -: -------- ruby: improve general data get helper 4: 19fa26de ! 1: a1dc3960 ruby: simplify data get helper @@ Metadata ## Commit message ## ruby: simplify data get helper - The type is not actually needed. + Data_Get_Struct is nothing but a macro that calls + rb_data_object_get with a cast (unnecessary in C). + + #define Data_Get_Struct(obj, type, sval) \ + ((sval) = RBIMPL_CAST((type*)rb_data_object_get(obj))) + + We can use rb_data_object_get directly, and this way we don't need to + pass the type, which is unnecessary information. Signed-off-by: Felipe Contreras 5: 1872c4b5 = 2: 2f88cf0a ruby: fetch class name in case of error 6: b46bcac8 = 3: 6671b155 ruby: add unlikely hint 7: 1bfa0334 = 4: 87222fd0 ruby: create Data_Wrap_Notmuch_Object helper 8: a9b7ac45 ! 5: 1a3866c1 ruby: move towards more modern RTypedData @@ Metadata ## Commit message ## ruby: move towards more modern RTypedData + 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 ## 9: e2116d5d = 6: b3366e12 ruby: add all data types 10: f6660e5b ! 7: 05795b05 ruby: new notmuch_rb_object_destroy() helper @@ Metadata ## Commit message ## ruby: new notmuch_rb_object_destroy() helper + The struct used to store the types (rb_data_type_t) contains a "data" + field where we can store whatever we want. I use that field to store a + pointer to the corresponding destroy function. For example + notmuch_rb_database_type contains a pointer to notmuch_database_destroy. + + I cast that pointer as a notmuch_status_t (func*)(void *) and call + that function passing the internal object (e.g. notmuch_database_t). + Using the rb_data_type_t data we can call the correct notmuch destroy function. + Therefore this: + + ret = ((notmuch_status_t (*)(void *)) type->data) (nm_object); + + Is effectively the same as this: + + ret = notmuch_database_destroy (database); + + The advantage of doing it this way is that much less code is necesary + since each rb_data_type_t has the corresponding destroy function stored + in it. + Signed-off-by: Felipe Contreras ## bindings/ruby/database.c ## @@ bindings/ruby/defs.h: extern const rb_data_type_t notmuch_rb_tags_type; + + Data_Get_Notmuch_Object (rb_object, type, nm_object); + ++ /* Call the corresponding notmuch_*_destroy function */ + ret = ((notmuch_status_t (*)(void *)) type->data) (nm_object); + DATA_PTR (rb_object) = NULL; + -- 2.31.1