ruby-changes:46751
From: nobu <ko1@a...>
Date: Wed, 24 May 2017 15:55:13 +0900 (JST)
Subject: [ruby-changes:46751] nobu:r58866 (trunk): string.c: for small crypt_data
nobu 2017-05-24 15:55:09 +0900 (Wed, 24 May 2017) New Revision: 58866 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58866 Log: string.c: for small crypt_data * string.c (rb_str_crypt): struct crypt_data defined in missing/crypt.h is small enough. Modified files: trunk/missing/crypt.h trunk/string.c Index: string.c =================================================================== --- string.c (revision 58865) +++ string.c (revision 58866) @@ -8722,8 +8722,14 @@ rb_str_oct(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L8722 static VALUE rb_str_crypt(VALUE str, VALUE salt) { +#undef LARGE_CRYPT_DATA #ifdef HAVE_CRYPT_R +# if defined SIZEOF_CRYPT_DATA && SIZEOF_CRYPT_DATA <= 256 + struct crypt_data cdata, *const data = &cdata; +# else +# undef LARGE_CRYPT_DATA struct crypt_data *data = ALLOC(struct crypt_data); +# endif #else extern char *crypt(const char *, const char *); #endif @@ -8762,7 +8768,7 @@ rb_str_crypt(VALUE str, VALUE salt) https://github.com/ruby/ruby/blob/trunk/string.c#L8768 res = crypt(s, saltp); #endif if (!res) { -#ifdef HAVE_CRYPT_R +#ifdef LARGE_CRYPT_DATA int err = errno; xfree(data); errno = err; @@ -8770,7 +8776,7 @@ rb_str_crypt(VALUE str, VALUE salt) https://github.com/ruby/ruby/blob/trunk/string.c#L8776 rb_sys_fail("crypt"); } result = rb_str_new_cstr(res); -#ifdef HAVE_CRYPT_R +#ifdef LARGE_CRYPT_DATA xfree(data); #endif FL_SET_RAW(result, OBJ_TAINTED_RAW(str) | OBJ_TAINTED_RAW(salt)); Index: missing/crypt.h =================================================================== --- missing/crypt.h (revision 58865) +++ missing/crypt.h (revision 58866) @@ -237,6 +237,8 @@ struct crypt_data { https://github.com/ruby/ruby/blob/trunk/missing/crypt.h#L237 char cryptresult[1+4+4+11+1]; /* encrypted result */ }; +#define SIZEOF_CRYPT_DATA (KS_SIZE*8+(1+4+4+11+1)) + char *crypt(const char *key, const char *setting); void setkey(const char *key); void encrypt(char *block, int flag); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/