[svn:parrot] r37930 - in trunk: config/gen/makefiles src/jit/i386 src/ops src/pmc tools/build
cotto at svn.parrot.org
cotto at svn.parrot.org
Mon Apr 6 22:35:24 UTC 2009
Author: cotto
Date: Mon Apr 6 22:35:23 2009
New Revision: 37930
URL: https://trac.parrot.org/parrot/changeset/37930
Log:
[PMC] use an ATTR for *ManagedStruct's struct pointer
Modified:
trunk/config/gen/makefiles/root.in
trunk/src/jit/i386/jit_defs.c
trunk/src/ops/core.ops
trunk/src/pmc/managedstruct.pmc
trunk/src/pmc/unmanagedstruct.pmc
trunk/tools/build/nativecall.pl
Modified: trunk/config/gen/makefiles/root.in
==============================================================================
--- trunk/config/gen/makefiles/root.in Mon Apr 6 22:28:04 2009 (r37929)
+++ trunk/config/gen/makefiles/root.in Mon Apr 6 22:35:23 2009 (r37930)
@@ -1058,7 +1058,8 @@
$(SRC_DIR)/exec_cpu$(O) : $(GENERAL_H_FILES) @TEMP_exec_h@ $(SRC_DIR)/jit_emit.h
-$(SRC_DIR)/jit_defs$(O) : $(GENERAL_H_FILES) @TEMP_exec_h@ $(SRC_DIR)/jit_emit.h
+$(SRC_DIR)/jit_defs$(O) : $(GENERAL_H_FILES) @TEMP_exec_h@ $(SRC_DIR)/jit_emit.h \
+ $(SRC_DIR)/pmc/pmc_fixedintegerarray.h $(SRC_DIR)/pmc/pmc_unmanagedstruct.h
$(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
$(PERL) $(BUILD_TOOLS_DIR)/vtable_extend.pl
Modified: trunk/src/jit/i386/jit_defs.c
==============================================================================
--- trunk/src/jit/i386/jit_defs.c Mon Apr 6 22:28:04 2009 (r37929)
+++ trunk/src/jit/i386/jit_defs.c Mon Apr 6 22:35:23 2009 (r37930)
@@ -11,6 +11,7 @@
#include "parrot/hash.h"
#include "parrot/oplib/ops.h"
#include "pmc/pmc_fixedintegerarray.h"
+#include "pmc/pmc_unmanagedstruct.h"
#include "jit.h"
#include "jit_emit.h"
@@ -2394,9 +2395,11 @@
emitm_movl_r_m(interp, pc, emit_EAX, emit_EBP, 0, 1, temp_calls_offset + 8);
/* eax = PMC, get return value into edx */
- /* stuff return value into pmc->data */
- /* mov %edx, (data) %eax */
- emitm_movl_r_m(interp, pc, emit_EDX, emit_EAX, 0, 1, offsetof(struct PMC, data));
+ /* mov data(%eax), %eax
+ mov %edx, ptr(%eax) */
+ emitm_movl_m_r(interp, pc, emit_EAX, emit_EAX, 0, 1, offsetof(struct PMC, data));
+ emitm_movl_r_m(interp, pc, emit_EDX, emit_EAX, 0, 1,
+ offsetof(struct Parrot_UnManagedStruct_attributes, ptr));
/* reset EBP(4) */
emitm_lea_m_r(interp, pc, emit_EAX, emit_EBP, 0, 1, st_offset);
Modified: trunk/src/ops/core.ops
==============================================================================
--- trunk/src/ops/core.ops Mon Apr 6 22:28:04 2009 (r37929)
+++ trunk/src/ops/core.ops Mon Apr 6 22:35:23 2009 (r37930)
@@ -1405,7 +1405,7 @@
/* At this point we have the symbol's address. We just need to build
a PMC with it so we can get and set the value */
$1 = pmc_new(interp, enum_class_UnManagedStruct);
- PMC_data($1) = p;
+ VTABLE_set_pointer(interp, $1, p);
}
Parrot_str_free_cstring(name);
}
Modified: trunk/src/pmc/managedstruct.pmc
==============================================================================
--- trunk/src/pmc/managedstruct.pmc Mon Apr 6 22:28:04 2009 (r37929)
+++ trunk/src/pmc/managedstruct.pmc Mon Apr 6 22:35:23 2009 (r37930)
@@ -35,9 +35,13 @@
*/
VTABLE void init() {
+ Parrot_ManagedStruct_attributes *attrs =
+ mem_allocate_zeroed_typed(Parrot_ManagedStruct_attributes);
PObj_active_destroy_SET(SELF);
PMC_pmc_val(SELF) = NULL;
PMC_int_val(SELF) = 0;
+ PMC_data(SELF) = attrs;
+
}
/*
@@ -66,8 +70,9 @@
*/
VTABLE void destroy() {
- if (PMC_data(SELF))
- mem_sys_free(PMC_data(SELF));
+ if (PARROT_MANAGEDSTRUCT(SELF)->ptr)
+ mem_sys_free(PARROT_MANAGEDSTRUCT(SELF)->ptr);
+ mem_sys_free(PMC_data(SELF));
}
/*
@@ -81,19 +86,19 @@
*/
VTABLE void set_integer_native(INTVAL value) {
- if (PMC_data(SELF) && !value) {
- mem_sys_free(PMC_data(SELF));
- PMC_data(SELF) = NULL;
+ if (PARROT_MANAGEDSTRUCT(SELF)->ptr && !value) {
+ mem_sys_free(PARROT_MANAGEDSTRUCT(SELF)->ptr);
+ PARROT_MANAGEDSTRUCT(SELF)->ptr = NULL;
PMC_int_val(SELF) = 0;
}
- else if (value && !PMC_data(SELF)) {
- PMC_data(SELF) = mem_sys_allocate_zeroed((size_t)value);
+ else if (value && !PARROT_MANAGEDSTRUCT(SELF)->ptr) {
+ PARROT_MANAGEDSTRUCT(SELF)->ptr = mem_sys_allocate_zeroed((size_t)value);
PMC_int_val(SELF) = value;
}
- else if (value && PMC_data(SELF)) {
+ else if (value && PARROT_MANAGEDSTRUCT(SELF)->ptr) {
if (PMC_int_val(SELF) != value) {
- PMC_data(SELF) = mem_sys_realloc(PMC_data(SELF),
- (size_t)value);
+ PARROT_MANAGEDSTRUCT(SELF)->ptr =
+ mem_sys_realloc(PARROT_MANAGEDSTRUCT(SELF)->ptr, (size_t)value);
PMC_int_val(SELF) = value;
}
}
@@ -118,8 +123,9 @@
PMC *dest = pmc_new_init(interp, SELF->vtable->base_type,
PMC_pmc_val(SELF));
- if (PMC_data(SELF))
- memmove(PMC_data(dest), PMC_data(SELF), PMC_int_val(SELF));
+ if (PARROT_MANAGEDSTRUCT(SELF)->ptr)
+ memmove(PARROT_MANAGEDSTRUCT(dest)->ptr,
+ PARROT_MANAGEDSTRUCT(SELF)->ptr, PMC_int_val(SELF));
return dest;
}
Modified: trunk/src/pmc/unmanagedstruct.pmc
==============================================================================
--- trunk/src/pmc/unmanagedstruct.pmc Mon Apr 6 22:28:04 2009 (r37929)
+++ trunk/src/pmc/unmanagedstruct.pmc Mon Apr 6 22:35:23 2009 (r37930)
@@ -63,7 +63,7 @@
offs = (size_t) VTABLE_get_integer_keyed_int(interp,
PMC_pmc_val(pmc), ix + 2);
- return ((char *)PMC_data(pmc)) + offs;
+ return ((char *)VTABLE_get_pointer(interp, pmc)) + offs;
}
/*
@@ -183,16 +183,16 @@
}
if (init->vtable->base_type == enum_class_UnManagedStruct) {
- /* now point PMC_data of this struct to the real data */
+ /* now point ptr to the real data */
if (*type == enum_type_struct_ptr) {
/* that is either a pointer */
PARROT_ASSERT((PTR2INTVAL(p) & (PARROT_PTR_ALIGNMENT - 1)) == 0);
- PMC_data(init) = *(void**)p;
+ VTABLE_set_pointer(interp, init, *(void**)p);
}
/* or just an offset for nested structs */
else
- PMC_data(init) = p;
+ VTABLE_set_pointer(interp, init, p);
}
else if (init->vtable->base_type == enum_class_ManagedStruct
&& *type == enum_type_struct_ptr) {
@@ -201,7 +201,7 @@
* outer struct, the inner is at PMC_data(init) */
PARROT_ASSERT((PTR2INTVAL(p) & (PARROT_PTR_ALIGNMENT - 1)) == 0);
- *(void **)p = PMC_data(init);
+ *(void **)p = VTABLE_get_pointer(interp, init);
}
return char_offset_key(interp, init, next, type);
@@ -411,8 +411,7 @@
"no initializer available for nested struct");
}
- /* assign the pointer */
- PMC_data(ret) = *(void**)p;
+ VTABLE_set_pointer(interp, ret, *(void**)p);
return ret;
default:
@@ -657,6 +656,7 @@
}
pmclass UnManagedStruct need_ext no_ro {
+ ATTR void *ptr; /* whatever this UnManagedStruct isn't managing */
/*
@@ -675,6 +675,10 @@
*/
VTABLE void init() {
+ Parrot_UnManagedStruct_attributes *attrs =
+ mem_allocate_zeroed_typed(Parrot_UnManagedStruct_attributes);
+ PMC_data(SELF) = attrs;
+ attrs->ptr = NULL;
PMC_pmc_val(SELF) = NULL;
}
@@ -707,11 +711,31 @@
*/
VTABLE void init_pmc(PMC *value) {
+ SELF.init();
SELF.set_pmc(value);
}
/*
+=item C<PMC *clone()>
+
+Return a clone of this PMC.
+
+=cut
+
+*/
+
+ VTABLE PMC *clone() {
+ PMC *clone = pmc_new(INTERP, enum_class_UnManagedStruct);
+ mem_sys_memmove(PMC_data(clone), PMC_data(SELF),
+ sizeof (Parrot_UnManagedStruct_attributes));
+ PMC_pmc_val(clone) = VTABLE_clone(INTERP, PMC_pmc_val(SELF));
+ PMC_int_val(clone) = PMC_int_val(SELF);
+ return clone;
+ }
+
+/*
+
=item C<void set_pmc(PMC *value)>
Sets C<*value> (see C<init_pmc()> and calculates the offsets.
@@ -753,7 +777,7 @@
VTABLE INTVAL is_equal(PMC *value) {
return (SELF->vtable == value->vtable
- && PMC_data(SELF) == PMC_data(value));
+ && SELF.get_pointer() == VTABLE_get_pointer(interp, value));
}
/*
@@ -767,7 +791,7 @@
*/
VTABLE INTVAL defined() {
- return PMC_data(SELF) != NULL;
+ return SELF.get_pointer() != NULL;
}
/*
@@ -937,7 +961,7 @@
*/
VTABLE void *get_pointer() {
- return PMC_data(SELF);
+ return PARROT_UNMANAGEDSTRUCT(SELF)->ptr;
}
/*
@@ -951,7 +975,7 @@
*/
VTABLE void set_pointer(void *value) {
- PMC_data(SELF) = value;
+ PARROT_UNMANAGEDSTRUCT(SELF)->ptr = value;
}
/*
Modified: trunk/tools/build/nativecall.pl
==============================================================================
--- trunk/tools/build/nativecall.pl Mon Apr 6 22:28:04 2009 (r37929)
+++ trunk/tools/build/nativecall.pl Mon Apr 6 22:35:23 2009 (r37930)
@@ -43,7 +43,7 @@
as_proto => "void *",
other_decl => "PMC * const final_destination = pmc_new(interp, enum_class_UnManagedStruct);",
sig_char => "P",
- ret_assign => "PMC_data(final_destination) = return_data; set_nci_P(interp, &st, final_destination);",
+ ret_assign => "VTABLE_set_pointer(interp, final_destination, return_data); set_nci_P(interp, &st, final_destination);",
},
i => { as_proto => "int", sig_char => "I" },
l => { as_proto => "long", sig_char => "I" },
@@ -477,7 +477,7 @@
push @{$put_pointer_ref}, <<"PUT_POINTER";
temp_pmc = pmc_new(interp, enum_class_UnManagedStruct);
- PMC_data(temp_pmc) = (void *)$value;
+ VTABLE_set_pointer(interp, temp_pmc, (void *)$value);
VTABLE_set_pmc_keyed_str(interp, HashPointer, CONST_STRING(interp, "$key"), temp_pmc);
PUT_POINTER
@@ -569,7 +569,7 @@
b = VTABLE_get_pmc_keyed_str(interp, HashPointer, signature);
if (b && b->vtable->base_type == enum_class_UnManagedStruct)
- return F2DPTR(PMC_data(b));
+ return F2DPTR(VTABLE_get_pointer(interp, b));
/*
These three lines have been added to aid debugging. I want to be able to
More information about the parrot-commits
mailing list