Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix two brainos.
One in P6int.c; if you're gonna reset the bit value to the default just before
returning, you're gonna have a bad time.
Another in CStruct.c; ensuring proper alignment wasn't done properly.
  • Loading branch information
arnsholt committed Jan 28, 2013
1 parent a20d952 commit b4e360b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/6model/reprs/CStruct.c
Expand Up @@ -212,7 +212,6 @@ static void compute_allocation_strategy(PARROT_INTERP, PMC *WHAT, CStructREPRDat
* that get_attribute_ref can find it later. */
bits = spec.bits;
align = spec.align;
printf("bits: %ld\n", bits);
repr_data->attribute_locations[i] = (bits << CSTRUCT_ATTR_SHIFT) | CSTRUCT_ATTR_IN_STRUCT;
repr_data->flattened_stables[i] = STABLE(type);
if (REPR(type)->initialize) {
Expand Down Expand Up @@ -257,8 +256,12 @@ static void compute_allocation_strategy(PARROT_INTERP, PMC *WHAT, CStructREPRDat
}

/* Do allocation. */
/* C structure needs careful alignment */
cur_size += cur_size % align;
/* C structure needs careful alignment. If cur_size is not aligned
* to align bytes (cur_size % align), make sure it is before we
* add the next element. */
if (cur_size % align) {
cur_size += align - cur_size % align;
}

repr_data->struct_offsets[i] = cur_size;
cur_size += bits / 8;
Expand Down
6 changes: 3 additions & 3 deletions src/6model/reprs/P6int.c
Expand Up @@ -43,16 +43,16 @@ static void compose(PARROT_INTERP, STable *st, PMC *repr_info) {
P6intREPRData *repr_data = (P6intREPRData *) st->REPR_data;
PMC *integer = VTABLE_get_pmc_keyed_str(interp, repr_info,
Parrot_str_new_constant(interp, "integer"));
INTVAL bits = sizeof(INTVAL)*8;

repr_data->bits = sizeof(INTVAL)*8;
if(!PMC_IS_NULL(integer)) {
/* TODO: Handle possible unsigned key. How to handle it though, since
* Parrot's INTVAL is inherently signed? */
/* XXX: I should probably handle the case where no "bits" key is set
* as well, which would set it to 0 (I think?). */
repr_data->bits = VTABLE_get_integer_keyed_str(interp, integer,
Parrot_str_new_constant(interp, "bits"));
}

repr_data->bits = bits;
}

/* Creates a new instance based on the type object. */
Expand Down

0 comments on commit b4e360b

Please sign in to comment.