summaryrefslogtreecommitdiff
path: root/ext/psych/psych_emitter.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/psych/psych_emitter.c')
-rw-r--r--ext/psych/psych_emitter.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/ext/psych/psych_emitter.c b/ext/psych/psych_emitter.c
index feffc54ce7..f77d8d7d86 100644
--- a/ext/psych/psych_emitter.c
+++ b/ext/psych/psych_emitter.c
@@ -15,7 +15,11 @@ static void emit(yaml_emitter_t * emitter, yaml_event_t * event)
static int writer(void *ctx, unsigned char *buffer, size_t size)
{
VALUE io = (VALUE)ctx;
+#ifdef HAVE_RUBY_ENCODING_H
+ VALUE str = rb_enc_str_new((const char *)buffer, (long)size, rb_utf8_encoding());
+#else
VALUE str = rb_str_new((const char *)buffer, (long)size);
+#endif
VALUE wrote = rb_funcall(io, id_write, 1, str);
return (int)NUM2INT(wrote);
}