ObjFW  Check-in [ac004e624d]

Overview
Comment:More type cleanups
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ac004e624d3607cf20e9fce65f6f2919154f69d3c4985f87ca06466c4ac730df
User & Date: js on 2020-10-10 21:54:38
Other Links: manifest | tags
Context
2020-10-25
17:53
Add tests for ARC check-in: 5b8955df34 user: js tags: trunk
2020-10-10
21:54
More type cleanups check-in: ac004e624d user: js tags: trunk
14:43
Fix accidental type change check-in: c14f0fc208 user: js tags: trunk
Changes

Modified src/OFDate.h from [975839f73c] to [b56f401ff6].

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







-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+







@property (class, readonly, nonatomic) OFDate *distantFuture;
@property (class, readonly, nonatomic) OFDate *distantPast;
#endif

/**
 * @brief The microsecond of the date.
 */
@property (readonly, nonatomic) uint32_t microsecond;
@property (readonly, nonatomic) unsigned long microsecond;

/**
 * @brief The second of the date.
 */
@property (readonly, nonatomic) uint8_t second;
@property (readonly, nonatomic) unsigned char second;

/**
 * @brief The minute of the date.
 */
@property (readonly, nonatomic) uint8_t minute;
@property (readonly, nonatomic) unsigned char minute;

/**
 * @brief The minute of the date in local time.
 */
@property (readonly, nonatomic) uint8_t localMinute;
@property (readonly, nonatomic) unsigned char localMinute;

/**
 * @brief The hour of the date.
 */
@property (readonly, nonatomic) uint8_t hour;
@property (readonly, nonatomic) unsigned char hour;

/**
 * @brief The hour of the date in local time.
 */
@property (readonly, nonatomic) uint8_t localHour;
@property (readonly, nonatomic) unsigned char localHour;

/**
 * @brief The day of the month of the date.
 */
@property (readonly, nonatomic) uint8_t dayOfMonth;
@property (readonly, nonatomic) unsigned char dayOfMonth;

/**
 * @brief The day of the month of the date in local time.
 */
@property (readonly, nonatomic) uint8_t localDayOfMonth;
@property (readonly, nonatomic) unsigned char localDayOfMonth;

/**
 * @brief The month of the year of the date.
 */
@property (readonly, nonatomic) uint8_t monthOfYear;
@property (readonly, nonatomic) unsigned char monthOfYear;

/**
 * @brief The month of the year of the date in local time.
 */
@property (readonly, nonatomic) uint8_t localMonthOfYear;
@property (readonly, nonatomic) unsigned char localMonthOfYear;

/**
 * @brief The year of the date.
 */
@property (readonly, nonatomic) uint16_t year;
@property (readonly, nonatomic) unsigned short year;

/**
 * @brief The year of the date in local time.
 */
@property (readonly, nonatomic) uint16_t localYear;
@property (readonly, nonatomic) unsigned short localYear;

/**
 * @brief The day of the week of the date.
 */
@property (readonly, nonatomic) uint8_t dayOfWeek;
@property (readonly, nonatomic) unsigned char dayOfWeek;

/**
 * @brief The day of the week of the date in local time.
 */
@property (readonly, nonatomic) uint8_t localDayOfWeek;
@property (readonly, nonatomic) unsigned char localDayOfWeek;

/**
 * @brief The day of the year of the date.
 */
@property (readonly, nonatomic) uint16_t dayOfYear;
@property (readonly, nonatomic) unsigned short dayOfYear;

/**
 * @brief The day of the year of the date in local time.
 */
@property (readonly, nonatomic) uint16_t localDayOfYear;
@property (readonly, nonatomic) unsigned short localDayOfYear;

/**
 * @brief The seconds since 1970-01-01T00:00:00Z.
 */
@property (readonly, nonatomic) of_time_interval_t timeIntervalSince1970;

/**

Modified src/OFDate.m from [f5afc23b94] to [2789a95e81].

219
220
221
222
223
224
225
226

227
228
229
230
231
232
233
219
220
221
222
223
224
225

226
227
228
229
230
231
232
233







-
+







	31 + 28 + 31 + 30 + 31 + 30 + 31 + 31,
	31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30,
	31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
	31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30,
};

static double
tmAndTzToTime(struct tm *tm, int16_t *tz)
tmAndTzToTime(const struct tm *tm, short tz)
{
	double seconds;

	/* Years */
	seconds = (int64_t)(tm->tm_year - 70) * 31536000;
	/* Days of leap years, excluding the year to look at */
	seconds += (((tm->tm_year + 1899) / 4) - 492) * 86400;
247
248
249
250
251
252
253
254

255
256
257
258
259
260
261
247
248
249
250
251
252
253

254
255
256
257
258
259
260
261







-
+







	/* Hours */
	seconds += tm->tm_hour * 3600;
	/* Minutes */
	seconds += tm->tm_min * 60;
	/* Seconds */
	seconds += tm->tm_sec;
	/* Time zone */
	seconds += -(double)*tz * 60;
	seconds += -(double)tz * 60;

	return seconds;
}

@implementation OFDateSingleton
- (instancetype)autorelease
{
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
485
486
487

488
489
490
491
492
493
494
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
485
486

487
488
489
490
491
492
493
494







-
+







-
+









-
+



-
+






-
+












-
+








- (instancetype)initWithDateString: (OFString *)string
			    format: (OFString *)format
{
	void *pool = objc_autoreleasePoolPush();
	const char *UTF8String = string.UTF8String;
	struct tm tm = { .tm_isdst = -1 };
	int16_t tz = 0;
	short tz = 0;

	if (of_strptime(UTF8String, format.UTF8String, &tm, &tz) !=
	    UTF8String + string.UTF8StringLength)
		@throw [OFInvalidFormatException exception];

	objc_autoreleasePoolPop(pool);

	return [self initWithTimeIntervalSince1970: tmAndTzToTime(&tm, &tz)];
	return [self initWithTimeIntervalSince1970: tmAndTzToTime(&tm, tz)];
}

- (instancetype)initWithLocalDateString: (OFString *)string
				 format: (OFString *)format
{
	void *pool = objc_autoreleasePoolPush();
	const char *UTF8String = string.UTF8String;
	struct tm tm = { .tm_isdst = -1 };
	/*
	 * of_strptime() can never set this to INT16_MAX, no matter what is
	 * of_strptime() can never set this to SHRT_MAX, no matter what is
	 * passed to it, so this is a safe way to figure out if the date
	 * contains a time zone.
	 */
	int16_t tz = INT16_MAX;
	short tz = SHRT_MAX;
	of_time_interval_t seconds;

	if (of_strptime(UTF8String, format.UTF8String, &tm, &tz) !=
	    UTF8String + string.UTF8StringLength)
		@throw [OFInvalidFormatException exception];

	if (tz == INT16_MAX) {
	if (tz == SHRT_MAX) {
#ifdef OF_WINDOWS
		if (func__mktime64 != NULL) {
			if ((seconds = func__mktime64(&tm)) == -1)
				@throw [OFInvalidFormatException exception];
		} else {
#endif
			if ((seconds = mktime(&tm)) == -1)
				@throw [OFInvalidFormatException exception];
#ifdef OF_WINDOWS
		}
#endif
	} else
		seconds = tmAndTzToTime(&tm, &tz);
		seconds = tmAndTzToTime(&tm, tz);

	objc_autoreleasePoolPop(pool);

	return [self initWithTimeIntervalSince1970: seconds];
}

- (instancetype)initWithSerialization: (OFXMLElement *)element
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
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







-
+



-
+


-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+







	[ret retain];

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}

- (uint32_t)microsecond
- (unsigned long)microsecond
{
	of_time_interval_t timeInterval = self.timeIntervalSince1970;

	return (uint32_t)((timeInterval - trunc(timeInterval)) * 1000000);
	return (unsigned long)((timeInterval - trunc(timeInterval)) * 1000000);
}

- (uint8_t)second
- (unsigned char)second
{
	GMTIME_RET(tm_sec)
}

- (uint8_t)minute
- (unsigned char)minute
{
	GMTIME_RET(tm_min)
}

- (uint8_t)localMinute
- (unsigned char)localMinute
{
	LOCALTIME_RET(tm_min)
}

- (uint8_t)hour
- (unsigned char)hour
{
	GMTIME_RET(tm_hour)
}

- (uint8_t)localHour
- (unsigned char)localHour
{
	LOCALTIME_RET(tm_hour)
}

- (uint8_t)dayOfMonth
- (unsigned char)dayOfMonth
{
	GMTIME_RET(tm_mday)
}

- (uint8_t)localDayOfMonth
- (unsigned char)localDayOfMonth
{
	LOCALTIME_RET(tm_mday)
}

- (uint8_t)monthOfYear
- (unsigned char)monthOfYear
{
	GMTIME_RET(tm_mon + 1)
}

- (uint8_t)localMonthOfYear
- (unsigned char)localMonthOfYear
{
	LOCALTIME_RET(tm_mon + 1)
}

- (uint16_t)year
- (unsigned short)year
{
	GMTIME_RET(tm_year + 1900)
}

- (uint16_t)localYear
- (unsigned short)localYear
{
	LOCALTIME_RET(tm_year + 1900)
}

- (uint8_t)dayOfWeek
- (unsigned char)dayOfWeek
{
	GMTIME_RET(tm_wday)
}

- (uint8_t)localDayOfWeek
- (unsigned char)localDayOfWeek
{
	LOCALTIME_RET(tm_wday)
}

- (uint16_t)dayOfYear
- (unsigned short)dayOfYear
{
	GMTIME_RET(tm_yday + 1)
}

- (uint16_t)localDayOfYear
- (unsigned short)localDayOfYear
{
	LOCALTIME_RET(tm_yday + 1)
}

- (OFString *)dateStringWithFormat: (OFConstantString *)format
{
	OFString *ret;

Modified src/OFHTTPRequest.h from [345d23988c] to [8374acae4d].

55
56
57
58
59
60
61
62

63
64

65
66
67
68
69
70
71
55
56
57
58
59
60
61

62
63

64
65
66
67
68
69
70
71







-
+

-
+







 * @struct of_http_request_protocol_version_t \
 *	   OFHTTPRequest.h ObjFW/OFHTTPRequest.h
 *
 * @brief The HTTP version of the HTTP request.
 */
struct OF_BOXABLE of_http_request_protocol_version_t {
	/** The major of the HTTP version */
	uint8_t major;
	unsigned char major;
	/** The minor of the HTTP version */
	uint8_t minor;
	unsigned char minor;
};
typedef struct of_http_request_protocol_version_t
    of_http_request_protocol_version_t;

/**
 * @class OFHTTPRequest OFHTTPRequest.h ObjFW/OFHTTPRequest.h
 *

Modified src/OFHTTPRequest.m from [5fbba85cad] to [517654630c].

204
205
206
207
208
209
210
211

212
213
214
215
216
217
218
204
205
206
207
208
209
210

211
212
213
214
215
216
217
218







-
+







	return hash;
}

- (void)setProtocolVersion: (of_http_request_protocol_version_t)protocolVersion
{
	if (protocolVersion.major != 1 || protocolVersion.minor > 1)
		@throw [OFUnsupportedVersionException exceptionWithVersion:
		    [OFString stringWithFormat: @"%u.%u",
		    [OFString stringWithFormat: @"%hhu.%hhu",
						protocolVersion.major,
						protocolVersion.minor]];

	_protocolVersion = protocolVersion;
}

- (of_http_request_protocol_version_t)protocolVersion
229
230
231
232
233
234
235
236

237
238
239
240


241
242
243
244
245
246
247
248
249

250
251
252
253
254
255
256
229
230
231
232
233
234
235

236
237
238


239
240
241
242
243
244
245
246
247
248

249
250
251
252
253
254
255
256







-
+


-
-
+
+








-
+








	if (components.count != 2)
		@throw [OFInvalidFormatException exception];

	major = [components.firstObject unsignedLongLongValue];
	minor = [components.lastObject unsignedLongLongValue];

	if (major > UINT8_MAX || minor > UINT8_MAX)
	if (major > UCHAR_MAX || minor > UCHAR_MAX)
		@throw [OFOutOfRangeException exception];

	protocolVersion.major = (uint8_t)major;
	protocolVersion.minor = (uint8_t)minor;
	protocolVersion.major = (unsigned char)major;
	protocolVersion.minor = (unsigned char)minor;

	self.protocolVersion = protocolVersion;

	objc_autoreleasePoolPop(pool);
}

- (OFString *)protocolVersionString
{
	return [OFString stringWithFormat: @"%u.%u",
	return [OFString stringWithFormat: @"%hhu.%hhu",
					   _protocolVersion.major,
					   _protocolVersion.minor];
}

- (OFString *)description
{
	void *pool = objc_autoreleasePoolPush();

Modified src/OFHTTPResponse.m from [2c42d95890] to [4e1a4b346b].

251
252
253
254
255
256
257
258

259
260
261
262
263
264
265
251
252
253
254
255
256
257

258
259
260
261
262
263
264
265







-
+







	[super dealloc];
}

- (void)setProtocolVersion: (of_http_request_protocol_version_t)protocolVersion
{
	if (protocolVersion.major != 1 || protocolVersion.minor > 1)
		@throw [OFUnsupportedVersionException exceptionWithVersion:
		    [OFString stringWithFormat: @"%u.%u",
		    [OFString stringWithFormat: @"%hhu.%hhu",
						protocolVersion.major,
						protocolVersion.minor]];

	_protocolVersion = protocolVersion;
}

- (of_http_request_protocol_version_t)protocolVersion
276
277
278
279
280
281
282
283

284
285
286
287


288
289
290
291
292
293
294
295
296

297
298
299
300
301
302
303
276
277
278
279
280
281
282

283
284
285


286
287
288
289
290
291
292
293
294
295

296
297
298
299
300
301
302
303







-
+


-
-
+
+








-
+








	if (components.count != 2)
		@throw [OFInvalidFormatException exception];

	major = [components.firstObject unsignedLongLongValue];
	minor = [components.lastObject unsignedLongLongValue];

	if (major > UINT8_MAX || minor > UINT8_MAX)
	if (major > UCHAR_MAX || minor > UCHAR_MAX)
		@throw [OFOutOfRangeException exception];

	protocolVersion.major = (uint8_t)major;
	protocolVersion.minor = (uint8_t)minor;
	protocolVersion.major = (unsigned char)major;
	protocolVersion.minor = (unsigned char)minor;

	self.protocolVersion = protocolVersion;

	objc_autoreleasePoolPop(pool);
}

- (OFString *)protocolVersionString
{
	return [OFString stringWithFormat: @"%u.%u",
	return [OFString stringWithFormat: @"%hhu.%hhu",
					   _protocolVersion.major,
					   _protocolVersion.minor];
}

- (OFString *)string
{
	return [self stringWithEncoding: OF_STRING_ENCODING_AUTODETECT];

Modified src/OFMapTable.h from [7fe069efae] to [bf028bd496].

73
74
75
76
77
78
79
80

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

80
81
82
83
84
85
86
87







-
+







 */
OF_SUBCLASSING_RESTRICTED
@interface OFMapTable: OFObject <OFCopying, OFFastEnumeration>
{
	of_map_table_functions_t _keyFunctions, _objectFunctions;
	struct of_map_table_bucket *_Nonnull *_Nullable _buckets;
	unsigned long _count, _capacity;
	uint8_t _rotate;
	unsigned char _rotate;
	unsigned long _mutations;
}

/**
 * @brief The key functions used by the map table.
 */
@property (readonly, nonatomic) of_map_table_functions_t keyFunctions;

Modified src/OFTimer.h from [e04cb8b583] to [e351b12ba6].

46
47
48
49
50
51
52
53

54
55
56
57
58
59
60
46
47
48
49
50
51
52

53
54
55
56
57
58
59
60







-
+







@interface OFTimer: OFObject <OFComparing>
{
	OFDate *_fireDate;
	of_time_interval_t _interval;
	id _target;
	id _Nullable _object1, _object2, _object3, _object4;
	SEL _selector;
	uint8_t _arguments;
	unsigned char _arguments;
	bool _repeats;
#ifdef OF_HAVE_BLOCKS
	of_timer_block_t _block;
#endif
	bool _valid;
#ifdef OF_HAVE_THREADS
	OFCondition *_condition;

Modified src/OFTimer.m from [ced46435b5] to [b1d045935e].

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







-
+







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

	@try {
		_fireDate = [fireDate retain];

Modified src/condition.h from [1ae822cd57] to [ed39b78cbd].

39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53







-
+







	volatile int count;
} of_condition_t;
#elif defined(OF_AMIGAOS)
# include <exec/tasks.h>
typedef struct {
	struct of_condition_waiting_task {
		struct Task *task;
		uint8_t sigBit;
		unsigned char sigBit;
		struct of_condition_waiting_task *next;
	} *waitingTasks;
} of_condition_t;
#endif

#ifdef __cplusplus
extern "C" {

Modified src/of_strptime.h from [9a2eae4c29] to [569fe52fbb].

27
28
29
30
31
32
33
34
35


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


34
35
36
37
38
39
40







-
-
+
+





#import "macros.h"

OF_ASSUME_NONNULL_BEGIN

#ifdef __cplusplus
extern "C" {
#endif
extern const char *of_strptime(const char *buf, const char *fmt,
    struct tm *tm, int16_t *tz);
extern const char *of_strptime(const char *buf, const char *fmt, struct tm *tm,
    short *tz);
#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END

Modified src/of_strptime.m from [0542c09e57] to [ef61304e79].

20
21
22
23
24
25
26
27

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

27
28
29
30
31
32
33
34







-
+







#include <string.h>

#include <time.h>

#import "macros.h"

const char *
of_strptime(const char *buffer, const char *format, struct tm *tm, int16_t *tz)
of_strptime(const char *buffer, const char *format, struct tm *tm, short *tz)
{
	enum {
		SEARCH_CONVERSION_SPECIFIER,
		IN_CONVERSION_SPECIFIER
	} state = SEARCH_CONVERSION_SPECIFIER;
	size_t j, bufferLen, formatLen;

177
178
179
180
181
182
183
184
185
186
187




188
189
190
191
192
193
194
177
178
179
180
181
182
183




184
185
186
187
188
189
190
191
192
193
194







-
-
-
-
+
+
+
+








					if (bufferLen < j + 5)
						return NULL;

					if (tz == NULL)
						break;

					*tz = (((int16_t)b[1] - '0') * 600 +
					    ((int16_t)b[2] - '0') * 60 +
					    ((int16_t)b[3] - '0') * 10 +
					    ((int16_t)b[4] - '0')) *
					*tz = (((short)b[1] - '0') * 600 +
					    ((short)b[2] - '0') * 60 +
					    ((short)b[3] - '0') * 10 +
					    ((short)b[4] - '0')) *
					    (b[0] == '-' ? -1 : 1);

					j += 5;
				} else if (buffer[j] == 'Z') {
					if (tz != NULL)
						*tz = 0;

Modified src/thread.h from [b01274c03d] to [bf84b7cea6].

37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51







-
+







# include <exec/semaphores.h>
typedef struct {
	struct Task *task;
	void (*function)(id);
	id object;
	struct SignalSemaphore semaphore;
	struct Task *joinTask;
	uint8_t joinSigBit;
	unsigned char joinSigBit;
	bool detached, done;
} *of_thread_t;
#endif

typedef struct of_thread_attr_t {
	float priority;
	size_t stackSize;