ObjFW  Check-in [f42a4471b9]

Overview
Comment:OFData: Ensure init methods return correct class
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f42a4471b958f3ba944be31f8b76054b8a58e4473077a815b73e5aff61dcffef
User & Date: js on 2023-08-09 11:30:54
Other Links: manifest | tags
Context
2023-08-09
12:38
Move some classes out of OFDate.m check-in: 1726744573 user: js tags: trunk
11:41
Merge trunk into 1.0 branch check-in: 7061b887af user: js tags: 1.0
11:30
OFData: Ensure init methods return correct class check-in: f42a4471b9 user: js tags: trunk
10:09
More consistency in naming of private classes check-in: 281b494de4 user: js tags: trunk
Changes

Modified src/OFData.m from [4738b91ed8] to [6b96716473].

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







435





436















437
438
439
440
441
442
443
	}

	return self;
}

- (instancetype)initWithBase64EncodedString: (OFString *)string
{
	bool mutable = [self isKindOfClass: [OFMutableData class]];

	if (!mutable) {
		[self release];
		self = [OFMutableData alloc];
	}

	self = [(OFMutableData *)self initWithCapacity: string.length / 3];

	@try {
		if (!OFBase64Decode((OFMutableData *)self,
		    [string cStringWithEncoding: OFStringEncodingASCII],
		    [string cStringLengthWithEncoding: OFStringEncodingASCII]))
			@throw [OFInvalidFormatException exception];
	} @catch (id e) {
		[self release];
		@throw e;
	}








	if (!mutable)





		[(OFMutableData *)self makeImmutable];
















	return self;
}

- (size_t)count
{
	OF_UNRECOGNIZED_SELECTOR







<
|
<
<
|
|
|
|

<
|








>
>
>
>
>
>
>
|
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
435
436
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
	}

	return self;
}

- (instancetype)initWithBase64EncodedString: (OFString *)string
{

	void *pool = objc_autoreleasePoolPush();


	OFMutableData *data;

	@try {
		data = [OFMutableData data];


		if (!OFBase64Decode(data,
		    [string cStringWithEncoding: OFStringEncodingASCII],
		    [string cStringLengthWithEncoding: OFStringEncodingASCII]))
			@throw [OFInvalidFormatException exception];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	/* Avoid copying if the class already matches. */
	if (data.class == self.class) {
		[self release];
		self = [data retain];
		objc_autoreleasePoolPop(pool);
		return self;
	}

	/*
	 * Make it immutable and avoid copying if the class already matches
	 * after that.
	 */
	@try {
		[data makeImmutable];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	if (data.class == self.class) {
		[self release];
		self = [data retain];
		objc_autoreleasePoolPop(pool);
		return self;
	}

	self = [self initWithItems: data.items count: data.count];

	objc_autoreleasePoolPop(pool);

	return self;
}

- (size_t)count
{
	OF_UNRECOGNIZED_SELECTOR