Guys,

I shall shortly update the relevant calls, but I'd just like to check
a few things first.

These patches update the patches in #37303 and #36836, relating to
parrot_get_config_string and cygwin dynclasses.

The first patch modifies the parrot VM so as not to call
parrot_get_config_string on startup, which currently resides in the
calling executable. Instead, the executable (optionally) calls
Parrot_set_config_hash to set the config environment.

A couple of questions arise:

  * Currently only the interpreter that is explicitly created by the
application will have configuration settings. What's the best way to
make sure that each interpreter will have access to it? Will future
Interpreters clone the environment, or will it explicitly need to be
set on each new interpreter? (If need be, I can preserve the hash in
the VM and seed future interpreters with it)

  * The function call parrot_get_config_hash is shared between the
*_config.o object files and the calling executable (but *not* the VM
itself). What's the most suitable header file to declare it in?

There was talk the other day about whether install_config.o needed to
be distributed in a dev distribution, and while the answer is still
yes, after these changes it becomes up to the application as to
whether it needs to link with it.

A solution to the dynclasses on cygwin (and mingw?) [#36836] issue
becomes possible with these patches, and yesterday's shared library
work. Since (as far as I'm aware) cygwin doesn't have rpath
functionality, it is necessary to add blib/lib to the PATH for it to
find the parrot DLL.

Cheers,

Nick
Index: src/pbc_merge.c
===================================================================
--- src/pbc_merge.c     (revision 10901)
+++ src/pbc_merge.c     (working copy)
@@ -37,7 +37,9 @@
 #include "parrot/embed.h"
 #include "parrot/oplib/ops.h"
 
+extern PMC* parrot_get_config_hash(Interp* interpreter);
 
+
 /* This struct describes an input file. */
 struct pbc_merge_input
 {
@@ -725,6 +727,8 @@
     Parrot_init(interpreter);
     Parrot_block_DOD(interpreter);
 
+    Parrot_set_config_hash (interpreter, parrot_get_config_hash (interpreter));
+
     /* Get options, ensuring we have at least one input
        file and an output file. */
     if (argc < 4) {
Index: src/global_setup.c
===================================================================
--- src/global_setup.c  (revision 10901)
+++ src/global_setup.c  (working copy)
@@ -28,21 +28,6 @@
 /* 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)
-{
-    STRING *config = parrot_get_config_string(interpreter);
-    PMC *hash;
-
-    if (config) {
-        hash = Parrot_thaw(interpreter, config);
-    }
-    else
-        hash = pmc_new(interpreter, enum_class_Hash);
-    VTABLE_set_pmc_keyed_int(interpreter, iglobals,
-            (INTVAL) IGLOBALS_CONFIG_HASH, hash);
-
-}
 /*
 
 =item C<void init_world(Interp *interpreter)>
@@ -63,8 +48,8 @@
 void
 init_world(Interp *interpreter)
 {
-    PMC *iglobals;
     PMC *self, *pmc;
+    PMC *iglobals, *config_hash;
 
 #ifdef PARROT_HAS_PLATFORM_INIT_CODE
     Parrot_platform_init_code();
@@ -91,11 +76,14 @@
     PMC_data(self) = interpreter;
     VTABLE_set_pmc_keyed_int(interpreter, iglobals,
             (INTVAL) IGLOBALS_INTERPRETER, self);
+
+    /* Initialise the Interpreter with an empty config
+       hash. Applications will call Parrot_set_config_hash */
+    config_hash = pmc_new(interpreter, enum_class_Hash);
+    VTABLE_set_pmc_keyed_int(interpreter, iglobals,
+            (INTVAL) IGLOBALS_CONFIG_HASH, config_hash);
+
     /*
-     * create runtime config hash
-     */
-    create_config_hash(interpreter, iglobals);
-    /*
      * HLL support
      */
     if (interpreter->parent_interpreter)
@@ -121,6 +109,16 @@
             IGLOBALS_DYN_LIBS, pmc);
 }
 
+
+void Parrot_set_config_hash(Interp* interpreter, PMC * config_hash)
+{
+    PMC *iglobals = interpreter->iglobals;
+
+    VTABLE_set_pmc_keyed_int(interpreter, iglobals,
+            (INTVAL) IGLOBALS_CONFIG_HASH, config_hash);
+}
+
+
 /*
 
 =back
Index: tools/build/parrot_config_c.pl
===================================================================
--- tools/build/parrot_config_c.pl      (revision 10901)
+++ 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,18 +17,22 @@
 
 =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.
+Calling the generated parrot_get_config_hash function returns a hash
+table which can be passed to Parrot_set_config_hash.
 
+For miniparrot an empty hash is created.
+
 =cut
 
 
 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";
@@ -43,19 +47,38 @@
 
 #include "parrot/parrot.h"
 
-static const unsigned char parrot_config[] = {
+/* This needs to reside in a header file outside the core VM */
+extern PMC* parrot_get_config_hash(Interp* interpreter);
+
+
 EOF
 
 if ($mini_parrot) {
-    print "    0\n";
+
+    print << "EOF";
+
+PMC*
+parrot_get_config_hash(Interp* interpreter)
+{
+    return pmc_new(interpreter, enum_class_Hash);
 }
-else {
+
+EOF
+}
+else
+{
+    print << "EOF"
+
+static const unsigned char parrot_config[] = {
+EOF
+;
+
     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 '';
@@ -68,22 +91,22 @@
        print "\n    " unless $i % 8;
     }
     print "\n";
-}
 
 print << "EOF";
 }; /* parrot_config */
 
-STRING*
-parrot_get_config_string(Interp* interpreter)
+
+PMC*
+parrot_get_config_hash (Interp* interpreter)
 {
-    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);
+    STRING *config_string =  string_make_direct(interpreter,
+           parrot_config, sizeof(parrot_config),
+           PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET,
+           PObj_external_FLAG|PObj_constant_FLAG);
 
+    return Parrot_thaw(interpreter, config_string);
 }
+
 EOF
 
-
+}
Index: include/parrot/interpreter.h
===================================================================
--- include/parrot/interpreter.h        (revision 10901)
+++ include/parrot/interpreter.h        (working copy)
@@ -431,6 +431,8 @@
 void Parrot_init(Interp *);
 void Parrot_destroy(Interp *);
 
+void Parrot_set_config_hash(Interp*, PMC *);
+
 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 10901)
+++ 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 10901)
+++ compilers/imcc/main.c       (working copy)
@@ -26,6 +26,8 @@
 static char optimizer_opt[20];
 extern FILE *yyin;
 
+extern PMC* parrot_get_config_hash(Interp* interpreter);
+
 static void
 usage(FILE* fp)
 {
@@ -459,6 +461,8 @@
 
     Parrot_init(interp);
 
+    Parrot_set_config_hash (interp, parrot_get_config_hash (interp));
+
     Parrot_block_DOD(interp);
     Parrot_block_GC(interp);
 
Index: config/gen/makefiles/root.in
===================================================================
--- config/gen/makefiles/root.in        (revision 10901)
+++ config/gen/makefiles/root.in        (working copy)
@@ -781,13 +781,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)
 
 #
@@ -799,13 +797,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)
 
 #
@@ -815,13 +811,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)
 
 
@@ -829,13 +823,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)
 
 #


Index: config/gen/makefiles/dynclasses_pl.in
===================================================================
--- config/gen/makefiles/dynclasses_pl.in       (revision 10901)
+++ config/gen/makefiles/dynclasses_pl.in       (working copy)
@@ -18,19 +18,17 @@
 use File::Copy qw(copy);
 
 # qq[] isn't guaranteed to work, but it's safer than "" as some platforms
-# (eg FreeBSD) have ""s embedded in their substution values. q[] is used in
+# (eg FreeBSD) have ""s embedded in their substitution values. q[] is used in
 # some places as Win32 paths have \'s in, which qq[] treats as escape 
sequences.
 # Config stuff
+our $PERL = q[${perl}];
 our $CC = qq[${cc} -c];
 our $LD = qq[${ld}];
 our $LDFLAGS = qq[${ldflags} ${ld_debug}];
 our $LD_LOAD_FLAGS = qq[${ld_load_flags}];
-our $PERL = q[${perl}];
 our $LOAD_EXT = qq[${load_ext}];
 our $O = qq[${o}];
-our $LIBPARROT = qq[${build_dir}/src/extend${o}];
-    # XXX: ultimately, this should be replaced with:
-    #  $LIBPARROT = qq[-L../blib/lib -lparrot];
+our $LIBPARROT = qq[-L${build_dir}${slash}${blib_dir} -lparrot];
 our $CFLAGS = qq[${ccflags} ${cc_shared} ${cc_debug} ${ccwarn} ${cc_hasjit} 
${cg_flag} ${gc_flag} ${cc_building_dynclass_flag}];
 
 # Here comes some stuff for Win32.
Index: config/init/hints/cygwin.pm
===================================================================
--- config/init/hints/cygwin.pm (revision 10901)
+++ config/init/hints/cygwin.pm (working copy)
@@ -21,10 +21,11 @@
     # If this later causes problems, it might be worth revisiting.
     # A. Dougherty 9/9/2002
     $conf->data->set(
-        ld             => 'gcc',
-        ld_share_flags => '-shared',
-        ld_load_flags  => '-shared',
-        libs           => $libs,
+        ld                  => 'gcc',
+        ld_share_flags      => '-shared',
+        ld_load_flags       => '-shared',
+        libs                => $libs,
+        libparrot_is_shared => 1
     );
 
     # We need to define inet_aton on Cygwin.  The contents of the --define


Reply via email to