ObjFW  Check-in [c536c268a0]

Overview
Comment:Merge trunk into branch "amiga-library"
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | amiga-library
Files: files | file ages | folders
SHA3-256: c536c268a0751c560697619c8b4e235f3276c08993b342b72485cba83a353110
User & Date: js on 2020-07-06 23:50:22
Other Links: branch diff | manifest | tags
Context
2020-10-04
15:00
Merge trunk into branch "amiga-library" check-in: 92335940e9 user: js tags: amiga-library
2020-07-06
23:50
Merge trunk into branch "amiga-library" check-in: c536c268a0 user: js tags: amiga-library
19:10
Update PLATFORMS.md check-in: f87321ad31 user: js tags: trunk
2020-06-21
22:46
Add missing of_log to linklib check-in: 08606a8804 user: js tags: amiga-library
Changes

Modified .fossil-settings/clean-glob from [ae0763f577] to [a6565e5fc6].

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

34
35
36
37
38
39
40
17
18
19
20
21
22
23

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40







-









+







boot.dol
buildsys.mk
config.h
config.h.in
config.log
config.status
configure
DerivedData
docs
extra.mk
generators/gen_tables
src/Info.plist
src/bridge/Info.plist
src/inline.h
src/objfw-defs.h
src/runtime/amiga-library-functable.inc
src/runtime/inline.h
tests/DerivedData
tests/EBOOT.PBP
tests/Info.plist
tests/PARAM.SFO
tests/objc_sync/objc_sync
tests/plugin/Info.plist
tests/terminal/terminal_tests
tests/tests

Modified .fossil-settings/ignore-glob from [e019c86c67] to [1d0aa2f1ca].

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

36
37
38
39
40
41
42
19
20
21
22
23
24
25

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







-









+







boot.dol
buildsys.mk
config.h
config.h.in
config.log
config.status
configure
DerivedData
docs
extra.mk
generators/gen_tables
src/Info.plist
src/bridge/Info.plist
src/inline.h
src/objfw-defs.h
src/runtime/amiga-library-functable.inc
src/runtime/inline.h
tests/DerivedData
tests/EBOOT.PBP
tests/Info.plist
tests/PARAM.SFO
tests/iOS.xcodeproj/*.pbxuser
tests/iOS.xcodeproj/project.xcworkspace
tests/iOS.xcodeproj/xcuserdata
tests/objc_sync/objc_sync

Modified .gitignore from [d1c8b6c7eb] to [7181f2f586].

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

36
37
38
39
40
41
42
19
20
21
22
23
24
25

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







-









+







boot.dol
buildsys.mk
config.h
config.h.in
config.log
config.status
configure
DerivedData
docs
extra.mk
generators/gen_tables
src/Info.plist
src/bridge/Info.plist
src/inline.h
src/objfw-defs.h
src/runtime/amiga-library-functable.inc
src/runtime/inline.h
tests/DerivedData
tests/EBOOT.PBP
tests/Info.plist
tests/PARAM.SFO
tests/iOS.xcodeproj/*.pbxuser
tests/iOS.xcodeproj/project.xcworkspace
tests/iOS.xcodeproj/xcuserdata
tests/objc_sync/objc_sync

Modified .travis.yml from [839879cad6] to [f5a0aabab2].

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
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







-
+





-
+





-
+







    - os: linux
      dist: trusty
      env:
        - config=amigaos

    # Nintendo 3DS
    - os: linux
      dist: trusty
      dist: bionic
      env:
        - config=nintendo_3ds

    # Nintendo DS
    - os: linux
      dist: trusty
      dist: bionic
      env:
        - config=nintendo_ds

    # Nintendo Wii
    - os: linux
      dist: trusty
      dist: bionic
      env:
        - config=wii

before_install:
  - if [ "$TRAVIS_OS_NAME" = "linux" -a -z "$config" ]; then
            case "$TRAVIS_CPU_ARCH" in
                    amd64 | s390x)
266
267
268
269
270
271
272

273
274



275
276
277
278
279
280
281
266
267
268
269
270
271
272
273


274
275
276
277
278
279
280
281
282
283







+
-
-
+
+
+







            if grep precise /etc/lsb-release >/dev/null; then
                    sudo ipx_internal_net add 1234 123456;
            fi;
    fi

  - if [ "$config" = "nintendo_3ds" -o "$config" = "nintendo_ds"
        -o "$config" = "wii" ]; then
            deb=devkitpro-pacman.amd64.deb;
            wget https://github.com/devkitPro/pacman/releases/download/devkitpro-pacman-1.0.1/devkitpro-pacman.deb;
            sudo dpkg -i devkitpro-pacman.deb;
            wget https://github.com/devkitPro/pacman/releases/download/v1.0.2/$deb;
            sudo apt install gdebi;
            sudo gdebi -n $deb;
    fi

  - if [ "$config" = "nintendo_3ds" ]; then
            sudo dkp-pacman --noconfirm -Syu 3ds-dev;
    fi

  - if [ "$config" = "nintendo_ds" ]; then

Modified PLATFORMS.md from [f92cc38d5b] to [b932fb0b9a].

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
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







-
-
-
+
+
+
+







-
-
+
+
















-
-
+
+
+







  * Compilers: Clang
  * Runtimes: Apple


Linux
-----

  * Architectures: Alpha, ARMv6, ARM64, Itanium, m68k, MIPS (O32), RISC-V 64,
		   PowerPC, S390x, SH4, x86, x86_64
  * Compilers: Clang 3.0-9.0, GCC 4.6-8.2
  * Architectures: Alpha, ARMv6, ARMv7, ARM64, Itanium, m68k, MIPS (O32),
                   MIPS64 (N64), RISC-V 64, PowerPC, S390x, SuperH-4, x86,
                   x86_64
  * Compilers: Clang 3.0-10.0, GCC 4.6-10.0
  * Runtimes: ObjFW


macOS
-----

  * OS Versions: 10.5, 10.7-10.14, Darling
  * Architectures: PowerPC, PowerPC 64, x86, x86_64
  * Compilers: Clang 3.1-7.0, GCC 4.2.1
  * Architectures: PowerPC, PowerPC64, x86, x86_64
  * Compilers: Clang 3.1-10.0, GCC 4.2.1
  * Runtimes: Apple, ObjFW


MorphOS
-------

  * OS Versions: 3.9-3.11
  * Architectures: PowerPC
  * Compilers: GCC 5.3.0, GCC 5.4.0
  * Runtimes: ObjFW
  * Notes: libnix and ixemul are both supported


NetBSD
------

  * OS Versions: 5.1-7.99
  * Architectures: ARM, ARM (big endian, BE8 mode), SPARC, SPARC64, x86, x86_64
  * OS Versions: 5.1-9.0
  * Architectures: ARM, ARM (big endian, BE8 mode), MIPS (O32), SPARC, SPARC64,
                   x86, x86_64
  * Compilers: Clang 3.0-3.2, GCC 4.1.3 & 4.5.3
  * Runtimes: ObjFW


Nintendo 3DS
------------

132
133
134
135
136
137
138
139

140
141
142
143
144
145
146
134
135
136
137
138
139
140

141
142
143
144
145
146
147
148







-
+







  * Limitations: No threads, no sockets
  * Notes: File support requires an argv-compatible launcher (such as HBMenu)


OpenBSD
-------

  * OS Versions: 5.2-6.5
  * OS Versions: 5.2-6.7
  * Architectures: MIPS64, PA-RISC, PowerPC, SPARC64, x86_64
  * Compilers: GCC 6.3.0, Clang 4.0
  * Runtimes: ObjFW


PlayStation Portable
--------------------
182
183
184
185
186
187
188
189
190



191
192
193
194
195
196
197
184
185
186
187
188
189
190


191
192
193
194
195
196
197
198
199
200







-
-
+
+
+








Windows
-------

  * OS Versions: 98 SE, NT 4.0, XP (x86), 7 (x64), 8 (x64), 8.1 (x64), 10,
                 Wine (x86 & x64)
  * Architectures: x86, x86_64
  * Compilers: GCC 5.3.0 & 6.2.0 from msys2 (x86 and x64),
               Clang 3.9.0 from msys2 (x86)
  * Compilers: GCC 5.3.0 & 6.2.0 from msys2 (x86 & x64),
               Clang 3.9.0 from msys2 (x86),
               Clang 10.0 from msys2 (x86 & x86_64)
  * Runtimes: ObjFW


Others
------

Basically, it should run on any POSIX system to which GCC >= 4.6 or a recent
211
212
213
214
215
216
217

218
219
220
221
222
223
214
215
216
217
218
219
220
221
222
223
224
225
226
227







+






for the following platforms (except resolveClassMethod: and
resolveInstanceMethod:, which are always available):

  * ARM (EABI/ELF, Apple/Mach-O)
  * ARM64 (ARM64/ELF, Apple/Mach-O)
  * MIPS (O32/ELF, EABI/ELF)
  * PowerPC (SysV/ELF, EABI/ELF, Apple/Mach-O)
  * SPARC (SysV/ELF)
  * SPARC64 (SysV/ELF)
  * x86 (SysV/ELF, Apple/Mach-O, Win32/PE)
  * x86_64 (SysV/ELF, Apple/Mach-O, Mach-O, Win64/PE)

Apple/Mach-O means both, the Apple ABI and runtime, while Mach-O means the
ObjFW runtime on Mach-O.

Modified configure.ac from [5db7003e7d] to [2413ffe765].

250
251
252
253
254
255
256








257
258
259
260
261
262
263
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271







+
+
+
+
+
+
+
+







			dnl accept everything used in ObjFW's assembly files.
			dnl Therefore, use the integrated assembler for ObjC
			dnl files, but not for assembly files.
			mips*-*-*)
				flag="-integrated-as"
				OBJCFLAGS="$OBJCFLAGS $flag"
				OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flag"
				;;
			dnl Don't use -no-integrated-as on Darwin. It breaks
			dnl building for the iOS simulator.
			i?86-*-darwin* | x86_64-*-darwin*)
				;;
			dnl Many older Clang versions don't support jmp short.
			i?86-*-* | x86_64-*-*)
				ASFLAGS="$ASFLAGS -no-integrated-as"
				;;
			dnl Clang's assembler on Windows is not complete yet
			dnl and cannot compile all .S files.
			*-*-mingw*)
				ASFLAGS="$ASFLAGS -no-integrated-as"
				;;
			dnl Clang generates assembly output on SPARC64 that

Modified src/OFAdjacentArray.m from [6b6ede6c8d] to [8ce426fd6f].

339
340
341
342
343
344
345
346

347
348
349
350
351
352
353
339
340
341
342
343
344
345

346
347
348
349
350
351
352
353







-
+







						  objects: objects
						    count: count_];

	if (state->state >= count)
		return 0;

	state->state = (unsigned long)count;
	state->itemsPtr = _array.items;
	state->itemsPtr = (id *)_array.items;
	state->mutationsPtr = (unsigned long *)self;

	return (int)count;
}

#ifdef OF_HAVE_BLOCKS
- (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block

Modified src/OFApplication.m from [2e614ff495] to [818d93f949].

68
69
70
71
72
73
74

75
76
77
78
79
80
81
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82







+








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

OF_DIRECT_MEMBERS
@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;

Modified src/OFArray+Private.h from [008c28aeb0] to [fad96984ad].

15
16
17
18
19
20
21

22
23
24
25
26
27
28
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29







+







 * file.
 */

#import "OFArray.h"

OF_ASSUME_NONNULL_BEGIN

OF_DIRECT_MEMBERS
@interface OFArrayEnumerator: OFEnumerator
{
	OFArray	*_array;
	size_t _count;
	unsigned long _mutations;
	unsigned long *_Nullable _mutationsPtr;
	size_t _position;

Modified src/OFDNSResolver.m from [e0d24431d9] to [7061e87e9f].

61
62
63
64
65
66
67

68
69
70
71
72
73
74
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75







+








#define CNAME_RECURSION 3

@interface OFDNSResolver () <OFUDPSocketDelegate, OFTCPSocketDelegate>
- (void)of_contextTimedOut: (OFDNSResolverContext *)context;
@end

OF_DIRECT_MEMBERS
@interface OFDNSResolverContext: OFObject
{
@public
	OFDNSQuery *_query;
	OFNumber *_ID;
	OFDNSResolverSettings *_settings;
	size_t _nameServersIndex;

Modified src/OFData+CryptoHashing.m from [bef7610665] to [7fbcd74f01].

27
28
29
30
31
32
33
34

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

34
35
36
37
38
39
40
41







-
+







#import "OFSHA256Hash.h"
#import "OFSHA384Hash.h"
#import "OFSHA512Hash.h"

int _OFData_CryptoHashing_reference;

@implementation OFData (CryptoHashing)
- (OFString *)of_cryptoHashWithClass: (Class <OFCryptoHash>)class
- (OFString *)of_cryptoHashWithClass: (Class <OFCryptoHash>)class OF_DIRECT
{
	void *pool = objc_autoreleasePoolPush();
	id <OFCryptoHash> hash =
	    [class cryptoHashWithAllowsSwappableMemory: true];
	size_t digestSize = [class digestSize];
	const unsigned char *digest;
	char cString[digestSize * 2];

Modified src/OFDictionary.m from [473457960e] to [9428854186].

44
45
46
47
48
49
50

51
52
53
54
55
56
57
58
59

60
61
62
63
64
65
66
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







+









+







- (OFString *)of_JSONRepresentationWithOptions: (int)options
					 depth: (size_t)depth;
@end

@interface OFDictionaryPlaceholder: OFDictionary
@end

OF_DIRECT_MEMBERS
@interface OFDictionaryObjectEnumerator: OFEnumerator
{
	OFDictionary *_dictionary;
	OFEnumerator *_keyEnumerator;
}

- (instancetype)initWithDictionary: (OFDictionary *)dictionary;
@end

OF_DIRECT_MEMBERS
@interface OFURLQueryPartAllowedCharacterSet: OFCharacterSet
+ (OFCharacterSet *)URLQueryPartAllowedCharacterSet;
@end

@implementation OFDictionaryPlaceholder
- (instancetype)init
{
220
221
222
223
224
225
226

227

228
229
230
231
232
233
234
222
223
224
225
226
227
228
229

230
231
232
233
234
235
236
237







+
-
+







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

+ (instancetype)dictionaryWithDictionary: (OFDictionary *)dictionary
{
	return [[(OFDictionary *)[self alloc]
	return [[[self alloc] initWithDictionary: dictionary] autorelease];
	    initWithDictionary: dictionary] autorelease];
}

+ (instancetype)dictionaryWithObject: (id)object
			      forKey: (id)key
{
	return [[[self alloc] initWithObject: object
				      forKey: key] autorelease];

Modified src/OFEnumerator.h from [c01e86ac8b] to [8acf2a6a5e].

50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64







-
+







 */
#define of_fast_enumeration_state_t NSFastEnumerationState
#ifndef NSINTEGER_DEFINED
typedef struct {
	/*! Arbitrary state information for the enumeration */
	unsigned long state;
	/*! Pointer to a C array of objects to return */
	id const __unsafe_unretained _Nullable *_Nullable itemsPtr;
	id __unsafe_unretained _Nullable *_Nullable itemsPtr;
	/*! Arbitrary state information to detect mutations */
	unsigned long *_Nullable mutationsPtr;
	/*! Additional arbitrary state information */
	unsigned long extra[5];
} of_fast_enumeration_state_t;
#endif

Modified src/OFEpollKernelEventObserver.m from [8fc6ef4b31] to [5306d06560].

88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
88
89
90
91
92
93
94

95
96
97
98
99
100
101
102







-
+







	[_FDToEvents release];

	[super dealloc];
}

- (void)of_addObject: (id)object
      fileDescriptor: (int)fd
	      events: (int)addEvents
	      events: (int)addEvents OF_DIRECT
{
	struct epoll_event event;
	intptr_t events;

	events = (intptr_t)[_FDToEvents
	    objectForKey: (void *)((intptr_t)fd + 1)];

111
112
113
114
115
116
117
118

119
120
121
122
123
124
125
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125







-
+








	[_FDToEvents setObject: (void *)(events | addEvents)
			forKey: (void *)((intptr_t)fd + 1)];
}

- (void)of_removeObject: (id)object
	 fileDescriptor: (int)fd
		 events: (int)removeEvents
		 events: (int)removeEvents OF_DIRECT
{
	intptr_t events;

	events = (intptr_t)[_FDToEvents
	    objectForKey: (void *)((intptr_t)fd + 1)];
	events &= ~removeEvents;

Modified src/OFFileURLHandler.h from [852f35b467] to [8275bdd541].

16
17
18
19
20
21
22
23

24
25
26
16
17
18
19
20
21
22

23
24
25
26







-
+



 */

#import "OFURLHandler.h"

OF_ASSUME_NONNULL_BEGIN

@interface OFFileURLHandler: OFURLHandler
+ (bool)of_directoryExistsAtPath: (OFString *)path;
+ (bool)of_directoryExistsAtPath: (OFString *)path OF_DIRECT;
@end

OF_ASSUME_NONNULL_END

Modified src/OFFileURLHandler.m from [94bc38aa32] to [b404d9c716].

640
641
642
643
644
645
646
647

648
649
650
651
652
653
654
640
641
642
643
644
645
646

647
648
649
650
651
652
653
654







-
+








	return ret;
}

- (void)of_setLastAccessDate: (OFDate *)lastAccessDate
	 andModificationDate: (OFDate *)modificationDate
		 ofItemAtURL: (OFURL *)URL
		  attributes: (of_file_attributes_t)attributes
		  attributes: (of_file_attributes_t)attributes OF_DIRECT
{
	OFString *path = URL.fileSystemRepresentation;
	of_file_attribute_key_t attributeKey = (modificationDate != nil
	    ? of_file_attribute_key_modification_date
	    : of_file_attribute_key_last_access_date);

	if (lastAccessDate == nil)
753
754
755
756
757
758
759
760

761
762
763
764
765
766
767
753
754
755
756
757
758
759

760
761
762
763
764
765
766
767







-
+







		     failedAttribute: attributeKey
			       errNo: errno];
#endif
}

- (void)of_setPOSIXPermissions: (OFNumber *)permissions
		   ofItemAtURL: (OFURL *)URL
		    attributes: (of_file_attributes_t)attributes
		    attributes: (of_file_attributes_t)attributes OF_DIRECT
{
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
	uint16_t mode = permissions.uInt16Value & 0777;
	OFString *path = URL.fileSystemRepresentation;
	int status;

# ifdef OF_WINDOWS
783
784
785
786
787
788
789
790

791
792
793
794
795
796
797
783
784
785
786
787
788
789

790
791
792
793
794
795
796
797







-
+







#endif
}

- (void)of_setOwner: (OFString *)owner
	   andGroup: (OFString *)group
	ofItemAtURL: (OFURL *)URL
       attributeKey: (of_file_attribute_key_t)attributeKey
	 attributes: (of_file_attributes_t)attributes
	 attributes: (of_file_attributes_t)attributes OF_DIRECT
{
#ifdef OF_FILE_MANAGER_SUPPORTS_OWNER
	OFString *path = URL.fileSystemRepresentation;
	uid_t uid = -1;
	gid_t gid = -1;
	of_string_encoding_t encoding;

Modified src/OFHTTPClient.m from [7d20d55912] to [8dda35db24].

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
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







+



















+













+













+







#import "OFUnsupportedVersionException.h"
#import "OFWriteFailedException.h"

#import "socket_helpers.h"

#define REDIRECTS_DEFAULT 10

OF_DIRECT_MEMBERS
@interface OFHTTPClientRequestHandler: OFObject <OFTCPSocketDelegate>
{
@public
	OFHTTPClient *_client;
	OFHTTPRequest *_request;
	unsigned int _redirects;
	bool _firstLine;
	OFString *_version;
	int _status;
	OFMutableDictionary OF_GENERIC(OFString *, OFString *) *_serverHeaders;
}

- (instancetype)initWithClient: (OFHTTPClient *)client
		       request: (OFHTTPRequest *)request
		     redirects: (unsigned int)redirects;
- (void)start;
- (void)closeAndReconnect;
@end

OF_DIRECT_MEMBERS
@interface OFHTTPClientRequestBodyStream: OFStream <OFReadyForWritingObserving>
{
	OFHTTPClientRequestHandler *_handler;
	OFTCPSocket *_socket;
	bool _chunked;
	uintmax_t _toWrite;
	bool _atEndOfStream;
}

- (instancetype)initWithHandler: (OFHTTPClientRequestHandler *)handler
			 socket: (OFTCPSocket *)sock;
@end

OF_DIRECT_MEMBERS
@interface OFHTTPClientResponse: OFHTTPResponse <OFReadyForReadingObserving>
{
	OFTCPSocket *_socket;
	bool _hasContentLength, _chunked, _keepAlive;
	bool _atEndOfStream, _setAtEndOfStream;
	intmax_t _toRead;
}

@property (nonatomic, setter=of_setKeepAlive:) bool of_keepAlive;

- (instancetype)initWithSocket: (OFTCPSocket *)sock;
@end

OF_DIRECT_MEMBERS
@interface OFHTTPClientSyncPerformer: OFObject <OFHTTPClientDelegate>
{
	OFHTTPClient *_client;
	OFObject <OFHTTPClientDelegate> *_delegate;
	OFHTTPResponse *_response;
}

Modified src/OFHTTPServer.m from [9e1f23cc19] to [868929166e].

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
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







+













+







 * FIXME: Key normalization replaces headers like "DNT" with "Dnt".
 * FIXME: Errors are not reported to the user.
 */

@interface OFHTTPServer () <OFTCPSocketDelegate>
@end

OF_DIRECT_MEMBERS
@interface OFHTTPServerResponse: OFHTTPResponse <OFReadyForWritingObserving>
{
	OFStreamSocket *_socket;
	OFHTTPServer *_server;
	OFHTTPRequest *_request;
	bool _chunked, _headersSent;
}

- (instancetype)initWithSocket: (OFStreamSocket *)sock
			server: (OFHTTPServer *)server
		       request: (OFHTTPRequest *)request;
@end

OF_DIRECT_MEMBERS
@interface OFHTTPServerConnection: OFObject <OFTCPSocketDelegate>
{
@public
	OFStreamSocket *_socket;
	OFHTTPServer *_server;
	OFTimer *_timer;
	enum {
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
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







+














+







			server: (OFHTTPServer *)server;
- (bool)parseProlog: (OFString *)line;
- (bool)parseHeaders: (OFString *)line;
- (bool)sendErrorAndClose: (short)statusCode;
- (void)createResponse;
@end

OF_DIRECT_MEMBERS
@interface OFHTTPServerRequestBodyStream: OFStream <OFReadyForReadingObserving>
{
	OFStreamSocket *_socket;
	bool _chunked;
	intmax_t _toRead;
	bool _atEndOfStream, _setAtEndOfStream;
}

- (instancetype)initWithSocket: (OFStreamSocket *)sock
		       chunked: (bool)chunked
		 contentLength: (uintmax_t)contentLength;
@end

#ifdef OF_HAVE_THREADS
OF_DIRECT_MEMBERS
@interface OFHTTPServerThread: OFThread
- (void)stop;
@end
#endif

static OF_INLINE OFString *
normalizedKey(OFString *key)

Modified src/OFINICategory+Private.h from [c23b5362fb] to [daec4f9da8].

18
19
20
21
22
23
24

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







+









#import "OFINICategory.h"
#import "OFString.h"

OF_ASSUME_NONNULL_BEGIN

@class OFStream;

OF_DIRECT_MEMBERS
@interface OFINICategory ()
- (instancetype)of_initWithName: (OFString *)name OF_METHOD_FAMILY(init);
- (void)of_parseLine: (OFString *)line;
- (bool)of_writeToStream: (OFStream *)stream
		encoding: (of_string_encoding_t)encoding
		   first: (bool)first;
@end

OF_ASSUME_NONNULL_END

Modified src/OFINICategory.m from [78d0c3480f] to [6f7f003a8d].

118
119
120
121
122
123
124
125

126
127
128
129
130
131
132
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132







-
+







	[super dealloc];
}
@end

@implementation OFINICategory
@synthesize name = _name;

- (instancetype)of_initWithName: (OFString *)name
- (instancetype)of_initWithName: (OFString *)name OF_DIRECT
{
	self = [super init];

	@try {
		_name = [name copy];
		_lines = [[OFMutableArray alloc] init];
	} @catch (id e) {

Modified src/OFINIFile.m from [5e409bb0b6] to [e386265069].

25
26
27
28
29
30
31

32
33
34
35
36
37
38
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39







+







#import "OFFile.h"
#import "OFINICategory.h"
#import "OFINICategory+Private.h"

#import "OFInvalidFormatException.h"
#import "OFOpenItemFailedException.h"

OF_DIRECT_MEMBERS
@interface OFINIFile ()
- (void)of_parseFile: (OFString *)path
	    encoding: (of_string_encoding_t)encoding;
@end

static bool
isWhitespaceLine(OFString *line)

Modified src/OFINIFileSettings.m from [c14945381a] to [9d965e74da].

52
53
54
55
56
57
58
59

60
61
62
63
64
65
66
52
53
54
55
56
57
58

59
60
61
62
63
64
65
66







-
+







	[_INIFile release];

	[super dealloc];
}

- (void)of_getCategory: (OFString **)category
		andKey: (OFString **)key
	       forPath: (OFString *)path
	       forPath: (OFString *)path OF_DIRECT
{
	size_t pos = [path rangeOfString: @"."
				 options: OF_STRING_SEARCH_BACKWARDS].location;

	if (pos == OF_NOT_FOUND) {
		*category = @"";
		*key = path;

Modified src/OFKernelEventObserver.m from [2c737f6572] to [58babda954].

217
218
219
220
221
222
223
224

225
226
227
228
229
230
231
217
218
219
220
221
222
223

224
225
226
227
228
229
230
231







-
+







	bool foundInReadBuffer = false;

	for (id object in _readObjects) {
		void *pool = objc_autoreleasePoolPush();

		if ([object isKindOfClass: [OFStream class]] &&
		    [object hasDataInReadBuffer] &&
		    ![object of_isWaitingForDelimiter]) {
		    ![(OFStream *)object of_isWaitingForDelimiter]) {
			if ([_delegate respondsToSelector:
			    @selector(objectIsReadyForReading:)])
				[_delegate objectIsReadyForReading: object];

			foundInReadBuffer = true;
		}

Modified src/OFLHAArchive.m from [a8a54167d4] to [493061fab4].

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
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







+














+







#import "OFInvalidArgumentException.h"
#import "OFNotImplementedException.h"
#import "OFNotOpenException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
#import "OFWriteFailedException.h"

OF_DIRECT_MEMBERS
@interface OFLHAArchiveFileReadStream: OFStream <OFReadyForReadingObserving>
{
	OFStream *_stream, *_decompressedStream;
	OFLHAArchiveEntry *_entry;
	uint32_t _toRead, _bytesConsumed;
	uint16_t _CRC16;
	bool _atEndOfStream, _skipped;
}

- (instancetype)of_initWithStream: (OFStream *)stream
			    entry: (OFLHAArchiveEntry *)entry;
- (void)of_skip;
@end

OF_DIRECT_MEMBERS
@interface OFLHAArchiveFileWriteStream: OFStream <OFReadyForWritingObserving>
{
	OFMutableLHAArchiveEntry *_entry;
	of_string_encoding_t _encoding;
	OFSeekableStream *_stream;
	of_offset_t _headerOffset;
	uint32_t _bytesWritten;

Modified src/OFLHAArchiveEntry+Private.h from [4be7606365] to [085a1438c0].

15
16
17
18
19
20
21

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







+










 * file.
 */

#import "OFLHAArchive.h"

OF_ASSUME_NONNULL_BEGIN

OF_DIRECT_MEMBERS
@interface OFLHAArchiveEntry ()
- (instancetype)of_initWithHeader: (char [_Nonnull 21])header
			   stream: (OFStream *)stream
			 encoding: (of_string_encoding_t)encoding
    OF_METHOD_FAMILY(init);
- (void)of_writeToStream: (OFStream *)stream
		encoding: (of_string_encoding_t)encoding;
@end

OF_ASSUME_NONNULL_END

Modified src/OFLHADecompressingStream.h from [83e1abd175] to [cc62626ce1].

17
18
19
20
21
22
23

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







+








#import "OFStream.h"

OF_ASSUME_NONNULL_BEGIN

#define OF_LHA_DECOMPRESSING_STREAM_BUFFER_SIZE 4096

OF_DIRECT_MEMBERS
@interface OFLHADecompressingStream: OFStream
{
	OFStream *_stream;
	uint8_t _distanceBits, _dictionaryBits;
	unsigned char _buffer[OF_LHA_DECOMPRESSING_STREAM_BUFFER_SIZE];
	uint32_t _bytesConsumed;
	uint16_t _bufferIndex, _bufferLength;

Modified src/OFList.m from [8f702bf74a] to [58e8774a64].

24
25
26
27
28
29
30

31
32
33
34
35
36
37
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38







+







#import "OFString.h"
#import "OFXMLElement.h"
#import "OFArray.h"

#import "OFEnumerationMutationException.h"
#import "OFInvalidArgumentException.h"

OF_DIRECT_MEMBERS
@interface OFListEnumerator: OFEnumerator
{
	OFList *_list;
	of_list_object_t *_Nullable _current;
	unsigned long _mutations;
	unsigned long *_Nullable _mutationsPtr;
}

Modified src/OFMD5Hash.m from [4a0afb099d] to [f7acc8c4b8].

24
25
26
27
28
29
30

31
32
33
34
35
36
37
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38







+








#import "OFHashAlreadyCalculatedException.h"
#import "OFOutOfRangeException.h"

#define DIGEST_SIZE 16
#define BLOCK_SIZE 64

OF_DIRECT_MEMBERS
@interface OFMD5Hash ()
- (void)of_resetState;
@end

#define F(a, b, c) (((a) & (b)) | (~(a) & (c)))
#define G(a, b, c) (((a) & (c)) | ((b) & ~(c)))
#define H(a, b, c) ((a) ^ (b) ^ (c))

Modified src/OFMapTable+Private.h from [fcec305650] to [1364bfeb16].

15
16
17
18
19
20
21

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







+











 * file.
 */

#import "OFMapTable.h"

OF_ASSUME_NONNULL_BEGIN

OF_DIRECT_MEMBERS
@interface OFMapTableEnumeratorWrapper: OFEnumerator
{
	OFMapTableEnumerator *_enumerator;
	id _object;
}

- (instancetype)initWithEnumerator: (OFMapTableEnumerator *)enumerator
			    object: (id)object;
@end

OF_ASSUME_NONNULL_END

Modified src/OFMapTable.m from [df5b78cbf7] to [8ca8ae429a].

57
58
59
60
61
62
63

64
65
66
67
68
69

70
71
72
73
74
75
76
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78







+






+








static bool
defaultEqual(void *object1, void *object2)
{
	return (object1 == object2);
}

OF_DIRECT_MEMBERS
@interface OFMapTable ()
- (void)of_setObject: (void *)object
	      forKey: (void *)key
		hash: (uint32_t)hash;
@end

OF_DIRECT_MEMBERS
@interface OFMapTableEnumerator ()
- (instancetype)of_initWithMapTable: (OFMapTable *)mapTable
			    buckets: (struct of_map_table_bucket **)buckets
			   capacity: (uint32_t)capacity
		   mutationsPointer: (unsigned long *)mutationsPtr
    OF_METHOD_FAMILY(init);
@end
289
290
291
292
293
294
295
296

297
298
299
300
301
302
303
291
292
293
294
295
296
297

298
299
300
301
302
303
304
305







-
+







		if (_keyFunctions.equal(_buckets[i]->key, key))
			return _buckets[i]->object;
	}

	return NULL;
}

- (void)of_resizeForCount: (uint32_t)count
- (void)of_resizeForCount: (uint32_t)count OF_DIRECT
{
	uint32_t fullness, capacity;
	struct of_map_table_bucket **buckets;

	if (count > UINT32_MAX / sizeof(*_buckets) || count > UINT32_MAX / 8)
		@throw [OFOutOfRangeException exception];

Modified src/OFMutableAdjacentArray.m from [1107dc450e] to [1999b771ee].

324
325
326
327
328
329
330
331

332
333
334
335
336
337
338
324
325
326
327
328
329
330

331
332
333
334
335
336
337
338







-
+







		return ret;
	}

	if (state->state >= count)
		return 0;

	state->state = (unsigned long)count;
	state->itemsPtr = _array.items;
	state->itemsPtr = (id *)_array.items;
	state->mutationsPtr = &_mutations;

	return (int)count;
}

- (OFEnumerator *)objectEnumerator
{

Modified src/OFMutableString.m from [3e022bac69] to [bb86d6b9da].

231
232
233
234
235
236
237
238

239
240
241
242
243
244
245
231
232
233
234
235
236
237

238
239
240
241
242
243
244
245







-
+







	return [super alloc];
}

#ifdef OF_HAVE_UNICODE_TABLES
- (void)of_convertWithWordStartTable: (const of_unichar_t *const [])startTable
		     wordMiddleTable: (const of_unichar_t *const [])middleTable
		  wordStartTableSize: (size_t)startTableSize
		 wordMiddleTableSize: (size_t)middleTableSize
		 wordMiddleTableSize: (size_t)middleTableSize OF_DIRECT
{
	void *pool = objc_autoreleasePoolPush();
	const of_unichar_t *characters = self.characters;
	size_t length = self.length;
	bool isStart = true;

	for (size_t i = 0; i < length; i++) {
263
264
265
266
267
268
269

270
271
272
273
274
275
276
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277







+







	}

	objc_autoreleasePoolPop(pool);
}
#else
- (void)of_convertWithWordStartFunction: (char (*)(char))startFunction
		     wordMiddleFunction: (char (*)(char))middleFunction
    OF_DIRECT
{
	void *pool = objc_autoreleasePoolPush();
	const of_unichar_t *characters = self.characters;
	size_t length = self.length;
	bool isStart = true;

	for (size_t i = 0; i < length; i++) {

Modified src/OFMutableUTF8String.m from [88e7b0c06e] to [cb57991be9].

69
70
71
72
73
74
75
76

77
78
79
80
81
82
83
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83







-
+








	return self;
}

- (void)of_convertWithWordStartTable: (const of_unichar_t *const[])startTable
		     wordMiddleTable: (const of_unichar_t *const[])middleTable
		  wordStartTableSize: (size_t)startTableSize
		 wordMiddleTableSize: (size_t)middleTableSize
		 wordMiddleTableSize: (size_t)middleTableSize OF_DIRECT
{
	of_unichar_t *unicodeString;
	size_t unicodeLen, newCStringLength;
	size_t i, j;
	char *newCString;
	bool isStart = true;

Modified src/OFPollKernelEventObserver.m from [49ee878680] to [5ca69d7bfc].

67
68
69
70
71
72
73
74

75
76
77
78
79
80
81
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81







-
+







	[_FDs release];

	[super dealloc];
}

- (void)of_addObject: (id)object
      fileDescriptor: (int)fd
	      events: (short)events
	      events: (short)events OF_DIRECT
{
	struct pollfd *FDs;
	size_t count;
	bool found;

	if (fd < 0)
		@throw [OFObserveFailedException exceptionWithObserver: self
106
107
108
109
110
111
112
113

114
115
116
117
118
119
120
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120







-
+







		_FDToObject[fd] = object;
		[_FDs addItem: &p];
	}
}

- (void)of_removeObject: (id)object
	 fileDescriptor: (int)fd
		 events: (short)events
		 events: (short)events OF_DIRECT
{
	struct pollfd *FDs;
	size_t nFDs;

	if (fd < 0)
		@throw [OFObserveFailedException exceptionWithObserver: self
								 errNo: EBADF];

Modified src/OFRIPEMD160Hash.m from [cf17c7c508] to [f5c31d29f5].

24
25
26
27
28
29
30

31
32
33
34
35
36
37
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38







+








#import "OFHashAlreadyCalculatedException.h"
#import "OFOutOfRangeException.h"

#define DIGEST_SIZE 20
#define BLOCK_SIZE 64

OF_DIRECT_MEMBERS
@interface OFRIPEMD160Hash ()
- (void)of_resetState;
@end

#define F(a, b, c) ((a) ^ (b) ^ (c))
#define G(a, b, c) (((a) & (b)) | (~(a) & (c)))
#define H(a, b, c) (((a) | ~(b)) ^ (c))

Modified src/OFRunLoop+Private.h from [f46c29fa91] to [979d7c9f7e].

29
30
31
32
33
34
35

36
37
38
39
40
41
42
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43







+







@protocol OFRunLoopConnectDelegate <OFObject>
- (void)of_socketDidConnect: (id)socket
		  exception: (nullable id)exception;
- (id)of_connectionFailedExceptionForErrNo: (int)errNo;
@end
#endif

OF_DIRECT_MEMBERS
@interface OFRunLoop ()
+ (void)of_setMainRunLoop: (OFRunLoop *)runLoop;
#ifdef OF_HAVE_SOCKETS
+ (void)of_addAsyncReadForStream: (OFStream <OFReadyForReadingObserving> *)
				      stream
			  buffer: (void *)buffer
			  length: (size_t)length

Modified src/OFRunLoop.m from [bc1499b7d8] to [348cd20ee8].

74
75
76
77
78
79
80

81
82
83
84
85
86
87
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88







+







# ifdef OF_HAVE_THREADS
	OFMutex *_execSignalsMutex;
# endif
#endif
}
@end

OF_DIRECT_MEMBERS
@interface OFRunLoop ()
- (OFRunLoopState *)of_stateForMode: (of_run_loop_mode_t)mode
			     create: (bool)create;
@end

#ifdef OF_HAVE_SOCKETS
@interface OFRunLoopQueueItem: OFObject

Modified src/OFSHA1Hash.m from [744ef1090a] to [cfb97974cb].

24
25
26
27
28
29
30

31
32
33
34
35
36
37
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38







+








#import "OFHashAlreadyCalculatedException.h"
#import "OFOutOfRangeException.h"

#define DIGEST_SIZE 20
#define BLOCK_SIZE 64

OF_DIRECT_MEMBERS
@interface OFSHA1Hash ()
- (void)of_resetState;
@end

#define F(a, b, c, d) ((d) ^ ((b) & ((c) ^ (d))))
#define G(a, b, c, d) ((b) ^ (c) ^ (d))
#define H(a, b, c, d) (((b) & (c)) | ((d) & ((b) | (c))))

Modified src/OFSPXSocket.m from [9940cead8b] to [c3e334ddfc].

41
42
43
44
45
46
47

48
49
50
51
52
53
54
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55







+







- (int)of_createSocketForAddress: (const of_socket_address_t *)address
			   errNo: (int *)errNo;
- (bool)of_connectSocketToAddress: (const of_socket_address_t *)address
			    errNo: (int *)errNo;
- (void)of_closeSocket;
@end

OF_DIRECT_MEMBERS
@interface OFSPXSocketAsyncConnectDelegate: OFObject <OFRunLoopConnectDelegate>
{
	OFSPXSocket *_socket;
	unsigned char _node[IPX_NODE_LEN];
	uint32_t _network;
	uint16_t _port;
#ifdef OF_HAVE_BLOCKS

Modified src/OFSPXStreamSocket.m from [cb1a9316c7] to [fcd6269f1f].

41
42
43
44
45
46
47

48
49
50
51
52
53
54
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55







+







- (int)of_createSocketForAddress: (const of_socket_address_t *)address
			   errNo: (int *)errNo;
- (bool)of_connectSocketToAddress: (const of_socket_address_t *)address
			    errNo: (int *)errNo;
- (void)of_closeSocket;
@end

OF_DIRECT_MEMBERS
@interface OFSPXStreamSocketAsyncConnectDelegate: OFObject
    <OFRunLoopConnectDelegate>
{
	OFSPXStreamSocket *_socket;
	unsigned char _node[IPX_NODE_LEN];
	uint32_t _network;
	uint16_t _port;

Modified src/OFStdIOStream+Private.h from [f49b4a7fef] to [c5d65c7b40].

15
16
17
18
19
20
21

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







+










 * file.
 */

#import "OFStdIOStream.h"

OF_ASSUME_NONNULL_BEGIN

OF_DIRECT_MEMBERS
@interface OFStdIOStream ()
#ifndef OF_AMIGAOS
- (instancetype)of_initWithFileDescriptor: (int)fd OF_METHOD_FAMILY(init);
#else
- (instancetype)of_initWithHandle: (BPTR)handle
			 closable: (bool)closable OF_METHOD_FAMILY(init);
#endif
@end

OF_ASSUME_NONNULL_END

Modified src/OFStdIOStream.m from [acfa5ef390] to [73bfd58144].

39
40
41
42
43
44
45




46
47
48
49

50
51
52
53
54
55
56
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61







+
+
+
+




+








#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFNotOpenException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"

#ifdef OF_IOS
# undef HAVE_ISATTY
#endif

#ifdef OF_AMIGAOS
# include <proto/exec.h>
# include <proto/dos.h>
# undef HAVE_ISATTY
#endif

/* References for static linking */
#ifdef OF_WINDOWS
void
_reference_to_OFWin32ConsoleStdIOStream(void)
{
127
128
129
130
131
132
133
134

135
136
137
138
139
140
141
132
133
134
135
136
137
138

139
140
141
142
143
144
145
146







-
+








	[of_stderr writeFormat: @"[%@.%03d %@(%d)] %@\n", dateString,
				date.microsecond / 1000, me, getpid(), msg];

	objc_autoreleasePoolPop(pool);
}

#if defined(HAVE_ISATTY) && !defined(OF_AMIGAOS)
#ifdef HAVE_ISATTY
static int
colorToANSI(OFColor *color)
{
	if ([color isEqual: [OFColor black]])
		return 30;
	if ([color isEqual: [OFColor maroon]])
		return 31;
417
418
419
420
421
422
423
424

425
426
427
428
429
430
431
422
423
424
425
426
427
428

429
430
431
432
433
434
435
436







-
+







- (unsigned int)retainCount
{
	return OF_RETAIN_COUNT_MAX;
}

- (bool)hasTerminal
{
#if defined(HAVE_ISATTY) && !defined(OF_AMIGAOS)
#ifdef HAVE_ISATTY
	return isatty(_fd);
#else
	return false;
#endif
}

- (int)columns
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
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







-
+














-
+














-
+









-
+









-
+









-
+












-
+










-
+







#else
	return -1;
#endif
}

- (void)setForegroundColor: (OFColor *)color
{
#if defined(HAVE_ISATTY) && !defined(OF_AMIGAOS)
#ifdef HAVE_ISATTY
	int code;

	if (!isatty(_fd))
		return;

	if ((code = colorToANSI(color)) == -1)
		return;

	[self writeFormat: @"\033[%um", code];
#endif
}

- (void)setBackgroundColor: (OFColor *)color
{
#if defined(HAVE_ISATTY) && !defined(OF_AMIGAOS)
#ifdef HAVE_ISATTY
	int code;

	if (!isatty(_fd))
		return;

	if ((code = colorToANSI(color)) == -1)
		return;

	[self writeFormat: @"\033[%um", code + 10];
#endif
}

- (void)reset
{
#if defined(HAVE_ISATTY) && !defined(OF_AMIGAOS)
#ifdef HAVE_ISATTY
	if (!isatty(_fd))
		return;

	[self writeString: @"\033[0m"];
#endif
}

- (void)clear
{
#if defined(HAVE_ISATTY) && !defined(OF_AMIGAOS)
#ifdef HAVE_ISATTY
	if (!isatty(_fd))
		return;

	[self writeString: @"\033[2J"];
#endif
}

- (void)eraseLine
{
#if defined(HAVE_ISATTY) && !defined(OF_AMIGAOS)
#ifdef HAVE_ISATTY
	if (!isatty(_fd))
		return;

	[self writeString: @"\033[2K"];
#endif
}

- (void)setCursorColumn: (unsigned int)column
{
#if defined(HAVE_ISATTY) && !defined(OF_AMIGAOS)
#ifdef HAVE_ISATTY
	if (!isatty(_fd))
		return;

	[self writeFormat: @"\033[%uG", column + 1];
#endif
}

- (void)setCursorPosition: (of_point_t)position
{
	if (position.x < 0 || position.y < 0)
		@throw [OFInvalidArgumentException exception];

#if defined(HAVE_ISATTY) && !defined(OF_AMIGAOS)
#ifdef HAVE_ISATTY
	if (!isatty(_fd))
		return;

	[self writeFormat: @"\033[%u;%uH",
			   (unsigned)position.y + 1, (unsigned)position.x + 1];
#endif
}

- (void)setRelativeCursorPosition: (of_point_t)position
{
#if defined(HAVE_ISATTY) && !defined(OF_AMIGAOS)
#ifdef HAVE_ISATTY
	if (!isatty(_fd))
		return;

	if (position.x > 0)
		[self writeFormat: @"\033[%uC", (unsigned)position.x];
	else if (position.x < 0)
		[self writeFormat: @"\033[%uD", (unsigned)-position.x];

Modified src/OFStream+Private.h from [81ef70d19a] to [55a5b86424].

15
16
17
18
19
20
21

22
23
24
25
26
27
15
16
17
18
19
20
21
22
23
24
25
26
27
28







+






 * file.
 */

#import "OFStream.h"

OF_ASSUME_NONNULL_BEGIN

OF_DIRECT_MEMBERS
@interface OFStream ()
@property (readonly, nonatomic, getter=of_isWaitingForDelimiter)
    bool of_waitingForDelimiter;
@end

OF_ASSUME_NONNULL_END

Modified src/OFString.m from [9bf92ef7e1] to [e1b9c425c7].

84
85
86
87
88
89
90
91

92
93

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

91
92

93
94
95
96
97
98
99
100







-
+

-
+







static locale_t cLocale;
#endif

@interface OFString ()
- (size_t)of_getCString: (char *)cString
	      maxLength: (size_t)maxLength
	       encoding: (of_string_encoding_t)encoding
		  lossy: (bool)lossy;
		  lossy: (bool)lossy OF_DIRECT;
- (const char *)of_cStringWithEncoding: (of_string_encoding_t)encoding
				 lossy: (bool)lossy;
				 lossy: (bool)lossy OF_DIRECT;
- (OFString *)of_JSONRepresentationWithOptions: (int)options
					 depth: (size_t)depth;
@end

@interface OFStringPlaceholder: OFString
@end

372
373
374
375
376
377
378
379

380
381
382
383
384
385
386
387
388
389
390
391
392
393
394

395
396
397
398
399
400
401
372
373
374
375
376
377
378

379
380
381
382
383
384
385
386
387
388
389
390
391
392
393

394
395
396
397
398
399
400
401







-
+














-
+







- (instancetype)init
{
	return (id)[[OFUTF8String alloc] init];
}

- (instancetype)initWithUTF8String: (const char *)UTF8String
{
	id string;
	OFUTF8String *string;
	size_t length;
	void *storage;

	length = strlen(UTF8String);
	string = of_alloc_object([OFUTF8String class], length + 1, 1, &storage);

	return (id)[string of_initWithUTF8String: UTF8String
					  length: length
					 storage: storage];
}

- (instancetype)initWithUTF8String: (const char *)UTF8String
			    length: (size_t)UTF8StringLength
{
	id string;
	OFUTF8String *string;
	void *storage;

	string = of_alloc_object([OFUTF8String class], UTF8StringLength + 1, 1,
	    &storage);

	return (id)[string of_initWithUTF8String: UTF8String
					  length: UTF8StringLength
420
421
422
423
424
425
426
427

428
429
430
431
432
433
434
420
421
422
423
424
425
426

427
428
429
430
431
432
433
434







-
+







			freeWhenDone: freeWhenDone];
}

- (instancetype)initWithCString: (const char *)cString
		       encoding: (of_string_encoding_t)encoding
{
	if (encoding == OF_STRING_ENCODING_UTF_8) {
		id string;
		OFUTF8String *string;
		size_t length;
		void *storage;

		length = strlen(cString);
		string = of_alloc_object([OFUTF8String class], length + 1, 1,
		    &storage);

442
443
444
445
446
447
448
449

450
451
452
453
454
455
456
442
443
444
445
446
447
448

449
450
451
452
453
454
455
456







-
+







}

- (instancetype)initWithCString: (const char *)cString
		       encoding: (of_string_encoding_t)encoding
			 length: (size_t)cStringLength
{
	if (encoding == OF_STRING_ENCODING_UTF_8) {
		id string;
		OFUTF8String *string;
		void *storage;

		string = of_alloc_object([OFUTF8String class],
		    cStringLength + 1, 1, &storage);

		return (id)[string of_initWithUTF8String: cString
						  length: cStringLength

Modified src/OFTarArchive.m from [74012ab28d] to [22d3bc898d].

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
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







+













+







#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotOpenException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
#import "OFWriteFailedException.h"

OF_DIRECT_MEMBERS
@interface OFTarArchiveFileReadStream: OFStream <OFReadyForReadingObserving>
{
	OFTarArchiveEntry *_entry;
	OFStream *_stream;
	uint64_t _toRead;
	bool _atEndOfStream, _skipped;
}

- (instancetype)of_initWithStream: (OFStream *)stream
			    entry: (OFTarArchiveEntry *)entry;
- (void)of_skip;
@end

OF_DIRECT_MEMBERS
@interface OFTarArchiveFileWriteStream: OFStream <OFReadyForWritingObserving>
{
	OFTarArchiveEntry *_entry;
	OFStream *_stream;
	uint64_t _toWrite;
}

Modified src/OFTarArchiveEntry+Private.h from [b3f653d2b2] to [13ddd96cdf].

18
19
20
21
22
23
24

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







+









#import "OFTarArchiveEntry.h"
#import "OFString.h"

OF_ASSUME_NONNULL_BEGIN

@class OFStream;

OF_DIRECT_MEMBERS
@interface OFTarArchiveEntry ()
- (instancetype)of_initWithHeader: (unsigned char [_Nonnull 512])header
			 encoding: (of_string_encoding_t)encoding
    OF_METHOD_FAMILY(init);
- (void)of_writeToStream: (OFStream *)stream
		encoding: (of_string_encoding_t)encoding;
@end

OF_ASSUME_NONNULL_END

Modified src/OFThread+Private.h from [5617fb7048] to [5ab3745dfa].

16
17
18
19
20
21
22

23
24
25
26
27
28
16
17
18
19
20
21
22
23
24
25
26
27
28
29







+






 */

#import "OFThread.h"

OF_ASSUME_NONNULL_BEGIN

#ifdef OF_HAVE_THREADS
OF_DIRECT_MEMBERS
@interface OFThread ()
+ (void)of_createMainThread;
@end
#endif

OF_ASSUME_NONNULL_END

Modified src/OFThreadPool.m from [246b1b023f] to [29bc99edba].

22
23
24
25
26
27
28

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







+







#import "OFThreadPool.h"
#import "OFArray.h"
#import "OFList.h"
#import "OFThread.h"
#import "OFCondition.h"
#import "OFSystemInfo.h"

OF_DIRECT_MEMBERS
@interface OFThreadPoolJob: OFObject
{
	id _target;
	SEL _selector;
	id _object;
#ifdef OF_HAVE_BLOCKS
	of_thread_pool_block_t _block;
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
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







+
















+
-
+







	else
#endif
		[_target performSelector: _selector
			      withObject: _object];
}
@end

OF_DIRECT_MEMBERS
@interface OFThreadPoolThread: OFThread
{
	OFList *_queue;
	OFCondition *_queueCondition, *_countCondition;
@public
	volatile bool _terminate;
	volatile int *_doneCount;
}

+ (instancetype)threadWithThreadPool: (OFThreadPool *)threadPool;
- (instancetype)initWithThreadPool: (OFThreadPool *)threadPool;
@end

@implementation OFThreadPoolThread
+ (instancetype)threadWithThreadPool: (OFThreadPool *)threadPool
{
	return [[(OFThreadPoolThread *)[self alloc]
	return [[[self alloc] initWithThreadPool: threadPool] autorelease];
	    initWithThreadPool: threadPool] autorelease];
}

- (instancetype)initWithThreadPool: (OFThreadPool *)threadPool
{
	self = [super init];

	@try {
293
294
295
296
297
298
299
300

301
302
303
304
305
306
307
296
297
298
299
300
301
302

303
304
305
306
307
308
309
310







-
+







	[_queue release];
	[_queueCondition release];
	[_countCondition release];

	[super dealloc];
}

- (void)of_dispatchJob: (OFThreadPoolJob *)job
- (void)of_dispatchJob: (OFThreadPoolJob *)job OF_DIRECT
{
	[_countCondition lock];
	_count++;
	[_countCondition unlock];

	[_queueCondition lock];
	@try {

Modified src/OFTimer+Private.h from [89cdf956f3] to [3bdcab087f].

15
16
17
18
19
20
21

22
23
24
25
26
27
15
16
17
18
19
20
21
22
23
24
25
26
27
28







+






 * file.
 */

#import "OFTimer.h"

OF_ASSUME_NONNULL_BEGIN

OF_DIRECT_MEMBERS
@interface OFTimer ()
- (void)of_setInRunLoop: (nullable OFRunLoop *)runLoop
		   mode: (nullable of_run_loop_mode_t)mode;
@end

OF_ASSUME_NONNULL_END

Modified src/OFTimer.m from [51ddf396b5] to [ced46435b5].

325
326
327
328
329
330
331
332


333
334
335
336
337
338
339
325
326
327
328
329
330
331

332
333
334
335
336
337
338
339
340







-
+
+







			     target: (id)target
			   selector: (SEL)selector
			     object: (id)object1
			     object: (id)object2
			     object: (id)object3
			     object: (id)object4
			  arguments: (uint8_t)arguments
			    repeats: (bool)repeats OF_METHOD_FAMILY(init)
			    repeats: (bool)repeats
    OF_METHOD_FAMILY(init) OF_DIRECT
{
	self = [super init];

	@try {
		_fireDate = [fireDate retain];
		_interval = interval;
		_target = [target retain];

Modified src/OFUDPSocket+Private.h from [cc4f2c83e7] to [bc60d66b62].

15
16
17
18
19
20
21

22
23
24
25
26
27
15
16
17
18
19
20
21
22
23
24
25
26
27
28







+






 * file.
 */

#import "OFUDPSocket.h"

OF_ASSUME_NONNULL_BEGIN

OF_DIRECT_MEMBERS
@interface OFUDPSocket ()
- (uint16_t)of_bindToAddress: (of_socket_address_t *)address
		   extraType: (int)extraType;
@end

OF_ASSUME_NONNULL_END

Modified src/OFUDPSocket.m from [851b1788ef] to [8b135fcca2].

35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49







-
+







#import "socket.h"
#import "socket_helpers.h"

@implementation OFUDPSocket
@dynamic delegate;

- (uint16_t)of_bindToAddress: (of_socket_address_t *)address
		   extraType: (int)extraType
		   extraType: (int)extraType OF_DIRECT
{
	void *pool = objc_autoreleasePoolPush();
	OFString *host;
	uint16_t port;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
	int flags;
#endif

Modified src/OFURL.m from [71131960ae] to [2524e037d6].

83
84
85
86
87
88
89

90
91
92
93
94
95
96
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97







+







static void
initURLQueryOrFragmentAllowedCharacterSet(void)
{
	URLQueryOrFragmentAllowedCharacterSet =
	    [[OFURLQueryOrFragmentAllowedCharacterSet alloc] init];
}

OF_DIRECT_MEMBERS
@interface OFInvertedCharacterSetWithoutPercent: OFCharacterSet
{
	OFCharacterSet *_characterSet;
	bool (*_characterIsMember)(id, SEL, of_unichar_t);
}

- (instancetype)initWithCharacterSet: (OFCharacterSet *)characterSet;

Modified src/OFUTF8String+Private.h from [d056e7820f] to [03f2449d2e].

15
16
17
18
19
20
21

22
23
24
25
26
27
28
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29







+







 * file.
 */

#import "OFUTF8String.h"

OF_ASSUME_NONNULL_BEGIN

OF_DIRECT_MEMBERS
@interface OFUTF8String ()
- (instancetype)of_initWithUTF8String: (const char *)UTF8String
			       length: (size_t)UTF8StringLength
			      storage: (char *)storage OF_METHOD_FAMILY(init);
@end

OF_ASSUME_NONNULL_END

Modified src/OFWindowsRegistryKey.m from [adb04f0d00] to [db8bc56ab6].

30
31
32
33
34
35
36

37
38
39
40
41
42
43
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44







+







#import "OFGetWindowsRegistryValueFailedException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFOpenWindowsRegistryKeyFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFSetWindowsRegistryValueFailedException.h"

OF_DIRECT_MEMBERS
@interface OFWindowsRegistryKey ()
- (instancetype)of_initWithHKey: (HKEY)hKey
			  close: (bool)close;
@end

@implementation OFWindowsRegistryKey
+ (instancetype)classesRootKey

Modified src/OFXMLElement.m from [5b4791734b] to [a8d9602939].

424
425
426
427
428
429
430
431

432
433
434
435
436
437
438
424
425
426
427
428
429
430

431
432
433
434
435
436
437
438







-
+








	return ret;
}

- (OFString *)of_XMLStringWithParent: (OFXMLElement *)parent
			  namespaces: (OFDictionary *)allNamespaces
			 indentation: (unsigned int)indentation
			       level: (unsigned int)level
			       level: (unsigned int)level OF_DIRECT
{
	void *pool;
	char *cString;
	size_t length, i;
	OFString *prefix, *parentPrefix;
	OFString *ret;
	OFString *defaultNS;

Modified src/OFXMLParser.h from [5c2cc1a7e0] to [12985c0c38].

149
150
151
152
153
154
155
156

157
158
159
160
161
162
163
164
149
150
151
152
153
154
155

156

157
158
159
160
161
162
163







-
+
-







		OF_XMLPARSER_EXPECT_SPACE_OR_TAG_CLOSE,
		OF_XMLPARSER_IN_EXCLAMATION_MARK,
		OF_XMLPARSER_IN_CDATA_OPENING,
		OF_XMLPARSER_IN_CDATA,
		OF_XMLPARSER_IN_COMMENT_OPENING,
		OF_XMLPARSER_IN_COMMENT_1,
		OF_XMLPARSER_IN_COMMENT_2,
		OF_XMLPARSER_IN_DOCTYPE,
		OF_XMLPARSER_IN_DOCTYPE
		OF_XMLPARSER_NUM_STATES
	} _state;
	size_t _i, _last;
	const char *_Nullable _data;
	OFMutableData *_buffer;
	OFString *_Nullable _name, *_Nullable _prefix;
	OFMutableArray
	    OF_GENERIC(OFMutableDictionary OF_GENERIC(OFString *, OFString *) *)

Modified src/OFXMLParser.m from [7ad1f08170] to [51abbe68ac].

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
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







-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFMalformedXMLException.h"
#import "OFOutOfRangeException.h"
#import "OFUnboundPrefixException.h"

typedef void (*state_function_t)(id, SEL);
static SEL selectors[OF_XMLPARSER_NUM_STATES];
static state_function_t lookupTable[OF_XMLPARSER_NUM_STATES];

@interface OFXMLParser () <OFStringXMLUnescapingDelegate>
- (void)of_inByteOrderMarkState;
- (void)of_outsideTagState;
- (void)of_tagOpenedState;
- (void)of_inProcessingInstructionsState;
- (void)of_inTagNameState;
- (void)of_inCloseTagNameState;
- (void)of_inTagState;
- (void)of_inAttributeNameState;
- (void)of_expectAttributeEqualSignState;
- (void)of_expectAttributeDelimiterState;
- (void)of_inAttributeValueState;
- (void)of_expectTagCloseState;
- (void)of_expectSpaceOrTagCloseState;
- (void)of_inExclamationMarkState;
- (void)of_inCDATAOpeningState;
- (void)of_inCDATAState;
- (void)of_inCommentOpeningState;
- (void)of_inCommentState1;
- (void)of_inCommentState2;
- (void)of_inDOCTYPEState;
@end

static void inByteOrderMarkState(OFXMLParser *);
static void outsideTagState(OFXMLParser *);
static void tagOpenedState(OFXMLParser *);
static void inProcessingInstructionsState(OFXMLParser *);
static void inTagNameState(OFXMLParser *);
static void inCloseTagNameState(OFXMLParser *);
static void inTagState(OFXMLParser *);
static void inAttributeNameState(OFXMLParser *);
static void expectAttributeEqualSignState(OFXMLParser *);
static void expectAttributeDelimiterState(OFXMLParser *);
static void inAttributeValueState(OFXMLParser *);
static void expectTagCloseState(OFXMLParser *);
static void expectSpaceOrTagCloseState(OFXMLParser *);
static void inExclamationMarkState(OFXMLParser *);
static void inCDATAOpeningState(OFXMLParser *);
static void inCDATAState(OFXMLParser *);
static void inCommentOpeningState(OFXMLParser *);
static void inCommentState1(OFXMLParser *);
static void inCommentState2(OFXMLParser *);
static void inDOCTYPEState(OFXMLParser *);
typedef void (*state_function_t)(OFXMLParser *);
static state_function_t lookupTable[] = {
	[OF_XMLPARSER_IN_BYTE_ORDER_MARK] = inByteOrderMarkState,
	[OF_XMLPARSER_OUTSIDE_TAG] = outsideTagState,
	[OF_XMLPARSER_TAG_OPENED] = tagOpenedState,
	[OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS] =
	    inProcessingInstructionsState,
	[OF_XMLPARSER_IN_TAG_NAME] = inTagNameState,
	[OF_XMLPARSER_IN_CLOSE_TAG_NAME] = inCloseTagNameState,
	[OF_XMLPARSER_IN_TAG] = inTagState,
	[OF_XMLPARSER_IN_ATTRIBUTE_NAME] = inAttributeNameState,
	[OF_XMLPARSER_EXPECT_ATTRIBUTE_EQUAL_SIGN] =
	    expectAttributeEqualSignState,
	[OF_XMLPARSER_EXPECT_ATTRIBUTE_DELIMITER] =
	    expectAttributeDelimiterState,
	[OF_XMLPARSER_IN_ATTRIBUTE_VALUE] = inAttributeValueState,
	[OF_XMLPARSER_EXPECT_TAG_CLOSE] = expectTagCloseState,
	[OF_XMLPARSER_EXPECT_SPACE_OR_TAG_CLOSE] = expectSpaceOrTagCloseState,
	[OF_XMLPARSER_IN_EXCLAMATION_MARK] = inExclamationMarkState,
	[OF_XMLPARSER_IN_CDATA_OPENING] = inCDATAOpeningState,
	[OF_XMLPARSER_IN_CDATA] = inCDATAState,
	[OF_XMLPARSER_IN_COMMENT_OPENING] = inCommentOpeningState,
	[OF_XMLPARSER_IN_COMMENT_1] = inCommentState1,
	[OF_XMLPARSER_IN_COMMENT_2] = inCommentState2,
	[OF_XMLPARSER_IN_DOCTYPE] = inDOCTYPEState
};

static OF_INLINE void
appendToBuffer(OFMutableData *buffer, const char *string,
    of_string_encoding_t encoding, size_t length)
{
	if (OF_LIKELY(encoding == OF_STRING_ENCODING_UTF_8))
		[buffer addItems: string
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
186
187
188
189
190
191
192




































193
194
195
196
197
198
199







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	[attribute->_namespace release];
	attribute->_namespace = [attributeNS retain];
}

@implementation OFXMLParser
@synthesize delegate = _delegate, depthLimit = _depthLimit;

+ (void)initialize
{
	const SEL selectors_[OF_XMLPARSER_NUM_STATES] = {
		@selector(of_inByteOrderMarkState),
		@selector(of_outsideTagState),
		@selector(of_tagOpenedState),
		@selector(of_inProcessingInstructionsState),
		@selector(of_inTagNameState),
		@selector(of_inCloseTagNameState),
		@selector(of_inTagState),
		@selector(of_inAttributeNameState),
		@selector(of_expectAttributeEqualSignState),
		@selector(of_expectAttributeDelimiterState),
		@selector(of_inAttributeValueState),
		@selector(of_expectTagCloseState),
		@selector(of_expectSpaceOrTagCloseState),
		@selector(of_inExclamationMarkState),
		@selector(of_inCDATAOpeningState),
		@selector(of_inCDATAState),
		@selector(of_inCommentOpeningState),
		@selector(of_inCommentState1),
		@selector(of_inCommentState2),
		@selector(of_inDOCTYPEState)
	};
	memcpy(selectors, selectors_, sizeof(selectors_));

	for (size_t i = 0; i < OF_XMLPARSER_NUM_STATES; i++) {
		if (![self instancesRespondToSelector: selectors[i]])
			@throw [OFInitializationFailedException
			    exceptionWithClass: self];

		lookupTable[i] = (state_function_t)
		    [self instanceMethodForSelector: selectors[i]];
	}
}

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

- (instancetype)init
{
259
260
261
262
263
264
265
266

267
268
269
270
271
272
273
246
247
248
249
250
251
252

253
254
255
256
257
258
259
260







-
+







	     length: (size_t)length
{
	_data = buffer;

	for (_i = _last = 0; _i < length; _i++) {
		size_t j = _i;

		lookupTable[_state](self, selectors[_state]);
		lookupTable[_state](self);

		/* Ensure we don't count this character twice */
		if (_i != j)
			continue;

		if (_data[_i] == '\r' || (_data[_i] == '\n' &&
		    !_lastCarriageReturn))
315
316
317
318
319
320
321
322
323
324
325
326
327
328


329
330
331
332
333




334
335
336
337
338
339
340
341


342
343

344
345
346

347

348
349
350
351
352
353




354
355
356

357
358
359
360



361
362

363
364


365
366

367
368
369


370
371
372
373
374

375
376
377


378
379
380

381

382
383


384
385
386

387
388
389
390



391
392
393
394
395



396
397
398
399
400



401
402
403


404
405
406
407
408



409
410
411
412
413

414

415
416
417
418
419
420
421
422
423
424

425
426
427

428
429
430
431
432
433
434
302
303
304
305
306
307
308







309
310
311




312
313
314
315
316
317
318
319
320
321


322
323
324

325
326
327
328
329

330
331
332
333



334
335
336
337
338
339

340
341
342


343
344
345
346

347
348

349
350
351

352
353


354
355
356
357
358
359

360
361


362
363
364
365
366
367

368
369

370
371
372
373

374
375



376
377
378
379
380



381
382
383
384
385



386
387
388
389
390

391
392
393
394



395
396
397
398
399
400
401
402
403

404
405
406
407
408
409
410
411
412
413

414
415
416

417
418
419
420
421
422
423
424







-
-
-
-
-
-
-
+
+

-
-
-
-
+
+
+
+






-
-
+
+

-
+



+
-
+



-
-
-
+
+
+
+


-
+


-
-
+
+
+

-
+

-
+
+

-
+

-
-
+
+




-
+

-
-
+
+



+
-
+

-
+
+


-
+

-
-
-
+
+
+


-
-
-
+
+
+


-
-
-
+
+
+


-
+
+


-
-
-
+
+
+





+
-
+









-
+


-
+







		[self parseStream: file];
	} @finally {
		[file release];
	}
}
#endif

/*
 * The following methods handle the different states of the parser. They are
 * looked up in +[initialize] and put in a lookup table to speed things up.
 * One dispatch for every character would be way too slow!
 */

- (void)of_inByteOrderMarkState
static void
inByteOrderMarkState(OFXMLParser *self)
{
	if (_data[_i] != "\xEF\xBB\xBF"[_level]) {
		if (_level == 0) {
			_state = OF_XMLPARSER_OUTSIDE_TAG;
			_i--;
	if (self->_data[self->_i] != "\xEF\xBB\xBF"[self->_level]) {
		if (self->_level == 0) {
			self->_state = OF_XMLPARSER_OUTSIDE_TAG;
			self->_i--;
			return;
		}

		@throw [OFMalformedXMLException exceptionWithParser: self];
	}

	if (_level++ == 2)
		_state = OF_XMLPARSER_OUTSIDE_TAG;
	if (self->_level++ == 2)
		self->_state = OF_XMLPARSER_OUTSIDE_TAG;

	_last = _i + 1;
	self->_last = self->_i + 1;
}

/* Not in a tag */
static void
- (void)of_outsideTagState
outsideTagState(OFXMLParser *self)
{
	size_t length;

	if ((_finishedParsing || _previous.count < 1) && _data[_i] != ' ' &&
	    _data[_i] != '\t' && _data[_i] != '\n' && _data[_i] != '\r' &&
	    _data[_i] != '<')
	if ((self->_finishedParsing || self->_previous.count < 1) &&
	    self->_data[self->_i] != ' '  && self->_data[self->_i] != '\t' &&
	    self->_data[self->_i] != '\n' && self->_data[self->_i] != '\r' &&
	    self->_data[self->_i] != '<')
		@throw [OFMalformedXMLException exceptionWithParser: self];

	if (_data[_i] != '<')
	if (self->_data[self->_i] != '<')
		return;

	if ((length = _i - _last) > 0)
		appendToBuffer(_buffer, _data + _last, _encoding, length);
	if ((length = self->_i - self->_last) > 0)
		appendToBuffer(self->_buffer, self->_data + self->_last,
		    self->_encoding, length);

	if (_buffer.count > 0) {
	if (self->_buffer.count > 0) {
		void *pool = objc_autoreleasePoolPush();
		OFString *characters = transformString(self, _buffer, 0, true);
		OFString *characters = transformString(self, self->_buffer, 0,
		    true);

		if ([_delegate respondsToSelector:
		if ([self->_delegate respondsToSelector:
		    @selector(parser:foundCharacters:)])
			[_delegate parser: self
			  foundCharacters: characters];
			[self->_delegate parser: self
				foundCharacters: characters];

		objc_autoreleasePoolPop(pool);
	}

	[_buffer removeAllItems];
	[self->_buffer removeAllItems];

	_last = _i + 1;
	_state = OF_XMLPARSER_TAG_OPENED;
	self->_last = self->_i + 1;
	self->_state = OF_XMLPARSER_TAG_OPENED;
}

/* Tag was just opened */
static void
- (void)of_tagOpenedState
tagOpenedState(OFXMLParser *self)
{
	if (_finishedParsing && _data[_i] != '!' && _data[_i] != '?')
	if (self->_finishedParsing && self->_data[self->_i] != '!' &&
	    self->_data[self->_i] != '?')
		@throw [OFMalformedXMLException exceptionWithParser: self];

	switch (_data[_i]) {
	switch (self->_data[self->_i]) {
	case '?':
		_last = _i + 1;
		_state = OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS;
		_level = 0;
		self->_last = self->_i + 1;
		self->_state = OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS;
		self->_level = 0;
		break;
	case '/':
		_last = _i + 1;
		_state = OF_XMLPARSER_IN_CLOSE_TAG_NAME;
		_acceptProlog = false;
		self->_last = self->_i + 1;
		self->_state = OF_XMLPARSER_IN_CLOSE_TAG_NAME;
		self->_acceptProlog = false;
		break;
	case '!':
		_last = _i + 1;
		_state = OF_XMLPARSER_IN_EXCLAMATION_MARK;
		_acceptProlog = false;
		self->_last = self->_i + 1;
		self->_state = OF_XMLPARSER_IN_EXCLAMATION_MARK;
		self->_acceptProlog = false;
		break;
	default:
		if (_depthLimit > 0 && _previous.count >= _depthLimit)
		if (self->_depthLimit > 0 &&
		    self->_previous.count >= self->_depthLimit)
			@throw [OFOutOfRangeException exception];

		_state = OF_XMLPARSER_IN_TAG_NAME;
		_acceptProlog = false;
		_i--;
		self->_state = OF_XMLPARSER_IN_TAG_NAME;
		self->_acceptProlog = false;
		self->_i--;
		break;
	}
}

/* <?xml […]?> */
static bool
- (bool)of_parseXMLProcessingInstructions: (OFString *)pi
parseXMLProcessingInstructions(OFXMLParser *self, OFString *pi)
{
	const char *cString;
	size_t length, last;
	int PIState = 0;
	OFString *attribute = nil;
	OFMutableString *value = nil;
	char piDelimiter = 0;
	bool hasVersion = false;

	if (!_acceptProlog)
	if (!self->_acceptProlog)
		return false;

	_acceptProlog = false;
	self->_acceptProlog = false;

	pi = [pi substringWithRange: of_range(3, pi.length - 3)];
	pi = pi.stringByDeletingEnclosingWhitespaces;

	cString = pi.UTF8String;
	length = pi.UTF8StringLength;

447
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
437
438
439
440
441
442
443

444
445
446
447
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







-
+




















-
+











-
+







			break;
		case 1:
			if (cString[i] != '=')
				continue;

			attribute = [OFString
			    stringWithCString: cString + last
				     encoding: _encoding
				     encoding: self->_encoding
				       length: i - last];
			last = i + 1;
			PIState = 2;

			break;
		case 2:
			if (cString[i] != '\'' && cString[i] != '"')
				return false;

			piDelimiter = cString[i];
			last = i + 1;
			PIState = 3;

			break;
		case 3:
			if (cString[i] != piDelimiter)
				continue;

			value = [OFMutableString
			    stringWithCString: cString + last
				     encoding: _encoding
				     encoding: self->_encoding
				       length: i - last];

			if ([attribute isEqual: @"version"]) {
				if (![value hasPrefix: @"1."])
					return false;

				hasVersion = true;
			}

			if ([attribute isEqual: @"encoding"]) {
				@try {
					_encoding =
					self->_encoding =
					    of_string_parse_encoding(value);
				} @catch (OFInvalidArgumentException *e) {
					@throw [OFInvalidEncodingException
					    exception];
				}
			}

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
572
573
574


575
576
577

578
579
580


581
582

583
584

585
586
587

588
589
590
591
592
593





594
595
596


597
598
599
600
601




602
603
604


605
606

607
608
609
610



611
612

613
614
615
616

617
618
619


620
621
622
623
624


625
626
627

628

629
630
631
632
633
634

635
636


637
638
639
640



641
642
643
644
645


646
647
648
649
650

651
652
653
654

655
656
657
658
659


660
661
662

663
664
665

666
667

668
669
670
671
672





673
674

675
676
677
678
679




680
681
682
683
684
685
686




687
688
689


690
691
692
693
694


695
696
697

698

699
700
701
702
703
704
705
706
707
708
709
710








711
712
713
714
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




746
747
748


749
750
751
752
753
754





755
756

757
758
759
760
761
762
763




764
765
766


767
768
769
770
771

772

773
774
775
776
777
778

779
780


781
782
783
784



785
786
787
788
789


790
791
792
793
794
795

796
797
798
799

800
801
802
803
804


805
806
807
808
809

810
811
812


813
814
815
816
817

818

819
820
821
822



823
824
825
826
827


828
829
830
831

832

833
834

835
836
837


838
839
840

841
842
843
844


845
846
847

848

849
850
851
852
853
854
855

856
857
858
859



860
861
862

863

864
865
866
867
868
869






870
871
872


873
874
875


876
877
878
879
880
881
882




883
884
885


886
887
888

889

890
891
892
893



894
895
896
897
898

899

900
901
902
903
904
905






906
907
908
909

910

911
912

913
914
915
916
917
918
919
920
921
922








923
924
925
926

927
928
929

930

931
932

933
934
935
936
937



938
939
940

941
942

943

944
945

946
947
948


949
950
951
952
953



954
955

956
957
958


959
960
961
962

963
964
965


966
967

968
969
970

971

972
973

974
975
976
977
978



979
980

981

982
983
984


985
986

987
988
989


990
991

992

993
994
995
996
997

998
999
1000
1001
1002
1003



1004

1005
1006
1007



1008
1009
1010
1011

1012
1013
1014


1015
1016
1017

1018

1019
1020
1021
1022





1023
1024
1025

1026
1027
1028


1029
1030

1031
1032
1033
1034
1035
1036
1037
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

572
573
574

575
576
577

578
579

580
581
582

583
584





585
586
587
588
589
590


591
592
593




594
595
596
597
598


599
600
601

602
603



604
605
606
607

608
609
610
611

612
613


614
615
616
617
618


619
620
621
622
623
624

625
626
627
628
629
630
631
632


633
634
635
636


637
638
639
640
641
642


643
644
645
646
647
648

649
650
651
652

653
654
655
656


657
658
659
660

661
662
663

664
665

666
667




668
669
670
671
672
673

674
675




676
677
678
679
680
681
682




683
684
685
686
687


688
689
690
691
692


693
694
695
696
697
698

699
700
701
702
703
704
705






706
707
708
709
710
711
712
713
714
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




746
747
748
749
750


751
752
753





754
755
756
757
758
759

760
761
762
763




764
765
766
767
768


769
770
771
772
773
774
775
776

777
778
779
780
781
782
783
784


785
786
787
788


789
790
791
792
793
794


795
796
797
798
799
800
801

802
803
804
805

806
807
808
809


810
811
812
813
814
815

816
817


818
819
820
821
822
823
824
825

826
827



828
829
830
831
832
833


834
835
836
837
838
839
840

841
842

843
844


845
846
847
848

849
850
851


852
853
854
855
856
857

858
859
860
861
862
863
864

865
866
867


868
869
870
871
872

873
874
875






876
877
878
879
880
881
882


883
884
885


886
887
888
889
890




891
892
893
894
895


896
897
898
899
900
901

902
903



904
905
906
907
908
909
910
911
912

913
914





915
916
917
918
919
920
921
922
923
924
925

926
927

928
929
930








931
932
933
934
935
936
937
938
939
940
941

942
943
944
945
946

947
948

949
950
951



952
953
954
955
956

957
958
959
960

961
962

963



964
965
966
967
968


969
970
971
972

973
974


975
976
977
978
979

980
981


982
983
984

985
986
987
988
989

990
991

992
993
994



995
996
997
998
999
1000

1001
1002


1003
1004
1005

1006
1007


1008
1009
1010
1011
1012

1013
1014
1015
1016
1017

1018
1019
1020
1021
1022


1023
1024
1025
1026
1027



1028
1029
1030
1031
1032
1033

1034
1035


1036
1037
1038
1039
1040
1041

1042
1043



1044
1045
1046
1047
1048
1049
1050

1051
1052


1053
1054
1055

1056
1057
1058
1059
1060
1061
1062
1063







+
-
+

-
-
-
+
+
+



-
-
+
+
+




-
+



-
+

-
+




-
+

-
-
+
+

-
+



+
-
+






+
-
-
+
+


-
-
+
+
+



-
-
+
+




-
+



-
+



-
-
+
+


-
+


-
+
+

-
+

-
+


-
+

-
-
-
-
-
+
+
+
+
+

-
-
+
+

-
-
-
-
+
+
+
+

-
-
+
+

-
+

-
-
-
+
+
+

-
+



-
+

-
-
+
+



-
-
+
+



+
-
+






+
-
-
+
+


-
-
+
+
+



-
-
+
+




-
+



-
+



-
-
+
+


-
+


-
+

-
+

-
-
-
-
+
+
+
+
+

-
+

-
-
-
-
+
+
+
+



-
-
-
-
+
+
+
+

-
-
+
+



-
-
+
+



+
-
+






-
-
-
-
-
-
+
+
+
+
+
+
+
+





-
-
+
+

-
+

-
-
-
+
+
+
+


-
-
+
+



-
+

-
-
-
-
-
+
+
+
+
+

-
-
+
+

-
-
-
-
+
+
+
+

-
-
+
+

-
-
-
-
-
+
+
+
+
+

-
+



-
-
-
-
+
+
+
+

-
-
+
+





+
-
+






+
-
-
+
+


-
-
+
+
+



-
-
+
+





-
+



-
+



-
-
+
+




-
+

-
-
+
+





+
-
+

-
-
-
+
+
+



-
-
+
+




+
-
+

-
+

-
-
+
+


-
+


-
-
+
+



+
-
+






-
+


-
-
+
+
+


-
+

+
-
-
-
-
-
-
+
+
+
+
+
+

-
-
+
+

-
-
+
+



-
-
-
-
+
+
+
+

-
-
+
+



+
-
+

-
-
-
+
+
+





+
-
+

-
-
-
-
-
+
+
+
+
+
+




+
-
+

-
+


-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+



-
+



+
-
+

-
+


-
-
-
+
+
+


-
+


+
-
+

-
+
-
-
-
+
+



-
-
+
+
+

-
+

-
-
+
+



-
+

-
-
+
+

-
+



+
-
+

-
+


-
-
-
+
+
+


+
-
+

-
-
+
+

-
+

-
-
+
+


+
-
+




-
+




-
-
+
+
+

+
-
-
-
+
+
+



-
+

-
-
+
+



+
-
+

-
-
-
+
+
+
+
+


-
+

-
-
+
+

-
+







	if (PIState != 0 || !hasVersion)
		return false;

	return true;
}

/* Inside processing instructions */
static void
- (void)of_inProcessingInstructionsState
inProcessingInstructionsState(OFXMLParser *self)
{
	if (_data[_i] == '?')
		_level = 1;
	else if (_level == 1 && _data[_i] == '>') {
	if (self->_data[self->_i] == '?')
		self->_level = 1;
	else if (self->_level == 1 && self->_data[self->_i] == '>') {
		void *pool = objc_autoreleasePoolPush();
		OFString *PI;

		appendToBuffer(_buffer, _data + _last, _encoding, _i - _last);
		PI = transformString(self, _buffer, 1, false);
		appendToBuffer(self->_buffer, self->_data + self->_last,
		    self->_encoding, self->_i - self->_last);
		PI = transformString(self, self->_buffer, 1, false);

		if ([PI isEqual: @"xml"] || [PI hasPrefix: @"xml "] ||
		    [PI hasPrefix: @"xml\t"] || [PI hasPrefix: @"xml\r"] ||
		    [PI hasPrefix: @"xml\n"])
			if (![self of_parseXMLProcessingInstructions: PI])
			if (!parseXMLProcessingInstructions(self, PI))
				@throw [OFMalformedXMLException
				    exceptionWithParser: self];

		if ([_delegate respondsToSelector:
		if ([self->_delegate respondsToSelector:
		    @selector(parser:foundProcessingInstructions:)])
			[_delegate		 parser: self
			[self->_delegate	 parser: self
			    foundProcessingInstructions: PI];

		objc_autoreleasePoolPop(pool);

		[_buffer removeAllItems];
		[self->_buffer removeAllItems];

		_last = _i + 1;
		_state = OF_XMLPARSER_OUTSIDE_TAG;
		self->_last = self->_i + 1;
		self->_state = OF_XMLPARSER_OUTSIDE_TAG;
	} else
		_level = 0;
		self->_level = 0;
}

/* Inside a tag, no name yet */
static void
- (void)of_inTagNameState
inTagNameState(OFXMLParser *self)
{
	void *pool;
	const char *bufferCString, *tmp;
	size_t length, bufferLength;
	OFString *bufferString;

	if (self->_data[self->_i] != ' '  && self->_data[self->_i] != '\t' &&
	if (_data[_i] != ' ' && _data[_i] != '\t' && _data[_i] != '\n' &&
	    _data[_i] != '\r' && _data[_i] != '>' && _data[_i] != '/')
	    self->_data[self->_i] != '\n' && self->_data[self->_i] != '\r' &&
	    self->_data[self->_i] != '>'  && self->_data[self->_i] != '/')
		return;

	if ((length = _i - _last) > 0)
		appendToBuffer(_buffer, _data + _last, _encoding, length);
	if ((length = self->_i - self->_last) > 0)
		appendToBuffer(self->_buffer, self->_data + self->_last,
		    self->_encoding, length);

	pool = objc_autoreleasePoolPush();

	bufferCString = _buffer.items;
	bufferLength = _buffer.count;
	bufferCString = self->_buffer.items;
	bufferLength = self->_buffer.count;
	bufferString = [OFString stringWithUTF8String: bufferCString
					       length: bufferLength];

	if ((tmp = memchr(bufferCString, ':', bufferLength)) != NULL) {
		_name = [[OFString alloc]
		self->_name = [[OFString alloc]
		    initWithUTF8String: tmp + 1
				length: bufferLength -
					(tmp - bufferCString) - 1];
		_prefix = [[OFString alloc]
		self->_prefix = [[OFString alloc]
		    initWithUTF8String: bufferCString
				length: tmp - bufferCString];
	} else {
		_name = [bufferString copy];
		_prefix = nil;
		self->_name = [bufferString copy];
		self->_prefix = nil;
	}

	if (_data[_i] == '>' || _data[_i] == '/') {
	if (self->_data[self->_i] == '>' || self->_data[self->_i] == '/') {
		OFString *namespace;

		namespace = namespaceForPrefix(_prefix, _namespaces);
		namespace = namespaceForPrefix(self->_prefix,
		    self->_namespaces);

		if (_prefix != nil && namespace == nil)
		if (self->_prefix != nil && namespace == nil)
			@throw [OFUnboundPrefixException
			    exceptionWithPrefix: _prefix
			    exceptionWithPrefix: self->_prefix
					 parser: self];

		if ([_delegate respondsToSelector: @selector(parser:
		if ([self->_delegate respondsToSelector: @selector(parser:
		    didStartElement:prefix:namespace:attributes:)])
			[_delegate parser: self
			  didStartElement: _name
				   prefix: _prefix
				namespace: namespace
			       attributes: nil];
			[self->_delegate parser: self
				didStartElement: self->_name
					 prefix: self->_prefix
				      namespace: namespace
				     attributes: nil];

		if (_data[_i] == '/') {
			if ([_delegate respondsToSelector:
		if (self->_data[self->_i] == '/') {
			if ([self->_delegate respondsToSelector:
			    @selector(parser:didEndElement:prefix:namespace:)])
				[_delegate parser: self
				    didEndElement: _name
					   prefix: _prefix
					namespace: namespace];
				[self->_delegate parser: self
					  didEndElement: self->_name
						 prefix: self->_prefix
					      namespace: namespace];

			if (_previous.count == 0)
				_finishedParsing = true;
			if (self->_previous.count == 0)
				self->_finishedParsing = true;
		} else
			[_previous addObject: bufferString];
			[self->_previous addObject: bufferString];

		[_name release];
		[_prefix release];
		_name = _prefix = nil;
		[self->_name release];
		[self->_prefix release];
		self->_name = self->_prefix = nil;

		_state = (_data[_i] == '/'
		self->_state = (self->_data[self->_i] == '/'
		    ? OF_XMLPARSER_EXPECT_TAG_CLOSE
		    : OF_XMLPARSER_OUTSIDE_TAG);
	} else
		_state = OF_XMLPARSER_IN_TAG;
		self->_state = OF_XMLPARSER_IN_TAG;

	if (_data[_i] != '/')
		[_namespaces addObject: [OFMutableDictionary dictionary]];
	if (self->_data[self->_i] != '/')
		[self->_namespaces addObject: [OFMutableDictionary dictionary]];

	objc_autoreleasePoolPop(pool);

	[_buffer removeAllItems];
	_last = _i + 1;
	[self->_buffer removeAllItems];
	self->_last = self->_i + 1;
}

/* Inside a close tag, no name yet */
static void
- (void)of_inCloseTagNameState
inCloseTagNameState(OFXMLParser *self)
{
	void *pool;
	const char *bufferCString, *tmp;
	size_t length, bufferLength;
	OFString *bufferString, *namespace;

	if (self->_data[self->_i] != ' '  && self->_data[self->_i] != '\t' &&
	if (_data[_i] != ' ' && _data[_i] != '\t' && _data[_i] != '\n' &&
	    _data[_i] != '\r' && _data[_i] != '>')
	    self->_data[self->_i] != '\n' && self->_data[self->_i] != '\r' &&
	    self->_data[self->_i] != '>')
		return;

	if ((length = _i - _last) > 0)
		appendToBuffer(_buffer, _data + _last, _encoding, length);
	if ((length = self->_i - self->_last) > 0)
		appendToBuffer(self->_buffer, self->_data + self->_last,
		    self->_encoding, length);

	pool = objc_autoreleasePoolPush();

	bufferCString = _buffer.items;
	bufferLength = _buffer.count;
	bufferCString = self->_buffer.items;
	bufferLength = self->_buffer.count;
	bufferString = [OFString stringWithUTF8String: bufferCString
					       length: bufferLength];

	if ((tmp = memchr(bufferCString, ':', bufferLength)) != NULL) {
		_name = [[OFString alloc]
		self->_name = [[OFString alloc]
		    initWithUTF8String: tmp + 1
				length: bufferLength -
					(tmp - bufferCString) - 1];
		_prefix = [[OFString alloc]
		self->_prefix = [[OFString alloc]
		    initWithUTF8String: bufferCString
				length: tmp - bufferCString];
	} else {
		_name = [bufferString copy];
		_prefix = nil;
		self->_name = [bufferString copy];
		self->_prefix = nil;
	}

	if (![_previous.lastObject isEqual: bufferString])
	if (![self->_previous.lastObject isEqual: bufferString])
		@throw [OFMalformedXMLException exceptionWithParser: self];

	[_previous removeLastObject];
	[self->_previous removeLastObject];

	[_buffer removeAllItems];
	[self->_buffer removeAllItems];

	namespace = namespaceForPrefix(_prefix, _namespaces);
	if (_prefix != nil && namespace == nil)
		@throw [OFUnboundPrefixException exceptionWithPrefix: _prefix
							      parser: self];
	namespace = namespaceForPrefix(self->_prefix, self->_namespaces);
	if (self->_prefix != nil && namespace == nil)
		@throw [OFUnboundPrefixException
		    exceptionWithPrefix: self->_prefix
				 parser: self];

	if ([_delegate respondsToSelector:
	if ([self->_delegate respondsToSelector:
	    @selector(parser:didEndElement:prefix:namespace:)])
		[_delegate parser: self
		    didEndElement: _name
			   prefix: _prefix
			namespace: namespace];
		[self->_delegate parser: self
			  didEndElement: self->_name
				 prefix: self->_prefix
			      namespace: namespace];

	objc_autoreleasePoolPop(pool);

	[_namespaces removeLastObject];
	[_name release];
	[_prefix release];
	_name = _prefix = nil;
	[self->_namespaces removeLastObject];
	[self->_name release];
	[self->_prefix release];
	self->_name = self->_prefix = nil;

	_last = _i + 1;
	_state = (_data[_i] == '>'
	self->_last = self->_i + 1;
	self->_state = (self->_data[self->_i] == '>'
	    ? OF_XMLPARSER_OUTSIDE_TAG
	    : OF_XMLPARSER_EXPECT_SPACE_OR_TAG_CLOSE);

	if (_previous.count == 0)
		_finishedParsing = true;
	if (self->_previous.count == 0)
		self->_finishedParsing = true;
}

/* Inside a tag, name found */
static void
- (void)of_inTagState
inTagState(OFXMLParser *self)
{
	void *pool;
	OFString *namespace;
	OFXMLAttribute *const *attributesObjects;
	size_t attributesCount;

	if (_data[_i] != '>' && _data[_i] != '/') {
		if (_data[_i] != ' ' && _data[_i] != '\t' &&
		    _data[_i] != '\n' && _data[_i] != '\r') {
			_last = _i;
			_state = OF_XMLPARSER_IN_ATTRIBUTE_NAME;
			_i--;
	if (self->_data[self->_i] != '>' && self->_data[self->_i] != '/') {
		if (self->_data[self->_i] != ' ' &&
		    self->_data[self->_i] != '\t' &&
		    self->_data[self->_i] != '\n' &&
		    self->_data[self->_i] != '\r') {
			self->_last = self->_i;
			self->_state = OF_XMLPARSER_IN_ATTRIBUTE_NAME;
			self->_i--;
		}

		return;
	}

	attributesObjects = _attributes.objects;
	attributesCount = _attributes.count;
	attributesObjects = self->_attributes.objects;
	attributesCount = self->_attributes.count;

	namespace = namespaceForPrefix(_prefix, _namespaces);
	namespace = namespaceForPrefix(self->_prefix, self->_namespaces);

	if (_prefix != nil && namespace == nil)
		@throw [OFUnboundPrefixException exceptionWithPrefix: _prefix
							      parser: self];
	if (self->_prefix != nil && namespace == nil)
		@throw [OFUnboundPrefixException
		    exceptionWithPrefix: self->_prefix
				 parser: self];

	for (size_t j = 0; j < attributesCount; j++)
		resolveAttributeNamespace(attributesObjects[j], _namespaces,
		    self);
		resolveAttributeNamespace(attributesObjects[j],
		    self->_namespaces, self);

	pool = objc_autoreleasePoolPush();

	if ([_delegate respondsToSelector:
	if ([self->_delegate respondsToSelector:
	    @selector(parser:didStartElement:prefix:namespace:attributes:)])
		[_delegate parser: self
		  didStartElement: _name
			   prefix: _prefix
			namespace: namespace
		       attributes: _attributes];
		[self->_delegate parser: self
			didStartElement: self->_name
				 prefix: self->_prefix
			      namespace: namespace
			     attributes: self->_attributes];

	if (_data[_i] == '/') {
		if ([_delegate respondsToSelector:
	if (self->_data[self->_i] == '/') {
		if ([self->_delegate respondsToSelector:
		    @selector(parser:didEndElement:prefix:namespace:)])
			[_delegate parser: self
			    didEndElement: _name
				   prefix: _prefix
				namespace: namespace];
			[self->_delegate parser: self
				  didEndElement: self->_name
					 prefix: self->_prefix
				      namespace: namespace];

		if (_previous.count == 0)
			_finishedParsing = true;
		if (self->_previous.count == 0)
			self->_finishedParsing = true;

		[_namespaces removeLastObject];
	} else if (_prefix != nil) {
		OFString *str = [OFString stringWithFormat: @"%@:%@",
							    _prefix, _name];
		[_previous addObject: str];
		[self->_namespaces removeLastObject];
	} else if (self->_prefix != nil) {
		OFString *str = [OFString stringWithFormat:
		    @"%@:%@", self->_prefix, self->_name];
		[self->_previous addObject: str];
	} else
		[_previous addObject: _name];
		[self->_previous addObject: self->_name];

	objc_autoreleasePoolPop(pool);

	[_name release];
	[_prefix release];
	[_attributes removeAllObjects];
	_name = _prefix = nil;
	[self->_name release];
	[self->_prefix release];
	[self->_attributes removeAllObjects];
	self->_name = self->_prefix = nil;

	_last = _i + 1;
	_state = (_data[_i] == '/'
	self->_last = self->_i + 1;
	self->_state = (self->_data[self->_i] == '/'
	    ? OF_XMLPARSER_EXPECT_TAG_CLOSE
	    : OF_XMLPARSER_OUTSIDE_TAG);
}

/* Looking for attribute name */
static void
- (void)of_inAttributeNameState
inAttributeNameState(OFXMLParser *self)
{
	void *pool;
	OFString *bufferString;
	const char *bufferCString, *tmp;
	size_t length, bufferLength;

	if (self->_data[self->_i] != '='  && self->_data[self->_i] != ' '  &&
	if (_data[_i] != '=' && _data[_i] != ' ' && _data[_i] != '\t' &&
	    _data[_i] != '\n' && _data[_i] != '\r')
	    self->_data[self->_i] != '\t' && self->_data[self->_i] != '\n' &&
	    self->_data[self->_i] != '\r')
		return;

	if ((length = _i - _last) > 0)
		appendToBuffer(_buffer, _data + _last, _encoding, length);
	if ((length = self->_i - self->_last) > 0)
		appendToBuffer(self->_buffer, self->_data + self->_last,
		    self->_encoding, length);

	pool = objc_autoreleasePoolPush();

	bufferString = [OFString stringWithUTF8String: _buffer.items
					       length: _buffer.count];
	bufferString = [OFString stringWithUTF8String: self->_buffer.items
					       length: self->_buffer.count];

	bufferCString = bufferString.UTF8String;
	bufferLength = bufferString.UTF8StringLength;

	if ((tmp = memchr(bufferCString, ':', bufferLength)) != NULL) {
		_attributeName = [[OFString alloc]
		self->_attributeName = [[OFString alloc]
		    initWithUTF8String: tmp + 1
				length: bufferLength -
					(tmp - bufferCString) - 1];
		_attributePrefix = [[OFString alloc]
		self->_attributePrefix = [[OFString alloc]
		    initWithUTF8String: bufferCString
				length: tmp - bufferCString];
	} else {
		_attributeName = [bufferString copy];
		_attributePrefix = nil;
		self->_attributeName = [bufferString copy];
		self->_attributePrefix = nil;
	}

	objc_autoreleasePoolPop(pool);

	[_buffer removeAllItems];
	[self->_buffer removeAllItems];

	_last = _i + 1;
	_state = (_data[_i] == '='
	self->_last = self->_i + 1;
	self->_state = (self->_data[self->_i] == '='
	    ? OF_XMLPARSER_EXPECT_ATTRIBUTE_DELIMITER
	    : OF_XMLPARSER_EXPECT_ATTRIBUTE_EQUAL_SIGN);
}

/* Expecting equal sign of an attribute */
static void
- (void)of_expectAttributeEqualSignState
expectAttributeEqualSignState(OFXMLParser *self)
{
	if (_data[_i] == '=') {
		_last = _i + 1;
		_state = OF_XMLPARSER_EXPECT_ATTRIBUTE_DELIMITER;
	if (self->_data[self->_i] == '=') {
		self->_last = self->_i + 1;
		self->_state = OF_XMLPARSER_EXPECT_ATTRIBUTE_DELIMITER;
		return;
	}

	if (_data[_i] != ' ' && _data[_i] != '\t' && _data[_i] != '\n' &&
	    _data[_i] != '\r')
	if (self->_data[self->_i] != ' '  && self->_data[self->_i] != '\t' &&
	    self->_data[self->_i] != '\n' && self->_data[self->_i] != '\r')
		@throw [OFMalformedXMLException exceptionWithParser: self];
}

/* Expecting name/value delimiter of an attribute */
static void
- (void)of_expectAttributeDelimiterState
expectAttributeDelimiterState(OFXMLParser *self)
{
	_last = _i + 1;
	self->_last = self->_i + 1;

	if (_data[_i] == ' ' || _data[_i] == '\t' || _data[_i] == '\n' ||
	    _data[_i] == '\r')
	if (self->_data[self->_i] == ' '  || self->_data[self->_i] == '\t' ||
	    self->_data[self->_i] == '\n' || self->_data[self->_i] == '\r')
		return;

	if (_data[_i] != '\'' && _data[_i] != '"')
	if (self->_data[self->_i] != '\'' && self->_data[self->_i] != '"')
		@throw [OFMalformedXMLException exceptionWithParser: self];

	_delimiter = _data[_i];
	_state = OF_XMLPARSER_IN_ATTRIBUTE_VALUE;
	self->_delimiter = self->_data[self->_i];
	self->_state = OF_XMLPARSER_IN_ATTRIBUTE_VALUE;
}

/* Looking for attribute value */
static void
- (void)of_inAttributeValueState
inAttributeValueState(OFXMLParser *self)
{
	void *pool;
	OFString *attributeValue;
	size_t length;
	OFXMLAttribute *attribute;

	if (_data[_i] != _delimiter)
	if (self->_data[self->_i] != self->_delimiter)
		return;

	if ((length = _i - _last) > 0)
		appendToBuffer(_buffer, _data + _last, _encoding, length);
	if ((length = self->_i - self->_last) > 0)
		appendToBuffer(self->_buffer, self->_data + self->_last,
		    self->_encoding, length);

	pool = objc_autoreleasePoolPush();
	attributeValue = transformString(self, _buffer, 0, true);
	attributeValue = transformString(self, self->_buffer, 0, true);

	if (self->_attributePrefix == nil &&
	if (_attributePrefix == nil && [_attributeName isEqual: @"xmlns"])
		[_namespaces.lastObject setObject: attributeValue
					   forKey: @""];
	if ([_attributePrefix isEqual: @"xmlns"])
		[_namespaces.lastObject setObject: attributeValue
					   forKey: _attributeName];
	    [self->_attributeName isEqual: @"xmlns"])
		[self->_namespaces.lastObject setObject: attributeValue
						 forKey: @""];
	if ([self->_attributePrefix isEqual: @"xmlns"])
		[self->_namespaces.lastObject setObject: attributeValue
						 forKey: self->_attributeName];

	attribute = [OFXMLAttribute attributeWithName: _attributeName
					    namespace: _attributePrefix
	attribute = [OFXMLAttribute attributeWithName: self->_attributeName
					    namespace: self->_attributePrefix
					  stringValue: attributeValue];
	attribute->_useDoubleQuotes = (_delimiter == '"');
	[_attributes addObject: attribute];
	attribute->_useDoubleQuotes = (self->_delimiter == '"');
	[self->_attributes addObject: attribute];

	objc_autoreleasePoolPop(pool);

	[_buffer removeAllItems];
	[_attributeName release];
	[_attributePrefix release];
	_attributeName = _attributePrefix = nil;
	[self->_buffer removeAllItems];
	[self->_attributeName release];
	[self->_attributePrefix release];
	self->_attributeName = self->_attributePrefix = nil;

	_last = _i + 1;
	_state = OF_XMLPARSER_IN_TAG;
	self->_last = self->_i + 1;
	self->_state = OF_XMLPARSER_IN_TAG;
}

/* Expecting closing '>' */
static void
- (void)of_expectTagCloseState
expectTagCloseState(OFXMLParser *self)
{
	if (_data[_i] == '>') {
		_last = _i + 1;
		_state = OF_XMLPARSER_OUTSIDE_TAG;
	if (self->_data[self->_i] == '>') {
		self->_last = self->_i + 1;
		self->_state = OF_XMLPARSER_OUTSIDE_TAG;
	} else
		@throw [OFMalformedXMLException exceptionWithParser: self];
}

/* Expecting closing '>' or space */
static void
- (void)of_expectSpaceOrTagCloseState
expectSpaceOrTagCloseState(OFXMLParser *self)
{
	if (_data[_i] == '>') {
		_last = _i + 1;
		_state = OF_XMLPARSER_OUTSIDE_TAG;
	} else if (_data[_i] != ' ' && _data[_i] != '\t' &&
	    _data[_i] != '\n' && _data[_i] != '\r')
	if (self->_data[self->_i] == '>') {
		self->_last = self->_i + 1;
		self->_state = OF_XMLPARSER_OUTSIDE_TAG;
	} else if (self->_data[self->_i] != ' ' &&
	    self->_data[self->_i] != '\t' && self->_data[self->_i] != '\n' &&
	    self->_data[self->_i] != '\r')
		@throw [OFMalformedXMLException exceptionWithParser: self];
}

/* In <! */
static void
- (void)of_inExclamationMarkState
inExclamationMarkState(OFXMLParser *self)
{
	if (_finishedParsing && _data[_i] != '-')
	if (self->_finishedParsing && self->_data[self->_i] != '-')
		@throw [OFMalformedXMLException exceptionWithParser: self];

	if (_data[_i] == '-')
		_state = OF_XMLPARSER_IN_COMMENT_OPENING;
	else if (_data[_i] == '[') {
		_state = OF_XMLPARSER_IN_CDATA_OPENING;
		_level = 0;
	} else if (_data[_i] == 'D') {
		_state = OF_XMLPARSER_IN_DOCTYPE;
		_level = 0;
	if (self->_data[self->_i] == '-')
		self->_state = OF_XMLPARSER_IN_COMMENT_OPENING;
	else if (self->_data[self->_i] == '[') {
		self->_state = OF_XMLPARSER_IN_CDATA_OPENING;
		self->_level = 0;
	} else if (self->_data[self->_i] == 'D') {
		self->_state = OF_XMLPARSER_IN_DOCTYPE;
		self->_level = 0;
	} else
		@throw [OFMalformedXMLException exceptionWithParser: self];

	_last = _i + 1;
	self->_last = self->_i + 1;
}

/* CDATA */
static void
- (void)of_inCDATAOpeningState
inCDATAOpeningState(OFXMLParser *self)
{
	if (_data[_i] != "CDATA["[_level])
	if (self->_data[self->_i] != "CDATA["[self->_level])
		@throw [OFMalformedXMLException exceptionWithParser: self];

	if (++_level == 6) {
		_state = OF_XMLPARSER_IN_CDATA;
		_level = 0;
	if (++self->_level == 6) {
		self->_state = OF_XMLPARSER_IN_CDATA;
		self->_level = 0;
	}

	_last = _i + 1;
	self->_last = self->_i + 1;
}

static void
- (void)of_inCDATAState
inCDATAState(OFXMLParser *self)
{

	if (self->_data[self->_i] == ']')
	if (_data[_i] == ']')
		_level++;
	else if (_data[_i] == '>' && _level >= 2) {
		self->_level++;
	else if (self->_data[self->_i] == '>' && self->_level >= 2) {
		void *pool = objc_autoreleasePoolPush();
		OFString *CDATA;

		appendToBuffer(_buffer, _data + _last, _encoding, _i - _last);
		CDATA = transformString(self, _buffer, 2, false);
		appendToBuffer(self->_buffer, self->_data + self->_last,
		    self->_encoding, self->_i - self->_last);
		CDATA = transformString(self, self->_buffer, 2, false);

		if ([_delegate respondsToSelector:
		if ([self->_delegate respondsToSelector:
		    @selector(parser:foundCDATA:)])
			[_delegate parser: self
			       foundCDATA: CDATA];
			[self->_delegate parser: self
				     foundCDATA: CDATA];

		objc_autoreleasePoolPop(pool);

		[_buffer removeAllItems];
		[self->_buffer removeAllItems];

		_last = _i + 1;
		_state = OF_XMLPARSER_OUTSIDE_TAG;
		self->_last = self->_i + 1;
		self->_state = OF_XMLPARSER_OUTSIDE_TAG;
	} else
		_level = 0;
		self->_level = 0;
}

/* Comment */
static void
- (void)of_inCommentOpeningState
inCommentOpeningState(OFXMLParser *self)
{
	if (_data[_i] != '-')
	if (self->_data[self->_i] != '-')
		@throw [OFMalformedXMLException exceptionWithParser: self];

	_last = _i + 1;
	_state = OF_XMLPARSER_IN_COMMENT_1;
	_level = 0;
	self->_last = self->_i + 1;
	self->_state = OF_XMLPARSER_IN_COMMENT_1;
	self->_level = 0;
}

static void
- (void)of_inCommentState1
inCommentState1(OFXMLParser *self)
{
	if (_data[_i] == '-')
		_level++;
	if (self->_data[self->_i] == '-')
		self->_level++;
	else
		_level = 0;
		self->_level = 0;

	if (_level == 2)
		_state = OF_XMLPARSER_IN_COMMENT_2;
	if (self->_level == 2)
		self->_state = OF_XMLPARSER_IN_COMMENT_2;
}

static void
- (void)of_inCommentState2
inCommentState2(OFXMLParser *self)
{
	void *pool;
	OFString *comment;

	if (_data[_i] != '>')
	if (self->_data[self->_i] != '>')
		@throw [OFMalformedXMLException exceptionWithParser: self];

	pool = objc_autoreleasePoolPush();

	appendToBuffer(_buffer, _data + _last, _encoding, _i - _last);
	comment = transformString(self, _buffer, 2, false);
	appendToBuffer(self->_buffer, self->_data + self->_last,
	    self->_encoding, self->_i - self->_last);
	comment = transformString(self, self->_buffer, 2, false);

	if ([self->_delegate respondsToSelector:
	if ([_delegate respondsToSelector: @selector(parser:foundComment:)])
		[_delegate parser: self
		     foundComment: comment];
	    @selector(parser:foundComment:)])
		[self->_delegate parser: self
			   foundComment: comment];

	objc_autoreleasePoolPop(pool);

	[_buffer removeAllItems];
	[self->_buffer removeAllItems];

	_last = _i + 1;
	_state = OF_XMLPARSER_OUTSIDE_TAG;
	self->_last = self->_i + 1;
	self->_state = OF_XMLPARSER_OUTSIDE_TAG;
}

/* In <!DOCTYPE ...> */
static void
- (void)of_inDOCTYPEState
inDOCTYPEState(OFXMLParser *self)
{
	if ((_level < 6 && _data[_i] != "OCTYPE"[_level]) ||
	    (_level == 6 && _data[_i] != ' ' && _data[_i] != '\t' &&
	    _data[_i] != '\n' && _data[_i] != '\r'))
	if ((self->_level < 6 &&
	    self->_data[self->_i] != "OCTYPE"[self->_level]) ||
	    (self->_level == 6 && self->_data[self->_i] != ' ' &&
	    self->_data[self->_i] != '\t' && self->_data[self->_i] != '\n' &&
	    self->_data[self->_i] != '\r'))
		@throw [OFMalformedXMLException exceptionWithParser: self];

	_level++;
	self->_level++;

	if (_level > 6 && _data[_i] == '>')
		_state = OF_XMLPARSER_OUTSIDE_TAG;
	if (self->_level > 6 && self->_data[self->_i] == '>')
		self->_state = OF_XMLPARSER_OUTSIDE_TAG;

	_last = _i + 1;
	self->_last = self->_i + 1;
}

- (size_t)lineNumber
{
	return _lineNumber;
}

Modified src/OFZIPArchive.m from [bebc27a315] to [6d9893fc0c].

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
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







+







+















+













+








/*
 * FIXME: Current limitations:
 *  - Split archives are not supported.
 *  - Encrypted files cannot be read.
 */

OF_DIRECT_MEMBERS
@interface OFZIPArchive ()
- (void)of_readZIPInfo;
- (void)of_readEntries;
- (void)of_closeLastReturnedStream;
- (void)of_writeCentralDirectory;
@end

OF_DIRECT_MEMBERS
@interface OFZIPArchiveLocalFileHeader: OFObject
{
@public
	uint16_t _minVersionNeeded, _generalPurposeBitFlag, _compressionMethod;
	uint16_t _lastModifiedFileTime, _lastModifiedFileDate;
	uint32_t _CRC32;
	uint64_t _compressedSize, _uncompressedSize;
	OFString *_fileName;
	OFData *_extraField;
}

- (instancetype)initWithStream: (OFStream *)stream;
- (bool)matchesEntry: (OFZIPArchiveEntry *)entry;
@end

OF_DIRECT_MEMBERS
@interface OFZIPArchiveFileReadStream: OFStream
{
	OFStream *_stream, *_decompressedStream;
	OFZIPArchiveEntry *_entry;
	uint64_t _toRead;
	uint32_t _CRC32;
	bool _atEndOfStream;
}

- (instancetype)of_initWithStream: (OFStream *)stream
			    entry: (OFZIPArchiveEntry *)entry;
@end

OF_DIRECT_MEMBERS
@interface OFZIPArchiveFileWriteStream: OFStream
{
	OFStream *_stream;
	uint32_t _CRC32;
@public
	int64_t _bytesWritten;
	OFMutableZIPArchiveEntry *_entry;

Modified src/OFZIPArchiveEntry+Private.h from [4c3ba1613a] to [19e5b08dac].

20
21
22
23
24
25
26
27
28



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


27
28
29
30
31
32
33
34
35
36
37







-
-
+
+
+








OF_ASSUME_NONNULL_BEGIN

@interface OFZIPArchiveEntry ()
@property (readonly, nonatomic)
    uint16_t of_lastModifiedFileTime, of_lastModifiedFileDate;
@property (readonly, nonatomic) int64_t of_localFileHeaderOffset;

- (instancetype)of_initWithStream: (OFStream *)stream OF_METHOD_FAMILY(init);
- (uint64_t)of_writeToStream: (OFStream *)stream;
- (instancetype)of_initWithStream: (OFStream *)stream
    OF_METHOD_FAMILY(init) OF_DIRECT;
- (uint64_t)of_writeToStream: (OFStream *)stream OF_DIRECT;
@end

@interface OFMutableZIPArchiveEntry ()
@property (readwrite, nonatomic, setter=of_setLocalFileHeaderOffset:)
    int64_t of_localFileHeaderOffset;
@end

OF_ASSUME_NONNULL_END

Modified src/ObjFW.h from [da93ca7656] to [117174bdb9].

66
67
68
69
70
71
72


73
74
75
76
77
78
79
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81







+
+







#ifdef OF_HAVE_FILES
# import "OFFile.h"
# import "OFINIFile.h"
# import "OFSettings.h"
#endif
#ifdef OF_HAVE_SOCKETS
# import "OFStreamSocket.h"
# import "OFDatagramSocket.h"
# import "OFSequencedPacketSocket.h"
# import "OFTCPSocket.h"
# import "OFUDPSocket.h"
# import "OFTLSSocket.h"
# import "OFKernelEventObserver.h"
# import "OFDNSQuery.h"
# import "OFDNSResourceRecord.h"
# import "OFDNSResponse.h"
259
260
261
262
263
264
265

266
267
268
269
270
271
272
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275







+







#endif

#import "OFLocking.h"
#import "OFThread.h"
#import "once.h"
#ifdef OF_HAVE_THREADS
# import "thread.h"
# import "tlskey.h"
# import "mutex.h"
# import "condition.h"
# import "OFThreadPool.h"
# import "OFMutex.h"
# import "OFRecursiveMutex.h"
# import "OFCondition.h"
#endif

Modified src/forwarding/apple-forwarding-i386.S from [b4b70f083a] to [288bef5c12].

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
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







+
+




-
+



-
-
+
+






-
-
+
+

-
-
+
+




-
-
+
+


-
-
-
+
+
+
+
+


-
+


-
-
-
-
-
-
+
+
+
+
+
+
+
+


-
+

-
+


-
+

-
-
-
+
+
+




-
-
-
+
+
+




-
-
+
+

-
-
+
+




-
-
+
+


-
-
-
+
+
+
+
+


-
+


-
-
-
-
-
-
+
+
+
+
+
+
+
+


-
+

-
+


-
+

-
-
-
+
+
+




-
-
-
+
+
+




-
+

 * 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"

.intel_syntax noprefix

.globl _of_forward
.globl _of_forward_stret

.section __TEXT, __cstring, cstring_literals
str_forwardingTargetForSelector_:
Lstr_forwardingTargetForSelector_:
	.asciz "forwardingTargetForSelector:"

.section __OBJC, __message_refs, literal_pointers, no_dead_strip
sel_forwardingTargetForSelector_:
	.long str_forwardingTargetForSelector_
Lsel_forwardingTargetForSelector_:
	.long Lstr_forwardingTargetForSelector_

.section __OBJC, __image_info
	.long 0, 0

.section __TEXT, __text, regular, pure_instructions
_of_forward:
	pushl	%ebp
	movl	%esp, %ebp
	push	ebp
	mov	ebp, esp

	pushl	%ebx
	subl	$20, %esp
	push	ebx
	sub	esp, 20

	call	get_eip
0:

	movl	8(%ebp), %eax
	movl	%eax, (%esp)
	mov	eax, [ebp+8]
	mov	[esp], eax
	call	_object_getClass

	movl	%eax, (%esp)
	movl	sel_forwardingTargetForSelector_-0b(%ebx), %eax
	movl	%eax, 4(%esp)
	mov	[esp], eax
	.att_syntax	/* Next line is broken in Intel syntax */
	movl	Lsel_forwardingTargetForSelector_-0b(%ebx), %eax
	.intel_syntax noprefix
	mov	[esp+4], eax
	call	_class_respondsToSelector

	testl	%eax, %eax
	test	eax, eax
	jz	0f

	movl	8(%ebp), %eax
	movl	%eax, (%esp)
	movl	sel_forwardingTargetForSelector_-0b(%ebx), %eax
	movl	%eax, 4(%esp)
	movl	12(%ebp), %eax
	movl	%eax, 8(%esp)
	mov	eax, [ebp+8]
	mov	[esp], eax
	.att_syntax	/* Next line is broken in Intel syntax */
	movl	Lsel_forwardingTargetForSelector_-0b(%ebx), %eax
	.intel_syntax noprefix
	mov	[esp+4], eax
	mov	eax, [ebp+12]
	mov	[esp+8], eax
	call	_objc_msgSend

	testl	%eax, %eax
	test	eax, eax
	jz	0f
	cmpl	8(%ebp), %eax
	cmp	eax, [ebp+8]
	je	0f

	movl	%eax, 8(%ebp)
	mov	[ebp+8], eax

	addl	$20, %esp
	popl	%ebx
	popl	%ebp
	add	esp, 20
	pop	ebx
	pop	ebp

	jmp	_objc_msgSend

0:
	addl	$20, %esp
	popl	%ebx
	popl	%ebp
	add	esp, 20
	pop	ebx
	pop	ebp

	jmp	_of_method_not_found

_of_forward_stret:
	pushl	%ebp
	movl	%esp, %ebp
	push	ebp
	mov	ebp, esp

	pushl	%ebx
	subl	$20, %esp
	push	ebx
	sub	esp, 20

	call	get_eip
0:

	movl	12(%ebp), %eax
	movl	%eax, (%esp)
	mov	eax, [ebp+12]
	mov	[esp], eax
	call	_object_getClass

	movl	%eax, (%esp)
	movl	sel_forwardingTargetForSelector_-0b(%ebx), %eax
	movl	%eax, 4(%esp)
	mov	[esp], eax
	.att_syntax	/* Next line is broken in Intel syntax */
	movl	Lsel_forwardingTargetForSelector_-0b(%ebx), %eax
	.intel_syntax noprefix
	mov	[esp+4], eax
	call	_class_respondsToSelector

	testl	%eax, %eax
	test	eax, eax
	jz	0f

	movl	12(%ebp), %eax
	movl	%eax, (%esp)
	movl	sel_forwardingTargetForSelector_-0b(%ebx), %eax
	movl	%eax, 4(%esp)
	movl	16(%ebp), %eax
	movl	%eax, 8(%esp)
	mov	eax, [ebp+12]
	mov	[esp], eax
	.att_syntax	/* Next line is broken in Intel syntax */
	movl	Lsel_forwardingTargetForSelector_-0b(%ebx), %eax
	.intel_syntax noprefix
	mov	[esp+4], eax
	mov	eax, [ebp+16]
	mov	[esp+8], eax
	call	_objc_msgSend

	testl	%eax, %eax
	test	eax, eax
	jz	0f
	cmpl	12(%ebp), %eax
	cmp	eax, [ebp+12]
	je	0f

	movl	%eax, 12(%ebp)
	mov	[ebp+12], eax

	addl	$20, %esp
	popl	%ebx
	popl	%ebp
	add	esp, 20
	pop	ebx
	pop	ebp

	jmp	_objc_msgSend_stret

0:
	addl	$20, %esp
	popl	%ebx
	popl	%ebp
	add	esp, 20
	pop	ebx
	pop	ebp

	jmp	_of_method_not_found_stret

get_eip:
	movl	(%esp), %ebx
	mov	ebx, [esp]
	ret

Modified src/forwarding/apple-forwarding-x86_64.S from [b46de1999b] to [5b8fcf7945].

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
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







+
+
















-
-
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
+
+


-
+


-
-
-
+
+
+


-
+

-
+


-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+




-
-
+
+

-
-
+
+




-
-
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+


-
-
+
+

-
+


-
-
-
+
+
+


-
+

-
+


-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+




-
-
-
+
+
+

-
-
+
+


 * 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"

.intel_syntax noprefix

.globl _of_forward
.globl _of_forward_stret

.section __TEXT, __objc_methname, cstring_literals
str_forwardingTargetForSelector_:
	.asciz "forwardingTargetForSelector:"

.section __DATA, __objc_selrefs, literal_pointers, no_dead_strip
sel_forwardingTargetForSelector_:
	.quad str_forwardingTargetForSelector_

.section __DATA, __objc_imageinfo, regular, no_dead_strip
	.long 0, 0

.section __TEXT, __text, regular, pure_instructions
_of_forward:
	pushq	%rbp
	movq	%rsp, %rbp
	push	rbp
	mov	rbp, rsp

	/* Save all arguments */
	subq	$0xC0, %rsp	/* 16-byte alignment */
	movq	%rax, -0x8(%rbp)
	movq	%rdi, -0x10(%rbp)
	movq	%rsi, -0x18(%rbp)
	movq	%rdx, -0x20(%rbp)
	movq	%rcx, -0x28(%rbp)
	movq	%r8, -0x30(%rbp)
	movq	%r9, -0x38(%rbp)
	movaps	%xmm0, -0x50(%rbp)
	movaps	%xmm1, -0x60(%rbp)
	movaps	%xmm2, -0x70(%rbp)
	movaps	%xmm3, -0x80(%rbp)
	movaps	%xmm4, -0x90(%rbp)
	movaps	%xmm5, -0xA0(%rbp)
	movaps	%xmm6, -0xB0(%rbp)
	movaps	%xmm7, -0xC0(%rbp)
	sub	rsp, 0xC0	/* 16-byte alignment */
	mov	[rbp-0x08], rax
	mov	[rbp-0x10], rdi
	mov	[rbp-0x18], rsi
	mov	[rbp-0x20], rdx
	mov	[rbp-0x28], rcx
	mov	[rbp-0x30], r8
	mov	[rbp-0x38], r9
	movaps	[rbp-0x50], xmm0
	movaps	[rbp-0x60], xmm1
	movaps	[rbp-0x70], xmm2
	movaps	[rbp-0x80], xmm3
	movaps	[rbp-0x90], xmm4
	movaps	[rbp-0xA0], xmm5
	movaps	[rbp-0xB0], xmm6
	movaps	[rbp-0xC0], xmm7

	call	_object_getClass

	movq	%rax, %rdi
	movq	sel_forwardingTargetForSelector_(%rip), %rsi
	mov	rdi, rax
	mov	rsi, [rip+sel_forwardingTargetForSelector_]
	call	_class_respondsToSelector

	testq	%rax, %rax
	test	rax, rax
	jz	0f

	movq	-0x10(%rbp), %rdi
	movq	sel_forwardingTargetForSelector_(%rip), %rsi
	movq	-0x18(%rbp), %rdx
	mov	rdi, [rbp-0x10]
	mov	rsi, [rip+sel_forwardingTargetForSelector_]
	mov	rdx, [rbp-0x18]
	call	_objc_msgSend

	testq	%rax, %rax
	test	rax, rax
	jz	0f
	cmpq	-0x10(%rbp), %rax
	cmp	rax, [rbp-0x10]
	je	0f

	movq	%rax, %rdi
	mov	rdi, rax

	/* Restore all arguments, except %rdi */
	movaps	-0xC0(%rbp), %xmm7
	movaps	-0xB0(%rbp), %xmm6
	movaps	-0xA0(%rbp), %xmm5
	movaps	-0x90(%rbp), %xmm4
	movaps	-0x80(%rbp), %xmm3
	movaps	-0x70(%rbp), %xmm2
	movaps	-0x60(%rbp), %xmm1
	movaps	-0x50(%rbp), %xmm0
	movq	-0x38(%rbp), %r9
	movq	-0x30(%rbp), %r8
	movq	-0x28(%rbp), %rcx
	movq	-0x20(%rbp), %rdx
	movq	-0x18(%rbp), %rsi
	movq	-0x8(%rbp), %rax
	movaps	xmm7, [rbp-0xC0]
	movaps	xmm6, [rbp-0xB0]
	movaps	xmm5, [rbp-0xA0]
	movaps	xmm4, [rbp-0x90]
	movaps	xmm3, [rbp-0x80]
	movaps	xmm2, [rbp-0x70]
	movaps	xmm1, [rbp-0x60]
	movaps	xmm0, [rbp-0x50]
	mov	r9,   [rbp-0x38]
	mov	r8,   [rbp-0x30]
	mov	rcx,  [rbp-0x28]
	mov	rdx,  [rbp-0x20]
	mov	rsi,  [rbp-0x18]
	mov	rax,  [rbp-0x08]

	movq	%rbp, %rsp
	popq	%rbp
	mov	rsp, rbp
	pop	rbp

	jmp	_objc_msgSend

0:
	movq	-0x10(%rbp), %rdi
	movq	-0x18(%rbp), %rsi
	mov	rdi, [rbp-0x10]
	mov	rsi, [rbp-0x18]

	movq	%rbp, %rsp
	popq	%rbp
	mov	rsp, rbp
	pop	rbp

	jmp	_of_method_not_found

_of_forward_stret:
	pushq	%rbp
	movq	%rsp, %rbp
	push	rbp
	mov	rbp, rsp

	/* Save all arguments */
	subq	$0xC0, %rsp	/* 16-byte alignment */
	movq	%rax, -0x8(%rbp)
	movq	%rdi, -0x10(%rbp)
	movq	%rsi, -0x18(%rbp)
	movq	%rdx, -0x20(%rbp)
	movq	%rcx, -0x28(%rbp)
	movq	%r8, -0x30(%rbp)
	movq	%r9, -0x38(%rbp)
	movaps	%xmm0, -0x50(%rbp)
	movaps	%xmm1, -0x60(%rbp)
	movaps	%xmm2, -0x70(%rbp)
	movaps	%xmm3, -0x80(%rbp)
	movaps	%xmm4, -0x90(%rbp)
	movaps	%xmm5, -0xA0(%rbp)
	movaps	%xmm6, -0xB0(%rbp)
	movaps	%xmm7, -0xC0(%rbp)
	sub	rsp, 0xC0	/* 16-byte alignment */
	mov	[rbp-0x08], rax
	mov	[rbp-0x10], rdi
	mov	[rbp-0x18], rsi
	mov	[rbp-0x20], rdx
	mov	[rbp-0x28], rcx
	mov	[rbp-0x30], r8
	mov	[rbp-0x38], r9
	movaps	[rbp-0x50], xmm0
	movaps	[rbp-0x60], xmm1
	movaps	[rbp-0x70], xmm2
	movaps	[rbp-0x80], xmm3
	movaps	[rbp-0x90], xmm4
	movaps	[rbp-0xA0], xmm5
	movaps	[rbp-0xB0], xmm6
	movaps	[rbp-0xC0], xmm7

	movq	%rsi, %rdi
	mov	rdi, rsi
	call	_object_getClass

	movq	%rax, %rdi
	movq	sel_forwardingTargetForSelector_(%rip), %rsi
	mov	rdi, rax
	mov	rsi, [rip+sel_forwardingTargetForSelector_]
	call	_class_respondsToSelector
	testq	%rax, %rax
	test	rax, rax
	jz	0f

	movq	-0x18(%rbp), %rdi
	movq	sel_forwardingTargetForSelector_(%rip), %rsi
	movq	-0x20(%rbp), %rdx
	mov	rdi, [rbp-0x18]
	mov	rsi, [rip+sel_forwardingTargetForSelector_]
	mov	rdx, [rbp-0x20]
	call	_objc_msgSend

	testq	%rax, %rax
	test	rax, rax
	jz	0f
	cmpq	-0x18(%rbp), %rax
	cmp	rax, [rbp-0x18]
	je	0f

	movq	%rax, %rsi
	mov	rsi, rax

	/* Restore all arguments, except %rsi */
	movaps	-0xC0(%rbp), %xmm7
	movaps	-0xB0(%rbp), %xmm6
	movaps	-0xA0(%rbp), %xmm5
	movaps	-0x90(%rbp), %xmm4
	movaps	-0x80(%rbp), %xmm3
	movaps	-0x70(%rbp), %xmm2
	movaps	-0x60(%rbp), %xmm1
	movaps	-0x50(%rbp), %xmm0
	movq	-0x38(%rbp), %r9
	movq	-0x30(%rbp), %r8
	movq	-0x28(%rbp), %rcx
	movq	-0x20(%rbp), %rdx
	movq	-0x10(%rbp), %rdi
	movq	-0x8(%rbp), %rax
	movaps	xmm7, [rbp-0xC0]
	movaps	xmm6, [rbp-0xB0]
	movaps	xmm5, [rbp-0xA0]
	movaps	xmm4, [rbp-0x90]
	movaps	xmm3, [rbp-0x80]
	movaps	xmm2, [rbp-0x70]
	movaps	xmm1, [rbp-0x60]
	movaps	xmm0, [rbp-0x50]
	mov	r9,   [rbp-0x38]
	mov	r8,   [rbp-0x30]
	mov	rcx,  [rbp-0x28]
	mov	rdx,  [rbp-0x20]
	mov	rdi,  [rbp-0x10]
	mov	rax,  [rbp-0x08]

	movq	%rbp, %rsp
	popq	%rbp
	mov	rsp, rbp
	pop	rbp

	jmp	_objc_msgSend_stret

0:
	movq	-0x10(%rbp), %rdi
	movq	-0x18(%rbp), %rsi
	movq	-0x20(%rbp), %rdx
	mov	rdi, [rbp-0x10]
	mov	rsi, [rbp-0x18]
	mov	rdx, [rbp-0x20]

	movq	%rbp, %rsp
	popq	%rbp
	mov	rsp, rbp
	pop	rbp

	jmp	_of_method_not_found_stret

Added src/forwarding/forwarding-sparc-elf.S version [9eae73a539].
















































































































































































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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019, 2020
 *   Jonathan Schleifer <js@nil.im>
 *
 * 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"

#include "platform.h"

.globl of_forward
.globl of_forward_stret

.section .text
of_forward:
	save	%sp, -96, %sp

	sethi	%hi(_GLOBAL_OFFSET_TABLE_ - 4), %l7
	call	add_pc
	 add	%l7, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %l7

	mov	%i0, %o0
	call	object_getClass
	 nop

	sethi	%hi(sel_forwardingTargetForSelector_), %o1
	or	%o1, %lo(sel_forwardingTargetForSelector_), %o1
	ld	[%l7 + %o1], %o1
	call	class_respondsToSelector
	 nop

	cmp	%o0, 0
	be	0f

	 mov	%i0, %o0
	sethi	%hi(sel_forwardingTargetForSelector_), %o1
	or	%o1, %lo(sel_forwardingTargetForSelector_), %o1
	ld	[%l7 + %o1], %o1
	call	objc_msg_lookup
	 nop
	mov	%o0, %l0

	mov	%i0, %o0
	sethi	%hi(sel_forwardingTargetForSelector_), %o1
	or	%o1, %lo(sel_forwardingTargetForSelector_), %o1
	ld	[%l7 + %o1], %o1
	jmpl	%l0, %o7
	 mov	%i1, %o2

	cmp	%o0, 0
	be	0f
	 cmp	%o0, %i0
	be	0f

	 mov	%o0, %i0
	call	objc_msg_lookup
	 mov	%i1, %o1

	jmpl	%o0, %g0
	 restore

0:
	call	of_method_not_found
	 restore
.type of_forward, %function
.size of_forward, .-of_forward

of_forward_stret:
	save	%sp, -96, %sp

	sethi	%hi(_GLOBAL_OFFSET_TABLE_ - 4), %l7
	call	add_pc
	 add	%l7, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %l7

	mov	%i1, %o0
	call	object_getClass
	 nop

	sethi	%hi(sel_forwardingTargetForSelector_), %o1
	or	%o1, %lo(sel_forwardingTargetForSelector_), %o1
	ld	[%l7 + %o1], %o1
	call	class_respondsToSelector
	 nop

	cmp	%o0, 0
	be	0f

	 mov	%i1, %o0
	sethi	%hi(sel_forwardingTargetForSelector_), %o1
	or	%o1, %lo(sel_forwardingTargetForSelector_), %o1
	ld	[%l7 + %o1], %o1
	call	objc_msg_lookup
	 nop
	mov	%o0, %l0

	mov	%i1, %o0
	sethi	%hi(sel_forwardingTargetForSelector_), %o1
	or	%o1, %lo(sel_forwardingTargetForSelector_), %o1
	ld	[%l7 + %o1], %o1
	jmpl	%l0, %o7
	 mov	%i2, %o2

	cmp	%o0, 0
	be	0f
	 cmp	%o0, %i1
	be	0f

	 mov	%o0, %i1
	call	objc_msg_lookup
	 mov	%i2, %o1

	jmpl	%o0, %g0
	 restore

0:
	call	of_method_not_found_stret
	 restore
.type of_forward_stret, %function
.size of_forward_stret, .-of_forward_stret

init:
	save	%sp, -96, %sp

	sethi	%hi(_GLOBAL_OFFSET_TABLE_ - 4), %l7
	call	add_pc
	 add	%l7, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %l7

	sethi	%hi(module), %i0
	or	%i0, %lo(module), %i0
	ld	[%l7 + %i0], %i0

	call	__objc_exec_class
	 restore

add_pc:
	jmp	%o7 + 8
	 add	%l7, %o7, %l7

#ifdef OF_SOLARIS
.section .init_array, "aw"
#else
.section .ctors, "aw", %progbits
#endif
	.word init

.section .rodata
str_forwardingTargetForSelector_:
	.asciz "forwardingTargetForSelector:"

.section .data
sel_forwardingTargetForSelector_:
	.word str_forwardingTargetForSelector_, 0
	.word 0, 0
symtab:
	.word 0, sel_forwardingTargetForSelector_
	.half 0, 0
	.word 0
	.word 0
module:
	.word 8, 16, 0, symtab

#ifdef OF_LINUX
.section .note.GNU-stack, "", %progbits
#endif

Modified src/forwarding/forwarding-sparc64-elf.S from [bea41e7809] to [af08d696f6].

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
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







-
+
-
-

-
+














-
+
-
-
-
+

-

-
+








	sethi	%hi(sel_forwardingTargetForSelector_), %o1
	or	%o1, %lo(sel_forwardingTargetForSelector_), %o1
	ldx	[%l7 + %o1], %o1
	call	class_respondsToSelector
	 nop

	cmp	%o0, 0
	brz,pn	%o0, 0f
	be,pn	%xcc, 0f
	 nop

	mov	%i0, %o0
	 mov	%i0, %o0
	sethi	%hi(sel_forwardingTargetForSelector_), %o1
	or	%o1, %lo(sel_forwardingTargetForSelector_), %o1
	ldx	[%l7 + %o1], %o1
	call	objc_msg_lookup
	 nop
	mov	%o0, %l0

	mov	%i0, %o0
	sethi	%hi(sel_forwardingTargetForSelector_), %o1
	or	%o1, %lo(sel_forwardingTargetForSelector_), %o1
	ldx	[%l7 + %o1], %o1
	jmpl	%l0, %o7
	 mov	%i1, %o2

	cmp	%o0, 0
	brz,pn	%o0, 0f
	be,pn	%xcc, 0f
	 nop
	cmp	%o0, %i0
	 cmp	%o0, %i0
	be,pn	%xcc, 0f
	 nop

	mov	%o0, %i0
	 mov	%o0, %i0
	call	objc_msg_lookup
	 mov	%i1, %o1

	/*
	 * Restore all floating point registers as they can be used for
	 * parameter passing.
	 */
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
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







-
+
-
-

-
+














-
+
-
-
-
+

-

-
+








	sethi	%hi(sel_forwardingTargetForSelector_), %o1
	or	%o1, %lo(sel_forwardingTargetForSelector_), %o1
	ldx	[%l7 + %o1], %o1
	call	class_respondsToSelector
	 nop

	cmp	%o0, 0
	brz,pn	%o0, 0f
	be,pn	%xcc, 0f
	 nop

	mov	%i1, %o0
	 mov	%i1, %o0
	sethi	%hi(sel_forwardingTargetForSelector_), %o1
	or	%o1, %lo(sel_forwardingTargetForSelector_), %o1
	ldx	[%l7 + %o1], %o1
	call	objc_msg_lookup
	 nop
	mov	%o0, %l0

	mov	%i1, %o0
	sethi	%hi(sel_forwardingTargetForSelector_), %o1
	or	%o1, %lo(sel_forwardingTargetForSelector_), %o1
	ldx	[%l7 + %o1], %o1
	jmpl	%l0, %o7
	 mov	%i2, %o2

	cmp	%o0, 0
	brz,pn	%o0, 0f
	be,pn	%xcc, 0f
	 nop
	cmp	%o0, %i1
	 cmp	%o0, %i1
	be,pn	%xcc, 0f
	 nop

	mov	%o0, %i1
	 mov	%o0, %i1
	call	objc_msg_lookup
	 mov	%i2, %o1

	/*
	 * Restore all floating point registers as they can be used for
	 * parameter passing.
	 */

Modified src/forwarding/forwarding-x86-elf.S from [9bcb5fc324] to [294c10a12e].

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
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







+
+





-
-
+
+

-
-
+
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+

-
-
-
+
+
+

-
+




-
-
+
+

-
-
+
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+

-
-
-
+
+
+

-
+




-
-
+
+

-
-
+
+


-
-
+

-
-
-
+
+
+
-

-
-
-
+
+
+



-
+







 * file.
 */

#include "config.h"

#include "platform.h"

.intel_syntax noprefix

.globl of_forward
.globl of_forward_stret

.section .text
of_forward:
	pushl	%ebp
	movl	%esp, %ebp
	push	ebp
	mov	ebp, esp

	pushl	%ebx
	subl	$20, %esp
	push	ebx
	sub	esp, 20

	call	get_eip
	add	ebx, offset _GLOBAL_OFFSET_TABLE_

	mov	eax, [ebp+8]
	mov	[esp], eax
	call	object_getClass@PLT

	mov	[esp], eax
	lea	eax, [ebx+sel_forwardingTargetForSelector_@GOTOFF]
	mov	[esp+4], eax
	call	class_respondsToSelector@PLT

	test	eax, eax
	jz	short 0f

	mov	eax, [ebp+8]
	mov	[esp], eax
	lea	eax, [ebx+sel_forwardingTargetForSelector_@GOTOFF]
	mov	[esp+4], eax
	call	objc_msg_lookup@PLT

	mov	edx, [ebp+8]
	mov	[esp], edx
	lea	edx, [ebx+sel_forwardingTargetForSelector_@GOTOFF]
	mov	[esp+4], edx
	mov	edx, [ebp+12]
	mov	[esp+8], edx
	call	eax

	test	eax, eax
	jz	short 0f
	cmp	eax, [ebp+8]
	je	short 0f

	mov	[ebp+8], eax
	mov	[esp], eax
	mov	eax, [ebp+12]
	mov	[esp+4], eax
	call	objc_msg_lookup@PLT

	add	esp, 20
	pop	ebx
	pop	ebp

	jmp	eax

0:
	addl	$_GLOBAL_OFFSET_TABLE_, %ebx

	movl	8(%ebp), %eax
	movl	%eax, (%esp)
	movl	object_getClass@GOT(%ebx), %eax
	call	*%eax

	movl	%eax, (%esp)
	leal	sel_forwardingTargetForSelector_@GOTOFF(%ebx), %eax
	movl	%eax, 4(%esp)
	movl	class_respondsToSelector@GOT(%ebx), %eax
	call	*%eax

	testl	%eax, %eax
	jz	1f

	movl	8(%ebp), %eax
	movl	%eax, (%esp)
	leal	sel_forwardingTargetForSelector_@GOTOFF(%ebx), %eax
	movl	%eax, 4(%esp)
	movl	objc_msg_lookup@GOT(%ebx), %eax
	call	*%eax

	movl	8(%ebp), %edx
	movl	%edx, (%esp)
	leal	sel_forwardingTargetForSelector_@GOTOFF(%ebx), %edx
	movl	%edx, 4(%esp)
	movl	12(%ebp), %edx
	movl	%edx, 8(%esp)
	call	*%eax

	testl	%eax, %eax
	jz	1f
	cmpl	8(%ebp), %eax
	je	1f

	movl	%eax, 8(%ebp)
	movl	%eax, (%esp)
	movl	12(%ebp), %eax
	movl	%eax, 4(%esp)
	movl	objc_msg_lookup@GOT(%ebx), %eax
	call	*%eax

	addl	$20, %esp
	popl	%ebx
	popl	%ebp

	jmp	*%eax

1:
	movl	of_method_not_found@GOT(%ebx), %eax
	lea	eax, [ebx+of_method_not_found@GOTOFF]

	addl	$20, %esp
	popl	%ebx
	popl	%ebp
	add	esp, 20
	pop	ebx
	pop	ebp

	jmp	*%eax
	jmp	eax
.type of_forward, %function
.size of_forward, .-of_forward

of_forward_stret:
	pushl	%ebp
	movl	%esp, %ebp
	push	ebp
	mov	ebp, esp

	pushl	%ebx
	subl	$20, %esp
	push	ebx
	sub	esp, 20

	call	get_eip
	add	ebx, offset _GLOBAL_OFFSET_TABLE_

	mov	eax, [ebp+12]
	mov	[esp], eax
	call	object_getClass@PLT

	mov	[esp], eax
	lea	eax, [ebx+sel_forwardingTargetForSelector_@GOTOFF]
	mov	[esp+4], eax
	call	class_respondsToSelector@PLT

	test	eax, eax
	jz	short 0f

	mov	eax, [ebp+12]
	mov	[esp], eax
	lea	eax, [ebx+sel_forwardingTargetForSelector_@GOTOFF]
	mov	[esp+4], eax
	call	objc_msg_lookup@PLT

	mov	edx, [ebp+12]
	mov	[esp], edx
	lea	edx, [ebx+sel_forwardingTargetForSelector_@GOTOFF]
	mov	[esp+4], edx
	mov	edx, [ebp+16]
	mov	[esp+8], edx
	call	eax

	test	eax, eax
	jz	short 0f
	cmp	eax, [ebp+12]
	je	short 0f

	mov	[ebp+12], eax
	mov	[esp], eax
	mov	eax, [ebp+16]
	mov	[esp+4], eax
	call	objc_msg_lookup_stret@PLT

	add	esp, 20
	pop	ebx
	pop	ebp

	jmp	eax

0:
	addl	$_GLOBAL_OFFSET_TABLE_, %ebx

	movl	12(%ebp), %eax
	movl	%eax, (%esp)
	movl	object_getClass@GOT(%ebx), %eax
	call	*%eax

	movl	%eax, (%esp)
	leal	sel_forwardingTargetForSelector_@GOTOFF(%ebx), %eax
	movl	%eax, 4(%esp)
	movl	class_respondsToSelector@GOT(%ebx), %eax
	call	*%eax

	testl	%eax, %eax
	jz	1f

	movl	12(%ebp), %eax
	movl	%eax, (%esp)
	leal	sel_forwardingTargetForSelector_@GOTOFF(%ebx), %eax
	movl	%eax, 4(%esp)
	movl	objc_msg_lookup@GOT(%ebx), %eax
	call	*%eax

	movl	12(%ebp), %edx
	movl	%edx, (%esp)
	leal	sel_forwardingTargetForSelector_@GOTOFF(%ebx), %edx
	movl	%edx, 4(%esp)
	movl	16(%ebp), %edx
	movl	%edx, 8(%esp)
	call	*%eax

	testl	%eax, %eax
	jz	1f
	cmpl	12(%ebp), %eax
	je	1f

	movl	%eax, 12(%ebp)
	movl	%eax, (%esp)
	movl	16(%ebp), %eax
	movl	%eax, 4(%esp)
	movl	objc_msg_lookup_stret@GOT(%ebx), %eax
	call	*%eax

	addl	$20, %esp
	popl	%ebx
	popl	%ebp

	jmp	*%eax

1:
	movl	of_method_not_found_stret@GOT(%ebx), %eax
	lea	eax, [ebx+of_method_not_found_stret@GOTOFF]

	addl	$20, %esp
	popl	%ebx
	popl	%ebp
	add	esp, 20
	pop	ebx
	pop	ebp

	jmp	*%eax
	jmp	eax
.type of_forward_stret, %function
.size of_forward_stret, .-of_forward_stret

init:
	pushl	%ebp
	movl	%esp, %ebp
	push	ebp
	mov	ebp, esp

	pushl	%ebx
	subl	$4, %esp
	push	ebx
	sub	esp, 4

	call	get_eip
0:
	add	$_GLOBAL_OFFSET_TABLE_, %ebx
	add	ebx, offset _GLOBAL_OFFSET_TABLE_

	leal	module@GOTOFF(%ebx), %eax
	movl	%eax, (%esp)
	movl	__objc_exec_class@GOT(%ebx), %eax
	lea	eax, [ebx+module@GOTOFF]
	mov	[esp], eax
	call	__objc_exec_class@PLT
	call	*%eax

	addl	$4, %esp
	popl	%ebx
	popl	%ebp
	add	esp, 4
	pop	ebx
	pop	ebp
	ret

get_eip:
	movl	(%esp), %ebx
	mov	ebx, [esp]
	ret

#ifdef OF_SOLARIS
.section .init_array, "aw"
#else
.section .ctors, "aw", %progbits
#endif

Modified src/forwarding/forwarding-x86-win32.S from [2062a9ecd0] to [38023e4835].

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
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







+
+





-
-
+
+
+
+
+

+
+
+
-
-
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+

-
-
-
-
+
-
-
-
-
-
-


-
-
+
+
+
+
+

+
+
+
-
-
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+

-
-
-
-
+
-
-
-
-
-
-


-
-
+
+

-
-
+
+

-
-
-
-
-
+
+
+
-

-
-
-
+
+
+
-
-
-
-







 * 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"

.intel_syntax noprefix

.globl _of_forward
.globl _of_forward_stret

.section .text
_of_forward:
	pushl	%ebp
	movl	%esp, %ebp
	push	ebp
	mov	ebp, esp

	push	ebx
	sub	esp, 20

	mov	eax, [ebp+8]
	mov	[esp], eax
	call	_object_getClass
	pushl	%ebx
	subl	$20, %esp

	mov	[esp], eax
	mov	eax, offset sel_forwardingTargetForSelector_
	mov	[esp+4], eax
	call	_class_respondsToSelector

	test	eax, eax
	jz	short 0f

	mov	eax, [ebp+8]
	mov	[esp], eax
	mov	eax, offset sel_forwardingTargetForSelector_
	mov	[esp+4], eax
	call	_objc_msg_lookup

	mov	edx, [ebp+8]
	mov	[esp], edx
	mov	edx, offset sel_forwardingTargetForSelector_
	mov	[esp+4], edx
	mov	edx, [ebp+12]
	mov	[esp+8], edx
	call	get_eip
	call	eax

	test	eax, eax
	jz	short 0f
	cmp	eax, [ebp+8]
	je	short 0f

	mov	[ebp+8], eax
	mov	[esp], eax
	mov	eax, [ebp+12]
	mov	[esp+4], eax
	call	_objc_msg_lookup

	add	esp, 20
	pop	ebx
	pop	ebp

	jmp	eax

0:

	add	esp, 20
	movl	8(%ebp), %eax
	movl	%eax, (%esp)
	leal	_object_getClass-0b(%ebx), %eax
	call	*%eax

	movl	%eax, (%esp)
	leal	sel_forwardingTargetForSelector_-0b(%ebx), %eax
	movl	%eax, 4(%esp)
	leal	_class_respondsToSelector-0b(%ebx), %eax
	call	*%eax

	testl	%eax, %eax
	jz	1f

	movl	8(%ebp), %eax
	movl	%eax, (%esp)
	leal	sel_forwardingTargetForSelector_-0b(%ebx), %eax
	movl	%eax, 4(%esp)
	leal	_objc_msg_lookup-0b(%ebx), %eax
	call	*%eax

	movl	8(%ebp), %edx
	movl	%edx, (%esp)
	leal	sel_forwardingTargetForSelector_-0b(%ebx), %edx
	movl	%edx, 4(%esp)
	movl	12(%ebp), %edx
	movl	%edx, 8(%esp)
	call	*%eax

	testl	%eax, %eax
	jz	1f
	cmpl	8(%ebp), %eax
	je	1f

	movl	%eax, 8(%ebp)
	movl	%eax, (%esp)
	movl	12(%ebp), %eax
	movl	%eax, 4(%esp)
	leal	_objc_msg_lookup-0b(%ebx), %eax
	call	*%eax

	addl	$20, %esp
	popl	%ebx
	popl	%ebp
	pop	ebx
	pop	ebp

	jmp	*%eax

1:
	leal	_of_method_not_found-0b(%ebx), %eax
	jmp	_of_method_not_found

	addl	$20, %esp
	popl	%ebx
	popl	%ebp

	jmp	*%eax

_of_forward_stret:
	pushl	%ebp
	movl	%esp, %ebp
	push	ebp
	mov	ebp, esp

	push	ebx
	sub	esp, 20

	mov	eax, [ebp+12]
	mov	[esp], eax
	call	_object_getClass
	pushl	%ebx
	subl	$20, %esp

	mov	[esp], eax
	mov	eax, offset sel_forwardingTargetForSelector_
	mov	[esp+4], eax
	call	_class_respondsToSelector

	test	eax, eax
	jz	short 0f

	mov	eax, [ebp+12]
	mov	[esp], eax
	mov	eax, offset sel_forwardingTargetForSelector_
	mov	[esp+4], eax
	call	_objc_msg_lookup

	mov	edx, [ebp+12]
	mov	[esp], edx
	mov	edx, offset sel_forwardingTargetForSelector_
	mov	[esp+4], edx
	mov	edx, [ebp+16]
	mov	[esp+8], edx
	call	get_eip
	call	eax

	test	eax, eax
	jz	short 0f
	cmp	eax, [ebp+12]
	je	short 0f

	mov	[ebp+12], eax
	mov	[esp], eax
	mov	eax, [ebp+16]
	mov	[esp+4], eax
	call	_objc_msg_lookup_stret

	add	esp, 20
	pop	ebx
	pop	ebp

	jmp	eax

0:

	add	esp, 20
	movl	12(%ebp), %eax
	movl	%eax, (%esp)
	leal	_object_getClass-0b(%ebx), %eax
	call	*%eax

	movl	%eax, (%esp)
	leal	sel_forwardingTargetForSelector_-0b(%ebx), %eax
	movl	%eax, 4(%esp)
	leal	_class_respondsToSelector-0b(%ebx), %eax
	call	*%eax

	testl	%eax, %eax
	jz	1f

	movl	12(%ebp), %eax
	movl	%eax, (%esp)
	leal	sel_forwardingTargetForSelector_-0b(%ebx), %eax
	movl	%eax, 4(%esp)
	leal	_objc_msg_lookup-0b(%ebx), %eax
	call	*%eax

	movl	12(%ebp), %edx
	movl	%edx, (%esp)
	leal	sel_forwardingTargetForSelector_-0b(%ebx), %edx
	movl	%edx, 4(%esp)
	movl	16(%ebp), %edx
	movl	%edx, 8(%esp)
	call	*%eax

	testl	%eax, %eax
	jz	1f
	cmpl	12(%ebp), %eax
	je	1f

	movl	%eax, 12(%ebp)
	movl	%eax, (%esp)
	movl	16(%ebp), %eax
	movl	%eax, 4(%esp)
	leal	_objc_msg_lookup_stret-0b(%ebx), %eax
	call	*%eax

	addl	$20, %esp
	popl	%ebx
	popl	%ebp
	pop	ebx
	pop	ebp

	jmp	*%eax

1:
	leal	_of_method_not_found_stret-0b(%ebx), %eax
	jmp	_of_method_not_found_stret

	addl	$20, %esp
	popl	%ebx
	popl	%ebp

	jmp	*%eax

init:
	pushl	%ebp
	movl	%esp, %ebp
	push	ebp
	mov	ebp, esp

	pushl	%ebx
	subl	$4, %esp
	push	ebx
	sub	esp, 4

	call	get_eip
0:
	leal	module-0b(%ebx), %eax
	movl	%eax, (%esp)
	leal	___objc_exec_class-0b(%ebx), %eax
	mov	eax, offset module
	mov	[esp], eax
	call	___objc_exec_class
	call	*%eax

	addl	$4, %esp
	popl	%ebx
	popl	%ebp
	add	esp, 4
	pop	ebx
	pop	ebp
	ret

get_eip:
	movl	(%esp), %ebx
	ret

.section .ctors, "aw"
	.long init

.section .rodata
str_forwardingTargetForSelector_:

Modified src/forwarding/forwarding-x86_64-elf.S from [d6c82663f6] to [1d1fc641cf].

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
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







+
+





-
-
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
+
+


-
-
+
+

-
-
+
+


-
-
-
-
+
+
+
+

-
-
-
-
+
+
+
+

-
+

-
-
+
+

-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+

-
+


-
-
+
+

-
-
+
+






-
-
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+


-
-
+
+


-
-
+
+

-
-
+
+


-
-
-
-
+
+
+
+

-
-
-
-
+
+
+
+

-
+

-
-
+
+

-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+

-
+


-
-
-
+
+
+

-
-
+
+






-
+







 * file.
 */

#include "config.h"

#include "platform.h"

.intel_syntax noprefix

.globl of_forward
.globl of_forward_stret

.section .text
of_forward:
	pushq	%rbp
	movq	%rsp, %rbp
	push	rbp
	mov	rbp, rsp

	/* Save all arguments */
	subq	$0xC0, %rsp	/* 16-byte alignment */
	movq	%rax, -0x8(%rbp)
	movq	%rdi, -0x10(%rbp)
	movq	%rsi, -0x18(%rbp)
	movq	%rdx, -0x20(%rbp)
	movq	%rcx, -0x28(%rbp)
	movq	%r8, -0x30(%rbp)
	movq	%r9, -0x38(%rbp)
	movaps	%xmm0, -0x50(%rbp)
	movaps	%xmm1, -0x60(%rbp)
	movaps	%xmm2, -0x70(%rbp)
	movaps	%xmm3, -0x80(%rbp)
	movaps	%xmm4, -0x90(%rbp)
	movaps	%xmm5, -0xA0(%rbp)
	movaps	%xmm6, -0xB0(%rbp)
	movaps	%xmm7, -0xC0(%rbp)
	sub	rsp, 0xC0	/* 16-byte alignment */
	mov	[rbp-0x08], rax
	mov	[rbp-0x10], rdi
	mov	[rbp-0x18], rsi
	mov	[rbp-0x20], rdx
	mov	[rbp-0x28], rcx
	mov	[rbp-0x30], r8
	mov	[rbp-0x38], r9
	movaps	[rbp-0x50], xmm0
	movaps	[rbp-0x60], xmm1
	movaps	[rbp-0x70], xmm2
	movaps	[rbp-0x80], xmm3
	movaps	[rbp-0x90], xmm4
	movaps	[rbp-0xA0], xmm5
	movaps	[rbp-0xB0], xmm6
	movaps	[rbp-0xC0], xmm7

	call	object_getClass@PLT

	movq	%rax, %rdi
	leaq	sel_forwardingTargetForSelector_(%rip), %rsi
	mov	rdi, rax
	lea	rsi, [rip+sel_forwardingTargetForSelector_]
	call	class_respondsToSelector@PLT

	testq	%rax, %rax
	jz	0f
	test	rax, rax
	jz	short 0f

	movq	-0x10(%rbp), %rdi
	leaq	sel_forwardingTargetForSelector_(%rip), %rsi
	mov	rdi, [rbp-0x10]
	lea	rsi, [rip+sel_forwardingTargetForSelector_]
	call	objc_msg_lookup@PLT

	movq	-0x10(%rbp), %rdi
	leaq	sel_forwardingTargetForSelector_(%rip), %rsi
	movq	-0x18(%rbp), %rdx
	call	*%rax
	mov	rdi, [rbp-0x10]
	lea	rsi, [rip+sel_forwardingTargetForSelector_]
	mov	rdx, [rbp-0x18]
	call	rax

	testq	%rax, %rax
	jz	0f
	cmpq	-0x10(%rbp), %rax
	je	0f
	test	rax, rax
	jz	short 0f
	cmp	rax, [rbp-0x10]
	je	short 0f

	movq	%rax, -0x10(%rbp)
	mov	[rbp-0x10], rax

	movq	%rax, %rdi
	movq	-0x18(%rbp), %rsi
	mov	rdi, rax
	mov	rsi, [rbp-0x18]
	call	objc_msg_lookup@PLT
	movq	%rax, %r11
	mov	r11, rax

	/* Restore all arguments */
	movaps	-0xC0(%rbp), %xmm7
	movaps	-0xB0(%rbp), %xmm6
	movaps	-0xA0(%rbp), %xmm5
	movaps	-0x90(%rbp), %xmm4
	movaps	-0x80(%rbp), %xmm3
	movaps	-0x70(%rbp), %xmm2
	movaps	-0x60(%rbp), %xmm1
	movaps	-0x50(%rbp), %xmm0
	movq	-0x38(%rbp), %r9
	movq	-0x30(%rbp), %r8
	movq	-0x28(%rbp), %rcx
	movq	-0x20(%rbp), %rdx
	movq	-0x18(%rbp), %rsi
	movq	-0x10(%rbp), %rdi
	movq	-0x8(%rbp), %rax
	movaps	xmm7, [rbp-0xC0]
	movaps	xmm6, [rbp-0xB0]
	movaps	xmm5, [rbp-0xA0]
	movaps	xmm4, [rbp-0x90]
	movaps	xmm3, [rbp-0x80]
	movaps	xmm2, [rbp-0x70]
	movaps	xmm1, [rbp-0x60]
	movaps	xmm0, [rbp-0x50]
	mov	r9,   [rbp-0x38]
	mov	r8,   [rbp-0x30]
	mov	rcx,  [rbp-0x28]
	mov	rdx,  [rbp-0x20]
	mov	rsi,  [rbp-0x18]
	mov	rdi,  [rbp-0x10]
	mov	rax,  [rbp-0x08]

	movq	%rbp, %rsp
	popq	%rbp
	mov	rsp, rbp
	pop	rbp

	jmpq	*%r11
	jmp	r11

0:
	movq	-0x10(%rbp), %rdi
	movq	-0x18(%rbp), %rsi
	mov	rdi, [rbp-0x10]
	mov	rsi, [rbp-0x18]

	movq	%rbp, %rsp
	popq	%rbp
	mov	rsp, rbp
	pop	rbp

	jmp	of_method_not_found@PLT
.type of_forward, %function
.size of_forward, .-of_forward

of_forward_stret:
	pushq	%rbp
	movq	%rsp, %rbp
	push	rbp
	mov	rbp, rsp

	/* Save all arguments */
	subq	$0xC0, %rsp	/* 16-byte alignment */
	movq	%rax, -0x8(%rbp)
	movq	%rdi, -0x10(%rbp)
	movq	%rsi, -0x18(%rbp)
	movq	%rdx, -0x20(%rbp)
	movq	%rcx, -0x28(%rbp)
	movq	%r8, -0x30(%rbp)
	movq	%r9, -0x38(%rbp)
	movaps	%xmm0, -0x50(%rbp)
	movaps	%xmm1, -0x60(%rbp)
	movaps	%xmm2, -0x70(%rbp)
	movaps	%xmm3, -0x80(%rbp)
	movaps	%xmm4, -0x90(%rbp)
	movaps	%xmm5, -0xA0(%rbp)
	movaps	%xmm6, -0xB0(%rbp)
	movaps	%xmm7, -0xC0(%rbp)
	sub	rsp, 0xC0	/* 16-byte alignment */
	mov	[rbp-0x08], rax
	mov	[rbp-0x10], rdi
	mov	[rbp-0x18], rsi
	mov	[rbp-0x20], rdx
	mov	[rbp-0x28], rcx
	mov	[rbp-0x30], r8
	mov	[rbp-0x38], r9
	movaps	[rbp-0x50], xmm0
	movaps	[rbp-0x60], xmm1
	movaps	[rbp-0x70], xmm2
	movaps	[rbp-0x80], xmm3
	movaps	[rbp-0x90], xmm4
	movaps	[rbp-0xA0], xmm5
	movaps	[rbp-0xB0], xmm6
	movaps	[rbp-0xC0], xmm7

	movq	%rsi, %rdi
	mov	rdi, rsi
	call	object_getClass@PLT

	movq	%rax, %rdi
	leaq	sel_forwardingTargetForSelector_(%rip), %rsi
	mov	rdi, rax
	lea	rsi, [rip+sel_forwardingTargetForSelector_]
	call	class_respondsToSelector@PLT

	testq	%rax, %rax
	jz	0f
	test	rax, rax
	jz	short 0f

	movq	-0x18(%rbp), %rdi
	leaq	sel_forwardingTargetForSelector_(%rip), %rsi
	mov	rdi, [rbp-0x18]
	lea	rsi, [rip+sel_forwardingTargetForSelector_]
	call	objc_msg_lookup@PLT

	movq	-0x18(%rbp), %rdi
	leaq	sel_forwardingTargetForSelector_(%rip), %rsi
	movq	-0x20(%rbp), %rdx
	call	*%rax
	mov	rdi, [rbp-0x18]
	lea	rsi, [rip+sel_forwardingTargetForSelector_]
	mov	rdx, [rbp-0x20]
	call	rax

	testq	%rax, %rax
	jz	0f
	cmpq	-0x18(%rbp), %rax
	je	0f
	test	rax, rax
	jz	short 0f
	cmp	rax, [rbp-0x18]
	je	short 0f

	movq	%rax, -0x18(%rbp)
	mov	[rbp-0x18], rax

	movq	%rax, %rdi
	movq	-0x20(%rbp), %rsi
	mov	rdi, rax
	mov	rsi, [rbp-0x20]
	call	objc_msg_lookup_stret@PLT
	movq	%rax, %r11
	mov	r11, rax

	/* Restore all arguments */
	movaps	-0xC0(%rbp), %xmm7
	movaps	-0xB0(%rbp), %xmm6
	movaps	-0xA0(%rbp), %xmm5
	movaps	-0x90(%rbp), %xmm4
	movaps	-0x80(%rbp), %xmm3
	movaps	-0x70(%rbp), %xmm2
	movaps	-0x60(%rbp), %xmm1
	movaps	-0x50(%rbp), %xmm0
	movq	-0x38(%rbp), %r9
	movq	-0x30(%rbp), %r8
	movq	-0x28(%rbp), %rcx
	movq	-0x20(%rbp), %rdx
	movq	-0x18(%rbp), %rsi
	movq	-0x10(%rbp), %rdi
	movq	-0x8(%rbp), %rax
	movaps	xmm7, [rbp-0xC0]
	movaps	xmm6, [rbp-0xB0]
	movaps	xmm5, [rbp-0xA0]
	movaps	xmm4, [rbp-0x90]
	movaps	xmm3, [rbp-0x80]
	movaps	xmm2, [rbp-0x70]
	movaps	xmm1, [rbp-0x60]
	movaps	xmm0, [rbp-0x50]
	mov	r9,   [rbp-0x38]
	mov	r8,   [rbp-0x30]
	mov	rcx,  [rbp-0x28]
	mov	rdx,  [rbp-0x20]
	mov	rsi,  [rbp-0x18]
	mov	rdi,  [rbp-0x10]
	mov	rax,  [rbp-0x08]

	movq	%rbp, %rsp
	popq	%rbp
	mov	rsp, rbp
	pop	rbp

	jmpq	*%r11
	jmp	r11

0:
	movq	-0x10(%rbp), %rdi
	movq	-0x18(%rbp), %rsi
	movq	-0x20(%rbp), %rdx
	mov	rdi, [rbp-0x10]
	mov	rsi, [rbp-0x18]
	mov	rdx, [rbp-0x20]

	movq	%rbp, %rsp
	popq	%rbp
	mov	rsp, rbp
	pop	rbp

	jmp	of_method_not_found_stret@PLT
.type of_forward_stret, %function
.size of_forward_stret, .-of_forward_stret

init:
	leaq	module(%rip), %rdi
	lea	rdi, [rip+module]
	jmp	__objc_exec_class@PLT

#ifdef OF_SOLARIS
.section .init_array, "aw"
#else
.section .ctors, "aw", %progbits
#endif

Modified src/forwarding/forwarding-x86_64-macho.S from [42dfac05fa] to [4631e2d50d].

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
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







+
+





-
-
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
+
+


-
+


-
-
+
+


-
-
-
-
+
+
+
+

-
+

-
+


-
+

-
-
+
+

-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+

-
+


-
-
+
+

-
-
+
+




-
-
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+


-
-
+
+


-
+


-
-
+
+


-
-
-
-
+
+
+
+

-
+

-
+


-
+

-
-
+
+

-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+

-
+


-
-
-
+
+
+

-
-
+
+




-
+







 * file.
 */

#include "config.h"

#include "platform.h"

.intel_syntax noprefix

.globl _of_forward
.globl _of_forward_stret

.section __TEXT, __text, regular, pure_instructions
_of_forward:
	pushq	%rbp
	movq	%rsp, %rbp
	push	rbp
	mov	rbp, rsp

	/* Save all arguments */
	subq	$0xC0, %rsp	/* 16-byte alignment */
	movq	%rax, -0x8(%rbp)
	movq	%rdi, -0x10(%rbp)
	movq	%rsi, -0x18(%rbp)
	movq	%rdx, -0x20(%rbp)
	movq	%rcx, -0x28(%rbp)
	movq	%r8, -0x30(%rbp)
	movq	%r9, -0x38(%rbp)
	movaps	%xmm0, -0x50(%rbp)
	movaps	%xmm1, -0x60(%rbp)
	movaps	%xmm2, -0x70(%rbp)
	movaps	%xmm3, -0x80(%rbp)
	movaps	%xmm4, -0x90(%rbp)
	movaps	%xmm5, -0xA0(%rbp)
	movaps	%xmm6, -0xB0(%rbp)
	movaps	%xmm7, -0xC0(%rbp)
	sub	rsp, 0xC0	/* 16-byte alignment */
	mov	[rbp-0x08], rax
	mov	[rbp-0x10], rdi
	mov	[rbp-0x18], rsi
	mov	[rbp-0x20], rdx
	mov	[rbp-0x28], rcx
	mov	[rbp-0x30], r8
	mov	[rbp-0x38], r9
	movaps	[rbp-0x50], xmm0
	movaps	[rbp-0x60], xmm1
	movaps	[rbp-0x70], xmm2
	movaps	[rbp-0x80], xmm3
	movaps	[rbp-0x90], xmm4
	movaps	[rbp-0xA0], xmm5
	movaps	[rbp-0xB0], xmm6
	movaps	[rbp-0xC0], xmm7

	call	_object_getClass

	movq	%rax, %rdi
	leaq	sel_forwardingTargetForSelector_(%rip), %rsi
	mov	rdi, rax
	lea	rsi, [rip+sel_forwardingTargetForSelector_]
	call	_class_respondsToSelector

	testq	%rax, %rax
	test	rax, rax
	jz	0f

	movq	-0x10(%rbp), %rdi
	leaq	sel_forwardingTargetForSelector_(%rip), %rsi
	mov	rdi, [rbp-0x10]
	lea	rsi, [rip+sel_forwardingTargetForSelector_]
	call	_objc_msg_lookup

	movq	-0x10(%rbp), %rdi
	leaq	sel_forwardingTargetForSelector_(%rip), %rsi
	movq	-0x18(%rbp), %rdx
	call	*%rax
	mov	rdi, [rbp-0x10]
	lea	rsi, [rip+sel_forwardingTargetForSelector_]
	mov	rdx, [rbp-0x18]
	call	rax

	testq	%rax, %rax
	test	rax, rax
	jz	0f
	cmpq	-0x10(%rbp), %rax
	cmp	rax, [rbp-0x10]
	je	0f

	movq	%rax, -0x10(%rbp)
	mov	[rbp-0x10], rax

	movq	%rax, %rdi
	movq	-0x18(%rbp), %rsi
	mov	rdi, rax
	mov	rsi, [rbp-0x18]
	call	_objc_msg_lookup
	movq	%rax, %r11
	mov	r11, rax

	/* Restore all arguments */
	movaps	-0xC0(%rbp), %xmm7
	movaps	-0xB0(%rbp), %xmm6
	movaps	-0xA0(%rbp), %xmm5
	movaps	-0x90(%rbp), %xmm4
	movaps	-0x80(%rbp), %xmm3
	movaps	-0x70(%rbp), %xmm2
	movaps	-0x60(%rbp), %xmm1
	movaps	-0x50(%rbp), %xmm0
	movq	-0x38(%rbp), %r9
	movq	-0x30(%rbp), %r8
	movq	-0x28(%rbp), %rcx
	movq	-0x20(%rbp), %rdx
	movq	-0x18(%rbp), %rsi
	movq	-0x10(%rbp), %rdi
	movq	-0x8(%rbp), %rax
	movaps	xmm7, [rbp-0xC0]
	movaps	xmm6, [rbp-0xB0]
	movaps	xmm5, [rbp-0xA0]
	movaps	xmm4, [rbp-0x90]
	movaps	xmm3, [rbp-0x80]
	movaps	xmm2, [rbp-0x70]
	movaps	xmm1, [rbp-0x60]
	movaps	xmm0, [rbp-0x50]
	mov	r9,   [rbp-0x38]
	mov	r8,   [rbp-0x30]
	mov	rcx,  [rbp-0x28]
	mov	rdx,  [rbp-0x20]
	mov	rsi,  [rbp-0x18]
	mov	rdi,  [rbp-0x10]
	mov	rax,  [rbp-0x08]

	movq	%rbp, %rsp
	popq	%rbp
	mov	rsp, rbp
	pop	rbp

	jmpq	*%r11
	jmp	r11

0:
	movq	-0x10(%rbp), %rdi
	movq	-0x18(%rbp), %rsi
	mov	rdi, [rbp-0x10]
	mov	rsi, [rbp-0x18]

	movq	%rbp, %rsp
	popq	%rbp
	mov	rsp, rbp
	pop	rbp

	jmp	_of_method_not_found

_of_forward_stret:
	pushq	%rbp
	movq	%rsp, %rbp
	push	rbp
	mov	rbp, rsp

	/* Save all arguments */
	subq	$0xC0, %rsp	/* 16-byte alignment */
	movq	%rax, -0x8(%rbp)
	movq	%rdi, -0x10(%rbp)
	movq	%rsi, -0x18(%rbp)
	movq	%rdx, -0x20(%rbp)
	movq	%rcx, -0x28(%rbp)
	movq	%r8, -0x30(%rbp)
	movq	%r9, -0x38(%rbp)
	movaps	%xmm0, -0x50(%rbp)
	movaps	%xmm1, -0x60(%rbp)
	movaps	%xmm2, -0x70(%rbp)
	movaps	%xmm3, -0x80(%rbp)
	movaps	%xmm4, -0x90(%rbp)
	movaps	%xmm5, -0xA0(%rbp)
	movaps	%xmm6, -0xB0(%rbp)
	movaps	%xmm7, -0xC0(%rbp)
	sub	rsp, 0xC0	/* 16-byte alignment */
	mov	[rbp-0x08], rax
	mov	[rbp-0x10], rdi
	mov	[rbp-0x18], rsi
	mov	[rbp-0x20], rdx
	mov	[rbp-0x28], rcx
	mov	[rbp-0x30], r8
	mov	[rbp-0x38], r9
	movaps	[rbp-0x50], xmm0
	movaps	[rbp-0x60], xmm1
	movaps	[rbp-0x70], xmm2
	movaps	[rbp-0x80], xmm3
	movaps	[rbp-0x90], xmm4
	movaps	[rbp-0xA0], xmm5
	movaps	[rbp-0xB0], xmm6
	movaps	[rbp-0xC0], xmm7

	movq	%rsi, %rdi
	mov	rdi, rsi
	call	_object_getClass

	movq	%rax, %rdi
	leaq	sel_forwardingTargetForSelector_(%rip), %rsi
	mov	rdi, rax
	lea	rsi, [rip+sel_forwardingTargetForSelector_]
	call	_class_respondsToSelector

	testq	%rax, %rax
	test	rax, rax
	jz	0f

	movq	-0x18(%rbp), %rdi
	leaq	sel_forwardingTargetForSelector_(%rip), %rsi
	mov	rdi, [rbp-0x18]
	lea	rsi, [rip+sel_forwardingTargetForSelector_]
	call	_objc_msg_lookup

	movq	-0x18(%rbp), %rdi
	leaq	sel_forwardingTargetForSelector_(%rip), %rsi
	movq	-0x20(%rbp), %rdx
	call	*%rax
	mov	rdi, [rbp-0x18]
	lea	rsi, [rip+sel_forwardingTargetForSelector_]
	mov	rdx, [rbp-0x20]
	call	rax

	testq	%rax, %rax
	test	rax, rax
	jz	0f
	cmpq	-0x18(%rbp), %rax
	cmp	rax, [rbp-0x18]
	je	0f

	movq	%rax, -0x18(%rbp)
	mov	[rbp-0x18], rax

	movq	%rax, %rdi
	movq	-0x20(%rbp), %rsi
	mov	rdi, rax
	mov	rsi, [rbp-0x20]
	call	_objc_msg_lookup_stret
	movq	%rax, %r11
	mov	r11, rax

	/* Restore all arguments */
	movaps	-0xC0(%rbp), %xmm7
	movaps	-0xB0(%rbp), %xmm6
	movaps	-0xA0(%rbp), %xmm5
	movaps	-0x90(%rbp), %xmm4
	movaps	-0x80(%rbp), %xmm3
	movaps	-0x70(%rbp), %xmm2
	movaps	-0x60(%rbp), %xmm1
	movaps	-0x50(%rbp), %xmm0
	movq	-0x38(%rbp), %r9
	movq	-0x30(%rbp), %r8
	movq	-0x28(%rbp), %rcx
	movq	-0x20(%rbp), %rdx
	movq	-0x18(%rbp), %rsi
	movq	-0x10(%rbp), %rdi
	movq	-0x8(%rbp), %rax
	movaps	xmm7, [rbp-0xC0]
	movaps	xmm6, [rbp-0xB0]
	movaps	xmm5, [rbp-0xA0]
	movaps	xmm4, [rbp-0x90]
	movaps	xmm3, [rbp-0x80]
	movaps	xmm2, [rbp-0x70]
	movaps	xmm1, [rbp-0x60]
	movaps	xmm0, [rbp-0x50]
	mov	r9,   [rbp-0x38]
	mov	r8,   [rbp-0x30]
	mov	rcx,  [rbp-0x28]
	mov	rdx,  [rbp-0x20]
	mov	rsi,  [rbp-0x18]
	mov	rdi,  [rbp-0x10]
	mov	rax,  [rbp-0x08]

	movq	%rbp, %rsp
	popq	%rbp
	mov	rsp, rbp
	pop	rbp

	jmpq	*%r11
	jmp	r11

0:
	movq	-0x10(%rbp), %rdi
	movq	-0x18(%rbp), %rsi
	movq	-0x20(%rbp), %rdx
	mov	rdi, [rbp-0x10]
	mov	rsi, [rbp-0x18]
	mov	rdx, [rbp-0x20]

	movq	%rbp, %rsp
	popq	%rbp
	mov	rsp, rbp
	pop	rbp

	jmp	_of_method_not_found_stret

init:
	leaq	module(%rip), %rdi
	lea	rdi, [rip+module]
	jmp	___objc_exec_class

.section __DATA, __mod_init_func, mod_init_funcs
	.quad init

.section __TEXT, __cstring, cstring_literals
str_forwardingTargetForSelector_:

Modified src/forwarding/forwarding-x86_64-win64.S from [ec2efee322] to [b1b62864b4].

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
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







+
+





-
-
+
+


-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+



-
-
+
+


-
-
+
+

-
-
+
+


-
-
-
-
+
+
+
+

-
-
-
-
+
+
+
+

-
+

-
-
+
+

-
+


-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
+
+

-
+


-
-
+
+

-
-
+
+




-
-
+
+


-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
+


-
-
+
+


-
-
+
+

-
-
+
+


-
-
-
-
+
+
+
+

-
-
-
-
+
+
+
+

-
+

-
-
+
+

-
+


-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
+
+

-
+


-
-
-
+
+
+

-
-
+
+




-
+







 * 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"

.intel_syntax noprefix

.globl of_forward
.globl of_forward_stret

.section .text
of_forward:
	pushq	%rbp
	movq	%rsp, %rbp
	push	rbp
	mov	rbp, rsp

	/* Save all arguments */
	subq	$0x90, %rsp	/* 16-byte alignment */
	movq	%rax, -0x28(%rbp)
	movq	%rcx, -0x30(%rbp)
	movq	%rdx, -0x38(%rbp)
	movq	%r8, -0x40(%rbp)
	movq	%r9, -0x48(%rbp)
	movaps	%xmm0, -0x60(%rbp)
	movaps	%xmm1, -0x70(%rbp)
	movaps	%xmm2, -0x80(%rbp)
	movaps	%xmm3, -0x90(%rbp)
	sub	rsp, 0x90	/* 16-byte alignment */
	mov	[rbp-0x28], rax
	mov	[rbp-0x30], rcx
	mov	[rbp-0x38], rdx
	mov	[rbp-0x40], r8
	mov	[rbp-0x48], r9
	movaps	[rbp-0x60], xmm0
	movaps	[rbp-0x70], xmm1
	movaps	[rbp-0x80], xmm2
	movaps	[rbp-0x90], xmm3

	call	object_getClass

	movq	%rax, %rcx
	leaq	sel_forwardingTargetForSelector_(%rip), %rdx
	mov	rcx, rax
	mov	rdx, offset sel_forwardingTargetForSelector_
	call	class_respondsToSelector

	testq	%rax, %rax
	jz	0f
	test	rax, rax
	jz	short 0f

	movq	-0x30(%rbp), %rcx
	leaq	sel_forwardingTargetForSelector_(%rip), %rdx
	mov	rcx, [rbp-0x30]
	mov	rdx, offset sel_forwardingTargetForSelector_
	call	objc_msg_lookup

	movq	-0x30(%rbp), %rcx
	leaq	sel_forwardingTargetForSelector_(%rip), %rdx
	movq	-0x38(%rbp), %r8
	call	*%rax
	mov	rcx, [rbp-0x30]
	mov	rdx, offset sel_forwardingTargetForSelector_
	mov	r8,  [rbp-0x38]
	call	rax

	testq	%rax, %rax
	jz	0f
	cmpq	-0x30(%rbp), %rax
	je	0f
	test	rax, rax
	jz	short 0f
	cmp	rax, [rbp-0x30]
	je	short 0f

	movq	%rax, -0x30(%rbp)
	mov	[rbp-0x30], rax

	movq	%rax, %rcx
	movq	-0x38(%rbp), %rdx
	mov	rcx, rax
	mov	rdx, [rbp-0x38]
	call	objc_msg_lookup
	movq	%rax, %r11
	mov	r11, rax

	/* Restore all arguments */
	movaps	-0x90(%rbp), %xmm3
	movaps	-0x80(%rbp), %xmm2
	movaps	-0x70(%rbp), %xmm1
	movaps	-0x60(%rbp), %xmm0
	movq	-0x48(%rbp), %r9
	movq	-0x40(%rbp), %r8
	movq	-0x38(%rbp), %rdx
	movq	-0x30(%rbp), %rcx
	movq	-0x28(%rbp), %rax
	movaps	xmm3, [rbp-0x90]
	movaps	xmm2, [rbp-0x80]
	movaps	xmm1, [rbp-0x70]
	movaps	xmm0, [rbp-0x60]
	mov	r9,   [rbp-0x48]
	mov	r8,   [rbp-0x40]
	mov	rdx,  [rbp-0x38]
	mov	rcx,  [rbp-0x30]
	mov	rax,  [rbp-0x28]

	movq	%rbp, %rsp
	popq	%rbp
	mov	rsp, rbp
	pop	rbp

	jmpq	*%r11
	jmp	r11

0:
	movq	-0x30(%rbp), %rcx
	movq	-0x38(%rbp), %rdx
	mov	rcx, [rbp-0x30]
	mov	rdx, [rbp-0x38]

	movq	%rbp, %rsp
	popq	%rbp
	mov	rsp, rbp
	pop	rbp

	jmp	of_method_not_found

of_forward_stret:
	pushq	%rbp
	movq	%rsp, %rbp
	push	rbp
	mov	rbp, rsp

	/* Save all arguments */
	subq	$0x90, %rsp	/* 16-byte alignment */
	movq	%rax, -0x28(%rbp)
	movq	%rcx, -0x30(%rbp)
	movq	%rdx, -0x38(%rbp)
	movq	%r8, -0x40(%rbp)
	movq	%r9, -0x48(%rbp)
	movaps	%xmm0, -0x60(%rbp)
	movaps	%xmm1, -0x70(%rbp)
	movaps	%xmm2, -0x80(%rbp)
	movaps	%xmm3, -0x90(%rbp)
	sub	rsp, 0x90	/* 16-byte alignment */
	mov	[rbp-0x28], rax
	mov	[rbp-0x30], rcx
	mov	[rbp-0x38], rdx
	mov	[rbp-0x40], r8
	mov	[rbp-0x48], r9
	movaps	[rbp-0x60], xmm0
	movaps	[rbp-0x70], xmm1
	movaps	[rbp-0x80], xmm2
	movaps	[rbp-0x90], xmm3

	movq	%rdx, %rcx
	mov	rcx, rdx
	call	object_getClass

	movq	%rax, %rcx
	leaq	sel_forwardingTargetForSelector_(%rip), %rdx
	mov	rcx, rax
	mov	rdx, offset sel_forwardingTargetForSelector_
	call	class_respondsToSelector

	testq	%rax, %rax
	jz	0f
	test	rax, rax
	jz	short 0f

	movq	-0x38(%rbp), %rcx
	leaq	sel_forwardingTargetForSelector_(%rip), %rdx
	mov	rcx, [rbp-0x38]
	mov	rdx, offset sel_forwardingTargetForSelector_
	call	objc_msg_lookup

	movq	-0x38(%rbp), %rcx
	leaq	sel_forwardingTargetForSelector_(%rip), %rdx
	movq	-0x40(%rbp), %r8
	call	*%rax
	mov	rcx, [rbp-0x38]
	mov	rdx, offset sel_forwardingTargetForSelector_
	mov	r8,  [rbp-0x40]
	call	rax

	testq	%rax, %rax
	jz	0f
	cmpq	-0x38(%rbp), %rax
	je	0f
	test	rax, rax
	jz	short 0f
	cmp	rax, [rbp-0x38]
	je	short 0f

	movq	%rax, -0x38(%rbp)
	mov	[rbp-0x38], rax

	movq	%rax, %rcx
	movq	-0x40(%rbp), %rdx
	mov	rcx, rax
	mov	rdx, [rbp-0x40]
	call	objc_msg_lookup_stret
	movq	%rax, %r11
	mov	r11, rax

	/* Restore all arguments */
	movaps	-0x90(%rbp), %xmm3
	movaps	-0x80(%rbp), %xmm2
	movaps	-0x70(%rbp), %xmm1
	movaps	-0x60(%rbp), %xmm0
	movq	-0x48(%rbp), %r9
	movq	-0x40(%rbp), %r8
	movq	-0x38(%rbp), %rdx
	movq	-0x30(%rbp), %rcx
	movq	-0x28(%rbp), %rax
	movaps	xmm3, [rbp-0x90]
	movaps	xmm2, [rbp-0x80]
	movaps	xmm1, [rbp-0x70]
	movaps	xmm0, [rbp-0x60]
	mov	r9,   [rbp-0x48]
	mov	r8,   [rbp-0x40]
	mov	rdx,  [rbp-0x38]
	mov	rcx,  [rbp-0x30]
	mov	rax,  [rbp-0x28]

	movq	%rbp, %rsp
	popq	%rbp
	mov	rsp, rbp
	pop	rbp

	jmpq	*%r11
	jmp	r11

0:
	movq	-0x30(%rbp), %rcx
	movq	-0x38(%rbp), %rdx
	movq	-0x40(%rbp), %r8
	mov	rcx, [rbp-0x30]
	mov	rdx, [rbp-0x38]
	mov	r8,  [rbp-0x40]

	movq	%rbp, %rsp
	popq	%rbp
	mov	rsp, rbp
	pop	rbp

	jmp	of_method_not_found_stret

init:
	leaq	module(%rip), %rcx
	mov	rcx, offset module
	jmp	__objc_exec_class

.section .ctors, "aw"
	.quad init

.section .rodata
str_forwardingTargetForSelector_:

Modified src/forwarding/forwarding.S from [50662045f8] to [873a2fafd1].

43
44
45
46
47
48
49


50
51
52
53
54
55
56
57
58
59
60
61
62
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64







+
+













#   include "forwarding-arm-elf.S"
#  elif defined(OF_POWERPC)
#   include "forwarding-powerpc-elf.S"
#  elif defined(OF_MIPS)
#   include "forwarding-mips-elf.S"
#  elif defined(OF_SPARC64)
#   include "forwarding-sparc64-elf.S"
#  elif defined(OF_SPARC)
#   include "forwarding-sparc-elf.S"
#  endif
# elif defined(OF_MACH_O)
#  if defined(OF_X86_64)
#   include "forwarding-x86_64-macho.S"
#  endif
# elif defined(OF_WINDOWS)
#  if defined(OF_X86_64)
#   include "forwarding-x86_64-win64.S"
#  elif defined(OF_X86)
#   include "forwarding-x86-win32.S"
#  endif
# endif
#endif

Modified src/invocation/apple-call-x86_64.S from [faa19cc12c] to [3884ee11f3].

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
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







+
+





-
-
+
+

-
-
-
+
+
+

-
-
+
+

-
+



-
+


-
-
-
+
+
+




-
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
+
+

-
+


-
+


-
+





-
-
-
-
-
+
+
+
+
+

-
+

-
+


-
+



-
-
+
+




-
-
+
+







-
+



-
-
+
+

 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include "invoke-x86_64.h"

.intel_syntax noprefix

.globl _of_invocation_call

.section __TEXT, __text, regular, pure_instructions
_of_invocation_call:
	pushq	%rbp
	movq	%rsp, %rbp
	push	rbp
	mov	rbp, rsp

	subq	$16, %rsp
	andq	$-16, %rsp
	movq	%rdi, -8(%rbp)
	sub	rsp, 16
	and	rsp, -16
	mov	[rbp-8], rdi

	leaq	OFFSET_STACK(%rdi), %rdx
	movq	OFFSET_STACK_SIZE(%rdi), %rcx
	lea	rdx, [rdi+OFFSET_STACK]
	mov	rcx, [rdi+OFFSET_STACK_SIZE]

	testq	$1, %rcx
	test	rcx, 1
	jnz	Lfix_align

Lfill_stack:
	testq	%rcx, %rcx
	test	rcx, rcx
	jz	Lstack_filled

	decq	%rcx
	movq	(%rdx,%rcx,8), %r11
	pushq	%r11
	dec	rcx
	mov	r11, [rdx+rcx*8]
	push	r11

	jmp	Lfill_stack

Lstack_filled:
	movb	OFFSET_NUM_SSE_USED(%rdi), %al
	mov	al, [rdi+OFFSET_NUM_SSE_USED]

	movaps	OFFSET_SSE_INOUT+112(%rdi), %xmm7
	movaps	OFFSET_SSE_INOUT+96(%rdi), %xmm6
	movaps	OFFSET_SSE_INOUT+80(%rdi), %xmm5
	movaps	OFFSET_SSE_INOUT+64(%rdi), %xmm4
	movaps	OFFSET_SSE_INOUT+48(%rdi), %xmm3
	movaps	OFFSET_SSE_INOUT+32(%rdi), %xmm2
	movaps	OFFSET_SSE_INOUT+16(%rdi), %xmm1
	movaps	OFFSET_SSE_INOUT(%rdi), %xmm0
	movaps	xmm7, [rdi+OFFSET_SSE_INOUT+112]
	movaps	xmm6, [rdi+OFFSET_SSE_INOUT+96]
	movaps	xmm5, [rdi+OFFSET_SSE_INOUT+80]
	movaps	xmm4, [rdi+OFFSET_SSE_INOUT+64]
	movaps	xmm3, [rdi+OFFSET_SSE_INOUT+48]
	movaps	xmm2, [rdi+OFFSET_SSE_INOUT+32]
	movaps	xmm1, [rdi+OFFSET_SSE_INOUT+16]
	movaps	xmm0, [rdi+OFFSET_SSE_INOUT]

	movq	OFFSET_GPR_IN+40(%rdi), %r9
	movq	OFFSET_GPR_IN+32(%rdi), %r8
	movq	OFFSET_GPR_IN+24(%rdi), %rcx
	movq	OFFSET_GPR_IN+16(%rdi), %rdx
	movq	OFFSET_GPR_IN+8(%rdi), %rsi
	mov	r9,  [rdi+OFFSET_GPR_IN+40]
	mov	r8,  [rdi+OFFSET_GPR_IN+32]
	mov	rcx, [rdi+OFFSET_GPR_IN+24]
	mov	rdx, [rdi+OFFSET_GPR_IN+16]
	mov	rsi, [rdi+OFFSET_GPR_IN+8]

	movb	OFFSET_RETURN_TYPE(%rdi), %r11b
	movq	OFFSET_GPR_IN(%rdi), %rdi
	mov	r11b, [rdi+OFFSET_RETURN_TYPE]
	mov	rdi,  [rdi+OFFSET_GPR_IN]

	cmpb	$RETURN_TYPE_STRET, %r11b
	cmp	r11b, RETURN_TYPE_STRET
	je	Lcall_send_stret

	cmpb	$RETURN_TYPE_JMP, %r11b
	cmp	r11b, RETURN_TYPE_JMP
	je	_objc_msgSend

	cmpb	$RETURN_TYPE_JMP_STRET, %r11b
	cmp	r11b, RETURN_TYPE_JMP_STRET
	je	_objc_msgSend_stret

	call	_objc_msgSend

Lafter_send:
	movq	-8(%rbp), %rdi
	movq	%rax, OFFSET_GPR_OUT(%rdi)
	movq	%rdx, OFFSET_GPR_OUT+8(%rdi)
	movaps	%xmm0, OFFSET_SSE_INOUT(%rdi)
	movaps	%xmm1, OFFSET_SSE_INOUT+16(%rdi)
	mov	rdi, [rbp-8]
	mov	[rdi+OFFSET_GPR_OUT], rax
	mov	[rdi+OFFSET_GPR_OUT+8], rdx
	movaps	[rdi+OFFSET_SSE_INOUT], xmm0
	movaps	[rdi+OFFSET_SSE_INOUT+16], xmm1

	movb	OFFSET_RETURN_TYPE(%rdi), %r11b
	mov	r11b, [rdi+OFFSET_RETURN_TYPE]

	cmpb	$RETURN_TYPE_X87, %r11b
	cmp	r11b, RETURN_TYPE_X87
	je	Lpop_long_double

	cmpb	$RETURN_TYPE_COMPLEX_X87, %r11b
	cmp	r11b, RETURN_TYPE_COMPLEX_X87
	je	Lpop_complex_long_double

Lreturn:
	movq	%rbp, %rsp
	popq	%rbp
	mov	rsp, rbp
	pop	rbp

	ret

Lfix_align:
	xorq	%r11, %r11
	pushq	%r11
	xor	r11, r11
	push	r11
	jmp	Lfill_stack

Lcall_send_stret:
	call	_objc_msgSend_stret
	jmp	Lafter_send

Lpop_long_double:
	fstpt	OFFSET_X87_OUT(%rdi)
	fstp	tbyte ptr [rdi+OFFSET_X87_OUT]
	jmp	Lreturn

Lpop_complex_long_double:
	fstpt	OFFSET_X87_OUT(%rdi)
	fstpt	OFFSET_X87_OUT+16(%rdi)
	fstp	tbyte ptr [rdi+OFFSET_X87_OUT]
	fstp	tbyte ptr [rdi+OFFSET_X87_OUT+16]
	jmp	Lreturn

Modified src/invocation/call-x86_64-elf.S from [5b83df7d17] to [10e2914d71].

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
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







+
+





-
-
+
+

-
-
-
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
+
+


-
-
-
+
+
+

-
-
+
+

-
-
+
+

-
-
-
+
+
+

-
-
-
+
+
+

-
+

-
-
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
+
+

-
-
-
-
+
+
+
+

-
-
+
+

-
-
-
-
-
-
+
+
+
+
+
+

-
+

-
-
+
+

-
-
+
+

-
-
-
+
+
+



-
-
-
-
+
+
+
+

-
-
-
+
+
+


-
+

-
-
-
+
+
+

-
-
-
+
+
+

-
-
-
-
+
+
+
+




 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include "invoke-x86_64.h"

.intel_syntax noprefix

.globl of_invocation_call

.section .text
of_invocation_call:
	pushq	%rbp
	movq	%rsp, %rbp
	pushq	rbp
	mov	rbp, rsp

	subq	$16, %rsp
	andq	$-16, %rsp
	movq	%rdi, -8(%rbp)
	sub	rsp, 16
	and	rsp, -16
	mov	[rbp-8], rdi

	movb	OFFSET_RETURN_TYPE(%rdi), %r11b
	cmpb	$RETURN_TYPE_STRET, %r11b
	je	.lookup_stret
	cmpb	$RETURN_TYPE_JMP_STRET, %r11b
	je	.lookup_stret
	mov	r11b, [rdi+OFFSET_RETURN_TYPE]
	cmp	r11b, RETURN_TYPE_STRET
	je	short .Llookup_stret
	cmp	r11b, RETURN_TYPE_JMP_STRET
	je	short .Llookup_stret

	movq	OFFSET_GPR_IN+8(%rdi), %rsi
	movq	OFFSET_GPR_IN+0(%rdi), %rdi
	mov	rsi, [rdi+OFFSET_GPR_IN+8]
	mov	rdi, [rdi+OFFSET_GPR_IN]
	call	objc_msg_lookup@PLT

.after_lookup:
	movq	%rax, -16(%rbp)
	movq	-8(%rbp), %rdi
.Lafter_lookup:
	mov	[rbp-16], rax
	mov	rdi, [rbp-8]

	leaq	OFFSET_STACK(%rdi), %rdx
	movq	OFFSET_STACK_SIZE(%rdi), %rcx
	lea	rdx, [rdi+OFFSET_STACK]
	mov	rcx, [rdi+OFFSET_STACK_SIZE]

	testq	$1, %rcx
	jnz	.fix_align
	test	rcx, 1
	jnz	short .Lfix_align

.fill_stack:
	testq	%rcx, %rcx
	jz	.stack_filled
.Lfill_stack:
	test	rcx, rcx
	jz	short .Lstack_filled

	decq	%rcx
	movq	(%rdx,%rcx,8), %r11
	pushq	%r11
	dec	rcx
	mov	r11, [rdx+rcx*8]
	push	r11

	jmp	.fill_stack
	jmp	short .Lfill_stack

.stack_filled:
	movb	OFFSET_NUM_SSE_USED(%rdi), %al
.Lstack_filled:
	mov	al, [rdi+OFFSET_NUM_SSE_USED]

	movaps	OFFSET_SSE_INOUT+112(%rdi), %xmm7
	movaps	OFFSET_SSE_INOUT+96(%rdi), %xmm6
	movaps	OFFSET_SSE_INOUT+80(%rdi), %xmm5
	movaps	OFFSET_SSE_INOUT+64(%rdi), %xmm4
	movaps	OFFSET_SSE_INOUT+48(%rdi), %xmm3
	movaps	OFFSET_SSE_INOUT+32(%rdi), %xmm2
	movaps	OFFSET_SSE_INOUT+16(%rdi), %xmm1
	movaps	OFFSET_SSE_INOUT(%rdi), %xmm0
	movaps	xmm7, [rdi+OFFSET_SSE_INOUT+112]
	movaps	xmm6, [rdi+OFFSET_SSE_INOUT+96]
	movaps	xmm5, [rdi+OFFSET_SSE_INOUT+80]
	movaps	xmm4, [rdi+OFFSET_SSE_INOUT+64]
	movaps	xmm3, [rdi+OFFSET_SSE_INOUT+48]
	movaps	xmm2, [rdi+OFFSET_SSE_INOUT+32]
	movaps	xmm1, [rdi+OFFSET_SSE_INOUT+16]
	movaps	xmm0, [rdi+OFFSET_SSE_INOUT]

	movq	OFFSET_GPR_IN+40(%rdi), %r9
	movq	OFFSET_GPR_IN+32(%rdi), %r8
	movq	OFFSET_GPR_IN+24(%rdi), %rcx
	movq	OFFSET_GPR_IN+16(%rdi), %rdx
	movq	OFFSET_GPR_IN+8(%rdi), %rsi
	mov	r9,  [rdi+OFFSET_GPR_IN+40]
	mov	r8,  [rdi+OFFSET_GPR_IN+32]
	mov	rcx, [rdi+OFFSET_GPR_IN+24]
	mov	rdx, [rdi+OFFSET_GPR_IN+16]
	mov	rsi, [rdi+OFFSET_GPR_IN+8]

	movb	OFFSET_RETURN_TYPE(%rdi), %r11b
	movq	OFFSET_GPR_IN(%rdi), %rdi
	mov	r11b, [rdi+OFFSET_RETURN_TYPE]
	mov	rdi,  [rdi+OFFSET_GPR_IN]

	cmpb	$RETURN_TYPE_JMP, %r11b
	je	.jmp_into_method
	cmpb	$RETURN_TYPE_JMP_STRET, %r11b
	je	.jmp_into_method
	cmp	r11b, RETURN_TYPE_JMP
	je	short .Ljmp_into_method
	cmp	r11b, RETURN_TYPE_JMP_STRET
	je	short .Ljmp_into_method

	movq	-16(%rbp), %r11
	call	*%r11
	mov	r11, [rbp-16]
	call	r11

.after_send:
	movq	-8(%rbp), %rdi
	movq	%rax, OFFSET_GPR_OUT(%rdi)
	movq	%rdx, OFFSET_GPR_OUT+8(%rdi)
	movaps	%xmm0, OFFSET_SSE_INOUT(%rdi)
	movaps	%xmm1, OFFSET_SSE_INOUT+16(%rdi)
.Lafter_send:
	mov	rdi, [rbp-8]
	mov	[rdi+OFFSET_GPR_OUT], rax
	mov	[rdi+OFFSET_GPR_OUT+8], rdx
	movaps	[rdi+OFFSET_SSE_INOUT], xmm0
	movaps	[rdi+OFFSET_SSE_INOUT+16], xmm1

	movb	OFFSET_RETURN_TYPE(%rdi), %r11b
	mov	r11b, [rdi+OFFSET_RETURN_TYPE]

	cmpb	$RETURN_TYPE_X87, %r11b
	je	.pop_long_double
	cmp	r11b, RETURN_TYPE_X87
	je	short .Lpop_long_double

	cmpb	$RETURN_TYPE_COMPLEX_X87, %r11b
	je	.pop_complex_long_double
	cmp	r11b, RETURN_TYPE_COMPLEX_X87
	je	short .Lpop_complex_long_double

.return:
	movq	%rbp, %rsp
	popq	%rbp
.Lreturn:
	mov	rsp, rbp
	pop	rbp

	ret

.fix_align:
	xorq	%r11, %r11
	pushq	%r11
	jmp	.fill_stack
.Lfix_align:
	xor	r11, r11
	push	r11
	jmp	short .Lfill_stack

.lookup_stret:
	movq	OFFSET_GPR_IN+16(%rdi), %rsi
	movq	OFFSET_GPR_IN+8(%rdi), %rdi
.Llookup_stret:
	mov	rsi, [rdi+OFFSET_GPR_IN+16]
	mov	rdi, [rdi+OFFSET_GPR_IN+8]
	call	objc_msg_lookup_stret@PLT

	jmp	.after_lookup
	jmp	short .Lafter_lookup

.jmp_into_method:
	movq	-16(%rbp), %r11
	jmp	*%r11
.Ljmp_into_method:
	mov	r11, [rbp-16]
	jmp	r11

.pop_long_double:
	fstpt	OFFSET_X87_OUT(%rdi)
	jmp	.return
.Lpop_long_double:
	fstp	tbyte ptr [rdi+OFFSET_X87_OUT]
	jmp	short .Lreturn

.pop_complex_long_double:
	fstpt	OFFSET_X87_OUT(%rdi)
	fstpt	OFFSET_X87_OUT+16(%rdi)
	jmp	.return
.Lpop_complex_long_double:
	fstp	tbyte ptr [rdi+OFFSET_X87_OUT]
	fstp	tbyte ptr [rdi+OFFSET_X87_OUT+16]
	jmp	short .Lreturn

#ifdef OF_LINUX
.section .note.GNU-stack, "", %progbits
#endif

Modified src/macros.h from [b900515d8a] to [975aa82042].

304
305
306
307
308
309
310











311
312
313
314
315
316
317
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328







+
+
+
+
+
+
+
+
+
+
+







#endif

#if __has_attribute(__swift_name__)
# define OF_SWIFT_NAME(name) __attribute__((__swift_name__(name)))
#else
# define OF_SWIFT_NAME(name)
#endif

#if __has_attribute(__objc_direct__) && defined(OF_APPLE_RUNTIME)
# define OF_DIRECT __attribute__((__objc_direct__))
#else
# define OF_DIRECT
#endif
#if __has_attribute(__objc_direct_members__) && defined(OF_APPLE_RUNTIME)
# define OF_DIRECT_MEMBERS __attribute__((__objc_direct_members__))
#else
# define OF_DIRECT_MEMBERS
#endif

#ifdef __GNUC__
# ifdef OF_X86_64
#  define OF_X86_64_ASM
# endif
# ifdef OF_X86
#  define OF_X86_ASM
351
352
353
354
355
356
357
358

359
360
361
362
363
364
365
362
363
364
365
366
367
368

369
370
371
372
373
374
375
376







-
+







#  define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR
#  define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET
# endif
#else
# if defined(OF_ELF)
#  if defined(OF_X86_64) || defined(OF_X86) || \
    defined(OF_ARM64) || defined(OF_ARM) || defined(OF_POWERPC) || \
    defined(OF_MIPS) || defined(OF_SPARC64)
    defined(OF_MIPS) || defined(OF_SPARC64) || defined(OF_SPARC)
#   define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR
#   if __OBJFW_RUNTIME_ABI__ >= 800
#    define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET
#   endif
#  endif
# elif defined(OF_MACH_O)
#  if defined(OF_X86_64)

Modified src/runtime/lookup-asm/lookup-asm-sparc-elf.S from [16219ec5cd] to [3c80564f3f].

50
51
52
53
54
55
56
57

58
59
60
61





62
63
64
65
66
67
68
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73







-
+




+
+
+
+
+







#ifdef OF_SELUID24
	ld	[%o2 + %o3], %o2
#endif
	ld	[%o2 + %o4], %o2
	ld	[%o2 + %o5], %o2

	cmp	%o2, 0
	be	\not_found
	be	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

Modified src/runtime/lookup-asm/lookup-asm-x86-elf.S from [6c4a8f6d7c] to [582b619bd5].

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
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







+
+








-
-
-
+
+
+

-
-
+
+


-
+


-
-
+
+

-
-
-
-
+
+
+
+

-
-
+
+





-
-
-
-
+
+
+






-
-
-
-
+
+
+
+

-
-
-
-
+
+
+
+











-
-
+
+



-
+



-
+





 * file.
 */

#include "config.h"

#include "platform.h"

.intel_syntax noprefix

.globl objc_msg_lookup
.globl objc_msg_lookup_stret
.globl objc_msg_lookup_super
.globl objc_msg_lookup_super_stret

.section .text
.macro generate_lookup name not_found
\name:
	movl	4(%esp), %edx
	testl	%edx, %edx
	jz	ret_nil
	mov	edx, [esp+4]
	test	edx, edx
	jz	short ret_nil

	movl	(%edx), %edx
	movl	32(%edx), %edx
	mov	edx, [edx]
	mov	edx, [edx+32]

.Lmain_\name:
	movl	8(%esp), %eax
	mov	eax, [esp+8]

#ifdef OF_SELUID24
	movzbl	2(%eax), %ecx
	movl	(%edx,%ecx,4), %edx
	movzx	ecx, byte ptr [eax+2]
	mov	edx, [edx+ecx*4]
#endif
	movzbl	1(%eax), %ecx
	movl	(%edx,%ecx,4), %edx
	movzbl	(%eax), %ecx
	movl	(%edx,%ecx,4), %eax
	movzx	ecx, byte ptr [eax+1]
	mov	edx, [edx+ecx*4]
	movzx	ecx, byte ptr [eax]
	mov	eax, [edx+ecx*4]

	testl	%eax, %eax
	jz	0f
	test	eax, eax
	jz	short 0f

	ret

0:
	call	get_eip
1:
	addl	$_GLOBAL_OFFSET_TABLE_, %eax
	movl	\not_found@GOT(%eax), %eax
	jmp	*%eax
	add	eax, offset _GLOBAL_OFFSET_TABLE_
	lea	eax, [eax+\not_found@GOTOFF]
	jmp	eax
.type \name, %function
.size \name, .-\name
.endm

.macro generate_lookup_super name lookup
\name:
	movl	4(%esp), %edx
	movl	(%edx), %eax
	cmpl	$0, %eax
	je	ret_nil
	mov	edx, [esp+4]
	mov	eax, [edx]
	test	eax, eax
	jz	short ret_nil

	movl	%eax, 4(%esp)
	movl	4(%edx), %edx
	movl	32(%edx), %edx
	jmp	.Lmain_\lookup
	mov	[esp+4], eax
	mov	edx, [edx+4]
	mov	edx, [edx+32]
	jmp	short .Lmain_\lookup
.type \name, %function
.size \name, .-\name
.endm

generate_lookup objc_msg_lookup objc_method_not_found
generate_lookup objc_msg_lookup_stret objc_method_not_found_stret
generate_lookup_super objc_msg_lookup_super objc_msg_lookup
generate_lookup_super objc_msg_lookup_super_stret objc_msg_lookup_stret

ret_nil:
	call	get_eip
0:
	addl	$nil_method-0b, %eax
	add	eax, offset _GLOBAL_OFFSET_TABLE_
	lea	eax, [eax+nil_method@GOTOFF]
	ret

nil_method:
	xorl	%eax, %eax
	xor	eax, eax
	ret

get_eip:
	movl	(%esp), %eax
	mov	eax, [esp]
	ret

#ifdef OF_LINUX
.section .note.GNU-stack, "", %progbits
#endif

Modified src/runtime/lookup-asm/lookup-asm-x86-win32.S from [4aa81a0136] to [44cfb2c923].

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
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











+
+









-
-
-
+
+
+

-
-
+
+


-
+


-
-
+
+

-
-
-
-
+
+
+
+

-
-
+
+




-
-
-
+
-




-
-
-
-
+
+
+
+

-
-
-
-
+
+
+
+








-
-
-
+



-
+

-
-
-
-
 * 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"

.intel_syntax noprefix

.globl _objc_msg_lookup
.globl _objc_msg_lookup_stret
.globl _objc_msg_lookup_super
.globl _objc_msg_lookup_super_stret

.section .text
.macro generate_lookup name not_found
\name:
	movl	4(%esp), %edx
	testl	%edx, %edx
	jz	ret_nil
	mov	edx, [esp+4]
	test	edx, edx
	jz	short ret_nil

	movl	(%edx), %edx
	movl	32(%edx), %edx
	mov	edx, [edx]
	mov	edx, [edx+32]

.Lmain_\name:
	movl	8(%esp), %eax
	mov	eax, [esp+8]

#ifdef OF_SELUID24
	movzbl	2(%eax), %ecx
	movl	(%edx,%ecx,4), %edx
	movzx	ecx, byte ptr [eax+2]
	mov	edx, [edx+ecx*4]
#endif
	movzbl	1(%eax), %ecx
	movl	(%edx,%ecx,4), %edx
	movzbl	(%eax), %ecx
	movl	(%edx,%ecx,4), %eax
	movzx	ecx, byte ptr [eax+1]
	mov	edx, [edx+ecx*4]
	movzx	ecx, byte ptr [eax]
	mov	eax, [edx+ecx*4]

	testl	%eax, %eax
	jz	0f
	test	eax, eax
	jz	short 0f

	ret

0:
	call	get_eip
1:
	addl	$\not_found-1b, %eax
	jmp	\not_found
	jmp	*%eax
.endm

.macro generate_lookup_super name lookup
\name:
	movl	4(%esp), %edx
	movl	(%edx), %eax
	cmpl	$0, %eax
	je	ret_nil
	mov	edx, [esp+4]
	mov	eax, [edx]
	test	eax, eax
	jz	short ret_nil

	movl	%eax, 4(%esp)
	movl	4(%edx), %edx
	movl	32(%edx), %edx
	jmp	.Lmain_\lookup
	mov	[esp+4], eax
	mov	edx, [edx+4]
	mov	edx, [edx+32]
	jmp	short .Lmain_\lookup
.endm

generate_lookup _objc_msg_lookup _objc_method_not_found
generate_lookup _objc_msg_lookup_stret _objc_method_not_found_stret
generate_lookup_super _objc_msg_lookup_super _objc_msg_lookup
generate_lookup_super _objc_msg_lookup_super_stret _objc_msg_lookup_stret

ret_nil:
	call	get_eip
0:
	addl	$nil_method-0b, %eax
	mov	eax, offset nil_method
	ret

nil_method:
	xorl	%eax, %eax
	xor	eax, eax
	ret

get_eip:
	movl	(%esp), %eax
	ret

Modified src/runtime/lookup-asm/lookup-asm-x86_64-elf.S from [16edfd651f] to [d030c5228c].

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
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







+
+








-
-
+
+

-
-
+
+


-
-
-
+
+
+

-
+

-
+

-
-
+
+

-
-
+
+








-
-
-
-
+
+
+
+

-
-
-
+
+
+










-
+



-
+





 * file.
 */

#include "config.h"

#include "platform.h"

.intel_syntax noprefix

.globl objc_msg_lookup
.globl objc_msg_lookup_stret
.globl objc_msg_lookup_super
.globl objc_msg_lookup_super_stret

.section .text
.macro generate_lookup name not_found
\name:
	testq	%rdi, %rdi
	jz	ret_nil
	test	rdi, rdi
	jz	short ret_nil

	movq	(%rdi), %r8
	movq	64(%r8), %r8
	mov	r8, [rdi]
	mov	r8, [r8+64]

.Lmain_\name:
	movq	(%rsi), %rax
	movzbl	%ah, %ecx
	movzbl	%al, %edx
	mov	rax, [rsi]
	movzx	ecx, ah
	movzx	edx, al
#ifdef OF_SELUID24
	shrl	$16, %eax
	shr	eax, 16

	movq	(%r8,%rax,8), %r8
	mov	r8,  [r8+rax*8]
#endif
	movq	(%r8,%rcx,8), %r8
	movq	(%r8,%rdx,8), %rax
	mov	r8,  [r8+rcx*8]
	mov	rax, [r8+rdx*8]

	testq	%rax, %rax
	jz	\not_found@PLT
	test	rax, rax
	jz	short \not_found@PLT

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

.macro generate_lookup_super name lookup
\name:
	movq	%rdi, %r8
	movq	(%rdi), %rdi
	testq	%rdi, %rdi
	jz	ret_nil
	mov	r8, rdi
	mov	rdi, [rdi]
	test	rdi, rdi
	jz	short ret_nil

	movq	8(%r8), %r8
	movq	64(%r8), %r8
	jmp	.Lmain_\lookup
	mov	r8, [r8+8]
	mov	r8, [r8+64]
	jmp	short .Lmain_\lookup
.type \name, %function
.size \name, .-\name
.endm

generate_lookup objc_msg_lookup objc_method_not_found
generate_lookup objc_msg_lookup_stret objc_method_not_found_stret
generate_lookup_super objc_msg_lookup_super objc_msg_lookup
generate_lookup_super objc_msg_lookup_super_stret objc_msg_lookup_stret

ret_nil:
	leaq	nil_method(%rip), %rax
	lea	rax, [rip+nil_method]
	ret

nil_method:
	xorq	%rax, %rax
	xor	rax, rax
	ret

#ifdef OF_LINUX
.section .note.GNU-stack, "", %progbits
#endif

Modified src/runtime/lookup-asm/lookup-asm-x86_64-macho.S from [31f7e82d2f] to [679535bcad].

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
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







+
+









-
+


-
-
+
+


-
-
-
+
+
+

-
+

-
+

-
-
+
+

-
+







-
-
-
+
+
+


-
-
+
+









-
+



-
+

 * 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"

.intel_syntax noprefix

.globl _objc_msg_lookup
.globl _objc_msg_lookup_stret
.globl _objc_msg_lookup_super
.globl _objc_msg_lookup_super_stret

.section __TEXT, __text, regular, pure_instructions
.macro generate_lookup
$0:
	testq	%rdi, %rdi
	test	rdi, rdi
	jz	ret_nil

	movq	(%rdi), %r8
	movq	64(%r8), %r8
	mov	r8, [rdi]
	mov	r8, [r8+64]

Lmain_$0:
	movq	(%rsi), %rax
	movzbl	%ah, %ecx
	movzbl	%al, %edx
	mov	rax, [rsi]
	movzx	ecx, ah
	movzx	edx, al
#ifdef OF_SELUID24
	shrl	$$16, %eax
	shr	eax, 16

	movq	(%r8,%rax,8), %r8
	mov	r8, [r8+rax*8]
#endif
	movq	(%r8,%rcx,8), %r8
	movq	(%r8,%rdx,8), %rax
	mov	r8, [r8+rcx*8]
	mov	rax, [r8+rdx*8]

	testq	%rax, %rax
	test	rax, rax
	jz	$1

	ret
.endmacro

.macro generate_lookup_super
$0:
	movq	%rdi, %r8
	movq	(%rdi), %rdi
	testq	%rdi, %rdi
	mov	r8, rdi
	mov	rdi, [rdi]
	test	rdi, rdi
	jz	ret_nil

	movq	8(%r8), %r8
	movq	64(%r8), %r8
	mov	r8, [r8+8]
	mov	r8, [r8+64]
	jmp	Lmain_$1
.endmacro

generate_lookup _objc_msg_lookup, _objc_method_not_found
generate_lookup _objc_msg_lookup_stret, _objc_method_not_found_stret
generate_lookup_super _objc_msg_lookup_super, _objc_msg_lookup
generate_lookup_super _objc_msg_lookup_super_stret, _objc_msg_lookup_stret

ret_nil:
	leaq	nil_method(%rip), %rax
	lea	rax, [rip+nil_method]
	ret

nil_method:
	movq	%rdi, %rax
	mov	rax, rdi
	ret

Modified src/runtime/lookup-asm/lookup-asm-x86_64-win64.S from [71fe436f5b] to [47f8ccf7d6].

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
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







+
+








-
-
+
+

-
-
+
+


-
-
+
+

-
-
-
+
+
+

-
+

-
+

-
-
+
+

-
-
+
+




-
-
+
+





-
-
-
-
+
+
+
+

-
-
-
+
+
+








-
+



-
+

 * 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"

.intel_syntax noprefix

.globl objc_msg_lookup
.globl objc_msg_lookup_stret
.globl objc_msg_lookup_super
.globl objc_msg_lookup_super_stret

.section .text
.macro generate_lookup name not_found
\name:
	testq	%rcx, %rcx
	jz	ret_nil
	test	%rcx, %rcx
	jz	short ret_nil

	movq	(%rcx), %r8
	movq	56(%r8), %r8
	mov	r8, [rcx]
	mov	r8, [r8+56]

.Lmain_\name:
	movq	%rcx, %r10
	movq	%rdx, %r11
	mov	r10, rcx
	mov	r11, rdx

	movq	(%rdx), %rax
	movzbl	%ah, %ecx
	movzbl	%al, %edx
	mov	rax, [rdx]
	movzx	ecx, ah
	movzx	edx, al
#ifdef OF_SELUID24
	shrl	$16, %eax
	shr	eax, 16

	movq	(%r8,%rax,8), %r8
	mov	r8,  [r8+rax*8]
#endif
	movq	(%r8,%rcx,8), %r8
	movq	(%r8,%rdx,8), %rax
	mov	r8,  [r8+rcx*8]
	mov	rax, [r8+rdx*8]

	testq	%rax, %rax
	jz	0f
	test	rax, rax
	jz	short 0f

	ret

0:
	movq	%r10, %rcx
	movq	%r11, %rdx
	mov	rcx, r10
	mov	rdx, r11
	jmp	\not_found
.endm

.macro generate_lookup_super name lookup
\name:
	movq	%rcx, %r8
	movq	(%rcx), %rcx
	testq	%rcx, %rcx
	jz	ret_nil
	mov	r8, rcx
	mov	rcx, [rcx]
	test	rcx, rcx
	jz	short ret_nil

	movq	8(%r8), %r8
	movq	56(%r8), %r8
	jmp	.Lmain_\lookup
	mov	r8, [r8+8]
	mov	r8, [r8+56]
	jmp	short .Lmain_\lookup
.endm

generate_lookup objc_msg_lookup objc_method_not_found
generate_lookup objc_msg_lookup_stret objc_method_not_found_stret
generate_lookup_super objc_msg_lookup_super objc_msg_lookup
generate_lookup_super objc_msg_lookup_super_stret objc_msg_lookup_stret

ret_nil:
	leaq	nil_method(%rip), %rax
	mov	rax, offset nil_method
	ret

nil_method:
	xorq	%rax, %rax
	xor	rax, rax
	ret

Modified tests/TestsAppDelegate.m from [0707701acb] to [3cf677c3a1].

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
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







-


-
+








-


-
+







		[of_stdout writeFormat: @"[%@] %@: ", module, test];
}

- (void)outputSuccess: (OFString *)test
	     inModule: (OFString *)module
{
	if (of_stdout.hasTerminal) {
		of_stdout.cursorColumn = 0;
		of_stdout.foregroundColor = [OFColor lime];
		[of_stdout eraseLine];
		[of_stdout writeFormat: @"[%@] %@: ok\n", module, test];
		[of_stdout writeFormat: @"\r[%@] %@: ok\n", module, test];
	} else
		[of_stdout writeLine: @"ok"];
}

- (void)outputFailure: (OFString *)test
	     inModule: (OFString *)module
{
	if (of_stdout.hasTerminal) {
		of_stdout.cursorColumn = 0;
		of_stdout.foregroundColor = [OFColor red];
		[of_stdout eraseLine];
		[of_stdout writeFormat: @"[%@] %@: failed\n", module, test];
		[of_stdout writeFormat: @"\r[%@] %@: failed\n", module, test];

#ifdef OF_WII
		[of_stdout reset];
		[of_stdout writeLine: @"Press A to continue!"];

		for (;;) {
			WPAD_ScanPads();
283
284
285
286
287
288
289
290

291
292
293
294
295
296
297
281
282
283
284
285
286
287

288
289
290
291
292
293
294
295







-
+







			if (hidKeysDown() & KEY_A)
				break;

			gspWaitForVBlank();
		}
#endif

		of_stdout.cursorColumn = 0;
		[of_stdout writeString: @"\r"];
		[of_stdout reset];
		[of_stdout eraseLine];
	} else
		[of_stdout writeLine: @"failed"];
}

- (void)applicationDidFinishLaunching