ObjFW  Diff

Differences From Artifact [f8e15d9a7d]:

To Artifact [8d40ffbf81]:


178
179
180
181
182
183
184



185


186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208



209




210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225

	return self;
}

#ifdef OF_HAVE_FILES
- (instancetype)initWithContentsOfFile: (OFString *)path
{



	@try {


		uintmax_t size = [[[OFFileManager defaultManager]
		    attributesOfItemAtPath: path] fileSize];
		char *buffer;

# if UINTMAX_MAX > SIZE_MAX
		if (size > SIZE_MAX)
			@throw [OFOutOfRangeException exception];
# endif

		buffer = malloc((size_t)size);
		if (buffer == NULL)
			@throw [OFOutOfMemoryException
			    exceptionWithRequestedSize: (size_t)size];

		@try {
			OFFile *file = [[OFFile alloc] initWithPath: path
							       mode: @"r"];
			@try {
				[file readIntoBuffer: buffer
					 exactLength: (size_t)size];
			} @finally {
				[file release];
			}








			self = [self initWithItemsNoCopy: buffer
						   count: (size_t)size
					    freeWhenDone: true];
		} @catch (id e) {
			free(buffer);
			@throw e;
		}
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
#endif








>
>
>

>
>
|

<






|
<



<
|
|
|
|
|
|
|
|
>
>
>

>
>
>
>
|
|
|
|
|
<
<
<
<







178
179
180
181
182
183
184
185
186
187
188
189
190
191
192

193
194
195
196
197
198
199

200
201
202

203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223




224
225
226
227
228
229
230

	return self;
}

#ifdef OF_HAVE_FILES
- (instancetype)initWithContentsOfFile: (OFString *)path
{
	char *buffer = NULL;
	uintmax_t size;

	@try {
		OFFile *file;

		size = [[[OFFileManager defaultManager]
		    attributesOfItemAtPath: path] fileSize];


# if UINTMAX_MAX > SIZE_MAX
		if (size > SIZE_MAX)
			@throw [OFOutOfRangeException exception];
# endif

		if ((buffer = malloc((size_t)size)) == NULL)

			@throw [OFOutOfMemoryException
			    exceptionWithRequestedSize: (size_t)size];


		file = [[OFFile alloc] initWithPath: path
					       mode: @"r"];
		@try {
			[file readIntoBuffer: buffer
				 exactLength: (size_t)size];
		} @finally {
			[file release];
		}
	} @catch (id e) {
		free(buffer);
		[self release];

		@throw e;
	}

	@try {
		self = [self initWithItemsNoCopy: buffer
					   count: (size_t)size
				    freeWhenDone: true];
	} @catch (id e) {
		free(buffer);




		@throw e;
	}

	return self;
}
#endif

349
350
351
352
353
354
355
356
357
358
359

360
361
362
363
364
365
366
367
368
369
370
371
372




373
374
375
376
377
378
379
		[(OFMutableData *)self makeImmutable];

	return self;
}

- (instancetype)initWithSerialization: (OFXMLElement *)element
{
	@try {
		void *pool = objc_autoreleasePoolPush();
		OFString *stringValue;


		if (![[element name] isEqual: [self className]] ||
		    ![[element namespace] isEqual: OF_SERIALIZATION_NS])
			@throw [OFInvalidArgumentException exception];

		stringValue = [element stringValue];

		self = [self initWithBase64EncodedString: stringValue];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}





	return self;
}

- (void)dealloc
{
	if (_freeWhenDone)







<
|
|

>





<
<
<
<




>
>
>
>







354
355
356
357
358
359
360

361
362
363
364
365
366
367
368
369




370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
		[(OFMutableData *)self makeImmutable];

	return self;
}

- (instancetype)initWithSerialization: (OFXMLElement *)element
{

	void *pool = objc_autoreleasePoolPush();
	OFString *stringValue;

	@try {
		if (![[element name] isEqual: [self className]] ||
		    ![[element namespace] isEqual: OF_SERIALIZATION_NS])
			@throw [OFInvalidArgumentException exception];

		stringValue = [element stringValue];




	} @catch (id e) {
		[self release];
		@throw e;
	}

	self = [self initWithBase64EncodedString: stringValue];

	objc_autoreleasePoolPop(pool);

	return self;
}

- (void)dealloc
{
	if (_freeWhenDone)