-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
append!, prepend!, and splice! should not modify arrays if convert throws #7642
Comments
…rray elements. This causes a MethodError to be thrown before any array growing/shrinking happens. Fixes #7642
I don't think this is a bug. |
This strikes me as pretty buggy behavior. What's the rationale for this not being a bug? |
If a mutating operation fails, the object's state after the error is not well defined. But it would be nice to do mutations atomically when there is no cost. In this case I don't yet see a cheap way to do this. |
You can try converting one element first and bail out if that fails. This won't make this atomic, but it will make it less likely to leave the array to be spliced into in a broken state. |
…plice! in case conversion fails. Fixes #7642.
… conversion fails. This allows us to un-modify the original arrays so the user gets back what they put in. Fixes #7642
…conversion fails. If it does, the original arrays are rewound to their original state. Fixes #7642
… the same typed arrays. This guards against the possibility of failing on arrays of different types and messing up the original array. Fixes #7642
…e for atomicity. Adds further method definitions when array element types don't match to try to convert the second array to the element type of the first. Fixes #7642
The dequeue functions that take scalars are carefully written to call
convert
before resizing the vector, but the functions that take vectors (append!
,prepend!
, andsplice!
) mutate the array but leave the corresponding values uninitialized. It would be preferable if these functions either checked ifconvert
fails before mutating the array, or undid the changes on failure. See also julia-users discussion.The text was updated successfully, but these errors were encountered: