ObjFW  Check-in [3b43d51006]

Overview
Comment: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.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3b43d510061a2f5ef2261ff35e76d948a7121fdd3c95470c4eeeacb64029854a
User & Date: js on 2020-01-14 00:16:04
Other Links: manifest | tags
Context
2020-01-14
22:53
OF{Poll,Select}KernelEventObserver: Throw EBADF check-in: 94479b861b user: js tags: trunk
00:16
More consistent -[close] behavior check-in: 3b43d51006 user: js tags: trunk
2020-01-13
00:18
OFPollKernelEventObserver: Copy FDs check-in: 7e9f70c477 user: js tags: trunk
Changes

Modified src/OFFile.m from [8a16e3648e] to [1f08d5d8ea].

526
527
528
529
530
531
532
533
534
535

536
537
538
539
540
541
542

543
544
545
546
547
{
	return _handle;
}
#endif

- (void)close
{
	if (_handle != OF_INVALID_FILE_HANDLE)
		closeHandle(_handle);


	_handle = OF_INVALID_FILE_HANDLE;

	[super close];
}

- (void)dealloc
{

	[self close];

	[super dealloc];
}
@end







|
|

>







>
|




526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
{
	return _handle;
}
#endif

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

	closeHandle(_handle);
	_handle = OF_INVALID_FILE_HANDLE;

	[super close];
}

- (void)dealloc
{
	if (_handle != OF_INVALID_FILE_HANDLE)
		[self close];

	[super dealloc];
}
@end

Modified src/OFGZIPStream.m from [3efdd5018a] to [f8e93c416d].

61
62
63
64
65
66
67

68
69
70
71
72
73
74
75
	}

	return self;
}

- (void)dealloc
{

	[self close];

	[_inflateStream release];
	[_modificationDate release];

	[super dealloc];
}








>
|







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

	return self;
}

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

	[_inflateStream release];
	[_modificationDate release];

	[super dealloc];
}

319
320
321
322
323
324
325



326
327
328
329
330
331
		    _inflateStream.hasDataInReadBuffer);

	return (super.hasDataInReadBuffer || _stream.hasDataInReadBuffer);
}

- (void)close
{



	[_stream release];
	_stream = nil;

	[super close];
}
@end







>
>
>






320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
		    _inflateStream.hasDataInReadBuffer);

	return (super.hasDataInReadBuffer || _stream.hasDataInReadBuffer);
}

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

	[_stream release];
	_stream = nil;

	[super close];
}
@end

Modified src/OFHTTPClient.m from [90f1585c87] to [cc1af7fa6d].

729
730
731
732
733
734
735

736
737
738
739
740
741
742
743
744
745
746
	}

	return self;
}

- (void)dealloc
{

	[self close];

	[_handler release];
	[_socket release];

	[super dealloc];
}

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







>
|


<







729
730
731
732
733
734
735
736
737
738
739

740
741
742
743
744
745
746
	}

	return self;
}

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

	[_handler release];


	[super dealloc];
}

- (size_t)lowlevelWriteBuffer: (const void *)buffer
		       length: (size_t)length
{
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801


802
803
804
805
806
807
808
{
	return _atEndOfStream;
}

- (void)close
{
	if (_socket == nil)
		return;

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

	_socket.delegate = _handler;
	[_socket asyncReadLine];

	[_socket release];
	_socket = nil;


}

- (int)fileDescriptorForWriting
{
	return _socket.fileDescriptorForWriting;
}
@end







|









>
>







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
{
	return _atEndOfStream;
}

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

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

	_socket.delegate = _handler;
	[_socket asyncReadLine];

	[_socket release];
	_socket = nil;

	[super close];
}

- (int)fileDescriptorForWriting
{
	return _socket.fileDescriptorForWriting;
}
@end
817
818
819
820
821
822
823
824

825
826
827
828
829
830
831
	_socket = [sock retain];

	return self;
}

- (void)dealloc
{
	[_socket release];


	[super dealloc];
}

- (void)setHeaders: (OFDictionary *)headers
{
	OFString *contentLength;







|
>







819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
	_socket = [sock retain];

	return self;
}

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

	[super dealloc];
}

- (void)setHeaders: (OFDictionary *)headers
{
	OFString *contentLength;
981
982
983
984
985
986
987



988
989
990
991
992
993
994
- (bool)hasDataInReadBuffer
{
	return (super.hasDataInReadBuffer || _socket.hasDataInReadBuffer);
}

- (void)close
{



	_atEndOfStream = false;

	[_socket release];
	_socket = nil;

	[super close];
}







>
>
>







984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
- (bool)hasDataInReadBuffer
{
	return (super.hasDataInReadBuffer || _socket.hasDataInReadBuffer);
}

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

	_atEndOfStream = false;

	[_socket release];
	_socket = nil;

	[super close];
}

Modified src/OFHTTPServer.m from [8b4765d161] to [e03c4b06ca].

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

	return self;
}

- (void)dealloc
{
	if (_socket != nil)
		[self close];	/* includes [_socket release] */

	[_server release];
	[_request release];

	[super dealloc];
}








|







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

	return self;
}

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

	[_server release];
	[_request release];

	[super dealloc];
}

673
674
675
676
677
678
679

680
681
682
683
684
685
686
687
	}

	return self;
}

- (void)dealloc
{

	[self close];

	[super dealloc];
}

- (bool)lowlevelIsAtEndOfStream
{
	return _atEndOfStream;







>
|







673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
	}

	return self;
}

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

	[super dealloc];
}

- (bool)lowlevelIsAtEndOfStream
{
	return _atEndOfStream;
716
717
718
719
720
721
722



723
724


725
726
727
728
729
730
731
- (int)fileDescriptorForReading
{
	return _socket.fileDescriptorForReading;
}

- (void)close
{



	[_socket release];
	_socket = nil;


}
@end

#ifdef OF_HAVE_THREADS
@implementation OFHTTPServerThread
- (void)stop
{







>
>
>


>
>







717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
- (int)fileDescriptorForReading
{
	return _socket.fileDescriptorForReading;
}

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

	[_socket release];
	_socket = nil;

	[super close];
}
@end

#ifdef OF_HAVE_THREADS
@implementation OFHTTPServerThread
- (void)stop
{

Modified src/OFInflateStream.m from [89d633e369] to [3cf4fd3893].

204
205
206
207
208
209
210

211
212
213
214
215
216
217
218
	}

	return self;
}

- (void)dealloc
{

	[self close];

	if (_state == HUFFMAN_TREE)
		if (_context.huffmanTree.codeLenTree != NULL)
			of_huffman_tree_release(
			    _context.huffmanTree.codeLenTree);

	if (_state == HUFFMAN_TREE || _state == HUFFMAN_BLOCK) {







>
|







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

	return self;
}

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

	if (_state == HUFFMAN_TREE)
		if (_context.huffmanTree.codeLenTree != NULL)
			of_huffman_tree_release(
			    _context.huffmanTree.codeLenTree);

	if (_state == HUFFMAN_TREE || _state == HUFFMAN_BLOCK) {
675
676
677
678
679
680
681



682
683
684
685
686
687
688
689
690
691
692
{
	return (super.hasDataInReadBuffer || _stream.hasDataInReadBuffer ||
	    _bufferLength - _bufferIndex > 0);
}

- (void)close
{



	/* Give back our buffer to the stream, in case it's shared */
	[_stream unreadFromBuffer: _buffer + _bufferIndex
			   length: _bufferLength - _bufferIndex];
	_bufferIndex = _bufferLength = 0;

	[_stream release];
	_stream = nil;

	[super close];
}
@end







>
>
>











676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
{
	return (super.hasDataInReadBuffer || _stream.hasDataInReadBuffer ||
	    _bufferLength - _bufferIndex > 0);
}

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

	/* Give back our buffer to the stream, in case it's shared */
	[_stream unreadFromBuffer: _buffer + _bufferIndex
			   length: _bufferLength - _bufferIndex];
	_bufferIndex = _bufferLength = 0;

	[_stream release];
	_stream = nil;

	[super close];
}
@end

Modified src/OFLHAArchive.m from [dd17a9200e] to [a09f2c8a17].

148
149
150
151
152
153
154

155
156
157
158
159
160
161
162

	return self;
}
#endif

- (void)dealloc
{

	[self close];

	[super dealloc];
}

- (OFLHAArchiveEntry *)nextEntry
{
	OFLHAArchiveEntry *entry;







>
|







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

	return self;
}
#endif

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

	[super dealloc];
}

- (OFLHAArchiveEntry *)nextEntry
{
	OFLHAArchiveEntry *entry;
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
	return [[(OFLHAArchiveFileWriteStream *)_lastReturnedStream
	    retain] autorelease];
}

- (void)close
{
	if (_stream == nil)
		return;

	[_lastReturnedStream close];
	[_lastReturnedStream release];
	_lastReturnedStream = nil;

	[_stream release];
	_stream = nil;







|







239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
	return [[(OFLHAArchiveFileWriteStream *)_lastReturnedStream
	    retain] autorelease];
}

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

	[_lastReturnedStream close];
	[_lastReturnedStream release];
	_lastReturnedStream = nil;

	[_stream release];
	_stream = nil;
293
294
295
296
297
298
299

300
301
302
303
304
305
306
307
308
309
310
	}

	return self;
}

- (void)dealloc
{

	[self close];

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

	[super dealloc];
}

- (bool)lowlevelIsAtEndOfStream
{







>
|

<
<







294
295
296
297
298
299
300
301
302
303


304
305
306
307
308
309
310
	}

	return self;
}

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



	[_entry release];

	[super dealloc];
}

- (bool)lowlevelIsAtEndOfStream
{
413
414
415
416
417
418
419



420
421
422
423
424
425
426

	_toRead = 0;
	_skipped = true;
}

- (void)close
{



	[self of_skip];

	[_stream release];
	_stream = nil;

	[_decompressedStream release];
	_decompressedStream = nil;







>
>
>







413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429

	_toRead = 0;
	_skipped = true;
}

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

	[self of_skip];

	[_stream release];
	_stream = nil;

	[_decompressedStream release];
	_decompressedStream = nil;
456
457
458
459
460
461
462

463
464
465
466
467
468
469
470
	}

	return self;
}

- (void)dealloc
{

	[self close];

	[_entry release];

	[super dealloc];
}

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







>
|







459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
	}

	return self;
}

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

	[_entry release];

	[super dealloc];
}

- (size_t)lowlevelWriteBuffer: (const void *)buffer
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
}

- (void)close
{
	of_offset_t offset;

	if (_stream == nil)
		return;

	_entry.uncompressedSize = _bytesWritten;
	_entry.compressedSize = _bytesWritten;
	_entry.CRC16 = _CRC16;

	offset = [_stream seekToOffset: 0
				whence:SEEK_CUR];







|







513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
}

- (void)close
{
	of_offset_t offset;

	if (_stream == nil)
		@throw [OFNotOpenException exceptionWithObject: self];

	_entry.uncompressedSize = _bytesWritten;
	_entry.compressedSize = _bytesWritten;
	_entry.CRC16 = _CRC16;

	offset = [_stream seekToOffset: 0
				whence:SEEK_CUR];

Modified src/OFLHADecompressingStream.m from [14251acfde] to [aae6155a72].

119
120
121
122
123
124
125

126
127
128
129
130
131
132
133
	}

	return self;
}

- (void)dealloc
{

	[self close];

	if (_codeLenTree != NULL)
		of_huffman_tree_release(_codeLenTree);
	if (_litLenTree != NULL)
		of_huffman_tree_release(_litLenTree);
	if (_distTree != NULL)
		of_huffman_tree_release(_distTree);







>
|







119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
	}

	return self;
}

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

	if (_codeLenTree != NULL)
		of_huffman_tree_release(_codeLenTree);
	if (_litLenTree != NULL)
		of_huffman_tree_release(_litLenTree);
	if (_distTree != NULL)
		of_huffman_tree_release(_distTree);
512
513
514
515
516
517
518



519
520
521
522
523
524
525
526
527
528
529
530
{
	return (super.hasDataInReadBuffer || _stream.hasDataInReadBuffer ||
	    _bufferLength - _bufferIndex > 0);
}

- (void)close
{



	/* Give back our buffer to the stream, in case it's shared */
	[_stream unreadFromBuffer: _buffer + _bufferIndex
			   length: _bufferLength - _bufferIndex];
	_bytesConsumed -= _bufferLength - _bufferIndex;
	_bufferIndex = _bufferLength = 0;

	[_stream release];
	_stream = nil;

	[super close];
}
@end







>
>
>












513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
{
	return (super.hasDataInReadBuffer || _stream.hasDataInReadBuffer ||
	    _bufferLength - _bufferIndex > 0);
}

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

	/* Give back our buffer to the stream, in case it's shared */
	[_stream unreadFromBuffer: _buffer + _bufferIndex
			   length: _bufferLength - _bufferIndex];
	_bytesConsumed -= _bufferLength - _bufferIndex;
	_bufferIndex = _bufferLength = 0;

	[_stream release];
	_stream = nil;

	[super close];
}
@end

Modified src/OFProcess.m from [7babcc132e] to [dc3506687f].

324
325
326
327
328
329
330





331
332
333
334
335
336
337
338
	}

	return self;
}

- (void)dealloc
{





	[self close];

	[super dealloc];
}

#ifndef OF_WINDOWS
- (void)of_getArgv: (char ***)argv
    forProgramName: (OFString *)programName







>
>
>
>
>
|







324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
	}

	return self;
}

- (void)dealloc
{
#ifndef OF_WINDOWS
	if (_readPipe[0] != -1)
#else
	if (_readPipe[0] != NULL)
#endif
		[self close];

	[super dealloc];
}

#ifndef OF_WINDOWS
- (void)of_getArgv: (char ***)argv
    forProgramName: (OFString *)programName
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
	_writePipe[1] = NULL;
#endif
}

- (void)close
{
#ifndef OF_WINDOWS
	if (_readPipe[0] != -1)



		close(_readPipe[0]);
	if (_writePipe[1] != -1)
		close(_writePipe[1]);

	if (_pid != -1) {
		kill(_pid, SIGTERM);
		waitpid(_pid, &_status, WNOHANG);
	}

	_pid = -1;
	_readPipe[0] = -1;
	_writePipe[1] = -1;
#else
	if (_readPipe[0] != NULL)



		CloseHandle(_readPipe[0]);
	if (_writePipe[1] != NULL)
		CloseHandle(_writePipe[1]);

	if (_process != INVALID_HANDLE_VALUE) {
		TerminateProcess(_process, 0);
		CloseHandle(_process);
	}

	_process = INVALID_HANDLE_VALUE;
	_readPipe[0] = NULL;
	_writePipe[1] = NULL;
#endif

	[super close];
}
@end







|
>
>
>
|
<
<








<

|
>
>
>
|
<
<








<





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
	_writePipe[1] = NULL;
#endif
}

- (void)close
{
#ifndef OF_WINDOWS
	if (_readPipe[0] == -1)
		@throw [OFNotOpenException exceptionWithObject: self];

	[self closeForWriting];
	close(_readPipe[0]);



	if (_pid != -1) {
		kill(_pid, SIGTERM);
		waitpid(_pid, &_status, WNOHANG);
	}

	_pid = -1;
	_readPipe[0] = -1;

#else
	if (_readPipe[0] == NULL)
		@throw [OFNotOpenException exceptionWithObject: self];

	[self closeForWriting];
	CloseHandle(_readPipe[0]);



	if (_process != INVALID_HANDLE_VALUE) {
		TerminateProcess(_process, 0);
		CloseHandle(_process);
	}

	_process = INVALID_HANDLE_VALUE;
	_readPipe[0] = NULL;

#endif

	[super close];
}
@end

Modified src/OFStdIOStream.m from [4ead6e5d4b] to [730550a384].

174
175
176
177
178
179
180





181
182
183
184
185
186
187
188

	return self;
}
#endif

- (void)dealloc
{





	[self close];

	[super dealloc];
}

- (bool)lowlevelIsAtEndOfStream
{
#ifndef OF_AMIGAOS







>
>
>
>
>
|







174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

	return self;
}
#endif

- (void)dealloc
{
#ifndef OF_AMIGAOS
	if (_fd != -1)
#else
	if (_handle != 0)
#endif
		[self close];

	[super dealloc];
}

- (bool)lowlevelIsAtEndOfStream
{
#ifndef OF_AMIGAOS
297
298
299
300
301
302
303
304
305
306

307
308



309
310
311
312
313
314
315
316
	return _fd;
}
#endif

- (void)close
{
#ifndef OF_AMIGAOS
	if (_fd != -1)
		close(_fd);


	_fd = -1;
#else



	if (_closable && _handle != 0)
		Close(_handle);

	_handle = 0;
#endif

	[super close];
}







|
|

>


>
>
>
|







302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
	return _fd;
}
#endif

- (void)close
{
#ifndef OF_AMIGAOS
	if (_fd == -1)
		@throw [OFNotOpenException exceptionWithObject: self];

	close(_fd);
	_fd = -1;
#else
	if (_handle == 0)
		@throw [OFNotOpenException exceptionWithObject: self];

	if (_closable)
		Close(_handle);

	_handle = 0;
#endif

	[super close];
}

Modified src/OFStreamSocket.m from [6026b8fcfc] to [bc21bce60d].

173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
}

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

#ifdef OF_HAVE_SOCKETS
	[self cancelAsyncRequests];
#endif

	closesocket(_socket);
	_socket = INVALID_SOCKET;

	_atEndOfStream = false;

	[super close];
}







<
<
<
<







173
174
175
176
177
178
179




180
181
182
183
184
185
186
}

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





	closesocket(_socket);
	_socket = INVALID_SOCKET;

	_atEndOfStream = false;

	[super close];
}

Modified src/OFTarArchive.m from [e1828579de] to [9fd5fb5c63].

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

Modified src/OFZIPArchive.m from [0b0c4f5246] to [f2e2222c23].

244
245
246
247
248
249
250

251
252
253
254
255
256
257
258

	return self;
}
#endif

- (void)dealloc
{

	[self close];

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








>
|







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

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

	objc_autoreleasePoolPop(pool);
}

- (void)close
{
	if (_stream == nil)
		return;

	[self of_closeLastReturnedStream];

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








|







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

	objc_autoreleasePoolPop(pool);
}

- (void)close
{
	if (_stream == nil)
		@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
	}

	return self;
}

- (void)dealloc
{

	[self close];

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

	[super dealloc];
}

- (bool)lowlevelIsAtEndOfStream
{







>
|

<
<







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



	[_entry release];

	[super dealloc];
}

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



850
851
852
853
854
855
856
{
	return ((id <OFReadyForReadingObserving>)_decompressedStream)
	    .fileDescriptorForReading;
}

- (void)close
{



	[_stream release];
	_stream = nil;

	[_decompressedStream release];
	_decompressedStream = nil;

	[super close];







>
>
>







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
	_CRC32 = ~0;

	return self;
}

- (void)dealloc
{

	[self close];

	[_stream release];
	[_entry release];

	[super dealloc];
}

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







>
|

<







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


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

	return bytesWritten;
}

- (void)close
{
	if (_stream == nil)
		return;

	[_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);
}


@end







|















|
>
>

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