ObjFW  Changes On Branch 5c0bf046cc66f767

Changes In Branch 0.90 Through [5c0bf046cc] Excluding Merge-Ins

This is equivalent to a diff from 636098dbdd to 5c0bf046cc

2017-09-24
01:21
OFTCPSocket: Retain exception for async connect check-in: 892e623e3a user: js tags: 0.90
2017-08-20
19:30
ChangeLog: Add 0.90.1 check-in: 5c0bf046cc user: js tags: 0.90.1-release, 0.90
19:22
Set version to 0.90.1 check-in: 7a08766151 user: js tags: 0.90
2017-07-29
10:50
Set version to 0.90-dev as 0.90 has been branched check-in: 7e614ef5c0 user: js tags: trunk
10:22
Create 0.90 branch check-in: f934699959 user: js tags: 0.90
2017-07-24
20:33
runtime: Don't depend on platform.h in ObjFW-RT.h check-in: 636098dbdd user: js tags: trunk
20:29
OFINIFile: Always use \r\n check-in: 1248c00475 user: js tags: trunk

Modified ChangeLog from [22a812d84f] to [f57f7a2cc8].

1
2
3















































4
5
6
7
8
9
10
Legend:
 * Changes of existing features or bugfixes
 + New features
















































ObjFW 0.8 -> ObjFW 0.8.1, 04.10.2015
 * Adjust to __nullable / __nonnull being changed to _Nullable / _Nonnull in
   Clang 3.7 (this fixes compilation with Clang 3.7)
 * Blocks: Proper handling when called from a byref handler
 * Fix compilation on Solaris
 * Fix compilation for Wii, PSP and Nintendo DS



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Legend:
 * Changes of existing features or bugfixes
 + New features

This file only contains the most significant changes.

ObjFW 0.90 -> ObjFW 0.90.1, 20.08.2017
 * OFData: Fix -[description]
 * OFFileManager: Set errno to 0 before readdir()
 * OFDate: Add -[localMinute]
 * OFTarArchiveEntry: Fix prefix handling for ustar
 * OFZIPArchive: Fix uncompressed + data descriptor
 * OFArray: Fix MessagePack encoding
 * of_asprintf: Don't require set up OFLocalization
 * OFGZIPStream: Add missing documentation
 * Fix a linker warning on OpenBSD/SPARC64
 * Remove the OFFile b modes from MorphOS
   (they were already removed for all other OSes)

ObjFW 0.8.1 -> ObjFW 0.90, 01.08.2017
 + New classes: OFFileManager, OFGZIPStream, OFTarArchive, OFTarArchiveEntry
		OFHMAC, OFSandbox, OFHTTPCookie, OFHTTPCookieManager,
		OFLocalization
 + New platforms: Nintendo 3DS, MorphOS
 + New lookup assembly for platforms: SPARC64/ELF, ARM64/ELF
 + New forwarding for: ARM64/ELF
 + New tools: objfw-new (to create boilerplate code)
 + New options: --disable-unicode-tables
 * Required GCC version increased to 4.6
 * OFDataArray was split into OFData and OFMutableData
 * OFURL was split into OFURL and OFMutableURL
 * Most properties are now nonatomic
   (this changes from returned retained + autoreleased to +0 retained)
 * Correct handling of encoding on Win32 console
   (stream is read and written in UTF-8 and translated to UTF-16 on the fly)
 * Runtime is now built as a separate library
 + More encodings for strings
 * Reworked OFOptionsParser API
 * Refactored OFKernelEventObserver
 * Better randomization of HTTP header order
 * Allow overriding all HTTP headers
 * Definition of thread priorities changed
 + Key Value Coding
 + Exceptions in ObjC++
 * OFHash was renamed to OFCryptoHash
 + PBKDF2
 + scrypt
 + Xcode project to build for iOS
 + String decomposition to NFD
 * OFFile modes simplified ('b' removed)

ObjFW 0.8 -> ObjFW 0.8.1, 04.10.2015
 * Adjust to __nullable / __nonnull being changed to _Nullable / _Nonnull in
   Clang 3.7 (this fixes compilation with Clang 3.7)
 * Blocks: Proper handling when called from a byref handler
 * Fix compilation on Solaris
 * Fix compilation for Wii, PSP and Nintendo DS

Modified configure.ac from [12f3d4bae6] to [cbc3ad562a].

1
2
3
4
5
6
7
8
AC_INIT(ObjFW, 0.9-dev, js@heap.zone)
BUILDSYS_INIT

AS_IF([test configure.ac -nt configure], [
	AC_MSG_ERROR([configure.ac is newer than configure! Run autoreconf!])
])

AC_CONFIG_SRCDIR(src)
|







1
2
3
4
5
6
7
8
AC_INIT(ObjFW, 0.90.1, js@heap.zone)
BUILDSYS_INIT

AS_IF([test configure.ac -nt configure], [
	AC_MSG_ERROR([configure.ac is newer than configure! Run autoreconf!])
])

AC_CONFIG_SRCDIR(src)
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
	*-morphos*)
		AS_IF([test x"$with_ixemul" != x"yes"], [
			OBJCFLAGS="$OBJCFLAGS -noixemul"
			LDFLAGS="$LDFLAGS -noixemul"
			enable_files="yes"	# Required for reading ENV:

			AC_SUBST(NOIXEMUL, -noixemul)
			AC_SUBST(OBJFW_RT_MORPHOS_LIB, objfw-rt.library)
		])

		enable_shared="no"
		enable_threads="no"
		;;
	*-msdosdjgpp*)
		enable_shared="no"







<







21
22
23
24
25
26
27

28
29
30
31
32
33
34
	*-morphos*)
		AS_IF([test x"$with_ixemul" != x"yes"], [
			OBJCFLAGS="$OBJCFLAGS -noixemul"
			LDFLAGS="$LDFLAGS -noixemul"
			enable_files="yes"	# Required for reading ENV:

			AC_SUBST(NOIXEMUL, -noixemul)

		])

		enable_shared="no"
		enable_threads="no"
		;;
	*-msdosdjgpp*)
		enable_shared="no"
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
	])
	AS_IF([test x"$enable_static" = x"yes" -o x"$enable_shared" = x"no"], [
		AC_SUBST(ENCODINGS_A, "encodings.a")
		AC_SUBST(ENCODINGS_ENCODINGS_A, "encodings/encodings.a")
	])
])

AC_CHECK_FUNCS(sigaction)

AC_CHECK_FUNCS(arc4random random, break)

AC_CHECK_LIB(dl, dlopen, LIBS="$LIBS -ldl")
AC_CHECK_HEADERS_ONCE(dlfcn.h)
case "$host_os" in
	netbsd*)
		dnl dladdr exists on NetBSD, but it is completely broken.







<
<







652
653
654
655
656
657
658


659
660
661
662
663
664
665
	])
	AS_IF([test x"$enable_static" = x"yes" -o x"$enable_shared" = x"no"], [
		AC_SUBST(ENCODINGS_A, "encodings.a")
		AC_SUBST(ENCODINGS_ENCODINGS_A, "encodings/encodings.a")
	])
])



AC_CHECK_FUNCS(arc4random random, break)

AC_CHECK_LIB(dl, dlopen, LIBS="$LIBS -ldl")
AC_CHECK_HEADERS_ONCE(dlfcn.h)
case "$host_os" in
	netbsd*)
		dnl dladdr exists on NetBSD, but it is completely broken.
1038
1039
1040
1041
1042
1043
1044

1045
1046
1047
1048
1049
1050
1051
		AC_DEFINE(HAVE_EPOLL, 1, [Whether we have epoll])
		AC_SUBST(OFKERNELEVENTOBSERVER_EPOLL_M,
			"OFKernelEventObserver_epoll.m")
		break
	])

	AS_IF([test x"$with_wii" = x"yes"], [

		AC_SUBST(OFKERNELEVENTOBSERVER_POLL_M,
			"OFKernelEventObserver_poll.m")
	], [
		AC_CHECK_HEADERS(poll.h)
		AC_CHECK_FUNC(poll, [
			AC_DEFINE(HAVE_POLL, 1, [Whether we have poll()])
			AC_SUBST(OFKERNELEVENTOBSERVER_POLL_M,







>







1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
		AC_DEFINE(HAVE_EPOLL, 1, [Whether we have epoll])
		AC_SUBST(OFKERNELEVENTOBSERVER_EPOLL_M,
			"OFKernelEventObserver_epoll.m")
		break
	])

	AS_IF([test x"$with_wii" = x"yes"], [
		AC_DEFINE(HAVE_POLL, 1, [Whether we have poll()])
		AC_SUBST(OFKERNELEVENTOBSERVER_POLL_M,
			"OFKernelEventObserver_poll.m")
	], [
		AC_CHECK_HEADERS(poll.h)
		AC_CHECK_FUNC(poll, [
			AC_DEFINE(HAVE_POLL, 1, [Whether we have poll()])
			AC_SUBST(OFKERNELEVENTOBSERVER_POLL_M,

Modified extra.mk.in from [130d0ab22e] to [f18de84cc5].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
OBJFW_SHARED_LIB = @OBJFW_SHARED_LIB@
OBJFW_STATIC_LIB = @OBJFW_STATIC_LIB@
# When changing: Be sure to also change these in the Xcode project!
OBJFW_LIB_MAJOR = 8
OBJFW_LIB_MINOR = 0
OBJFW_LIB_MAJOR_MINOR = ${OBJFW_LIB_MAJOR}.${OBJFW_LIB_MINOR}

OBJFW_RT_SHARED_LIB = @OBJFW_RT_SHARED_LIB@
OBJFW_RT_STATIC_LIB = @OBJFW_RT_STATIC_LIB@
OBJFW_RT_MORPHOS_LIB = @OBJFW_RT_MORPHOS_LIB@
OBJFW_RT_LIB_MAJOR = 0
OBJFW_RT_LIB_MINOR = 0
OBJFW_RT_LIB_MAJOR_MINOR = ${OBJFW_RT_LIB_MAJOR}.${OBJFW_RT_LIB_MINOR}

OBJFW_BRIDGE_SHARED_LIB = @OBJFW_BRIDGE_SHARED_LIB@
OBJFW_BRIDGE_STATIC_LIB = @OBJFW_BRIDGE_STATIC_LIB@





|




<







1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
OBJFW_SHARED_LIB = @OBJFW_SHARED_LIB@
OBJFW_STATIC_LIB = @OBJFW_STATIC_LIB@
# When changing: Be sure to also change these in the Xcode project!
OBJFW_LIB_MAJOR = 8
OBJFW_LIB_MINOR = 1
OBJFW_LIB_MAJOR_MINOR = ${OBJFW_LIB_MAJOR}.${OBJFW_LIB_MINOR}

OBJFW_RT_SHARED_LIB = @OBJFW_RT_SHARED_LIB@
OBJFW_RT_STATIC_LIB = @OBJFW_RT_STATIC_LIB@

OBJFW_RT_LIB_MAJOR = 0
OBJFW_RT_LIB_MINOR = 0
OBJFW_RT_LIB_MAJOR_MINOR = ${OBJFW_RT_LIB_MAJOR}.${OBJFW_RT_LIB_MINOR}

OBJFW_BRIDGE_SHARED_LIB = @OBJFW_BRIDGE_SHARED_LIB@
OBJFW_BRIDGE_STATIC_LIB = @OBJFW_BRIDGE_STATIC_LIB@

Modified src/OFApplication.m from [c9d4f7d315] to [a37acbc186].

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

#ifdef OF_NINTENDO_DS
# define asm __asm__
# include <nds.h>
# undef asm
#endif

#ifdef HAVE_SIGACTION
# ifndef SA_RESTART
#  define SA_RESTART 0
# endif
#endif

@interface OFApplication ()
- (instancetype)of_init OF_METHOD_FAMILY(init);
- (void)of_setArgumentCount: (int *)argc
	  andArgumentValues: (char **[])argv;
#ifdef OF_WINDOWS
- (void)of_setArgumentCount: (int)argc
      andWideArgumentValues: (wchar_t *[])argv;







<
<
<
<
<
<







67
68
69
70
71
72
73






74
75
76
77
78
79
80

#ifdef OF_NINTENDO_DS
# define asm __asm__
# include <nds.h>
# undef asm
#endif







@interface OFApplication ()
- (instancetype)of_init OF_METHOD_FAMILY(init);
- (void)of_setArgumentCount: (int *)argc
	  andArgumentValues: (char **[])argv;
#ifdef OF_WINDOWS
- (void)of_setArgumentCount: (int)argc
      andWideArgumentValues: (wchar_t *[])argv;
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
- (id <OFApplicationDelegate>)delegate
{
	return _delegate;
}

- (void)setDelegate: (id <OFApplicationDelegate>)delegate
{
#ifdef HAVE_SIGACTION
	struct sigaction sa = { .sa_flags = SA_RESTART };
	sigemptyset(&sa.sa_mask);

# define REGISTER_SIGNAL(sig)						\
	if ([delegate respondsToSelector:				\
	    @selector(applicationDidReceive##sig)]) {			\
		_##sig##Handler = (void (*)(id, SEL))[(id)delegate	\
		    methodForSelector:					\
		    @selector(applicationDidReceive##sig)];		\
									\
		sa.sa_handler = handle##sig;				\
	} else								\
		sa.sa_handler = SIG_DFL;				\
									\
	OF_ENSURE(sigaction(sig, &sa, NULL) == 0);
#else
# define REGISTER_SIGNAL(sig)						\
	if ([delegate respondsToSelector:				\
	    @selector(applicationDidReceive##sig)]) {			\
		_##sig##Handler = (void (*)(id, SEL))[(id)delegate	\
		    methodForSelector:					\
		    @selector(applicationDidReceive##sig)];		\
		signal(sig, handle##sig);				\
	} else								\
		signal(sig, (void (*)(int))SIG_DFL);
#endif

	_delegate = delegate;

	REGISTER_SIGNAL(SIGINT)
#ifdef SIGHUP
	REGISTER_SIGNAL(SIGHUP)
#endif







<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<








<







499
500
501
502
503
504
505




506













507
508
509
510
511
512
513
514

515
516
517
518
519
520
521
- (id <OFApplicationDelegate>)delegate
{
	return _delegate;
}

- (void)setDelegate: (id <OFApplicationDelegate>)delegate
{




#define REGISTER_SIGNAL(sig)						\













	if ([delegate respondsToSelector:				\
	    @selector(applicationDidReceive##sig)]) {			\
		_##sig##Handler = (void (*)(id, SEL))[(id)delegate	\
		    methodForSelector:					\
		    @selector(applicationDidReceive##sig)];		\
		signal(sig, handle##sig);				\
	} else								\
		signal(sig, (void (*)(int))SIG_DFL);


	_delegate = delegate;

	REGISTER_SIGNAL(SIGINT)
#ifdef SIGHUP
	REGISTER_SIGNAL(SIGHUP)
#endif

Modified src/OFArray.m from [15022d3186] to [bc7d3f13f5].

672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
		uint8_t type = 0xDC;
		uint16_t tmp = OF_BSWAP16_IF_LE((uint16_t)count);

		[data addItem: &type];
		[data addItems: &tmp
			 count: sizeof(tmp)];
	} else if (count <= UINT32_MAX) {
		uint8_t type = 0xDC;
		uint32_t tmp = OF_BSWAP32_IF_LE((uint32_t)count);

		[data addItem: &type];
		[data addItems: &tmp
			 count: sizeof(tmp)];
	} else
		@throw [OFOutOfRangeException exception];







|







672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
		uint8_t type = 0xDC;
		uint16_t tmp = OF_BSWAP16_IF_LE((uint16_t)count);

		[data addItem: &type];
		[data addItems: &tmp
			 count: sizeof(tmp)];
	} else if (count <= UINT32_MAX) {
		uint8_t type = 0xDD;
		uint32_t tmp = OF_BSWAP32_IF_LE((uint32_t)count);

		[data addItem: &type];
		[data addItems: &tmp
			 count: sizeof(tmp)];
	} else
		@throw [OFOutOfRangeException exception];

Modified src/OFData.h from [ef14e3ba64] to [9086a3be08].

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 *
 * For security reasons, serialization and deserialization is only implemented
 * for OFData with item size 1.
 */
@interface OFData: OFObject <OFCopying, OFMutableCopying, OFComparing,
    OFSerialization, OFMessagePackRepresentation>
{
	char *_items;
	size_t _count, _itemSize;
	bool _freeWhenDone;
}

/*!
 * The size of a single item in the OFData in bytes.
 */







|







30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 *
 * For security reasons, serialization and deserialization is only implemented
 * for OFData with item size 1.
 */
@interface OFData: OFObject <OFCopying, OFMutableCopying, OFComparing,
    OFSerialization, OFMessagePackRepresentation>
{
	unsigned char *_items;
	size_t _count, _itemSize;
	bool _freeWhenDone;
}

/*!
 * The size of a single item in the OFData in bytes.
 */

Modified src/OFData.m from [ab1e932258] to [945c020d4d].

181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
{
	self = [super init];

	@try {
		if (itemSize == 0)
			@throw [OFInvalidArgumentException exception];

		_items = (char *)items;
		_itemSize = itemSize;
		_count = count;
		_freeWhenDone = freeWhenDone;
	} @catch (id e) {
		[self release];
		@throw e;
	}







|







181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
{
	self = [super init];

	@try {
		if (itemSize == 0)
			@throw [OFInvalidArgumentException exception];

		_items = (unsigned char *)items;
		_itemSize = itemSize;
		_count = count;
		_freeWhenDone = freeWhenDone;
	} @catch (id e) {
		[self release];
		@throw e;
	}

Modified src/OFDate.h from [7c2a95ab3f] to [fcd33a4a3b].

184
185
186
187
188
189
190







191
192
193
194
195
196
197
/*!
 * @brief Returns the minute of the date.
 *
 * @return The minute of the date
 */
- (uint8_t)minute;








/*!
 * @brief Returns the hour of the date.
 *
 * @return The hour of the date
 */
- (uint8_t)hour;








>
>
>
>
>
>
>







184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*!
 * @brief Returns the minute of the date.
 *
 * @return The minute of the date
 */
- (uint8_t)minute;

/*!
 * @brief Returns the minute of the date in local time.
 *
 * @return The minute of the date in local time
 */
- (uint8_t)localMinute;

/*!
 * @brief Returns the hour of the date.
 *
 * @return The hour of the date
 */
- (uint8_t)hour;

Modified src/OFDate.m from [388aebd154] to [618922b043].

449
450
451
452
453
454
455





456
457
458
459
460
461
462
	GMTIME_RET(tm_sec)
}

- (uint8_t)minute
{
	GMTIME_RET(tm_min)
}






- (uint8_t)hour
{
	GMTIME_RET(tm_hour)
}

- (uint8_t)localHour







>
>
>
>
>







449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
	GMTIME_RET(tm_sec)
}

- (uint8_t)minute
{
	GMTIME_RET(tm_min)
}

- (uint8_t)localMinute
{
	LOCALTIME_RET(tm_min)
}

- (uint8_t)hour
{
	GMTIME_RET(tm_hour)
}

- (uint8_t)localHour

Modified src/OFFile.m from [afef5a8ffe] to [44dc0ec6b9].

130
131
132
133
134
135
136


137
138
139
140




141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
static int
parseMode(const char *mode, bool *append)
{
	*append = false;

	if (strcmp(mode, "r") == 0)
		return MODE_OLDFILE;


	if (strcmp(mode, "w") == 0)
		return MODE_NEWFILE;
	if (strcmp(mode, "wx") == 0)
		return MODE_NEWFILE;




	if (strcmp(mode, "a") == 0) {
		*append = true;
		return MODE_READWRITE;
	}
	if (strcmp(mode, "rb") == 0)
		return MODE_OLDFILE;
	if (strcmp(mode, "wb") == 0)
		return MODE_NEWFILE;
	if (strcmp(mode, "wbx") == 0)
		return MODE_NEWFILE;
	if (strcmp(mode, "ab") == 0) {
		*append = true;
		return MODE_READWRITE;
	}
	if (strcmp(mode, "r+") == 0)
		return MODE_OLDFILE;
	if (strcmp(mode, "w+") == 0)
		return MODE_NEWFILE;
	if (strcmp(mode, "a+") == 0) {
		*append = true;
		return MODE_READWRITE;
	}
	if (strcmp(mode, "r+b") == 0 || strcmp(mode, "rb+") == 0)
		return MODE_OLDFILE;
	if (strcmp(mode, "w+b") == 0 || strcmp(mode, "wb+") == 0)
		return MODE_NEWFILE;
	if (strcmp(mode, "w+bx") == 0 || strcmp(mode, "wb+x") == 0)
		return MODE_NEWFILE;
	if (strcmp(mode, "ab+") == 0 || strcmp(mode, "a+b") == 0) {
		*append = true;
		return MODE_READWRITE;
	}

	return -1;
}
#endif








>
>




>
>
>
>




<
<
<
<
<
<
<
<
<
<
<
<
<
<


<
<
<
<
<
<
<
<
<
<







130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150














151
152










153
154
155
156
157
158
159
static int
parseMode(const char *mode, bool *append)
{
	*append = false;

	if (strcmp(mode, "r") == 0)
		return MODE_OLDFILE;
	if (strcmp(mode, "r+") == 0)
		return MODE_OLDFILE;
	if (strcmp(mode, "w") == 0)
		return MODE_NEWFILE;
	if (strcmp(mode, "wx") == 0)
		return MODE_NEWFILE;
	if (strcmp(mode, "w+") == 0)
		return MODE_NEWFILE;
	if (strcmp(mode, "w+x") == 0)
		return MODE_NEWFILE;
	if (strcmp(mode, "a") == 0) {
		*append = true;
		return MODE_READWRITE;
	}














	if (strcmp(mode, "a+") == 0) {
		*append = true;










		return MODE_READWRITE;
	}

	return -1;
}
#endif

Modified src/OFFileManager.m from [7bb3d63d81] to [f7096a9a7b].

569
570
571
572
573
574
575

576
577
578
579
580
581
582
				    exceptionWithObject: self
					requestedLength: 0
						  errNo: errno];

			if (dirent == NULL)
				break;
# else

			if ((dirent = readdir(dir)) == NULL) {
				if (errno == 0)
					break;
				else
					@throw [OFReadFailedException
					    exceptionWithObject: self
						requestedLength: 0







>







569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
				    exceptionWithObject: self
					requestedLength: 0
						  errNo: errno];

			if (dirent == NULL)
				break;
# else
			errno = 0;
			if ((dirent = readdir(dir)) == NULL) {
				if (errno == 0)
					break;
				else
					@throw [OFReadFailedException
					    exceptionWithObject: self
						requestedLength: 0

Modified src/OFGZIPStream.h from [9ece715a6e] to [28a3137a76].

17
18
19
20
21
22
23






24
25
26
27
28
29
30
#import "OFStream.h"
#import "OFDate.h"

@class OFInflateStream;

OF_ASSUME_NONNULL_BEGIN







@interface OFGZIPStream: OFStream
{
	OFStream *_stream;
	OFInflateStream *_inflateStream;
	enum of_gzip_stream_state {
		OF_GZIP_STREAM_ID1,
		OF_GZIP_STREAM_ID2,







>
>
>
>
>
>







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#import "OFStream.h"
#import "OFDate.h"

@class OFInflateStream;

OF_ASSUME_NONNULL_BEGIN

/*!
 * @class OFGZIPStream OFGZIPStream.h ObjFW/OFGZIPStream.h
 *
 * @brief A class that handles GZIP compression and decompression transparently
 *	  for an underlying stream.
 */
@interface OFGZIPStream: OFStream
{
	OFStream *_stream;
	OFInflateStream *_inflateStream;
	enum of_gzip_stream_state {
		OF_GZIP_STREAM_ID1,
		OF_GZIP_STREAM_ID2,
70
71
72
73
74
75
76






77

78








79
80
81
82
	size_t _bytesRead;
	uint8_t _buffer[4];
	OFDate *_modificationDate;
	uint16_t _extraLength;
	uint32_t _CRC32, _uncompressedSize;
}







+ (instancetype)streamWithStream: (OFStream *)stream;

- init OF_UNAVAILABLE;








- initWithStream: (OFStream *)stream OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END







>
>
>
>
>
>

>

>
>
>
>
>
>
>
>




76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
	size_t _bytesRead;
	uint8_t _buffer[4];
	OFDate *_modificationDate;
	uint16_t _extraLength;
	uint32_t _CRC32, _uncompressedSize;
}

/*!
 * @brief Creates a new OFGZIPStream with the specified underlying stream.
 *
 * @param stream The underlying stream for the OFGZIPStream
 * @return A new, autoreleased OFGZIPStream
 */
+ (instancetype)streamWithStream: (OFStream *)stream;

- init OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated OFGZIPStream with the specified
 *	  underlying stream.
 *
 * @param stream The underlying stream for the OFGZIPStream
 * @return An initialized OFGZIPStream
 */
- initWithStream: (OFStream *)stream OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END

Modified src/OFMutableURL.m from [60a5553f44] to [d83d33a394].

14
15
16
17
18
19
20

21
22
23
24
25
26
27
 * file.
 */

#include "config.h"

#import "OFMutableURL.h"
#import "OFURL+Private.h"


@implementation OFMutableURL
@dynamic scheme, host, port, user, password, path, parameters, query, fragment;

+ (instancetype)URL
{
	return [[[self alloc] init] autorelease];







>







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 * file.
 */

#include "config.h"

#import "OFMutableURL.h"
#import "OFURL+Private.h"
#import "OFString.h"

@implementation OFMutableURL
@dynamic scheme, host, port, user, password, path, parameters, query, fragment;

+ (instancetype)URL
{
	return [[[self alloc] init] autorelease];

Modified src/OFRunLoop.m from [50df1150e8] to [2bcc651795].

13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35


36
37
38
39
40
41
42
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <assert.h>


#import "OFRunLoop.h"
#import "OFRunLoop+Private.h"
#import "OFDictionary.h"
#ifdef OF_HAVE_SOCKETS
# import "OFKernelEventObserver.h"
#endif
#import "OFThread.h"
#ifdef OF_HAVE_THREADS
# import "OFMutex.h"
# import "OFCondition.h"
#endif
#import "OFSortedList.h"
#import "OFTimer.h"
#import "OFTimer+Private.h"
#import "OFDate.h"



static OFRunLoop *mainRunLoop = nil;

#ifdef OF_HAVE_SOCKETS
@interface OFRunLoop_QueueItem: OFObject
{
@public







>
















>
>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <assert.h>
#include <errno.h>

#import "OFRunLoop.h"
#import "OFRunLoop+Private.h"
#import "OFDictionary.h"
#ifdef OF_HAVE_SOCKETS
# import "OFKernelEventObserver.h"
#endif
#import "OFThread.h"
#ifdef OF_HAVE_THREADS
# import "OFMutex.h"
# import "OFCondition.h"
#endif
#import "OFSortedList.h"
#import "OFTimer.h"
#import "OFTimer+Private.h"
#import "OFDate.h"

#import "OFObserveFailedException.h"

static OFRunLoop *mainRunLoop = nil;

#ifdef OF_HAVE_SOCKETS
@interface OFRunLoop_QueueItem: OFObject
{
@public
715
716
717
718
719
720
721

722
723




724
725
726
727
728
729
730
731
732
733
734
735
736
737

738




739
740
741
742
743
744
745
				timeout = [[nextTimer earlierDate: deadline]
				    timeIntervalSinceNow];

			if (timeout < 0)
				timeout = 0;

#if defined(OF_HAVE_SOCKETS)

			[_kernelEventObserver
			    observeForTimeInterval: timeout];




#elif defined(OF_HAVE_THREADS)
			[_condition lock];
			[_condition waitForTimeInterval: timeout];
			[_condition unlock];
#else
			[OFThread sleepForTimeInterval: timeout];
#endif
		} else {
			/*
			 * No more timers and no deadline: Just watch for I/O
			 * until we get an event. If a timer is added by
			 * another thread, it cancels the observe.
			 */
#if defined(OF_HAVE_SOCKETS)

			[_kernelEventObserver observe];




#elif defined(OF_HAVE_THREADS)
			[_condition lock];
			[_condition wait];
			[_condition unlock];
#else
			[OFThread sleepForTimeInterval: 86400];
#endif







>
|
|
>
>
>
>














>
|
>
>
>
>







718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
				timeout = [[nextTimer earlierDate: deadline]
				    timeIntervalSinceNow];

			if (timeout < 0)
				timeout = 0;

#if defined(OF_HAVE_SOCKETS)
			@try {
				[_kernelEventObserver
				    observeForTimeInterval: timeout];
			} @catch (OFObserveFailedException *e) {
				if ([e errNo] != EINTR)
					@throw e;
			}
#elif defined(OF_HAVE_THREADS)
			[_condition lock];
			[_condition waitForTimeInterval: timeout];
			[_condition unlock];
#else
			[OFThread sleepForTimeInterval: timeout];
#endif
		} else {
			/*
			 * No more timers and no deadline: Just watch for I/O
			 * until we get an event. If a timer is added by
			 * another thread, it cancels the observe.
			 */
#if defined(OF_HAVE_SOCKETS)
			@try {
				[_kernelEventObserver observe];
			} @catch (OFObserveFailedException *e) {
				if ([e errNo] != EINTR)
					@throw e;
			}
#elif defined(OF_HAVE_THREADS)
			[_condition lock];
			[_condition wait];
			[_condition unlock];
#else
			[OFThread sleepForTimeInterval: 86400];
#endif

Modified src/OFStream.m from [d30563e398] to [e48fbb2fa9].

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#import "of_asprintf.h"

#define MIN_READ_SIZE 512

@implementation OFStream
@synthesize of_waitingForDelimiter = _waitingForDelimiter;

#if !defined(OF_WINDOWS) && !defined(OF_MORPHOS)
+ (void)initialize
{
	if (self == [OFStream class])
		signal(SIGPIPE, SIG_IGN);
}
#endif








|







54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#import "of_asprintf.h"

#define MIN_READ_SIZE 512

@implementation OFStream
@synthesize of_waitingForDelimiter = _waitingForDelimiter;

#if defined(SIGPIPE) && defined(SIG_IGN)
+ (void)initialize
{
	if (self == [OFStream class])
		signal(SIGPIPE, SIG_IGN);
}
#endif

Modified src/OFString.h from [f5efa5d129] to [bb11f44cdb].

16
17
18
19
20
21
22






23
24
25
26
27
28
29

#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS
#endif
#ifndef __STDC_CONSTANT_MACROS
# define __STDC_CONSTANT_MACROS
#endif







#include <stdarg.h>
#include <stdint.h>

#import "OFObject.h"
#import "OFSerialization.h"
#import "OFJSONRepresentation.h"







>
>
>
>
>
>







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS
#endif
#ifndef __STDC_CONSTANT_MACROS
# define __STDC_CONSTANT_MACROS
#endif

#import "objfw-defs.h"

#ifdef OF_HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif

#include <stdarg.h>
#include <stdint.h>

#import "OFObject.h"
#import "OFSerialization.h"
#import "OFJSONRepresentation.h"

Modified src/OFTarArchiveEntry.m from [e3da7730a5] to [1b943dcfae].

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100



101
102
103
104

105
106
107
108
109
110
111
		_type = header[156];
		_targetFileName = [stringFromBuffer(header + 157, 100) copy];

		if (_type == '\0')
			_type = OF_TAR_ARCHIVE_ENTRY_TYPE_FILE;

		if (memcmp(header + 257, "ustar\0" "00", 8) == 0) {
			OFString *fileName;

			_owner = [stringFromBuffer(header + 265, 32) copy];
			_group = [stringFromBuffer(header + 297, 32) copy];

			_deviceMajor = (uint32_t)octalValueFromBuffer(
			    header + 329, 8, UINT32_MAX);
			_deviceMinor = (uint32_t)octalValueFromBuffer(
			    header + 337, 8, UINT32_MAX);




			fileName = [OFString stringWithFormat: @"%@/%@",
			    stringFromBuffer(header + 345, 155), _fileName];
			[_fileName release];
			_fileName = [fileName copy];

		}

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}







|









>
>
>
|
|
|
|
>







84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
		_type = header[156];
		_targetFileName = [stringFromBuffer(header + 157, 100) copy];

		if (_type == '\0')
			_type = OF_TAR_ARCHIVE_ENTRY_TYPE_FILE;

		if (memcmp(header + 257, "ustar\0" "00", 8) == 0) {
			OFString *prefix;

			_owner = [stringFromBuffer(header + 265, 32) copy];
			_group = [stringFromBuffer(header + 297, 32) copy];

			_deviceMajor = (uint32_t)octalValueFromBuffer(
			    header + 329, 8, UINT32_MAX);
			_deviceMinor = (uint32_t)octalValueFromBuffer(
			    header + 337, 8, UINT32_MAX);

			prefix = stringFromBuffer(header + 345, 155);
			if ([prefix length] > 0) {
				OFString *fileName = [OFString
				    stringWithFormat: @"%@/%@",
						      prefix, _fileName];
				[_fileName release];
				_fileName = [fileName copy];
			}
		}

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}

Modified src/OFZIPArchive.m from [8c3891b987] to [65a1aa4c22].

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
- initWithStream: (OFStream *)stream;
- (bool)matchesEntry: (OFZIPArchiveEntry *)entry;
@end

@interface OFZIPArchive_FileStream: OFStream
{
	OFStream *_stream, *_decompressedStream;
	OFZIPArchive_LocalFileHeader *_localFileHeader;
	bool _hasDataDescriptor;
	uint64_t _size;
	uint32_t _CRC32;
	bool _atEndOfStream;
}

-  initWithStream: (OFStream *)path
  localFileHeader: (OFZIPArchive_LocalFileHeader *)localFileHeader;
@end

uint32_t
of_zip_archive_read_field32(const uint8_t **data, uint16_t *size)
{
	uint32_t field = 0;








|
<
|





|







69
70
71
72
73
74
75
76

77
78
79
80
81
82
83
84
85
86
87
88
89
90
- initWithStream: (OFStream *)stream;
- (bool)matchesEntry: (OFZIPArchiveEntry *)entry;
@end

@interface OFZIPArchive_FileStream: OFStream
{
	OFStream *_stream, *_decompressedStream;
	OFZIPArchiveEntry *_entry;

	uint64_t _toRead;
	uint32_t _CRC32;
	bool _atEndOfStream;
}

-  initWithStream: (OFStream *)path
	    entry: (OFZIPArchiveEntry *)localFileHeader;
@end

uint32_t
of_zip_archive_read_field32(const uint8_t **data, uint16_t *size)
{
	uint32_t field = 0;

356
357
358
359
360
361
362
363
364
365
366
367
368
369
370

		@throw [OFUnsupportedVersionException
		    exceptionWithVersion: version];
	}

	_lastReturnedStream = [[OFZIPArchive_FileStream alloc]
	     initWithStream: _stream
	    localFileHeader: localFileHeader];

	objc_autoreleasePoolPop(pool);

	return _lastReturnedStream;
}
@end








|







355
356
357
358
359
360
361
362
363
364
365
366
367
368
369

		@throw [OFUnsupportedVersionException
		    exceptionWithVersion: version];
	}

	_lastReturnedStream = [[OFZIPArchive_FileStream alloc]
	     initWithStream: _stream
		      entry: entry];

	objc_autoreleasePoolPop(pool);

	return _lastReturnedStream;
}
@end

449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497

498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571

	return true;
}
@end

@implementation OFZIPArchive_FileStream
-  initWithStream: (OFStream *)stream
  localFileHeader: (OFZIPArchive_LocalFileHeader *)localFileHeader
{
	self = [super init];

	@try {
		_stream = [stream retain];

		switch (localFileHeader->_compressionMethod) {
		case OF_ZIP_ARCHIVE_ENTRY_COMPRESSION_METHOD_NONE:
			_decompressedStream = [stream retain];
			break;
		case OF_ZIP_ARCHIVE_ENTRY_COMPRESSION_METHOD_DEFLATE:
			_decompressedStream = [[OFInflateStream alloc]
			    initWithStream: stream];
			break;
		case OF_ZIP_ARCHIVE_ENTRY_COMPRESSION_METHOD_DEFLATE64:
			_decompressedStream = [[OFInflate64Stream alloc]
			    initWithStream: stream];
			break;
		default:
			@throw [OFNotImplementedException
			    exceptionWithSelector: _cmd
					   object: self];
		}

		_localFileHeader = [localFileHeader retain];
		_hasDataDescriptor = (localFileHeader->_generalPurposeBitFlag &
		    (1 << 3));
		_size = localFileHeader->_uncompressedSize;
		_CRC32 = ~0;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[self close];


	[_decompressedStream release];
	[_localFileHeader release];

	[super dealloc];
}

- (bool)lowlevelIsAtEndOfStream
{
	return _atEndOfStream;
}

- (size_t)lowlevelReadIntoBuffer: (void *)buffer
			  length: (size_t)length
{
	size_t min, ret;

	if (_stream == nil)
		@throw [OFNotOpenException exceptionWithObject: self];

	if (_atEndOfStream)
		return 0;

	if (_hasDataDescriptor) {
		if ([_decompressedStream isAtEndOfStream]) {
			uint32_t CRC32;

			_atEndOfStream = true;

			CRC32 = [_stream readLittleEndianInt32];
			if (CRC32 == 0x08074B50)
				CRC32 = [_stream readLittleEndianInt32];

			if (~_CRC32 != CRC32)
				@throw [OFChecksumFailedException exception];

			/*
			 * FIXME: Check (un)compressed length!
			 * (Note: Both are 64 bit if the entry uses ZIP64!)
			 */

			return 0;
		}

		ret = [_decompressedStream readIntoBuffer: buffer
						   length: length];
	} else {
		if (_size == 0) {
			_atEndOfStream = true;

			if (~_CRC32 != _localFileHeader->_CRC32)
				@throw [OFChecksumFailedException exception];

			return 0;
		}

		min = (length < _size ? length : (size_t)_size);
		ret = [_decompressedStream readIntoBuffer: buffer
						   length: min];
		_size -= ret;
	}

	_CRC32 = of_crc32(_CRC32, buffer, ret);

	return ret;
}

- (void)close
{
	[_stream release];
	_stream = nil;

	[super close];
}
@end







|






|

















|
<
<
|













>

|












|







<
<
<
|
<
|
<
<
<

<
<
|
<
<
<
<
|
<
|
<
|
|
|
|
|

<
<
|
|
|
|
<
|
<
<
<
|
<












448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480


481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517



518

519



520


521




522

523

524
525
526
527
528
529


530
531
532
533

534



535

536
537
538
539
540
541
542
543
544
545
546
547

	return true;
}
@end

@implementation OFZIPArchive_FileStream
-  initWithStream: (OFStream *)stream
	    entry: (OFZIPArchiveEntry *)entry
{
	self = [super init];

	@try {
		_stream = [stream retain];

		switch ([entry compressionMethod]) {
		case OF_ZIP_ARCHIVE_ENTRY_COMPRESSION_METHOD_NONE:
			_decompressedStream = [stream retain];
			break;
		case OF_ZIP_ARCHIVE_ENTRY_COMPRESSION_METHOD_DEFLATE:
			_decompressedStream = [[OFInflateStream alloc]
			    initWithStream: stream];
			break;
		case OF_ZIP_ARCHIVE_ENTRY_COMPRESSION_METHOD_DEFLATE64:
			_decompressedStream = [[OFInflate64Stream alloc]
			    initWithStream: stream];
			break;
		default:
			@throw [OFNotImplementedException
			    exceptionWithSelector: _cmd
					   object: self];
		}

		_entry = [entry retain];


		_toRead = [entry uncompressedSize];
		_CRC32 = ~0;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[self close];

	[_stream release];
	[_decompressedStream release];
	[_entry release];

	[super dealloc];
}

- (bool)lowlevelIsAtEndOfStream
{
	return _atEndOfStream;
}

- (size_t)lowlevelReadIntoBuffer: (void *)buffer
			  length: (size_t)length
{
	size_t ret;

	if (_stream == nil)
		@throw [OFNotOpenException exceptionWithObject: self];

	if (_atEndOfStream)
		return 0;




	if (sizeof(length) >= sizeof(uint64_t) && length > UINT64_MAX)

		@throw [OFOutOfRangeException exception];






	if ((uint64_t)length > _toRead)




		length = (size_t)_toRead;



	ret = [_decompressedStream readIntoBuffer: buffer
					   length: length];

	if (ret == 0)
		_atEndOfStream = true;



	_toRead -= ret;
	_CRC32 = of_crc32(_CRC32, buffer, ret);

	if (_toRead == 0)

		if (~_CRC32 != [_entry CRC32])



			@throw [OFChecksumFailedException exception];


	return ret;
}

- (void)close
{
	[_stream release];
	_stream = nil;

	[super close];
}
@end

Modified src/of_asprintf.m from [3e2fecec3f] to [e20ce9de33].

556
557
558
559
560
561
562
563
564


565
566
567
568
569
570
571
572
573
			void *pool = objc_autoreleasePoolPush();
			char *tmp2;

			@try {
				OFMutableString *tmpStr = [OFMutableString
				    stringWithUTF8String: tmp
						  length: tmpLen];
				OFString *decimalPoint =
				    [OFLocalization decimalPoint];


				[tmpStr replaceOccurrencesOfString: decimalPoint
							withString: @"."];
				if ([tmpStr UTF8StringLength] > INT_MAX)
					return false;
				tmpLen = (int)[tmpStr UTF8StringLength];
				tmp2 = malloc(tmpLen);
				memcpy(tmp2, [tmpStr UTF8String], tmpLen);
			} @finally {
				free(tmp);







|

>
>
|
|







556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
			void *pool = objc_autoreleasePoolPush();
			char *tmp2;

			@try {
				OFMutableString *tmpStr = [OFMutableString
				    stringWithUTF8String: tmp
						  length: tmpLen];
				OFString *point =
				    [OFLocalization decimalPoint];
				if (point != nil)
					[tmpStr
					    replaceOccurrencesOfString: point
							    withString: @"."];
				if ([tmpStr UTF8StringLength] > INT_MAX)
					return false;
				tmpLen = (int)[tmpStr UTF8StringLength];
				tmp2 = malloc(tmpLen);
				memcpy(tmp2, [tmpStr UTF8String], tmpLen);
			} @finally {
				free(tmp);

Modified src/runtime/Makefile from [80fa148287] to [34e6bcc419].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
include ../../extra.mk

SUBDIRS = lookup-asm

SHARED_LIB = ${OBJFW_RT_SHARED_LIB}
STATIC_LIB = ${OBJFW_RT_STATIC_LIB}
MORPHOS_LIB = ${OBJFW_RT_MORPHOS_LIB}
LIB_MAJOR = ${OBJFW_RT_LIB_MAJOR}
LIB_MINOR = ${OBJFW_RT_LIB_MINOR}

SRCS = arc.m			\
       category.m		\
       class.m			\
       dtable.m			\






<







1
2
3
4
5
6

7
8
9
10
11
12
13
include ../../extra.mk

SUBDIRS = lookup-asm

SHARED_LIB = ${OBJFW_RT_SHARED_LIB}
STATIC_LIB = ${OBJFW_RT_STATIC_LIB}

LIB_MAJOR = ${OBJFW_RT_LIB_MAJOR}
LIB_MINOR = ${OBJFW_RT_LIB_MINOR}

SRCS = arc.m			\
       category.m		\
       class.m			\
       dtable.m			\
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
SRCS_THREADS = threading.m	\
	       ../threading.m
INCLUDES = ObjFW-RT.h
includesubdir = ObjFW-RT

OBJS_EXTRA = ${LOOKUP_ASM_LOOKUP_ASM_A}
LIB_OBJS_EXTRA = ${LOOKUP_ASM_LOOKUP_ASM_LIB_A}
MORPHOS_LIB_OBJS_EXTRA = morphos-library.o ${LOOKUP_ASM_LOOKUP_ASM_A}

include ../../buildsys.mk

${MORPHOS_LIB}: ppcinline.h
ppcinline.h: ObjFW-RT.fd protos.h
	cvinclude.pl			\
		--root ObjFW_RT		\
		--fd ObjFW-RT.fd	\
		--clib protos.h		\
		--inline $@

CPPFLAGS += -I. -I.. -I../..				\
	    -DOF_COMPILING_OBJFW_RT			\
	    -DOBJFW_RT_LIB_MAJOR=${OBJFW_RT_LIB_MAJOR}	\
	    -DOBJFW_RT_LIB_MINOR=${OBJFW_RT_LIB_MINOR}
LD = ${OBJC}







<



<
<
<
<
<
<
<
<





26
27
28
29
30
31
32

33
34
35








36
37
38
39
40
SRCS_THREADS = threading.m	\
	       ../threading.m
INCLUDES = ObjFW-RT.h
includesubdir = ObjFW-RT

OBJS_EXTRA = ${LOOKUP_ASM_LOOKUP_ASM_A}
LIB_OBJS_EXTRA = ${LOOKUP_ASM_LOOKUP_ASM_LIB_A}


include ../../buildsys.mk









CPPFLAGS += -I. -I.. -I../..				\
	    -DOF_COMPILING_OBJFW_RT			\
	    -DOBJFW_RT_LIB_MAJOR=${OBJFW_RT_LIB_MAJOR}	\
	    -DOBJFW_RT_LIB_MINOR=${OBJFW_RT_LIB_MINOR}
LD = ${OBJC}

Modified src/runtime/ObjFW-RT.h from [8577ac8d70] to [aad7cef107].

195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

struct objc_protocol_list {
	struct objc_protocol_list *_Nullable next;
	long count;
	Protocol *__unsafe_unretained _Nonnull list[1];
};

#if 1 /* !defined(__MORPHOS__) || defined(OF_COMPILING_OBJFW_RT) */
# ifdef __cplusplus
extern "C" {
# endif
extern SEL _Nonnull sel_registerName(const char *_Nonnull);
extern const char *_Nonnull sel_getName(SEL _Nonnull);
extern bool sel_isEqual(SEL _Nonnull, SEL _Nonnull);
extern Class _Nonnull objc_allocateClassPair(Class _Nullable,
    const char *_Nonnull, size_t);
extern void objc_registerClassPair(Class _Nonnull);
extern unsigned int objc_getClassList(Class _Nonnull *_Nullable, unsigned int);







<
|

|







195
196
197
198
199
200
201

202
203
204
205
206
207
208
209
210
211

struct objc_protocol_list {
	struct objc_protocol_list *_Nullable next;
	long count;
	Protocol *__unsafe_unretained _Nonnull list[1];
};


#ifdef __cplusplus
extern "C" {
#endif
extern SEL _Nonnull sel_registerName(const char *_Nonnull);
extern const char *_Nonnull sel_getName(SEL _Nonnull);
extern bool sel_isEqual(SEL _Nonnull, SEL _Nonnull);
extern Class _Nonnull objc_allocateClassPair(Class _Nullable,
    const char *_Nonnull, size_t);
extern void objc_registerClassPair(Class _Nonnull);
extern unsigned int objc_getClassList(Class _Nonnull *_Nullable, unsigned int);
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
extern _Nullable objc_uncaught_exception_handler
    objc_setUncaughtExceptionHandler(
    objc_uncaught_exception_handler _Nullable);
extern void objc_setForwardHandler(IMP _Nullable, IMP _Nullable);
extern void objc_setEnumerationMutationHandler(
    objc_enumeration_mutation_handler _Nullable);
extern void objc_zero_weak_references(id _Nonnull);
# ifdef __cplusplus
}
# endif
#else
# define BOOL EXEC_BOOL
# include <ppcinline/macros.h>
# undef BOOL
# ifdef __cplusplus
extern "C" {
# endif
extern struct Library *ObjFWRTBase;
# ifdef __cplusplus
}
# endif
# include "ppcinline.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif
/*
 * Used by the compiler, but can also be called manually.
 *
 * They need to be in the glue code for the MorphOS library.
 *
 * These declarations are also required to prevent Clang's implicit
 * declarations which include __declspec(dllimport) on Windows.







<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







236
237
238
239
240
241
242

243


















244
245
246
247
248
249
250
extern _Nullable objc_uncaught_exception_handler
    objc_setUncaughtExceptionHandler(
    objc_uncaught_exception_handler _Nullable);
extern void objc_setForwardHandler(IMP _Nullable, IMP _Nullable);
extern void objc_setEnumerationMutationHandler(
    objc_enumeration_mutation_handler _Nullable);
extern void objc_zero_weak_references(id _Nonnull);




















/*
 * Used by the compiler, but can also be called manually.
 *
 * They need to be in the glue code for the MorphOS library.
 *
 * These declarations are also required to prevent Clang's implicit
 * declarations which include __declspec(dllimport) on Windows.

Modified src/runtime/lookup-asm/lookup-asm-sparc64-elf.S from [03722104be] to [44cfec8a34].

48
49
50
51
52
53
54
55
56
57
58
59





60
61
62
63
64
65
66
#ifdef OF_SELUID24
	ldx	[%o2 + %o3], %o2
#endif
	ldx	[%o2 + %o4], %o2
	ldx	[%o2 + %o5], %o2

	cmp	%o2, 0
	be,pn	%xcc, \not_found
	 nop

	retl
	 mov	%o2, %o0





.type \name, %function
.size \name, .-\name
.endm

.macro generate_lookup_super name lookup
\name:
	mov	%o0, %o2







|




>
>
>
>
>







48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifdef OF_SELUID24
	ldx	[%o2 + %o3], %o2
#endif
	ldx	[%o2 + %o4], %o2
	ldx	[%o2 + %o5], %o2

	cmp	%o2, 0
	be,pn	%xcc, 0f
	 nop

	retl
	 mov	%o2, %o0

0:
	mov	%o7, %g1
	call	\not_found
	 mov	%g1, %o7
.type \name, %function
.size \name, .-\name
.endm

.macro generate_lookup_super name lookup
\name:
	mov	%o0, %o2

Deleted src/runtime/morphos-library.m version [90367d03a6].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
 *   Jonathan Schleifer <js@heap.zone>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "ObjFW-RT.h"
#import "macros.h"

#define BOOL EXEC_BOOL
#include <dos/dos.h>
#include <emul/emulregs.h>
#include <exec/execbase.h>
#include <exec/nodes.h>
#include <exec/resident.h>
#include <exec/types.h>
#include <proto/exec.h>
#undef BOOL

struct ObjFWRTBase {
	struct Library library;
	BPTR seg_list;
};

/* Forward declarations for all functions in the func_table */
static struct Library *lib_init(struct ObjFWRTBase *base, BPTR seg_list,
    struct ExecBase *exec_base);
static struct Library *lib_open(void);
static BPTR lib_close(void);
static BPTR lib_expunge(void);
static void lib_null(void);
void objc_set_exit(void OF_NO_RETURN_FUNC (*exit_fn_)(int status));

static ULONG func_table[] = {
	FUNCARRAY_BEGIN,
	FUNCARRAY_32BIT_NATIVE,
	(ULONG)lib_open,
	(ULONG)lib_close,
	(ULONG)lib_expunge,
	(ULONG)lib_null,
	-1,
	FUNCARRAY_32BIT_SYSTEMV,
	/* Functions for the glue code */
	(ULONG)objc_set_exit,
	/* Used by the compiler - these need glue code */
	(ULONG)__objc_exec_class,
	(ULONG)objc_msg_lookup,
	(ULONG)objc_msg_lookup_stret,
	(ULONG)objc_msg_lookup_super,
	(ULONG)objc_msg_lookup_super_stret,
	(ULONG)objc_lookUpClass,
	(ULONG)objc_getClass,
	(ULONG)objc_getRequiredClass,
	(ULONG)objc_exception_throw,
	(ULONG)objc_sync_enter,
	(ULONG)objc_sync_exit,
	(ULONG)objc_getProperty,
	(ULONG)objc_setProperty,
	(ULONG)objc_getPropertyStruct,
	(ULONG)objc_setPropertyStruct,
	(ULONG)objc_enumerationMutation,
	/* Functions declared in ObjFW-RT.h */
	(ULONG)sel_registerName,
	(ULONG)sel_getName,
	(ULONG)sel_isEqual,
	(ULONG)objc_allocateClassPair,
	(ULONG)objc_registerClassPair,
	(ULONG)objc_getClassList,
	(ULONG)objc_copyClassList,
	(ULONG)class_isMetaClass,
	(ULONG)class_getName,
	(ULONG)class_getSuperclass,
	(ULONG)class_getInstanceSize,
	(ULONG)class_respondsToSelector,
	(ULONG)class_conformsToProtocol,
	(ULONG)class_getMethodImplementation,
	(ULONG)class_getMethodImplementation_stret,
	(ULONG)class_getMethodTypeEncoding,
	(ULONG)class_addMethod,
	(ULONG)class_replaceMethod,
	(ULONG)object_getClass,
	(ULONG)object_setClass,
	(ULONG)object_getClassName,
	(ULONG)protocol_getName,
	(ULONG)protocol_isEqual,
	(ULONG)protocol_conformsToProtocol,
	(ULONG)objc_exit,
	(ULONG)objc_setUncaughtExceptionHandler,
	(ULONG)objc_setForwardHandler,
	(ULONG)objc_setEnumerationMutationHandler,
	(ULONG)objc_zero_weak_references,
	-1,
	FUNCARRAY_END
};

static struct Library *lib_init(struct ObjFWRTBase *base, BPTR seg_list,
    struct ExecBase *exec_base);

static struct {
	LONG struct_size;
	ULONG *func_table;
	void *data_table;
	struct Library *(*init_func)(struct ObjFWRTBase *base, BPTR seg_list,
	    struct ExecBase *exec_base);
} init_table = {
	.struct_size = sizeof(struct ObjFWRTBase),
	func_table,
	NULL,
	lib_init
};

static struct Resident resident = {
	.rt_MatchWord = RTC_MATCHWORD,
	.rt_MatchTag = &resident,
	.rt_EndSkip = &resident + 1,
	.rt_Flags = RTF_AUTOINIT | RTF_PPC,
	.rt_Version = OBJFW_RT_LIB_MAJOR * 10 + OBJFW_RT_LIB_MINOR,
	.rt_Type = NT_LIBRARY,
	.rt_Pri = 0,
	.rt_Name = (char *)"objfw-rt.library",
	.rt_IdString = (char *)"ObjFW-RT " PACKAGE_VERSION
	    " \xA9 2008-2017 Jonathan Schleifer",
	.rt_Init = &init_table
};

/* Magic required to make this a MorphOS binary */
const ULONG __abox__ = 1;

/* Global variables needed by libnix */
int ThisRequiresConstructorHandling;
struct ExecBase *SysBase;
void *libnix_mempool;

/* Functions passed in from the glue linklib */
static void OF_NO_RETURN_FUNC (*exit_fn)(int status);

void OF_NO_RETURN_FUNC
exit(int status)
{
	exit_fn(status);
}

void
objc_set_exit(void OF_NO_RETURN_FUNC (*exit_fn_)(int status))
{
	exit_fn = exit_fn_;
}

/* Standard library functions */
static struct Library *lib_init(struct ObjFWRTBase *base, BPTR seg_list,
    struct ExecBase *exec_base)
{
	SysBase = exec_base;

	base->seg_list = seg_list;

	return &base->library;
}

static struct Library *
lib_open(void)
{
	struct ObjFWRTBase *base = (struct ObjFWRTBase *)REG_A6;

	base->library.lib_OpenCnt++;
	base->library.lib_Flags &= ~LIBF_DELEXP;

	return &base->library;
}

static BPTR
expunge(struct ObjFWRTBase *base)
{
	/* Still in use - set delayed expunge flag and refuse to expunge */
	if (base->library.lib_OpenCnt > 0) {
		base->library.lib_Flags |= LIBF_DELEXP;
		return 0;
	}

	Remove(&base->library.lib_Node);
	FreeMem((char *)base - base->library.lib_NegSize,
	    base->library.lib_NegSize + base->library.lib_PosSize);

	return base->seg_list;
}

static BPTR
lib_close(void)
{
	struct ObjFWRTBase *base = (struct ObjFWRTBase *)REG_A6;

	/* Not used anymore and delayed expunge flag set -> expunge */
	if (--base->library.lib_OpenCnt == 0 &&
	    (base->library.lib_Flags & LIBF_DELEXP))
		return expunge(base);

	return 0;
}

static BPTR
lib_expunge(void)
{
	return expunge((struct ObjFWRTBase *)REG_A6);
}

static void
lib_null(void)
{
}
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


























































































































































































































































































































































































































































Modified tests/OFBlockTests.m from [b51076c2c2] to [57afcae22d].

67
68
69
70
71
72
73





74
75
76

77
78
79
80
81
82
83
	void (^m)(void);
	int (^v)(void);

	TEST(@"Class of stack block",
	    (Class)&_NSConcreteStackBlock == objc_getClass("OFStackBlock") &&
	    [s isKindOfClass: [OFBlock class]])






	TEST(@"Class of global block",
	    (Class)&_NSConcreteGlobalBlock == objc_getClass("OFGlobalBlock") &&
	    [g isKindOfClass: [OFBlock class]])


	TEST(@"Class of a malloc block",
	    (Class)&_NSConcreteMallocBlock == objc_getClass("OFMallocBlock"))

	TEST(@"Copying a stack block",
	    (m = [[s copy] autorelease]) &&
	    [m class] == objc_getClass("OFMallocBlock") &&







>
>
>
>
>



>







67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
	void (^m)(void);
	int (^v)(void);

	TEST(@"Class of stack block",
	    (Class)&_NSConcreteStackBlock == objc_getClass("OFStackBlock") &&
	    [s isKindOfClass: [OFBlock class]])

#if !defined(OF_WINDOWS) || !defined(__clang__)
	/*
	 * Causes a linker error on Windows with Clang when compiling as a
	 * static library. This is a bug in Clang.
	 */
	TEST(@"Class of global block",
	    (Class)&_NSConcreteGlobalBlock == objc_getClass("OFGlobalBlock") &&
	    [g isKindOfClass: [OFBlock class]])
#endif

	TEST(@"Class of a malloc block",
	    (Class)&_NSConcreteMallocBlock == objc_getClass("OFMallocBlock"))

	TEST(@"Copying a stack block",
	    (m = [[s copy] autorelease]) &&
	    [m class] == objc_getClass("OFMallocBlock") &&

Modified tests/OFKernelEventObserverTests.m from [f2b6e225cb] to [a33e059e26].

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33



34
35
36
37
38
39
40
41
42

#import "OFKernelEventObserver.h"
#import "OFString.h"
#import "OFDate.h"
#import "OFTCPSocket.h"
#import "OFAutoreleasePool.h"

#if defined(HAVE_SYS_SELECT_H) || defined(OF_WINDOWS)
# import "OFKernelEventObserver_select.h"
#endif
#if defined(HAVE_POLL_H) || defined(OF_WII)
# import "OFKernelEventObserver_poll.h"
#endif
#ifdef HAVE_EPOLL
# import "OFKernelEventObserver_epoll.h"
#endif



#ifdef HAVE_KQUEUE
# import "OFKernelEventObserver_kqueue.h"
#endif

#import "TestsAppDelegate.h"

#define EXPECTED_EVENTS 3

static OFString *module;







<
<
|
<
|




>
>
>
|
|







18
19
20
21
22
23
24


25

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

#import "OFKernelEventObserver.h"
#import "OFString.h"
#import "OFDate.h"
#import "OFTCPSocket.h"
#import "OFAutoreleasePool.h"



#ifdef HAVE_KQUEUE

# import "OFKernelEventObserver_kqueue.h"
#endif
#ifdef HAVE_EPOLL
# import "OFKernelEventObserver_epoll.h"
#endif
#ifdef HAVE_POLL
# import "OFKernelEventObserver_poll.h"
#endif
#ifdef HAVE_SELECT
# import "OFKernelEventObserver_select.h"
#endif

#import "TestsAppDelegate.h"

#define EXPECTED_EVENTS 3

static OFString *module;
199
200
201
202
203
204
205

206
207
208
209
210
211
212
213
214
215
216
217
218
219
220


221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
	}
}
@end

@implementation TestsAppDelegate (OFKernelEventObserverTests)
- (void)kernelEventObserverTestsWithClass: (Class)class
{

	ObserverTest *test;

	module = [class className];
	test = [[[ObserverTest alloc]
	    initWithTestsAppDelegate: self] autorelease];

	TEST(@"+[observer]",
	    (test->_observer = [OFKernelEventObserver observer]))
	[test->_observer setDelegate: test];

	TEST(@"-[addObjectForReading:]",
	    R([test->_observer addObjectForReading: test->_server]))

	[test run];
	_fails += test->_fails;


}

- (void)kernelEventObserverTests
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

#if defined(HAVE_SYS_SELECT_H) || defined(OF_WINDOWS)
	[self kernelEventObserverTestsWithClass:
	    [OFKernelEventObserver_select class]];
#endif

#if defined(HAVE_POLL_H) || defined(OF_WII)
	[self kernelEventObserverTestsWithClass:
	    [OFKernelEventObserver_poll class]];
#endif

#ifdef HAVE_EPOLL
	[self kernelEventObserverTestsWithClass:
	    [OFKernelEventObserver_epoll class]];
#endif

#ifdef HAVE_KQUEUE
	[self kernelEventObserverTestsWithClass:
	    [OFKernelEventObserver_kqueue class]];
#endif

	[pool drain];
}
@end







>















>
>




<
|
<




|













|
<
<

199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227

228

229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247


248
	}
}
@end

@implementation TestsAppDelegate (OFKernelEventObserverTests)
- (void)kernelEventObserverTestsWithClass: (Class)class
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	ObserverTest *test;

	module = [class className];
	test = [[[ObserverTest alloc]
	    initWithTestsAppDelegate: self] autorelease];

	TEST(@"+[observer]",
	    (test->_observer = [OFKernelEventObserver observer]))
	[test->_observer setDelegate: test];

	TEST(@"-[addObjectForReading:]",
	    R([test->_observer addObjectForReading: test->_server]))

	[test run];
	_fails += test->_fails;

	[pool drain];
}

- (void)kernelEventObserverTests
{

#ifdef HAVE_SELECT

	[self kernelEventObserverTestsWithClass:
	    [OFKernelEventObserver_select class]];
#endif

#ifdef HAVE_POLL
	[self kernelEventObserverTestsWithClass:
	    [OFKernelEventObserver_poll class]];
#endif

#ifdef HAVE_EPOLL
	[self kernelEventObserverTestsWithClass:
	    [OFKernelEventObserver_epoll class]];
#endif

#ifdef HAVE_KQUEUE
	[self kernelEventObserverTestsWithClass:
	    [OFKernelEventObserver_kqueue class]];
#endif
}


@end