summaryrefslogtreecommitdiffstats
path: root/pack.c
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-29 16:27:00 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-29 16:27:00 +0000
commitbcc6561df8e2fdf97bbcb7194e2e36f80183d6be (patch)
tree2893a1cd2a585b0cb777a28f82d762d85042cc91 /pack.c
parent56dccab73e3ed71ea203285994a2594105608016 (diff)
downloadruby-bcc6561df8e2fdf97bbcb7194e2e36f80183d6be.tar.gz
ruby-bcc6561df8e2fdf97bbcb7194e2e36f80183d6be.tar.xz
ruby-bcc6561df8e2fdf97bbcb7194e2e36f80183d6be.zip
merged r20021 and r20022 from trunk into ruby_1_9_1.
* pack.c (pack_pack): set encoding from packing string and UTF-8 for "U". [ruby-core:19590] * test/ruby/test_array.rb (test_pack): use utf-8. * test/ruby/test_pack.rb (test_pack_U): ditto. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1@20042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'pack.c')
-rw-r--r--pack.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/pack.c b/pack.c
index 9641f6e40..df2523161 100644
--- a/pack.c
+++ b/pack.c
@@ -10,6 +10,7 @@
**********************************************************************/
#include "ruby/ruby.h"
+#include "ruby/encoding.h"
#include <sys/types.h>
#include <ctype.h>
#include <errno.h>
@@ -443,6 +444,7 @@ pack_pack(VALUE ary, VALUE fmt)
char type;
long items, len, idx, plen;
const char *ptr;
+ rb_encoding *enc;
#ifdef NATINT_PACK
int natint; /* native integer */
#endif
@@ -517,6 +519,8 @@ pack_pack(VALUE ary, VALUE fmt)
ptr = RSTRING_PTR(from);
plen = RSTRING_LEN(from);
OBJ_INFECT(res, from);
+ enc = rb_enc_compatible(res, from);
+ rb_enc_associate(res, enc);
}
if (p[-1] == '*')
@@ -865,6 +869,8 @@ pack_pack(VALUE ary, VALUE fmt)
break;
case 'U': /* Unicode character */
+ enc = rb_enc_compatible(res, rb_enc_from_encoding(rb_utf8_encoding()));
+ rb_enc_associate(res, enc);
while (len-- > 0) {
SIGNED_VALUE l;
char buf[8];