about summary refs log tree commit homepage
path: root/ext/posix_mq/posix_mq.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-24 23:24:29 -0800
committerEric Wong <normalperson@yhbt.net>2010-12-24 23:32:19 -0800
commit79583aaa426ac2f0967cb84524b6e17d72499cd5 (patch)
tree5a3ca18a417eda80a56fe7bf9b2c3b56cee8b15a /ext/posix_mq/posix_mq.c
parent31dee76d5ef41ec5524c3e4dfb802db4a7a468ef (diff)
downloadruby_posix_mq-79583aaa426ac2f0967cb84524b6e17d72499cd5.tar.gz
StringValuePtr should already be a sufficient guard.
There are more tests while we're at it, too, and we'll
now raise TypeError instead of ArgumentError when a
POSIX_MQ::Attr is not passed properly.
Diffstat (limited to 'ext/posix_mq/posix_mq.c')
-rw-r--r--ext/posix_mq/posix_mq.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/ext/posix_mq/posix_mq.c b/ext/posix_mq/posix_mq.c
index b634a91..26c4514 100644
--- a/ext/posix_mq/posix_mq.c
+++ b/ext/posix_mq/posix_mq.c
@@ -14,10 +14,6 @@
 #  define NUM2TIMET NUM2INT
 #endif
 
-#ifndef RB_GC_GUARD
-#  define RB_GC_GUARD(v) (*(volatile VALUE *)&(v))
-#endif
-
 #include <time.h>
 #include <mqueue.h>
 #include <fcntl.h>
@@ -303,17 +299,21 @@ static struct posix_mq *get(VALUE self, int need_valid)
         return mq;
 }
 
+static void check_struct_type(VALUE astruct)
+{
+        if (CLASS_OF(astruct) == cAttr)
+                return;
+        astruct = rb_inspect(astruct);
+        rb_raise(rb_eTypeError, "not a POSIX_MQ::Attr: %s",
+                 StringValuePtr(astruct));
+}
+
 /* converts the POSIX_MQ::Attr astruct into a struct mq_attr attr */
 static void attr_from_struct(struct mq_attr *attr, VALUE astruct, int all)
 {
         VALUE *ptr;
 
-        if (CLASS_OF(astruct) != cAttr) {
-                RB_GC_GUARD(astruct) = rb_inspect(astruct);
-                rb_raise(rb_eArgError, "not a POSIX_MQ::Attr: %s",
-                         RSTRING_PTR(astruct));
-        }
-
+        check_struct_type(astruct);
         ptr = RSTRUCT_PTR(astruct);
 
         attr->mq_flags = NUM2LONG(ptr[0]);
@@ -369,10 +369,10 @@ static VALUE init(int argc, VALUE *argv, VALUE self)
                 else if (oflags == sym_rw)
                         x.oflags = O_CREAT|O_RDWR;
                 else {
-                        RB_GC_GUARD(oflags) = oflags;
+                        oflags = rb_inspect(oflags);
                         rb_raise(rb_eArgError,
                                  "symbol must be :r, :w, or :rw: %s",
-                                 RSTRING_PTR(oflags));
+                                 StringValuePtr(oflags));
                 }
                 break;
         case T_BIGNUM:
@@ -413,9 +413,7 @@ static VALUE init(int argc, VALUE *argv, VALUE self)
         case T_NIL:
                 break;
         default:
-                RB_GC_GUARD(attr) = rb_inspect(attr);
-                rb_raise(rb_eArgError, "attr must be a POSIX_MQ::Attr: %s",
-                         RSTRING_PTR(attr));
+                check_struct_type(attr);
         }
 
         mq->des = (mqd_t)xopen(&x);