Skip to content

Commit

Permalink
[pmc] harmonize out of bounds exception strings
Browse files Browse the repository at this point in the history
use less static string memory, but translate it. no context.
"illegal argument" for unsupported negative arguments.
  • Loading branch information
Reini Urban committed Nov 9, 2014
1 parent 43537c1 commit 8607c1e
Show file tree
Hide file tree
Showing 20 changed files with 104 additions and 95 deletions.
2 changes: 1 addition & 1 deletion src/hll.c
Expand Up @@ -357,7 +357,7 @@ Parrot_hll_get_HLL_type(PARROT_INTERP, INTVAL hll_id, INTVAL core_type)

if (core_type >= PARROT_MAX_CLASSES || core_type < 0) {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS,
"FixedIntegerArray: index out of bounds!");
_("index out of bounds"));
}

type_array_attrs = PARROT_FIXEDINTEGERARRAY(type_array);
Expand Down
2 changes: 1 addition & 1 deletion src/pmc/arrayiterator.pmc
Expand Up @@ -682,7 +682,7 @@ out_of_bounds(PARROT_INTERP)
{
ASSERT_ARGS(out_of_bounds)
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS,
"StopIteration");
_("StopIteration"));
}

/*
Expand Down
9 changes: 4 additions & 5 deletions src/pmc/bytebuffer.pmc
Expand Up @@ -90,7 +90,7 @@ Free the buffer when destroying.
unsigned char *content;
if (initial_size < 0)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
_("ByteBuffer: Cannot set buffer size to a negative number (%d)"), initial_size);
_("illegal argument"));
STATICSELF.init();
SET_ATTR_size(INTERP, SELF, initial_size);
SET_ATTR_allocated_size(INTERP, SELF, initial_size);
Expand Down Expand Up @@ -146,7 +146,7 @@ Resize the buffer to the given value.
unsigned char *content;
if (set_size < 0)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"Negative size in ByteBuffer");
_("illegal argument"));

GET_ATTR_allocated_size(INTERP, SELF, allocated_size);
if (set_size == 0) {
Expand Down Expand Up @@ -444,9 +444,8 @@ length in codepoints.
GET_ATTR_size(interp, SELF, size);

if (pos < 0 || pos > size)
Parrot_ex_throw_from_c_args(INTERP, NULL,
EXCEPTION_OUT_OF_BOUNDS,
"get_chars: index out of bounds");
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
_("index out of bounds"));

if (content == NULL) {
STRING *source;
Expand Down
8 changes: 4 additions & 4 deletions src/pmc/fixedbooleanarray.pmc
Expand Up @@ -91,7 +91,7 @@ Initializes the array.

if (size < 0)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
_("FixedBooleanArray: Cannot set array size to a negative number (%d)"), size);
_("illegal argument"));

SET_ATTR_size(INTERP, SELF, size);
SET_ATTR_resize_threshold(INTERP, SELF, size_in_bytes * BITS_PER_CHAR);
Expand Down Expand Up @@ -214,7 +214,7 @@ Returns the integer value of the element at index C<key>.

if (key < 0 || (UINTVAL)key >= size)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"FixedBooleanArray: index out of bounds!");
_("index out of bounds"));

return (bit_array[key / BITS_PER_CHAR] & (1 << (key % BITS_PER_CHAR))) ? 1 : 0;
}
Expand Down Expand Up @@ -373,7 +373,7 @@ Resizes the array to C<size> elements.

if (old_size || size < 1)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"FixedBooleanArray: Can't resize!");
_("Can't resize"));

SET_ATTR_size(INTERP, SELF, size);
SET_ATTR_resize_threshold(INTERP, SELF, size_in_bytes * BITS_PER_CHAR);
Expand All @@ -400,7 +400,7 @@ Sets the integer value of the element at index C<key> to C<value>.

if (key < 0 || (UINTVAL)key >= size)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"FixedBooleanArray: index out of bounds!");
_("index out of bounds"));

if (value)
bit_array[key/BITS_PER_CHAR] |= (1 << (key % BITS_PER_CHAR));
Expand Down
9 changes: 5 additions & 4 deletions src/pmc/fixedfloatarray.pmc
Expand Up @@ -104,7 +104,8 @@ Initializes the array.
VTABLE void init_int(INTVAL size) {
if (size < 0)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
_("FixedFloatArray: Cannot set array size to a negative number (%d)"), size);
_("illegal argument"));

SET_ATTR_size(INTERP, SELF, size);
SET_ATTR_float_array(INTERP, SELF, mem_gc_allocate_n_typed(INTERP, size, FLOATVAL));
PObj_custom_destroy_SET(SELF);
Expand Down Expand Up @@ -247,7 +248,7 @@ Returns the floating-point value of the element at index C<key>.
GET_ATTR_size(INTERP, SELF, size);
if (key < 0 || key >= size)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"FixedFloatArray: index out of bounds!");
_("index out of bounds"));

GET_ATTR_float_array(INTERP, SELF, float_array);
return float_array[key];
Expand Down Expand Up @@ -365,7 +366,7 @@ Resizes the array to C<size> elements.
GET_ATTR_size(INTERP, SELF, old_size);
if (old_size || new_size < 1)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"FixedFloatArray: Can't resize!");
_("Can't resize"));

SET_ATTR_size(INTERP, SELF, new_size);
SET_ATTR_float_array(INTERP, SELF,
Expand Down Expand Up @@ -420,7 +421,7 @@ C<value>.
GET_ATTR_size(INTERP, SELF, size);
if (key < 0 || key >= size)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"FixedFloatArray: index out of bounds!");
_("index out of bounds"));

GET_ATTR_float_array(INTERP, SELF, float_array);
float_array[key] = value;
Expand Down
8 changes: 4 additions & 4 deletions src/pmc/fixedintegerarray.pmc
Expand Up @@ -67,7 +67,7 @@ Initializes the array.
VTABLE void init_int(INTVAL size) {
if (size < 0)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
_("FixedIntegerArray: Cannot set array size to a negative number (%d)"), size);
_("illegal argument"));
if (size > 0) {
SET_ATTR_size(INTERP, SELF, size);
SET_ATTR_int_array(INTERP, SELF, mem_gc_allocate_n_typed(INTERP, size, INTVAL));
Expand Down Expand Up @@ -199,7 +199,7 @@ Returns the integer value of the element at index C<key>.

if (key < 0 || key >= size)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"FixedIntegerArray: index out of bounds!");
_("index out of bounds"));

GET_ATTR_int_array(INTERP, SELF, int_array);
return int_array[key];
Expand Down Expand Up @@ -390,7 +390,7 @@ Resizes the array to C<size> elements.

if (cur_size || size < 1)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"FixedIntegerArray: Can't resize!");
_("Can't resize"));

SET_ATTR_size(INTERP, SELF, size);
GET_ATTR_int_array(INTERP, SELF, int_array);
Expand All @@ -417,7 +417,7 @@ Sets the integer value of the element at index C<key> to C<value>.

if (key < 0 || key >= size)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"FixedIntegerArray: index out of bounds!");
_("index out of bounds"));

GET_ATTR_int_array(INTERP, SELF, int_array);
int_array[key] = value;
Expand Down
12 changes: 6 additions & 6 deletions src/pmc/fixedpmcarray.pmc
Expand Up @@ -115,7 +115,7 @@ Initializes the array.
VTABLE void init_int(INTVAL size) :manual_wb {
if (size < 0)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
_("FixedPMCArray: Cannot set array size to a negative number (%d)"), size);
_("illegal argument"));

SELF.set_integer_native(size);
}
Expand Down Expand Up @@ -364,7 +364,7 @@ Returns the PMC value of the element at index C<key>.

if (key < 0 || key >= PMC_size(SELF))
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
_("FixedPMCArray: index out of bounds!"));
_("index out of bounds"));

data = PMC_array(SELF);
return data[key];
Expand Down Expand Up @@ -414,13 +414,13 @@ array.

if (PMC_size(SELF) && size)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
_("FixedPMCArray: Can't resize!"));
_("Can't resize"));
if (!size)
return;

if (size < 0)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
_("FixedPMCArray: Cannot set array size to a negative number"));
_("illegal argument"));

PMC_size(SELF) = size;
data = mem_gc_allocate_n_typed(INTERP, size, PMC *);
Expand Down Expand Up @@ -572,7 +572,7 @@ Sets the PMC value of the element at index C<key> to C<*src>.

if (key < 0 || key >= PMC_size(SELF))
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
_("FixedPMCArray: index out of bounds!"));
_("index out of bounds"));

data = PMC_array(SELF);
data[key] = src;
Expand Down Expand Up @@ -675,7 +675,7 @@ Returns TRUE is the element at C<key> exists; otherwise returns false.
PMC **data;
if (key < 0 || key >= PMC_size(SELF))
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
_("FixedPMCArray: index out of bounds!"));
_("index out of bounds"));

data = PMC_array(SELF);
return !PMC_IS_NULL(data[key]);
Expand Down
4 changes: 2 additions & 2 deletions src/pmc/fixedstringarray.pmc
Expand Up @@ -293,7 +293,7 @@ Returns the Parrot string value of the element at index C<key>.
GET_ATTR_size(INTERP, SELF, size);
if (key < 0 || (UINTVAL)key >= size)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"FixedStringArray: index out of bounds!");
_("index out of bounds"));

GET_ATTR_str_array(INTERP, SELF, str_array);
return str_array[key];
Expand Down Expand Up @@ -453,7 +453,7 @@ Sets the Parrot string value of the element at index C<key> to C<value>.

if (key < 0 || key >= SELF.elements())
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"FixedStringArray: index out of bounds!");
_("index out of bounds"));

GET_ATTR_str_array(INTERP, SELF, str_array);

Expand Down
4 changes: 2 additions & 2 deletions src/pmc/hashiterator.pmc
Expand Up @@ -277,7 +277,7 @@ the next one.

if (attrs->elements < 0)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"StopIteration");
_("StopIteration"));

ret = Parrot_pmc_new(INTERP, enum_class_HashIteratorKey);
VTABLE_set_pointer_keyed_int(INTERP, ret, 0, attrs->parrot_hash);
Expand Down Expand Up @@ -315,7 +315,7 @@ the next one.

if (attrs->elements < 0)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"StopIteration");
_("StopIteration"));

return Parrot_hash_key_to_int(INTERP, attrs->parrot_hash, attrs->bucket->key);
}
Expand Down
4 changes: 2 additions & 2 deletions src/pmc/integer.pmc
Expand Up @@ -1279,7 +1279,7 @@ and 36, inclusive.

if ((base < 2) || (base > 36))
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"get_as_base: base out of bounds");
_("base out of bounds"));

result = Parrot_str_from_int_base(INTERP, buf,
(HUGEINTVAL)VTABLE_get_integer(INTERP, SELF),
Expand Down Expand Up @@ -1348,7 +1348,7 @@ Set to a random value.
}
if (a == b || a > b) {
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"set_random: range start must be less than range end (%d, %d)", a, b);
"range start must be less than range end (%d, %d)", a, b);
}
{
const double spread = (double)(b - a + 1);
Expand Down
32 changes: 17 additions & 15 deletions src/pmc/mappedbytearray.pmc
Expand Up @@ -139,7 +139,8 @@ Free all resources used.
if (mapping == 0 || mapping == (void *)-1)
Parrot_ex_throw_from_c_args(INTERP, NULL,
EXCEPTION_INVALID_OPERATION,
"mmap failed: %s", strerror(errno));
_("mmap failed: %s"),
strerror(errno));
PObj_custom_destroy_SET(SELF);
SET_ATTR_size(INTERP, SELF, length);
SET_ATTR_buffer(INTERP, SELF, (unsigned char*)mapping);
Expand Down Expand Up @@ -231,11 +232,10 @@ Set the byte at pos to value.
if (size <= 0)
Parrot_ex_throw_from_c_args(INTERP, NULL,
EXCEPTION_INVALID_OPERATION,
"not mapped");
_("not mapped"));
if (pos < 0 || pos >= size)
Parrot_ex_throw_from_c_args(INTERP, NULL,
EXCEPTION_OUT_OF_BOUNDS,
"index out of mapped");
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
_("index out of bounds"));
GET_ATTR_buffer(INTERP, SELF, buffer);
return buffer[pos];
}
Expand All @@ -247,11 +247,10 @@ Set the byte at pos to value.
if (size <= 0)
Parrot_ex_throw_from_c_args(INTERP, NULL,
EXCEPTION_INVALID_OPERATION,
"not mapped");
_("not mapped"));
if (pos < 0 || pos >= size)
Parrot_ex_throw_from_c_args(INTERP, NULL,
EXCEPTION_OUT_OF_BOUNDS,
"index out of mapped");
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
_("index out of bounds"));
GET_ATTR_buffer(INTERP, SELF, buffer);
buffer[pos] = value;
}
Expand Down Expand Up @@ -313,15 +312,16 @@ Map a file by its name. The mode argument can be "r", "w" or "rw",
default:
Parrot_ex_throw_from_c_args(INTERP, NULL,
EXCEPTION_INVALID_OPERATION,
"invalid open mapped mode");
_("invalid open mapped mode"));
}
}
}
mapping = mapfromfilename(interp, filename, &length, flag);
if (mapping == 0 || mapping == (void *)-1)
Parrot_ex_throw_from_c_args(INTERP, NULL,
EXCEPTION_INVALID_OPERATION,
"mmap failed: %s", strerror(errno));
_("mmap failed: %s"),
strerror(errno));
SET_ATTR_size(INTERP, SELF, length);
SET_ATTR_buffer(INTERP, SELF, (unsigned char*)mapping);
#endif
Expand Down Expand Up @@ -383,7 +383,7 @@ Get a string from the buffer content with the specified encoding.
if (pos < 0 || bytelength < 0 || size < 0 || pos + bytelength > size)
Parrot_ex_throw_from_c_args(INTERP, NULL,
EXCEPTION_OUT_OF_BOUNDS,
"get_string: index out of mapped");
_("index out of bounds"));
result = build_string(INTERP, buffer + pos, bytelength, encoding);
RETURN(STRING *result);
#endif
Expand Down Expand Up @@ -523,7 +523,8 @@ mapfromfilename(PARROT_INTERP, ARGIN(STRING *name), ARGMOD(unsigned long *size),
* calling this function.
*/
Parrot_ex_throw_from_c_args(interp, NULL,
EXCEPTION_INTERNAL_NOT_IMPLEMENTED, "invalid mmap mode");
EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
_("invalid mmap mode"));
}
{
char * const name_str = Parrot_str_to_cstring(interp, name);
Expand All @@ -546,7 +547,8 @@ mapfromfilename(PARROT_INTERP, ARGIN(STRING *name), ARGMOD(unsigned long *size),
* calling this function.
*/
Parrot_ex_throw_from_c_args(interp, NULL,
EXCEPTION_INTERNAL_NOT_IMPLEMENTED, "invalid mmap mode");
EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
_("invalid mmap mode"));
}
{
char * const name_str = Parrot_str_to_cstring(interp, name);
Expand Down Expand Up @@ -623,7 +625,7 @@ get_encoded_chars(PARROT_INTERP, ARGIN(PMC *self), INTVAL pos, INTVAL length,
if (pos < 0 || pos > size)
Parrot_ex_throw_from_c_args(interp, NULL,
EXCEPTION_OUT_OF_BOUNDS,
"get_chars: index out of bounds");
_("index out of bounds"));

return Parrot_str_extract_chars(interp, (char *)buffer + pos, size - pos,
length, encoding);
Expand Down
6 changes: 3 additions & 3 deletions src/pmc/packfileview.pmc
Expand Up @@ -285,7 +285,7 @@ Get a FLOATVAL from the constants table, by index
return PMCNULL;
if (idx < 0 || idx >= ct->pmc.const_count) {
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"PMC constant index out of bounds");
_("index out of bounds"));
}
return ct->pmc.constants[idx];
}
Expand All @@ -296,7 +296,7 @@ Get a FLOATVAL from the constants table, by index
return STRINGNULL;
if (idx < 0 || idx >= ct->str.const_count) {
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"STRING constant index out of bounds");
_("index out of bounds"));
}
return ct->str.constants[idx];
}
Expand All @@ -307,7 +307,7 @@ Get a FLOATVAL from the constants table, by index
return 0.0;
if (idx < 0 || idx >= ct->num.const_count) {
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
"PMC constant index out of bounds");
_("index out of bounds"));
}
return ct->num.constants[idx];
}
Expand Down

0 comments on commit 8607c1e

Please sign in to comment.