From 04cd7cc62d8b16da8ccdff92f46e54e62ff26fab Mon Sep 17 00:00:00 2001 From: knu Date: Wed, 28 Feb 2007 18:24:25 +0000 Subject: [PATCH] * ext/digest/digest.c (get_digest_base_metadata): Allow inheriting Digest::Base subclasses, which was unintentionally made impossible while restructuring Digest classes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11947 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ ext/digest/digest.c | 12 ++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8ffdd89918..e74403b4b4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Thu Mar 1 02:55:25 2007 Akinori MUSHA + + * ext/digest/digest.c (get_digest_base_metadata): Allow inheriting + Digest::Base subclasses, which was unintentionally made + impossible while restructuring Digest classes. + Thu Mar 1 02:05:17 2007 Nobuyoshi Nakada * mkconfig.rb (patchlevel): read from version.h. diff --git a/ext/digest/digest.c b/ext/digest/digest.c index 07484f897f..c239be294f 100644 --- a/ext/digest/digest.c +++ b/ext/digest/digest.c @@ -423,15 +423,19 @@ rb_digest_class_s_hexdigest(int argc, VALUE *argv, VALUE klass) static rb_digest_metadata_t * get_digest_base_metadata(VALUE klass) { + VALUE p; VALUE obj; rb_digest_metadata_t *algo; - if (rb_ivar_defined(klass, id_metadata) == Qfalse) { - /* This class should not be subclassed in Ruby */ - rb_notimplement(); + for (p = klass; p; p = RCLASS(p)->super) { + if (rb_ivar_defined(p, id_metadata)) { + obj = rb_ivar_get(p, id_metadata); + break; + } } - obj = rb_ivar_get(klass, id_metadata); + if (!p) + rb_raise(rb_eRuntimeError, "Digest::Base cannot be inherited in Ruby"); Data_Get_Struct(obj, rb_digest_metadata_t, algo);