Update -[NSMutableArray removeLastObject] (#433)

* Update `-[NSMutableArray removeLastObject]`

Updates the following implementation to avoid raising an exception if the array is already empty (or notifying observers if applicable):
 * `-[NSMutableArray removeLastObject]`
 * `-[GSMutableArray removeLastObject]`
 * `-[NSKeyValueMutableArray removeLastObject]`
 * `-[NSKeyValueIvarMutableArray removeLastObject]`

This brings the behavior of `-[NSMutableArray removeLastObject]` inline with the Apple implementation, improving compatibility for code bases which use both GNUStep and Apple objc/Foundation implementations.

* Add `-[NSMutableArray removeLastObject]` test case

Adds a test case to ensure `-[NSMutableArray removeLastObject]` does not raise an exception when called on an empty array.
This commit is contained in:
Earl Robsham 2024-08-10 17:44:02 -04:00 committed by GitHub
parent bf7ccc407d
commit a5ed5dbe11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 22 additions and 8 deletions

View file

@ -669,8 +669,7 @@ static Class GSInlineArrayClass;
_version++;
if (_count == 0)
{
[NSException raise: NSRangeException
format: @"Trying to remove from an empty array."];
return;
}
_count--;
RELEASE(_contents_array[_count]);