Skip to content

Commit

Permalink
Forward mono_string_new_wrapper to mono_string_new for error handling.
Browse files Browse the repository at this point in the history
In commit 8ba48b5
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.
  • Loading branch information
joncham committed Mar 23, 2018
1 parent 01019fe commit f650db8
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions mono/metadata/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit f650db8

Please sign in to comment.