Index: lang/cplusplus/fcgi-v8/trunk/core.cc
===================================================================
--- lang/cplusplus/fcgi-v8/trunk/core.cc (revision 18794)
+++ lang/cplusplus/fcgi-v8/trunk/core.cc (revision 18804)
@@ -2,4 +2,5 @@
 #include <cstdio>
 #include <cstdlib>
+#include <memory.h>
 #include "v8-util.h"
 
@@ -7,9 +8,66 @@
 extern char ** __argv;
 
+int utf_char2bytes(int c, unsigned char* buf) {
+    if (c < 0x80) {
+        buf[0] = c;
+        return 1;
+    }
+    if (c < 0x800) {
+        buf[0] = 0xc0 + ((unsigned)c >> 6);
+        buf[1] = 0x80 + (c & 0x3f);
+        return 2;
+    }
+    if (c < 0x10000) {
+        buf[0] = 0xe0 + ((unsigned)c >> 12);
+        buf[1] = 0x80 + (((unsigned)c >> 6) & 0x3f);
+        buf[2] = 0x80 + (c & 0x3f);
+        return 3;
+    }
+    if (c < 0x200000) {
+        buf[0] = 0xf0 + ((unsigned)c >> 18);
+        buf[1] = 0x80 + (((unsigned)c >> 12) & 0x3f);
+        buf[2] = 0x80 + (((unsigned)c >> 6) & 0x3f);
+        buf[3] = 0x80 + (c & 0x3f);
+        return 4;
+    }
+    if (c < 0x4000000) {
+        buf[0] = 0xf8 + ((unsigned)c >> 24);
+        buf[1] = 0x80 + (((unsigned)c >> 18) & 0x3f);
+        buf[2] = 0x80 + (((unsigned)c >> 12) & 0x3f);
+        buf[3] = 0x80 + (((unsigned)c >> 6) & 0x3f);
+        buf[4] = 0x80 + (c & 0x3f);
+        return 5;
+    }
+    /* 31 bits */
+    buf[0] = 0xfc + ((unsigned)c >> 30);
+    buf[1] = 0x80 + (((unsigned)c >> 24) & 0x3f);
+    buf[2] = 0x80 + (((unsigned)c >> 18) & 0x3f);
+    buf[3] = 0x80 + (((unsigned)c >> 12) & 0x3f);
+    buf[4] = 0x80 + (((unsigned)c >> 6) & 0x3f);
+    buf[5] = 0x80 + (c & 0x3f);
+    return 6;
+}
+
+unsigned char* ucs2utf_alloc(uint16_t *instr) {
+    uint16_t *p = instr;
+    int inlen = 0;
+
+    while(*p++) inlen++;
+    unsigned char* outstr = new unsigned char[inlen * 8];
+    unsigned char* outp = outstr;
+    memset(outstr, 0, inlen * 8);
+
+    p = instr;
+    while (*p) outstr += utf_char2bytes(*p++, outstr);
+    return outp;
+}
+
 v8::Handle<v8::Value> P(const v8::Arguments& args) {
     for (int i = 0; i < args.Length(); i++) {
         v8::HandleScope handle_scope;
-        v8::String::AsciiValue str(args[i]);
-        printf("%s", *str);
+        v8::String::Value val(args[i]);
+        unsigned char* buf = ucs2utf_alloc(*val);
+        printf("%s", buf);
+        delete[] buf;
     }
     printf("\n");
@@ -20,6 +78,8 @@
     for (int i = 0; i < args.Length(); i++) {
         v8::HandleScope handle_scope;
-        v8::String::AsciiValue str(args[i]);
-        printf("%s", *str);
+        v8::String::Value val(args[i]);
+        unsigned char* buf = ucs2utf_alloc(*val);
+        printf("%s", buf);
+        delete[] buf;
     }
     printf("\n");
@@ -30,6 +90,8 @@
     for (int i = 0; i < args.Length(); i++) {
         v8::HandleScope handle_scope;
-        v8::String::AsciiValue str(args[i]);
-        printf("%s\n", *str);
+        v8::String::Value val(args[i]);
+        unsigned char* buf = ucs2utf_alloc(*val);
+        printf("%s", buf);
+        delete[] buf;
     }
     return v8::Undefined();
