Replace non-printable-ascii characters in ProtoDebugString (#14918)
authorDavid Reiss <dreiss@fb.com>
Thu, 13 Dec 2018 21:14:11 +0000 (13:14 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 13 Dec 2018 21:16:24 +0000 (13:16 -0800)
commitcbd1c519c46186eb7c70590ba02f126297ee251f
tree2a1e6dba48dbe71708cf6fe3a9e86e3868366f05
parent994f72ee3e4ae94d73f695613174c9a0a23e8e76
Replace non-printable-ascii characters in ProtoDebugString (#14918)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/14918

When ProtoBuf-Lite is in use, ProtoDebugString just calls SerializeAsString.
This produces binary output, which is not a very suitable "debug" string.
Specifically, we've observed it causing problems when calling code tries to
add the debug string to a Java exception message (which requires valid UTF-8).
Now, we replace all non-ASCII bytes with "?".

This is not a very fast implementation, but generating debug strings shouldn't
be a performance-sensitive operation in any application.

Reviewed By: dzhulgakov

Differential Revision: D13385540

fbshipit-source-id: 8868172baf20efaf53fecf7d666a6980f59b64f5
caffe2/utils/proto_utils.cc