@@ -281,7 +281,7 @@ struct rb_callcache {
281281 /* inline cache: key */
282282 const VALUE klass ; // should not mark it because klass can not be free'd
283283 // because of this marking. When klass is collected,
284- // cc will be cleared (cc->klass = 0 ) at rb_vm_cc_table_invalidate_ccs().
284+ // cc will be cleared (cc->klass = Qundef ) at rb_vm_cc_table_invalidate_ccs().
285285
286286 /* inline cache: values */
287287 const struct rb_callable_method_entry_struct * const cme_ ;
@@ -324,12 +324,20 @@ vm_cc_attr_index_initialize(const struct rb_callcache *cc, shape_id_t shape_id)
324324 vm_cc_attr_index_set (cc , (attr_index_t )- 1 , shape_id );
325325}
326326
327+ static inline VALUE
328+ cc_check_class (VALUE klass )
329+ {
330+ VM_ASSERT (klass == Qundef || RB_TYPE_P (klass , T_CLASS ) || RB_TYPE_P (klass , T_ICLASS ));
331+ return klass ;
332+ }
333+
327334static inline const struct rb_callcache *
328335vm_cc_new (VALUE klass ,
329336 const struct rb_callable_method_entry_struct * cme ,
330337 vm_call_handler call ,
331338 enum vm_cc_type type )
332339{
340+ cc_check_class (klass );
333341 struct rb_callcache * cc = IMEMO_NEW (struct rb_callcache , imemo_callcache , klass );
334342 * ((struct rb_callable_method_entry_struct * * )& cc -> cme_ ) = (struct rb_callable_method_entry_struct * )cme ;
335343 * ((vm_call_handler * )& cc -> call_ ) = call ;
@@ -374,7 +382,7 @@ vm_cc_refinement_p(const struct rb_callcache *cc)
374382 (imemo_callcache << FL_USHIFT) | \
375383 VM_CALLCACHE_UNMARKABLE | \
376384 VM_CALLCACHE_ON_STACK, \
377- .klass = clazz, \
385+ .klass = cc_check_class( clazz), \
378386 .cme_ = cme, \
379387 .call_ = call, \
380388 .aux_ = aux, \
@@ -384,7 +392,7 @@ static inline bool
384392vm_cc_class_check (const struct rb_callcache * cc , VALUE klass )
385393{
386394 VM_ASSERT (IMEMO_TYPE_P (cc , imemo_callcache ));
387- VM_ASSERT (cc -> klass == 0 ||
395+ VM_ASSERT (cc -> klass == Qundef ||
388396 RB_TYPE_P (cc -> klass , T_CLASS ) || RB_TYPE_P (cc -> klass , T_ICLASS ));
389397 return cc -> klass == klass ;
390398}
@@ -396,6 +404,13 @@ vm_cc_markable(const struct rb_callcache *cc)
396404 return FL_TEST_RAW ((VALUE )cc , VM_CALLCACHE_UNMARKABLE ) == 0 ;
397405}
398406
407+ static inline bool
408+ vm_cc_valid (const struct rb_callcache * cc )
409+ {
410+ VM_ASSERT (IMEMO_TYPE_P (cc , imemo_callcache ));
411+ return cc -> klass && !UNDEF_P (cc -> klass );
412+ }
413+
399414static inline const struct rb_callable_method_entry_struct *
400415vm_cc_cme (const struct rb_callcache * cc )
401416{
@@ -447,7 +462,7 @@ vm_cc_cmethod_missing_reason(const struct rb_callcache *cc)
447462static inline bool
448463vm_cc_invalidated_p (const struct rb_callcache * cc )
449464{
450- if (cc -> klass && !METHOD_ENTRY_INVALIDATED (vm_cc_cme (cc ))) {
465+ if (vm_cc_valid ( cc ) && !METHOD_ENTRY_INVALIDATED (vm_cc_cme (cc ))) {
451466 return false;
452467 }
453468 else {
@@ -543,9 +558,9 @@ vm_cc_invalidate(const struct rb_callcache *cc)
543558{
544559 VM_ASSERT (IMEMO_TYPE_P (cc , imemo_callcache ));
545560 VM_ASSERT (cc != vm_cc_empty ());
546- VM_ASSERT (cc -> klass != 0 ); // should be enable
561+ VM_ASSERT (cc -> klass != Qundef ); // should be enable
547562
548- * (VALUE * )& cc -> klass = 0 ;
563+ * (VALUE * )& cc -> klass = Qundef ;
549564 RB_DEBUG_COUNTER_INC (cc_ent_invalidate );
550565}
551566
0 commit comments