Skip to content

Commit

Permalink
Require creation of P5Namespace through proper channels
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Apr 4, 2010
1 parent 5145ceb commit 4c0982a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 37 deletions.
24 changes: 24 additions & 0 deletions src/pmc/p5interpreter.pmc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ These are the vtable functions for the P5Interpreter class.


/* Need to know a bit about other PMCs. */ /* Need to know a bit about other PMCs. */
#include "pmc_p5scalar.h" #include "pmc_p5scalar.h"
#include "pmc_p5namespace.h"
#include "bkmarshal.h" #include "bkmarshal.h"


/* Tracking of whether we've initialized or not. */ /* Tracking of whether we've initialized or not. */
Expand Down Expand Up @@ -160,6 +161,29 @@ Run the Perl 5 code.


return blizkost_return_from_invoke(interp, next); return blizkost_return_from_invoke(interp, next);
} }

/*

=item C<PMC *get_namespace(const char *name)>

Acquire a namespace handle.

=cut

*/

METHOD PMC *get_namespace(STRING *name) {
PMC *pmc = Parrot_pmc_new_noinit(interp, pmc_type(interp,
string_from_literal(interp, "P5Namespace")));
/* Set up the underlying structure. */
PMC_data(pmc) = mem_allocate_zeroed_typed(Parrot_P5Namespace_attributes);
PObj_custom_mark_SET(pmc);
PObj_custom_destroy_SET(pmc);
SETATTR_P5Namespace_p5i(interp, pmc, SELF);
SETATTR_P5Namespace_ns_name(interp, pmc, name);

return pmc;
}
} }


/* /*
Expand Down
41 changes: 4 additions & 37 deletions src/pmc/p5namespace.pmc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,29 +34,13 @@ These are the vtable functions for the P5Namespace class.


pmclass P5Namespace group blizkost_group dynpmc { pmclass P5Namespace group blizkost_group dynpmc {
ATTR PMC *p5i; ATTR PMC *p5i;
ATTR PMC *marshall_cache;
ATTR STRING *ns_name; ATTR STRING *ns_name;


/* VTABLE void init() {

Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_ILL_INHERIT,
=item C<void init()> "P5Namespace values can only be created through an interpreter");

Set up P5Namespace PMC.

=cut

*/

VTABLE void init_pmc(PMC *p5i) {
/* Set up the underlying structure. */
PMC_data(SELF) = mem_allocate_zeroed_typed(Parrot_P5Namespace_attributes);
PObj_custom_mark_SET(SELF);
PObj_custom_destroy_SET(SELF);
SET_ATTR_p5i(interp, SELF, p5i);
SET_ATTR_marshall_cache(interp, SELF, PMCNULL);
} }



/* /*


=item C<void mark()> =item C<void mark()>
Expand All @@ -68,15 +52,12 @@ Mark GC-ables.
*/ */
VTABLE void mark() { VTABLE void mark() {
if (PMC_data(SELF)) { if (PMC_data(SELF)) {
PMC *p5i, *cache; PMC *p5i;
STRING *name; STRING *name;
GET_ATTR_p5i(interp, SELF, p5i); GET_ATTR_p5i(interp, SELF, p5i);
GET_ATTR_marshall_cache(interp, SELF, cache);
GET_ATTR_ns_name(interp, SELF, name); GET_ATTR_ns_name(interp, SELF, name);
if (p5i) if (p5i)
Parrot_gc_mark_PObj_alive(interp, (PObj*)p5i); Parrot_gc_mark_PObj_alive(interp, (PObj*)p5i);
if (cache)
Parrot_gc_mark_PObj_alive(interp, (PObj*)cache);
if (name) if (name)
Parrot_gc_mark_PObj_alive(interp, (PObj*)name); Parrot_gc_mark_PObj_alive(interp, (PObj*)name);
} }
Expand All @@ -97,20 +78,6 @@ Free underlying structure.
mem_sys_free(PMC_data(SELF)); mem_sys_free(PMC_data(SELF));
} }



/*

=item C<void set_string_native(STRING *name)>

Set the name of the Perl 5 namespace that we map to.

=cut

*/
VTABLE void set_string_native(STRING *name) {
SET_ATTR_ns_name(interp, SELF, name);
}

/* /*


=item C<PMC *find_method(STRING *name)> =item C<PMC *find_method(STRING *name)>
Expand Down

0 comments on commit 4c0982a

Please sign in to comment.