Ticket #519: managed_struct_attempt.patch
File managed_struct_attempt.patch, 10.4 KB (added by cotto, 13 years ago) |
---|
-
src/ops/core.ops
1406 1406 /* At this point we have the symbol's address. We just need to build 1407 1407 a PMC with it so we can get and set the value */ 1408 1408 $1 = pmc_new(interp, enum_class_UnManagedStruct); 1409 PMC_data($1) = p;1409 VTABLE_set_pointer(interp, $1, p); 1410 1410 } 1411 1411 Parrot_str_free_cstring(name); 1412 1412 } -
src/pmc/unmanagedstruct.pmc
63 63 offs = (size_t) VTABLE_get_integer_keyed_int(interp, 64 64 PMC_pmc_val(pmc), ix + 2); 65 65 66 return ((char *) PMC_data(pmc)) + offs;66 return ((char *)VTABLE_get_pointer(interp, pmc)) + offs; 67 67 } 68 68 69 69 /* … … 183 183 } 184 184 185 185 if (init->vtable->base_type == enum_class_UnManagedStruct) { 186 /* now point PMC_data of this structto the real data */186 /* now point ptr to the real data */ 187 187 if (*type == enum_type_struct_ptr) { 188 188 /* that is either a pointer */ 189 189 PARROT_ASSERT((PTR2INTVAL(p) & (PARROT_PTR_ALIGNMENT - 1)) == 0); 190 PMC_data(init) = *(void**)p;190 VTABLE_set_pointer(interp, init, *(void**)p); 191 191 } 192 192 193 193 /* or just an offset for nested structs */ 194 194 else 195 PMC_data(init) = p;195 VTABLE_set_pointer(interp, init, p); 196 196 } 197 197 else if (init->vtable->base_type == enum_class_ManagedStruct 198 198 && *type == enum_type_struct_ptr) { … … 201 201 * outer struct, the inner is at PMC_data(init) */ 202 202 203 203 PARROT_ASSERT((PTR2INTVAL(p) & (PARROT_PTR_ALIGNMENT - 1)) == 0); 204 *(void **)p = PMC_data(init);204 *(void **)p = VTABLE_get_pointer(interp, init); 205 205 } 206 206 207 207 return char_offset_key(interp, init, next, type); … … 411 411 "no initializer available for nested struct"); 412 412 } 413 413 414 /* assign the pointer */ 415 PMC_data(ret) = *(void**)p; 414 VTABLE_set_pointer(interp, ret, *(void**)p); 416 415 417 416 return ret; 418 417 default: … … 657 656 } 658 657 659 658 pmclass UnManagedStruct need_ext no_ro { 659 ATTR void *ptr; /* whatever this UnManagedStruct isn't managing */ 660 660 661 661 /* 662 662 … … 675 675 */ 676 676 677 677 VTABLE void init() { 678 Parrot_UnManagedStruct_attributes *attrs = 679 mem_allocate_zeroed_typed(Parrot_UnManagedStruct_attributes); 680 PMC_data(SELF) = attrs; 681 attrs->ptr = NULL; 678 682 PMC_pmc_val(SELF) = NULL; 679 683 } 680 684 … … 712 716 713 717 /* 714 718 719 =item C<PMC *clone()> 720 721 Return a clone of this PMC. 722 723 =cut 724 725 */ 726 727 VTABLE PMC *clone() { 728 PMC *clone = pmc_new(INTERP, enum_class_UnManagedStruct); 729 mem_sys_memmove(PMC_data(clone), PMC_data(SELF), 730 sizeof(Parrot_UnManagedStruct_attributes)); 731 PMC_pmc_val(clone) = VTABLE_clone(INTERP, PMC_pmc_val(SELF)); 732 PMC_int_val(clone) = PMC_int_val(SELF); 733 return clone; 734 } 735 736 /* 737 715 738 =item C<void set_pmc(PMC *value)> 716 739 717 740 Sets C<*value> (see C<init_pmc()> and calculates the offsets. … … 753 776 754 777 VTABLE INTVAL is_equal(PMC *value) { 755 778 return (SELF->vtable == value->vtable 756 && PMC_data(SELF) == PMC_data(value));779 && SELF.get_pointer() == VTABLE_get_pointer(interp, value)); 757 780 } 758 781 759 782 /* … … 767 790 */ 768 791 769 792 VTABLE INTVAL defined() { 770 return PMC_data(SELF) != NULL;793 return SELF.get_pointer() != NULL; 771 794 } 772 795 773 796 /* … … 937 960 */ 938 961 939 962 VTABLE void *get_pointer() { 940 return P MC_data(SELF);963 return PARROT_UNMANAGEDSTRUCT(SELF)->ptr; 941 964 } 942 965 943 966 /* … … 951 974 */ 952 975 953 976 VTABLE void set_pointer(void *value) { 954 P MC_data(SELF)= value;977 PARROT_UNMANAGEDSTRUCT(SELF)->ptr = value; 955 978 } 956 979 957 980 /* -
src/pmc/managedstruct.pmc
35 35 */ 36 36 37 37 VTABLE void init() { 38 Parrot_ManagedStruct_attributes *attrs = 39 mem_allocate_zeroed_typed(Parrot_ManagedStruct_attributes); 38 40 PObj_active_destroy_SET(SELF); 39 41 PMC_pmc_val(SELF) = NULL; 40 42 PMC_int_val(SELF) = 0; 43 PMC_data(SELF) = attrs; 44 41 45 } 42 46 43 47 /* … … 66 70 */ 67 71 68 72 VTABLE void destroy() { 69 if (PMC_data(SELF)) 70 mem_sys_free(PMC_data(SELF)); 73 if (PARROT_MANAGEDSTRUCT(SELF)->ptr) 74 mem_sys_free(PARROT_MANAGEDSTRUCT(SELF)->ptr); 75 mem_sys_free(PMC_data(SELF)); 71 76 } 72 77 73 78 /* … … 81 86 */ 82 87 83 88 VTABLE void set_integer_native(INTVAL value) { 84 if (P MC_data(SELF)&& !value) {85 mem_sys_free(P MC_data(SELF));86 P MC_data(SELF)= NULL;89 if (PARROT_MANAGEDSTRUCT(SELF)->ptr && !value) { 90 mem_sys_free(PARROT_MANAGEDSTRUCT(SELF)->ptr); 91 PARROT_MANAGEDSTRUCT(SELF)->ptr = NULL; 87 92 PMC_int_val(SELF) = 0; 88 93 } 89 else if (value && !P MC_data(SELF)) {90 P MC_data(SELF)= mem_sys_allocate_zeroed((size_t)value);94 else if (value && !PARROT_MANAGEDSTRUCT(SELF)->ptr) { 95 PARROT_MANAGEDSTRUCT(SELF)->ptr = mem_sys_allocate_zeroed((size_t)value); 91 96 PMC_int_val(SELF) = value; 92 97 } 93 else if (value && P MC_data(SELF)) {98 else if (value && PARROT_MANAGEDSTRUCT(SELF)->ptr) { 94 99 if (PMC_int_val(SELF) != value) { 95 PMC_data(SELF) = mem_sys_realloc(PMC_data(SELF), 96 (size_t)value); 100 PARROT_MANAGEDSTRUCT(SELF)->ptr = mem_sys_realloc(PARROT_MANAGEDSTRUCT(SELF)->ptr, (size_t)value); 97 101 PMC_int_val(SELF) = value; 98 102 } 99 103 } … … 118 122 PMC *dest = pmc_new_init(interp, SELF->vtable->base_type, 119 123 PMC_pmc_val(SELF)); 120 124 121 if (P MC_data(SELF))122 memmove(P MC_data(dest), PMC_data(SELF), PMC_int_val(SELF));125 if (PARROT_MANAGEDSTRUCT(SELF)->ptr) 126 memmove(PARROT_MANAGEDSTRUCT(dest)->ptr, PARROT_MANAGEDSTRUCT(SELF)->ptr, PMC_int_val(SELF)); 123 127 124 128 return dest; 125 129 } -
src/jit/i386/jit_defs.c
11 11 #include "parrot/hash.h" 12 12 #include "parrot/oplib/ops.h" 13 13 #include "pmc/pmc_fixedintegerarray.h" 14 #include "pmc/pmc_unmanagedstruct.h" 14 15 #include "jit.h" 15 16 #include "jit_emit.h" 16 17 … … 2235 2236 case 'p': /* push pmc->data */ 2236 2237 emitm_call_cfunc(pc, get_nci_P); 2237 2238 #if ! PMC_DATA_IN_EXT 2238 /* mov pmc, %edx 2239 * mov 8(%edx), %eax 2240 * push %eax 2241 */ 2239 2242 2240 emitm_movl_m_r(interp, pc, emit_EAX, emit_EAX, 0, 1, offsetof(struct PMC, data)); 2241 emitm_movl_m_r(interp, pc, emit_EAX, emit_EAX, 0, 1, offsetof(struct Parrot_UnManagedStruct_attributes, ptr)); 2243 2242 #else 2244 2243 /* push pmc->pmc_ext->data 2245 2244 * mov pmc, %edx … … 2405 2404 /* stuff return value into pmc->data */ 2406 2405 2407 2406 #if ! PMC_DATA_IN_EXT 2408 /* mov %edx, (data) %eax */ 2409 emitm_movl_r_m(interp, pc, emit_EDX, emit_EAX, 0, 1, offsetof(struct PMC, data)); 2407 /* mov pmc_data(%eax), %eax 2408 mov %edx, ptr(%eax) */ 2409 emitm_movl_m_r(interp, pc, emit_EAX, emit_EAX, 0, 1, offsetof(struct PMC, data)); 2410 emitm_movl_r_m(interp, pc, emit_EDX, emit_EAX, 0, 1, offsetof(struct Parrot_UnManagedStruct_attributes, ptr)); 2410 2411 #else 2412 /* XXX: if PMC_DATA_IN_EXT is ever fixed, this will need to be 2413 * changed to put the result in pmc->data->ptr instead of 2414 * pmc->data*/ 2411 2415 /* mov pmc_ext(%eax), %eax 2412 2416 mov %edx, data(%eax) */ 2413 2417 emitm_movl_m_r(interp, pc, emit_EAX, emit_EAX, 0, 1, offsetof(struct PMC, pmc_ext)); -
tools/build/nativecall.pl
43 43 as_proto => "void *", 44 44 other_decl => "PMC * const final_destination = pmc_new(interp, enum_class_UnManagedStruct);", 45 45 sig_char => "P", 46 ret_assign => " PMC_data(final_destination) = return_data; set_nci_P(interp, &st, final_destination);",46 ret_assign => "VTABLE_set_pointer(interp, final_destination, return_data); set_nci_P(interp, &st, final_destination);", 47 47 }, 48 48 i => { as_proto => "int", sig_char => "I" }, 49 49 l => { as_proto => "long", sig_char => "I" }, … … 477 477 478 478 push @{$put_pointer_ref}, <<"PUT_POINTER"; 479 479 temp_pmc = pmc_new(interp, enum_class_UnManagedStruct); 480 PMC_data(temp_pmc) = (void *)$value;480 VTABLE_set_pointer(interp, temp_pmc, (void *)$value); 481 481 VTABLE_set_pmc_keyed_str(interp, HashPointer, CONST_STRING(interp, "$key"), temp_pmc); 482 482 PUT_POINTER 483 483 … … 569 569 b = VTABLE_get_pmc_keyed_str(interp, HashPointer, signature); 570 570 571 571 if (b && b->vtable->base_type == enum_class_UnManagedStruct) 572 return F2DPTR( PMC_data(b));572 return F2DPTR(VTABLE_get_pointer(interp, b)); 573 573 574 574 /* 575 575 These three lines have been added to aid debugging. I want to be able to -
config/gen/makefiles/root.in
1048 1048 1049 1049 $(SRC_DIR)/exec_cpu$(O) : $(GENERAL_H_FILES) @TEMP_exec_h@ $(SRC_DIR)/jit_emit.h 1050 1050 1051 $(SRC_DIR)/jit_defs$(O) : $(GENERAL_H_FILES) @TEMP_exec_h@ $(SRC_DIR)/jit_emit.h 1051 $(SRC_DIR)/jit_defs$(O) : $(GENERAL_H_FILES) @TEMP_exec_h@ $(SRC_DIR)/jit_emit.h \ 1052 $(SRC_DIR)/pmc/pmc_fixedintegerarray.h $(SRC_DIR)/pmc/pmc_unmanagedstruct.h 1052 1053 1053 1054 $(INC_DIR)/extend_vtable.h $(SRC_DIR)/extend_vtable.c $(SRC_DIR)/vtable.h : src/vtable.tbl $(BUILD_TOOLS_DIR)/vtable_extend.pl lib/Parrot/Vtable.pm 1054 1055 $(PERL) $(BUILD_TOOLS_DIR)/vtable_extend.pl