Ticket #185: parrot-vtable-method.patch
| File parrot-vtable-method.patch, 3.8 KB (added by jhorwitz, 4 years ago) |
|---|
-
src/oo.c
436 436 437 437 /* 438 438 439 =item C<const char * Parrot_get_vtable_name> 440 441 Return the method name at the specified index in the vtable slot array. 442 Use this function when you cannot access Parrot_vtable_slot_names directly. 443 444 =cut 445 446 */ 447 448 PARROT_EXPORT 449 PARROT_PURE_FUNCTION 450 PARROT_CAN_RETURN_NULL 451 const char * 452 Parrot_get_vtable_name(PARROT_INTERP, INTVAL idx) 453 { 454 ASSERT_ARGS(Parrot_get_vtable_name) 455 456 INTVAL low = PARROT_VTABLE_LOW; 457 INTVAL high = NUM_VTABLE_FUNCTIONS + PARROT_VTABLE_LOW; 458 459 PARROT_ASSERT(idx > 0); 460 461 if (idx < low || idx > high) { 462 return NULL; 463 } 464 465 return Parrot_vtable_slot_names[idx]; 466 } 467 468 469 /* 470 439 471 =item C<const char* Parrot_MMD_method_name> 440 472 441 473 Return the method name for the given MMD enum. -
src/pmc/namespace.pmc
58 58 PMC * vtable = nsinfo->vtable; 59 59 Parrot_sub * const sub = PMC_sub(value); 60 60 PMC * const classobj = VTABLE_get_class(interp, self); 61 STRING * vtable_key = NULL; 61 62 63 62 64 /* Handle vtable methods with two underscores at the start. */ 63 65 if (sub->vtable_index == -1) { 64 66 if (string_str_index(interp, key, CONST_STRING(interp, "__"), 0) == 0) { … … 71 73 72 74 if (sub->vtable_index != -1) { 73 75 /* Insert it in class, if there is a class */ 74 if (!PMC_IS_NULL(classobj) && PObj_is_class_TEST(classobj)) 75 VTABLE_add_vtable_override(interp, classobj, key, value); 76 if (!PMC_IS_NULL(classobj) && PObj_is_class_TEST(classobj)) { 77 const char *vtable_key_c; 78 vtable_key_c = Parrot_get_vtable_name(interp, sub->vtable_index); 79 PARROT_ASSERT(vtable_key_c); 80 vtable_key = string_from_cstring(interp, vtable_key_c, 81 strlen(vtable_key_c)); 82 VTABLE_add_vtable_override(interp, classobj, vtable_key, value); 83 } 76 84 77 85 /* Otherwise, store it in the namespace for the class to 78 86 * retrieve later */ … … 89 97 if (sub->comp_flags & SUB_COMP_FLAG_METHOD) { 90 98 STRING *method_name = key; 91 99 92 if (0 != string_equal(interp, sub->method_name, CONST_STRING(interp, ""))) 100 if (0 == string_equal(interp, sub->method_name, CONST_STRING(interp, ""))) { 101 if (sub->vtable_index != -1 && vtable_key != NULL) { 102 method_name = string_copy(interp, vtable_key); 103 } 104 } 105 else { 93 106 method_name = sub->method_name; 107 } 94 108 add_to_class(interp, nsinfo, classobj, method_name, value); 95 109 } 96 110 -
include/parrot/oo.h
105 105 __attribute__nonnull__(2); 106 106 107 107 PARROT_EXPORT 108 PARROT_PURE_FUNCTION 109 PARROT_CAN_RETURN_NULL 110 const char * Parrot_get_vtable_name(PARROT_INTERP, INTVAL idx) 111 __attribute__nonnull__(1); 112 113 PARROT_EXPORT 108 114 void Parrot_invalidate_method_cache(PARROT_INTERP, 109 115 ARGIN_NULLOK(STRING *_class)) 110 116 __attribute__nonnull__(1); … … 212 218 #define ASSERT_ARGS_Parrot_get_vtable_index __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 213 219 PARROT_ASSERT_ARG(interp) \ 214 220 || PARROT_ASSERT_ARG(name) 221 #define ASSERT_ARGS_Parrot_get_vtable_name __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 222 PARROT_ASSERT_ARG(interp) 215 223 #define ASSERT_ARGS_Parrot_invalidate_method_cache \ 216 224 __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 217 225 PARROT_ASSERT_ARG(interp)
