Skip to content

Commit f650db8

Browse files
committed
Forward mono_string_new_wrapper to mono_string_new for error handling.
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.
1 parent 01019fe commit f650db8

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

mono/metadata/object.c

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6285,23 +6285,16 @@ mono_string_new_len_checked (MonoDomain *domain, const char *text, guint length,
62856285
return o;
62866286
}
62876287

6288-
/**
6289-
* mono_string_new:
6290-
* \param text a pointer to a UTF-8 string
6291-
* \deprecated Use \c mono_string_new_checked in new code.
6292-
* This function asserts if it cannot allocate a new string.
6293-
* \returns A newly created string object which contains \p text.
6294-
*/
6295-
MonoString*
6296-
mono_string_new (MonoDomain *domain, const char *text)
6288+
static MonoString*
6289+
mono_string_new_internal (MonoDomain *domain, const char *text)
62976290
{
62986291
MonoError error;
62996292
MonoString *res = NULL;
63006293
res = mono_string_new_checked (domain, text, &error);
63016294
if (!is_ok (&error)) {
63026295
/* Mono API compatability: assert on Out of Memory errors,
6303-
* return NULL otherwise (most likely an invalid UTF-8 byte
6304-
* sequence). */
6296+
* return NULL otherwise (most likely an invalid UTF-8 byte
6297+
* sequence). */
63056298
if (mono_error_get_error_code (&error) == MONO_ERROR_OUT_OF_MEMORY)
63066299
mono_error_assert_ok (&error);
63076300
else
@@ -6310,6 +6303,19 @@ mono_string_new (MonoDomain *domain, const char *text)
63106303
return res;
63116304
}
63126305

6306+
/**
6307+
* mono_string_new:
6308+
* \param text a pointer to a UTF-8 string
6309+
* \deprecated Use \c mono_string_new_checked in new code.
6310+
* This function asserts if it cannot allocate a new string.
6311+
* \returns A newly created string object which contains \p text.
6312+
*/
6313+
MonoString*
6314+
mono_string_new (MonoDomain *domain, const char *text)
6315+
{
6316+
return mono_string_new_internal (domain, text);
6317+
}
6318+
63136319
/**
63146320
* mono_string_new_checked:
63156321
* \param text a pointer to an utf8 string
@@ -6380,16 +6386,7 @@ mono_string_new_wrapper (const char *text)
63806386
{
63816387
MONO_REQ_GC_UNSAFE_MODE;
63826388

6383-
MonoDomain *domain = mono_domain_get ();
6384-
6385-
if (text) {
6386-
MonoError error;
6387-
MonoString *result = mono_string_new_checked (domain, text, &error);
6388-
mono_error_assert_ok (&error);
6389-
return result;
6390-
}
6391-
6392-
return NULL;
6389+
return mono_string_new_internal (mono_domain_get (), text);
63936390
}
63946391

63956392
/**

0 commit comments

Comments
 (0)