Skip to content

Commit

Permalink
Merge branch 'leto/get_pointer'
Browse files Browse the repository at this point in the history
  • Loading branch information
leto committed Aug 28, 2012
2 parents 35ddd64 + 6bdfd32 commit 67d6238
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/pmc/float.pmc
Expand Up @@ -58,6 +58,21 @@ Make an exact copy of this PMC.

/*

=item C<void *get_pointer()>

Return the memory address of an Float PMC. This is needed for certain NCI
applications and may be disabled in certain security contexts.

=cut

*/

VTABLE void *get_pointer() {
return &(PARROT_FLOAT(SELF)->fv);
}

/*

=item C<FLOATVAL get_number()>

Returns the value of the number.
Expand Down
16 changes: 16 additions & 0 deletions src/pmc/integer.pmc
Expand Up @@ -132,6 +132,8 @@ Initializes the integer with a default value of C<0>.

/*



=item C<PMC *clone()>

Creates an exact duplicate of this PMC.
Expand All @@ -143,6 +145,20 @@ Creates an exact duplicate of this PMC.
return Parrot_pmc_new_init_int(INTERP, SELF->vtable->base_type,
SELF.get_integer());
}
/*

=item C<void *get_pointer()>

Return the memory address of an Integer PMC. This is needed for certain NCI
applications and may be disabled in certain security contexts.

=cut

*/

VTABLE void *get_pointer() {
return &(PARROT_INTEGER(SELF)->iv);
}

/*

Expand Down
33 changes: 32 additions & 1 deletion t/src/extend_vtable.t
Expand Up @@ -14,7 +14,7 @@ my $parrot_config = "parrot_config" . $PConfig{o};
plan skip_all => 'src/parrot_config.o does not exist' unless -e catfile("src", $parrot_config);


plan tests => 133;
plan tests => 134;

=head1 NAME
Expand Down Expand Up @@ -187,6 +187,36 @@ CODE
}
# actual tests start here

extend_vtable_output_is(<<'CODE', <<'OUTPUT', "Parrot_PMC_get_pointer");
integer = (Parrot_Int) Parrot_PMC_get_pointer(interp, pmc);
if (integer != NULL)
Parrot_printf(interp,"get_pointer on Integer PMC is non-null!\n");
integer = (Parrot_Int) Parrot_PMC_get_pointer(interp, pmc_float);
if (integer != NULL)
Parrot_printf(interp,"get_pointer on Float PMC is non-null!\n");
/* Now give them values and verify stuff still works */
Parrot_PMC_set_integer_native(interp, pmc, 42);
Parrot_PMC_set_number_native(interp, pmc_float, 42.0);
integer = (Parrot_Int) Parrot_PMC_get_pointer(interp, pmc);
if (integer != NULL)
Parrot_printf(interp,"get_pointer on Integer PMC is non-null!\n");
integer = (Parrot_Int) Parrot_PMC_get_pointer(interp, pmc_float);
if (integer != NULL)
Parrot_printf(interp,"get_pointer on Float PMC is non-null!\n");
CODE
get_pointer on Integer PMC is non-null!
get_pointer on Float PMC is non-null!
get_pointer on Integer PMC is non-null!
get_pointer on Float PMC is non-null!
Done!
OUTPUT

extend_vtable_output_is(<<'CODE', <<'OUTPUT', "Parrot_ext_try coverage");
type = Parrot_PMC_typenum(interp, "Object");
klass = Parrot_pmc_new(interp, type);
Expand Down Expand Up @@ -915,6 +945,7 @@ Done!
OUTPUT



extend_vtable_output_is(<<'CODE', <<'OUTPUT', "Parrot_PMC_get_pointer_keyed");
Parrot_PMC_set_integer_native(interp, pmc, 42);
Parrot_PMC_set_integer_native(interp, pmc2, 99);
Expand Down

0 comments on commit 67d6238

Please sign in to comment.