Skip to content

Commit

Permalink
[object] mono_string_new should not assert on UTF conversion failures (
Browse files Browse the repository at this point in the history
…mono#6333)

Revert the embedding API behavior change introduced by dcdfb3c

mono_string_new will:
 * return NULL if the given byte sequence is not a valid UTF-8 sequence
 * assert if there is not enough memory to allocate a new MonoString.

This only changes the behavior of the API function.  The runtime will continue
to use mono_string_new_checked which sets MonoError* for both sorts of
failures.
  • Loading branch information
lambdageek authored and joncham committed Mar 23, 2018
1 parent 6590226 commit 01019fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion mono/metadata/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -6298,7 +6298,15 @@ mono_string_new (MonoDomain *domain, const char *text)
MonoError error;
MonoString *res = NULL;
res = mono_string_new_checked (domain, text, &error);
mono_error_assert_ok (&error);
if (!is_ok (&error)) {
/* Mono API compatability: assert on Out of Memory errors,
* return NULL otherwise (most likely an invalid UTF-8 byte
* sequence). */
if (mono_error_get_error_code (&error) == MONO_ERROR_OUT_OF_MEMORY)
mono_error_assert_ok (&error);
else
mono_error_cleanup (&error);
}
return res;
}

Expand Down
2 changes: 1 addition & 1 deletion mono/utils/mono-error-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct _MonoErrorBoxed {
void
mono_error_assert_ok_pos (MonoError *error, const char* filename, int lineno) MONO_LLVM_INTERNAL;

#define mono_error_assert_ok(e) mono_error_assert_ok_pos (e, __FILE__, __LINE__);
#define mono_error_assert_ok(e) mono_error_assert_ok_pos (e, __FILE__, __LINE__)

void
mono_error_dup_strings (MonoError *error, gboolean dup_strings);
Expand Down

0 comments on commit 01019fe

Please sign in to comment.