Here's an updated version of a patch to change how parrot picks up its built-in configuration values. They are currently picked up by the parrot library through globals linked against the executable.

This patch changes the API so that the parrot environment starts without a config (which makes linking pdb, disassemble et al. cleaner) and then the executable can call Parrot_set_config_string to register the environment.

I'd like to thank Francois Perrad for behind-the-scenes involvement on this.

Regards,

Nick

p.s. I've had to make up some variable and file names, so feel free to change them to meet broken conventions. It's the mechanism that I keen to refine (enabling libparrot.so/libparrot.dll to be more easily built on more platforms)
Index: build_tools/parrot_config_c.pl
===================================================================
--- build_tools/parrot_config_c.pl      (revision 9493)
+++ build_tools/parrot_config_c.pl      (working copy)
@@ -7,7 +7,7 @@
 
 =head1 NAME
 
-build_tools/parrot_config_c.pl - Create src/parrot_config.c
+build_tools/parrot_config_c.pl - Create src/parrot_config.c and variants
 
 =head1 SYNOPSIS
 
@@ -41,46 +41,44 @@
  *
  */
 
-#include "parrot/parrot.h"
-
-static const char parrot_config[] = {
 EOF
 
 if ($mini_parrot) {
-    print "    0\n";
+
+    print << "EOF";
+const char* parrot_config_ptr   = 0;
+unsigned int parrot_config_size = 0;
+EOF
 }
-else {
+else
+{
+    print << "EOF";
+static const 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 '';
     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";
-}
 
 print << "EOF";
 }; /* parrot_config */
 
-STRING*
-parrot_get_config_string(Interp* interpreter)
-{
-    if (sizeof(parrot_config) <= 1)
-       return NULL;
-    return string_from_const_cstring(interpreter,
-       parrot_config, sizeof(parrot_config));
-}
+const char* parrot_config_ptr   = parrot_config;
+unsigned int parrot_config_size = sizeof(parrot_config);
 EOF
-
-
+}
Index: src/config.c
===================================================================
--- src/config.c        (revision 0)
+++ src/config.c        (revision 0)
@@ -0,0 +1,63 @@
+/*
+  Copyright: 2005 The Perl Foundation.  All Rights Reserved.
+  $Id$
+
+=head1 NAME
+
+src/config.c - Register configuration bundle with parrot runtime
+
+=head1 DESCRIPTION
+
+The routines in this file can be used to set and retrieve the embedded
+configuration data for the parrot runtime.
+
+There are currently three runtimes:
+
+=over 4
+
+=item * a dummy stub used in minparrot during and other utilities. No
+explicit set is required for this
+
+=item * the default config used during the build
+
+=item * a config profile suitable once parrot has been installed system-wide
+
+=back
+
+=cut
+
+*/
+
+#include "parrot/parrot.h"
+
+static const char  *parrot_config_private_ptr  = NULL;
+static unsigned int parrot_config_private_size = 0;
+
+void
+Parrot_set_config_string(const char*  new_parrot_config_ptr,
+                         unsigned int new_parrot_config_size)
+{
+    parrot_config_private_ptr  = new_parrot_config_ptr;
+    parrot_config_private_size = new_parrot_config_size;
+}
+
+STRING*
+parrot_get_config_string(Interp* interpreter)
+{
+    if (!parrot_config_private_ptr)
+        return NULL;
+
+    return string_from_const_cstring(interpreter,
+                                     parrot_config_private_ptr,
+                                     parrot_config_private_size);
+}
+
+/*
+ * Local variables:
+ * c-indentation-style: bsd
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vim: expandtab shiftwidth=4:
+ */
Index: src/embed.c
===================================================================
--- src/embed.c (revision 9493)
+++ src/embed.c (working copy)
@@ -368,7 +368,7 @@
         }
 
         program_code =
-            mmap(0, program_size, PROT_READ, MAP_SHARED, fd, (off_t)0);
+            mmap(0, program_size, PROT_READ, MAP_PRIVATE, fd, (off_t)0);
 
         if (program_code == (void *)MAP_FAILED) {
             Parrot_warn(interpreter, PARROT_WARNINGS_IO_FLAG,
Index: MANIFEST
===================================================================
--- MANIFEST    (revision 9493)
+++ MANIFEST    (working copy)
@@ -1728,6 +1728,7 @@
 src/exec_save.c                                   []
 src/exec_start.c                                  []
 src/exit.c                                        []
+src/config.c                                      []
 src/extend.c                                      []
 src/gc_gms.c                                      []
 src/gc_ims.c                                      []
Index: imcc/main.c
===================================================================
--- imcc/main.c (revision 9493)
+++ imcc/main.c (working copy)
@@ -455,6 +455,8 @@
     char *sourcefile;
     char *output;
 
+    Parrot_set_config_string(parrot_config_ptr,parrot_config_size);
+
     Interp *interp = Parrot_new(NULL);
 
     Parrot_init(interp);
Index: include/parrot/library.h
===================================================================
--- include/parrot/library.h    (revision 9493)
+++ include/parrot/library.h    (working copy)
@@ -28,6 +28,12 @@
         enum_runtime_ft);
 
 void Parrot_autoload_class(Interp *, STRING *class);
+
+const char*  parrot_config_ptr;
+unsigned int parrot_config_size;
+
+void Parrot_set_config_string(const char*  new_parrot_config_ptr,
+                             unsigned int new_parrot_config_size);
 STRING * parrot_get_config_string(Interp* );
 const char* Parrot_get_runtime_prefix(Interp *, STRING **prefix);
 
Index: config/gen/makefiles/libparrot_def.in
===================================================================
--- config/gen/makefiles/libparrot_def.in       (revision 9493)
+++ config/gen/makefiles/libparrot_def.in       (working copy)
@@ -10,4 +10,6 @@
        Parrot_destroy
        Parrot_debug
        Parrot_disassemble
+        Parrot_set_config_string
+        Parrot_base_vtables DATA
        Parrot_DynOp_core_${MAJOR}_${MINOR}_${PATCH}
Index: config/gen/makefiles/root.in
===================================================================
--- config/gen/makefiles/root.in        (revision 9493)
+++ config/gen/makefiles/root.in        (working copy)
@@ -426,6 +426,7 @@
     $(SRC_DIR)/mmd$(O) \
     $(SRC_DIR)/builtin$(O) \
     $(SRC_DIR)/extend$(O) \
+    $(SRC_DIR)/config$(O) \
     $(SRC_DIR)/revision$(O) \
     $(PF_DIR)/pf_items$(O) \
     $(OPS_DIR)/core_ops$(O) \
@@ -764,7 +765,6 @@
 $(PDB) : $(SRC_DIR)/pdb$(O) $(LIBPARROT)
        $(LINK) ${ld_out}$(PDB) \
        $(SRC_DIR)/pdb$(O) \
-       $(SRC_DIR)/null_config$(O) \
        $(LINKFLAGS) $(ALL_PARROT_LIBS)
 
 #
@@ -776,7 +776,6 @@
 $(DIS) : $(SRC_DIR)/disassemble$(O) $(LIBPARROT)
        $(LINK) ${ld_out}$(DIS) \
        $(SRC_DIR)/disassemble$(O) \
-       $(SRC_DIR)/null_config$(O) \
        $(LINKFLAGS) $(ALL_PARROT_LIBS)
 
 #
@@ -786,7 +785,6 @@
 $(PDUMP) : $(SRC_DIR)/pdump$(O) $(SRC_DIR)/packdump$(O) $(LIBPARROT)
        $(LINK) ${ld_out}$(PDUMP) \
        $(SRC_DIR)/pdump$(O) \
-       $(SRC_DIR)/null_config$(O) \
        $(SRC_DIR)/packdump$(O) $(LINKFLAGS) $(ALL_PARROT_LIBS)
 
 
@@ -794,7 +792,6 @@
 $(PINFO) : $(SRC_DIR)/pbc_info$(O) $(LIBPARROT)
        $(LINK) ${ld_out}$(PINFO) \
        $(SRC_DIR)/pbc_info$(O) \
-       $(SRC_DIR)/null_config$(O) \
        $(LINKFLAGS) $(ALL_PARROT_LIBS)
 
 #
@@ -805,7 +802,6 @@
 $(PBCMERGE) : $(SRC_DIR)/pbc_merge$(O) $(LIBPARROT)
        $(LINK) ${ld_out}$(PBCMERGE) \
        $(SRC_DIR)/pbc_merge$(O) \
-       $(SRC_DIR)/null_config$(O) \
        $(LINKFLAGS) $(ALL_PARROT_LIBS)
 
 
@@ -946,6 +942,8 @@
 
 $(SRC_DIR)/thread$(O) : $(GENERAL_H_FILES)
 
+$(SRC_DIR)/config$(O) : $(GENERAL_H_FILES)
+
 $(SRC_DIR)/extend$(O) : $(GENERAL_H_FILES) $(INC_DIR)/extend.h
 
 $(SRC_DIR)/interpreter$(O) : $(SRC_DIR)/interpreter.c $(GENERAL_H_FILES) \

Reply via email to