From: Eric Wong <bofh@yhbt.net>
To: clogger-public@yhbt.net
Subject: [PATCH] switch to TypedData macros for allocation
Date: Tue, 23 Jan 2024 12:57:45 +0000 [thread overview]
Message-ID: <20240123125745.498086-1-bofh@yhbt.net> (raw)
This gives us memsize information and appears to fix a leak
under Ruby 3.3.
---
ext/clogger_ext/clogger.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c
index 8cd40be..9861d70 100644
--- a/ext/clogger_ext/clogger.c
+++ b/ext/clogger_ext/clogger.c
@@ -225,18 +225,28 @@ static void clogger_mark(void *ptr)
rb_gc_mark(c->body);
}
+static size_t memsize(const void *ptr)
+{
+ return sizeof(struct clogger);
+}
+
+static const rb_data_type_t clogger_type = {
+ "clogger",
+ { clogger_mark, RUBY_TYPED_DEFAULT_FREE, memsize, /* reserved */ },
+};
+
static VALUE clogger_alloc(VALUE klass)
{
struct clogger *c;
- return Data_Make_Struct(klass, struct clogger, clogger_mark, -1, c);
+ return TypedData_Make_Struct(klass, struct clogger, &clogger_type, c);
}
static struct clogger *clogger_get(VALUE self)
{
struct clogger *c;
- Data_Get_Struct(self, struct clogger, c);
+ TypedData_Get_Struct(self, struct clogger, &clogger_type, c);
assert(c);
return c;
}
reply other threads:[~2024-01-23 12:57 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/clogger/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240123125745.498086-1-bofh@yhbt.net \
--to=bofh@yhbt.net \
--cc=clogger-public@yhbt.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhbt.net/clogger.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).