From db19fc3308d911f1e73e0c0a85b3b928a2c59e7c Mon Sep 17 00:00:00 2001 From: Frederik Seiffert Date: Tue, 19 May 2020 16:07:02 +0200 Subject: [PATCH 1/9] Android assets improvements to support directories - Extend NSBundle resources support to handle directories in Android assets. - Fix NSFileManager -isReadableFileAtPath: to also support directories in Android assets. --- ChangeLog | 7 +++++++ Source/NSBundle.m | 16 ++++++++++++++++ Source/NSFileManager.m | 15 ++++++++++++--- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 35e243797..a4453cb6f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2020-05-20 Frederik Seiffert + + * Source/NSBundle.m: Extend NSBundle resources support to handle + directories in Android assets. + * Source/NSFileManager.m: Fix NSFileManager -isReadableFileAtPath: + to also support directories in Android assets. + 2020-05-14 Frederik Seiffert * Headers/Foundation/NSException.h: diff --git a/Source/NSBundle.m b/Source/NSBundle.m index c494aa822..fdedf0eb2 100644 --- a/Source/NSBundle.m +++ b/Source/NSBundle.m @@ -2228,6 +2228,22 @@ IF_NO_GC( } } +#ifdef __ANDROID__ + /* Android: check for directory resources by passing file path as subpath, + * as AAssetDir and thereby NSDirectoryEnumerator doesn't list directories + */ + subPath = subPath ? [subPath stringByAppendingPathComponent: file] : file; + pathlist = [[self _bundleResourcePathsWithRootPath: rootPath + subPath: subPath localization: nil] objectEnumerator]; + while ((path = [pathlist nextObject]) != nil) + { + if (YES == [mgr isReadableFileAtPath: path]) + { + return path; + } + } +#endif /* __ANDROID__ */ + return nil; } diff --git a/Source/NSFileManager.m b/Source/NSFileManager.m index 8946e285b..b0ff06d75 100644 --- a/Source/NSFileManager.m +++ b/Source/NSFileManager.m @@ -1806,8 +1806,8 @@ static NSStringEncoding defaultEncoding; { #ifdef __ANDROID__ /* Android: try using asset manager if path is in - * main bundle resources - */ + * main bundle resources + */ AAsset *asset = [NSBundle assetForPath: path]; if (asset) { @@ -1877,13 +1877,22 @@ static NSStringEncoding defaultEncoding; } #ifdef __ANDROID__ - // Android: try using asset manager if path is in main bundle resources + /* Android: try using asset manager if path is in + * main bundle resources + */ AAsset *asset = [NSBundle assetForPath: path]; if (asset) { AAsset_close(asset); return YES; } + + AAssetDir *assetDir = [NSBundle assetDirForPath: path]; + if (assetDir) + { + AAssetDir_close(assetDir); + return YES; + } #endif return NO; From d04bbaafd7ceb64e912cec375fea5ff953142598 Mon Sep 17 00:00:00 2001 From: Frederik Seiffert Date: Wed, 27 May 2020 10:42:31 +0200 Subject: [PATCH 2/9] Fix optional NSFilePresenter methods not being declared as optional. --- Headers/Foundation/NSFilePresenter.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Headers/Foundation/NSFilePresenter.h b/Headers/Foundation/NSFilePresenter.h index 879fd2bc1..2e43eea21 100644 --- a/Headers/Foundation/NSFilePresenter.h +++ b/Headers/Foundation/NSFilePresenter.h @@ -39,11 +39,16 @@ DEFINE_BLOCK_TYPE(GSFilePresentedItemChangesWithCompletionHandler, void, NSError @protocol NSFilePresenter -// @required - (NSURL *) presentedItemURL; - (NSOperationQueue *) presentedItemOperationQueue; -// @optional +#if GS_PROTOCOLS_HAVE_OPTIONAL +@optional +#else +@end +@interface NSObject (NSFilePresenter) +#endif + - (NSURL *) primaryPresentedItemURL; - (NSString *) observedPresentedItemUbiquityAttributes; From b05c6d65bfc42a628a447a238f0683e2700744ea Mon Sep 17 00:00:00 2001 From: Frederik Seiffert Date: Fri, 5 Jun 2020 11:48:35 +0200 Subject: [PATCH 3/9] Test replacing a weak value in NSMapTable. --- Tests/base/NSMapTable/weakObjects.m | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Tests/base/NSMapTable/weakObjects.m b/Tests/base/NSMapTable/weakObjects.m index 895a037b3..db7d05f63 100644 --- a/Tests/base/NSMapTable/weakObjects.m +++ b/Tests/base/NSMapTable/weakObjects.m @@ -19,9 +19,14 @@ int main() NSAutoreleasePool *arp2 = [NSAutoreleasePool new]; - id testObj = [[[NSObject alloc] init] autorelease]; - [mapTable setObject:testObj forKey:@"test"]; - PASS([mapTable objectForKey:@"test"] != nil, "Table retains active weak reference"); + id testObj1 = [[[NSObject alloc] init] autorelease]; + id testObj2 = [[[NSObject alloc] init] autorelease]; + + [mapTable setObject:testObj1 forKey:@"test"]; + PASS([mapTable objectForKey:@"test"] == testObj1, "Table retains first active weak reference"); + + [mapTable setObject:testObj2 forKey:@"test"]; + PASS([mapTable objectForKey:@"test"] == testObj2, "Table retains second active weak reference"); [arp2 release]; arp2 = nil; From 71f6cde4bdc0e2181f19e3d65dd96938c75d0aa6 Mon Sep 17 00:00:00 2001 From: Frederik Seiffert Date: Fri, 5 Jun 2020 11:39:32 +0200 Subject: [PATCH 4/9] Fix replacing an existing value in a weak objects map table. --- ChangeLog | 7 +++++++ Source/NSConcreteMapTable.m | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 9a2ac91cc..aa94b001c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2020-06-05 Frederik Seiffert + + * Tests/base/NSMapTable/weakObjects.m, + * Source/NSConcreteMapTable.m: + Add test for and fix replacing an existing value in a weak objects map + table. + 2020-05-25 Frederik Seiffert * Source/NSUserDefaults.m: diff --git a/Source/NSConcreteMapTable.m b/Source/NSConcreteMapTable.m index 714d336b1..5c01e54fd 100644 --- a/Source/NSConcreteMapTable.m +++ b/Source/NSConcreteMapTable.m @@ -1392,7 +1392,7 @@ const NSMapTableValueCallBacks NSOwnedPointerMapValueCallBacks = if (GSI_MAP_READ_VALUE(self, &node->value).obj != anObject) { GSI_MAP_RELEASE_VAL(self, node->value); - node->value.obj = anObject; + GSI_MAP_WRITE_VAL(self, &node->value, (GSIMapVal)anObject); GSI_MAP_RETAIN_VAL(self, node->value); version++; } From 5bbe378a797272afd5c556f9cdc0d5d2852a0422 Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Fri, 5 Jun 2020 13:46:34 +0200 Subject: [PATCH 5/9] remove unneeded window headers include, since common.h will include GSConfig.h --- Source/win32/GSFileHandle.m | 3 --- 1 file changed, 3 deletions(-) diff --git a/Source/win32/GSFileHandle.m b/Source/win32/GSFileHandle.m index 45e621b20..4795dd422 100644 --- a/Source/win32/GSFileHandle.m +++ b/Source/win32/GSFileHandle.m @@ -22,9 +22,6 @@ Boston, MA 02111 USA. */ -#include -#include - #include "common.h" #define EXPOSE_NSFileHandle_IVARS 1 #define EXPOSE_GSFileHandle_IVARS 1 From 6ab0e3465fc66bf8a1b21083ea5eb31ce43366e4 Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Fri, 5 Jun 2020 16:32:55 +0200 Subject: [PATCH 6/9] MSYS and MSYS2 differ in the tricks to include both windows.h and winsock2.h, use __MINGW32_VERSION to differentiate them --- Headers/GNUstepBase/GSConfig.h.in | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Headers/GNUstepBase/GSConfig.h.in b/Headers/GNUstepBase/GSConfig.h.in index 8d23b6f5d..9ee38c4af 100644 --- a/Headers/GNUstepBase/GSConfig.h.in +++ b/Headers/GNUstepBase/GSConfig.h.in @@ -306,8 +306,18 @@ typedef struct { #define WINVER Windows2000 #endif +// Trick to distinguish between MSYS/MinGW and MSYS2/MinGW32, the latter defines +// __MINGW32_MAJOR_VERSION and __MINGW32_MINOR_VERSION for compatibility +// but to a lower version than older MSYS/MinGW, but not the compound version +// +#if defined(__MINGW32_VERSION) +#define __USE_W32_SOCKETS +#include +#include +#else #include #include +#endif #undef __OBJC_BOOL #undef BOOL From 41badcb417d98225ec40eb17242a182ab336195c Mon Sep 17 00:00:00 2001 From: Richard Frith-Macdonald Date: Fri, 5 Jun 2020 17:43:46 +0100 Subject: [PATCH 7/9] Fix leak of new operation in -blockOperationWithBlock: method. Make -addExecutionBlock: ensure it works with an on-heap copy of its argument. Tidy code to have NSBlockOperation methods with normal formatting and alphabetical order. Tidy code to use standard macros for memory management. --- Source/NSOperation.m | 81 +++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/Source/NSOperation.m b/Source/NSOperation.m index 4a8eb5661..bdaff4614 100644 --- a/Source/NSOperation.m +++ b/Source/NSOperation.m @@ -97,7 +97,7 @@ static NSArray *empty = nil; + (void) initialize { empty = [NSArray new]; - [[NSObject leakAt: &empty] release]; + RELEASE([NSObject leakAt: &empty]); } - (void) addDependency: (NSOperation *)op @@ -430,8 +430,9 @@ static NSArray *empty = nil; - (void) start { - NSAutoreleasePool *pool = [NSAutoreleasePool new]; - double prio = [NSThread threadPriority]; + ENTER_POOL + + double prio = [NSThread threadPriority]; AUTORELEASE(RETAIN(self)); // Make sure we exist while running. [internal->lock lock]; @@ -486,7 +487,7 @@ static NSArray *empty = nil; NS_ENDHANDLER; [self _finish]; - [pool release]; + LEAVE_POOL } - (double) threadPriority @@ -507,7 +508,7 @@ static NSArray *empty = nil; /* retain while finishing so that we don't get deallocated when our * queue removes and releases us. */ - [self retain]; + RETAIN(self); [internal->lock lock]; if (NO == internal->finished) { @@ -532,7 +533,7 @@ static NSArray *empty = nil; } } [internal->lock unlock]; - [self release]; + RELEASE(self); } @end @@ -540,15 +541,20 @@ static NSArray *empty = nil; @implementation NSBlockOperation -// Initialize -- (id) init ++ (instancetype) blockOperationWithBlock: (GSBlockOperationBlock)block { - self = [super init]; - if(self != nil) - { - _executionBlocks = [[NSMutableArray alloc] initWithCapacity: 1]; - } - return self; + NSBlockOperation *op = [[self alloc] init]; + + [op addExecutionBlock: block]; + return AUTORELEASE(op); +} + +- (void) addExecutionBlock: (GSBlockOperationBlock)block +{ + GSBlockOperationBlock blockCopy = [block copy]; + + [_executionBlocks addObject: blockCopy]; + RELEASE(blockCopy); } - (void) dealloc @@ -557,29 +563,27 @@ static NSArray *empty = nil; [super dealloc]; } -// Managing the blocks in the Operation -+ (instancetype)blockOperationWithBlock: (GSBlockOperationBlock)block -{ - NSBlockOperation *op = [[self alloc] init]; - [op addExecutionBlock: block]; - return op; -} - -- (void)addExecutionBlock: (GSBlockOperationBlock)block -{ - [_executionBlocks addObject: block]; -} - - (NSArray *) executionBlocks { return _executionBlocks; } +- (id) init +{ + self = [super init]; + if (self != nil) + { + _executionBlocks = [[NSMutableArray alloc] initWithCapacity: 1]; + } + return self; +} + - (void) main { - NSEnumerator *en = [[self executionBlocks] objectEnumerator]; + NSEnumerator *en = [[self executionBlocks] objectEnumerator]; GSBlockOperationBlock theBlock; - while((theBlock = [en nextObject]) != NULL) + + while ((theBlock = [en nextObject]) != NULL) { CALL_BLOCK_NO_ARGS(theBlock); } @@ -836,9 +840,9 @@ static NSOperationQueue *mainQueue = nil; internal->name = [[NSString alloc] initWithFormat: @"NSOperation %p", self]; } - s = [internal->name retain]; + s = RETAIN(internal->name); [internal->lock unlock]; - return [s autorelease]; + return AUTORELEASE(s); } - (NSUInteger) operationCount @@ -888,7 +892,7 @@ static NSOperationQueue *mainQueue = nil; if (NO == [internal->name isEqual: s]) { [self willChangeValueForKey: @"name"]; - [internal->name release]; + RELEASE(internal->name); internal->name = [s copy]; [self didChangeValueForKey: @"name"]; } @@ -915,10 +919,10 @@ static NSOperationQueue *mainQueue = nil; [internal->lock lock]; while ((op = [internal->operations lastObject]) != nil) { - [op retain]; + RETAIN(op); [internal->lock unlock]; [op waitUntilFinished]; - [op release]; + RELEASE(op); [internal->lock lock]; } [internal->lock unlock]; @@ -979,7 +983,7 @@ static NSOperationQueue *mainQueue = nil; - (void) _thread { - NSAutoreleasePool *pool = [NSAutoreleasePool new]; + ENTER_POOL [[[NSThread currentThread] threadDictionary] setObject: self forKey: threadKey]; @@ -1022,11 +1026,10 @@ static NSOperationQueue *mainQueue = nil; { NS_DURING { - NSAutoreleasePool *opPool = [NSAutoreleasePool new]; - + ENTER_POOL [NSThread setThreadPriority: [op threadPriority]]; [op start]; - RELEASE(opPool); + LEAVE_POOL } NS_HANDLER { @@ -1043,7 +1046,7 @@ static NSOperationQueue *mainQueue = nil; [internal->lock lock]; internal->threadCount--; [internal->lock unlock]; - RELEASE(pool); + LEAVE_POOL [NSThread exit]; } From 3fc184e5d7b3d01eba6b85cd13f876ae7540335b Mon Sep 17 00:00:00 2001 From: Richard Frith-Macdonald Date: Sat, 6 Jun 2020 12:15:08 +0100 Subject: [PATCH 8/9] fix indentation --- ChangeLog | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3e5828144..be4226f25 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,16 +1,16 @@ 2020-06-06 Frederik Seiffert - * Source/NSBundle.m: Extend NSBundle resources support to handle - directories in Android assets. - * Source/NSFileManager.m: Fix NSFileManager -isReadableFileAtPath: - to also support directories in Android assets. + * Source/NSBundle.m: Extend NSBundle resources support to handle + directories in Android assets. + * Source/NSFileManager.m: Fix NSFileManager -isReadableFileAtPath: + to also support directories in Android assets. 2020-06-05 Frederik Seiffert - * Tests/base/NSMapTable/weakObjects.m, - * Source/NSConcreteMapTable.m: - Add test for and fix replacing an existing value in a weak objects map - table. + * Tests/base/NSMapTable/weakObjects.m, + * Source/NSConcreteMapTable.m: + Add test for and fix replacing an existing value in a weak objects map + table. 2020-05-25 Frederik Seiffert From 0b689d4df4e56d1ea67ec973b0e064599a02f562 Mon Sep 17 00:00:00 2001 From: Frederik Seiffert Date: Wed, 3 Jun 2020 16:53:28 +0200 Subject: [PATCH 9/9] Fix finding libiconv via cross.config. --- configure | 29 ++++++++++++++++++++++++++--- configure.ac | 17 ++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/configure b/configure index 70ad993b9..7a76d7d1f 100755 --- a/configure +++ b/configure @@ -10985,7 +10985,15 @@ if test $enable_iconv = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking iconv support" >&5 $as_echo_n "checking iconv support... " >&6; } if test "$cross_compiling" = yes; then : - found_iconv="$cross_found_iconv_libc" + found_iconv="$cross_found_iconv_libc"; + if test "$found_iconv" = "yes"; then + +$as_echo "#define HAVE_ICONV 1" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes, in libc (via cross.config)" >&5 +$as_echo "yes, in libc (via cross.config)" >&6; } + fi + else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -11041,7 +11049,13 @@ esac LIBS="-liconv $LIBS" if test "$cross_compiling" = yes; then : found_iconv="$cross_found_iconv_liconv"; - if test "$found_iconv" = "no"; then + if test "$found_iconv" = "yes"; then + +$as_echo "#define HAVE_ICONV 1" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes, -liconv (via cross.config)" >&5 +$as_echo "yes, -liconv (via cross.config)" >&6; } + else LIBS="$old_LIBS" fi @@ -11080,7 +11094,16 @@ if test $found_iconv = no ; then LIBS="-lgiconv $LIBS" if test "$cross_compiling" = yes; then : found_iconv="$cross_found_iconv_lgiconv"; - if test "$found_iconv" = "no"; then + if test "$found_iconv" = "yes"; then + +$as_echo "#define HAVE_ICONV 1" >>confdefs.h + + +$as_echo "#define HAVE_GICONV 1" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes, -lgiconv (via cross.config)" >&5 +$as_echo "yes, -lgiconv (via cross.config)" >&6; } + else LIBS="$old_LIBS" fi diff --git a/configure.ac b/configure.ac index e541f8c02..3b5bf657f 100644 --- a/configure.ac +++ b/configure.ac @@ -2996,7 +2996,11 @@ int main(int argc,char **argv) , found_iconv=no , - found_iconv="$cross_found_iconv_libc", + found_iconv="$cross_found_iconv_libc"; + if test "$found_iconv" = "yes"; then + AC_DEFINE(HAVE_ICONV,1, [Define if you have this function]) + AC_MSG_RESULT([[yes, in libc (via cross.config)]]) + fi ) if test $found_iconv = no ; then @@ -3025,7 +3029,10 @@ if test $found_iconv = no ; then LIBS="$old_LIBS" , found_iconv="$cross_found_iconv_liconv"; - if test "$found_iconv" = "no"; then + if test "$found_iconv" = "yes"; then + AC_DEFINE(HAVE_ICONV,1, [Define if you have this function]) + AC_MSG_RESULT([[yes, -liconv (via cross.config)]]) + else LIBS="$old_LIBS" fi ) @@ -3049,7 +3056,11 @@ if test $found_iconv = no ; then LIBS="$old_LIBS" , found_iconv="$cross_found_iconv_lgiconv"; - if test "$found_iconv" = "no"; then + if test "$found_iconv" = "yes"; then + AC_DEFINE(HAVE_ICONV,1, [Define if you have this function]) + AC_DEFINE(HAVE_GICONV,1, [Define if you have this function]) + AC_MSG_RESULT([[yes, -lgiconv (via cross.config)]]) + else LIBS="$old_LIBS" fi )