Skip to content

Commit

Permalink
[core] Fix the remaining exception exitcodes
Browse files Browse the repository at this point in the history
Closes GH #1133.
  • Loading branch information
Reini Urban committed Nov 12, 2014
1 parent ac932da commit ba276e1
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 45 deletions.
2 changes: 1 addition & 1 deletion ChangeLog
Expand Up @@ -20,7 +20,7 @@
+ Shorten and harmonize array exception messages: no context, just:
index out of bounds, illegal argument, can't resize, ... #1126
+ Add simplier Parrot_ex_throw_from_c_noargs. #1132
+ Fix most wrong exception codes, 0 or 1. #1133
+ Fix all wrong exception codes left-overs, 0, 1 or -1. #1133
+ Unescape double-quoted .lex string constants. #1095, perl6 RT#116643
+ Downgrade external ascii strings on multi-byte platform encodings
to ascii. #1098
Expand Down
3 changes: 2 additions & 1 deletion src/embed/api.c
Expand Up @@ -214,7 +214,8 @@ Parrot_api_set_runcore(Parrot_PMC interp_pmc, ARGIN(const char * corename),
|| STREQ(corename, "switch-jit"))
Parrot_runcore_switch(interp, Parrot_str_new_constant(interp, "fast"));
else
Parrot_ex_throw_from_c_args(interp, NULL, 1, "Invalid runcore type %s", corename);
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_KEY_NOT_FOUND,
"Invalid runcore type %s", corename);
}
EMBED_API_CALLOUT(interp_pmc, interp)
}
Expand Down
6 changes: 3 additions & 3 deletions src/interp/inter_cb.c
@@ -1,5 +1,5 @@
/*
Copyright (C) 2001-2010, Parrot Foundation.
Copyright (C) 2001-2014, Parrot Foundation.
=head1 NAME
Expand Down Expand Up @@ -111,7 +111,7 @@ Parrot_make_cb(PARROT_INTERP, ARGMOD(PMC* sub), ARGIN(PMC* user_data),
}
}
if (type != 'C' && type != 'D')
Parrot_ex_throw_from_c_args(interp, NULL, 1,
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"unhandled signature '%Ss' in make_cb", cb_signature);

cb_sig = Parrot_pmc_new(interp, enum_class_String);
Expand Down Expand Up @@ -344,7 +344,7 @@ Parrot_run_callback(PARROT_INTERP,
param = Parrot_str_new(interp, (const char*)external_data, 0);
break;
default:
Parrot_ex_throw_from_c_args(interp, NULL, 1,
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"unhandled signature char '%c' in run_cb", ch);
}
pasm_sig[2] = '-';
Expand Down
5 changes: 3 additions & 2 deletions src/nci/signatures.c
@@ -1,5 +1,5 @@
/*
Copyright (C) 2010-2011, Parrot Foundation.
Copyright (C) 2010-2014, Parrot Foundation.
=head1 NAME
Expand Down Expand Up @@ -163,7 +163,8 @@ ncidt_to_pcc(PARROT_INTERP, PARROT_DATA_TYPE t)
return 'v';

default:
Parrot_ex_throw_from_c_args(interp, NULL, 0, "Unhandled NCI type: `%Ss'",
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_KEY_NOT_FOUND,
"Unhandled NCI type: `%Ss'",
Parrot_dt_get_datatype_name(interp, t));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/packfile/api.c
Expand Up @@ -2240,7 +2240,7 @@ load_file(PARROT_INTERP, ARGIN(STRING *path))
PMC * const pf_pmc = Parrot_pf_get_packfile_pmc(interp, pf, path);

if (!pf_pmc)
Parrot_ex_throw_from_c_args(interp, NULL, 1,
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_MALFORMED_PACKFILE,
"Unable to load PBC file %Ss", path);
else {
PMC * const pbc_cache = VTABLE_get_pmc_keyed_int(interp,
Expand Down
6 changes: 3 additions & 3 deletions src/platform/generic/entropy.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011, Parrot Foundation.
* Copyright (C) 2011-2014, Parrot Foundation.
*/

/*
Expand Down Expand Up @@ -46,7 +46,7 @@ Parrot_get_entropy(PARROT_INTERP) {
* as a way to figure out interp's initializedness.
*/
if (interp->gc_registry)
Parrot_ex_throw_from_c_noargs(interp, 1, msg);
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_EXTERNAL_ERROR, msg);
else
PANIC(interp, msg);
}
Expand All @@ -55,7 +55,7 @@ Parrot_get_entropy(PARROT_INTERP) {
const char* msg = "Couldn't read from /dev/urandom.";
fclose(urand_fh);
if (interp->gc_registry)
Parrot_ex_throw_from_c_noargs(interp, 1, msg);
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_EXTERNAL_ERROR, msg);
else
PANIC(interp, msg);
}
Expand Down
10 changes: 5 additions & 5 deletions src/platform/generic/file.c
@@ -1,13 +1,13 @@
/*
Copyright (C) 2011-2012, Parrot Foundation.
Copyright (C) 2011-2014, Parrot Foundation.
=head1 NAME
src/platform/generic/file.c - Generic UNIX file functions
src/platform/generic/file.c - Generic POSIX file functions
=head1 DESCRIPTION
This file implements OS-specific file functions for generic UNIX platforms.
This file implements OS-specific file functions for generic POSIX platforms.
=head2 Functions
Expand Down Expand Up @@ -471,15 +471,15 @@ stat_intval(PARROT_INTERP, ARGIN(struct stat *statbuf), INTVAL thing, int status
#ifdef PARROT_HAS_BSD_STAT_EXTN
result = statbuf->st_blksize;
#else
Parrot_ex_throw_from_c_noargs(interp, 1,
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_ARG_OP_NOT_HANDLED,
"STAT_PLATFORM_BLOCKSIZE not supported");
#endif
break;
case STAT_PLATFORM_BLOCKS:
#ifdef PARROT_HAS_BSD_STAT_EXTN
result = statbuf->st_blocks;
#else
Parrot_ex_throw_from_c_noargs(interp, 1,
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_ARG_OP_NOT_HANDLED,
"STAT_PLATFORM_BLOCKS not supported");
#endif
break;
Expand Down
6 changes: 3 additions & 3 deletions src/platform/win32/entropy.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011, Parrot Foundation.
* Copyright (C) 2011-2014, Parrot Foundation.
*/

/*
Expand Down Expand Up @@ -47,14 +47,14 @@ Parrot_get_entropy(PARROT_INTERP) {
* as a way to figure out interp's initializedness.
*/
if (interp->gc_registry)
Parrot_ex_throw_from_c_noargs(interp, 1, msg);
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_EXTERNAL_ERROR, msg);
else
PANIC(interp, msg);
}
if (!CryptGenRandom(hCryptProv, sizeof (INTVAL), &entropy)) {
const char *msg = "Couldn't get entropy from crypt context";
if (interp->gc_registry)
Parrot_ex_throw_from_c_noargs(interp, 1, msg);
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_EXTERNAL_ERROR, msg);
else
PANIC(interp, msg);
}
Expand Down
2 changes: 1 addition & 1 deletion src/pmc.c
Expand Up @@ -776,7 +776,7 @@ Parrot_pmc_register_new_type(PARROT_INTERP, ARGIN(STRING *name))
return type;

if (type < enum_type_undef)
Parrot_ex_throw_from_c_noargs(interp, 1,
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_INVALID_OPERATION,
"undefined type already exists - can't register PMC");

type = Parrot_pmc_get_new_vtable_index(interp);
Expand Down
10 changes: 6 additions & 4 deletions src/pmc/bignum.pmc
Expand Up @@ -687,7 +687,8 @@ bignum_get_si(PARROT_INTERP, ARGIN(PMC *self)) {
if (mpf_fits_slong_p(bn->b))
return mpf_get_si(bn->b);

Parrot_ex_throw_from_c_noargs(interp, 1, "bignum_get_si: number too big");
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_ERR_OVERFLOW,
"BigNum: number too big");
}

PARROT_WARN_UNUSED_RESULT
Expand All @@ -700,7 +701,8 @@ bignum_get_ui(PARROT_INTERP, ARGIN(PMC *self)) {
if (mpf_fits_slong_p(bn->b))
return mpf_get_ui(bn->b);

Parrot_ex_throw_from_c_noargs(interp, 1, "bignum_get_ui: number too big");
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_ERR_OVERFLOW,
"BigNum: number too big");
}

PARROT_WARN_UNUSED_RESULT
Expand Down Expand Up @@ -1113,8 +1115,8 @@ bignum_get_bigint(PARROT_INTERP, ARGIN(PMC *self)) {
bi_dest->b = mpf_get_ui(bn->b);
}
else {
Parrot_ex_throw_from_c_noargs(interp, 1,
"bignum_get_bigint: Precision loss");
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_LOSSY_CONVERSION,
"BigNum: Precision loss");
}
return bi_dest;
}
Expand Down
2 changes: 1 addition & 1 deletion src/pmc/multisub.pmc
Expand Up @@ -86,7 +86,7 @@ pmclass MultiSub
SELF, sig_obj);

if (PMC_IS_NULL(func))
Parrot_ex_throw_from_c_args(INTERP, NULL, 1,
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_METHOD_NOT_FOUND,
"No applicable candidates found to dispatch to for '%Ss'",
VTABLE_get_string(INTERP, SELF));
return VTABLE_invoke(INTERP, func, next);
Expand Down
2 changes: 1 addition & 1 deletion src/pmc/object.pmc
Expand Up @@ -567,7 +567,7 @@ Queries this object's class to find the method with the given name.
break;
}
else
Parrot_ex_throw_from_c_args(INTERP, NULL, -1,
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_NO_CLASS,
"Class %Ss inherits from alien parents",
class_info->name);
}
Expand Down
2 changes: 1 addition & 1 deletion src/pmc/ptrobj.pmc
Expand Up @@ -76,7 +76,7 @@ Get or set the custom C<clone> function.
if (clone)
return clone(INTERP, SELF, ptr);
else
Parrot_ex_throw_from_c_args(INTERP, NULL, 0,
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_METHOD_NOT_FOUND,
"clone not implemented for PtrObj %x", ptr);
}

Expand Down
8 changes: 4 additions & 4 deletions src/runcore/cores.c
Expand Up @@ -569,7 +569,7 @@ runops_trace_core(PARROT_INTERP, ARGIN(opcode_t *pc))
while (pc) {
size_t runs;
if (pc < code_start || pc >= code_end)
Parrot_ex_throw_from_c_noargs(interp, 1,
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_OUT_OF_BOUNDS,
"attempt to access code outside of current code segment");

Parrot_pcc_set_pc(interp, CURRENT_CONTEXT(interp), pc);
Expand Down Expand Up @@ -620,7 +620,7 @@ runops_slow_core(PARROT_INTERP, SHIM(Parrot_runcore_t *runcore), ARGIN(opcode_t

while (pc) {
if (pc < code_start || pc >= code_end)
Parrot_ex_throw_from_c_noargs(interp, 1,
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_OUT_OF_BOUNDS,
"attempt to access code outside of current code segment");

Parrot_pcc_set_pc(interp, CURRENT_CONTEXT(interp), pc);
Expand Down Expand Up @@ -653,7 +653,7 @@ runops_gc_debug_core(PARROT_INTERP, SHIM(Parrot_runcore_t *runcore), ARGIN(opcod
ASSERT_ARGS(runops_gc_debug_core)
while (pc) {
if (pc < code_start || pc >= code_end)
Parrot_ex_throw_from_c_noargs(interp, 1,
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_OUT_OF_BOUNDS,
"attempt to access code outside of current code segment");

Parrot_gc_mark_and_sweep(interp, GC_trace_stack_FLAG);
Expand Down Expand Up @@ -694,7 +694,7 @@ runops_debugger_core(PARROT_INTERP, SHIM(Parrot_runcore_t *runcore), ARGIN(opcod

while (pc) {
if (pc < interp->code->base.data || pc >= interp->code->base.data + interp->code->base.size)
Parrot_ex_throw_from_c_noargs(interp, 1,
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_OUT_OF_BOUNDS,
"attempt to access code outside of current code segment");

if (interp->pdb->state & PDB_GCDEBUG)
Expand Down
4 changes: 2 additions & 2 deletions src/runcore/main.c
@@ -1,5 +1,5 @@
/*
Copyright (C) 2001-2010, Parrot Foundation.
Copyright (C) 2001-2014, Parrot Foundation.
=head1 NAME
Expand Down Expand Up @@ -225,7 +225,7 @@ runops_int(PARROT_INTERP, size_t offset)
* is ok. */
if (interp->resume_flag & RESUME_RESTART) {
if ((int)interp->resume_offset < 0)
Parrot_ex_throw_from_c_noargs(interp, 1,
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_INTERNAL_PANIC,
"branch_cs: illegal resume offset");
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/runcore/profiling.c
@@ -1,5 +1,5 @@
/*
Copyright (C) 2009-2011, Parrot Foundation.
Copyright (C) 2009-2014, Parrot Foundation.
=head1 NAME
Expand Down Expand Up @@ -376,7 +376,7 @@ ARGIN(opcode_t *pc))
PMC *preop_ctx_pmc;

if (pc < code_start || pc >= code_end)
Parrot_ex_throw_from_c_noargs(interp, 1,
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_OUT_OF_BOUNDS,
"attempt to access code outside of current code segment");

preop_ctx_pmc = CURRENT_CONTEXT(interp);
Expand Down
15 changes: 8 additions & 7 deletions src/runcore/subprof.c
@@ -1,5 +1,5 @@
/*
Copyright (C) 2001-2012, Parrot Foundation.
Copyright (C) 2001-2014, Parrot Foundation.
=head1 NAME
Expand Down Expand Up @@ -1185,10 +1185,11 @@ get_subprofiledata(PARROT_INTERP, ARGIN(Parrot_runcore_t *runcore), int type)
}

if (spdata->profile_type != type)
Parrot_ex_throw_from_c_noargs(interp, 1, "illegal profile type change while profiling");

Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_INVALID_OPERATION,
"illegal profile type change while profiling");
if (spdata->interp != interp)
Parrot_ex_throw_from_c_noargs(interp, 1, "illegal interpreter change while profiling");
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_INVALID_OPERATION,
"illegal interpreter change while profiling");

return core->spdata;
}
Expand Down Expand Up @@ -1253,7 +1254,7 @@ runops_subprof_sub_core(PARROT_INTERP, ARGIN(Parrot_runcore_t *runcore), ARGIN(o

while (pc) {
if (pc < code_start || pc >= code_end)
Parrot_ex_throw_from_c_noargs(interp, 1,
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_OUT_OF_BOUNDS,
"attempt to access code outside of current code segment");

ctx = CURRENT_CONTEXT(interp);
Expand Down Expand Up @@ -1351,7 +1352,7 @@ runops_subprof_hll_core(PARROT_INTERP, ARGIN(Parrot_runcore_t *runcore), ARGIN(o
PMC *ctx;
PMC *subpmc;
if (pc < code_start || pc >= code_end)
Parrot_ex_throw_from_c_noargs(interp, 1,
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_OUT_OF_BOUNDS,
"attempt to access code outside of current code segment");

ctx = CURRENT_CONTEXT(interp);
Expand Down Expand Up @@ -1487,7 +1488,7 @@ runops_subprof_ops_core(PARROT_INTERP, ARGIN(Parrot_runcore_t *runcore), ARGIN(o
PMC *ctx;
PMC *subpmc;
if (pc < code_start || pc >= code_end)
Parrot_ex_throw_from_c_noargs(interp, 1,
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_OUT_OF_BOUNDS,
"attempt to access code outside of current code segment");

ctx = CURRENT_CONTEXT(interp);
Expand Down
6 changes: 3 additions & 3 deletions src/runcore/trace.c
Expand Up @@ -448,7 +448,7 @@ trace_op_dump(PARROT_INTERP,
sig = interp->code->const_table->pmc.constants[pc[1]];

if (!sig)
Parrot_ex_throw_from_c_noargs(interp, 1,
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_UNEXPECTED_NULL,
"NULL sig PMC detected in trace_op_dump");

var_args = VTABLE_elements(interp, sig);
Expand All @@ -466,7 +466,7 @@ trace_op_dump(PARROT_INTERP,
type = info->types[i - 1];
else {
if (PMC_IS_NULL(sig))
Parrot_ex_throw_from_c_noargs(interp, 1,
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_UNEXPECTED_NULL,
"NULL sig PMC detected in trace_op_dump");

type = VTABLE_get_integer_keyed_int(interp, sig, i - 2) &
Expand Down Expand Up @@ -540,7 +540,7 @@ trace_op_dump(PARROT_INTERP,
more = 1;
break;
default:
Parrot_ex_throw_from_c_noargs(interp, 1,
Parrot_ex_throw_from_c_noargs(interp, EXCEPTION_NULL_REG_ACCESS,
"unhandled type in trace");
break;
}
Expand Down

0 comments on commit ba276e1

Please sign in to comment.