From 2aed2e4ee54570f223c8e88513a0a0a1c06ad54d Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Fri, 2 Jan 2015 13:44:47 -0500 Subject: [PATCH] new BoundsError: style fixes and renamings --- base/boot.jl | 5 ++--- base/replutil.jl | 8 +++----- src/alloc.c | 4 ++-- src/array.c | 10 +++++----- src/builtins.c | 36 ++++++++++++++++++------------------ src/cgutils.cpp | 6 +++--- src/codegen.cpp | 16 ++++++++-------- src/gc.c | 1 - src/init.c | 2 +- src/julia.h | 14 +++++++------- 10 files changed, 49 insertions(+), 53 deletions(-) diff --git a/base/boot.jl b/base/boot.jl index 04723a0c61e3ab..db8a0094ae97bb 100644 --- a/base/boot.jl +++ b/base/boot.jl @@ -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 diff --git a/base/replutil.jl b/base/replutil.jl index b6a62ba88d3522..62dfe94f815cf2 100644 --- a/base/replutil.jl +++ b/base/replutil.jl @@ -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) diff --git a/src/alloc.c b/src/alloc.c index 27b6be58a89702..eb61896113e25f 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -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; @@ -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); diff --git a/src/array.c b/src/array.c index a19e2e8a0d8944..98347cdcf81690 100644 --- a/src/array.c +++ b/src/array.c @@ -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; } @@ -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); @@ -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; @@ -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; diff --git a/src/builtins.c b/src/builtins.c index a6f6f7df5ca38f..a8e6b30dcef896 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -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); @@ -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); } @@ -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; @@ -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) @@ -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); } @@ -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]); @@ -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]); @@ -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]); diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 77843d90c202e1..d13e1151391780 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -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); diff --git a/src/codegen.cpp b/src/codegen.cpp index 0ac68287550929..f8fbacb2b453a2 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -4489,9 +4489,9 @@ 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 args2_boundserror(0); args2_boundserror.push_back(jl_pvalue_llvmt); @@ -4499,9 +4499,9 @@ static void init_julia_llvm_env(Module *m) 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 args3_vboundserror(0); args3_vboundserror.push_back(jl_ppvalue_llvmt); @@ -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 args3_uboundserror(0); args3_uboundserror.push_back(T_pint8); @@ -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 args2_throw(0); args2_throw.push_back(jl_pvalue_llvmt); diff --git a/src/gc.c b/src/gc.c index cf686d00ce07f1..42b6bbad33affb 100644 --- a/src/gc.c +++ b/src/gc.c @@ -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(); diff --git a/src/init.c b/src/init.c index 6c368d140afb95..c222bf63da4eb5 100644 --- a/src/init.c +++ b/src/init.c @@ -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"); diff --git a/src/julia.h b/src/julia.h index 567ef593b93deb..9c6808572400ea 100644 --- a/src/julia.h +++ b/src/julia.h @@ -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; @@ -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);