Skip to content

Commit

Permalink
Fix RSTRING_PTR usage in Ruby (#2375)
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone authored Jun 28, 2024
1 parent 3ba16c8 commit 69a5907
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 37 deletions.
35 changes: 0 additions & 35 deletions ruby/src/IceRuby/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,39 +79,4 @@ extern "C"

#define CAST_METHOD(X) reinterpret_cast<ICE_RUBY_ENTRY_POINT>(X)

//
// These macros are defined in Ruby 1.9 but not in 1.8. We define them here
// to maintain compatibility with 1.8.
//
#ifndef RARRAY_PTR
# define RARRAY_PTR(v) RARRAY(v)->ptr
#endif

#ifndef RARRAY_LEN
# define RARRAY_LEN(v) RARRAY(v)->len
#endif

#ifndef RSTRING_PTR
# define RSTRING_PTR(v) RSTRING(v)->ptr
#endif

#ifndef RSTRING_LEN
# define RSTRING_LEN(v) RSTRING(v)->len
#endif

#ifndef RFLOAT_VALUE
# define RFLOAT_VALUE(v) RFLOAT(v)->value
#endif

//
// The RARRAY_AREF and RARRAY_ASET macros were added in Ruby 2.1.
//
#ifndef RARRAY_AREF
# define RARRAY_AREF(a, i) (RARRAY_PTR(a)[i])
#endif

#ifndef RARRAY_ASET
# define RARRAY_ASET(a, i, v) RARRAY_PTR(a)[i] = v
#endif

#endif
5 changes: 4 additions & 1 deletion ruby/src/IceRuby/Operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,10 @@ IceRuby::OperationI::unmarshalException(const vector<byte>& bytes, const Ice::Co
volatile VALUE cls = CLASS_OF(ex);
volatile VALUE path = callRuby(rb_class_path, cls);
assert(TYPE(path) == T_STRING);
throw Ice::UnknownUserException{__FILE__, __LINE__, RSTRING_PTR(path)};
throw Ice::UnknownUserException{
__FILE__,
__LINE__,
string{RSTRING_PTR(path), static_cast<size_t>(RSTRING_LEN(path))}};
}
}

Expand Down
3 changes: 2 additions & 1 deletion ruby/src/IceRuby/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ IceRuby::RubyException::operator<<(ostream& ostr) const
{
volatile VALUE cls = rb_class_path(CLASS_OF(ex));
volatile VALUE msg = rb_obj_as_string(ex);
ostr << RSTRING_PTR(cls) << ": " << RSTRING_PTR(msg);
ostr << string_view{RSTRING_PTR(cls), static_cast<size_t>(RSTRING_LEN(cls))} << ": "
<< string_view{RSTRING_PTR(msg), static_cast<size_t>(RSTRING_LEN(msg))};
return ostr;
}

Expand Down

0 comments on commit 69a5907

Please sign in to comment.