void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE (*dumper)(VALUE), VALUE (*loader)(VALUE, VALUE)) { marshal_compat_t *compat; rb_alloc_func_t allocator = rb_get_alloc_func(newclass); if (!allocator) { rb_raise(rb_eTypeError, "no allocator"); } compat = ALLOC(marshal_compat_t); compat->newclass = Qnil; compat->oldclass = Qnil; compat->newclass = newclass; compat->oldclass = oldclass; compat->dumper = dumper; compat->loader = loader; st_insert(compat_allocator_tbl, (st_data_t)allocator, (st_data_t)compat); }
void validate_type_class(upb_fieldtype_t type, VALUE klass) { if (rb_ivar_get(klass, descriptor_instancevar_interned) == Qnil) { rb_raise(rb_eArgError, "Type class has no descriptor. Please pass a " "class or enum as returned by the DescriptorPool."); } if (type == UPB_TYPE_MESSAGE) { VALUE desc = rb_ivar_get(klass, descriptor_instancevar_interned); if (!RB_TYPE_P(desc, T_DATA) || !RTYPEDDATA_P(desc) || RTYPEDDATA_TYPE(desc) != &_Descriptor_type) { rb_raise(rb_eArgError, "Descriptor has an incorrect type."); } if (rb_get_alloc_func(klass) != &Message_alloc) { rb_raise(rb_eArgError, "Message class was not returned by the DescriptorPool."); } } else if (type == UPB_TYPE_ENUM) { VALUE enumdesc = rb_ivar_get(klass, descriptor_instancevar_interned); if (!RB_TYPE_P(enumdesc, T_DATA) || !RTYPEDDATA_P(enumdesc) || RTYPEDDATA_TYPE(enumdesc) != &_EnumDescriptor_type) { rb_raise(rb_eArgError, "Descriptor has an incorrect type."); } } }