diff --git a/cpp/include/Ice/InputStream.h b/cpp/include/Ice/InputStream.h index 08ac525d950..4c011cc1b09 100644 --- a/cpp/include/Ice/InputStream.h +++ b/cpp/include/Ice/InputStream.h @@ -798,8 +798,6 @@ namespace Ice std::string resolveCompactId(int) const; - void postUnmarshal(const ValuePtr&) const; - class Encaps; enum SliceType { @@ -1071,10 +1069,8 @@ namespace Ice int _startSeq; int _minSeqSize; - // These values are retrieved from instance during construction and cached. + // Retrieved from instance during construction and cached. Never null. const ValueFactoryManagerPtr _valueFactoryManager; - const LoggerPtr _logger; - const std::function _compactIdResolver; std::vector> _deleters; }; diff --git a/cpp/src/Ice/InputStream.cpp b/cpp/src/Ice/InputStream.cpp index 5053febceb8..ef4f68e8bec 100644 --- a/cpp/src/Ice/InputStream.cpp +++ b/cpp/src/Ice/InputStream.cpp @@ -1061,10 +1061,9 @@ Ice::InputStream::InputStream(Instance* instance, EncodingVersion encoding, Buff _closure(nullptr), _startSeq(-1), _minSeqSize(0), - _valueFactoryManager(instance->initializationData().valueFactoryManager), - _logger(instance->initializationData().logger), - _compactIdResolver(instance->initializationData().compactIdResolver) + _valueFactoryManager(instance->initializationData().valueFactoryManager) { + assert(_valueFactoryManager); } ReferencePtr @@ -1263,12 +1262,14 @@ Ice::InputStream::throwUnmarshalOutOfBoundsException(const char* file, int line) string Ice::InputStream::resolveCompactId(int id) const { - string type; - if (_compactIdResolver) + string typeId; + const std::function& compactIdResolver = _instance->initializationData().compactIdResolver; + + if (compactIdResolver) { try { - type = _compactIdResolver(id); + typeId = compactIdResolver(id); } catch (const LocalException&) { @@ -1294,40 +1295,25 @@ Ice::InputStream::resolveCompactId(int id) const } } - return type; -} - -void -Ice::InputStream::postUnmarshal(const shared_ptr& v) const -{ - try + if (typeId.empty()) { - v->ice_postUnmarshal(); - } - catch (const std::exception& ex) - { - if (_logger) - { - Warning out(_logger); - out << "std::exception raised by ice_postUnmarshal:\n" << ex; - } - } - catch (...) - { - if (_logger) - { - Warning out(_logger); - out << "unknown exception raised by ice_postUnmarshal"; - } + typeId = IceInternal::factoryTable->getTypeId(id); } + + return typeId; } void Ice::InputStream::traceSkipSlice(string_view typeId, SliceType sliceType) const { - if (_instance->traceLevels()->slicing > 0 && _logger) + assert(_instance->initializationData().logger); // not null once the communicator is initialized + if (_instance->traceLevels()->slicing > 0) { - traceSlicing(sliceType == ExceptionSlice ? "exception" : "object", typeId, "Slicing", _logger); + traceSlicing( + sliceType == ExceptionSlice ? "exception" : "object", + typeId, + "Slicing", + _instance->initializationData().logger); } } @@ -1389,20 +1375,14 @@ Ice::InputStream::EncapsDecoder::newInstance(string_view typeId) shared_ptr v; // Try to find a factory registered for the specific type. - function(string_view)> userFactory; - if (_valueFactoryManager) + function(string_view)> userFactory = _valueFactoryManager->find(typeId); + if (userFactory) { - userFactory = _valueFactoryManager->find(typeId); - if (userFactory) - { - v = userFactory(typeId); - } + v = userFactory(typeId); } - // // If that fails, invoke the default factory if one has been registered. - // - if (!v && _valueFactoryManager) + if (!v) { userFactory = _valueFactoryManager->find(""); if (userFactory) @@ -1517,7 +1497,7 @@ Ice::InputStream::EncapsDecoder::unmarshal(int32_t index, const ValuePtr& v) if (_valueList.empty() && _patchMap.empty()) { - _stream->postUnmarshal(v); + v->ice_postUnmarshal(); } else { @@ -1525,15 +1505,13 @@ Ice::InputStream::EncapsDecoder::unmarshal(int32_t index, const ValuePtr& v) if (_patchMap.empty()) { - // // Iterate over the value list and invoke ice_postUnmarshal on // each value. We must do this after all values have been // unmarshaled in order to ensure that any value data members // have been properly patched. - // - for (ValueList::iterator p = _valueList.begin(); p != _valueList.end(); ++p) + for (auto& value : _valueList) { - _stream->postUnmarshal(*p); + value->ice_postUnmarshal(); } _valueList.clear(); } @@ -2207,14 +2185,8 @@ Ice::InputStream::EncapsDecoder11::readInstance(int32_t index, PatchFunc patchFu { if (_current->compactId >= 0) { - // // Translate a compact (numeric) type ID into a string type ID. - // _current->typeId = _stream->resolveCompactId(_current->compactId); - if (_current->typeId.empty()) - { - _current->typeId = IceInternal::factoryTable->getTypeId(_current->compactId); - } } if (!_current->typeId.empty()) diff --git a/csharp/src/Ice/InputStream.cs b/csharp/src/Ice/InputStream.cs index 7e35346cb79..1c9dd69bc17 100644 --- a/csharp/src/Ice/InputStream.cs +++ b/csharp/src/Ice/InputStream.cs @@ -2553,15 +2553,7 @@ protected void unmarshal(int index, Value v) if ((_patchMap == null || _patchMap.Count == 0) && _valueList == null) { - try - { - v.ice_postUnmarshal(); - } - catch (System.Exception ex) - { - string s = "exception raised by ice_postUnmarshal:\n" + ex; - _stream.instance().initializationData().logger!.warning(s); - } + v.ice_postUnmarshal(); } else { @@ -2581,15 +2573,7 @@ protected void unmarshal(int index, Value v) // foreach (var p in _valueList) { - try - { - p.ice_postUnmarshal(); - } - catch (System.Exception ex) - { - string s = "exception raised by ice_postUnmarshal:\n" + ex; - _stream.instance().initializationData().logger!.warning(s); - } + p.ice_postUnmarshal(); } _valueList.Clear(); } diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/InputStream.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/InputStream.java index 8b329d7c574..358929535d9 100644 --- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/InputStream.java +++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/InputStream.java @@ -79,11 +79,9 @@ private InputStream(Instance instance, EncodingVersion encoding, Buffer buf) { // Everything below is cached from instance. _classGraphDepthMax = _instance.classGraphDepthMax(); _valueFactoryManager = _instance.initializationData().valueFactoryManager; - _logger = _instance.initializationData().logger; _classResolver = _instance; assert (_valueFactoryManager != null); - assert (_logger != null); } /** @@ -1744,12 +1742,7 @@ protected void unmarshal(int index, Value v) { } if ((_patchMap == null || _patchMap.isEmpty()) && _valueList == null) { - try { - v.ice_postUnmarshal(); - } catch (Exception ex) { - String s = "exception raised by ice_postUnmarshal:\n" + Ex.toString(ex); - _stream.instance().initializationData().logger.warning(s); - } + v.ice_postUnmarshal(); } else { if (_valueList == null) // Lazy initialization { @@ -1758,19 +1751,12 @@ protected void unmarshal(int index, Value v) { _valueList.add(v); if (_patchMap == null || _patchMap.isEmpty()) { - // // Iterate over the instance list and invoke ice_postUnmarshal on // each instance. We must do this after all instances have been // unmarshaled in order to ensure that any instance data members // have been properly patched. - // for (Value p : _valueList) { - try { - p.ice_postUnmarshal(); - } catch (Exception ex) { - String s = "exception raised by ice_postUnmarshal:\n" + Ex.toString(ex); - _stream.instance().initializationData().logger.warning(s); - } + p.ice_postUnmarshal(); } _valueList.clear(); } @@ -2651,7 +2637,7 @@ private void traceSkipSlice(String typeId, SliceType sliceType) { sliceType == SliceType.ExceptionSlice ? "exception" : "object", typeId, "Slicing", - _logger); + _instance.initializationData().logger); } } @@ -2698,7 +2684,6 @@ public static interface Unmarshaler { private int _minSeqSize; private final ValueFactoryManager _valueFactoryManager; - private final Logger _logger; private final java.util.function.Function> _classResolver; private static final String END_OF_BUFFER_MESSAGE = diff --git a/js/src/Ice/InputStream.js b/js/src/Ice/InputStream.js index 9e939b5610c..4e7f8601e72 100644 --- a/js/src/Ice/InputStream.js +++ b/js/src/Ice/InputStream.js @@ -963,7 +963,6 @@ export class InputStream { this._sizePos = -1; this._valueFactoryManager = this._instance.initializationData().valueFactoryManager; - this._logger = this._instance.initializationData().logger; this._classGraphDepthMax = this._instance.classGraphDepthMax(); } @@ -985,7 +984,6 @@ export class InputStream { // These are cached values derived from instance. DEV: console.assert(this._classGraphDepthMax === other._classGraphDepthMax); DEV: console.assert(this._valueFactoryManager === other._valueFactoryManager); - DEV: console.assert(this._logger === other._logger); [other._buf, this._buf] = [this._buf, other._buf]; [other._encoding, this._encoding] = [this._encoding, other._encoding]; @@ -1622,12 +1620,12 @@ export class InputStream { } traceSkipSlice(typeId, sliceType) { - if (this._instance.traceLevels().slicing > 0 && this._logger !== null) { + if (this._instance.traceLevels().slicing > 0) { traceSlicing( sliceType === SliceType.ExceptionSlice ? "exception" : "object", typeId, "Slicing", - this._logger, + this._instance.initializationData().logger, ); } } diff --git a/matlab/lib/+IceInternal/EncapsDecoder.m b/matlab/lib/+IceInternal/EncapsDecoder.m index 0a000073900..dc8f4e859fd 100644 --- a/matlab/lib/+IceInternal/EncapsDecoder.m +++ b/matlab/lib/+IceInternal/EncapsDecoder.m @@ -41,12 +41,7 @@ function finish(obj) % for i = 1:length(obj.delayedPostUnmarshal) v = obj.delayedPostUnmarshal{i}; - try - v.ice_postUnmarshal(); - catch ex - msg = sprintf('exception raised by ice_postUnmarshal:\n%s', getReport(ex, 'extended')); - obj.is.getCommunicator().getLogger().warning(msg); - end + v.ice_postUnmarshal(); end obj.delayedPostUnmarshal = {}; @@ -195,12 +190,7 @@ function unmarshal(obj, index, v) if v.iceDelayPostUnmarshal() obj.delayedPostUnmarshal{end + 1} = v; % See finish() else - try - v.ice_postUnmarshal(); - catch ex - msg = sprintf('exception raised by ice_postUnmarshal:\n%s', getReport(ex, 'extended')); - obj.is.getCommunicator().getLogger().warning(msg); - end + v.ice_postUnmarshal(); end else obj.valueList{end + 1} = v; @@ -217,12 +207,7 @@ function unmarshal(obj, index, v) if p.iceDelayPostUnmarshal() obj.delayedPostUnmarshal{end + 1} = p; % See finish() else - try - p.ice_postUnmarshal(); - catch ex - msg = sprintf('exception raised by ice_postUnmarshal:\n%s', getReport(ex, 'extended')); - obj.is.getCommunicator().getLogger().warning(msg); - end + p.ice_postUnmarshal(); end end obj.valueList = {};