Skip to content

Commit

Permalink
Revert "Revert "Merge pull request #1139 from MasterDuke17/add_contex…
Browse files Browse the repository at this point in the history
…t_to_error_messages""

This reverts commit b2dc3f3.

This was reverted because a previous commit also had to be reverted and
I wanted these changes to get their own NQP bump for easy bisecting.
  • Loading branch information
MasterDuke17 committed Oct 4, 2019
1 parent b72a790 commit 01f85c8
Show file tree
Hide file tree
Showing 19 changed files with 180 additions and 102 deletions.
26 changes: 7 additions & 19 deletions src/core/args.c
Expand Up @@ -413,25 +413,13 @@ void MVM_args_assert_nameds_used(MVMThreadContext *tc, MVMArgProcContext *ctx) {
MVMuint16 i;
if (size > 64) {
for (i = 0; i < size; i++)
if (!ctx->named_used.byte_array[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 argument '%s' passed",
c_param);
}
if (!ctx->named_used.byte_array[i])
MVM_args_throw_named_unused_error(tc, ctx->args[ctx->num_pos + 2 * i].s);
}
else {
for (i = 0; i < size; i++)
if (!(ctx->named_used.bit_field & ((MVMuint64)1 << 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 argument '%s' passed",
c_param);
}
if (!(ctx->named_used.bit_field & ((MVMuint64)1 << i)))
MVM_args_throw_named_unused_error(tc, ctx->args[ctx->num_pos + 2 * i].s);
}
}

Expand Down Expand Up @@ -701,7 +689,7 @@ MVMObject * MVM_args_slurpy_positional(MVMThreadContext *tc, MVMArgProcContext *
break;
}
default:
MVM_exception_throw_adhoc(tc, "arg flag is empty in slurpy positional");
MVM_exception_throw_adhoc(tc, "Arg flag is empty in slurpy_positional");
}

find_pos_arg(&(tc->cur_frame->params), pos, arg_info);
Expand Down Expand Up @@ -819,7 +807,7 @@ MVMObject * MVM_args_slurpy_named(MVMThreadContext *tc, MVMArgProcContext *ctx)
break;
}
default:
MVM_exception_throw_adhoc(tc, "arg flag is empty in slurpy named");
MVM_exception_throw_adhoc(tc, "Arg flag is empty in slurpy_named");
}
}

Expand Down Expand Up @@ -864,7 +852,7 @@ static void flatten_args(MVMThreadContext *tc, MVMArgProcContext *ctx) {
MVMStorageSpec lss = REPR(list)->pos_funcs.get_elem_storage_spec(tc, STABLE(list));

if ((MVMint64)new_arg_pos + count > 0xFFFF) {
MVM_exception_throw_adhoc(tc, "Too many arguments in flattening array.");
MVM_exception_throw_adhoc(tc, "Too many arguments (%"PRId64") in flattening array, only %"PRId32" allowed.", (MVMint64)new_arg_pos + count, 0xFFFF);
}

for (i = 0; i < count; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/bytecode.c
Expand Up @@ -682,7 +682,7 @@ void MVM_bytecode_finish_frame(MVMThreadContext *tc, MVMCompUnit *cu,

if (lex_idx >= sf->body.num_lexicals) {
MVM_reentrantmutex_unlock(tc, (MVMReentrantMutex *)cu->body.deserialize_frame_mutex);
MVM_exception_throw_adhoc(tc, "Lexical index out of bounds: %d > %d", lex_idx, sf->body.num_lexicals);
MVM_exception_throw_adhoc(tc, "Lexical index out of bounds: %d >= %d", lex_idx, sf->body.num_lexicals);
}

sf->body.static_env_flags[lex_idx] = flags;
Expand Down
14 changes: 7 additions & 7 deletions src/core/coerce.c
Expand Up @@ -222,7 +222,7 @@ MVMString * MVM_coerce_i_s(MVMThreadContext *tc, MVMint64 i) {
return result;
}
else {
MVM_exception_throw_adhoc(tc, "Could not stringify integer");
MVM_exception_throw_adhoc(tc, "Could not stringify integer (%"PRId64")", i);
}
}

Expand All @@ -248,7 +248,7 @@ MVMString * MVM_coerce_u_s(MVMThreadContext *tc, MVMuint64 i) {
return result;
}
else {
MVM_exception_throw_adhoc(tc, "Could not stringify integer");
MVM_exception_throw_adhoc(tc, "Could not stringify integer (%"PRIu64")", i);
}
}

Expand All @@ -265,7 +265,7 @@ MVMString * MVM_coerce_n_s(MVMThreadContext *tc, MVMnum64 n) {
else {
char buf[64];
if (dtoa_grisu3(n, buf, 64) < 0)
MVM_exception_throw_adhoc(tc, "Could not stringify number");
MVM_exception_throw_adhoc(tc, "Could not stringify number (%f)", n);
else {
MVMStringIndex len = strlen(buf);
MVMGrapheme8 *blob = MVM_malloc(len);
Expand Down Expand Up @@ -321,7 +321,7 @@ void MVM_coerce_smart_stringify(MVMThreadContext *tc, MVMObject *obj, MVMRegiste
else if (ss->can_box & MVM_STORAGE_SPEC_CAN_BOX_NUM)
res_reg->s = MVM_coerce_n_s(tc, REPR(obj)->box_funcs.get_num(tc, STABLE(obj), obj, OBJECT_BODY(obj)));
else
MVM_exception_throw_adhoc(tc, "Cannot stringify this type (%s)", MVM_6model_get_stable_debug_name(tc, STABLE(obj)));
MVM_exception_throw_adhoc(tc, "Cannot stringify this object of type %s (%s)", REPR(obj)->name, MVM_6model_get_stable_debug_name(tc, STABLE(obj)));
}
}

Expand Down Expand Up @@ -376,7 +376,7 @@ void MVM_coerce_smart_numify(MVMThreadContext *tc, MVMObject *obj, MVMRegister *
else if (REPR(obj)->ID == MVM_REPR_ID_MVMHash)
res_reg->n64 = (MVMnum64)REPR(obj)->elems(tc, STABLE(obj), obj, OBJECT_BODY(obj));
else
MVM_exception_throw_adhoc(tc, "Cannot numify this type (%s)", MVM_6model_get_stable_debug_name(tc, STABLE(obj)));
MVM_exception_throw_adhoc(tc, "Cannot numify this object of type %s (%s)", REPR(obj)->name, MVM_6model_get_stable_debug_name(tc, STABLE(obj)));
}
}

Expand Down Expand Up @@ -423,7 +423,7 @@ void MVM_coerce_smart_intify(MVMThreadContext *tc, MVMObject *obj, MVMRegister *
else if (REPR(obj)->ID == MVM_REPR_ID_MVMHash)
res_reg->i64 = REPR(obj)->elems(tc, STABLE(obj), obj, OBJECT_BODY(obj));
else
MVM_exception_throw_adhoc(tc, "Cannot intify this type (%s)", MVM_6model_get_stable_debug_name(tc, STABLE(obj)));
MVM_exception_throw_adhoc(tc, "Cannot intify this object of type %s (%s)", REPR(obj)->name, MVM_6model_get_stable_debug_name(tc, STABLE(obj)));
}
}

Expand All @@ -447,7 +447,7 @@ MVMint64 MVM_coerce_simple_intify(MVMThreadContext *tc, MVMObject *obj) {
else if (REPR(obj)->ID == MVM_REPR_ID_MVMHash)
return REPR(obj)->elems(tc, STABLE(obj), obj, OBJECT_BODY(obj));
else
MVM_exception_throw_adhoc(tc, "Cannot intify this type (%s)", MVM_6model_get_stable_debug_name(tc, STABLE(obj)));
MVM_exception_throw_adhoc(tc, "Cannot intify this object of type %s (%s)", REPR(obj)->name, MVM_6model_get_stable_debug_name(tc, STABLE(obj)));
}
}

Expand Down
20 changes: 14 additions & 6 deletions src/core/dll.c
Expand Up @@ -57,8 +57,10 @@ int MVM_dll_free(MVMThreadContext *tc, MVMString *name) {
MVM_HASH_GET(tc, tc->instance->dll_registry, name, entry);

if (!entry) {
char *c_name = MVM_string_utf8_encode_C_string(tc, name);
char *waste[] = { c_name, NULL };
uv_mutex_unlock(&tc->instance->mutex_dll_registry);
MVM_exception_throw_adhoc(tc, "cannot free non-existent library");
MVM_exception_throw_adhoc_free(tc, waste, "cannot free non-existent library '%s'", c_name);
}

/* already freed */
Expand All @@ -68,8 +70,10 @@ int MVM_dll_free(MVMThreadContext *tc, MVMString *name) {
}

if (entry->refcount > 0) {
char *c_name = MVM_string_utf8_encode_C_string(tc, name);
char *waste[] = { c_name, NULL };
uv_mutex_unlock(&tc->instance->mutex_dll_registry);
MVM_exception_throw_adhoc(tc, "cannot free in-use library");
MVM_exception_throw_adhoc_free(tc, waste, "cannot free in-use library '%s'", c_name);
}

MVM_nativecall_free_lib(entry->lib);
Expand All @@ -92,15 +96,19 @@ MVMObject * MVM_dll_find_symbol(MVMThreadContext *tc, MVMString *lib,
MVM_HASH_GET(tc, tc->instance->dll_registry, lib, entry);

if (!entry) {
char *c_lib = MVM_string_utf8_encode_C_string(tc, lib);
char *waste[] = { c_lib, NULL };
uv_mutex_unlock(&tc->instance->mutex_dll_registry);
MVM_exception_throw_adhoc(tc,
"cannot find symbol in non-existent library");
MVM_exception_throw_adhoc_free(tc, waste,
"cannot find symbol '%s' in non-existent library", c_lib);
}

if (!entry->lib) {
char *c_lib = MVM_string_utf8_encode_C_string(tc, lib);
char *waste[] = { c_lib, NULL };
uv_mutex_unlock(&tc->instance->mutex_dll_registry);
MVM_exception_throw_adhoc(tc,
"cannot find symbol in unloaded library");
MVM_exception_throw_adhoc_free(tc, waste,
"cannot find symbol '%s' in unloaded library", c_lib);
}

csym = MVM_string_utf8_c8_encode_C_string(tc, sym);
Expand Down
4 changes: 3 additions & 1 deletion src/core/ext.c
Expand Up @@ -27,8 +27,10 @@ int MVM_ext_load(MVMThreadContext *tc, MVMString *lib, MVMString *ext) {
sym = (MVMDLLSym *)MVM_dll_find_symbol(tc, lib, ext);
});
if (!sym) {
char *c_name = MVM_string_utf8_encode_C_string(tc, name);
char *waste[] = { c_name, NULL };
uv_mutex_unlock(&tc->instance->mutex_ext_registry);
MVM_exception_throw_adhoc(tc, "extension symbol not found");
MVM_exception_throw_adhoc_free(tc, waste, "extension symbol (%s) not found", c_name);
}

entry = MVM_malloc(sizeof *entry);
Expand Down

0 comments on commit 01f85c8

Please sign in to comment.