[前][次][番号順一覧][スレッド一覧]

ruby-changes:34967

From: nobu <ko1@a...>
Date: Mon, 4 Aug 2014 00:19:42 +0900 (JST)
Subject: [ruby-changes:34967] nobu:r47048 (trunk): openssl: constify

nobu	2014-08-04 00:19:20 +0900 (Mon, 04 Aug 2014)

  New Revision: 47048

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47048

  Log:
    openssl: constify
    
    * ext/openssl/ossl_asn1.c (ossl_asn1_info): constify.
    
    * ext/openssl/ossl_pkcs7.c (ossl_pkcs7_sym2typeid): constify and
      remove sentinel as the count is used.
    
    * ext/openssl/ossl_ssl.c (ossl_ssl_method_tab): constify.

  Modified files:
    trunk/ext/openssl/ossl_asn1.c
    trunk/ext/openssl/ossl_pkcs7.c
    trunk/ext/openssl/ossl_ssl.c
Index: ext/openssl/ossl_ssl.c
===================================================================
--- ext/openssl/ossl_ssl.c	(revision 47047)
+++ ext/openssl/ossl_ssl.c	(revision 47048)
@@ -108,7 +108,7 @@ static VALUE sym_exception; https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L108
 /*
  * SSLContext class
  */
-struct {
+static const struct {
     const char *name;
     SSL_METHOD *(*func)(void);
 } ossl_ssl_method_tab[] = {
Index: ext/openssl/ossl_asn1.c
===================================================================
--- ext/openssl/ossl_asn1.c	(revision 47047)
+++ ext/openssl/ossl_asn1.c	(revision 47048)
@@ -495,7 +495,7 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_asn1.c#L495
     VALUE *klass;
 } ossl_asn1_info_t;
 
-static ossl_asn1_info_t ossl_asn1_info[] = {
+static const ossl_asn1_info_t ossl_asn1_info[] = {
     { "EOC",               &cASN1EndOfContent,    },  /*  0 */
     { "BOOLEAN",           &cASN1Boolean,         },  /*  1 */
     { "INTEGER",           &cASN1Integer,         },  /*  2 */
@@ -529,7 +529,7 @@ static ossl_asn1_info_t ossl_asn1_info[] https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_asn1.c#L529
     { "BMPSTRING",         &cASN1BMPString,       },  /* 30 */
 };
 
-int ossl_asn1_info_size = (sizeof(ossl_asn1_info)/sizeof(ossl_asn1_info[0]));
+enum {ossl_asn1_info_size = (sizeof(ossl_asn1_info)/sizeof(ossl_asn1_info[0]))};
 
 static VALUE class_tag_map;
 
Index: ext/openssl/ossl_pkcs7.c
===================================================================
--- ext/openssl/ossl_pkcs7.c	(revision 47047)
+++ ext/openssl/ossl_pkcs7.c	(revision 47048)
@@ -364,8 +364,8 @@ ossl_pkcs7_sym2typeid(VALUE sym) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_pkcs7.c#L364
     const char *s;
     size_t l;
 
-    static struct {
-        const char *name;
+    static const struct {
+        char name[20];
         int nid;
     } p7_type_tab[] = {
         { "signed",             NID_pkcs7_signed },
@@ -374,14 +374,13 @@ ossl_pkcs7_sym2typeid(VALUE sym) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_pkcs7.c#L374
         { "enveloped",          NID_pkcs7_enveloped },
         { "encrypted",          NID_pkcs7_encrypted },
         { "digest",             NID_pkcs7_digest },
-        { NULL,                 0 },
     };
 
     if (RB_TYPE_P(sym, T_SYMBOL)) sym = rb_sym2str(sym);
     else StringValue(sym);
     RSTRING_GETMEM(sym, s, l);
-    for(i = 0; i < numberof(p7_type_tab); i++){
-	if(p7_type_tab[i].name == NULL)
+    for(i = 0; ; i++){
+	if(i == numberof(p7_type_tab))
 	    ossl_raise(ePKCS7Error, "unknown type \"%s\"", s);
 	if(strlen(p7_type_tab[i].name) != l) continue;
 	if(strcmp(p7_type_tab[i].name, s) == 0){

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]