Skip to content

Commit

Permalink
[GH #837] Honor encoding in imcc optimizer
Browse files Browse the repository at this point in the history
Context registers unfortunately do not store type information,
just the values. We would need at least type 'U" here.
So recreate an proper const'ed encoding string from the register
value.
  • Loading branch information
Reini Urban committed Sep 20, 2012
1 parent c552eb6 commit 8a56a8e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
16 changes: 9 additions & 7 deletions compilers/imcc/optimizer.c
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2002-2010, Parrot Foundation. * Copyright (C) 2002-2012, Parrot Foundation.
*/ */


/* /*
Expand Down Expand Up @@ -1070,13 +1070,15 @@ IMCC_subst_constants(ARGMOD(imc_info_t *imcc), ARGMOD(IMC_Unit *unit),
case 'S': case 'S':
{ {
char * const cstr = Parrot_str_to_cstring(imcc->interp, REG_STR(imcc->interp, 0)); char * const cstr = Parrot_str_to_cstring(imcc->interp, REG_STR(imcc->interp, 0));

const STR_VTABLE* encoding = REG_STR(imcc->interp, 0)->encoding;
r[1] = mk_const(imcc, cstr, r[0]->set); if (encoding == Parrot_ascii_encoding_ptr) {

r[1] = mk_const(imcc, cstr, r[0]->set);
snprintf(b, sizeof (b), "%p", REG_STR(imcc->interp, 0)); }
else {
snprintf(b, sizeof (b), "%s:\"%s\"", encoding->name, cstr);
r[1] = mk_const(imcc, b, 'U');
}
Parrot_str_free_cstring(cstr); Parrot_str_free_cstring(cstr);

break;
} }
default: default:
break; break;
Expand Down
2 changes: 1 addition & 1 deletion src/string/api.c
Expand Up @@ -700,7 +700,7 @@ STRING *encodingname)>
Given a buffer and an encoding, creates and returns a new string. If buffer is Given a buffer and an encoding, creates and returns a new string. If buffer is
NULL the result is a null string. Otherwise, the buffer should be a zero NULL the result is a null string. Otherwise, the buffer should be a zero
terminated c-style string and its content must be valid for the encoding terminated c-style string and its content must be valid for the encoding
specified. If encoding is null, assume plaftorm encoding. specified. If encoding is null, assume platform encoding.
=cut =cut
Expand Down
6 changes: 5 additions & 1 deletion t/op/stringu.t
Expand Up @@ -22,8 +22,11 @@ Tests Parrot unicode string system.
=cut =cut


pir_output_is(<<'CODE',<<'OUTPUT', 'concat utf8 GH#837'); pir_output_is(<<'CODE',<<'OUTPUT', 'non-ascii immc optimizer GH#837');
.sub main .sub main
$S1 = utf8:"\x{a2}"
say $S1
concat $S1, unicode:"\x{a2}", unicode:"\x{a2}" concat $S1, unicode:"\x{a2}", unicode:"\x{a2}"
say $S1 say $S1
Expand All @@ -34,6 +37,7 @@ pir_output_is(<<'CODE',<<'OUTPUT', 'concat utf8 GH#837');
say $S3 say $S3
.end .end
CODE CODE
¢
¢¢ ¢¢
¢c ¢c
bb bb
Expand Down

0 comments on commit 8a56a8e

Please sign in to comment.