* [PATCH] switch to TypedData macros for allocation
@ 2024-01-23 12:57 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2024-01-23 12:57 UTC (permalink / raw)
To: clogger-public
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;
}
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2024-01-23 12:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-23 12:57 [PATCH] switch to TypedData macros for allocation Eric Wong
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).