Skip to content

Commit

Permalink
Add Parrot_api_pmc_[get|set]_keyed_int to the embedded API.
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlum committed Dec 17, 2010
1 parent 9f2ff29 commit df005fa
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/parrot/api.h
Expand Up @@ -448,6 +448,15 @@ Parrot_Int Parrot_api_pmc_get_integer(
__attribute__nonnull__(3)
FUNC_MODIFIES(* value);

PARROT_API
Parrot_Int Parrot_api_pmc_get_keyed_int(
Parrot_PMC interp_pmc,
Parrot_PMC pmc,
Parrot_Int key,
ARGOUT(Parrot_PMC * value))
__attribute__nonnull__(4)
FUNC_MODIFIES(* value);

PARROT_API
Parrot_Int Parrot_api_pmc_get_string(
Parrot_PMC interp_pmc,
Expand Down Expand Up @@ -475,6 +484,13 @@ Parrot_Int Parrot_api_pmc_set_integer(
Parrot_PMC pmc,
Parrot_Int value);

PARROT_API
Parrot_Int Parrot_api_pmc_set_keyed_int(
Parrot_PMC interp_pmc,
Parrot_PMC pmc,
Parrot_Int key,
Parrot_PMC value);

PARROT_API
Parrot_Int Parrot_api_pmc_set_string(
Parrot_PMC interp_pmc,
Expand All @@ -495,12 +511,15 @@ Parrot_Int Parrot_api_pmc_set_string(
PARROT_ASSERT_ARG(value))
#define ASSERT_ARGS_Parrot_api_pmc_get_integer __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(value))
#define ASSERT_ARGS_Parrot_api_pmc_get_keyed_int __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(value))
#define ASSERT_ARGS_Parrot_api_pmc_get_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(str))
#define ASSERT_ARGS_Parrot_api_pmc_null __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(pmctonull))
#define ASSERT_ARGS_Parrot_api_pmc_set_float __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_Parrot_api_pmc_set_integer __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_Parrot_api_pmc_set_keyed_int __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_Parrot_api_pmc_set_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/embed/pmc.c */
Expand Down
20 changes: 20 additions & 0 deletions src/embed/pmc.c
Expand Up @@ -66,6 +66,16 @@ Parrot_api_pmc_get_float(Parrot_PMC interp_pmc, Parrot_PMC pmc,
EMBED_API_CALLOUT(interp_pmc, interp)
}

PARROT_API
Parrot_Int
Parrot_api_pmc_get_keyed_int(Parrot_PMC interp_pmc, Parrot_PMC pmc,
Parrot_Int key, ARGOUT(Parrot_PMC * value))
{
EMBED_API_CALLIN(interp_pmc, interp)
*value = VTABLE_get_pmc_keyed_int(interp, pmc, key);
EMBED_API_CALLOUT(interp_pmc, interp)
}

PARROT_API
Parrot_Int
Parrot_api_pmc_set_string(Parrot_PMC interp_pmc, Parrot_PMC pmc,
Expand Down Expand Up @@ -96,6 +106,16 @@ Parrot_api_pmc_set_float(Parrot_PMC interp_pmc, Parrot_PMC pmc,
EMBED_API_CALLOUT(interp_pmc, interp)
}

PARROT_API
Parrot_Int
Parrot_api_pmc_set_keyed_int(Parrot_PMC interp_pmc, Parrot_PMC pmc,
Parrot_Int key, Parrot_PMC value)
{
EMBED_API_CALLIN(interp_pmc, interp)
VTABLE_set_pmc_keyed_int(interp, pmc, key, value);
EMBED_API_CALLOUT(interp_pmc, interp)
}

PARROT_API
Parrot_Int
Parrot_api_add_exception_handler(Parrot_PMC interp_pmc, Parrot_PMC handler)
Expand Down
86 changes: 86 additions & 0 deletions t/src/embed/pmc.t
@@ -0,0 +1,86 @@
#!perl
# Copyright (C) 2010, Parrot Foundation.

use strict;
use warnings;

use lib qw(. lib ../lib ../../lib );

use Test::More;
use Parrot::Test;
use Parrot::Config;

=head1 NAME
t/src/embed/pmc.t - Parrot API PMC operations
=head1 SYNPOSIS
% prove t/src/embed/pmc.t
=head1 DESCRIPTION
Tests PMC API support.
=cut

plan tests => 1;

c_output_is( <<'CODE', <<'OUTPUT', "get/set_keyed_int" );
#include <parrot/parrot.h>
#include <parrot/embed.h>
#include <parrot/api.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
Parrot_Interp interp = Parrot_new(NULL);
Parrot_PMC interpmc = Parrot_pmc_new(interp, enum_class_ParrotInterpreter);
Parrot_PMC p_str = Parrot_pmc_new(interp, enum_class_String), p_keyedstr = NULL;
Parrot_String s_teststr = NULL, s_outstr = NULL;
Parrot_api_string_import_ascii(interpmc, "I am a string.", &s_teststr);
Parrot_api_pmc_set_string(interpmc, p_str, s_teststr);
Parrot_api_pmc_get_keyed_int(interpmc, p_str, 0, &p_keyedstr);
Parrot_api_pmc_get_string(interpmc, p_keyedstr, &s_outstr);
if (strcmp(Parrot_str_to_cstring(interp, s_outstr), "I") != 0) {
printf("Failed indexing a String PMC\n");
return EXIT_FAILURE;
}
printf("ok 1\n");
Parrot_api_string_import_ascii(interpmc, "i", &s_teststr);
Parrot_api_pmc_set_string(interpmc, p_keyedstr, s_teststr);
Parrot_api_pmc_set_keyed_int(interpmc, p_str, 0, p_keyedstr);
Parrot_api_pmc_get_string(interpmc, p_str, &s_outstr);
if (strcmp(Parrot_str_to_cstring(interp, s_outstr), "i am a string.") != 0) {
printf("Failed int-index setting a String PMC\n");
return EXIT_FAILURE;
}
printf("ok 2\n");
Parrot_pmc_destroy(interp, p_str);
Parrot_pmc_destroy(interp, p_keyedstr);
Parrot_pmc_destroy(interp, interpmc);
return 0;
}
CODE
ok 1
ok 2
OUTPUT

# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4:

0 comments on commit df005fa

Please sign in to comment.