ObjFW  Check-in [5e44debc07]

Overview
Comment:Rename a few exception-related methods.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 5e44debc0705bdce2a50fabf1f502f29af7a216480648895379c53ab20ec9e16
User & Date: js on 2010-12-11 20:27:54
Other Links: manifest | tags
Context
2010-12-12
00:38
Add -[filtered{Array,Dictionary}UsingBlock]. check-in: 42060f220c user: js tags: trunk
2010-12-11
20:27
Rename a few exception-related methods. check-in: 5e44debc07 user: js tags: trunk
20:13
Add -[description] to OFXMLElement. check-in: 4a8fcc8716 user: js tags: trunk
Changes

Modified src/OFExceptions.h from [c7546e633b] to [997d7c3607].

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

/**
 * \param class_ The class of the object which caused the exception
 * \param size The size of the memory that couldn't be allocated
 * \return A new no memory exception
 */
+ newWithClass: (Class)class_
	  size: (size_t)size;

/**
 * Initializes an already allocated no memory exception.
 *
 * \param class_ The class of the object which caused the exception
 * \param size The size of the memory that couldn't be allocated
 * \return An initialized no memory exception
 */
- initWithClass: (Class)class_
	   size: (size_t)size;

/**
 * \return The size of the memoory that couldn't be allocated
 */
- (size_t)requestedSize;
@end








|









|







94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

/**
 * \param class_ The class of the object which caused the exception
 * \param size The size of the memory that couldn't be allocated
 * \return A new no memory exception
 */
+ newWithClass: (Class)class_
  requestedSize: (size_t)size;

/**
 * Initializes an already allocated no memory exception.
 *
 * \param class_ The class of the object which caused the exception
 * \param size The size of the memory that couldn't be allocated
 * \return An initialized no memory exception
 */
- initWithClass: (Class)class_
  requestedSize: (size_t)size;

/**
 * \return The size of the memoory that couldn't be allocated
 */
- (size_t)requestedSize;
@end

333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357

/**
 * \param class_ The class of the object which caused the exception
 * \param size The requested size of the data that couldn't be read / written
 * \return A new open file failed exception
 */
+ newWithClass: (Class)class_
	  size: (size_t)size;

/**
 * Initializes an already allocated read or write failed exception.
 *
 * \param class_ The class of the object which caused the exception
 * \param size The requested size of the data that couldn't be read / written
 * \return A new open file failed exception
 */
- initWithClass: (Class)class_
	   size: (size_t)size;

/**
 * \return The errno from when the exception was created
 */
- (int)errNo;

/**







|









|







333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357

/**
 * \param class_ The class of the object which caused the exception
 * \param size The requested size of the data that couldn't be read / written
 * \return A new open file failed exception
 */
+ newWithClass: (Class)class_
  requestedSize: (size_t)size;

/**
 * Initializes an already allocated read or write failed exception.
 *
 * \param class_ The class of the object which caused the exception
 * \param size The requested size of the data that couldn't be read / written
 * \return A new open file failed exception
 */
- initWithClass: (Class)class_
  requestedSize: (size_t)size;

/**
 * \return The errno from when the exception was created
 */
- (int)errNo;

/**

Modified src/OFExceptions.m from [f88616d600] to [809a668c5e].

188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}
@end

@implementation OFOutOfMemoryException
+ newWithClass: (Class)class_
	  size: (size_t)size
{
	return [[self alloc] initWithClass: class_
				      size: size];
}

- initWithClass: (Class)class_
	   size: (size_t)size
{
	self = [super initWithClass: class_];

	requestedSize = size;

	return self;
}







|


|



|







188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}
@end

@implementation OFOutOfMemoryException
+ newWithClass: (Class)class_
  requestedSize: (size_t)size
{
	return [[self alloc] initWithClass: class_
			     requestedSize: size];
}

- initWithClass: (Class)class_
  requestedSize: (size_t)size
{
	self = [super initWithClass: class_];

	requestedSize = size;

	return self;
}
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
{
	return mode;
}
@end

@implementation OFReadOrWriteFailedException
+ newWithClass: (Class)class_
	  size: (size_t)size
{
	return [[self alloc] initWithClass: class_
				      size: size];
}

- initWithClass: (Class)class_
{
	Class c = isa;
	[self release];
	@throw [OFNotImplementedException newWithClass: c
					      selector: _cmd];
}

- initWithClass: (Class)class_
	   size: (size_t)size
{
	self = [super initWithClass: class_];

	requestedSize = size;

	if ([class_ isSubclassOfClass: [OFStreamSocket class]])
		errNo = GET_SOCK_ERRNO;







|


|











|







515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
{
	return mode;
}
@end

@implementation OFReadOrWriteFailedException
+ newWithClass: (Class)class_
  requestedSize: (size_t)size
{
	return [[self alloc] initWithClass: class_
			     requestedSize: size];
}

- initWithClass: (Class)class_
{
	Class c = isa;
	[self release];
	@throw [OFNotImplementedException newWithClass: c
					      selector: _cmd];
}

- initWithClass: (Class)class_
  requestedSize: (size_t)size
{
	self = [super initWithClass: class_];

	requestedSize = size;

	if ([class_ isSubclassOfClass: [OFStreamSocket class]])
		errNo = GET_SOCK_ERRNO;

Modified src/OFFile.m from [d71ec31613] to [fc04feb323].

466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
- (size_t)_readNBytes: (size_t)size
	   intoBuffer: (char*)buf
{
	size_t ret;

	if (fd == -1 || eos)
		@throw [OFReadFailedException newWithClass: isa
						      size: size];
	if ((ret = read(fd, buf, size)) == 0)
		eos = YES;

	return ret;
}

- (size_t)_writeNBytes: (size_t)size
	    fromBuffer: (const char*)buf
{
	size_t ret;

	if (fd == -1 || eos || (ret = write(fd, buf, size)) < size)
		@throw [OFWriteFailedException newWithClass: isa
						       size: size];

	return ret;
}

- (void)_seekToOffset: (off_t)offset
{
	if (lseek(fd, offset, SEEK_SET) == -1)







|













|







466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
- (size_t)_readNBytes: (size_t)size
	   intoBuffer: (char*)buf
{
	size_t ret;

	if (fd == -1 || eos)
		@throw [OFReadFailedException newWithClass: isa
					     requestedSize: size];
	if ((ret = read(fd, buf, size)) == 0)
		eos = YES;

	return ret;
}

- (size_t)_writeNBytes: (size_t)size
	    fromBuffer: (const char*)buf
{
	size_t ret;

	if (fd == -1 || eos || (ret = write(fd, buf, size)) < size)
		@throw [OFWriteFailedException newWithClass: isa
					      requestedSize: size];

	return ret;
}

- (void)_seekToOffset: (off_t)offset
{
	if (lseek(fd, offset, SEEK_SET) == -1)

Modified src/OFObject.m from [72238fc133] to [5f364917f3].

497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
	if (SIZE_MAX - PRE_IVAR->memchunks_size < 1 ||
	    memchunks_size > SIZE_MAX / sizeof(void*))
		@throw [OFOutOfRangeException newWithClass: isa];

	if ((memchunks = realloc(PRE_IVAR->memchunks,
	    memchunks_size * sizeof(void*))) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
						       size: memchunks_size];

	PRE_IVAR->memchunks = memchunks;
	PRE_IVAR->memchunks[PRE_IVAR->memchunks_size] = ptr;
	PRE_IVAR->memchunks_size = memchunks_size;
}

- (void*)allocMemoryWithSize: (size_t)size







|







497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
	if (SIZE_MAX - PRE_IVAR->memchunks_size < 1 ||
	    memchunks_size > SIZE_MAX / sizeof(void*))
		@throw [OFOutOfRangeException newWithClass: isa];

	if ((memchunks = realloc(PRE_IVAR->memchunks,
	    memchunks_size * sizeof(void*))) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
					      requestedSize: memchunks_size];

	PRE_IVAR->memchunks = memchunks;
	PRE_IVAR->memchunks[PRE_IVAR->memchunks_size] = ptr;
	PRE_IVAR->memchunks_size = memchunks_size;
}

- (void*)allocMemoryWithSize: (size_t)size
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540

	if (SIZE_MAX - PRE_IVAR->memchunks_size == 0 ||
	    memchunks_size > SIZE_MAX / sizeof(void*))
		@throw [OFOutOfRangeException newWithClass: isa];

	if ((ptr = malloc(size)) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
						       size: size];

	if ((memchunks = realloc(PRE_IVAR->memchunks,
	    memchunks_size * sizeof(void*))) == NULL) {
		free(ptr);
		@throw [OFOutOfMemoryException newWithClass: isa
						       size: memchunks_size];
	}

	PRE_IVAR->memchunks = memchunks;
	PRE_IVAR->memchunks[PRE_IVAR->memchunks_size] = ptr;
	PRE_IVAR->memchunks_size = memchunks_size;

	return ptr;







|





|







520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540

	if (SIZE_MAX - PRE_IVAR->memchunks_size == 0 ||
	    memchunks_size > SIZE_MAX / sizeof(void*))
		@throw [OFOutOfRangeException newWithClass: isa];

	if ((ptr = malloc(size)) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
					      requestedSize: size];

	if ((memchunks = realloc(PRE_IVAR->memchunks,
	    memchunks_size * sizeof(void*))) == NULL) {
		free(ptr);
		@throw [OFOutOfMemoryException newWithClass: isa
					      requestedSize: memchunks_size];
	}

	PRE_IVAR->memchunks = memchunks;
	PRE_IVAR->memchunks[PRE_IVAR->memchunks_size] = ptr;
	PRE_IVAR->memchunks_size = memchunks_size;

	return ptr;
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
	iter = PRE_IVAR->memchunks + PRE_IVAR->memchunks_size;

	while (iter-- > PRE_IVAR->memchunks) {
		if (OF_UNLIKELY(*iter == ptr)) {
			if (OF_UNLIKELY((ptr = realloc(ptr, size)) == NULL))
				@throw [OFOutOfMemoryException
				    newWithClass: isa
					    size: size];

			*iter = ptr;
			return ptr;
		}
	}

	@throw [OFMemoryNotPartOfObjectException newWithClass: isa







|







568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
	iter = PRE_IVAR->memchunks + PRE_IVAR->memchunks_size;

	while (iter-- > PRE_IVAR->memchunks) {
		if (OF_UNLIKELY(*iter == ptr)) {
			if (OF_UNLIKELY((ptr = realloc(ptr, size)) == NULL))
				@throw [OFOutOfMemoryException
				    newWithClass: isa
				    requestedSize: size];

			*iter = ptr;
			return ptr;
		}
	}

	@throw [OFMemoryNotPartOfObjectException newWithClass: isa

Modified src/OFStreamSocket.m from [fc3b5a9ea7] to [66237703fc].

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
	/* FIXME: We want a sane error message on Win32 as well */
	if (eos)
		errno = ENOTCONN;
#endif

	if (eos || (ret = recv(sock, buf, size, 0)) < 0)
		@throw [OFReadFailedException newWithClass: isa
						      size: size];

	if (ret == 0)
		eos = YES;

	return ret;
}








|







67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
	/* FIXME: We want a sane error message on Win32 as well */
	if (eos)
		errno = ENOTCONN;
#endif

	if (eos || (ret = recv(sock, buf, size, 0)) < 0)
		@throw [OFReadFailedException newWithClass: isa
					     requestedSize: size];

	if (ret == 0)
		eos = YES;

	return ret;
}

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
	/* FIXME: We want a sane error message on Win32 as well */
	if (eos)
		errno = ENOTCONN;
#endif

	if (eos || (ret = send(sock, buf, size, 0)) == -1)
		@throw [OFWriteFailedException newWithClass: isa
						       size: size];

	/* This is safe, as we already checked for -1 */
	return ret;
}

#ifdef _WIN32
- (void)setBlocking: (BOOL)enable







|







91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
	/* FIXME: We want a sane error message on Win32 as well */
	if (eos)
		errno = ENOTCONN;
#endif

	if (eos || (ret = send(sock, buf, size, 0)) == -1)
		@throw [OFWriteFailedException newWithClass: isa
					      requestedSize: size];

	/* This is safe, as we already checked for -1 */
	return ret;
}

#ifdef _WIN32
- (void)setBlocking: (BOOL)enable

Modified src/OFString+URLEncoding.m from [7718e4ffef] to [5dc41af38c].

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
	/*
	 * Worst case: 3 times longer than before.
	 * Oh, and we can't use [self allocWithSize:] here as self might be a
	 * @"" literal.
	 */
	if ((ret_c = malloc((length * 3) + 1)) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
						       size: (length * 3) + 1];

	for (i = 0; *s != '\0'; s++) {
		if (isalnum((int)*s) || *s == '-' || *s == '_' || *s == '.' ||
		    *s == '~')
			ret_c[i++] = *s;
		else {
			uint8_t high, low;







|







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
	/*
	 * Worst case: 3 times longer than before.
	 * Oh, and we can't use [self allocWithSize:] here as self might be a
	 * @"" literal.
	 */
	if ((ret_c = malloc((length * 3) + 1)) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
					      requestedSize: (length * 3) + 1];

	for (i = 0; *s != '\0'; s++) {
		if (isalnum((int)*s) || *s == '-' || *s == '_' || *s == '.' ||
		    *s == '~')
			ret_c[i++] = *s;
		else {
			uint8_t high, low;
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
	int st;
	OFString *ret;

	s = string;

	if ((ret_c = malloc(length + 1)) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
						       size: length + 1];

	for (st = 0, i = 0, c = 0; *s; s++) {
		switch (st) {
		case 0:
			if (*s == '%')
				st = 1;
			else if (*s == '+')







|







74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
	int st;
	OFString *ret;

	s = string;

	if ((ret_c = malloc(length + 1)) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
					      requestedSize: length + 1];

	for (st = 0, i = 0, c = 0; *s; s++) {
		switch (st) {
		case 0:
			if (*s == '%')
				st = 1;
			else if (*s == '+')

Modified src/OFString+XMLEscaping.m from [fa81256b88] to [a9e7ed69df].

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
	len = length;

	/*
	 * We can't use allocMemoryWithSize: here as it might be a @"" literal
	 */
	if ((str_c = malloc(len)) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
						       size: len];

	for (i = 0; i < length; i++) {
		switch (string[i]) {
			case '<':
				append = "&lt;";
				append_len = 4;
				break;







|







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
	len = length;

	/*
	 * We can't use allocMemoryWithSize: here as it might be a @"" literal
	 */
	if ((str_c = malloc(len)) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
					      requestedSize: len];

	for (i = 0; i < length; i++) {
		switch (string[i]) {
			case '<':
				append = "&lt;";
				append_len = 4;
				break;
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
		}

		if (append != NULL) {
			if ((tmp = realloc(str_c, len + append_len)) == NULL) {
				free(str_c);
				@throw [OFOutOfMemoryException
				    newWithClass: isa
					    size: len + append_len];
			}
			str_c = tmp;
			len += append_len - 1;

			memcpy(str_c + j, append, append_len);
			j += append_len;
		} else







|







66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
		}

		if (append != NULL) {
			if ((tmp = realloc(str_c, len + append_len)) == NULL) {
				free(str_c);
				@throw [OFOutOfMemoryException
				    newWithClass: isa
				    requestedSize: len + append_len];
			}
			str_c = tmp;
			len += append_len - 1;

			memcpy(str_c + j, append, append_len);
			j += append_len;
		} else

Modified src/OFString.m from [b78aed1909] to [197d311a2d].

585
586
587
588
589
590
591
592

593
594
595
596
597
598
599
600
601
			isUTF8 = YES;
			break;
		case -1:;
			@throw [OFInvalidEncodingException newWithClass: isa];
		}

		if ((string = strdup(string)) == NULL)
			@throw [OFOutOfMemoryException newWithClass: isa

							       size: length +
								     1];

		@try {
			[self addMemoryToPool: string];
		} @catch (id e) {
			free(string);
			@throw e;
		}







|
>
|
<







585
586
587
588
589
590
591
592
593
594

595
596
597
598
599
600
601
			isUTF8 = YES;
			break;
		case -1:;
			@throw [OFInvalidEncodingException newWithClass: isa];
		}

		if ((string = strdup(string)) == NULL)
			@throw [OFOutOfMemoryException
			     newWithClass: isa
			    requestedSize: length + 1];


		@try {
			[self addMemoryToPool: string];
		} @catch (id e) {
			free(string);
			@throw e;
		}