ruby-changes:43198
From: nobu <ko1@a...>
Date: Sat, 4 Jun 2016 10:54:59 +0900 (JST)
Subject: [ruby-changes:43198] nobu:r55272 (trunk): crypt.h: remove initialized
nobu 2016-06-04 10:54:54 +0900 (Sat, 04 Jun 2016) New Revision: 55272 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55272 Log: crypt.h: remove initialized * missing/crypt.h (struct crypt_data): remove unnecessary member "initialized". * missing/crypt.c (des_setkey_r): nothing to be initialized in crypt_data. * configure.in (struct crypt_data): check for "initialized" in struct crypt_data, which may be only in glibc, and isn't on AIX at least. Modified files: trunk/ChangeLog trunk/common.mk trunk/configure.in trunk/missing/crypt.c trunk/missing/crypt.h trunk/string.c Index: string.c =================================================================== --- string.c (revision 55271) +++ string.c (revision 55272) @@ -8424,7 +8424,9 @@ rb_str_crypt(VALUE str, VALUE salt) https://github.com/ruby/ruby/blob/trunk/string.c#L8424 } #endif #ifdef HAVE_CRYPT_R +# ifdef HAVE_STRUCT_CRYPT_DATA_INITIALIZED data.initialized = 0; +# endif res = crypt_r(s, saltp, &data); #else res = crypt(s, saltp); Index: missing/crypt.c =================================================================== --- missing/crypt.c (revision 55271) +++ missing/crypt.c (revision 55272) @@ -49,6 +49,10 @@ static char sccsid[] = "@(#)crypt.c 8.1 https://github.com/ruby/ruby/blob/trunk/missing/crypt.c#L49 #define _PASSWORD_EFMT1 '_' #endif +#ifndef numberof +#define numberof(array) (int)(sizeof(array) / sizeof((array)[0])) +#endif + /* * UNIX password, and DES, encryption. * By Tom Truscott, trt@r..., @@ -82,6 +86,14 @@ static char sccsid[] = "@(#)crypt.c 8.1 https://github.com/ruby/ruby/blob/trunk/missing/crypt.c#L86 #endif #endif +#ifndef INIT_DES +# if defined DUMP || defined NO_DES_TABLES +# define INIT_DES 1 +# else +# define INIT_DES 0 +# endif +#endif + /* * Convert twenty-four-bit long in host-order * to six bits (and 2 low-order zeroes) per char little-endian format. @@ -149,7 +161,7 @@ permute(const unsigned char *cp, C_block https://github.com/ruby/ruby/blob/trunk/missing/crypt.c#L161 STATIC void prtab(const char *s, const unsigned char *t, int num_rows); #endif -#ifdef DUMP +#if INIT_DES /* ===== (mostly) Standard DES Tables ==================== */ static const unsigned char IP[] = { /* initial permutation */ @@ -193,7 +205,7 @@ static const unsigned char Rotates[] = { https://github.com/ruby/ruby/blob/trunk/missing/crypt.c#L205 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, }; -#ifdef DUMP +#if INIT_DES /* note: each "row" of PC2 is left-padded with bits that make it invertible */ static const unsigned char PC2[] = { /* permuted choice table 2 */ 9, 18, 14, 17, 11, 24, 1, 5, @@ -309,7 +321,7 @@ static const unsigned char a64toi[256] = https://github.com/ruby/ruby/blob/trunk/missing/crypt.c#L321 A64TOI64(0x00), A64TOI64(0x40), }; -#ifdef DUMP +#if INIT_DES /* ===== Tables that are initialized at run time ==================== */ typedef struct { @@ -351,7 +363,6 @@ static const C_block constdatablock = {{ https://github.com/ruby/ruby/blob/trunk/missing/crypt.c#L363 #define KS (data->KS) #define cryptresult (data->cryptresult) -#define des_ready (data->initialized) static void des_setkey_r(const unsigned char *key, struct crypt_data *data); static void des_cipher_r(const unsigned char *in, unsigned char *out, long salt, int num_iter, struct crypt_data *data); @@ -472,16 +483,12 @@ des_setkey_r(const unsigned char *key, s https://github.com/ruby/ruby/blob/trunk/missing/crypt.c#L483 register int i; C_block *ksp; - if (!des_ready) { - memset(data, 0, sizeof(*data)); - init_des(); - des_ready = 1; - } + init_des(); PERM6464(K,K0,K1,key,PC1ROT[0]); ksp = &KS[0]; STORE(K&~0x03030303L, K0&~0x03030303L, K1, *ksp); - for (i = 1; i < 16; i++) { + for (i = 1; i < numberof(KS); i++) { ksp++; STORE(K,K0,K1,*ksp); ptabp = PC2ROT[Rotates[i]-1][0]; @@ -612,9 +619,8 @@ des_cipher_r(const unsigned char *in, un https://github.com/ruby/ruby/blob/trunk/missing/crypt.c#L619 #undef des_tables #undef KS #undef cryptresult -#undef des_ready -#ifdef DUMP +#if INIT_DES /* * Initialize various tables. This need only be done once. It could even be * done at compile time, if the compiler were capable of that sort of thing. @@ -862,9 +868,6 @@ prtab(const char *s, const unsigned char https://github.com/ruby/ruby/blob/trunk/missing/crypt.c#L868 #endif #ifdef DUMP -#ifndef numberof -#define numberof(array) (int )(sizeof(array) / sizeof((array)[0])) -#endif void dump_block(const C_block *block) { Index: missing/crypt.h =================================================================== --- missing/crypt.h (revision 55271) +++ missing/crypt.h (revision 55272) @@ -224,7 +224,6 @@ struct crypt_data { https://github.com/ruby/ruby/blob/trunk/missing/crypt.h#L224 /* ==================================== */ char cryptresult[1+4+4+11+1]; /* encrypted result */ - int initialized; }; char *crypt(const char *key, const char *setting); Index: configure.in =================================================================== --- configure.in (revision 55271) +++ configure.in (revision 55272) @@ -2442,6 +2442,10 @@ main(int argc, char **argv) https://github.com/ruby/ruby/blob/trunk/configure.in#L2442 AS_IF([test "$rb_cv_getcwd_malloc" = no], [AC_DEFINE(NO_GETCWD_MALLOC, 1)]) ]) +AS_IF([test "$ac_cv_func_crypt_r" = yes], + [AC_CHECK_MEMBERS([struct crypt_data.initialized], [], [], + [AC_INCLUDES_DEFAULT([@%:@include <crypt.h>])])]) + AC_DEFUN([RUBY_CHECK_BUILTIN_FUNC], [dnl AC_CACHE_CHECK([for $1], AS_TR_SH(rb_cv_builtin_$1), [AC_LINK_IFELSE( Index: ChangeLog =================================================================== --- ChangeLog (revision 55271) +++ ChangeLog (revision 55272) @@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Jun 4 10:54:52 2016 Nobuyoshi Nakada <nobu@r...> + + * missing/crypt.h (struct crypt_data): remove unnecessary member + "initialized". + + * missing/crypt.c (des_setkey_r): nothing to be initialized in + crypt_data. + + * configure.in (struct crypt_data): check for "initialized" in + struct crypt_data, which may be only in glibc, and isn't on AIX + at least. + Sat Jun 4 10:38:39 2016 Nobuyoshi Nakada <nobu@r...> * win32/win32.c: unify MAX_PATH, _MAX_PATH, and MAXPATHLEN to Index: common.mk =================================================================== --- common.mk (revision 55271) +++ common.mk (revision 55272) @@ -749,7 +749,9 @@ $(NEWLINE_C): $(srcdir)/enc/trans/newlin https://github.com/ruby/ruby/blob/trunk/common.mk#L749 enc/trans/newline.$(OBJEXT): $(NEWLINE_C) {$(VPATH)}missing/des_tables.c: $(srcdir)/missing/crypt.c + @$(ECHO) building make_des_table $(Q) $(PURIFY) $(CC) $(CPPFLAGS) -DDUMP $(LDFLAGS) $(XLDFLAGS) $(LIBS) $(OUTFLAG)make_des_table $(srcdir)/missing/crypt.c + @$(ECHO) generating $@ $(Q) $(MAKEDIRS) $(@D) $(Q) ./make_des_table > $@ $(Q) $(RMALL) make_des_table* -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/