From ff658886ffff2796d054e3e04086bd2c54c35b13 Mon Sep 17 00:00:00 2001 From: knu Date: Thu, 24 May 2001 16:00:54 +0000 Subject: * ext/sha1/sha1-ruby.c (md5i_new): separate initialize() from new(). * ext/md5/md5init.c (sha1_new): ditto. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@1448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/sha1/sha1-ruby.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'ext/sha1/sha1-ruby.c') diff --git a/ext/sha1/sha1-ruby.c b/ext/sha1/sha1-ruby.c index 760ce0f2b..75b382640 100644 --- a/ext/sha1/sha1-ruby.c +++ b/ext/sha1/sha1-ruby.c @@ -63,23 +63,33 @@ sha1_clone(obj) return obj; } +static VALUE +sha1_init(argc, argv, self) + int argc; + VALUE* argv; + VALUE self; +{ + VALUE arg; + + rb_scan_args(argc, argv, "01", &arg); + + if (!NIL_P(arg)) sha1_update(self, arg); + + return self; +} + static VALUE sha1_new(argc, argv, class) int argc; VALUE* argv; VALUE class; { - VALUE arg, obj; + VALUE obj; SHA1_CTX *sha1; - rb_scan_args(argc, argv, "01", &arg); - if (!NIL_P(arg)) Check_Type(arg, T_STRING); - obj = Data_Make_Struct(class, SHA1_CTX, 0, free, sha1); SHA1Init(sha1); - if (!NIL_P(arg)) { - sha1_update(obj, arg); - } + rb_obj_call_init(obj, argc, argv); return obj; } @@ -93,6 +103,7 @@ Init_sha1() rb_define_singleton_method(cSHA1, "sha1", sha1_new, -1); rb_define_method(cSHA1, "update", sha1_update, 1); + rb_define_method(cSHA1, "initialize", sha1_init, -1); rb_define_method(cSHA1, "<<", sha1_update, 1); rb_define_method(cSHA1, "digest", sha1_digest, 0); rb_define_method(cSHA1, "hexdigest", sha1_hexdigest, 0); -- cgit