From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS5577 94.242.192.0/18 X-Spam-Status: No, score=-1.0 required=3.0 tests=AWL,BAYES_00, RCVD_IN_BRBL_LASTEXT,RCVD_IN_XBL shortcircuit=no autolearn=no version=3.3.2 X-Original-To: spew@80x24.org Received: from 80x24.org (azura.nullbyte.me [94.242.198.164]) by dcvr.yhbt.net (Postfix) with ESMTP id ADAA01F4EE for ; Wed, 27 May 2015 00:43:46 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH] openssl: use RB_GC_GUARD instead of volatile Date: Wed, 27 May 2015 00:43:41 +0000 Message-Id: <1432687421-6698-1-git-send-email-e@80x24.org> List-Id: >From doc/extension.rdoc: > > Using the RB_GC_GUARD macro is preferable to using the "volatile" > keyword in C. RB_GC_GUARD has the following advantages: > > 1) the intent of the macro use is clear > > 2) RB_GC_GUARD only affects its call site, "volatile" generates some > extra code every time the variable is used, hurting optimization. > > 3) "volatile" implementations may be buggy/inconsistent in some > compilers and architectures. RB_GC_GUARD is customizable for broken > systems/compilers without those without negatively affecting other > systems. --- ext/openssl/ossl_asn1.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ext/openssl/ossl_asn1.c b/ext/openssl/ossl_asn1.c index bcd0929..fb7861d 100644 --- a/ext/openssl/ossl_asn1.c +++ b/ext/openssl/ossl_asn1.c @@ -1029,7 +1029,7 @@ static VALUE ossl_asn1_traverse(VALUE self, VALUE obj) { unsigned char *p; - volatile VALUE tmp; + VALUE tmp; long len, read = 0, offset = 0; obj = ossl_to_der_if_possible(obj); @@ -1037,6 +1037,7 @@ ossl_asn1_traverse(VALUE self, VALUE obj) p = (unsigned char *)RSTRING_PTR(tmp); len = RSTRING_LEN(tmp); ossl_asn1_decode0(&p, len, &offset, 0, 1, &read); + RB_GC_GUARD(tmp); int_ossl_decode_sanity_check(len, read, offset); return Qnil; } @@ -1058,7 +1059,7 @@ ossl_asn1_decode(VALUE self, VALUE obj) { VALUE ret; unsigned char *p; - volatile VALUE tmp; + VALUE tmp; long len, read = 0, offset = 0; obj = ossl_to_der_if_possible(obj); @@ -1066,6 +1067,7 @@ ossl_asn1_decode(VALUE self, VALUE obj) p = (unsigned char *)RSTRING_PTR(tmp); len = RSTRING_LEN(tmp); ret = ossl_asn1_decode0(&p, len, &offset, 0, 0, &read); + RB_GC_GUARD(tmp); int_ossl_decode_sanity_check(len, read, offset); return ret; } @@ -1089,7 +1091,7 @@ ossl_asn1_decode_all(VALUE self, VALUE obj) VALUE ary, val; unsigned char *p; long len, tmp_len = 0, read = 0, offset = 0; - volatile VALUE tmp; + VALUE tmp; obj = ossl_to_der_if_possible(obj); tmp = rb_str_new4(StringValue(obj)); @@ -1104,6 +1106,7 @@ ossl_asn1_decode_all(VALUE self, VALUE obj) read += tmp_read; tmp_len -= tmp_read; } + RB_GC_GUARD(tmp); int_ossl_decode_sanity_check(len, read, offset); return ary; } -- EW