diff --git a/src/6model/6model.c b/src/6model/6model.c index 2d164adce5..5d73111c53 100644 --- a/src/6model/6model.c +++ b/src/6model/6model.c @@ -48,9 +48,11 @@ static void die_over_missing_method(MVMThreadContext *tc, MVMObject *obj, MVMStr return; } else { - MVM_exception_throw_adhoc(tc, + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Cannot find method '%s'", - MVM_string_utf8_encode_C_string(tc, name)); + c_name); } } static void late_bound_find_method_return(MVMThreadContext *tc, void *sr_data) { @@ -74,10 +76,13 @@ void MVM_6model_find_method(MVMThreadContext *tc, MVMObject *obj, MVMString *nam MVMObject *cache, *HOW, *find_method, *code; MVMCallsite *findmeth_callsite; - if (MVM_is_null(tc, obj)) - MVM_exception_throw_adhoc(tc, + if (MVM_is_null(tc, obj)) { + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Cannot call method '%s' on a null object", - MVM_string_utf8_encode_C_string(tc, name)); + c_name); + } /* First try to find it in the cache. If we find it, we have a result. * If we don't find it, but the cache is authoritative, then error. */ @@ -99,10 +104,13 @@ void MVM_6model_find_method(MVMThreadContext *tc, MVMObject *obj, MVMString *nam HOW = MVM_6model_get_how(tc, STABLE(obj)); find_method = MVM_6model_find_method_cache_only(tc, HOW, tc->instance->str_consts.find_method); - if (MVM_is_null(tc, find_method)) - MVM_exception_throw_adhoc(tc, + if (MVM_is_null(tc, find_method)) { + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Cannot find method '%s': no method cache and no .^find_method", - MVM_string_utf8_encode_C_string(tc, name)); + c_name); + } /* Set up the call, using the result register as the target. */ code = MVM_frame_find_invokee(tc, find_method, NULL); @@ -164,6 +172,7 @@ MVMint64 MVM_6model_can_method_cache_only(MVMThreadContext *tc, MVMObject *obj, MVMObject *cache; if (MVM_is_null(tc, obj)) + // XXX here MVM_exception_throw_adhoc(tc, "Cannot look for method '%s' on a null object", MVM_string_utf8_encode_C_string(tc, name)); diff --git a/src/6model/reprs.c b/src/6model/reprs.c index 08bf8e6bc0..8666ba5b6b 100644 --- a/src/6model/reprs.c +++ b/src/6model/reprs.c @@ -240,9 +240,12 @@ static MVMReprRegistry * find_repr_by_name(MVMThreadContext *tc, MVM_string_flatten(tc, name); MVM_HASH_GET(tc, tc->instance->repr_hash, name, entry) - if (entry == NULL) - MVM_exception_throw_adhoc(tc, "Lookup by name of unknown REPR: %s", - MVM_string_ascii_encode_any(tc, name)); + if (entry == NULL) { + char *c_name = MVM_string_ascii_encode_any(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Lookup by name of unknown REPR: %s", + c_name); + } return entry; } diff --git a/src/6model/reprs/CStruct.c b/src/6model/reprs/CStruct.c index 33f24054ef..0ced42e5de 100644 --- a/src/6model/reprs/CStruct.c +++ b/src/6model/reprs/CStruct.c @@ -344,8 +344,10 @@ static void copy_to(MVMThreadContext *tc, MVMSTable *st, void *src, MVMObject *d /* Helper for complaining about attribute access errors. */ MVM_NO_RETURN static void no_such_attribute(MVMThreadContext *tc, const char *action, MVMObject *class_handle, MVMString *name) MVM_NO_RETURN_GCC; static void no_such_attribute(MVMThreadContext *tc, const char *action, MVMObject *class_handle, MVMString *name) { - MVM_exception_throw_adhoc(tc, "Can not %s non-existent attribute '%s'", - action, MVM_string_utf8_encode_C_string(tc, name)); + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Can not %s non-existent attribute '%s'", + action, c_name); } /* Helper to die because this type doesn't support attributes. */ diff --git a/src/6model/reprs/CUnion.c b/src/6model/reprs/CUnion.c index 5263913270..8d5cbf4c00 100644 --- a/src/6model/reprs/CUnion.c +++ b/src/6model/reprs/CUnion.c @@ -357,8 +357,10 @@ static void copy_to(MVMThreadContext *tc, MVMSTable *st, void *src, MVMObject *d /* Helper for complaining about attribute access errors. */ MVM_NO_RETURN static void no_such_attribute(MVMThreadContext *tc, const char *action, MVMObject *class_handle, MVMString *name) MVM_NO_RETURN_GCC; static void no_such_attribute(MVMThreadContext *tc, const char *action, MVMObject *class_handle, MVMString *name) { - MVM_exception_throw_adhoc(tc, "Can not %s non-existent attribute '%s'", - action, MVM_string_utf8_encode_C_string(tc, name)); + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Can not %s non-existent attribute '%s'", + action, c_name); } /* Helper to die because this type doesn't support attributes. */ diff --git a/src/6model/reprs/MVMContext.c b/src/6model/reprs/MVMContext.c index 1d01d4f130..d6cd048760 100644 --- a/src/6model/reprs/MVMContext.c +++ b/src/6model/reprs/MVMContext.c @@ -42,21 +42,27 @@ static void at_key(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *d MVMFrame *frame = body->context; MVMLexicalRegistry *lexical_names = frame->static_info->body.lexical_names, *entry; if (!lexical_names) { - MVM_exception_throw_adhoc(tc, + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Lexical with name '%s' does not exist in this frame", - MVM_string_utf8_encode_C_string(tc, name)); + c_name); } MVM_string_flatten(tc, name); MVM_HASH_GET(tc, lexical_names, name, entry); if (!entry) { - MVM_exception_throw_adhoc(tc, + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Lexical with name '%s' does not exist in this frame", - MVM_string_utf8_encode_C_string(tc, name)); + c_name); } if (frame->static_info->body.lexical_types[entry->value] != kind) { - MVM_exception_throw_adhoc(tc, + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Lexical with name '%s' has a different type in this frame", - MVM_string_utf8_encode_C_string(tc, name)); + c_name); } *result = frame->env[entry->value]; if (kind == MVM_reg_obj && !result->o) @@ -69,21 +75,27 @@ static void bind_key(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void MVMFrame *frame = body->context; MVMLexicalRegistry *lexical_names = frame->static_info->body.lexical_names, *entry; if (!lexical_names) { - MVM_exception_throw_adhoc(tc, + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Lexical with name '%s' does not exist in this frame", - MVM_string_utf8_encode_C_string(tc, name)); + c_name); } MVM_string_flatten(tc, name); MVM_HASH_GET(tc, lexical_names, name, entry); if (!entry) { - MVM_exception_throw_adhoc(tc, + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Lexical with name '%s' does not exist in this frame", - MVM_string_utf8_encode_C_string(tc, name)); + c_name); } if (frame->static_info->body.lexical_types[entry->value] != kind) { - MVM_exception_throw_adhoc(tc, + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Lexical with name '%s' has a different type in this frame", - MVM_string_utf8_encode_C_string(tc, name)); + c_name); } frame->env[entry->value] = value; } diff --git a/src/6model/reprs/NativeRef.c b/src/6model/reprs/NativeRef.c index 73029462e1..b1b0fb5f58 100644 --- a/src/6model/reprs/NativeRef.c +++ b/src/6model/reprs/NativeRef.c @@ -281,16 +281,20 @@ static MVMObject * lexref_by_name(MVMThreadContext *tc, MVMObject *type, MVMStri return reg_or_lex_ref(tc, type, cur_frame, &cur_frame->env[entry->value], kind); } else { - MVM_exception_throw_adhoc(tc, + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Lexical with name '%s' has wrong type", - MVM_string_utf8_encode_C_string(tc, name)); + c_name); } } } cur_frame = cur_frame->outer; } - MVM_exception_throw_adhoc(tc, "No lexical found with name '%s'", - MVM_string_utf8_encode_C_string(tc, name)); + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "No lexical found with name '%s'", + c_name); } MVMObject * MVM_nativeref_lex_name_i(MVMThreadContext *tc, MVMString *name) { MVMObject *ref_type = MVM_hll_current(tc)->int_lex_ref; diff --git a/src/6model/reprs/P6opaque.c b/src/6model/reprs/P6opaque.c index 6c2d493df9..dede52a73d 100644 --- a/src/6model/reprs/P6opaque.c +++ b/src/6model/reprs/P6opaque.c @@ -201,7 +201,9 @@ static void gc_free_repr_data(MVMThreadContext *tc, MVMSTable *st) { MVM_NO_RETURN static void no_such_attribute(MVMThreadContext *tc, const char *action, MVMObject *class_handle, MVMString *name) { MVMuint64 output_size; - MVM_exception_throw_adhoc(tc, "P6opaque: no such attribute '%s'", MVM_string_ascii_encode(tc, name, &output_size)); + char *c_name = MVM_string_ascii_encode(tc, name, &output_size); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "P6opaque: no such attribute '%s'", c_name); } /* Gets the current value for an attribute. */ diff --git a/src/6model/sc.c b/src/6model/sc.c index 4f1d1e7eda..c0617c43b0 100644 --- a/src/6model/sc.c +++ b/src/6model/sc.c @@ -126,11 +126,18 @@ MVMint64 MVM_sc_find_code_idx(MVMThreadContext *tc, MVMSerializationContext *sc, if (test == obj) return i; } - MVM_exception_throw_adhoc(tc, - "Code ref '%s' does not exist in serialization context", - REPR(obj)->ID == MVM_REPR_ID_MVMCode - ? MVM_string_utf8_encode_C_string(tc, ((MVMCode *)obj)->body.name) - : ""); + + if (REPR(obj)->ID == MVM_REPR_ID_MVMCode) { + char *c_name = MVM_string_utf8_encode_C_string(tc, ((MVMCode *)obj)->body.name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, + "Code ref '%s' does not exist in serialization context", + c_name); + } + else { + MVM_exception_throw_adhoc(tc, + "Code ref '' does not exist in serialization context"); + } } /* Given a compilation unit and dependency index, returns that SC. */ @@ -163,10 +170,13 @@ MVMObject * MVM_sc_get_object(MVMThreadContext *tc, MVMSerializationContext *sc, return roots[idx] && !sc_working(sc) ? roots[idx] : MVM_serialization_demand_object(tc, sc, idx); - else - MVM_exception_throw_adhoc(tc, + else { + char *c_description = MVM_string_utf8_encode_C_string(tc, sc->body->description); + char *waste[] = { c_description, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Probable version skew in pre-compiled '%s' (cause: no object at index %"PRId64")", - MVM_string_utf8_encode_C_string(tc, sc->body->description), idx); + c_description, idx); + } } MVMObject * MVM_sc_get_sc_object(MVMThreadContext *tc, MVMCompUnit *cu, @@ -224,9 +234,11 @@ MVMSTable * MVM_sc_get_stable(MVMThreadContext *tc, MVMSerializationContext *sc, return got && !sc_working(sc) ? got : MVM_serialization_demand_stable(tc, sc, idx); } else { - MVM_exception_throw_adhoc(tc, + char *c_description = MVM_string_utf8_encode_C_string(tc, sc->body->description); + char *waste[] = { c_description, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Probable version skew in pre-compiled '%s' (cause: no STable at index %"PRId64")", - MVM_string_utf8_encode_C_string(tc, sc->body->description), idx); + c_description, idx); } } @@ -288,9 +300,11 @@ MVMObject * MVM_sc_get_code(MVMThreadContext *tc, MVMSerializationContext *sc, M : found; } else { - MVM_exception_throw_adhoc(tc, + char *c_description = MVM_string_utf8_encode_C_string(tc, sc->body->description); + char *waste[] = { c_description, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Probable version skew in pre-compiled '%s' (cause: no code ref at index %"PRId64")", - MVM_string_utf8_encode_C_string(tc, sc->body->description), idx); + c_description, idx); } } diff --git a/src/6model/serialization.c b/src/6model/serialization.c index 02362a9583..94e76b9589 100644 --- a/src/6model/serialization.c +++ b/src/6model/serialization.c @@ -503,11 +503,14 @@ static MVMObject * closure_to_static_code_ref(MVMThreadContext *tc, MVMObject *c MVMObject *scr = (MVMObject *)(((MVMCode *)closure)->body.sf)->body.static_code; if (scr == NULL || MVM_sc_get_obj_sc(tc, scr) == NULL) { - if (fatal) - MVM_exception_throw_adhoc(tc, + if (fatal) { + char *c_name = MVM_string_utf8_encode_C_string(tc, + (((MVMCode *)closure)->body.sf)->body.name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Serialization Error: missing static code ref for closure '%s'", - MVM_string_utf8_encode_C_string(tc, - (((MVMCode *)closure)->body.sf)->body.name)); + c_name); + } return NULL; } return scr; diff --git a/src/core/args.c b/src/core/args.c index add3507028..99a3e32423 100644 --- a/src/core/args.c +++ b/src/core/args.c @@ -348,7 +348,9 @@ MVMArgInfo MVM_args_get_pos_str(MVMThreadContext *tc, MVMArgProcContext *ctx, MV for (flag_pos = arg_pos = ctx->num_pos; arg_pos < ctx->arg_count; flag_pos++, arg_pos += 2) { \ if (MVM_string_equal(tc, ctx->args[arg_pos].s, name)) { \ if (ctx->named_used[(arg_pos - ctx->num_pos)/2]) { \ - MVM_exception_throw_adhoc(tc, "Named argument '%s' already used", MVM_string_utf8_encode_C_string(tc, name)); \ + char *c_name = MVM_string_utf8_encode_C_string(tc, name); \ + char *waste[] = { c_name, NULL }; \ + MVM_exception_throw_adhoc_free(tc, waste, "Named argument '%s' already used", c_name); \ } \ result.arg = ctx->args[arg_pos + 1]; \ result.flags = (ctx->arg_flags ? ctx->arg_flags : ctx->callsite->arg_flags)[flag_pos]; \ @@ -357,9 +359,11 @@ MVMArgInfo MVM_args_get_pos_str(MVMThreadContext *tc, MVMArgProcContext *ctx, MV break; \ } \ } \ - if (!result.exists && required) \ - MVM_exception_throw_adhoc(tc, "Required named parameter '%s' not passed", MVM_string_utf8_encode_C_string(tc, name)); \ - \ + if (!result.exists && required) { \ + char *c_name = MVM_string_utf8_encode_C_string(tc, name); \ + char *waste[] = { c_name, NULL }; \ + MVM_exception_throw_adhoc_free(tc, waste, "Required named parameter '%s' not passed", c_name); \ + } \ } while (0) MVMArgInfo MVM_args_get_named_obj(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMString *name, MVMuint8 required) { @@ -398,11 +402,14 @@ void MVM_args_assert_nameds_used(MVMThreadContext *tc, MVMArgProcContext *ctx) { MVMuint16 size = (ctx->arg_count - ctx->num_pos) / 2; MVMuint16 i; for (i = 0; i < size; i++) - if (!ctx->named_used[i]) - MVM_exception_throw_adhoc(tc, + if (!ctx->named_used[i]) { + char *c_param = MVM_string_utf8_encode_C_string(tc, + ctx->args[ctx->num_pos + 2 * i].s); + char *waste[] = { c_param, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Unexpected named parameter '%s' passed", - MVM_string_utf8_encode_C_string(tc, - ctx->args[ctx->num_pos + 2 * i].s)); + c_param); + } } } diff --git a/src/core/dll.c b/src/core/dll.c index 6bb3ec86d9..fa605afa1e 100644 --- a/src/core/dll.c +++ b/src/core/dll.c @@ -28,7 +28,8 @@ int MVM_dll_load(MVMThreadContext *tc, MVMString *name, MVMString *path) { if (!lib) { uv_mutex_unlock(&tc->instance->mutex_dll_registry); - MVM_exception_throw_adhoc(tc, "failed to load library '%s'", cpath); + char *waste[] = { cpath, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "failed to load library '%s'", cpath); } MVM_free(cpath); diff --git a/src/core/frame.c b/src/core/frame.c index 9d75b672e3..79d0887ab3 100644 --- a/src/core/frame.c +++ b/src/core/frame.c @@ -397,17 +397,52 @@ void MVM_frame_invoke(MVMThreadContext *tc, MVMStaticFrame *static_frame, * to cope with nqp::freshcoderef). */ if (outer->static_info->body.orig_bytecode == static_frame_body->outer->body.orig_bytecode) frame->outer = outer; - else - MVM_exception_throw_adhoc(tc, + else { + char *frame_cuuid = MVM_string_utf8_encode_C_string(tc, static_frame_body->cuuid); + char *frame_name; + char *outer_cuuid = MVM_string_utf8_encode_C_string(tc, outer->static_info->body.cuuid); + char *outer_name; + char *frame_outer_cuuid = MVM_string_utf8_encode_C_string(tc, static_frame_body->outer->body.cuuid); + char *frame_outer_name; + + char *waste[7] = { frame_cuuid, outer_cuuid, frame_outer_cuuid, NULL, NULL, NULL, NULL }; + int waste_counter = 3; + + if (static_frame_body->name) { + frame_name = MVM_string_utf8_encode_C_string(tc, static_frame_body->name); + waste[waste_counter++] = frame_name; + } + else { + frame_name = ""; + } + + if (outer->static_info->body.name) { + outer_name = MVM_string_utf8_encode_C_string(tc, outer->static_info->body.name); + waste[waste_counter++] = outer_name; + } + else { + outer_name = ""; + } + + if (static_frame_body->outer->body.name) { + frame_outer_name = MVM_string_utf8_encode_C_string(tc, static_frame_body->outer->body.name); + waste[waste_counter++] = frame_outer_name; + } + else { + frame_outer_name = ""; + } + + MVM_exception_throw_adhoc_free(tc, waste, "When invoking %s '%s', provided outer frame %p (%s '%s') does not match expected static frame %p (%s '%s')", - MVM_string_utf8_encode_C_string(tc, static_frame_body->cuuid), - static_frame_body->name ? MVM_string_utf8_encode_C_string(tc, static_frame_body->name) : "", + frame_cuuid, + frame_name, outer->static_info, - MVM_string_utf8_encode_C_string(tc, outer->static_info->body.cuuid), - outer->static_info->body.name ? MVM_string_utf8_encode_C_string(tc, outer->static_info->body.name) : "", + outer_cuuid, + outer_name, static_frame_body->outer, - MVM_string_utf8_encode_C_string(tc, static_frame_body->outer->body.cuuid), - static_frame_body->outer->body.name ? MVM_string_utf8_encode_C_string(tc, static_frame_body->outer->body.name) : ""); + frame_outer_cuuid, + frame_outer_name); + } } else if (static_frame_body->static_code) { MVMCode *static_code = static_frame_body->static_code; @@ -924,9 +959,11 @@ MVMRegister * MVM_frame_find_lexical_by_name(MVMThreadContext *tc, MVMString *na return result; } else { - MVM_exception_throw_adhoc(tc, + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Lexical with name '%s' has wrong type", - MVM_string_utf8_encode_C_string(tc, name)); + c_name); } } } @@ -934,8 +971,10 @@ MVMRegister * MVM_frame_find_lexical_by_name(MVMThreadContext *tc, MVMString *na } if (type == MVM_reg_obj) return NULL; - MVM_exception_throw_adhoc(tc, "No lexical found with name '%s'", - MVM_string_utf8_encode_C_string(tc, name)); + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "No lexical found with name '%s'", + c_name); } /* Finds a lexical in the outer frame, throwing if it's not there. */ @@ -943,9 +982,12 @@ MVMObject * MVM_frame_find_lexical_by_name_outer(MVMThreadContext *tc, MVMString MVMRegister *r = MVM_frame_find_lexical_by_name_rel(tc, name, tc->cur_frame->outer); if (r) return r->o; - else - MVM_exception_throw_adhoc(tc, "No lexical found with name '%s'", - MVM_string_utf8_encode_C_string(tc, name)); + else { + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "No lexical found with name '%s'", + c_name); + } } /* Looks up the address of the lexical with the specified name, starting with @@ -968,9 +1010,11 @@ MVMRegister * MVM_frame_find_lexical_by_name_rel(MVMThreadContext *tc, MVMString return result; } else { - MVM_exception_throw_adhoc(tc, + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Lexical with name '%s' has wrong type", - MVM_string_utf8_encode_C_string(tc, name)); + c_name); } } } @@ -1001,9 +1045,11 @@ MVMRegister * MVM_frame_find_lexical_by_name_rel_caller(MVMThreadContext *tc, MV return result; } else { - MVM_exception_throw_adhoc(tc, + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Lexical with name '%s' has wrong type", - MVM_string_utf8_encode_C_string(tc, name)); + c_name); } } } @@ -1235,8 +1281,10 @@ void MVM_frame_binddynlex(MVMThreadContext *tc, MVMString *name, MVMObject *valu MVMuint16 type; MVMRegister *lex_reg = MVM_frame_find_contextual_by_name(tc, name, &type, cur_frame, 0); if (!lex_reg) { - MVM_exception_throw_adhoc(tc, "No contextual found with name '%s'", - MVM_string_utf8_encode_C_string(tc, name)); + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "No contextual found with name '%s'", + c_name); } switch (type) { case MVM_reg_int64: @@ -1270,8 +1318,10 @@ MVMRegister * MVM_frame_lexical(MVMThreadContext *tc, MVMFrame *f, MVMString *na if (entry) return &f->env[entry->value]; } - MVM_exception_throw_adhoc(tc, "Frame has no lexical with name '%s'", - MVM_string_utf8_encode_C_string(tc, name)); + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Frame has no lexical with name '%s'", + c_name); } /* Returns the storage unit for the lexical in the specified frame. */ @@ -1309,14 +1359,20 @@ MVMuint16 MVM_frame_lexical_primspec(MVMThreadContext *tc, MVMFrame *f, MVMStrin case MVM_reg_obj: return MVM_STORAGE_SPEC_BP_NONE; default: - MVM_exception_throw_adhoc(tc, + { + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Unhandled lexical type in lexprimspec for '%s'", - MVM_string_utf8_encode_C_string(tc, name)); + c_name); + } } } } - MVM_exception_throw_adhoc(tc, "Frame has no lexical with name '%s'", - MVM_string_utf8_encode_C_string(tc, name)); + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Frame has no lexical with name '%s'", + c_name); } static MVMObject * find_invokee_internal(MVMThreadContext *tc, MVMObject *code, MVMCallsite **tweak_cs, MVMInvocationSpec *is) { diff --git a/src/core/interp.c b/src/core/interp.c index 580a800723..f9c7d77961 100644 --- a/src/core/interp.c +++ b/src/core/interp.c @@ -260,9 +260,12 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex MVMRegister *r = MVM_frame_find_lexical_by_name(tc, str, MVM_reg_obj); if (r) r->o = GET_REG(cur_op, 4).o; - else - MVM_exception_throw_adhoc(tc, "Cannot bind to non-existing object lexical '%s'", - MVM_string_utf8_encode_C_string(tc, str)); + else { + char *c_str = MVM_string_utf8_encode_C_string(tc, str); + char *waste[] = { c_str, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Cannot bind to non-existing object lexical '%s'", + c_str); + } cur_op += 6; goto NEXT; } @@ -3026,9 +3029,12 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex MVMSTable *st = STABLE(GET_REG(cur_op, 0).o); MVMString *name = GET_REG(cur_op, 2).s; const MVMContainerConfigurer *cc = MVM_6model_get_container_config(tc, name); - if (cc == NULL) - MVM_exception_throw_adhoc(tc, "Cannot use unknown container spec %s", - MVM_string_utf8_encode_C_string(tc, name)); + if (cc == NULL) { + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Cannot use unknown container spec %s", + c_name); + } if (st->container_spec) MVM_exception_throw_adhoc(tc, "Cannot change a type's container specification"); diff --git a/src/core/loadbytecode.c b/src/core/loadbytecode.c index 7bd44dbbd5..5ebf0b8189 100644 --- a/src/core/loadbytecode.c +++ b/src/core/loadbytecode.c @@ -27,6 +27,8 @@ void MVM_load_bytecode(MVMThreadContext *tc, MVMString *filename) { /* Otherwise, load from disk. */ MVMROOT(tc, filename, { char *c_filename = MVM_string_utf8_encode_C_string(tc, filename); + // XXX any exception from MVM_cu_map_from_file needs to be handled + // and c_filename needs to be freed cu = MVM_cu_map_from_file(tc, c_filename); MVM_free(c_filename); cu->body.filename = filename; diff --git a/src/core/nativecall.c b/src/core/nativecall.c index ce69a1a958..6dcc180ef5 100644 --- a/src/core/nativecall.c +++ b/src/core/nativecall.c @@ -87,8 +87,10 @@ MVMint16 MVM_nativecall_get_arg_type(MVMThreadContext *tc, MVMObject *info, MVMi result = MVM_NATIVECALL_ARG_VMARRAY; else if (strcmp(ctypename, "callback") == 0) result = MVM_NATIVECALL_ARG_CALLBACK; - else - MVM_exception_throw_adhoc(tc, "Unknown type '%s' used for native call", ctypename); + else { + char *waste[] = { ctypename, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Unknown type '%s' used for native call", ctypename); + } MVM_free(ctypename); return result; } @@ -357,14 +359,17 @@ void MVM_nativecall_build(MVMThreadContext *tc, MVMObject *site, MVMString *lib, if (!body->lib_handle) { MVM_free(sym_name); - MVM_exception_throw_adhoc(tc, "Cannot locate native library '%s': %s", lib_name, dlerror()); + char *waste[] = { lib_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Cannot locate native library '%s': %s", lib_name, dlerror()); } /* Try to locate the symbol. */ body->entry_point = MVM_nativecall_find_sym(body->lib_handle, sym_name); - if (!body->entry_point) - MVM_exception_throw_adhoc(tc, "Cannot locate symbol '%s' in native library '%s'", + if (!body->entry_point) { + char *waste[] = { sym_name, lib_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Cannot locate symbol '%s' in native library '%s'", sym_name, lib_name); + } MVM_free(sym_name); /* Set calling convention, if any. */ @@ -520,14 +525,17 @@ MVMObject * MVM_nativecall_global(MVMThreadContext *tc, MVMString *lib, MVMStrin lib_handle = MVM_nativecall_load_lib(strlen(lib_name) ? lib_name : NULL); if (!lib_handle) { MVM_free(sym_name); - MVM_exception_throw_adhoc(tc, "Cannot locate native library '%s': %s", lib_name, dlerror()); + char *waste[] = { lib_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Cannot locate native library '%s': %s", lib_name, dlerror()); } /* Try to locate the symbol. */ entry_point = MVM_nativecall_find_sym(lib_handle, sym_name); - if (!entry_point) - MVM_exception_throw_adhoc(tc, "Cannot locate symbol '%s' in native library '%s'", + if (!entry_point) { + char *waste[] = { sym_name, lib_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Cannot locate symbol '%s' in native library '%s'", sym_name, lib_name); + } MVM_free(sym_name); MVM_free(lib_name); diff --git a/src/core/nativecall_dyncall.c b/src/core/nativecall_dyncall.c index 34448ad8ef..7a981cfbd4 100644 --- a/src/core/nativecall_dyncall.c +++ b/src/core/nativecall_dyncall.c @@ -14,9 +14,11 @@ MVMint16 MVM_nativecall_get_calling_convention(MVMThreadContext *tc, MVMString * result = DC_CALL_C_X86_WIN32_STD; else if (strcmp(cname, "stdcall") == 0) result = DC_CALL_C_X64_WIN64; - else - MVM_exception_throw_adhoc(tc, + else { + char *waste[] = { cname, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Unknown calling convention '%s' used for native call", cname); + } MVM_free(cname); } return result; diff --git a/src/core/nativecall_libffi.c b/src/core/nativecall_libffi.c index e36af0106f..50e08e3e87 100644 --- a/src/core/nativecall_libffi.c +++ b/src/core/nativecall_libffi.c @@ -57,9 +57,11 @@ ffi_abi MVM_nativecall_get_calling_convention(MVMThreadContext *tc, MVMString *n //~ result = DC_CALL_C_X86_WIN32_STD; //~ else if (strcmp(cname, "stdcall") == 0) //~ result = DC_CALL_C_X64_WIN64; - //~ else - //~ MVM_exception_throw_adhoc(tc, + //~ else { + //~ char *waste[] = { cname, NULL }; + //~ MVM_exception_throw_adhoc_free(tc, waste, //~ "Unknown calling convention '%s' used for native call", cname); + //~ } //~ MVM_free(cname); //~ } return result; diff --git a/src/io/syncfile.c b/src/io/syncfile.c index a7baeaa855..329a04aff1 100644 --- a/src/io/syncfile.c +++ b/src/io/syncfile.c @@ -438,13 +438,15 @@ MVMObject * MVM_file_open_fh(MVMThreadContext *tc, MVMString *filename, MVMStrin int flag; if (!resolve_open_mode(&flag, fmode)) { MVM_free(fname); - MVM_exception_throw_adhoc(tc, "Invalid open mode: %s", fmode); + char *waste[] = { fmode, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Invalid open mode: %s", fmode); } MVM_free(fmode); /* Try to open the file. */ if ((fd = uv_fs_open(tc->loop, &req, (const char *)fname, flag, DEFAULT_MODE, NULL)) < 0) { - MVM_exception_throw_adhoc(tc, "Failed to open file %s: %s", fname, uv_strerror(req.result)); + char *waste[] = { fname, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Failed to open file %s: %s", fname, uv_strerror(req.result)); } /* Set up handle. */ diff --git a/src/mast/compiler.c b/src/mast/compiler.c index fde5a2c036..c0f9c914e9 100644 --- a/src/mast/compiler.c +++ b/src/mast/compiler.c @@ -809,9 +809,12 @@ static void compile_instruction(VM, WriterState *ws, MASTNode *node) { unsigned int current_frame_idx = ws->current_frame_idx; unsigned int current_ins_idx = ws->current_ins_idx; cleanup_all(vm, ws); - DIE(vm, "At Frame %u, Instruction %u, op '%s' has invalid number (%u) of operands; needs %u.", + + char *c_name = VM_STRING_TO_C_STRING(vm, o->name); + char *waste[] = { c_name, NULL }; + DIE_FREE(vm, waste, "At Frame %u, Instruction %u, op '%s' has invalid number (%u) of operands; needs %u.", current_frame_idx, current_ins_idx, - VM_STRING_TO_C_STRING(vm, o->name), + c_name, ELEMS(vm, o->operands), num_operands); } diff --git a/src/mast/driver.c b/src/mast/driver.c index c28fe24a07..c363fc5b0d 100644 --- a/src/mast/driver.c +++ b/src/mast/driver.c @@ -97,7 +97,11 @@ void MVM_mast_to_file(MVMThreadContext *tc, MVMObject *mast, MVMObject *types, M MVM_free(c_filename); } else { - MVM_exception_throw_adhoc(tc, "Unable to write bytecode to '%s'", c_filename); + /* we have to build waste by hand, otherwise MVMROOT gets mad */ + char *waste[2]; + waste[0] = c_filename; + waste[1] = NULL; + MVM_exception_throw_adhoc_free(tc, waste, "Unable to write bytecode to '%s'", c_filename); } }); } diff --git a/src/mast/nodes.h b/src/mast/nodes.h index 49953bdaba..998ab63249 100644 --- a/src/mast/nodes.h +++ b/src/mast/nodes.h @@ -179,3 +179,5 @@ typedef MVMString VMSTR; #define VM_STRING_IS_NULL(s) (s == NULL) #define VM_OBJ_IS_NULL(o) (o == NULL) #define VM_STRING_TO_C_STRING(vm, s) (MVM_string_ascii_encode_any(tc, s)) + +#define DIE_FREE(vm, waste, msg, ...) MVM_exception_throw_adhoc_free(tc, waste, msg, ## __VA_ARGS__) diff --git a/src/strings/ops.c b/src/strings/ops.c index ee85eb2244..e067772654 100644 --- a/src/strings/ops.c +++ b/src/strings/ops.c @@ -1595,8 +1595,10 @@ MVMuint8 MVM_string_find_encoding(MVMThreadContext *tc, MVMString *name) { return MVM_encoding_type_utf16; } else { - MVM_exception_throw_adhoc(tc, "Unknown string encoding: '%s'", - MVM_string_utf8_encode_C_string(tc, name)); + char *c_name = MVM_string_utf8_encode_C_string(tc, name); + char *waste[] = { c_name, NULL }; + MVM_exception_throw_adhoc_free(tc, waste, "Unknown string encoding: '%s'", + c_name); } }