summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Schleifer <js@heap.zone>2018-08-17 03:17:14 +0200
committerJonathan Schleifer <js@heap.zone>2018-08-17 03:17:14 +0200
commit360d11bb85c03479789868bd9f9b7b16b7c689f8 (patch)
tree349f88f24865d4ec2ad027ce6697030a5a1b0293
parentdc33158a0bbebd8b1f07ad9a4fcc9464b5e1a7ca (diff)
AmigaOS 4: Do not use libauto
libauto loads the libraries too late.
-rw-r--r--configure.ac2
-rw-r--r--src/OFApplication.m10
-rw-r--r--src/OFFile.m32
-rw-r--r--src/OFFileManager.m32
-rw-r--r--src/OFLocale.m29
-rw-r--r--src/OFStdIOStream.m39
-rw-r--r--src/OFThread.m37
-rw-r--r--src/OFURLHandler_file.m51
-rw-r--r--tests/TestsAppDelegate.m9
9 files changed, 228 insertions, 13 deletions
diff --git a/configure.ac b/configure.ac
index c5322fe8..a9c867d7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -53,8 +53,6 @@ case "$host" in
])
;;
powerpc-*-amigaos*)
- LIBS="$LIBS -lauto"
-
enable_shared="no"
enable_threads="no"
;;
diff --git a/src/OFApplication.m b/src/OFApplication.m
index 7009c75f..b614e949 100644
--- a/src/OFApplication.m
+++ b/src/OFApplication.m
@@ -54,7 +54,11 @@
extern int _CRT_glob;
extern void __wgetmainargs(int *, wchar_t ***, wchar_t ***, int, int *);
#elif defined(OF_AMIGAOS)
-# define __USE_INLINE__
+# ifdef OF_AMIGAOS4
+# define __USE_INLINE__
+# define __NOLIBBASE__
+# define __NOGLOBALIFACE__
+# endif
# include <proto/exec.h>
# include <proto/dos.h>
#elif !defined(OF_IOS)
@@ -72,6 +76,10 @@ extern char **environ;
# undef asm
#endif
+#ifdef OF_AMIGAOS4
+extern struct ExecIFace *IExec;
+#endif
+
@interface OFApplication ()
- (instancetype)of_init OF_METHOD_FAMILY(init);
- (void)of_setArgumentCount: (int *)argc
diff --git a/src/OFFile.m b/src/OFFile.m
index 17dc2f41..fba8cdfc 100644
--- a/src/OFFile.m
+++ b/src/OFFile.m
@@ -58,7 +58,12 @@
#endif
#ifdef OF_AMIGAOS
-# define __USE_INLINE__
+# ifdef OF_AMIGAOS4
+# define __USE_INLINE__
+# define __NOLIBBASE__
+# define __NOGLOBALIFACE__
+# endif
+# include <proto/exec.h>
# include <proto/dos.h>
#endif
@@ -78,6 +83,12 @@
#ifndef OF_AMIGAOS
# define closeHandle(h) close(h)
#else
+# ifdef OF_AMIGAOS4
+extern struct ExecIFace *IExec;
+static struct Library *DOSBase = NULL;
+static struct DOSIFace *IDOS = NULL;
+# endif
+
struct of_file_handle {
of_file_handle_t previous, next;
BPTR handle;
@@ -105,6 +116,14 @@ OF_DESTRUCTOR()
for (of_file_handle_t iter = firstHandle; iter != NULL;
iter = iter->next)
Close(iter->handle);
+
+# ifdef OF_AMIGAOS4
+ if (IDOS != NULL)
+ DropInterface(IDOS);
+
+ if (DOSBase != NULL)
+ CloseLibrary(DOSBase);
+# endif
}
#endif
@@ -179,6 +198,17 @@ parseMode(const char *mode, bool *append)
@throw [OFInitializationFailedException
exceptionWithClass: self];
#endif
+
+#ifdef OF_AMIGAOS4
+ if ((DOSBase = OpenLibrary("dos.library", 36)) == NULL)
+ @throw [OFInitializationFailedException
+ exceptionWithClass: self];
+
+ if ((IDOS = (struct DOSIFace *)
+ GetInterface(DOSBase, "main", 1, NULL)) == NULL)
+ @throw [OFInitializationFailedException
+ exceptionWithClass: self];
+#endif
}
+ (instancetype)fileWithPath: (OFString *)path
diff --git a/src/OFFileManager.m b/src/OFFileManager.m
index 6a56fe9f..c3385335 100644
--- a/src/OFFileManager.m
+++ b/src/OFFileManager.m
@@ -42,6 +42,7 @@
#import "OFChangeCurrentDirectoryPathFailedException.h"
#import "OFCopyItemFailedException.h"
#import "OFGetCurrentDirectoryPathFailedException.h"
+#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFMoveItemFailedException.h"
#import "OFOutOfMemoryException.h"
@@ -58,7 +59,11 @@
#endif
#ifdef OF_AMIGAOS
-# define __USE_INLINE__
+# ifdef OF_AMIGAOS4
+# define __USE_INLINE__
+# define __NOLIBBASE__
+# define __NOGLOBALIFACE__
+# endif
# include <proto/exec.h>
# include <proto/dos.h>
# include <proto/locale.h>
@@ -67,6 +72,12 @@
@interface OFFileManager_default: OFFileManager
@end
+#ifdef OF_AMIGAOS4
+extern struct ExecIFace *IExec;
+static struct Library *DOSBase = NULL;
+static struct DOSIFace *IDOS = NULL;
+#endif
+
static OFFileManager *defaultManager;
const of_file_attribute_key_t of_file_attribute_key_size =
@@ -109,6 +120,14 @@ OF_DESTRUCTOR()
{
if (dirChanged)
UnLock(CurrentDir(originalDirLock));
+
+# ifdef OF_AMIGAOS4
+ if (IDOS != NULL)
+ DropInterface(IDOS);
+
+ if (DOSBase != NULL)
+ CloseLibrary(DOSBase);
+# endif
}
#endif
@@ -131,6 +150,17 @@ attributeForKeyOrException(of_file_attributes_t attributes,
if (self != [OFFileManager class])
return;
+#ifdef OF_AMIGAOS4
+ if ((DOSBase = OpenLibrary("dos.library", 36)) == NULL)
+ @throw [OFInitializationFailedException
+ exceptionWithClass: self];
+
+ if ((IDOS = (struct DOSIFace *)
+ GetInterface(DOSBase, "main", 1, NULL)) == NULL)
+ @throw [OFInitializationFailedException
+ exceptionWithClass: self];
+#endif
+
defaultManager = [[OFFileManager_default alloc] init];
}
diff --git a/src/OFLocale.m b/src/OFLocale.m
index 8f05904e..0d884d55 100644
--- a/src/OFLocale.m
+++ b/src/OFLocale.m
@@ -30,7 +30,11 @@
#import "OFOpenItemFailedException.h"
#ifdef OF_AMIGAOS
-# define __USE_INLINE__
+# ifdef OF_AMIGAOS4
+# define __NOLIBBASE__
+# define __NOGLOBALIFACE__
+# define __USE_INLINE__
+# endif
# include <proto/dos.h>
# include <proto/exec.h>
# include <proto/locale.h>
@@ -38,6 +42,29 @@
static OFLocale *currentLocale = nil;
+#ifdef OF_AMIGAOS4
+extern struct ExecIFace *IExec;
+static struct Library *DOSBase = NULL;
+static struct DOSIFace *IDOS = NULL;
+static struct Library *LocaleBase = NULL;
+static struct LocaleIFace *ILocale = NULL;
+
+OF_DESTRUCTOR()
+{
+ if (ILocale != NULL)
+ DropInterface(ILocale);
+
+ if (LocaleBase != NULL)
+ CloseLibrary(LocaleBase);
+
+ if (IDOS != NULL)
+ DropInterface(IDOS);
+
+ if (DOSBase != NULL)
+ CloseLibrary(DOSBase);
+}
+#endif
+
#ifndef OF_AMIGAOS
static void
parseLocale(char *locale, of_string_encoding_t *encoding,
diff --git a/src/OFStdIOStream.m b/src/OFStdIOStream.m
index ce38749c..3b724e83 100644
--- a/src/OFStdIOStream.m
+++ b/src/OFStdIOStream.m
@@ -36,13 +36,18 @@
# include "OFStdIOStream_Win32Console.h"
#endif
+#import "OFInitializationFailedException.h"
#import "OFNotOpenException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"
#ifdef OF_AMIGAOS
-# define __USE_INLINE__
+# ifdef OF_AMIGAOS4
+# define __USE_INLINE__
+# define __NOLIBBASE__
+# define __NOGLOBALIFACE__
+# endif
# include <proto/exec.h>
# include <proto/dos.h>
#endif
@@ -56,6 +61,12 @@ _reference_to_OFStdIOStream_Win32Console(void)
}
#endif
+#ifdef OF_AMIGAOS4
+extern struct ExecIFace *IExec;
+static struct Library *DOSBase = NULL;
+static struct DOSIFace *IDOS = NULL;
+#endif
+
OFStdIOStream *of_stdin = nil;
OFStdIOStream *of_stdout = nil;
OFStdIOStream *of_stderr = nil;
@@ -66,6 +77,14 @@ OF_DESTRUCTOR()
[of_stdin dealloc];
[of_stdout dealloc];
[of_stderr dealloc];
+
+# ifdef OF_AMIGAOS4
+ if (IDOS != NULL)
+ DropInterface(IDOS);
+
+ if (DOSBase != NULL)
+ CloseLibrary(DOSBase);
+# endif
}
#endif
@@ -105,11 +124,25 @@ of_log(OFConstantString *format, ...)
of_stdout = [[OFStdIOStream alloc] of_initWithFileDescriptor: 1];
of_stderr = [[OFStdIOStream alloc] of_initWithFileDescriptor: 2];
# else
- BPTR input = Input(), output = Output();
- BPTR error = ((struct Process *)FindTask(NULL))->pr_CES;
+ BPTR input, output, error;
bool inputClosable = false, outputClosable = false,
errorClosable = false;
+# ifdef OF_AMIGAOS4
+ if ((DOSBase = OpenLibrary("dos.library", 36)) == NULL)
+ @throw [OFInitializationFailedException
+ exceptionWithClass: self];
+
+ if ((IDOS = (struct DOSIFace *)
+ GetInterface(DOSBase, "main", 1, NULL)) == NULL)
+ @throw [OFInitializationFailedException
+ exceptionWithClass: self];
+# endif
+
+ input = Input();
+ output = Output();
+ error = ((struct Process *)FindTask(NULL))->pr_CES;
+
if (input == 0) {
input = Open("*", MODE_OLDFILE);
inputClosable = true;
diff --git a/src/OFThread.m b/src/OFThread.m
index a9e6ba5c..a4b23d2d 100644
--- a/src/OFThread.m
+++ b/src/OFThread.m
@@ -33,7 +33,12 @@
#include "platform.h"
#ifdef OF_AMIGAOS
-# define __USE_INLINE__
+# ifdef OF_AMIGAOS4
+# define __USE_INLINE__
+# define __NOLIBBASE__
+# define __NOGLOBALIFACE__
+# endif
+# include <proto/exec.h>
# include <proto/dos.h>
#endif
@@ -88,6 +93,21 @@
# define lrint(x) rint(x)
#endif
+#ifdef OF_AMIGAOS4
+extern struct ExecIFace *IExec;
+static struct Library *DOSBase = NULL;
+static struct DOSIFace *IDOS = NULL;
+
+OF_DESTRUCTOR()
+{
+ if (IDOS != NULL)
+ DropInterface(IDOS);
+
+ if (DOSBase != NULL)
+ CloseLibrary(DOSBase);
+}
+#endif
+
#if defined(OF_HAVE_THREADS)
# import "threading.h"
@@ -188,6 +208,21 @@ static OFDNSResolver *DNSResolver;
return thread->_threadDictionary;
}
+#elif defined(OF_AMIGAOS4)
++ (void)initialize
+{
+ if (self != [OFThread class])
+ return;
+
+ if ((DOSBase = OpenLibrary("dos.library", 36)) == NULL)
+ @throw [OFInitializationFailedException
+ exceptionWithClass: self];
+
+ if ((IDOS = (struct DOSIFace *)
+ GetInterface(DOSBase, "main", 1, NULL)) == NULL)
+ @throw [OFInitializationFailedException
+ exceptionWithClass: self];
+}
#endif
#ifdef OF_HAVE_SOCKETS
diff --git a/src/OFURLHandler_file.m b/src/OFURLHandler_file.m
index 960518bc..c8531ab4 100644
--- a/src/OFURLHandler_file.m
+++ b/src/OFURLHandler_file.m
@@ -49,6 +49,7 @@
#import "OFCreateDirectoryFailedException.h"
#import "OFCreateSymbolicLinkFailedException.h"
+#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFLinkFailedException.h"
#import "OFMoveItemFailedException.h"
@@ -67,7 +68,12 @@
#endif
#ifdef OF_AMIGAOS
-# define __USE_INLINE__
+# ifdef OF_AMIGAOS4
+# define __USE_INLINE__
+# define __NOLIBBASE__
+# define __NOGLOBALIFACE__
+# endif
+# include <proto/exec.h>
# include <proto/dos.h>
# include <proto/locale.h>
# ifdef OF_AMIGAOS4
@@ -104,6 +110,29 @@ static OFMutex *readdirMutex;
static WINAPI BOOLEAN (*func_CreateSymbolicLinkW)(LPCWSTR, LPCWSTR, DWORD);
#endif
+#ifdef OF_AMIGAOS4
+extern struct ExecIFace *IExec;
+static struct Library *DOSBase = NULL;
+static struct DOSIFace *IDOS = NULL;
+static struct Library *LocaleBase = NULL;
+static struct LocaleIFace *ILocale = NULL;
+
+OF_DESTRUCTOR()
+{
+ if (ILocale != NULL)
+ DropInterface(ILocale);
+
+ if (LocaleBase != NULL)
+ CloseLibrary(LocaleBase);
+
+ if (IDOS != NULL)
+ DropInterface(IDOS);
+
+ if (DOSBase != NULL)
+ CloseLibrary(DOSBase);
+}
+#endif
+
static int
of_stat(OFString *path, of_stat_t *buffer)
{
@@ -417,6 +446,26 @@ setSymbolicLinkDestinationAttribute(of_mutable_file_attributes_t attributes,
*/
[OFFile class];
+#ifdef OF_AMIGAOS4
+ if ((DOSBase = OpenLibrary("dos.library", 36)) == NULL)
+ @throw [OFInitializationFailedException
+ exceptionWithClass: self];
+
+ if ((IDOS = (struct DOSIFace *)
+ GetInterface(DOSBase, "main", 1, NULL)) == NULL)
+ @throw [OFInitializationFailedException
+ exceptionWithClass: self];
+
+ if ((LocaleBase = OpenLibrary("locale.library", 38)) == NULL)
+ @throw [OFInitializationFailedException
+ exceptionWithClass: self];
+
+ if ((ILocale = (struct LocaleIFace *)
+ GetInterface(LocaleBase, "main", 1, NULL)) == NULL)
+ @throw [OFInitializationFailedException
+ exceptionWithClass: self];
+#endif
+
#if defined(OF_HAVE_CHOWN) && defined(OF_HAVE_THREADS)
passwdMutex = [[OFMutex alloc] init];
#endif
diff --git a/tests/TestsAppDelegate.m b/tests/TestsAppDelegate.m
index b2fccc3f..38348d6b 100644
--- a/tests/TestsAppDelegate.m
+++ b/tests/TestsAppDelegate.m
@@ -85,8 +85,13 @@ main(int argc, char *argv[])
int tid;
#endif
-#if defined(OF_OBJFW_RUNTIME) && !defined(OF_WINDOWS)
- /* This does not work on Win32 if ObjFW is built as a DLL */
+#if defined(OF_OBJFW_RUNTIME) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS4)
+ /*
+ * This does not work on Win32 if ObjFW is built as a DLL.
+ *
+ * On AmigaOS 4, atexit() calls objc_exit() before our destructors have
+ * run, but we need to send messages in some destructors.
+ */
atexit(objc_exit);
#endif