git ssb

0+

dangerousbeans / %aPBe2k3ugtjBr4rrsU1…



Commit ec33b8415fefd62c80000f74663dbfd6d9ed2fa4

use Ruby style indentation

Aaron Patterson committed on 7/22/2011, 11:40:07 PM
Parent: ff140cb71caaf8eddfd9bf4b4a5c387f2ec87ab3

Files changed

ext/mri/bcrypt_ext.cchanged
ext/mri/bcrypt_ext.cView
@@ -15,73 +15,75 @@
1515 #endif
1616
1717 #ifdef RUBY_1_9
1818
19- /* When on Ruby 1.9+, we will want to unlock the GIL while performing
20- * expensive calculations, for greater concurrency. Do not do this for
21- * cheap calculations because locking/unlocking the GIL incurs some overhead as well.
22- */
23- #define GIL_UNLOCK_COST_THRESHOLD 9
24-
25- typedef struct {
26- char *output;
27- const char *key;
28- const char *salt;
29- } BCryptArguments;
30-
31- static VALUE bcrypt_wrapper(void *_args) {
32- BCryptArguments *args = (BCryptArguments *)_args;
33- return (VALUE)ruby_bcrypt(args->output, args->key, args->salt);
34- }
19+/* When on Ruby 1.9+, we will want to unlock the GIL while performing
20+ * expensive calculations, for greater concurrency. Do not do this for
21+ * cheap calculations because locking/unlocking the GIL incurs some overhead as well.
22+ */
23+#define GIL_UNLOCK_COST_THRESHOLD 9
3524
25+typedef struct {
26+ char *output;
27+ const char *key;
28+ const char *salt;
29+} BCryptArguments;
30+
31+static VALUE bcrypt_wrapper(void *_args) {
32+ BCryptArguments *args = (BCryptArguments *)_args;
33+ return (VALUE)ruby_bcrypt(args->output, args->key, args->salt);
34+}
35+
3636 #endif /* RUBY_1_9 */
3737
3838 /* Given a logarithmic cost parameter, generates a salt for use with +bc_crypt+.
39- */
39+*/
4040 static VALUE bc_salt(VALUE self, VALUE cost, VALUE seed) {
41- int icost = NUM2INT(cost);
42- char salt[BCRYPT_SALT_OUTPUT_SIZE];
43-
44- ruby_bcrypt_gensalt(salt, icost, (uint8_t *)RSTRING_PTR(seed));
45- return rb_str_new2(salt);
41+ int icost = NUM2INT(cost);
42+ char salt[BCRYPT_SALT_OUTPUT_SIZE];
43+
44+ ruby_bcrypt_gensalt(salt, icost, (uint8_t *)RSTRING_PTR(seed));
45+ return rb_str_new2(salt);
4646 }
4747
4848 /* Given a secret and a salt, generates a salted hash (which you can then store safely).
49- */
49+*/
5050 static VALUE bc_crypt(VALUE self, VALUE key, VALUE salt, VALUE cost) {
51- const char * safeguarded = RSTRING_PTR(key) ? RSTRING_PTR(key) : "";
52- char output[BCRYPT_OUTPUT_SIZE];
53-
54- #ifdef RUBY_1_9
55- int icost = NUM2INT(cost);
56- if (icost >= GIL_UNLOCK_COST_THRESHOLD) {
57- BCryptArguments args;
58- VALUE ret;
59-
60- args.output = output;
61- args.key = safeguarded;
62- args.salt = RSTRING_PTR(salt);
63- ret = rb_thread_blocking_region(bcrypt_wrapper, &args, RUBY_UBF_IO, 0);
64- if (ret != (VALUE) 0) {
65- return rb_str_new2(output);
66- } else {
67- return Qnil;
68- }
69- }
70- /* otherwise, fallback to the non-GIL-unlocking code, just like on Ruby 1.8 */
71- #endif
72-
73- if (ruby_bcrypt(output, safeguarded, (char *)RSTRING_PTR(salt)) != NULL) {
74- return rb_str_new2(output);
51+ const char * safeguarded = RSTRING_PTR(key) ? RSTRING_PTR(key) : "";
52+ char output[BCRYPT_OUTPUT_SIZE];
53+
54+#ifdef RUBY_1_9
55+ int icost = NUM2INT(cost);
56+ if (icost >= GIL_UNLOCK_COST_THRESHOLD) {
57+ BCryptArguments args;
58+ VALUE ret;
59+
60+ args.output = output;
61+ args.key = safeguarded;
62+ args.salt = RSTRING_PTR(salt);
63+ ret = rb_thread_blocking_region(bcrypt_wrapper, &args, RUBY_UBF_IO, 0);
64+ if (ret != (VALUE) 0) {
65+ return rb_str_new2(output);
7566 } else {
76- return Qnil;
67+ return Qnil;
7768 }
69+ }
70+ /* otherwise, fallback to the non-GIL-unlocking code, just like on Ruby 1.8 */
71+#endif
72+
73+ if (ruby_bcrypt(output, safeguarded, (char *)RSTRING_PTR(salt)) != NULL) {
74+ return rb_str_new2(output);
75+ } else {
76+ return Qnil;
77+ }
7878 }
7979
8080 /* Create the BCrypt and BCrypt::Engine modules, and populate them with methods. */
8181 void Init_bcrypt_ext(){
82- mBCrypt = rb_define_module("BCrypt");
83- cBCryptEngine = rb_define_class_under(mBCrypt, "Engine", rb_cObject);
84-
85- rb_define_singleton_method(cBCryptEngine, "__bc_salt", bc_salt, 2);
86- rb_define_singleton_method(cBCryptEngine, "__bc_crypt", bc_crypt, 3);
82+ mBCrypt = rb_define_module("BCrypt");
83+ cBCryptEngine = rb_define_class_under(mBCrypt, "Engine", rb_cObject);
84+
85+ rb_define_singleton_method(cBCryptEngine, "__bc_salt", bc_salt, 2);
86+ rb_define_singleton_method(cBCryptEngine, "__bc_crypt", bc_crypt, 3);
8787 }
88+
89+/* vim: set noet sws=4 sw=4: */

Built with git-ssb-web