Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Teach P6opaque how to align objects properly.
  • Loading branch information
arnsholt committed Feb 2, 2013
1 parent 1531df3 commit 1a8e58a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/6model/reprs/P6opaque.c
Expand Up @@ -216,13 +216,15 @@ static void compute_allocation_strategy_OLD(PARROT_INTERP, PMC *WHAT, P6opaqueRE
/* Work out what unboxed type it is, if any. Default to a boxed. */
INTVAL unboxed_type = STORAGE_SPEC_BP_NONE;
INTVAL bits = sizeof(PMC *) * 8;
INTVAL align = ALIGNOF1(PMC *);
if (!PMC_IS_NULL(type)) {
/* Get the storage spec of the type and see what it wants. */
storage_spec spec = REPR(type)->get_storage_spec(interp, STABLE(type));
if (spec.inlineable == STORAGE_SPEC_INLINED) {
/* Yes, it's something we'll flatten. */
unboxed_type = spec.boxed_primitive;
bits = spec.bits;
align = spec.align;
repr_data->flattened_stables[i] = STABLE(type);

/* Does it need special initialization? */
Expand Down Expand Up @@ -297,8 +299,12 @@ static void compute_allocation_strategy_OLD(PARROT_INTERP, PMC *WHAT, P6opaqueRE
}
}

/* Do allocation. */
/* XXX TODO Alignment! Important when we get int1, int8, etc. */
/* Do allocation. Before updating the size of the structure, we
* make sure the object will be aligned appropriately. */
if (cur_size % align) {
cur_size += align - cur_size % align;
}

repr_data->attribute_offsets[i] = cur_size;
cur_size += bits / 8;
}
Expand Down Expand Up @@ -454,13 +460,15 @@ static void compute_allocation_strategy(PARROT_INTERP, PMC *repr_info, P6opaqueR
/* Work out what unboxed type it is, if any. Default to a boxed. */
INTVAL unboxed_type = STORAGE_SPEC_BP_NONE;
INTVAL bits = sizeof(PMC *) * 8;
INTVAL align = ALIGNOF1(PMC *);
if (!PMC_IS_NULL(type)) {
/* Get the storage spec of the type and see what it wants. */
storage_spec spec = REPR(type)->get_storage_spec(interp, STABLE(type));
if (spec.inlineable == STORAGE_SPEC_INLINED) {
/* Yes, it's something we'll flatten. */
unboxed_type = spec.boxed_primitive;
bits = spec.bits;
align = spec.align;
repr_data->flattened_stables[i] = STABLE(type);

/* Does it need special initialization? */
Expand Down Expand Up @@ -535,8 +543,12 @@ static void compute_allocation_strategy(PARROT_INTERP, PMC *repr_info, P6opaqueR
}
}

/* Do allocation. */
/* XXX TODO Alignment! Important when we get int1, int8, etc. */
/* Do allocation. Before updating the size of the structure, we
* make sure the object will be aligned appropriately. */
if (cur_size % align) {
cur_size += align - cur_size % align;
}

repr_data->attribute_offsets[i] = cur_size;
cur_size += bits / 8;
}
Expand Down

0 comments on commit 1a8e58a

Please sign in to comment.