From f650db8614596fdc81e55cdc546a803a9ee0416a Mon Sep 17 00:00:00 2001 From: Jonathan Chambers Date: Tue, 20 Mar 2018 13:26:58 -0400 Subject: [PATCH] Forward mono_string_new_wrapper to mono_string_new for error handling. In commit 8ba48b5a41ac48bf6fe9351406165d22c753722d mono_string_new was adjusted to only assert for out of memory rather than all errors to preserve previous behavior for invalid strings. This change preserves behavior for mono_string_new_wrapper. --- mono/metadata/object.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/mono/metadata/object.c b/mono/metadata/object.c index b41747db57bb..94a92c7517fa 100644 --- a/mono/metadata/object.c +++ b/mono/metadata/object.c @@ -6285,23 +6285,16 @@ mono_string_new_len_checked (MonoDomain *domain, const char *text, guint length, return o; } -/** - * mono_string_new: - * \param text a pointer to a UTF-8 string - * \deprecated Use \c mono_string_new_checked in new code. - * This function asserts if it cannot allocate a new string. - * \returns A newly created string object which contains \p text. - */ -MonoString* -mono_string_new (MonoDomain *domain, const char *text) +static MonoString* +mono_string_new_internal (MonoDomain *domain, const char *text) { MonoError error; MonoString *res = NULL; res = mono_string_new_checked (domain, text, &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). */ + * 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 @@ -6310,6 +6303,19 @@ mono_string_new (MonoDomain *domain, const char *text) return res; } +/** + * mono_string_new: + * \param text a pointer to a UTF-8 string + * \deprecated Use \c mono_string_new_checked in new code. + * This function asserts if it cannot allocate a new string. + * \returns A newly created string object which contains \p text. + */ +MonoString* +mono_string_new (MonoDomain *domain, const char *text) +{ + return mono_string_new_internal (domain, text); +} + /** * mono_string_new_checked: * \param text a pointer to an utf8 string @@ -6380,16 +6386,7 @@ mono_string_new_wrapper (const char *text) { MONO_REQ_GC_UNSAFE_MODE; - MonoDomain *domain = mono_domain_get (); - - if (text) { - MonoError error; - MonoString *result = mono_string_new_checked (domain, text, &error); - mono_error_assert_ok (&error); - return result; - } - - return NULL; + return mono_string_new_internal (mono_domain_get (), text); } /**