summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Lib/ruby/rubywstrings.swg6
-rw-r--r--Lib/ruby/std_wstring.i8
2 files changed, 11 insertions, 3 deletions
diff --git a/Lib/ruby/rubywstrings.swg b/Lib/ruby/rubywstrings.swg
index 54724b268..93d0da21d 100644
--- a/Lib/ruby/rubywstrings.swg
+++ b/Lib/ruby/rubywstrings.swg
@@ -8,7 +8,7 @@
SWIGINTERN int
SWIG_AsWCharPtrAndSize(VALUE obj, wchar_t **cptr, size_t *psize, int *alloc)
{
- static rb_encoding* wstr_enc = rb_to_encoding(rb_str_new_cstr( SWIG_RUBY_WSTRING_ENCODING ));
+ rb_encoding* wstr_enc = swig_ruby_wstring_encoding;
if (TYPE(obj) == T_STRING) {
VALUE rstr = rb_str_conv_enc(obj, rb_enc_get(obj), wstr_enc);
@@ -37,8 +37,8 @@ SWIG_AsWCharPtrAndSize(VALUE obj, wchar_t **cptr, size_t *psize, int *alloc)
SWIGINTERNINLINE VALUE
SWIG_FromWCharPtrAndSize(const wchar_t * carray, size_t size)
{
- static rb_encoding* wstr_enc = rb_to_encoding(rb_str_new_cstr( SWIG_RUBY_WSTRING_ENCODING ));
- static rb_encoding* rb_enc = rb_to_encoding(rb_str_new_cstr( SWIG_RUBY_INTERNAL_ENCODING ));
+ rb_encoding* wstr_enc = swig_ruby_wstring_encoding;
+ rb_encoding* rb_enc = swig_ruby_internal_encoding;
if (carray && size <= LONG_MAX/sizeof(wchar_t)) {
VALUE rstr = rb_str_new( (const char*)carray, %numeric_cast(size*sizeof(wchar_t),long) );
diff --git a/Lib/ruby/std_wstring.i b/Lib/ruby/std_wstring.i
index 943b4f770..38149e4ed 100644
--- a/Lib/ruby/std_wstring.i
+++ b/Lib/ruby/std_wstring.i
@@ -32,11 +32,19 @@ extern "C" {
#define SWIG_RUBY_INTERNAL_ENCODING "UTF-8"
#endif
+static rb_encoding *swig_ruby_wstring_encoding;
+static rb_encoding *swig_ruby_internal_encoding;
+
#ifdef __cplusplus
}
#endif
%}
+%init{
+ swig_ruby_wstring_encoding = rb_enc_find( SWIG_RUBY_WSTRING_ENCODING );
+ swig_ruby_internal_encoding = rb_enc_find( SWIG_RUBY_INTERNAL_ENCODING );
+}
+
%include <rubywstrings.swg>
%include <typemaps/std_wstring.swg>