ObjFW  Diff

Differences From Artifact [e1828579de]:

To Artifact [9fd5fb5c63]:

  • File src/OFTarArchive.m — part of check-in [3b43d51006] at 2020-01-14 00:16:04 on branch trunk — More consistent -[close] behavior

    This means refusing to close twice, calling -[close] from -[dealloc] and
    not calling -[cancelAsyncRequests].

    Calling -[cancelAsyncRequests] in -[close] is too dangerous, as -[close]
    gets called by -[dealloc]: If the queue is the last reference to the
    object, at the point where -[cancelAsyncRequests] removes it from the
    queue, the object will start to deallocate and call into
    -[cancelAsyncRequests] again, which is still in the middle of removing
    it and now finds itself with an inconsistent state. (user: js, size: 10273) [annotate] [blame] [check-ins using]


292
293
294
295
296
297
298

299
300
301
302
303
304
305
306
	}

	return self;
}

- (void)dealloc
{

	[self close];

	[_entry release];

	[super dealloc];
}

- (size_t)lowlevelReadIntoBuffer: (void *)buffer







>
|







292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
	}

	return self;
}

- (void)dealloc
{
	if (_stream != nil)
		[self close];

	[_entry release];

	[super dealloc];
}

- (size_t)lowlevelReadIntoBuffer: (void *)buffer
350
351
352
353
354
355
356



357
358
359
360
361
362
363
{
	return ((id <OFReadyForReadingObserving>)_stream)
	    .fileDescriptorForReading;
}

- (void)close
{



	[self of_skip];

	[_stream release];
	_stream = nil;

	[super close];
}







>
>
>







351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
{
	return ((id <OFReadyForReadingObserving>)_stream)
	    .fileDescriptorForReading;
}

- (void)close
{
	if (_stream == nil)
		@throw [OFNotOpenException exceptionWithObject: self];

	[self of_skip];

	[_stream release];
	_stream = nil;

	[super close];
}
425
426
427
428
429
430
431

432
433
434
435
436
437
438
439
	}

	return self;
}

- (void)dealloc
{

	[self close];

	[_entry release];

	[super dealloc];
}

- (size_t)lowlevelWriteBuffer: (const void *)buffer







>
|







429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
	}

	return self;
}

- (void)dealloc
{
	if (_stream != nil)
		[self close];

	[_entry release];

	[super dealloc];
}

- (size_t)lowlevelWriteBuffer: (const void *)buffer
472
473
474
475
476
477
478


479
480
481
482
483
484
485


486
487
488
489
490
491
492
{
	return ((id <OFReadyForWritingObserving>)_stream)
	    .fileDescriptorForWriting;
}

- (void)close
{


	if (_stream == nil)
		return;

	uint64_t remainder = 512 - _entry.size % 512;

	if (_toWrite > 0)
		@throw [OFTruncatedDataException exception];



	if (remainder != 512) {
		bool wasWriteBuffered = _stream.writeBuffered;

		[_stream setWriteBuffered: true];

		while (remainder--)







>
>

<
|
<



>
>







477
478
479
480
481
482
483
484
485
486

487

488
489
490
491
492
493
494
495
496
497
498
499
{
	return ((id <OFReadyForWritingObserving>)_stream)
	    .fileDescriptorForWriting;
}

- (void)close
{
	uint64_t remainder;

	if (_stream == nil)

		@throw [OFNotOpenException exceptionWithObject: self];


	if (_toWrite > 0)
		@throw [OFTruncatedDataException exception];

	remainder = 512 - _entry.size % 512;

	if (remainder != 512) {
		bool wasWriteBuffered = _stream.writeBuffered;

		[_stream setWriteBuffered: true];

		while (remainder--)