summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-12 22:04:24 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-12 22:04:24 +0000
commit9941f348e056a5e717cb943cee37ba8ba2396e6f (patch)
tree51bb3531e550fa93ca13faa06ce38648f303a45a
parentddf2558a167652cfec6a901b2116b832221e6e83 (diff)
accept_nonblock: favor rb_hash_lookup2 to avoid Hash#default
* ext/socket/init.c (rsock_s_accept_nonblock): use rb_hash_lookup2 * ext/openssl/ossl_ssl.c (get_no_exception): new function (ossl_ssl_accept_nonblock): use get_no_exception (ossl_ssl_read_internal): ditto (ossl_ssl_write_nonblock): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--ext/openssl/ossl_ssl.c26
-rw-r--r--ext/socket/init.c2
3 files changed, 24 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index d992d96..6450be1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Fri Mar 13 07:02:20 2015 Eric Wong <e@80x24.org>
+
+ * ext/socket/init.c (rsock_s_accept_nonblock): use rb_hash_lookup2
+ * ext/openssl/ossl_ssl.c (get_no_exception): new function
+ (ossl_ssl_accept_nonblock): use get_no_exception
+ (ossl_ssl_read_internal): ditto
+ (ossl_ssl_write_nonblock): ditto
+ [ruby-core:68511]
+
Fri Mar 13 07:01:38 2015 Eric Wong <e@80x24.org>
* ext/openssl/ossl_ssl.c: predefine wait_*able symbols
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index 496d948..1a67d35 100644
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -1369,6 +1369,14 @@ ossl_ssl_accept(VALUE self)
return ossl_start_ssl(self, SSL_accept, "SSL_accept", 0, 0);
}
+static int
+get_no_exception(VALUE opts)
+{
+ if (!NIL_P(opts) && Qfalse == rb_hash_lookup2(opts, sym_exception, Qundef))
+ return 1;
+ return 0;
+}
+
/*
* call-seq:
* ssl.accept_nonblock([options]) => self
@@ -1394,13 +1402,11 @@ ossl_ssl_accept(VALUE self)
static VALUE
ossl_ssl_accept_nonblock(int argc, VALUE *argv, VALUE self)
{
- int no_exception = 0;
+ int no_exception;
VALUE opts = Qnil;
rb_scan_args(argc, argv, "0:", &opts);
-
- if (!NIL_P(opts) && Qfalse == rb_hash_aref(opts, sym_exception))
- no_exception = 1;
+ no_exception = get_no_exception(opts);
ossl_ssl_setup(self);
return ossl_start_ssl(self, SSL_accept, "SSL_accept", 1, no_exception);
@@ -1411,15 +1417,13 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
{
SSL *ssl;
int ilen, nread = 0;
- int no_exception = 0;
+ int no_exception;
VALUE len, str;
rb_io_t *fptr;
VALUE opts = Qnil;
rb_scan_args(argc, argv, "11:", &len, &str, &opts);
-
- if (!NIL_P(opts) && Qfalse == rb_hash_aref(opts, sym_exception))
- no_exception = 1;
+ no_exception = get_no_exception(opts);
ilen = NUM2INT(len);
if(NIL_P(str)) str = rb_str_new(0, ilen);
@@ -1582,12 +1586,10 @@ ossl_ssl_write_nonblock(int argc, VALUE *argv, VALUE self)
{
VALUE str;
VALUE opts = Qnil;
- int no_exception = 0;
+ int no_exception;
rb_scan_args(argc, argv, "1:", &str, &opts);
-
- if (!NIL_P(opts) && Qfalse == rb_hash_aref(opts, sym_exception))
- no_exception = 1;
+ no_exception = get_no_exception(opts);
return ossl_ssl_write_internal(self, str, 1, no_exception);
}
diff --git a/ext/socket/init.c b/ext/socket/init.c
index b94b250..50d3f86 100644
--- a/ext/socket/init.c
+++ b/ext/socket/init.c
@@ -516,7 +516,7 @@ rsock_s_accept_nonblock(int argc, VALUE *argv, VALUE klass, rb_io_t *fptr,
rb_scan_args(argc, argv, "0:", &opts);
- if (!NIL_P(opts) && Qfalse == rb_hash_aref(opts, sym_exception))
+ if (!NIL_P(opts) && Qfalse == rb_hash_lookup2(opts, sym_exception, Qundef))
ex = 0;
rb_secure(3);