Skip to content

get_digest_base_metadata used to allow fallback to getting metadata pointer from VALUE created by Data_Wrap_Struct, why has this been changed? #121

@konsolebox

Description

@konsolebox

Here's the code from 3.3.10 which still allows the fallback. The new changes broke implementations that create the metadata object externally. I could check if rb_digest_make_metadata exists and call it on versions of digest.h where it exists but still call Data_Wrap_Struct (Data_Make_Struct actually) when it doesn't to preserve compatibility in all versions. Unfortunately I can't because my metadata is dynamic as I create one for every custom implementation of the algo, and rb_digest_make_metadata does not accept an argument for the free function.

static rb_digest_metadata_t *
get_digest_base_metadata(VALUE klass)
{
    VALUE p;
    VALUE obj;
    rb_digest_metadata_t *algo;

    for (p = klass; !NIL_P(p); p = rb_class_superclass(p)) {
        if (rb_ivar_defined(p, id_metadata)) {
            obj = rb_ivar_get(p, id_metadata);
            break;
        }
    }

    if (NIL_P(p))
        rb_raise(rb_eRuntimeError, "Digest::Base cannot be directly inherited in Ruby");

    if (!RB_TYPE_P(obj, T_DATA) || RTYPEDDATA_P(obj)) {
      wrong:
        if (p == klass)
            rb_raise(rb_eTypeError, "%"PRIsVALUE"::metadata is not initialized properly",
                     klass);
        else
            rb_raise(rb_eTypeError, "%"PRIsVALUE"(%"PRIsVALUE")::metadata is not initialized properly",
                     klass, p);
    }

#undef RUBY_UNTYPED_DATA_WARNING
#define RUBY_UNTYPED_DATA_WARNING 0
    Data_Get_Struct(obj, rb_digest_metadata_t, algo);

    if (!algo) goto wrong;

    switch (algo->api_version) {
      case 3:
        break;

      /*
       * put conversion here if possible when API is updated
       */

      default:
        rb_raise(rb_eRuntimeError, "Incompatible digest API version");
    }

    return algo;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions