Permalink
Browse files

add in a new packfile api function to get the main Sub from a PBC pmc…

…. Use this from the embedding API to get the main sub
  • Loading branch information...
1 parent 9c08d31 commit d7b325800417ba8bb7b207df933833bf665572ba @Whiteknight Whiteknight committed Apr 25, 2011
Showing with 25 additions and 1 deletion.
  1. +9 −0 include/parrot/packfile.h
  2. +1 −1 src/embed/api.c
  3. +15 −0 src/packfile/api.c
@@ -851,6 +851,11 @@ PARROT_CANNOT_RETURN_NULL
PMC * Parrot_pf_get_current_packfile(PARROT_INTERP)
__attribute__nonnull__(1);
+PARROT_CANNOT_RETURN_NULL
+PMC * Parrot_pf_get_packfile_main_sub(PARROT_INTERP, ARGIN(PMC * pbc))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
void Parrot_pf_mark_packfile(PARROT_INTERP, ARGMOD_NULLOK(PackFile * pf))
__attribute__nonnull__(1)
FUNC_MODIFIES(* pf);
@@ -998,6 +1003,10 @@ void Parrot_pf_mark_packfile(PARROT_INTERP, ARGMOD_NULLOK(PackFile * pf))
#define ASSERT_ARGS_Parrot_pf_get_current_packfile \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_Parrot_pf_get_packfile_main_sub \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(pbc))
#define ASSERT_ARGS_Parrot_pf_mark_packfile __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
View
@@ -411,7 +411,7 @@ Parrot_api_ready_bytecode(Parrot_PMC interp_pmc, Parrot_PMC pbc,
Parrot_pf_set_current_packfile(interp, pbc);
PackFile_fixup_subs(interp, PBC_MAIN, NULL);
- *main_sub = Parrot_pcc_get_sub(interp, CURRENT_CONTEXT(interp));
+ *main_sub = Parrot_pf_get_packfile_main_sub(interp, pbc);
Parrot_pcc_set_constants(interp, interp->ctx, interp->code->const_table);
EMBED_API_CALLOUT(interp_pmc, interp)
}
View
@@ -870,6 +870,10 @@ Parrot_pf_mark_packfile(PARROT_INTERP, ARGMOD_NULLOK(PackFile * pf))
/*
+=item C<PMC * Parrot_pf_get_packfile_main_sub(PARROT_INTERP, PMC * pbc)>
+
+Get the main function of the bytecode segment, if any.
+
=item C<static PMC * packfile_main(PackFile_ByteCode *bc)>
Access the main function of a bytecode segment.
@@ -878,6 +882,17 @@ Access the main function of a bytecode segment.
*/
+PARROT_CANNOT_RETURN_NULL
+PMC *
+Parrot_pf_get_packfile_main_sub(PARROT_INTERP, ARGIN(PMC * pbc))
+{
+ PackFile * const pf = (PackFile*)VTABLE_get_pointer(interp, pbc);
+ if (pf == NULL || pf->cur_cs == NULL || pf->cur_cs->const_table == NULL)
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNEXPECTED_NULL,
+ "Null or invalid PackFile");
+ return packfile_main(pf->cur_cs);
+}
+
PARROT_CANNOT_RETURN_NULL
static PMC *
packfile_main(ARGIN(PackFile_ByteCode *bc))

0 comments on commit d7b3258

Please sign in to comment.