diff options
author | Mark Spruiell <mes@zeroc.com> | 2017-10-26 16:29:09 -0700 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2017-11-22 08:04:01 +0100 |
commit | 141f764c4e57db55c54a5fdc3e310cc289b983b0 (patch) | |
tree | f9712728685d3e2c73b446b77c1121047de2d7e8 | |
parent | ICE-8378 - cloneWithPrefix cause System.IO.IOException: with IceBox and Ice.F... (diff) | |
download | ice-141f764c4e57db55c54a5fdc3e310cc289b983b0.tar.bz2 ice-141f764c4e57db55c54a5fdc3e310cc289b983b0.tar.xz ice-141f764c4e57db55c54a5fdc3e310cc289b983b0.zip |
ICE-8457 - Ruby and Python string fixes
-rw-r--r-- | python/modules/IcePy/Types.cpp | 39 | ||||
-rw-r--r-- | ruby/src/IceRuby/Types.cpp | 22 |
2 files changed, 53 insertions, 8 deletions
diff --git a/python/modules/IcePy/Types.cpp b/python/modules/IcePy/Types.cpp index b7183bf02aa..4c4eea9b778 100644 --- a/python/modules/IcePy/Types.cpp +++ b/python/modules/IcePy/Types.cpp @@ -71,18 +71,38 @@ struct ExceptionInfoObject extern PyTypeObject TypeInfoType; extern PyTypeObject ExceptionInfoType; +#if PY_VERSION_HEX >= 0x03000000 bool writeString(PyObject* p, Ice::OutputStream* os) { if(p == Py_None) { - os->write(string()); + os->write(string(), false); // Bypass string conversion. } else if(checkString(p)) { - os->write(getString(p)); + os->write(getString(p), false); // Bypass string conversion. } -#if defined(Py_USING_UNICODE) && PY_VERSION_HEX < 0x03000000 + else + { + assert(false); + } + + return true; +} +#else +bool +writeString(PyObject* p, Ice::OutputStream* os) +{ + if(p == Py_None) + { + os->write(string(), true); + } + else if(checkString(p)) + { + os->write(getString(p), true); + } +#if defined(Py_USING_UNICODE) else if(PyUnicode_Check(p)) { // @@ -104,6 +124,7 @@ writeString(PyObject* p, Ice::OutputStream* os) return true; } +#endif } @@ -1001,7 +1022,11 @@ IcePy::PrimitiveInfo::unmarshal(Ice::InputStream* is, const UnmarshalCallbackPtr case PrimitiveInfo::KindString: { string val; - is->read(val); +#if PY_VERSION_HEX >= 0x03000000 + is->read(val, false); // Bypass string conversion. +#else + is->read(val, true); +#endif PyObjectHandle p = createString(val); cb->unmarshaled(p.get(), target, closure); break; @@ -2288,7 +2313,11 @@ IcePy::SequenceInfo::unmarshalPrimitiveSequence(const PrimitiveInfoPtr& pi, Ice: case PrimitiveInfo::KindString: { Ice::StringSeq seq; - is->read(seq); +#if PY_VERSION_HEX >= 0x03000000 + is->read(seq, false); // Bypass string conversion. +#else + is->read(seq, true); +#endif int sz = static_cast<int>(seq.size()); result = sm->createContainer(sz); if(!result.get()) diff --git a/ruby/src/IceRuby/Types.cpp b/ruby/src/IceRuby/Types.cpp index 799c8197ab7..ea018cd839b 100644 --- a/ruby/src/IceRuby/Types.cpp +++ b/ruby/src/IceRuby/Types.cpp @@ -618,7 +618,11 @@ IceRuby::PrimitiveInfo::marshal(VALUE p, Ice::OutputStream* os, ObjectMap*, bool case PrimitiveInfo::KindString: { string val = getString(p); - os->write(val); +#ifdef HAVE_RUBY_ENCODING_H + os->write(val, false); // Bypass string conversion. +#else + os->write(val, true); +#endif break; } } @@ -683,7 +687,11 @@ IceRuby::PrimitiveInfo::unmarshal(Ice::InputStream* is, const UnmarshalCallbackP case PrimitiveInfo::KindString: { string str; - is->read(str); +#ifdef HAVE_RUBY_ENCODING_H + is->read(str, false); // Bypass string conversion. +#else + is->read(str, true); +#endif val = createString(str); break; } @@ -1517,7 +1525,11 @@ IceRuby::SequenceInfo::marshalPrimitiveSequence(const PrimitiveInfoPtr& pi, VALU { seq[i] = getString(RARRAY_AREF(arr, i)); } - os->write(&seq[0], &seq[0] + seq.size()); +#ifdef HAVE_RUBY_ENCODING_H + os->write(&seq[0], &seq[0] + seq.size(), false); // Bypass string conversion. +#else + os->write(&seq[0], &seq[0] + seq.size(), true); +#endif break; } } @@ -1643,7 +1655,11 @@ IceRuby::SequenceInfo::unmarshalPrimitiveSequence(const PrimitiveInfoPtr& pi, Ic case PrimitiveInfo::KindString: { Ice::StringSeq seq; +#ifdef HAVE_RUBY_ENCODING_H + is->read(seq, false); // Bypass string conversion. +#else is->read(seq, true); +#endif long sz = static_cast<long>(seq.size()); result = createArray(sz); |