Skip to content

Instantly share code, notes, and snippets.

@jnthn
Created June 18, 2010 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnthn/443011 to your computer and use it in GitHub Desktop.
Save jnthn/443011 to your computer and use it in GitHub Desktop.
Index: src/oo.c
===================================================================
--- src/oo.c (revision 47640)
+++ src/oo.c (working copy)
@@ -268,14 +268,17 @@
/* Now clone attributes list.class. */
cloned_guts = (Parrot_Object_attributes *) PMC_data(cloned);
cloned_guts->_class = obj->_class;
- cloned_guts->attrib_store = VTABLE_clone(interp, obj->attrib_store);
- num_attrs = VTABLE_elements(interp, cloned_guts->attrib_store);
+ num_attrs = VTABLE_elements(interp, PARROT_CLASS(obj->_class)->attrib_index);
+ cloned_guts->attrib_store = mem_sys_allocate(sizeof(PMC *) * num_attrs);
+
for (i = 0; i < num_attrs; ++i) {
- PMC * const to_clone = VTABLE_get_pmc_keyed_int(interp, cloned_guts->attrib_store, i);
+ PMC * const to_clone = obj->attrib_store[i];
if (!PMC_IS_NULL(to_clone)) {
- VTABLE_set_pmc_keyed_int(interp, cloned_guts->attrib_store, i,
- VTABLE_clone(interp, to_clone));
+ cloned_guts->attrib_store[i] = VTABLE_clone(interp, to_clone);
}
+ else {
+ cloned_guts->attrib_store[i] = to_clone;
+ }
}
/* Some of the attributes may have been the PMCs providing storage for any
Index: src/pmc/class.pmc
===================================================================
--- src/pmc/class.pmc (revision 47640)
+++ src/pmc/class.pmc (working copy)
@@ -1288,8 +1288,12 @@
{
Parrot_Object_attributes * const objattr =
PMC_data_typed(object, Parrot_Object_attributes *);
+ INTVAL num_attrs = VTABLE_elements(INTERP, _class->attrib_index);
+ INTVAL i;
objattr->_class = SELF;
- objattr->attrib_store = Parrot_pmc_new(INTERP, enum_class_ResizablePMCArray);
+ objattr->attrib_store = mem_sys_allocate(sizeof(PMC *) * num_attrs);
+ for (i = 0; i < num_attrs; i++)
+ objattr->attrib_store[i] = PMCNULL;
}
if (!PMC_IS_NULL(init)) {
Index: src/pmc/object.pmc
===================================================================
--- src/pmc/object.pmc (revision 47640)
+++ src/pmc/object.pmc (working copy)
@@ -204,8 +204,8 @@
}
pmclass Object auto_attrs {
- ATTR PMC *_class; /* The class this is an instance of. */
- ATTR PMC *attrib_store; /* The attributes store - a resizable PMC array. */
+ ATTR PMC *_class; /* The class this is an instance of. */
+ ATTR PMC **attrib_store; /* The attributes store - a C array of PMCs. */
/*
@@ -248,6 +248,11 @@
*/
VTABLE void destroy() {
+ if (PARROT_OBJECT(SELF)) {
+ Parrot_Object_attributes * const obj = PARROT_OBJECT(SELF);
+ mem_sys_free(obj->attrib_store);
+ obj->attrib_store = NULL;
+ }
}
/*
@@ -289,9 +294,12 @@
VTABLE void mark() {
if (PARROT_OBJECT(SELF)) {
Parrot_Object_attributes * const obj = PARROT_OBJECT(SELF);
+ INTVAL i;
Parrot_gc_mark_PMC_alive(INTERP, obj->_class);
- Parrot_gc_mark_PMC_alive(INTERP, obj->attrib_store);
+
+ for (i = 0; i < VTABLE_elements(interp, PARROT_CLASS(obj->_class)->attrib_index); i++)
+ Parrot_gc_mark_PMC_alive(INTERP, obj->attrib_store[i]);
}
}
@@ -329,7 +337,7 @@
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ATTRIB_NOT_FOUND,
"No such attribute '%S'", name);
- return VTABLE_get_pmc_keyed_int(INTERP, obj->attrib_store, index);
+ return obj->attrib_store[index];
}
/*
@@ -354,7 +362,7 @@
"No such attribute '%S' in class '%S'", name,
VTABLE_get_string(INTERP, key));
- return VTABLE_get_pmc_keyed_int(INTERP, obj->attrib_store, index);
+ return obj->attrib_store[index];
}
/*
@@ -388,7 +396,7 @@
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ATTRIB_NOT_FOUND,
"No such attribute '%S'", name);
- VTABLE_set_pmc_keyed_int(INTERP, obj->attrib_store, index, value);
+ obj->attrib_store[index] = value;
}
/*
@@ -411,7 +419,7 @@
"No such attribute '%S' in class '%S'", name,
VTABLE_get_string(INTERP, key));
- VTABLE_set_pmc_keyed_int(INTERP, obj->attrib_store, index, value);
+ obj->attrib_store[index] = value;
}
/*
@@ -807,12 +815,14 @@
VTABLE void visit(PMC *info) {
Parrot_Object_attributes * const obj_data = PARROT_OBJECT(SELF);
+ INTVAL i;
/* 1) visit class */
VISIT_PMC(INTERP, info, obj_data->_class);
/* 2) visit the attributes */
- VISIT_PMC(INTERP, info, obj_data->attrib_store);
+ for (i = 0; i < VTABLE_elements(INTERP, PARROT_CLASS(obj_data->_class)->attrib_index); i++)
+ VISIT_PMC(INTERP, info, obj_data->attrib_store[i]);
}
/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment