posix_mq RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: ruby-posix-mq@bogomips.org
Subject: [PATCH] TypedData C-API conversion
Date: Sat, 18 Mar 2017 08:27:10 +0000	[thread overview]
Message-ID: <20170318082710.8101-1-e@80x24.org> (raw)

This provides some extra type safety if combined with other
C extensions, as well as allowing us to account for memory usage of
the HTTP parser in ObjectSpace.

This requires Ruby 1.9.3+ and has remained a stable API since
then.  This will become officially supported when Ruby 2.3.0 is
released later this month.

This API has only been documented in doc/extension.rdoc (formerly
README.EXT) in the Ruby source tree since April 2015, r50318
---
 ext/posix_mq/posix_mq.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/ext/posix_mq/posix_mq.c b/ext/posix_mq/posix_mq.c
index 55ec51e..83e9e58 100644
--- a/ext/posix_mq/posix_mq.c
+++ b/ext/posix_mq/posix_mq.c
@@ -317,11 +317,22 @@ static void _free(void *ptr)
 	xfree(ptr);
 }
 
+static size_t memsize(const void *ptr)
+{
+	return sizeof(struct posix_mq);
+}
+
+static const rb_data_type_t mqtype = {
+	"posix_mq",
+	{ mark, _free, memsize, /* reserved */ },
+	/* parent, data, [ flags ] */
+};
+
 /* automatically called at creation (before initialize) */
 static VALUE alloc(VALUE klass)
 {
 	struct posix_mq *mq;
-	VALUE rv = Data_Make_Struct(klass, struct posix_mq, mark, _free, mq);
+	VALUE rv = TypedData_Make_Struct(klass, struct posix_mq, &mqtype, mq);
 
 	mq->des = MQD_INVALID;
 	mq->autoclose = 1;
@@ -341,7 +352,7 @@ static struct posix_mq *get(VALUE self, int need_valid)
 {
 	struct posix_mq *mq;
 
-	Data_Get_Struct(self, struct posix_mq, mq);
+	TypedData_Get_Struct(self, struct posix_mq, &mqtype, mq);
 
 	if (need_valid && mq->des == MQD_INVALID)
 		rb_raise(rb_eIOError, "closed queue descriptor");
-- 
EW


                 reply	other threads:[~2017-03-18  8:27 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/ruby_posix_mq/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170318082710.8101-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=ruby-posix-mq@bogomips.org \
    /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/ruby_posix_mq.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).