When a symbol literal is invalid in the source file's encoding, an EncodingError exception is raised, with the following message: invalid encoding symbol. This patches the interpreter so a more informative message is generated, similar to: encoding UTF-8 is invalid for symbol :"\xC7".
Calling RSTRING_PTR on any function return value directly is dangerous
because of GC. PRI*VALUE format strings were introduced to help make
avoiding this danger easier, and the '+' modifier will call inspect for
you.
How about the following?
rb_raise(rb_eEncodingError,
"encoding %s is invalid for symbol :%+"PRIsVALUE,
rb_enc_name(rb_enc_get(str)),
str);
(also wrapping at 80 cols, some of us use big fonts)