Navigation Menu

Skip to content

Commit

Permalink
Add a new IGLOBALS_LOADED_PBCS global to be a cache for load_bytecode…
Browse files Browse the repository at this point in the history
…_p_s. Add a ->path attr to packfile view to optionally hold the string path of the packfile, if it was loaded from a file with load_bytecode_p_s
  • Loading branch information
Whiteknight committed Jul 25, 2011
1 parent 05b0911 commit 0a84eb7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/parrot/interpreter.h
Expand Up @@ -280,6 +280,7 @@ typedef enum {
IGLOBALS_LIB_PATHS, /* LoL of search paths and dynamic ext */
IGLOBALS_PBC_LIBS, /* Hash of load_bytecode cde */
IGLOBALS_EXECUTABLE, /* How Parrot was invoked (from argv[0]) */
IGLOBALS_LOADED_PBCS, /* Hash of .pbc file -> PackfileView */

IGLOBALS_SIZE
} iglobals_enum;
Expand Down
3 changes: 3 additions & 0 deletions src/global_setup.c
Expand Up @@ -205,6 +205,9 @@ init_world(PARROT_INTERP)
pmc = Parrot_pmc_new(interp, enum_class_Hash);
VTABLE_set_pmc_keyed_int(interp, iglobals, IGLOBALS_PBC_LIBS, pmc);

pmc = Parrot_pmc_new(interp, enum_class_Hash);
VTABLE_set_pmc_keyed_int(interp, iglobals, IGLOBALS_LOADED_PBCS, pmc);

pmc = Parrot_pmc_new(interp, enum_class_Hash);
VTABLE_set_pmc_keyed_int(interp, iglobals, IGLOBALS_DYN_LIBS, pmc);

Expand Down
15 changes: 12 additions & 3 deletions src/packfile/api.c
Expand Up @@ -2352,9 +2352,18 @@ Parrot_pf_load_bytecode_search(PARROT_INTERP, ARGIN(STRING *file))
{
ASSERT_ARGS(Parrot_pf_load_bytecode_search)
const enum_runtime_ft file_type = PARROT_RUNTIME_FT_PBC;
STRING * const path = Parrot_locate_runtime_file_str(interp, file, file_type);
PackFile * const pf = Parrot_pf_read_pbc_file(interp, path);
return Parrot_pf_get_packfile_pmc(interp, pf);
PMC * const pbc_cache = VTABLE_get_pmc_keyed_int(interp,
interp->iglobals, IGLOBALS_LOADED_PBCS);
if (VTABLE_exists_keyed_str(interp, pbc_cache, file))
return VTABLE_get_pmc_keyed_str(interp, pbc_cache, file);
else {
STRING * const path = Parrot_locate_runtime_file_str(interp, file, file_type);
PackFile * const pf = Parrot_pf_read_pbc_file(interp, path);
PMC * const pfview = Parrot_pf_get_packfile_pmc(interp, pf);
VTABLE_set_string_native(interp, pfview, path);
VTABLE_set_pmc_keyed_str(interp, pbc_cache, file, pfview);
return pfview;
}
}

/*
Expand Down
25 changes: 25 additions & 0 deletions src/pmc/packfileview.pmc
Expand Up @@ -65,6 +65,7 @@ get_const_table(PARROT_INTERP, ARGIN(PMC * self))

pmclass PackfileView auto_attrs {
ATTR PackFile * pf;
ATTR STRING * path;

/*

Expand All @@ -89,6 +90,8 @@ Mark the PMC and the PackFile* contents
PARROT_PACKFILEVIEW(SELF);
if (attrs->pf != NULL)
Parrot_pf_mark_packfile(INTERP, attrs->pf);
if (!STRING_IS_NULL(attrs->path))
Parrot_gc_mark_STRING_alive(INTERP, attrs->path);
}

VTABLE void init() {
Expand Down Expand Up @@ -154,6 +157,28 @@ otherwise.

/*

=item C<VTABLE void set_string_native(STRING *path)>

=item C<VTABLE STRING *get_string_native(STRING *path)>

=cut

*/

VTABLE void set_string_native(STRING * path) {
Parrot_PackfileView_attributes * const attrs =
PARROT_PACKFILEVIEW(SELF);
attrs->path = path;
}

VTABLE STRING * get_string_native() {
Parrot_PackfileView_attributes * const attrs =
PARROT_PACKFILEVIEW(SELF);
return attrs->path ? attrs->path : STRINGNULL;
}

/*

=item C<VTABLE PMC *get_pmc_keyed_int(INTVAL idx)>

Get a PMC from the constants table, by index
Expand Down

0 comments on commit 0a84eb7

Please sign in to comment.