Re: cvs commit: parrot/t/pmc freeze.t

1 view
Skip to first unread message

Leopold Toetsch

unread,
Mar 30, 2005, 2:11:51 AM3/30/05
to Bernhard Schmalhofer, perl6-i...@perl.org
Bernhard Schmalhofer <bern...@cvs.perl.org> wrote:
> + void freeze(visit_info *info) {
> + IMAGE_IO *io = info->image_io;
> + io->vtable->push_integer(INTERP, io, PMC_int_val(SELF));
> + STRING * s = string_from_cstring(INTERP, PMC_data(SELF), PMC_int_val2(SELF)/BITS_PER_CHAR);
> + io->vtable->push_string(INTERP, io, s);
> + }

Hehe. Clever trick.

leo

PS nitpick: C89 doesn't allow the declaration of STRING *s after a
statement.

Nicholas Clark

unread,
Mar 30, 2005, 12:15:42 PM3/30/05
to Leopold Toetsch, Bernhard Schmalhofer, perl6-i...@perl.org
On Wed, Mar 30, 2005 at 09:11:51AM +0200, Leopold Toetsch wrote:
> Bernhard Schmalhofer <bern...@cvs.perl.org> wrote:
> > + void freeze(visit_info *info) {
> > + IMAGE_IO *io = info->image_io;
> > + io->vtable->push_integer(INTERP, io, PMC_int_val(SELF));
> > + STRING * s = string_from_cstring(INTERP, PMC_data(SELF), PMC_int_val2(SELF)/BITS_PER_CHAR);
> > + io->vtable->push_string(INTERP, io, s);
> > + }
>
> Hehe. Clever trick.

Could one of you explain how this works? I've tried to work it out and it's
not obvious to me.

Nicholas Clark

Leopold Toetsch

unread,
Mar 31, 2005, 2:49:25 AM3/31/05
to Nicholas Clark, perl6-i...@perl.org

The C<freeze> vtable appends an INTVAL (the array size) and the the bit
image of the bit array as a STRING to the frozen image. PMC_int_val2 is
the rounded up value of bits allocated. The C<string_from_cstring>
creates just a string header, with the string memory pointing to the bit
image.

NB, if the array was shrinked, the rounded up value of the array size
would be more efficient.

> Nicholas Clark

leo

Reply all
Reply to author
Forward
0 new messages