Guys,
I've been wanting to relax the dependency that parrot's core has on
parrot_config. As things stand at the moment, src/global_setup.c makes
a call to parrot_get_config which is linked into the executable itself
by selecting either null_config.o, parrot_config.o or
install_config.o.
Quite a bit of time has passed since I originally set about writing this
patch! I've made some more tweaks and wish for it to be considered for
inclusion. It can certainly wait until after the next release.
Any executable (currently only main.c and pbc_merge.c) which needs the
embedded config environment should call Parrot_set_config_hash /before/
creating an Interpreter. This function is contained in *_config.o, and
so will also need to be linked with.
It shouldn't ever now really be necessary to link with null_config.o,
although miniparrot does for technical reasons (the same code is used
for miniparrot, parrot and installable_parrot).
I am finding that I'm hopeless at coming up with variable and function
names, so you won't get any resistance if they are renamed.
Cheers,
Nick
p.s. This patch has changed quite a bit since a version that would core
dump. If this does core dump for anyone let me see a backtrace -- I did
see one core dump in the thawing calling, so it may be necessary to do
something with the garbage collection.
Index: src/pbc_merge.c
===================================================================
--- src/pbc_merge.c (revision 10929)
+++ src/pbc_merge.c (working copy)
@@ -720,6 +720,8 @@
struct PackFile *merged;
int i;
+ Parrot_set_config_hash ();
+
/* Create a Parrot interpreter. */
interpreter = make_interpreter(NULL, PARROT_NO_FLAGS);
Parrot_init(interpreter);
Index: src/global_setup.c
===================================================================
--- src/global_setup.c (revision 10929)
+++ src/global_setup.c (working copy)
@@ -28,21 +28,69 @@
/* These functions are defined in the auto-generated file core_pmcs.c */
extern void Parrot_initialize_core_pmcs(Interp *interp);
-static void
-create_config_hash(Interp *interpreter, PMC *iglobals)
+static const unsigned char* parrot_config_stored = NULL;
+static unsigned int parrot_config_size_stored = 0;
+
+
+/*
+
+=item C<void
+Parrot_set_config_hash_internal (const unsigned char* parrot_config,
+ unsigned int parrot_config_size)>
+
+Called by Parrot_set_config_hash with the serialised hash which
+will be used in subsequently created Interpreters
+
+=cut
+
+*/
+
+void
+Parrot_set_config_hash_internal (const unsigned char* parrot_config,
+ unsigned int parrot_config_size)
{
- STRING *config = parrot_get_config_string(interpreter);
- PMC *hash;
+ parrot_config_stored = parrot_config;
+ parrot_config_size_stored = parrot_config_size;
+}
- if (config) {
- hash = Parrot_thaw(interpreter, config);
+/*
+
+=item C<void parrot_set_config_hash_interpreter (Interp* interpreter)>
+
+
+Used internally to associate the config hash with an Interpreter
+using the last registered config data.
+
+=cut
+
+*/
+
+static void parrot_set_config_hash_interpreter (Interp* interpreter)
+{
+ PMC *iglobals = interpreter->iglobals;
+
+ PMC *config_hash = NULL;
+
+ if (parrot_config_size_stored > 1)
+ {
+ STRING *config_string =
+ string_make_direct(interpreter,
+ parrot_config_stored, parrot_config_size_stored,
+ PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET,
+ PObj_external_FLAG|PObj_constant_FLAG);
+
+ config_hash = Parrot_thaw(interpreter, config_string);
}
else
- hash = pmc_new(interpreter, enum_class_Hash);
+ {
+ config_hash = pmc_new(interpreter, enum_class_Hash);
+ }
+
VTABLE_set_pmc_keyed_int(interpreter, iglobals,
- (INTVAL) IGLOBALS_CONFIG_HASH, hash);
+ (INTVAL) IGLOBALS_CONFIG_HASH, config_hash);
+}
-}
+
/*
=item C<void init_world(Interp *interpreter)>
@@ -91,11 +139,10 @@
PMC_data(self) = interpreter;
VTABLE_set_pmc_keyed_int(interpreter, iglobals,
(INTVAL) IGLOBALS_INTERPRETER, self);
+
+ parrot_set_config_hash_interpreter (interpreter);
+
/*
- * create runtime config hash
- */
- create_config_hash(interpreter, iglobals);
- /*
* HLL support
*/
if (interpreter->parent_interpreter)
@@ -121,6 +168,7 @@
IGLOBALS_DYN_LIBS, pmc);
}
+
/*
=back
Index: tools/build/parrot_config_c.pl
===================================================================
--- tools/build/parrot_config_c.pl (revision 10929)
+++ tools/build/parrot_config_c.pl (working copy)
@@ -7,7 +7,7 @@
=head1 NAME
-tools/build/parrot_config_c.pl - Create src/parrot_config.c
+tools/build/parrot_config_c.pl - Create src/parrot_config.c and variants
=head1 SYNOPSIS
@@ -17,10 +17,13 @@
=head1 DESCRIPTION
-Create F<src/parrot_config.c> with relevant runtime fro the config
-process. The created string contains a frozen image of the config hash.
+Create F<src/parrot_config.c> with relevant runtime for the config
+process.
-For miniparrot a fake config file is written that contains just the interface.
+The data in the generated configuration file is a serialised hash
+which can be passed to the parrot VM by calling Parrot_set_config_hash
+and will in turn be used to provide the config environment for
+subsequently created Interpreters.
=cut
@@ -28,7 +31,8 @@
use strict;
my ($mini_parrot, $install_parrot);
-$mini_parrot = 1 if (@ARGV && $ARGV[0] =~ /mini/);
+
+$mini_parrot = 1 if (@ARGV && $ARGV[0] =~ /mini/);
$install_parrot = 1 if (@ARGV && $ARGV[0] =~ /install/);
print << "EOF";
@@ -41,31 +45,38 @@
*
*/
-#include "parrot/parrot.h"
+#include "parrot/embed.h"
+void
+Parrot_set_config_hash_internal (const unsigned char* parrot_config,
+ unsigned int parrot_config_size);
+
+
static const unsigned char parrot_config[] = {
EOF
+;
if ($mini_parrot) {
print " 0\n";
}
else {
+
my $image_file = $install_parrot ?
- 'install_config.fpmc' : 'runtime/parrot/include/config.fpmc';
+ 'install_config.fpmc' : 'runtime/parrot/include/config.fpmc';
open F, $image_file or die "Can't read '$image_file': $!";
my $image;
local $/;
- binmode F;
+ binmode F;
$_ = <F>;
close F;
my @c = split '';
printf ' ';
my $i;
for (@c) {
- printf "0x%02x", ord($_);
- ++$i;
- print ', ', if ($i < scalar(@c));
- print "\n " unless $i % 8;
+ printf "0x%02x", ord($_);
+ ++$i;
+ print ', ', if ($i < scalar(@c));
+ print "\n " unless $i % 8;
}
print "\n";
}
@@ -73,17 +84,10 @@
print << "EOF";
}; /* parrot_config */
-STRING*
-parrot_get_config_string(Interp* interpreter)
+
+void Parrot_set_config_hash (void)
{
- if (sizeof(parrot_config) <= 1)
- return NULL;
- return string_make_direct(interpreter,
- parrot_config, sizeof(parrot_config),
- PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET,
- PObj_external_FLAG|PObj_constant_FLAG);
+ Parrot_set_config_hash_internal (parrot_config, sizeof (parrot_config));
+}
-}
EOF
-
-
Index: include/parrot/embed.h
===================================================================
--- include/parrot/embed.h (revision 10929)
+++ include/parrot/embed.h (working copy)
@@ -62,6 +62,11 @@
void Parrot_run_native(Parrot_Interp interpreter, native_func_t func);
+/* Parrot_set_config_hash exists in *_config.o (e.g install_config.o),
+ so if you make this call then you will need to link with it in
+ addition to libparrot */
+void Parrot_set_config_hash(void);
+
int Parrot_revision(void);
#endif /* PARROT_EMBED_H_GUARD */
Index: include/parrot/interpreter.h
===================================================================
--- include/parrot/interpreter.h (revision 10929)
+++ include/parrot/interpreter.h (working copy)
@@ -431,6 +431,8 @@
void Parrot_init(Interp *);
void Parrot_destroy(Interp *);
+void Parrot_set_config_hash_internal(const unsigned char*, unsigned int);
+
INTVAL interpinfo(Interp *interpreter, INTVAL what);
PMC* interpinfo_p(Interp *interpreter, INTVAL what);
STRING*interpinfo_s(Interp *interpreter, INTVAL what);
Index: include/parrot/library.h
===================================================================
--- include/parrot/library.h (revision 10929)
+++ include/parrot/library.h (working copy)
@@ -39,7 +39,6 @@
enum_runtime_ft);
void Parrot_autoload_class(Interp *, STRING *class);
-STRING * parrot_get_config_string(Interp* );
const char* Parrot_get_runtime_prefix(Interp *, STRING **prefix);
void parrot_init_library_paths(Interp *);
STRING * parrot_split_path_ext(Interp* , STRING *in,
Index: compilers/imcc/main.c
===================================================================
--- compilers/imcc/main.c (revision 10929)
+++ compilers/imcc/main.c (working copy)
@@ -455,8 +455,12 @@
char *sourcefile;
const char *output_file;
- Interp *interp = Parrot_new(NULL);
+ Interp *interp;
+ Parrot_set_config_hash ();
+
+ interp = Parrot_new(NULL);
+
Parrot_init(interp);
Parrot_block_DOD(interp);
Index: config/gen/makefiles/root.in
===================================================================
--- config/gen/makefiles/root.in (revision 10929)
+++ config/gen/makefiles/root.in (working copy)
@@ -787,13 +787,11 @@
$(PDB) : $(SRC_DIR)/pdb$(O) $(LIBPARROT)
$(LINK) ${ld_out}$@ \
$(SRC_DIR)/pdb$(O) \
- $(SRC_DIR)/null_config$(O) \
$(LINKFLAGS) ${rpath_blib} $(ALL_PARROT_LIBS)
$(INSTALLABLEPDB) : $(SRC_DIR)/pdb$(O) $(LIBPARROT)
$(LINK) ${ld_out}$@ \
$(SRC_DIR)/pdb$(O) \
- $(SRC_DIR)/install_config$(O) \
$(LINKFLAGS) $(ALL_PARROT_LIBS)
#
@@ -805,13 +803,11 @@
$(DIS) : $(SRC_DIR)/disassemble$(O) $(LIBPARROT)
$(LINK) ${ld_out}$@ \
$(SRC_DIR)/disassemble$(O) \
- $(SRC_DIR)/null_config$(O) \
$(LINKFLAGS) ${rpath_blib} $(ALL_PARROT_LIBS)
$(INSTALLABLEDIS) : $(SRC_DIR)/disassemble$(O) $(LIBPARROT)
$(LINK) ${ld_out}$@ \
$(SRC_DIR)/disassemble$(O) \
- $(SRC_DIR)/install_config$(O) \
$(LINKFLAGS) $(ALL_PARROT_LIBS)
#
@@ -821,13 +817,11 @@
$(PDUMP) : $(SRC_DIR)/pdump$(O) $(SRC_DIR)/packdump$(O) $(LIBPARROT)
$(LINK) ${ld_out}$@ \
$(SRC_DIR)/pdump$(O) \
- $(SRC_DIR)/null_config$(O) \
$(SRC_DIR)/packdump$(O) $(LINKFLAGS) ${rpath_blib} $(ALL_PARROT_LIBS)
$(INSTALLABLEPDUMP) : $(SRC_DIR)/pdump$(O) $(SRC_DIR)/packdump$(O) $(LIBPARROT)
$(LINK) ${ld_out}$@ \
$(SRC_DIR)/pdump$(O) \
- $(SRC_DIR)/install_config$(O) \
$(SRC_DIR)/packdump$(O) $(LINKFLAGS) $(ALL_PARROT_LIBS)
@@ -835,13 +829,11 @@
$(PINFO) : $(SRC_DIR)/pbc_info$(O) $(LIBPARROT)
$(LINK) ${ld_out}$@ \
$(SRC_DIR)/pbc_info$(O) \
- $(SRC_DIR)/null_config$(O) \
$(LINKFLAGS) ${rpath_blib} $(ALL_PARROT_LIBS)
$(INSTALLABLEPINFO) : $(SRC_DIR)/pbc_info$(O) $(LIBPARROT)
$(LINK) ${ld_out}$@ \
$(SRC_DIR)/pbc_info$(O) \
- $(SRC_DIR)/install_config$(O) \
$(LINKFLAGS) $(ALL_PARROT_LIBS)
#