Skip to content

Commit 01019fe

Browse files
lambdageekjoncham
authored andcommitted
[object] mono_string_new should not assert on UTF conversion failures (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.
1 parent 6590226 commit 01019fe

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

mono/metadata/object.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6298,7 +6298,15 @@ mono_string_new (MonoDomain *domain, const char *text)
62986298
MonoError error;
62996299
MonoString *res = NULL;
63006300
res = mono_string_new_checked (domain, text, &error);
6301-
mono_error_assert_ok (&error);
6301+
if (!is_ok (&error)) {
6302+
/* Mono API compatability: assert on Out of Memory errors,
6303+
* return NULL otherwise (most likely an invalid UTF-8 byte
6304+
* sequence). */
6305+
if (mono_error_get_error_code (&error) == MONO_ERROR_OUT_OF_MEMORY)
6306+
mono_error_assert_ok (&error);
6307+
else
6308+
mono_error_cleanup (&error);
6309+
}
63026310
return res;
63036311
}
63046312

mono/utils/mono-error-internals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct _MonoErrorBoxed {
6363
void
6464
mono_error_assert_ok_pos (MonoError *error, const char* filename, int lineno) MONO_LLVM_INTERNAL;
6565

66-
#define mono_error_assert_ok(e) mono_error_assert_ok_pos (e, __FILE__, __LINE__);
66+
#define mono_error_assert_ok(e) mono_error_assert_ok_pos (e, __FILE__, __LINE__)
6767

6868
void
6969
mono_error_dup_strings (MonoError *error, gboolean dup_strings);

0 commit comments

Comments
 (0)