Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -54,11 +54,11 @@ } - (void*)item: (size_t)item { if (item >= items) - [[OFOutOfRangeException newWithObject: self] raise]; + @throw [OFOutOfRangeException newWithObject: self]; return data + item * itemsize; } - (void*)last @@ -67,11 +67,11 @@ } - add: (void*)item { if (SIZE_MAX - items < 1) - [[OFOutOfRangeException newWithObject: self] raise]; + @throw [OFOutOfRangeException newWithObject: self]; data = [self resizeMem: data toNItems: items + 1 ofSize: itemsize]; @@ -82,11 +82,11 @@ - addNItems: (size_t)nitems fromCArray: (void*)carray { if (nitems > SIZE_MAX - items) - [[OFOutOfRangeException newWithObject: self] raise]; + @throw [OFOutOfRangeException newWithObject: self]; data = [self resizeMem: data toNItems: items + nitems ofSize: itemsize]; @@ -97,11 +97,11 @@ } - removeNItems: (size_t)nitems { if (nitems > items) - [[OFOutOfRangeException newWithObject: self] raise]; + @throw [OFOutOfRangeException newWithObject: self]; data = [self resizeMem: data toNItems: items - nitems ofSize: itemsize]; @@ -131,11 +131,11 @@ - add: (void*)item { size_t nsize; if (SIZE_MAX - items < 1 || items + 1 > SIZE_MAX / itemsize) - [[OFOutOfRangeException newWithObject: self] raise]; + @throw [OFOutOfRangeException newWithObject: self]; nsize = ((items + 1) * itemsize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMem: data @@ -151,11 +151,11 @@ fromCArray: (void*)carray { size_t nsize; if (nitems > SIZE_MAX - items || items + nitems > SIZE_MAX / itemsize) - [[OFOutOfRangeException newWithObject: self] raise]; + @throw [OFOutOfRangeException newWithObject: self]; nsize = ((items + nitems) * itemsize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMem: data @@ -171,11 +171,11 @@ - removeNItems: (size_t)nitems { size_t nsize; if (nitems > items) - [[OFOutOfRangeException newWithObject: self] raise]; + @throw [OFOutOfRangeException newWithObject: self]; nsize = ((items - nitems) * itemsize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMem: data Index: src/OFExceptions.h ================================================================== --- src/OFExceptions.h +++ src/OFExceptions.h @@ -38,16 +38,10 @@ */ - initWithObject: (id)obj; - free; -/** - * Raises an OFException and aborts execution if the exception is not caught. - */ - -- raise; - /** * \return An error message for the exception as a C String */ - (char*)cString; @end Index: src/OFExceptions.m ================================================================== --- src/OFExceptions.m +++ src/OFExceptions.m @@ -50,16 +50,10 @@ free(string); return [super free]; } -- raise -{ - @throw self; - return self; -} - - (char*)cString { return string; } @end Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -67,13 +67,13 @@ - initWithPath: (const char*)path andMode: (const char*)mode { if ((self = [super init])) { if ((fp = fopen(path, mode)) == NULL) - [[OFOpenFileFailedException newWithObject: self - andPath: path - andMode: mode] raise]; + @throw [OFOpenFileFailedException newWithObject: self + andPath: path + andMode: mode]; } return self; } - free @@ -92,13 +92,13 @@ intoBuffer: (uint8_t*)buf { size_t ret; if ((ret = fread(buf, size, nitems, fp)) == 0 && !feof(fp)) - [[OFReadFailedException newWithObject: self - andSize: size - andNItems: nitems] raise]; + @throw [OFReadFailedException newWithObject: self + andSize: size + andNItems: nitems]; return ret; } - (size_t)readNBytes: (size_t)size @@ -141,13 +141,13 @@ { size_t ret; if ((ret = fwrite(buf, size, nitems, fp)) == 0 && size != 0 && nitems != 0) - [[OFWriteFailedException newWithObject: self - andSize: size - andNItems: nitems] raise]; + @throw [OFWriteFailedException newWithObject: self + andSize: size + andNItems: nitems]; return ret; } - (size_t)writeNBytes: (size_t)size Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -58,21 +58,21 @@ memchunks_size = __memchunks_size + 1; if (SIZE_MAX - __memchunks_size == 0 || memchunks_size > SIZE_MAX / sizeof(void*)) - [[OFOutOfRangeException newWithObject: self] raise]; + @throw [OFOutOfRangeException newWithObject: self]; if ((memchunks = realloc(__memchunks, memchunks_size * sizeof(void*))) == NULL) - [[OFNoMemException newWithObject: self - andSize: memchunks_size] raise]; + @throw [OFNoMemException newWithObject: self + andSize: memchunks_size]; if ((ptr = malloc(size)) == NULL) { free(memchunks); - [[OFNoMemException newWithObject: self - andSize: size] raise]; + @throw [OFNoMemException newWithObject: self + andSize: size]; } __memchunks = memchunks; __memchunks[__memchunks_size] = ptr; __memchunks_size = memchunks_size; @@ -85,11 +85,11 @@ { if (nitems == 0 || size == 0) return NULL; if (nitems > SIZE_MAX / size) - [[OFOutOfRangeException newWithObject: self] raise]; + @throw [OFOutOfRangeException newWithObject: self]; return [self getMemWithSize: nitems * size]; } - (void*)resizeMem: (void*)ptr @@ -108,20 +108,20 @@ iter = __memchunks + __memchunks_size; while (iter-- > __memchunks) { if (OF_UNLIKELY(*iter == ptr)) { if (OF_UNLIKELY((ptr = realloc(ptr, size)) == NULL)) - [[OFNoMemException newWithObject: self - andSize: size] raise]; + @throw [OFNoMemException newWithObject: self + andSize: size]; *iter = ptr; return ptr; } } - [[OFMemNotPartOfObjException newWithObject: self - andPointer: ptr] raise]; + @throw [OFMemNotPartOfObjException newWithObject: self + andPointer: ptr]; return NULL; /* never reached, but makes gcc happy */ } - (void*)resizeMem: (void*)ptr toNItems: (size_t)nitems @@ -137,11 +137,11 @@ [self freeMem: ptr]; return NULL; } if (nitems > SIZE_MAX / size) - [[OFOutOfRangeException newWithObject: self] raise]; + @throw [OFOutOfRangeException newWithObject: self]; memsize = nitems * size; return [self resizeMem: ptr toSize: memsize]; } @@ -161,12 +161,12 @@ memchunks_size = __memchunks_size - 1; last = __memchunks[memchunks_size]; if (OF_UNLIKELY(__memchunks_size == 0 || memchunks_size > SIZE_MAX / sizeof(void*))) - [[OFOutOfRangeException newWithObject: self] - raise]; + @throw [OFOutOfRangeException + newWithObject: self]; if (OF_UNLIKELY(memchunks_size == 0)) { free(ptr); free(__memchunks); @@ -176,14 +176,13 @@ return self; } if (OF_UNLIKELY((memchunks = realloc(__memchunks, memchunks_size * sizeof(void*))) == NULL)) - [[OFNoMemException newWithObject: self - andSize: - memchunks_size] - raise]; + @throw [OFNoMemException + newWithObject: self + andSize: memchunks_size]; free(ptr); __memchunks = memchunks; __memchunks[i] = last; __memchunks_size = memchunks_size; @@ -190,10 +189,10 @@ return self; } } - [[OFMemNotPartOfObjException newWithObject: self - andPointer: ptr] raise]; + @throw [OFMemNotPartOfObjException newWithObject: self + andPointer: ptr]; return self; /* never reached, but makes gcc happy */ } @end Index: src/OFXMLFactory.m ================================================================== --- src/OFXMLFactory.m +++ src/OFXMLFactory.m @@ -33,11 +33,11 @@ { char *str2; size_t len2; if (add > SIZE_MAX - *len) - [[OFOutOfRangeException newWithObject: nil] raise]; + @throw [OFOutOfRangeException newWithObject: nil]; len2 = *len + add; if ((str2 = realloc(*str, len2)) == NULL) { if (*str) free(*str); @@ -56,15 +56,15 @@ { wchar_t *str2; size_t len2; if (add > SIZE_MAX - *len) - [[OFOutOfRangeException newWithObject: nil] raise]; + @throw [OFOutOfRangeException newWithObject: nil]; len2 = *len + add; if (len2 > SIZE_MAX / sizeof(wchar_t)) - [[OFOutOfRangeException newWithObject: nil] raise]; + @throw [OFOutOfRangeException newWithObject: nil]; if ((str2 = realloc(*str, len2 * sizeof(wchar_t))) == NULL) { if (*str) free(*str); *str = NULL; @@ -115,51 +115,51 @@ char *ret; size_t i, j, len, nlen; len = nlen = strlen(s); if (SIZE_MAX - len < 1) - [[OFOutOfRangeException newWithObject: nil] raise]; + @throw [OFOutOfRangeException newWithObject: nil]; nlen++; if ((ret = malloc(nlen)) == NULL) - [[OFNoMemException newWithObject: nil - andSize: nlen] raise]; + @throw [OFNoMemException newWithObject: nil + andSize: nlen]; for (i = j = 0; i < len; i++) { switch (s[i]) { case '<': if (OF_UNLIKELY(!xf_add2chars(&ret, &nlen, &j, "<"))) - [[OFNoMemException newWithObject: nil - andSize: nlen + 4] - raise]; + @throw [OFNoMemException + newWithObject: nil + andSize: nlen + 4]; break; case '>': if (OF_UNLIKELY(!xf_add2chars(&ret, &nlen, &j, ">"))) - [[OFNoMemException newWithObject: nil - andSize: nlen + 4] - raise]; + @throw [OFNoMemException + newWithObject: nil + andSize: nlen + 4]; break; case '"': if (OF_UNLIKELY(!xf_add2chars(&ret, &nlen, &j, """))) - [[OFNoMemException newWithObject: nil - andSize: nlen + 6] - raise]; + @throw [OFNoMemException + newWithObject: nil + andSize: nlen + 6]; break; case '\'': if (OF_UNLIKELY(!xf_add2chars(&ret, &nlen, &j, "'"))) - [[OFNoMemException newWithObject: nil - andSize: nlen + 6] - raise]; + @throw [OFNoMemException + newWithObject: nil + andSize: nlen + 6]; break; case '&': if (OF_UNLIKELY(!xf_add2chars(&ret, &nlen, &j, "&"))) - [[OFNoMemException newWithObject: nil - andSize: nlen + 5] - raise]; + @throw [OFNoMemException + newWithObject: nil + andSize: nlen + 5]; break; default: ret[j++] = s[i]; break; } @@ -174,67 +174,61 @@ wchar_t *ret; size_t i, j, len, nlen; len = nlen = wcslen(s); if (SIZE_MAX - len < 1) - [[OFOutOfRangeException newWithObject: nil] raise]; + @throw [OFOutOfRangeException newWithObject: nil]; nlen++; if (nlen > SIZE_MAX / sizeof(wchar_t)) - [[OFOutOfRangeException newWithObject: nil] raise]; + @throw [OFOutOfRangeException newWithObject: nil]; if ((ret = malloc(nlen * sizeof(wchar_t))) == NULL) - [[OFNoMemException newWithObject: nil - andSize: nlen * sizeof(wchar_t)] - raise]; + @throw [OFNoMemException newWithObject: nil + andSize: nlen * sizeof(wchar_t)]; for (i = j = 0; i < len; i++) { switch (s[i]) { case L'<': if (OF_UNLIKELY(!xf_add2wchars(&ret, &nlen, &j, L"<"))) - [[OFNoMemException newWithObject: nil - andSize: (nlen + 4) * - sizeof( - wchar_t)] - raise]; + @throw [OFNoMemException + newWithObject: nil + andSize: (nlen + 4) * + sizeof(wchar_t)]; break; case L'>': if (OF_UNLIKELY(!xf_add2wchars(&ret, &nlen, &j, L">"))) - [[OFNoMemException newWithObject: nil - andSize: (nlen + 4) * - sizeof( - wchar_t)] - raise]; + @throw [OFNoMemException + newWithObject: nil + andSize: (nlen + 4) * + sizeof(wchar_t)]; break; case L'"': if (OF_UNLIKELY(!xf_add2wchars(&ret, &nlen, &j, L"""))) - [[OFNoMemException newWithObject: nil - andSize: (nlen + 6) * - sizeof( - wchar_t)] - raise]; + @throw [OFNoMemException + newWithObject: nil + andSize: (nlen + 6) * + sizeof(wchar_t)]; break; case L'\'': if (OF_UNLIKELY(!xf_add2wchars(&ret, &nlen, &j, L"'"))) - [[OFNoMemException newWithObject: nil - andSize: (nlen + 6) * - sizeof( - wchar_t)] - raise]; + @throw [OFNoMemException + newWithObject: nil + andSize: (nlen + 6) * + sizeof(wchar_t)]; break; case L'&': if (OF_UNLIKELY(!xf_add2wchars(&ret, &nlen, &j, L"&"))) - [[OFNoMemException newWithObject: nil - andSize: (nlen + 5) * - sizeof( - wchar_t)] - raise]; + @throw [OFNoMemException + newWithObject: nil + andSize: (nlen + 5) * + sizeof(wchar_t)]; break; default: ret[j++] = s[i]; break; } @@ -253,16 +247,16 @@ va_list args; /* Start of tag */ len = strlen(name); if (SIZE_MAX - len < 3) - [[OFOutOfRangeException newWithObject: nil] raise]; + @throw [OFOutOfRangeException newWithObject: nil]; len += 3; if ((xml = malloc(len)) == NULL) - [[OFNoMemException newWithObject: nil - andSize: len] raise]; + @throw [OFNoMemException newWithObject: nil + andSize: len]; i = 0; xml[i++] = '<'; memcpy(xml + i, name, strlen(name)); i += strlen(name); @@ -284,15 +278,14 @@ } if (OF_UNLIKELY(!xf_resize_chars(&xml, &len, 1 + strlen(arg) + 2 + strlen(esc_val) + 1))) { free(esc_val); - [[OFNoMemException newWithObject: nil - andSize: len + 1 + - strlen(arg) + 2 + - strlen(esc_val) + 1] - raise]; + @throw [OFNoMemException + newWithObject: nil + andSize: len + 1 + strlen(arg) + 2 + + strlen(esc_val) + 1]; } xml[i++] = ' '; memcpy(xml + i, arg, strlen(arg)); i += strlen(arg); @@ -308,26 +301,23 @@ /* End of tag */ if (close) { if (data == NULL) { if (!xf_resize_chars(&xml, &len, 2 - 1)) - [[OFNoMemException newWithObject: nil - andSize: len + 2 - 1] - raise]; + @throw [OFNoMemException + newWithObject: nil + andSize: len + 2 - 1]; xml[i++] = '/'; xml[i++] = '>'; } else { if (!xf_resize_chars(&xml, &len, 1 + strlen(data) + 2 + strlen(name) + 1 - 1)) - [[OFNoMemException newWithObject: nil - andSize: len + 1 + - strlen(data) + - 2 + - strlen(name) + - 1 - 1] - raise]; + @throw [OFNoMemException + newWithObject: nil + andSize: len + 1 + strlen(data) + 2 + + strlen(name) + 1 - 1]; xml[i++] = '>'; memcpy(xml + i, data, strlen(data)); i += strlen(data); xml[i++] = '<'; @@ -352,19 +342,19 @@ va_list args; /* Start of tag */ len = wcslen(name); if (SIZE_MAX - len < 3) - [[OFOutOfRangeException newWithObject: nil] raise]; + @throw [OFOutOfRangeException newWithObject: nil]; len += 3; if (len > SIZE_MAX / sizeof(wchar_t)) - [[OFOutOfRangeException newWithObject: nil] raise]; + @throw [OFOutOfRangeException newWithObject: nil]; if ((xml = malloc(len * sizeof(wchar_t))) == NULL) - [[OFNoMemException newWithObject: nil - andSize: len * sizeof(wchar_t)] raise]; + @throw [OFNoMemException newWithObject: nil + andSize: len * sizeof(wchar_t)]; i = 0; xml[i++] = L'<'; wmemcpy(xml + i, name, wcslen(name)); i += wcslen(name); @@ -386,16 +376,15 @@ } if (OF_UNLIKELY(!xf_resize_wchars(&xml, &len, 1 + wcslen(arg) + 2 + wcslen(esc_val) + 1))) { free(esc_val); - [[OFNoMemException newWithObject: nil - andSize: (len + 1 + - wcslen(arg) + 2 + - wcslen(esc_val) + 1) * - sizeof(wchar_t)] - raise]; + @throw [OFNoMemException + newWithObject: nil + andSize: (len + 1 + wcslen(arg) + 2 + + wcslen(esc_val) + 1) * + sizeof(wchar_t)]; } xml[i++] = L' '; wmemcpy(xml + i, arg, wcslen(arg)); i += wcslen(arg); @@ -411,30 +400,25 @@ /* End of tag */ if (close) { if (data == NULL) { if (!xf_resize_wchars(&xml, &len, 2 - 1)) - [[OFNoMemException newWithObject: nil - andSize: (len + 2 - - 1) * sizeof( - wchar_t)] - raise]; + @throw [OFNoMemException + newWithObject: nil + andSize: (len + 2 - 1) * + sizeof(wchar_t)]; xml[i++] = L'/'; xml[i++] = L'>'; } else { if (!xf_resize_wchars(&xml, &len, 1 + wcslen(data) + 2 + wcslen(name) + 1 - 1)) - [[OFNoMemException newWithObject: nil - andSize: (len + 1 + - wcslen(data) + - 2 + - wcslen(name) + - 1 - - 1) * sizeof( - wchar_t)] - raise]; + @throw [OFNoMemException + newWithObject: nil + andSize: (len + 1 + wcslen(data) + 2 + + wcslen(name) + 1 - 1) * + sizeof(wchar_t)]; xml[i++] = L'>'; wmemcpy(xml + i, data, wcslen(data)); i += wcslen(data); xml[i++] = L'<'; @@ -458,26 +442,26 @@ if (strs[0] == NULL) return NULL; len = strlen(*strs); if (SIZE_MAX - len < 1) - [[OFOutOfRangeException newWithObject: nil] raise]; + @throw [OFOutOfRangeException newWithObject: nil]; len++; if ((ret = malloc(len)) == NULL) - [[OFNoMemException newWithObject: nil - andSize: len] raise]; + @throw [OFNoMemException newWithObject: nil + andSize: len]; memcpy(ret, strs[0], len - 1); pos = len - 1; for (i = 1; strs[i] != NULL; i++) { if (OF_UNLIKELY(!xf_add2chars(&ret, &len, &pos, strs[i]))) { free(ret); - [[OFNoMemException newWithObject: nil - andSize: len + strlen(strs[i])] - raise]; + @throw [OFNoMemException + newWithObject: nil + andSize: len + strlen(strs[i])]; } } for (i = 0; strs[i] != NULL; i++) free(strs[i]); @@ -494,31 +478,30 @@ if (strs[0] == NULL) return NULL; len = wcslen(*strs); if (SIZE_MAX - len < 1) - [[OFOutOfRangeException newWithObject: nil] raise]; + @throw [OFOutOfRangeException newWithObject: nil]; len++; if (len > SIZE_MAX - sizeof(wchar_t)) - [[OFOutOfRangeException newWithObject: nil] raise]; + @throw [OFOutOfRangeException newWithObject: nil]; if ((ret = malloc(len * sizeof(wchar_t))) == NULL) - [[OFNoMemException newWithObject: nil - andSize: len * sizeof(wchar_t)] raise]; + @throw [OFNoMemException newWithObject: nil + andSize: len * sizeof(wchar_t)]; wmemcpy(ret, strs[0], len - 1); pos = len - 1; for (i = 1; strs[i] != NULL; i++) { if (!xf_add2wchars(&ret, &len, &pos, strs[i])) { free(ret); - [[OFNoMemException newWithObject: nil - andSize: (wcslen(strs[i]) + - len) * sizeof( - wchar_t)] - raise]; + @throw [OFNoMemException + newWithObject: nil + andSize: (wcslen(strs[i]) + len) * + sizeof(wchar_t)]; } } for (i = 0; strs[i] != NULL; i++) free(strs[i]);