gh-106287: Improve error handling in marshalling code#106288
Closed
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes#106287
Currently
w_objectandw_complex_objectroutines continue to marshal complex object until they return to their callers, regardless of error or exception occurred. This leads to ignored exceptions and, as a result, assertion failures in debug builds, e. g. ifPyObject_GetBufferis called during marshalling of complex object with exception being set. Another consequence is the late return fromw_objectin case of error: if arg is a container and the first item is unmarshallable, all other items will be processed anyway.This fix improves error handling of some marshalling routines, making them to return status value (0 or 1) depending on whether an error occurred, and use this status to decide whether to marshal remaining objects or not.
w_objectandw_complex_objectfunctions to return 1 if marshalling succeeded and 0 if error occurredw_objectcheck if error occurred and return 0 in this caseW_OBJECTmacro that callsw_objectand returns 0 from function in which it is expandedw_complex_objectfunction to useW_OBJECTmacro calls instead ofw_objectfunction callsW_SIZEmacro to return 0 on failurew_pstringreturn 0 to avoid compiler warning