Skip to content

Commit

Permalink
new BoundsError: style fixes and renamings
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored and kshyatt committed Jan 2, 2015
1 parent a563c47 commit 2aed2e4
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 53 deletions.
5 changes: 2 additions & 3 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,10 @@ abstract Exception

immutable BoundsError <: Exception
a::Any
i::Union(Tuple, Int)
i::Any
BoundsError() = new()
BoundsError(a::ANY) = new(a)
BoundsError(a::ANY, i::Tuple) = new(a,i)
BoundsError(a::ANY, i::Int) = new(a,i)
BoundsError(a::ANY, i::ANY) = new(a,i)
end
immutable DivideError <: Exception end
immutable DomainError <: Exception end
Expand Down
8 changes: 3 additions & 5 deletions base/replutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,17 @@ writemime(io::IO, ::MIME"text/plain", t::Union(KeyIterator, ValueIterator)) =

showerror(io::IO, e) = show(io, e)

function show(io::IO, be::BoundsError)
print(io, "BoundsError(")
function showerror(io::IO, be::BoundsError)
print(io, "BoundsError")
if isdefined(be, :a)
print(io, "\n attempt to access ")
print(io, ": attempt to access ")
writemime(io, MIME"text/plain"(), be.a)
if isdefined(be, :i)
print(io, "\n at index [")
print_joined(io, be.i, ',')
print(io, ']')
end
print(io, "\n ")
end
print(io, ')')
end

function showerror(io::IO, e::TypeError)
Expand Down
4 changes: 2 additions & 2 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jl_value_t *jl_overflow_exception;
jl_value_t *jl_inexact_exception;
jl_value_t *jl_undefref_exception;
jl_value_t *jl_interrupt_exception;
jl_value_t *jl_bounds_exception;
jl_datatype_t *jl_boundserror_type;
jl_value_t *jl_memory_exception;

jl_sym_t *call_sym; jl_sym_t *dots_sym;
Expand Down Expand Up @@ -247,7 +247,7 @@ jl_value_t *jl_get_nth_field_checked(jl_value_t *v, size_t i)
{
jl_datatype_t *st = (jl_datatype_t*)jl_typeof(v);
if (i >= jl_tuple_len(st->names))
jl_new_bounds_error_i(v, i+1);
jl_bounds_error_int(v, i+1);
size_t offs = jl_field_offset(st,i) + sizeof(void*);
if (st->fields[i].isptr) {
jl_value_t *fval = *(jl_value_t**)((char*)v + offs);
Expand Down
10 changes: 5 additions & 5 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,13 @@ static size_t array_nd_index(jl_array_t *a, jl_value_t **args, size_t nidxs,
i += ii * stride;
size_t d = k>=nd ? 1 : jl_array_dim(a, k);
if (k < nidxs-1 && ii >= d)
jl_new_bounds_error_v((jl_value_t*)a, args, nidxs);
jl_bounds_error_v((jl_value_t*)a, args, nidxs);
stride *= d;
}
for(; k < nd; k++)
stride *= jl_array_dim(a, k);
if (i >= stride)
jl_new_bounds_error_v((jl_value_t*)a, args, nidxs);
jl_bounds_error_v((jl_value_t*)a, args, nidxs);
return i;
}

Expand Down Expand Up @@ -518,7 +518,7 @@ JL_CALLABLE(jl_f_arrayset)
void jl_arrayunset(jl_array_t *a, size_t i)
{
if (i >= jl_array_len(a))
jl_new_bounds_error_i((jl_value_t*)a, i+1);
jl_bounds_error_int((jl_value_t*)a, i+1);
char *ptail = (char*)a->data + i*a->elsize;
if (a->ptrarray)
memset(ptail, 0, a->elsize);
Expand Down Expand Up @@ -622,7 +622,7 @@ void jl_array_del_end(jl_array_t *a, size_t dec)
{
if (dec == 0) return;
if (dec > a->nrows)
jl_new_bounds_error_i((jl_value_t*)a, a->nrows - dec);
jl_bounds_error_int((jl_value_t*)a, a->nrows - dec);
if (a->isshared) array_try_unshare(a);
if (a->elsize > 0) {
char *ptail = (char*)a->data + (a->nrows-dec)*a->elsize;
Expand Down Expand Up @@ -697,7 +697,7 @@ void jl_array_del_beg(jl_array_t *a, size_t dec)
{
if (dec == 0) return;
if (dec > a->nrows)
jl_new_bounds_error_i((jl_value_t*)a, dec);
jl_bounds_error_int((jl_value_t*)a, dec);
if (a->isshared) array_try_unshare(a);
size_t es = a->elsize;
size_t nb = dec*es;
Expand Down
36 changes: 18 additions & 18 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void NORETURN jl_too_many_args(const char *fname, int max)
}

void NORETURN jl_type_error_rt(const char *fname, const char *context,
jl_value_t *ty, jl_value_t *got)
jl_value_t *ty, jl_value_t *got)
{
jl_value_t *ctxt=NULL;
JL_GC_PUSH2(&ctxt, &got);
Expand All @@ -79,7 +79,7 @@ void NORETURN jl_type_error_rt(const char *fname, const char *context,
}

void NORETURN jl_type_error_rt_line(const char *fname, const char *context,
jl_value_t *ty, jl_value_t *got, int line)
jl_value_t *ty, jl_value_t *got, int line)
{
jl_type_error_rt(fname, context, ty, got);
}
Expand All @@ -100,43 +100,43 @@ DLLEXPORT void NORETURN jl_undefined_var_error(jl_sym_t *var)
jl_throw(jl_new_struct(jl_undefvarerror_type, var));
}

DLLEXPORT void NORETURN jl_new_bounds_error(jl_value_t* v, jl_value_t* t) // t::Union(Tuple, Int)
DLLEXPORT void NORETURN jl_bounds_error(jl_value_t *v, jl_value_t *t)
{
JL_GC_PUSH2(v, t); // root arguments so the caller doesn't need to
jl_throw(jl_new_struct((jl_datatype_t*)jl_bounds_exception->type, v, t));
jl_throw(jl_new_struct((jl_datatype_t*)jl_boundserror_type, v, t));
}

DLLEXPORT void NORETURN jl_new_bounds_error_v(jl_value_t* v, jl_value_t **idxs, size_t nidxs)
DLLEXPORT void NORETURN jl_bounds_error_v(jl_value_t *v, jl_value_t **idxs, size_t nidxs)
{
jl_tuple_t *t = NULL;
JL_GC_PUSH2(v, t); // root arguments so the caller doesn't need to
t = jl_tuplev(nidxs, idxs);
jl_throw(jl_new_struct((jl_datatype_t*)jl_bounds_exception->type, v, t));
jl_throw(jl_new_struct((jl_datatype_t*)jl_boundserror_type, v, t));
}

DLLEXPORT void NORETURN jl_new_v_bounds_error_i(jl_value_t** v, size_t nv, size_t i)
DLLEXPORT void NORETURN jl_bounds_error_tuple_int(jl_value_t **v, size_t nv, size_t i)
{
jl_new_bounds_error_i((jl_value_t*)jl_tuplev(nv, v), i);
jl_bounds_error_int((jl_value_t*)jl_tuplev(nv, v), i);
}

DLLEXPORT void NORETURN jl_new_unboxed_bounds_error_i(void* data, jl_value_t *vt, size_t i)
DLLEXPORT void NORETURN jl_bounds_error_unboxed_int(void *data, jl_value_t *vt, size_t i)
{
jl_value_t *t = NULL, *v = NULL;
JL_GC_PUSH2(v, t);
v = jl_new_bits(vt, data);
t = jl_box_long(i);
jl_throw(jl_new_struct((jl_datatype_t*)jl_bounds_exception->type, v, t));
jl_throw(jl_new_struct((jl_datatype_t*)jl_boundserror_type, v, t));
}

DLLEXPORT void NORETURN jl_new_bounds_error_i(jl_value_t* v, size_t i)
DLLEXPORT void NORETURN jl_bounds_error_int(jl_value_t *v, size_t i)
{
jl_value_t *t = NULL;
JL_GC_PUSH2(v, t); // root arguments so the caller doesn't need to
t = jl_box_long(i);
jl_throw(jl_new_struct((jl_datatype_t*)jl_bounds_exception->type, v, t));
jl_throw(jl_new_struct((jl_datatype_t*)jl_boundserror_type, v, t));
}

DLLEXPORT void NORETURN jl_new_bounds_error_unboxed(jl_value_t* v, size_t *idxs, size_t nidxs)
DLLEXPORT void NORETURN jl_bounds_error_ints(jl_value_t *v, size_t *idxs, size_t nidxs)
{
size_t i;
jl_tuple_t *t = NULL;
Expand All @@ -145,7 +145,7 @@ DLLEXPORT void NORETURN jl_new_bounds_error_unboxed(jl_value_t* v, size_t *idxs,
for (i = 0; i < nidxs; i++) {
jl_tupleset(t, i, jl_box_long(idxs[i]));
}
jl_throw(jl_new_struct((jl_datatype_t*)jl_bounds_exception->type, v, t));
jl_throw(jl_new_struct((jl_datatype_t*)jl_boundserror_type, v, t));
}

JL_CALLABLE(jl_f_throw)
Expand Down Expand Up @@ -572,7 +572,7 @@ JL_CALLABLE(jl_f_tupleref)
jl_tuple_t *t = (jl_tuple_t*)args[0];
size_t i = jl_unbox_long(args[1])-1;
if (i >= jl_tuple_len(t))
jl_new_bounds_error(args[0], args[1]);
jl_bounds_error(args[0], args[1]);
return jl_tupleref(t, i);
}

Expand Down Expand Up @@ -601,7 +601,7 @@ JL_CALLABLE(jl_f_get_field)
if (jl_is_long(args[1])) {
idx = jl_unbox_long(args[1])-1;
if (idx >= jl_tuple_len(st->names))
jl_new_bounds_error(args[0], args[1]);
jl_bounds_error(args[0], args[1]);
}
else {
JL_TYPECHK(getfield, symbol, args[1]);
Expand Down Expand Up @@ -630,7 +630,7 @@ JL_CALLABLE(jl_f_set_field)
if (jl_is_long(args[1])) {
idx = jl_unbox_long(args[1])-1;
if (idx >= jl_tuple_len(st->names))
jl_new_bounds_error(args[0], args[1]);
jl_bounds_error(args[0], args[1]);
}
else {
JL_TYPECHK(setfield!, symbol, args[1]);
Expand All @@ -654,7 +654,7 @@ JL_CALLABLE(jl_f_field_type)
if (jl_is_long(args[1])) {
field_index = jl_unbox_long(args[1]) - 1;
if (field_index < 0 || field_index >= jl_tuple_len(st->names))
jl_new_bounds_error(args[0], args[1]);
jl_bounds_error(args[0], args[1]);
}
else {
JL_TYPECHK(fieldtype, symbol, args[1]);
Expand Down
6 changes: 3 additions & 3 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -894,9 +894,9 @@ static Value *emit_bounds_check(Value *a, jl_value_t *ty, Value *i, Value *len,
a = tempSpace;
}
builder.CreateCall3(prepare_call(jluboundserror_func),
builder.CreatePointerCast(a, T_pint8),
literal_pointer_val(ty),
i);
builder.CreatePointerCast(a, T_pint8),
literal_pointer_val(ty),
i);
}
else {
builder.CreateCall2(prepare_call(jlboundserror_func), a, i);
Expand Down
16 changes: 8 additions & 8 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4489,19 +4489,19 @@ static void init_julia_llvm_env(Module *m)
jlboundserrorv_func =
Function::Create(FunctionType::get(T_void, args2_boundserrorv, false),
Function::ExternalLinkage,
"jl_new_bounds_error_unboxed", m);
"jl_bounds_error_ints", m);
jlboundserrorv_func->setDoesNotReturn();
add_named_global(jlboundserrorv_func, (void*)&jl_new_bounds_error_unboxed);
add_named_global(jlboundserrorv_func, (void*)&jl_bounds_error_ints);

std::vector<Type*> args2_boundserror(0);
args2_boundserror.push_back(jl_pvalue_llvmt);
args2_boundserror.push_back(T_size);
jlboundserror_func =
Function::Create(FunctionType::get(T_void, args2_boundserror, false),
Function::ExternalLinkage,
"jl_new_bounds_error_i", m);
"jl_bounds_error_int", m);
jlboundserror_func->setDoesNotReturn();
add_named_global(jlboundserror_func, (void*)&jl_new_bounds_error_i);
add_named_global(jlboundserror_func, (void*)&jl_bounds_error_int);

std::vector<Type*> args3_vboundserror(0);
args3_vboundserror.push_back(jl_ppvalue_llvmt);
Expand All @@ -4510,9 +4510,9 @@ static void init_julia_llvm_env(Module *m)
jlvboundserror_func =
Function::Create(FunctionType::get(T_void, args3_vboundserror, false),
Function::ExternalLinkage,
"jl_new_v_bounds_error_i", m);
"jl_bounds_error_tuple_int", m);
jlvboundserror_func->setDoesNotReturn();
add_named_global(jlvboundserror_func, (void*)&jl_new_v_bounds_error_i);
add_named_global(jlvboundserror_func, (void*)&jl_bounds_error_tuple_int);

std::vector<Type*> args3_uboundserror(0);
args3_uboundserror.push_back(T_pint8);
Expand All @@ -4521,9 +4521,9 @@ static void init_julia_llvm_env(Module *m)
jluboundserror_func =
Function::Create(FunctionType::get(T_void, args3_uboundserror, false),
Function::ExternalLinkage,
"jl_new_unboxed_bounds_error_i", m);
"jl_bounds_error_unboxed_int", m);
jluboundserror_func->setDoesNotReturn();
add_named_global(jluboundserror_func, (void*)&jl_new_unboxed_bounds_error_i);
add_named_global(jluboundserror_func, (void*)&jl_bounds_error_unboxed_int);

std::vector<Type*> args2_throw(0);
args2_throw.push_back(jl_pvalue_llvmt);
Expand Down
1 change: 0 additions & 1 deletion src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,6 @@ static void gc_mark(void)
gc_push_root(jl_null, 0);
gc_push_root(jl_true, 0);
gc_push_root(jl_false, 0);
gc_push_root(jl_bounds_exception, 0);

jl_mark_box_caches();

Expand Down
2 changes: 1 addition & 1 deletion src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ void jl_get_builtin_hooks(void)
jl_undefref_exception = jl_new_struct_uninit((jl_datatype_t*)core("UndefRefError"));
jl_undefvarerror_type = (jl_datatype_t*)core("UndefVarError");
jl_interrupt_exception = jl_new_struct_uninit((jl_datatype_t*)core("InterruptException"));
jl_bounds_exception = jl_new_struct_uninit((jl_datatype_t*)core("BoundsError"));
jl_boundserror_type = (jl_datatype_t*)core("BoundsError");
jl_memory_exception = jl_new_struct_uninit((jl_datatype_t*)core("MemoryError"));

jl_ascii_string_type = (jl_datatype_t*)core("ASCIIString");
Expand Down
14 changes: 7 additions & 7 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ extern DLLEXPORT jl_value_t *jl_overflow_exception;
extern DLLEXPORT jl_value_t *jl_inexact_exception;
extern DLLEXPORT jl_value_t *jl_undefref_exception;
extern DLLEXPORT jl_value_t *jl_interrupt_exception;
extern DLLEXPORT jl_value_t *jl_bounds_exception;
extern DLLEXPORT jl_datatype_t *jl_boundserror_type;
extern DLLEXPORT jl_value_t *jl_an_empty_cell;

extern DLLEXPORT jl_datatype_t *jl_bool_type;
Expand Down Expand Up @@ -834,12 +834,12 @@ DLLEXPORT void NORETURN jl_type_error_rt(const char *fname, const char *context,
DLLEXPORT void NORETURN jl_type_error_rt_line(const char *fname, const char *context,
jl_value_t *ty, jl_value_t *got, int line);
DLLEXPORT void NORETURN jl_undefined_var_error(jl_sym_t *var);
DLLEXPORT void NORETURN jl_new_bounds_error(jl_value_t* v, jl_value_t* t);
DLLEXPORT void NORETURN jl_new_bounds_error_v(jl_value_t* v, jl_value_t **idxs, size_t nidxs);
DLLEXPORT void NORETURN jl_new_bounds_error_i(jl_value_t* v, size_t i);
DLLEXPORT void NORETURN jl_new_v_bounds_error_i(jl_value_t** v, size_t nv, size_t i);
DLLEXPORT void NORETURN jl_new_unboxed_bounds_error_i(void *v, jl_value_t *vt, size_t i);
DLLEXPORT void NORETURN jl_new_bounds_error_unboxed(jl_value_t* v, size_t *idxs, size_t nidxs);
DLLEXPORT void NORETURN jl_bounds_error(jl_value_t *v, jl_value_t *t);
DLLEXPORT void NORETURN jl_bounds_error_v(jl_value_t *v, jl_value_t **idxs, size_t nidxs);
DLLEXPORT void NORETURN jl_bounds_error_int(jl_value_t *v, size_t i);
DLLEXPORT void NORETURN jl_bounds_error_tuple_int(jl_value_t **v, size_t nv, size_t i);
DLLEXPORT void NORETURN jl_bounds_error_unboxed_int(void *v, jl_value_t *vt, size_t i);
DLLEXPORT void NORETURN jl_bounds_error_ints(jl_value_t *v, size_t *idxs, size_t nidxs);
DLLEXPORT jl_value_t *jl_exception_occurred(void);
DLLEXPORT void jl_exception_clear(void);

Expand Down

0 comments on commit 2aed2e4

Please sign in to comment.