Created
March 8, 2018 21:57
-
-
Save ice799/c785e4c9223ee244d87fc17c9b09779f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/ext/gpgme/gpgme_n.c b/ext/gpgme/gpgme_n.c | |
index b9f9d6d..06c092a 100644 | |
--- a/ext/gpgme/gpgme_n.c | |
+++ b/ext/gpgme/gpgme_n.c | |
@@ -109,6 +109,11 @@ | |
#define UNWRAP_GPGME_TRUST_ITEM(vitem, item) \ | |
Data_Get_Struct(vitem, struct _gpgme_trust_item, item) | |
+#ifdef HAVE_RUBY_ENCODING_H | |
+#include <ruby/encoding.h> | |
+static rb_encoding *utf8Encoding; | |
+#endif | |
+ | |
static VALUE cEngineInfo, | |
cCtx, | |
cData, | |
@@ -286,6 +291,14 @@ write_cb (void *handle, const void *buffer, size_t size) | |
vhook_value = RARRAY_PTR(vcb)[1]; | |
vbuffer = rb_str_new (buffer, size); | |
+#ifdef HAVE_RUBY_ENCODING_H | |
+ rb_encoding *default_internal_enc = rb_default_internal_encoding(); | |
+ rb_enc_associate(vbuffer, utf8Encoding); | |
+ if (default_internal_enc) { | |
+ vbuffer = rb_str_export_to_enc(vbuffer, default_internal_enc); | |
+ } | |
+#endif | |
+ | |
vnwrite = rb_funcall (vcbs, rb_intern ("write"), 3, | |
vhook_value, vbuffer, LONG2NUM(size)); | |
return NUM2LONG(vnwrite); | |
@@ -2625,4 +2638,8 @@ Init_gpgme_n (void) | |
rb_define_const (mGPGME, "GPGME_ENCRYPT_NO_ENCRYPT_TO", | |
INT2FIX(GPGME_ENCRYPT_NO_ENCRYPT_TO)); | |
#endif | |
+ | |
+#ifdef HAVE_RUBY_ENCODING_H | |
+ utf8Encoding = rb_utf8_encoding(); | |
+#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment