ObjFW  Diff

Differences From Artifact [0b0c4f5246]:

To Artifact [f2e2222c23]:

  • File src/OFZIPArchive.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: 23778) [annotate] [blame] [check-ins using]


244
245
246
247
248
249
250

251

252
253
254
255
256
257
258
244
245
246
247
248
249
250
251

252
253
254
255
256
257
258
259







+
-
+








	return self;
}
#endif

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

	[_stream release];
	[_archiveComment release];
	[_entries release];
	[_pathToEntryMap release];
	[_lastReturnedStream release];

613
614
615
616
617
618
619
620

621
622
623
624
625
626
627
614
615
616
617
618
619
620

621
622
623
624
625
626
627
628







-
+








	objc_autoreleasePoolPop(pool);
}

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

	[self of_closeLastReturnedStream];

	if (_mode == OF_ZIP_ARCHIVE_MODE_WRITE ||
	    _mode == OF_ZIP_ARCHIVE_MODE_APPEND)
		[self of_writeCentralDirectory];

766
767
768
769
770
771
772

773

774
775
776
777
778
779
780
781
782
783
767
768
769
770
771
772
773
774

775
776


777
778
779
780
781
782
783







+
-
+

-
-







	}

	return self;
}

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

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

	[super dealloc];
}

- (bool)lowlevelIsAtEndOfStream
{
843
844
845
846
847
848
849



850
851
852
853
854
855
856
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859







+
+
+







{
	return ((id <OFReadyForReadingObserving>)_decompressedStream)
	    .fileDescriptorForReading;
}

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

	[_stream release];
	_stream = nil;

	[_decompressedStream release];
	_decompressedStream = nil;

	[super close];
868
869
870
871
872
873
874

875

876
877
878
879
880
881
882
883
884
871
872
873
874
875
876
877
878

879
880

881
882
883
884
885
886
887







+
-
+

-







	_CRC32 = ~0;

	return self;
}

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

	[_stream release];
	[_entry release];

	[super dealloc];
}

- (size_t)lowlevelWriteBuffer: (const void *)buffer
		       length: (size_t)length
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
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







-
+















-
+
+
+


	return bytesWritten;
}

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

	[_stream writeLittleEndianInt32: 0x08074B50];
	[_stream writeLittleEndianInt32: _CRC32];
	[_stream writeLittleEndianInt64: _bytesWritten];
	[_stream writeLittleEndianInt64: _bytesWritten];

	[_stream release];
	_stream = nil;

	_entry.CRC32 = ~_CRC32;
	_entry.compressedSize = _bytesWritten;
	_entry.uncompressedSize = _bytesWritten;
	[_entry makeImmutable];

	_bytesWritten += (2 * 4 + 2 * 8);
}

	[super close];
}
@end