Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[GH #837] Honor encoding in imcc optimizer

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...
commit 8a56a8e79c636325d646a029ba01c16b36f71644 1 parent c552eb6
@rurban rurban authored
Showing with 15 additions and 9 deletions.
  1. +9 −7 compilers/imcc/optimizer.c
  2. +1 −1  src/string/api.c
  3. +5 −1 t/op/stringu.t
View
16 compilers/imcc/optimizer.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2002-2010, Parrot Foundation.
+ * Copyright (C) 2002-2012, Parrot Foundation.
*/
/*
@@ -1070,13 +1070,15 @@ IMCC_subst_constants(ARGMOD(imc_info_t *imcc), ARGMOD(IMC_Unit *unit),
case 'S':
{
char * const cstr = Parrot_str_to_cstring(imcc->interp, REG_STR(imcc->interp, 0));
-
- r[1] = mk_const(imcc, cstr, r[0]->set);
-
- snprintf(b, sizeof (b), "%p", REG_STR(imcc->interp, 0));
+ const STR_VTABLE* encoding = REG_STR(imcc->interp, 0)->encoding;
+ if (encoding == Parrot_ascii_encoding_ptr) {
+ r[1] = mk_const(imcc, cstr, r[0]->set);
+ }
+ else {
+ snprintf(b, sizeof (b), "%s:\"%s\"", encoding->name, cstr);
+ r[1] = mk_const(imcc, b, 'U');
+ }
Parrot_str_free_cstring(cstr);
-
- break;
}
default:
break;
View
2  src/string/api.c
@@ -700,7 +700,7 @@ STRING *encodingname)>
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
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
View
6 t/op/stringu.t
@@ -22,8 +22,11 @@ Tests Parrot unicode string system.
=cut
-pir_output_is(<<'CODE',<<'OUTPUT', 'concat utf8 GH#837');
+pir_output_is(<<'CODE',<<'OUTPUT', 'non-ascii immc optimizer GH#837');
.sub main
+ $S1 = utf8:"\x{a2}"
+ say $S1
+
concat $S1, unicode:"\x{a2}", unicode:"\x{a2}"
say $S1
@@ -34,6 +37,7 @@ pir_output_is(<<'CODE',<<'OUTPUT', 'concat utf8 GH#837');
say $S3
.end
CODE
¢¢
¢c
bb

0 comments on commit 8a56a8e

Please sign in to comment.
Something went wrong with that request. Please try again.