From 64ba8edd2e95ee5092c23e2008c8fb44248934c6 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 d7780e3df35..cec0cf78094 100644 --- a/src/utilities/core/jsoncpp.i +++ b/src/utilities/core/jsoncpp.i @@ -74,16 +74,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) { @@ -120,7 +121,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]) ); }