From fb533a2bbbf0992c85635dfb4a36e76f08db789d Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Mon, 13 May 2024 22:18:50 +0200 Subject: [PATCH] Solve it via fragments --- src/utilities/core/jsoncpp.i | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/utilities/core/jsoncpp.i b/src/utilities/core/jsoncpp.i index e5bce4ef2b3..ab93cc82e1a 100644 --- a/src/utilities/core/jsoncpp.i +++ b/src/utilities/core/jsoncpp.i @@ -76,16 +76,17 @@ #if defined SWIGRUBY -%fragment("JsonToDict","header", fragment="SWIG_FromCharPtrAndSize") { - - extern "C" { - struct OnigEncodingTypeST; - typedef struct OnigEncodingTypeST OnigEncodingType; - typedef const OnigEncodingType rb_encoding; +%fragment("", "header") %{ +#include +%} - rb_encoding *rb_utf8_encoding(void); - ID rb_intern3(const char *name, long len, rb_encoding *enc); +%fragment("string_to_ruby_utf8_symbol", "header", fragment="") { + SWIGINTERN VALUE SWIG_String_to_ruby_utf8_symbol(const std::string& str) { + return ID2SYM(rb_intern3(str.data(), str.size(), rb_utf8_encoding())); } +} + +%fragment("JsonToDict", "header", fragment="SWIG_FromCharPtrAndSize", fragment="string_to_ruby_utf8_symbol") { SWIGINTERN VALUE SWIG_From_JsonValue(const Json::Value& value) { @@ -119,7 +120,7 @@ VALUE result = rb_hash_new(); for( const auto& id : value.getMemberNames()) { rb_hash_aset(result, - ID2SYM(rb_intern3(id.data(), id.size(), rb_utf8_encoding())), + SWIG_String_to_ruby_utf8_symbol(id), SWIG_From_JsonValue(value[id]) ); }