From 01019fe446fe9170250e42513cea9d83a4c66e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksey=20Kliger=20=28=CE=BBgeek=29?= Date: Mon, 25 Dec 2017 04:45:52 -0500 Subject: [PATCH] [object] mono_string_new should not assert on UTF conversion failures (#6333) Revert the embedding API behavior change introduced by dcdfb3c5005297b375c985ec5f0a4af99f8ad7cf 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. --- mono/metadata/object.c | 10 +++++++++- mono/utils/mono-error-internals.h | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/mono/metadata/object.c b/mono/metadata/object.c index 6cc790cb0817..b41747db57bb 100644 --- a/mono/metadata/object.c +++ b/mono/metadata/object.c @@ -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; } diff --git a/mono/utils/mono-error-internals.h b/mono/utils/mono-error-internals.h index 045d85ec38ec..cbb452c4ca1c 100644 --- a/mono/utils/mono-error-internals.h +++ b/mono/utils/mono-error-internals.h @@ -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);