[svn:parrot] r46387 - in branches/codestring: . compilers/imcc config/auto/zlib config/gen examples/shootout include/parrot lib/Parrot/Pmc2c ports/fedora/2.3.0 ports/suse/2.2.0 src src/interp src/ops src/pmc src/runcore src/string t/pmc t/src tools/dev

coke at svn.parrot.org coke at svn.parrot.org
Fri May 7 14:53:10 UTC 2010


Author: coke
Date: Fri May  7 14:53:09 2010
New Revision: 46387
URL: https://trac.parrot.org/parrot/changeset/46387

Log:
merge latest changes from trunk

Modified:
   branches/codestring/   (props changed)
   branches/codestring/compilers/imcc/pbc.c
   branches/codestring/config/auto/zlib/   (props changed)
   branches/codestring/config/gen/config_pm.pm
   branches/codestring/examples/shootout/revcomp.pir
   branches/codestring/include/parrot/embed.h
   branches/codestring/include/parrot/interpreter.h
   branches/codestring/include/parrot/packfile.h
   branches/codestring/include/parrot/runcore_trace.h   (props changed)
   branches/codestring/include/parrot/string_funcs.h
   branches/codestring/lib/Parrot/Pmc2c/PCCMETHOD.pm
   branches/codestring/ports/fedora/2.3.0/   (props changed)
   branches/codestring/ports/suse/2.2.0/   (props changed)
   branches/codestring/src/embed.c
   branches/codestring/src/hll.c
   branches/codestring/src/interp/inter_create.c   (contents, props changed)
   branches/codestring/src/library.c
   branches/codestring/src/ops/io.ops
   branches/codestring/src/ops/string.ops
   branches/codestring/src/packout.c
   branches/codestring/src/pmc/imageio.pmc
   branches/codestring/src/pmc/imageiosize.pmc
   branches/codestring/src/pmc/packfileannotations.pmc
   branches/codestring/src/pmc/string.pmc
   branches/codestring/src/pmc/stringbuilder.pmc
   branches/codestring/src/runcore/cores.c   (props changed)
   branches/codestring/src/runcore/trace.c   (props changed)
   branches/codestring/src/string/api.c
   branches/codestring/t/pmc/string.t
   branches/codestring/t/src/embed.t   (props changed)
   branches/codestring/tools/dev/mk_gitignore.pl   (props changed)

Modified: branches/codestring/compilers/imcc/pbc.c
==============================================================================
--- branches/codestring/compilers/imcc/pbc.c	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/compilers/imcc/pbc.c	Fri May  7 14:53:09 2010	(r46387)
@@ -983,23 +983,13 @@
 {
     ASSERT_ARGS(add_const_str)
 
+    PMC *s_pmc = key_new_string(interp, s);
     PackFile_ConstTable *table = interp->code->const_table;
-    int i;
+    int i = PackFile_ConstTable_rlookup(interp, table, s_pmc, PFC_STRING);
+
+    if (i >= 0)
+        return i;
 
-    for (i = 0; i < table->const_count; ++i) {
-        PackFile_Constant * const constant = table->constants[i];
-        if (constant->type == PFC_STRING) {
-            STRING * const sc = constant->u.string;
-            if (Parrot_str_equal(interp, s, sc)
-            &&  Parrot_charset_number_of_str(interp, s)
-            ==  Parrot_charset_number_of_str(interp, sc)
-            &&  Parrot_encoding_number_of_str(interp, s)
-            ==  Parrot_encoding_number_of_str(interp, sc))
-            {
-                return i;
-            }
-        }
-    }
 
     /* otherwise... */
     {

Modified: branches/codestring/config/gen/config_pm.pm
==============================================================================
--- branches/codestring/config/gen/config_pm.pm	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/config/gen/config_pm.pm	Fri May  7 14:53:09 2010	(r46387)
@@ -108,6 +108,7 @@
         if (/\@PCONFIG\@/) {
             for my $k ( sort { lc $a cmp lc $b || $a cmp $b } $conf->data->keys ) {
                 next if exists $p5_keys{$k};
+                next if $k =~ /_provisional$/;
 
                 my $v = $conf->data->get($k);
                 if ( defined $v ) {

Modified: branches/codestring/examples/shootout/revcomp.pir
==============================================================================
--- branches/codestring/examples/shootout/revcomp.pir	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/examples/shootout/revcomp.pir	Fri May  7 14:53:09 2010	(r46387)
@@ -87,7 +87,7 @@
         line = revline
 #
 	.const 'Sub' tr_00 = 'tr_00_init'
-	$P0.'trans'(line, tr_00)
+	line = $P0.'trans'(line, tr_00)
 
 	i = 0
 	$S0 = 'x'

Modified: branches/codestring/include/parrot/embed.h
==============================================================================
--- branches/codestring/include/parrot/embed.h	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/include/parrot/embed.h	Fri May  7 14:53:09 2010	(r46387)
@@ -5,9 +5,6 @@
  *  Overview:
  *     This is the Parrot embedding system--the only part of Parrot that
  *     the outside world should see.
- *  Data Structure and Algorithms:
- *  History:
- *  Notes:
  *  References:
  *      embed.c, docs/embed.pod.
  */
@@ -28,48 +25,52 @@
     enum_DIS_HEADER    = 2
 } Parrot_disassemble_options;
 
-PARROT_EXPORT Parrot_Interp Parrot_new(Parrot_Interp parent);
+PARROT_EXPORT
+PARROT_CANNOT_RETURN_NULL
+PARROT_MALLOC
+Parrot_Interp Parrot_new(ARGIN_NULLOK(Parrot_Interp parent));
 
-PARROT_EXPORT void Parrot_init_stacktop(Parrot_Interp, void *);
+PARROT_EXPORT void Parrot_init_stacktop(PARROT_INTERP, void *);
 
-PARROT_EXPORT void Parrot_set_flag(Parrot_Interp, Parrot_Int);
-PARROT_EXPORT void Parrot_clear_flag(Parrot_Interp, Parrot_Int);
-PARROT_EXPORT Parrot_Int Parrot_test_flag(Parrot_Interp, Parrot_Int);
+PARROT_EXPORT void Parrot_set_flag(PARROT_INTERP, Parrot_Int);
+PARROT_EXPORT void Parrot_clear_flag(PARROT_INTERP, Parrot_Int);
+PARROT_EXPORT Parrot_Int Parrot_test_flag(PARROT_INTERP, Parrot_Int);
 
-PARROT_EXPORT void Parrot_set_trace(Parrot_Interp, Parrot_UInt);
-PARROT_EXPORT void Parrot_clear_trace(Parrot_Interp, Parrot_UInt);
-PARROT_EXPORT Parrot_UInt Parrot_test_trace(Parrot_Interp, Parrot_UInt);
+PARROT_EXPORT void Parrot_set_trace(PARROT_INTERP, Parrot_UInt);
+PARROT_EXPORT void Parrot_clear_trace(PARROT_INTERP, Parrot_UInt);
+PARROT_EXPORT Parrot_UInt Parrot_test_trace(PARROT_INTERP, Parrot_UInt);
 
-PARROT_EXPORT void Parrot_set_debug(Parrot_Interp, Parrot_UInt);
-PARROT_EXPORT void Parrot_clear_debug(Parrot_Interp, Parrot_UInt);
-PARROT_EXPORT Parrot_UInt Parrot_test_debug(Parrot_Interp, Parrot_UInt);
+PARROT_EXPORT void Parrot_set_debug(PARROT_INTERP, Parrot_UInt);
+PARROT_EXPORT void Parrot_clear_debug(PARROT_INTERP, Parrot_UInt);
+PARROT_EXPORT Parrot_UInt Parrot_test_debug(PARROT_INTERP, Parrot_UInt);
 
-PARROT_EXPORT void Parrot_set_executable_name(Parrot_Interp, Parrot_String);
+PARROT_EXPORT void Parrot_set_executable_name(PARROT_INTERP, Parrot_String);
 
-PARROT_EXPORT void Parrot_set_run_core(Parrot_Interp, Parrot_Run_core_t core);
+PARROT_EXPORT void Parrot_set_run_core(PARROT_INTERP, Parrot_Run_core_t core);
 
-PARROT_EXPORT void Parrot_setwarnings(Parrot_Interp, Parrot_warnclass);
+PARROT_EXPORT void Parrot_setwarnings(PARROT_INTERP, Parrot_warnclass);
 
-PARROT_EXPORT Parrot_PackFile Parrot_pbc_read(Parrot_Interp, const char *, const int);
+PARROT_EXPORT Parrot_PackFile Parrot_pbc_read(PARROT_INTERP, ARGIN_NULLOK(const char *), int);
 
-PARROT_EXPORT void Parrot_pbc_load(Parrot_Interp, Parrot_PackFile);
+PARROT_EXPORT void Parrot_pbc_load(PARROT_INTERP, Parrot_PackFile);
 
-PARROT_EXPORT void Parrot_pbc_fixup_loaded(Parrot_Interp);
+PARROT_EXPORT void Parrot_pbc_fixup_loaded(PARROT_INTERP);
 
-PARROT_EXPORT void Parrot_runcode(Parrot_Interp, int argc, const char **argv);
+PARROT_EXPORT void Parrot_runcode(PARROT_INTERP, int argc, ARGIN(const char **argv));
 
-PARROT_EXPORT Parrot_PMC Parrot_compile_string(Parrot_Interp,
-        Parrot_String type, const char *code, Parrot_String *error);
+PARROT_EXPORT Parrot_PMC Parrot_compile_string(PARROT_INTERP,
+        Parrot_String type, ARGIN(const char *code), ARGOUT(Parrot_String *error));
 
-PARROT_EXPORT void Parrot_destroy(Parrot_Interp);
+PARROT_EXPORT void Parrot_destroy(PARROT_INTERP);
 
-PARROT_EXPORT Parrot_Opcode * Parrot_debug(Parrot_Interp, Parrot_Interp, Parrot_Opcode *pc);
+PARROT_EXPORT Parrot_Opcode * Parrot_debug(PARROT_INTERP, ARGIN(Parrot_Interp debugger), ARGIN(Parrot_Opcode *pc));
 
-PARROT_EXPORT void Parrot_disassemble(Parrot_Interp, const char *outfile, Parrot_disassemble_options options);
+PARROT_EXPORT void Parrot_disassemble(PARROT_INTERP, ARGIN(const char *outfile),
+        Parrot_disassemble_options options);
 
 PARROT_EXPORT
 PARROT_DOES_NOT_RETURN
-void Parrot_exit(Parrot_Interp, int status);
+void Parrot_exit(PARROT_INTERP, int status);
 
 PARROT_EXPORT void Parrot_run_native(PARROT_INTERP, native_func_t func);
 

Modified: branches/codestring/include/parrot/interpreter.h
==============================================================================
--- branches/codestring/include/parrot/interpreter.h	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/include/parrot/interpreter.h	Fri May  7 14:53:09 2010	(r46387)
@@ -364,6 +364,7 @@
 
 PARROT_EXPORT
 PARROT_CANNOT_RETURN_NULL
+PARROT_MALLOC
 Parrot_Interp allocate_interpreter(
     ARGIN_NULLOK(Interp *parent),
     INTVAL flags);
@@ -376,6 +377,7 @@
 
 PARROT_EXPORT
 PARROT_CANNOT_RETURN_NULL
+PARROT_MALLOC
 Parrot_Interp make_interpreter(ARGIN_NULLOK(Interp *parent), INTVAL flags);
 
 PARROT_EXPORT

Modified: branches/codestring/include/parrot/packfile.h
==============================================================================
--- branches/codestring/include/parrot/packfile.h	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/include/parrot/packfile.h	Fri May  7 14:53:09 2010	(r46387)
@@ -388,6 +388,15 @@
         __attribute__nonnull__(2);
 
 PARROT_EXPORT
+int PackFile_ConstTable_rlookup(PARROT_INTERP,
+    ARGIN(const PackFile_ConstTable *ct),
+    ARGIN(PMC *key),
+    int type)
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2)
+        __attribute__nonnull__(3);
+
+PARROT_EXPORT
 int PackFile_find_in_const(PARROT_INTERP,
     ARGIN(const PackFile_ConstTable *ct),
     ARGIN(PMC *key),
@@ -424,6 +433,10 @@
 #define ASSERT_ARGS_PackFile_ConstTable_pack_size __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(seg))
+#define ASSERT_ARGS_PackFile_ConstTable_rlookup __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(ct) \
+    , PARROT_ASSERT_ARG(key))
 #define ASSERT_ARGS_PackFile_find_in_const __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(ct) \

Modified: branches/codestring/include/parrot/string_funcs.h
==============================================================================
--- branches/codestring/include/parrot/string_funcs.h	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/include/parrot/string_funcs.h	Fri May  7 14:53:09 2010	(r46387)
@@ -236,8 +236,7 @@
 
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
-INTVAL Parrot_str_length(SHIM_INTERP, ARGIN(const STRING *s))
-        __attribute__nonnull__(2);
+INTVAL Parrot_str_length(SHIM_INTERP, ARGIN_NULLOK(const STRING *s));
 
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
@@ -550,8 +549,7 @@
 #define ASSERT_ARGS_Parrot_str_join __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(ar))
-#define ASSERT_ARGS_Parrot_str_length __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
-       PARROT_ASSERT_ARG(s))
+#define ASSERT_ARGS_Parrot_str_length __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
 #define ASSERT_ARGS_Parrot_str_new __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_Parrot_str_new_constant __attribute__unused__ int _ASSERT_ARGS_CHECK = (\

Modified: branches/codestring/lib/Parrot/Pmc2c/PCCMETHOD.pm
==============================================================================
--- branches/codestring/lib/Parrot/Pmc2c/PCCMETHOD.pm	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/lib/Parrot/Pmc2c/PCCMETHOD.pm	Fri May  7 14:53:09 2010	(r46387)
@@ -415,7 +415,7 @@
     PMC * const _ctx         = CURRENT_CONTEXT(interp);
     PMC * const _ccont       = Parrot_pcc_get_continuation(interp, _ctx);
     PMC * const _call_object = Parrot_pcc_get_signature(interp, _ctx);
-    PMC * _ret_object        = PMCNULL;
+    PMC * _ret_object;
 
     { /* BEGIN PARMS SCOPE */
 END

Modified: branches/codestring/src/embed.c
==============================================================================
--- branches/codestring/src/embed.c	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/src/embed.c	Fri May  7 14:53:09 2010	(r46387)
@@ -80,6 +80,7 @@
 
 PARROT_EXPORT
 PARROT_CANNOT_RETURN_NULL
+PARROT_MALLOC
 Parrot_Interp
 Parrot_new(ARGIN_NULLOK(Parrot_Interp parent))
 {
@@ -1087,8 +1088,8 @@
 
 PARROT_EXPORT
 Parrot_PMC
-Parrot_compile_string(PARROT_INTERP, Parrot_String type,
-        const char *code, Parrot_String *error)
+Parrot_compile_string(PARROT_INTERP, Parrot_String type, ARGIN(const char *code),
+        ARGOUT(Parrot_String *error))
 {
     /* For the benefit of embedders that do not load any pbc
      * before compiling a string */

Modified: branches/codestring/src/hll.c
==============================================================================
--- branches/codestring/src/hll.c	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/src/hll.c	Fri May  7 14:53:09 2010	(r46387)
@@ -200,9 +200,8 @@
 {
     ASSERT_ARGS(Parrot_register_HLL_lib)
     PMC   *hll_info = interp->HLL_info;
-    INTVAL nelements, i;
-
-    nelements = VTABLE_elements(interp, hll_info);
+    const INTVAL nelements = VTABLE_elements(interp, hll_info);
+    INTVAL i;
 
     for (i = 0; i < nelements; ++i) {
         PMC * const entry    = VTABLE_get_pmc_keyed_int(interp, hll_info, i);

Modified: branches/codestring/src/interp/inter_create.c
==============================================================================
--- branches/codestring/src/interp/inter_create.c	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/src/interp/inter_create.c	Fri May  7 14:53:09 2010	(r46387)
@@ -83,14 +83,13 @@
 
 PARROT_EXPORT
 PARROT_CANNOT_RETURN_NULL
+PARROT_MALLOC
 Parrot_Interp
 make_interpreter(ARGIN_NULLOK(Interp *parent), INTVAL flags)
 {
     ASSERT_ARGS(make_interpreter)
     int stacktop;
-    Interp *interp;
-
-    interp = allocate_interpreter(parent, flags);
+    Interp * const interp = allocate_interpreter(parent, flags);
     initialize_interpreter(interp, (void*)&stacktop);
     return interp;
 }
@@ -114,6 +113,7 @@
 
 PARROT_EXPORT
 PARROT_CANNOT_RETURN_NULL
+PARROT_MALLOC
 Parrot_Interp
 allocate_interpreter(ARGIN_NULLOK(Interp *parent), INTVAL flags)
 {

Modified: branches/codestring/src/library.c
==============================================================================
--- branches/codestring/src/library.c	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/src/library.c	Fri May  7 14:53:09 2010	(r46387)
@@ -505,8 +505,7 @@
     ASSERT_ARGS(path_concat)
     STRING* join;
 
-    join = l_path;
-    join = path_guarantee_trailing_separator(interp, join);
+    join = path_guarantee_trailing_separator(interp, l_path);
     join = Parrot_str_concat(interp, join, r_path);
 
     return join;
@@ -530,9 +529,7 @@
 try_load_path(PARROT_INTERP, ARGMOD(STRING* path))
 {
     ASSERT_ARGS(try_load_path)
-    STRING *final;
-
-    final = path_finalize(interp, path);
+    STRING * const final = path_finalize(interp, path);
 
     if (Parrot_stat_info_intval(interp, final, STAT_EXISTS)) {
         return final;

Modified: branches/codestring/src/ops/io.ops
==============================================================================
--- branches/codestring/src/ops/io.ops	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/src/ops/io.ops	Fri May  7 14:53:09 2010	(r46387)
@@ -390,7 +390,7 @@
 
     *s = NULL;
     if (Parrot_io_peek(interp, _PIO_STDIN(interp), s) < 0) {
-        $1 = Parrot_str_new_noinit(interp, enum_stringrep_one, 0);
+        $1 = STRINGNULL;
     }
 }
 
@@ -399,7 +399,7 @@
 
     *s = NULL;
     if (Parrot_io_peek(interp, $2, s) < 0) {
-        $1 = Parrot_str_new_noinit(interp, enum_stringrep_one, 0);
+        $1 = STRINGNULL;
     }
 }
 

Modified: branches/codestring/src/ops/string.ops
==============================================================================
--- branches/codestring/src/ops/string.ops	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/src/ops/string.ops	Fri May  7 14:53:09 2010	(r46387)
@@ -184,19 +184,11 @@
 =cut
 
 inline op length(out INT, in STR) :base_mem {
-    $1 = $2 ? Parrot_str_byte_length(interp, $2) : 0;
+    $1 = Parrot_str_length(interp, $2);
 }
 
 inline op bytelength(out INT, in STR) :base_mem {
-    UINTVAL n;
-    const STRING * const s = $2;
-    if (STRING_IS_NULL(s))
-        n = 0;
-    else {
-        n = s->bufused;
-        PARROT_ASSERT(n == ENCODING_BYTES(interp, $2));
-    }
-    $1 = n;
+    $1 = Parrot_str_byte_length(interp, $2);
 }
 
 

Modified: branches/codestring/src/packout.c
==============================================================================
--- branches/codestring/src/packout.c	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/src/packout.c	Fri May  7 14:53:09 2010	(r46387)
@@ -218,24 +218,76 @@
 PARROT_EXPORT
 int
 PackFile_find_in_const(PARROT_INTERP,
-        ARGIN(const PackFile_ConstTable *ct), ARGIN(PMC *key), int type)
+    ARGIN(const PackFile_ConstTable *ct), ARGIN(PMC *key), int type)
 {
     ASSERT_ARGS(PackFile_find_in_const)
+    int i = PackFile_ConstTable_rlookup(interp, ct, key, type);
+
+    if (i < 0) {
+        Parrot_io_eprintf(NULL, "find_in_const: couldn't find const for key\n");
+        Parrot_exit(interp, 1);
+    }
+
+    return i;
+}
+
+/*
+
+=item C<int PackFile_ConstTable_rlookup(PARROT_INTERP, const PackFile_ConstTable
+*ct, PMC *key, int type)>
+
+Reverse lookup a constant in the constant table.
+
+TODO: use a hash to make these O(1) for strings
+
+=cut
+
+*/
+
+PARROT_EXPORT
+int
+PackFile_ConstTable_rlookup(PARROT_INTERP,
+    ARGIN(const PackFile_ConstTable *ct), ARGIN(PMC *key), int type)
+{
+    ASSERT_ARGS(PackFile_ConstTable_rlookup)
     int      i;
     FLOATVAL key_num;
     STRING  *key_str;
 
+    PARROT_ASSERT(type == PFC_STRING || type == PFC_NUMBER);
+
     GETATTR_Key_str_key(interp, key, key_str);
     GETATTR_Key_num_key(interp, key, key_num);
 
     for (i = 0; i < ct->const_count; ++i) {
-        if (type == PFC_STRING && ct->constants[i]->u.string == key_str)
-            return i;
-        if (type == PFC_NUMBER && ct->constants[i]->u.number == key_num)
-            return i;
+        PackFile_Constant *constant = ct->constants[i];
+
+        switch (type) {
+          case PFC_STRING:
+            if (constant->type == PFC_STRING) {
+                STRING * const sc = constant->u.string;
+                if (Parrot_str_equal(interp, key_str, sc)
+                &&  Parrot_charset_number_of_str(interp, key_str)
+                ==  Parrot_charset_number_of_str(interp, sc)
+                &&  Parrot_encoding_number_of_str(interp, key_str)
+                ==  Parrot_encoding_number_of_str(interp, sc))
+                    return i;
+            }
+            break;
+
+          case PFC_NUMBER:
+            if (constant->type == PFC_NUMBER)
+                if (constant->u.number == key_num)
+                    return i;
+            break;
+
+          default:
+            PANIC(interp, "Universe imploded. Did you divide by zero?");
+        }
     }
-    Parrot_io_eprintf(NULL, "find_in_const: couldn't find const for key\n");
-    Parrot_exit(interp, 1);
+
+    /* not found */
+    return -1;
 }
 
 /*

Modified: branches/codestring/src/pmc/imageio.pmc
==============================================================================
--- branches/codestring/src/pmc/imageio.pmc	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/src/pmc/imageio.pmc	Fri May  7 14:53:09 2010	(r46387)
@@ -536,23 +536,15 @@
     VTABLE void push_string(STRING *v) {
         if (PObj_flag_TEST(private1, SELF)) {
             /* store a reference to constant table entry of string */
-            int i;
+            PMC *v_pmc = key_new_string(interp, v);
             PackFile_ConstTable *table = PARROT_IMAGEIO(SELF)->pf_ct;
-            for (i = 0; i < table->const_count; i++) {
-                PackFile_Constant *constant = table->constants[i];
-                if (constant->type == PFC_STRING) {
-                    STRING * const sc = constant->u.string;
-                    if (Parrot_str_equal(INTERP, v, sc)
-                    && Parrot_charset_number_of_str(INTERP, v)
-                    ==  Parrot_charset_number_of_str(INTERP, sc)
-                    &&  Parrot_encoding_number_of_str(INTERP, v)
-                    ==  Parrot_encoding_number_of_str(INTERP, sc))
-                    {
-                        STATICSELF.push_integer(i);
-                        return;
-                    }
-                }
+            int idx = PackFile_ConstTable_rlookup(INTERP, table, v_pmc, PFC_STRING);
+
+            if (idx >= 0) {
+                STATICSELF.push_integer(idx);
+                return;
             }
+
             /* XXX
              * handle cases where the PMC has changed after Parrot_freeze_strings was called
              * eg: :immediate subs

Modified: branches/codestring/src/pmc/imageiosize.pmc
==============================================================================
--- branches/codestring/src/pmc/imageiosize.pmc	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/src/pmc/imageiosize.pmc	Fri May  7 14:53:09 2010	(r46387)
@@ -246,23 +246,16 @@
 
     VTABLE void push_string(STRING *v) {
         if (PObj_flag_TEST(private1, SELF)) {
-            /* look for a reference to constant table entry of string */
-            int i;
+            /* store a reference to constant table entry of string */
+            PMC *v_pmc = key_new_string(interp, v);
             PackFile_ConstTable *table = PARROT_IMAGEIOSIZE(SELF)->pf_ct;
-            for (i = 0; i < table->const_count; i++) {
-                PackFile_Constant *constant = table->constants[i];
-                if (constant->type == PFC_STRING) {
-                    STRING * const sc = constant->u.string;
-                    if (Parrot_str_equal(INTERP, v, sc)
-                    &&  Parrot_charset_number_of_str(INTERP, v)
-                    ==  Parrot_charset_number_of_str(INTERP, sc)
-                    &&  Parrot_encoding_number_of_str(INTERP, v)
-                    ==  Parrot_encoding_number_of_str(INTERP, sc)) {
-                        STATICSELF.push_integer(i);
-                        return;
-                    }
-                }
+            int idx = PackFile_ConstTable_rlookup(INTERP, table, v_pmc, PFC_STRING);
+
+            if (idx >= 0) {
+                STATICSELF.push_integer(idx);
+                return;
             }
+
             /* XXX
              * handle cases where the PMC has changed after Parrot_freeze_strings was called
              * eg: :immediate subs

Modified: branches/codestring/src/pmc/packfileannotations.pmc
==============================================================================
--- branches/codestring/src/pmc/packfileannotations.pmc	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/src/pmc/packfileannotations.pmc	Fri May  7 14:53:09 2010	(r46387)
@@ -37,6 +37,9 @@
     /* ConstantTable used for names lookup */
     ATTR PMC *const_table;
 
+    /* Annotations group: two RIA for a now */
+    ATTR PMC *gr_byte;
+    ATTR PMC *gr_entries;
     /* RPA of Annotation */
     ATTR PMC *annotations;
 
@@ -219,6 +222,20 @@
         PMC      *annotation;
         Parrot_PackfileAnnotation_attributes *annotation_attrs;
 
+        /* Copy annotations groups */
+        if (a->num_groups > 0) {
+            attrs->gr_byte  = Parrot_pmc_new_init_int(INTERP,
+                    enum_class_ResizableIntegerArray, a->num_groups);
+            attrs->gr_entries = Parrot_pmc_new_init_int(INTERP,
+                    enum_class_ResizableIntegerArray, a->num_groups);
+            for (i = 0; i < a->num_groups; ++i) {
+                VTABLE_set_integer_keyed_int(INTERP, attrs->gr_byte, i,
+                        a->groups[i].bytecode_offset);
+                VTABLE_set_integer_keyed_int(INTERP, attrs->gr_entries, i,
+                        a->groups[i].entries_offset);
+            }
+        }
+
         /* Copy annotations to own array */
         VTABLE_set_integer_native(INTERP, attrs->annotations, a->num_entries);
         for (i = 0; i < a->num_entries; ++i) {
@@ -280,6 +297,21 @@
 
         res->base.type = PF_ANNOTATIONS_SEG;
 
+        /* Create annotations groups */
+        num = PMC_IS_NULL(attrs->gr_byte) ?
+            (INTVAL)0 : VTABLE_elements(INTERP, attrs->gr_byte);
+        res->num_groups = num;
+        if (num > 0) {
+            res->groups = mem_gc_allocate_n_zeroed_typed(interp,
+                    num, PackFile_Annotations_Group);
+            for (i = 0; i < num; ++i) {
+                res->groups[i].bytecode_offset =
+                        VTABLE_get_integer_keyed_int(INTERP, attrs->gr_byte, i);
+                res->groups[i].entries_offset =
+                        VTABLE_get_integer_keyed_int(INTERP, attrs->gr_entries, i);
+            }
+        }
+
         /*
             Create keys. Hash will be created in next structure:
             keys => {

Modified: branches/codestring/src/pmc/string.pmc
==============================================================================
--- branches/codestring/src/pmc/string.pmc	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/src/pmc/string.pmc	Fri May  7 14:53:09 2010	(r46387)
@@ -799,17 +799,19 @@
         unsigned char *p;
         INTVAL        *tr_data;
         INTVAL         i;
+        STRING        *dest;
 
         const INTVAL len = Parrot_str_byte_length(INTERP, src);
 
         if (!len)
-            RETURN(void);
+            RETURN(STRING src);
 
         if (src->charset != Parrot_ascii_charset_ptr)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_ENCODING,
                 "Can't translate non-ascii");
 
-        p = (unsigned char *)(src->strstart);
+        dest = Parrot_str_clone(INTERP, src);
+        p = (unsigned char *)(dest->strstart);
         /* TODO verify trans table */
 
         GETATTR_FixedIntegerArray_int_array(INTERP, table, tr_data);
@@ -819,6 +821,9 @@
             if (ch)
                 *p = ch;
         }
+
+        dest->hashval = 0; /* hash is invalid */
+        RETURN(STRING dest);
     }
 
 /*

Modified: branches/codestring/src/pmc/stringbuilder.pmc
==============================================================================
--- branches/codestring/src/pmc/stringbuilder.pmc	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/src/pmc/stringbuilder.pmc	Fri May  7 14:53:09 2010	(r46387)
@@ -101,9 +101,11 @@
 */
 
     VTABLE STRING *get_string() {
-        STRING *buffer;
+        STRING *buffer, *retv;
         GET_ATTR_buffer(INTERP, SELF, buffer);
-        return Parrot_str_clone(INTERP, buffer);
+        retv = Parrot_str_clone(INTERP, buffer);
+        retv->hashval = 0; /* hash is invalid */
+        return retv;
     }
 
 /*
@@ -286,14 +288,16 @@
 {
     ASSERT_ARGS(calculate_capacity)
     size_t total_size = current + additional;
+    size_t chunk_size = 1024*1024;
+
     if (total_size < 1024)
-        total_size = (total_size / 128 + 1) * 128;
+        chunk_size = 128;
     else if (total_size < 4096)
-        total_size = (total_size / 1024 + 1) * 1024;
+        chunk_size = 1024;
     else if (total_size < 1024*1024)
-        total_size = (total_size / 4096 + 1) * 4096;
-    else
-        total_size = (total_size / 1024 / 1024 + 1) * 1024 * 1024;
+        chunk_size = 4096;
+
+    total_size = (total_size / chunk_size + 1) * chunk_size;
 
     return total_size;
 }

Modified: branches/codestring/src/string/api.c
==============================================================================
--- branches/codestring/src/string/api.c	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/src/string/api.c	Fri May  7 14:53:09 2010	(r46387)
@@ -427,7 +427,7 @@
     /* XXX should this be a CHARSET method? */
 
     /* If B isn't real, we just bail */
-    const UINTVAL b_len = b ? Parrot_str_byte_length(interp, b) : 0;
+    const UINTVAL b_len = b ? Parrot_str_length(interp, b) : 0;
     if (!b_len)
         return STRING_IS_NULL(a) ? STRINGNULL : Parrot_str_copy(interp, a);
 
@@ -797,7 +797,7 @@
 {
     ASSERT_ARGS(Parrot_str_byte_length)
 
-    return STRING_IS_NULL(s) ? 0 : s->strlen;
+    return STRING_IS_NULL(s) ? 0 : s->bufused;
 }
 
 
@@ -852,7 +852,7 @@
     if (start < 0)
         return -1;
 
-    len = Parrot_str_byte_length(interp, s);
+    len = Parrot_str_length(interp, s);
 
     if (!len)
         return -1;
@@ -860,7 +860,7 @@
     if (start >= (INTVAL)len)
         return -1;
 
-    if (!Parrot_str_byte_length(interp, s2))
+    if (!Parrot_str_length(interp, s2))
         return -1;
     else {
         DECL_CONST_CAST;
@@ -896,7 +896,7 @@
         Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_ORD_OUT_OF_STRING,
             "Cannot get character of NULL string");
 
-    len = Parrot_str_byte_length(interp, s);
+    len = Parrot_str_length(interp, s);
     if (len == 0)
         Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_ORD_OUT_OF_STRING,
             "Cannot get character of empty string");
@@ -959,7 +959,7 @@
 
 =item C<INTVAL Parrot_str_length(PARROT_INTERP, const STRING *s)>
 
-Calculates and returns the number of characters in the specified Parrot string.
+Returns the number of characters in the specified Parrot string.
 
 =cut
 
@@ -968,11 +968,11 @@
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
 INTVAL
-Parrot_str_length(SHIM_INTERP, ARGIN(const STRING *s))
+Parrot_str_length(SHIM_INTERP, ARGIN_NULLOK(const STRING *s))
 {
     ASSERT_ARGS(Parrot_str_length)
 
-    return s->strlen;
+    return STRING_IS_NULL(s) ? 0 : s->strlen;
 }
 
 
@@ -1068,7 +1068,7 @@
     ASSERT_STRING_SANITY(src);
 
     /* Allow regexes to return $' easily for "aaa" =~ /aaa/ */
-    if (offset == (INTVAL)Parrot_str_byte_length(interp, src) || length < 1)
+    if (offset == (INTVAL)Parrot_str_length(interp, src) || length < 1)
         return Parrot_str_new_noinit(interp, enum_stringrep_one, 0);
 
     if (offset < 0)
@@ -3096,12 +3096,12 @@
 
     res  = Parrot_pmc_new(interp,
             Parrot_get_ctx_HLL_type(interp, enum_class_ResizableStringArray));
-    slen = Parrot_str_byte_length(interp, str);
+    slen = Parrot_str_length(interp, str);
 
     if (!slen)
         return res;
 
-    dlen = Parrot_str_byte_length(interp, delim);
+    dlen = Parrot_str_length(interp, delim);
 
     if (dlen == 0) {
         int i;
@@ -3129,7 +3129,7 @@
         STRING * const tstr = Parrot_str_substr(interp, str, ps, pl);
 
         VTABLE_push_string(interp, res, tstr);
-        ps = pe + Parrot_str_byte_length(interp, delim);
+        ps = pe + Parrot_str_length(interp, delim);
 
         if (ps > slen)
             break;

Modified: branches/codestring/t/pmc/string.t
==============================================================================
--- branches/codestring/t/pmc/string.t	Fri May  7 14:41:50 2010	(r46386)
+++ branches/codestring/t/pmc/string.t	Fri May  7 14:53:09 2010	(r46387)
@@ -20,7 +20,7 @@
 .sub main :main
     .include 'test_more.pir'
 
-    plan(166)
+    plan(167)
 
     set_or_get_strings()
     setting_integers()
@@ -814,9 +814,10 @@
     is( el, 256, 'elements' )
 
     $P0 = new ['String']
-    $P0.'trans'(s, tr_00)
+    t = $P0.'trans'(s, tr_00)
 
-    is( s, 'TAACGSTAACGS', 'trans' )
+    is( t, 'TAACGSTAACGS', 'trans' )
+    is( s, 'atugcsATUGCS', "trans doesn't touch source string")
 .end
 
 # create tr table at compile-time


More information about the parrot-commits mailing list